summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2019-09-03 08:37:55 +0000
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-09-03 13:38:08 +0000
commitccc1f364baea63733e93c6f4eb26ea97eeb77960 (patch)
tree2ce098bd1d4a28e611dd91f2eea6605a51cbf463 /openecomp-be
parente79935cbaa180a86eea2c7631de14c16bef9b3d8 (diff)
Onboard Package Handling
Retain the original onboarded package when it comes in zip/csar format. Issue-ID: SDC-2510 Change-Id: Ie293db25eca8872be26ffc8475b25ccace1aab6f Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java114
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java50
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java33
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java12
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java38
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java62
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java35
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java9
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java31
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java26
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java38
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackageInfo.java46
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java77
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java44
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java57
-rw-r--r--openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java38
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java83
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java37
19 files changed, 529 insertions, 303 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
index 5cf6f40c37..10f96e9d3b 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
@@ -19,8 +19,24 @@
package org.openecomp.sdcrests.vsp.rest.services;
+import static org.openecomp.core.utilities.file.FileUtils.getFileExtension;
+import static org.openecomp.core.utilities.file.FileUtils.getNetworkPackageName;
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import javax.activation.DataHandler;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.activitylog.ActivityLogManager;
import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
@@ -35,7 +51,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateMan
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
@@ -53,20 +72,6 @@ import org.openecomp.sdcrests.vsp.rest.mapping.MapValidationResponseToDto;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import static org.openecomp.core.utilities.file.FileUtils.getFileExtension;
-import static org.openecomp.core.utilities.file.FileUtils.getNetworkPackageName;
-import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-
@Named
@Service("orchestrationTemplateCandidate")
@Scope(value = "prototype")
@@ -81,35 +86,86 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
ActivityLogManagerFactory.getInstance().createInterface();
@Override
- public Response upload(String vspId, String versionId, Attachment fileToUpload, String user) {
- PackageArchive archive = new PackageArchive(fileToUpload.getObject(byte[].class));
+ public Response upload(final String vspId, final String versionId,
+ final Attachment fileToUpload, final String user) {
+ final byte[] fileToUploadBytes = fileToUpload.getObject(byte[].class);
+ String fileToUploadName = "";
+ String fileToUploadExtension = "";
+ final DataHandler dataHandler = fileToUpload.getDataHandler();
+ if(dataHandler != null) {
+ final String filename = dataHandler.getName();
+ fileToUploadName = FilenameUtils.removeExtension(filename);
+ fileToUploadExtension = FilenameUtils.getExtension(filename);
+ }
+ final PackageArchive archive = new PackageArchive(fileToUploadBytes);
+ final Optional<UploadFileResponseDto> validatePackageArchiveResponse =
+ validatePackageArchive(archive);
+ if (!validatePackageArchiveResponse.isPresent()) {
+ final VspDetails vspDetails = new VspDetails(vspId, new Version(versionId));
+ return processOnboardPackage(fileToUpload, fileToUploadBytes, fileToUploadName,
+ fileToUploadExtension, archive, vspDetails);
+ } else {
+ return Response.ok(validatePackageArchiveResponse.get()).build();
+ }
+ }
+
+ private Optional<UploadFileResponseDto> validatePackageArchive(final PackageArchive archive) {
UploadFileResponseDto uploadFileResponseDto;
try {
if (archive.isSigned() && !archive.isSignatureValid()) {
- ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
- getErrorWithParameters(Messages.FAILED_TO_VERIFY_SIGNATURE.getErrorMessage(), ""));
+ final ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
+ getErrorWithParameters(Messages.FAILED_TO_VERIFY_SIGNATURE.getErrorMessage(), ""));
LOGGER.error(errorMessage.getMessage());
uploadFileResponseDto = buildUploadResponseWithError(errorMessage);
//returning OK as SDC UI won't show error message if NOT OK error code.
- return Response.ok(uploadFileResponseDto).build();
+ return Optional.of(uploadFileResponseDto);
}
+ } catch (final SecurityManagerException e) {
+ final ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
+ getErrorWithParameters(e.getMessage(), ""));
+ LOGGER.error(errorMessage.getMessage(), e);
+ uploadFileResponseDto = buildUploadResponseWithError(errorMessage);
+ //returning OK as SDC UI won't show error message if NOT OK error code.
+ return Optional.of(uploadFileResponseDto);
+ }
+ return Optional.empty();
+ }
- String filename = archive.getArchiveFileName().orElse(fileToUpload.getContentDisposition().getFilename());
- UploadFileResponse uploadFileResponse = candidateManager
- .upload(vspId, new Version(versionId), new ByteArrayInputStream(archive.getPackageFileContents()),
- getFileExtension(filename), getNetworkPackageName(filename));
-
+ private Response processOnboardPackage(final Attachment fileToUpload,
+ final byte[] fileToUploadBytes,
+ final String fileToUploadName,
+ final String fileToUploadExtension,
+ final PackageArchive archive,
+ final VspDetails vspDetails) {
+ final String filename = archive.getArchiveFileName()
+ .orElse(fileToUpload.getContentDisposition().getFilename());
+ UploadFileResponseDto uploadFileResponseDto;
+ try {
+ final String archiveFileExtension = getFileExtension(filename);
+ final OnboardPackageInfo onboardPackageInfo;
+ if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(archiveFileExtension)) {
+ final OnboardPackage onboardPackage = new OnboardPackage(getNetworkPackageName(filename),
+ archiveFileExtension, ByteBuffer.wrap(archive.getPackageFileContents()));
+ onboardPackageInfo = new OnboardPackageInfo(fileToUploadName,
+ fileToUploadExtension, ByteBuffer.wrap(fileToUploadBytes), onboardPackage);
+ } else {
+ onboardPackageInfo = new OnboardPackageInfo(fileToUploadName,
+ fileToUploadExtension, ByteBuffer.wrap(fileToUploadBytes));
+ }
+ final UploadFileResponse uploadFileResponse = candidateManager
+ .upload(vspDetails, onboardPackageInfo);
uploadFileResponseDto = new MapUploadFileResponseToUploadFileResponseDto()
- .applyMapping(uploadFileResponse, UploadFileResponseDto.class);
- } catch (SecurityManagerException e) {
- ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
- getErrorWithParameters(e.getMessage(), ""));
+ .applyMapping(uploadFileResponse, UploadFileResponseDto.class);
+
+ return Response.ok(uploadFileResponseDto).build();
+ } catch (final SecurityManagerException e) {
+ final ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
+ getErrorWithParameters(e.getMessage(), ""));
LOGGER.error(errorMessage.getMessage(), e);
uploadFileResponseDto = buildUploadResponseWithError(errorMessage);
//returning OK as SDC UI won't show error message if NOT OK error code.
return Response.ok(uploadFileResponseDto).build();
}
- return Response.ok(uploadFileResponseDto).build();
}
private UploadFileResponseDto buildUploadResponseWithError(ErrorMessage errorMessage) {
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
index 0ebd014dbe..a9dfbb8449 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
@@ -20,6 +20,20 @@
package org.openecomp.sdcrests.vsp.rest.services;
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertFalse;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.UUID;
+import javax.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
@@ -52,18 +66,6 @@ import org.openecomp.sdcrests.vsp.rest.data.PackageArchive;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Optional;
-import java.util.UUID;
-
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertFalse;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.MockitoAnnotations.initMocks;
-import static org.powermock.api.mockito.PowerMockito.*;
-
@RunWith(PowerMockRunner.class)
@PrepareForTest({VspManagerFactory.class, ActivityLogManagerFactory.class,
OrchestrationTemplateCandidateManagerFactory.class, OrchestrationTemplateCandidateImpl.class})
@@ -114,7 +116,7 @@ public class OrchestrationTemplateCandidateImplTest {
UploadFileResponse uploadFileResponse = new UploadFileResponse();
uploadFileResponse.setOnboardingType(OnboardingTypesEnum.ZIP);
uploadFileResponse.setNetworkPackageName("test");
- when(candidateManager.upload(any(), any(), any(), any(), any())).thenReturn(uploadFileResponse);
+ when(candidateManager.upload(any(), any())).thenReturn(uploadFileResponse);
// get using the candidate manager.
@@ -165,22 +167,24 @@ public class OrchestrationTemplateCandidateImplTest {
when(packageArchive.isSigned()).thenReturn(true);
when(packageArchive.isSignatureValid()).thenReturn(true);
orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
- Attachment attachment = mock(Attachment.class);
- when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
- Response response = orchestrationTemplateCandidate.upload("1", "1", attachment, "1");
+ Response response = orchestrationTemplateCandidate.upload("1", "1", mockAttachment(), "1");
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
}
@Test
public void uploadNotSignedTest(){
when(packageArchive.isSigned()).thenReturn(false);
orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
- Attachment attachment = mock(Attachment.class);
- when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
- Response response = orchestrationTemplateCandidate.upload("1", "1", attachment, "1");
+ Response response = orchestrationTemplateCandidate.upload("1", "1", mockAttachment(), "1");
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ }
+ private Attachment mockAttachment() {
+ final Attachment attachment = mock(Attachment.class);
+ when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
+ final byte[] bytes = "upload package Test".getBytes();
+ when(attachment.getObject(ArgumentMatchers.any())).thenReturn(bytes);
+ return attachment;
}
@Test
@@ -188,12 +192,9 @@ public class OrchestrationTemplateCandidateImplTest {
when(packageArchive.isSigned()).thenReturn(true);
when(packageArchive.isSignatureValid()).thenReturn(false);
orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
- Attachment attachment = mock(Attachment.class);
- when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
- Response response = orchestrationTemplateCandidate.upload("1", "1", attachment, "1");
+ Response response = orchestrationTemplateCandidate.upload("1", "1", mockAttachment(), "1");
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertFalse(((UploadFileResponseDto)response.getEntity()).getErrors().isEmpty());
-
}
@Test
@@ -204,7 +205,6 @@ public class OrchestrationTemplateCandidateImplTest {
Assert.assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf("Candidate"),-1);
byte[] content = (byte[])rsp.getEntity();
Assert.assertEquals("World", new String(content));
-
}
@Test
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java
index 6f76bf4527..5bcd3d3a39 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vnf-repository-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VnfPackageRepositoryImpl.java
@@ -21,10 +21,8 @@ import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
import static org.openecomp.core.utilities.file.FileUtils.getFileExtension;
import static org.openecomp.core.utilities.file.FileUtils.getNetworkPackageName;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.net.URI;
+import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
@@ -49,6 +47,8 @@ import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.VersioningManagerFactory;
@@ -135,24 +135,23 @@ public class VnfPackageRepositoryImpl implements VnfPackageRepository {
}
}
- private Response uploadVnfPackage(String vspId, String versionId, String csarId, byte[] payload) {
-
- try (InputStream fileStream = new BufferedInputStream(new ByteArrayInputStream(payload))) {
-
- OrchestrationTemplateCandidateManager candidateManager =
+ private Response uploadVnfPackage(final String vspId, final String versionId,
+ final String csarId, final byte[] payload) {
+ try {
+ final OrchestrationTemplateCandidateManager candidateManager =
OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface();
-
- String filename = formatFilename(csarId);
- Version version = getVersion(vspId, versionId);
- UploadFileResponse response = candidateManager.upload(vspId, version, fileStream,
- getFileExtension(filename), getNetworkPackageName(filename));
-
- UploadFileResponseDto uploadFileResponse = new MapUploadFileResponseToUploadFileResponseDto()
- .applyMapping(response, UploadFileResponseDto.class);
+ final String filename = formatFilename(csarId);
+ final OnboardPackageInfo onboardPackageInfo = new OnboardPackageInfo(getNetworkPackageName(filename),
+ getFileExtension(filename), ByteBuffer.wrap(payload));
+ final VspDetails vspDetails = new VspDetails(vspId, getVersion(vspId, versionId));
+ final UploadFileResponse response = candidateManager.upload(vspDetails, onboardPackageInfo);
+ final UploadFileResponseDto uploadFileResponse =
+ new MapUploadFileResponseToUploadFileResponseDto()
+ .applyMapping(response, UploadFileResponseDto.class);
return Response.ok(uploadFileResponse).build();
- } catch (Exception e) {
+ } catch (final Exception e) {
ErrorCode error = new GeneralErrorBuilder().build();
LOGGER.error("Exception while uploading package received from VNF Repository", new CoreException(error, e));
return generateInternalServerError(error);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java
index 238dbc08d0..5cf66874c4 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java
@@ -16,21 +16,19 @@
package org.openecomp.sdc.vendorsoftwareproduct;
+import java.io.IOException;
+import java.util.Optional;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Optional;
-
public interface OrchestrationTemplateCandidateManager {
- UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload,
- String fileSuffix, String networkPackageName);
OrchestrationTemplateActionResponse process(String vspId, Version version);
@@ -44,4 +42,6 @@ public interface OrchestrationTemplateCandidateManager {
Optional<OrchestrationTemplateCandidateData> getInfo(String vspId, Version version);
void abort(String vspId, Version version);
+
+ UploadFileResponse upload(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo);
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
index 57f6b672be..d5d5c8045b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java
@@ -16,6 +16,11 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@@ -34,19 +39,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationT
import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUploadFactory;
import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationProcessFactory;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
public class OrchestrationTemplateCandidateManagerImpl
implements OrchestrationTemplateCandidateManager {
@@ -61,18 +61,16 @@ public class OrchestrationTemplateCandidateManagerImpl
}
@Override
- public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload,
- String fileSuffix, String networkPackageName) {
- OrchestrationTemplateFileHandler orchestrationTemplateFileHandler =
- OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(fileSuffix);
-
- VspDetails vspDetails = getVspDetails(vspId, version);
-
- UploadFileResponse uploadResponse = orchestrationTemplateFileHandler
- .upload(vspDetails, fileToUpload, fileSuffix, networkPackageName, candidateService);
-
- uploadResponse.setNetworkPackageName(networkPackageName);
- return uploadResponse;
+ public UploadFileResponse upload(final VspDetails vspDetails,
+ final OnboardPackageInfo onboardPackageInfo) {
+ final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage();
+ final OrchestrationTemplateFileHandler orchestrationTemplateFileHandler =
+ OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(onboardPackage.getFileExtension());
+
+ final UploadFileResponse uploadFileResponse =
+ orchestrationTemplateFileHandler.upload(vspDetails, onboardPackageInfo, candidateService);
+ uploadFileResponse.setNetworkPackageName(onboardPackage.getFilename());
+ return uploadFileResponse;
}
@Override
@@ -153,4 +151,4 @@ public class OrchestrationTemplateCandidateManagerImpl
private VspDetails getVspDetails(String vspId, Version version) {
return vspInfoDao.get(new VspDetails(vspId, version));
}
-}
+} \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java
index 87dd29d095..d87c9c8dbb 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java
@@ -20,9 +20,12 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+
+import java.io.ByteArrayInputStream;
+import java.util.Optional;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.common.utils.SdcCommon;
@@ -32,33 +35,32 @@ import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
-import java.io.InputStream;
-import java.util.Optional;
-
-import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-
public abstract class BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler {
- protected static final Logger logger =
- LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class);
+ protected static final Logger logger = LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class);
+
@Override
- public UploadFileResponse upload(VspDetails vspDetails, InputStream fileToUpload,
- String fileSuffix, String networkPackageName,
- CandidateService candidateService) {
- UploadFileResponse uploadFileResponse = new UploadFileResponse();
+ public UploadFileResponse upload(final VspDetails vspDetails,
+ final OnboardPackageInfo onboardPackageInfo,
+ final CandidateService candidateService) {
+ final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage();
+ final UploadFileResponse uploadFileResponse = new UploadFileResponse();
uploadFileResponse.setOnboardingType(getHandlerType());
- if (isNotEmptyFileToUpload(fileSuffix, fileToUpload, uploadFileResponse, candidateService)) {
+ if (isFileFileToUploadEmpty(onboardPackage, uploadFileResponse, candidateService)) {
return uploadFileResponse;
}
- byte[] uploadedFileData = FileUtils.toByteArray(fileToUpload);
- if (isInvalidRawZipData(fileSuffix, uploadFileResponse, uploadedFileData, candidateService)) {
+ final byte[] fileContentByteArray = onboardPackage.getFileContent().array();
+ if (isInvalidRawZipData(onboardPackage.getFileExtension(),
+ uploadFileResponse, fileContentByteArray, candidateService)) {
return uploadFileResponse;
}
- Optional<FileContentHandler> optionalContentMap =
- getFileContentMap(uploadFileResponse, uploadedFileData);
+ final Optional<FileContentHandler> optionalContentMap =
+ getFileContentMap(uploadFileResponse, fileContentByteArray);
if (!optionalContentMap.isPresent()) {
logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(),
getHandlerType().toString()));
@@ -71,27 +73,27 @@ public abstract class BaseOrchestrationTemplateHandler implements OrchestrationT
if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) {
return uploadFileResponse;
}
- if (updateCandidateData(vspDetails, uploadedFileData, optionalContentMap.get(), fileSuffix,
- networkPackageName, candidateService, uploadFileResponse)) {
+ if (updateCandidateData(vspDetails, onboardPackageInfo, candidateService, uploadFileResponse,
+ optionalContentMap.get())) {
return uploadFileResponse;
}
return uploadFileResponse;
}
- protected abstract boolean updateCandidateData(VspDetails vspDetails,
- byte[] uploadedFileData,
- FileContentHandler contentMap,
- String fileSuffix,
- String networkPackageName,
- CandidateService candidateService,
- UploadFileResponse uploadFileResponse);
+ protected abstract boolean updateCandidateData(final VspDetails vspDetails,
+ final OnboardPackageInfo onboardPackageInfo,
+ final CandidateService candidateService,
+ final UploadFileResponse uploadFileResponse,
+ final FileContentHandler contentMap);
- private boolean isNotEmptyFileToUpload(String fileSuffix, InputStream fileToUpload,
- UploadFileResponse uploadFileResponse,
- CandidateService candidateService) {
+ private boolean isFileFileToUploadEmpty(final OnboardPackage onboardPackage,
+ final UploadFileResponse uploadFileResponse,
+ final CandidateService candidateService) {
+ final ByteArrayInputStream fileToUpload = new ByteArrayInputStream(
+ onboardPackage.getFileContent().array());
Optional<ErrorMessage> errorMessage =
- candidateService.validateNonEmptyFileToUpload(fileToUpload, fileSuffix);
+ candidateService.validateNonEmptyFileToUpload(fileToUpload, onboardPackage.getFileExtension());
if (errorMessage.isPresent()) {
uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get());
return true;
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
index 669efa6dc5..61d1799aa0 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
@@ -20,6 +20,11 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
@@ -34,19 +39,13 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.Validator;
import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.ValidatorFactory;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.List;
-import java.util.Optional;
-
-import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-
public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler
implements OrchestrationTemplateFileHandler {
-
@Override
public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse,
byte[] uploadedFileData) {
@@ -74,16 +73,20 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH
}
@Override
- protected boolean updateCandidateData(VspDetails vspDetails, byte[] uploadedFileData,
- FileContentHandler contentMap,
- String fileSuffix, String networkPackageName,
- CandidateService candidateService,
- UploadFileResponse uploadFileResponse) {
+ protected boolean updateCandidateData(final VspDetails vspDetails,
+ final OnboardPackageInfo onboardPackageInfo,
+ final CandidateService candidateService,
+ final UploadFileResponse uploadFileResponse,
+ final FileContentHandler contentMap) {
try {
+ final OnboardPackage csarPackage = onboardPackageInfo.getOnboardPackage();
+ final OnboardPackage originalOnboardPackage = onboardPackageInfo.getOriginalOnboardPackage();
candidateService.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(),
- new OrchestrationTemplateCandidateData(ByteBuffer.wrap(uploadedFileData), "", fileSuffix,
- networkPackageName));
- } catch (Exception exception) {
+ new OrchestrationTemplateCandidateData(csarPackage.getFileContent(),
+ "", csarPackage.getFileExtension(),
+ csarPackage.getFilename(), originalOnboardPackage.getFilename(), originalOnboardPackage.getFileExtension(),
+ originalOnboardPackage.getFileContent()));
+ } catch (final Exception exception) {
logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(),
getHandlerType().toString()), exception);
uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE,
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java
index 953d88bc4d..2d2f1ae92b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java
@@ -18,14 +18,13 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
-import java.io.InputStream;
-
@FunctionalInterface
public interface OrchestrationTemplateFileHandler {
- UploadFileResponse upload(VspDetails vspDetails, InputStream fileToUpload,
- String fileSuffix, String networkPackageName,
- CandidateService candidateService);
+ UploadFileResponse upload(final VspDetails vspDetails,
+ final OnboardPackageInfo onboardPackageInfo,
+ final CandidateService candidateService);
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java
index 7e323928e1..bc4fb668b0 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java
@@ -20,6 +20,9 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+
+import java.util.Optional;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.common.errors.Messages;
@@ -30,12 +33,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCan
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
-import java.util.Optional;
-
-import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-
public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler
implements OrchestrationTemplateFileHandler {
@@ -47,22 +48,22 @@ public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHa
}
@Override
- protected boolean updateCandidateData(VspDetails vspDetails, byte[] uploadedFileData,
- FileContentHandler contentMap,
- String fileSuffix, String networkPackageName,
- CandidateService candidateService,
- UploadFileResponse uploadFileResponse) {
+ protected boolean updateCandidateData(final VspDetails vspDetails,
+ final OnboardPackageInfo onboardPackageInfo,
+ final CandidateService candidateService,
+ final UploadFileResponse uploadFileResponse,
+ final FileContentHandler contentMap) {
try {
- OrchestrationTemplateCandidateData candidateData =
+ final OnboardPackage zipPackage = onboardPackageInfo.getOnboardPackage();
+ final OrchestrationTemplateCandidateData candidateData =
new CandidateEntityBuilder(candidateService)
- .buildCandidateEntityFromZip(vspDetails, uploadedFileData, contentMap,
+ .buildCandidateEntityFromZip(vspDetails, zipPackage.getFileContent().array(), contentMap,
uploadFileResponse.getErrors());
- candidateData.setFileSuffix(fileSuffix);
- candidateData.setFileName(networkPackageName);
-
+ candidateData.setFileName(zipPackage.getFilename());
+ candidateData.setFileSuffix(zipPackage.getFileExtension());
candidateService
.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData);
- } catch (Exception exception) {
+ } catch (final Exception exception) {
logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(),
getHandlerType().toString()), exception);
uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE,
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
index a86ce33e47..875d6f2953 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
@@ -16,6 +16,14 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.impl.AbstractToscaSolConverter;
import org.openecomp.core.impl.ToscaConverterImpl;
@@ -47,15 +55,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImp
import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class);
@@ -133,8 +132,13 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem
ETSIService etsiService = new ETSIServiceImpl();
ToscaServiceModel toscaServiceModel;
if (etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) {
- fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getFileName() +
- EXT_SEPARATOR + candidateData.getFileSuffix(), candidateData.getContentData().array());
+ if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(candidateData.getFileSuffix())) {
+ fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getOriginalFileName() +
+ EXT_SEPARATOR + candidateData.getOriginalFileSuffix(), candidateData.getOriginalFileContentData().array());
+ } else {
+ fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getFileName() +
+ EXT_SEPARATOR + candidateData.getFileSuffix(), candidateData.getContentData().array());
+ }
final ResourceTypeEnum resourceType = etsiService.getResourceType(fileContentHandler);
toscaServiceModel = instantiateToscaConverterFor(resourceType).convert(fileContentHandler);
} else {
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java
new file mode 100644
index 0000000000..b8ef598d65
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java
@@ -0,0 +1,38 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.types;
+
+import java.nio.ByteBuffer;
+import lombok.Getter;
+
+@Getter
+public class OnboardPackage {
+
+ private final String filename;
+ private final String fileExtension;
+ private final ByteBuffer fileContent;
+
+ public OnboardPackage(final String filename, final String fileExtension, final ByteBuffer fileContent) {
+ this.filename = filename;
+ this.fileExtension = fileExtension;
+ this.fileContent = fileContent;
+ }
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackageInfo.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackageInfo.java
new file mode 100644
index 0000000000..308db035db
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackageInfo.java
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.types;
+
+import java.nio.ByteBuffer;
+import lombok.Getter;
+
+@Getter
+public class OnboardPackageInfo {
+
+ private final OnboardPackage originalOnboardPackage;
+ private final OnboardPackage onboardPackage;
+
+ public OnboardPackageInfo(final String filename,
+ final String fileExtension,
+ final ByteBuffer fileContent,
+ final OnboardPackage onboardPackage) {
+ originalOnboardPackage = new OnboardPackage(filename, fileExtension, fileContent);
+ this.onboardPackage = onboardPackage;
+ }
+
+ public OnboardPackageInfo(final String filename,
+ final String fileExtension,
+ final ByteBuffer fileContent) {
+ originalOnboardPackage = new OnboardPackage(filename, fileExtension, fileContent);
+ this.onboardPackage = originalOnboardPackage;
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java
index ee4b2fa26c..b922da9b46 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java
@@ -21,62 +21,50 @@
package org.openecomp.sdc.vendorsoftwareproduct;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.Objects;
import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Before;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.openecomp.core.model.dao.ServiceModelDao;
-import org.openecomp.core.model.types.ServiceElement;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.core.validation.util.MessageContainerUtil;
-import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
-import org.openecomp.sdc.healing.api.HealingManager;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData;
import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService;
-import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
-import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Objects;
-
public class QuestionnaireDataServiceTest {
+ private static final Logger LOGGER = LoggerFactory.getLogger(QuestionnaireDataServiceTest.class);
+
public static final Version VERSION = new Version(0, 1);
private QuestionnaireDataService questionnaireDataService;// = new QuestionnaireDataServiceImpl();
- @Mock
- private CandidateService candidateServiceMock;
- @Mock
- private HealingManager healingManagerMock;
- @Mock
- private CompositionDataExtractor compositionDataExtractorMock;
- @Mock
- private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
- @Mock
- private CompositionEntityDataManager compositionEntityDataManagerMock;
-
- @Captor
- private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
-
@InjectMocks
private OrchestrationTemplateCandidateManagerImpl candidateManager;
private UploadFileTest uploadFileTest = new UploadFileTest();
+ private OnboardPackageInfo onboardPackageInfo;
private static String vspId;
private static Version vspActiveVersion;
private static final String USER1 = "vspTestUser1";
+ private static final VspDetails vspDetails = new VspDetails(vspId, VERSION);
+ private static final String CSAR = "csar";
+ private static final String ZIP = "zip";
@Before
public void setUp() throws Exception {
@@ -101,38 +89,39 @@ public class QuestionnaireDataServiceTest {
// TODO: 3/15/2017 fix and enable //@Test
public void testQuestionnaireDataAfterIllegalUpload() throws IOException {
try (InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml")) {
+ onboardPackageInfo = new OnboardPackageInfo("missingYml", CSAR, convertFileInputStream(zipInputStream));
UploadFileResponse uploadFileResponse =
- candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "missingYml");
+ candidateManager.upload(vspDetails, onboardPackageInfo);
}
InformationArtifactData informationArtifactData = questionnaireDataService
.generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
}
- private InformationArtifactData uploadFileAndValidateInformationArtifactData(String filePath,
- int listSizeToCheck)
- throws IOException {
+ private InformationArtifactData uploadFileAndValidateInformationArtifactData(final String filePath,
+ final int listSizeToCheck)
+ throws IOException {
- try (InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) {
- UploadFileResponse uploadFileResponse =
- candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "file");
+ try (final InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) {
+ onboardPackageInfo = new OnboardPackageInfo("file", OnboardingTypesEnum.CSAR.toString(),
+ convertFileInputStream(zipInputStream));
+ final UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo);
candidateManager.process(vspId, VERSION);
Assert.assertTrue(MapUtils.isEmpty(
MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
}
- InformationArtifactData informationArtifactData = questionnaireDataService
+ final InformationArtifactData informationArtifactData = questionnaireDataService
.generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion);
Assert.assertNotNull(informationArtifactData);
- List<ComponentQuestionnaire> componentQuestionnaireList =
+ final List<ComponentQuestionnaire> componentQuestionnaireList =
informationArtifactData.getComponentQuestionnaires();
Assert.assertEquals(componentQuestionnaireList.size(), listSizeToCheck);
return informationArtifactData;
}
-
private void assertQuestionnaireValuesAreAsExpected(
InformationArtifactData informationArtifactData, boolean condition) {
Assert.assertEquals(
@@ -143,4 +132,14 @@ public class QuestionnaireDataServiceTest {
condition);
}
+ private ByteBuffer convertFileInputStream(final InputStream fileInputStream) {
+ byte[] fileContent = new byte[0];
+ try {
+ fileContent = IOUtils.toByteArray(fileInputStream);
+ } catch (final IOException e) {
+ LOGGER.error(String.format("Could not convert %s into byte[]", fileInputStream), e);
+ }
+ return ByteBuffer.wrap(fileContent);
+ }
+
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java
index c21358519a..8081184f68 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java
@@ -31,8 +31,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.nio.ByteBuffer;
import java.util.zip.ZipOutputStream;
-
+import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -43,6 +44,8 @@ import org.openecomp.core.model.dao.ServiceModelDao;
import org.openecomp.core.model.types.ServiceElement;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.healing.api.HealingManager;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
@@ -52,11 +55,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor;
import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon;
import org.openecomp.sdc.versioning.dao.types.Version;
public class UploadFileTest {
+ private static final Logger LOGGER = LoggerFactory.getLogger(UploadFileTest.class);
+
private static final String USER1 = "vspTestUser1";
public static final Version VERSION01 = new Version(0, 1);
@@ -76,15 +82,15 @@ public class UploadFileTest {
@Mock
private VendorSoftwareProductInfoDao vspInfoDaoMock;
+ private OnboardPackageInfo onboardPackageInfo;
+
@InjectMocks
private OrchestrationTemplateCandidateManagerImpl candidateManager;
- private static String vlm1Id;
- public static String id001 = null;
- public static String id002 = null;
-
- public static Version activeVersion002 = null;
+ public static String id001 = "dummyId";
+ public static Version activeVersion002 = new Version(1, 0);
+ private final VspDetails vspDetails = new VspDetails(id001, activeVersion002);
@Before
public void setUp() throws Exception {
@@ -92,17 +98,20 @@ public class UploadFileTest {
}
@Test
- public void testUploadFile() {
- VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0));
+ public void testUploadFile() throws IOException {
doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
- candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"),
- OnboardingTypesEnum.ZIP.toString(), "legalUpload");
- }
+ try (final InputStream inputStream = getZipInputStream("/legalUpload")) {
+ onboardPackageInfo = new OnboardPackageInfo("legalUpload", OnboardingTypesEnum.ZIP.toString(),
+ convertFileInputStream(inputStream));
+ candidateManager.upload(vspDetails, onboardPackageInfo);
+ }
+ }
private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
- UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002,
- upload, OnboardingTypesEnum.ZIP.toString(), "file");
+ onboardPackageInfo = new OnboardPackageInfo("file", OnboardingTypesEnum.ZIP.toString(),
+ convertFileInputStream(upload));
+ final UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo);
assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP);
OrchestrationTemplateEntity uploadData = orchestrationTemplateDataDaoMock.get(vspId, version);
@@ -121,5 +130,14 @@ public class UploadFileTest {
return new ByteArrayInputStream(baos.toByteArray());
}
+ private ByteBuffer convertFileInputStream(final InputStream fileInputStream) {
+ byte[] fileContent = new byte[0];
+ try {
+ fileContent = IOUtils.toByteArray(fileInputStream);
+ } catch (final IOException e) {
+ LOGGER.error(String.format("Could not convert %s into byte[]", fileInputStream), e);
+ }
+ return ByteBuffer.wrap(fileContent);
+ }
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java
index b772c69f4a..77e519c502 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java
@@ -22,33 +22,37 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteBuffer;
import java.util.List;
import java.util.function.Predicate;
-
+import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl;
import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl;
import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl;
+import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import org.openecomp.sdc.versioning.dao.types.Version;
public class UploadCSARFileTest {
- public static final Version VERSION01 = new Version("0.1");
+ private static final Logger LOGGER = LoggerFactory.getLogger(UploadCSARFileTest.class);
@Spy
private CandidateServiceImpl candidateService;
@@ -62,11 +66,12 @@ public class UploadCSARFileTest {
@InjectMocks
private OrchestrationTemplateCandidateManagerImpl candidateManager;
+ private OnboardPackageInfo onboardPackageInfo;
+ private final VspDetails vspDetails = new VspDetails(id001, activeVersion002);
private static String id001 = "dummyId";
private static Version activeVersion002 = new Version("dummyVersion");
private static final String BASE_DIR = "/vspmanager.csar";
- private static final String CSAR = "csar";
@Before
@@ -79,7 +84,6 @@ public class UploadCSARFileTest {
@Test
public void testSuccessfulUploadFile() throws Exception {
- VspDetails vspDetails = new VspDetails(id001, activeVersion002);
doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
testCsarUpload("successfulUpload.csar", 0);
@@ -87,7 +91,6 @@ public class UploadCSARFileTest {
@Test
public void testIllegalUploadInvalidFileInRoot() throws Exception {
- VspDetails vspDetails = new VspDetails(id001, activeVersion002);
doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
UploadFileResponse response = testCsarUpload("invalidFileInRoot.csar", 1);
@@ -97,7 +100,6 @@ public class UploadCSARFileTest {
@Test
public void testIllegalUploadMissingMainServiceTemplate() throws Exception {
- VspDetails vspDetails = new VspDetails(id001, activeVersion002);
doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
UploadFileResponse response = testCsarUpload("missingMainServiceTemplate.csar", 1);
@@ -107,7 +109,6 @@ public class UploadCSARFileTest {
@Test
public void testUploadFileIsNotZip() throws Exception {
- VspDetails vspDetails = new VspDetails(id001, activeVersion002);
doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
UploadFileResponse response = testCsarUpload("notCsar.txt", 1);
@@ -117,26 +118,24 @@ public class UploadCSARFileTest {
@Test
public void testUploadFileIsEmpty() throws Exception {
- VspDetails vspDetails = new VspDetails(id001, activeVersion002);
doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
-
- try (InputStream is = new ByteArrayInputStream(new byte[]{})) {
- UploadFileResponse uploadFileResponse = candidateManager.upload(id001,
- activeVersion002, is, "csar", "file");
- assertEquals(1, uploadFileResponse.getErrors().size());
- }
+ onboardPackageInfo = new OnboardPackageInfo("file", OnboardingTypesEnum.CSAR.toString(),
+ ByteBuffer.wrap(new byte[]{}));
+ UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo);
+ assertEquals(1, uploadFileResponse.getErrors().size());
}
@Test
public void testInvalidManifestContent() throws Exception {
- VspDetails vspDetails = new VspDetails(id001, activeVersion002);
- doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
+ doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class));
- try (InputStream is = getClass()
+ try (InputStream inputStream = getClass()
.getResourceAsStream(BASE_DIR + "/invalidManifestContent.csar")) {
+ onboardPackageInfo = new OnboardPackageInfo("invalidManifestContent",
+ OnboardingTypesEnum.CSAR.toString(), convertFileInputStream(inputStream));
UploadFileResponse response =
- candidateManager.upload(id001, activeVersion002, is, "csar", "invalidManifestContent");
+ candidateManager.upload(vspDetails, onboardPackageInfo);
assertEquals(1, response.getErrors().size());
assertEquals(response.getErrors().values().iterator().next().get(0).getMessage(),
"Manifest " +
@@ -153,17 +152,27 @@ public class UploadCSARFileTest {
return error.iterator().next().getMessage().contains(substring);
}
- private UploadFileResponse testCsarUpload(String csarFileName, int expectedErrorsNumber)
- throws IOException {
+ private UploadFileResponse testCsarUpload(final String csarFileName,
+ final int expectedErrorsNumber) throws IOException {
UploadFileResponse uploadFileResponse;
- try (InputStream is = getClass()
+ try (final InputStream inputStream = getClass()
.getResourceAsStream(BASE_DIR + File.separator + csarFileName)) {
- uploadFileResponse =
- candidateManager.upload(id001, activeVersion002, is, CSAR, csarFileName);
+ onboardPackageInfo = new OnboardPackageInfo(csarFileName, OnboardingTypesEnum.CSAR.toString(),
+ convertFileInputStream(inputStream));
+ uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo);
assertEquals(expectedErrorsNumber, uploadFileResponse.getErrors().size());
}
return uploadFileResponse;
}
+ private ByteBuffer convertFileInputStream(final InputStream fileInputStream) {
+ byte[] fileContent = new byte[0];
+ try {
+ fileContent = IOUtils.toByteArray(fileInputStream);
+ } catch (final IOException e) {
+ LOGGER.error(String.format("Could not convert %s into byte[]", fileInputStream), e);
+ }
+ return ByteBuffer.wrap(fileContent);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java b/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java
index 1eb688b057..d1ddc5c48d 100644
--- a/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java
+++ b/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/model/ElementType.java
@@ -31,7 +31,7 @@ public enum ElementType {
VspModel, NetworkPackage,
OrchestrationTemplateCandidate, OrchestrationTemplateCandidateContent,
- OrchestrationTemplateCandidateValidationData,
+ OrchestrationTemplateCandidateValidationData, ORIGINAL_ONBOARDED_PACKAGE,
OrchestrationTemplateStructure, OrchestrationTemplate,
OrchestrationTemplateValidationData,
// todo - remove OrchestrationTemplateContent
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java
index 398d84c8e5..57e8405138 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/type/OrchestrationTemplateCandidateData.java
@@ -27,16 +27,26 @@ public class OrchestrationTemplateCandidateData {
private String fileSuffix;
private String fileName;
private String validationData;
+ private ByteBuffer originalFileContentData;
+ private String originalFileName;
+ private String originalFileSuffix;
public OrchestrationTemplateCandidateData() {
}
- public OrchestrationTemplateCandidateData(ByteBuffer contentData, String dataStructureJson,
- String fileSuffix, String fileName) {
+ public OrchestrationTemplateCandidateData(final ByteBuffer contentData,
+ final String dataStructureJson,
+ final String fileSuffix, final String fileName,
+ final String originalFileName,
+ final String originalFileSuffix,
+ final ByteBuffer originalFileContentData) {
this.contentData = contentData;
this.filesDataStructure = dataStructureJson;
this.fileSuffix = fileSuffix;
this.fileName = fileName;
+ this.originalFileName = originalFileName;
+ this.originalFileSuffix = originalFileSuffix;
+ this.originalFileContentData = originalFileContentData;
}
public ByteBuffer getContentData() {
@@ -88,4 +98,28 @@ public class OrchestrationTemplateCandidateData {
this.validationData = validationData == null ? null
: JsonUtil.object2Json(validationData);
}
+
+ public ByteBuffer getOriginalFileContentData() {
+ return originalFileContentData;
+ }
+
+ public void setOriginalFileContentData(ByteBuffer originalFileContentData) {
+ this.originalFileContentData = originalFileContentData;
+ }
+
+ public String getOriginalFileName() {
+ return originalFileName;
+ }
+
+ public void setOriginalFileName(String originalFileName) {
+ this.originalFileName = originalFileName;
+ }
+
+ public String getOriginalFileSuffix() {
+ return originalFileSuffix;
+ }
+
+ public void setOriginalFileSuffix(String originalFileSuffix) {
+ this.originalFileSuffix = originalFileSuffix;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java
index c3dbab55f6..4c1e2e1ef2 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/OrchestrationTemplateCandidateDaoZusammenImpl.java
@@ -16,6 +16,9 @@
package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
+import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+
import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
@@ -23,7 +26,11 @@ import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.utils.fileutils.FileUtils;
+import java.io.ByteArrayInputStream;
+import java.nio.ByteBuffer;
+import java.util.Optional;
import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.sdc.datatypes.model.ElementType;
import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList;
@@ -34,13 +41,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCan
import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.io.ByteArrayInputStream;
-import java.nio.ByteBuffer;
-import java.util.Optional;
-
-import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement;
-import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
-
public class OrchestrationTemplateCandidateDaoZusammenImpl
implements OrchestrationTemplateCandidateDao {
@@ -118,26 +118,30 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
return candidate.getFileSuffix() == null ? Optional.empty() : Optional.of(candidate);
}
- private void populateCandidate(OrchestrationTemplateCandidateData candidate,
- Element candidateInfoElement,
- boolean fullData) {
- if (candidateInfoElement.getInfo().getName()
- .equals(ElementType.OrchestrationTemplateCandidateContent.name())) {
-
+ private void populateCandidate(final OrchestrationTemplateCandidateData candidate,
+ final Element candidateInfoElement,
+ final boolean fullData) {
+ final String elementName = candidateInfoElement.getInfo().getName();
+ if (ElementType.OrchestrationTemplateCandidateContent.name().equals(elementName)) {
if (fullData) {
- candidate
- .setContentData(ByteBuffer.wrap(FileUtils.toByteArray(candidateInfoElement.getData())));
+ candidate.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(candidateInfoElement.getData())));
+ }
+ candidate.setFileSuffix(candidateInfoElement.getInfo()
+ .getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
+ candidate.setFileName(candidateInfoElement.getInfo()
+ .getProperty(InfoPropertyName.FILE_NAME.getVal()));
+ } else if (ElementType.OrchestrationTemplateCandidateValidationData.name().equals(elementName)) {
+ candidate.setValidationData(new String(FileUtils.toByteArray(candidateInfoElement.getData())));
+ } else if (ElementType.ORIGINAL_ONBOARDED_PACKAGE.name().equals(elementName)) {
+ candidate.setOriginalFileName(candidateInfoElement.getInfo()
+ .getProperty(InfoPropertyName.ORIGINAL_FILE_NAME.getVal()));
+ candidate.setOriginalFileSuffix(candidateInfoElement.getInfo()
+ .getProperty(InfoPropertyName.ORIGINAL_FILE_SUFFIX.getVal()));
+ if (fullData) {
+ candidate.setOriginalFileContentData(
+ ByteBuffer.wrap(FileUtils.toByteArray(candidateInfoElement.getData()))
+ );
}
- candidate.setFileSuffix(
- candidateInfoElement.getInfo().getProperty(InfoPropertyName.FILE_SUFFIX.getVal()));
- candidate.setFileName(
- candidateInfoElement.getInfo().getProperty(InfoPropertyName.FILE_NAME.getVal()));
-
- } else if (candidateInfoElement.getInfo().getName()
- .equals(ElementType.OrchestrationTemplateCandidateValidationData.name())) {
-
- candidate
- .setValidationData(new String(FileUtils.toByteArray(candidateInfoElement.getData())));
}
}
@@ -166,16 +170,15 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
}
@Override
- public void update(String vspId, Version version,
- OrchestrationTemplateCandidateData candidateData) {
+ public void update(final String vspId, final Version version,
+ final OrchestrationTemplateCandidateData candidateData) {
logger.info("Uploading candidate data entity for vsp id {}", vspId);
-
- ZusammenElement candidateElement =
+ final ZusammenElement candidateElement =
buildStructuralElement(ElementType.OrchestrationTemplateCandidate, Action.UPDATE);
candidateElement
.setData(new ByteArrayInputStream(candidateData.getFilesDataStructure().getBytes()));
- ZusammenElement candidateContentElement =
+ final ZusammenElement candidateContentElement =
buildStructuralElement(ElementType.OrchestrationTemplateCandidateContent, Action.UPDATE);
candidateContentElement
.setData(new ByteArrayInputStream(candidateData.getContentData().array()));
@@ -184,14 +187,24 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
candidateContentElement.getInfo()
.addProperty(InfoPropertyName.FILE_NAME.getVal(), candidateData.getFileName());
- ZusammenElement validationData = buildStructuralElement(ElementType
+ if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(candidateData.getFileSuffix())) {
+ final ZusammenElement originalPackageElement =
+ buildStructuralElement(ElementType.ORIGINAL_ONBOARDED_PACKAGE, Action.UPDATE);
+ originalPackageElement.getInfo()
+ .addProperty(InfoPropertyName.ORIGINAL_FILE_NAME.getVal(), candidateData.getOriginalFileName());
+ originalPackageElement.getInfo()
+ .addProperty(InfoPropertyName.ORIGINAL_FILE_SUFFIX.getVal(), candidateData.getOriginalFileSuffix());
+ originalPackageElement.setData(new ByteArrayInputStream(candidateData.getOriginalFileContentData().array()));
+ candidateElement.addSubElement(originalPackageElement);
+ }
+ final ZusammenElement validationData = buildStructuralElement(ElementType
.OrchestrationTemplateCandidateValidationData, Action.UPDATE);
if (candidateData.getValidationData() != null) {
validationData
.setData(new ByteArrayInputStream(candidateData.getValidationData().getBytes()));
}
- candidateElement.addSubElement(candidateContentElement);
candidateElement.addSubElement(validationData);
+ candidateElement.addSubElement(candidateContentElement);
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(vspId, version.getId());
zusammenAdaptor.saveElement(context, elementContext, candidateElement,
@@ -261,7 +274,9 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
public enum InfoPropertyName {
FILE_SUFFIX("fileSuffix"),
- FILE_NAME("fileName");
+ FILE_NAME("fileName"),
+ ORIGINAL_FILE_NAME("originalFilename"),
+ ORIGINAL_FILE_SUFFIX("originalFileSuffix");
private final String val;
@@ -269,7 +284,7 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl
this.val = val;
}
- String getVal() {
+ private String getVal() {
return val;
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
index 93a706c688..3255e186e4 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
@@ -16,6 +16,25 @@
package org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule;
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.json.JsonUtil;
@@ -49,20 +68,6 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-import java.util.stream.Collectors;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
-
-import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-
public class CandidateServiceImpl implements CandidateService {
private static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class);
private CandidateServiceValidator candidateServiceValidator = new CandidateServiceValidator();
@@ -300,8 +305,8 @@ public class CandidateServiceImpl implements CandidateService {
}
@Override
- public void updateCandidateUploadData(String vspId, Version version,
- OrchestrationTemplateCandidateData uploadData) {
+ public void updateCandidateUploadData(final String vspId, final Version version,
+ final OrchestrationTemplateCandidateData uploadData) {
orchestrationTemplateCandidateDao.update(vspId, version, uploadData);
}