aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-07-08 18:54:19 +0100
committerMichael Morris <michael.morris@est.tech>2021-07-21 14:01:01 +0000
commit8278b79c92f5149813f0161670a0eb76c33db322 (patch)
treec70bc2078111faa5cc5e29c071598ed1e11a5898 /openecomp-be/api/openecomp-sdc-rest-webapp
parent5cb26d5eb1ab5d04319624f1ffb49f7f26d55315 (diff)
Support handling of 'Large CSARs'
If artifact storage is enabled, stores original onboarded package, leaving a reference in the VSP, instead of the original onboarded package itself. Strips files from configured folders in order to reduce the package size and onboard it. To retrieve the package, one needs to read the reference and go to the artifact storage to retrieve. If disabled, it just goes through the current onboarding process. Change-Id: I3dce0ab8422ea736c8a1ffaeb1136cf8b12a2af4 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Signed-off-by: André Schmid <andre.schmid@est.tech> Issue-ID: SDC-3635
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp')
-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/OrchestrationTemplateCandidateException.java6
-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.java119
-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.java173
3 files changed, 193 insertions, 105 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/OrchestrationTemplateCandidateException.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/OrchestrationTemplateCandidateException.java
index 1e20d1ced7..abe227c745 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/OrchestrationTemplateCandidateException.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/OrchestrationTemplateCandidateException.java
@@ -19,9 +19,9 @@
*/
package org.openecomp.sdcrests.vsp.rest.services;
-public class OrchestrationTemplateCandidateException extends Exception {
+public class OrchestrationTemplateCandidateException extends RuntimeException {
- public OrchestrationTemplateCandidateException(String message, Throwable t) {
- super(message, t);
+ public OrchestrationTemplateCandidateException(final String message) {
+ super(message);
}
}
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 cd18cf973b..10f6012a76 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
@@ -16,30 +16,52 @@
* limitations under the License.
* ============LICENSE_END=========================================================
* Modifications copyright (c) 2019 Nokia
+ * Modifications copyright (c) 2021 Nordix Foundation
* ================================================================================
*/
package org.openecomp.sdcrests.vsp.rest.services;
+import static javax.ws.rs.core.Response.Status.EXPECTATION_FAILED;
+import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
+import static javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+import static org.openecomp.sdc.common.errors.Messages.ERROR_HAS_OCCURRED_WHILE_PERSISTING_THE_ARTIFACT;
+import static org.openecomp.sdc.common.errors.Messages.ERROR_HAS_OCCURRED_WHILE_REDUCING_THE_ARTIFACT_SIZE;
+import static org.openecomp.sdc.common.errors.Messages.EXTERNAL_CSAR_STORE_CONFIGURATION_FAILURE_MISSING_FULL_PATH;
+import static org.openecomp.sdc.common.errors.Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST;
+import static org.openecomp.sdc.common.errors.Messages.PACKAGE_PROCESS_ERROR;
+import static org.openecomp.sdc.common.errors.Messages.UNEXPECTED_PROBLEM_HAPPENED_WHILE_GETTING;
import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import javax.activation.DataHandler;
+import java.util.Set;
+import java.util.stream.Collectors;
import javax.inject.Named;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.openecomp.sdc.activitylog.ActivityLogManager;
import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
import org.openecomp.sdc.activitylog.dao.type.ActivityType;
-import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.be.csar.storage.ArtifactInfo;
+import org.openecomp.sdc.be.csar.storage.ArtifactStorageConfig;
+import org.openecomp.sdc.be.csar.storage.ArtifactStorageManager;
+import org.openecomp.sdc.be.csar.storage.CsarPackageReducerConfiguration;
+import org.openecomp.sdc.be.csar.storage.CsarSizeReducer;
+import org.openecomp.sdc.be.csar.storage.PackageSizeReducer;
+import org.openecomp.sdc.be.csar.storage.PersistentVolumeArtifactStorageConfig;
+import org.openecomp.sdc.be.csar.storage.PersistentVolumeArtifactStorageManager;
+import org.openecomp.sdc.be.exception.BusinessException;
+import org.openecomp.sdc.common.CommonConfigurationManager;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
@@ -76,49 +98,100 @@ import org.springframework.stereotype.Service;
public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplateCandidate {
private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateCandidateImpl.class);
+ private static final String EXTERNAL_CSAR_STORE = "externalCsarStore";
private final OrchestrationTemplateCandidateManager candidateManager;
private final VendorSoftwareProductManager vendorSoftwareProductManager;
private final ActivityLogManager activityLogManager;
+ private final ArtifactStorageManager artifactStorageManager;
+ private final PackageSizeReducer packageSizeReducer;
public OrchestrationTemplateCandidateImpl() {
this.candidateManager = OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface();
this.vendorSoftwareProductManager = VspManagerFactory.getInstance().createInterface();
this.activityLogManager = ActivityLogManagerFactory.getInstance().createInterface();
+ LOGGER.info("Instantiating artifactStorageManager");
+ this.artifactStorageManager = new PersistentVolumeArtifactStorageManager(readArtifactStorageConfiguration());
+ LOGGER.info("Instantiating packageSizeReducer");
+ this.packageSizeReducer = new CsarSizeReducer(readPackageReducerConfiguration());
}
// Constructor used in test to avoid mock static
- public OrchestrationTemplateCandidateImpl(OrchestrationTemplateCandidateManager candidateManager,
- VendorSoftwareProductManager vendorSoftwareProductManager, ActivityLogManager activityLogManager) {
+ public OrchestrationTemplateCandidateImpl(final OrchestrationTemplateCandidateManager candidateManager,
+ final VendorSoftwareProductManager vendorSoftwareProductManager,
+ final ActivityLogManager activityLogManager,
+ final ArtifactStorageManager artifactStorageManager,
+ final PackageSizeReducer packageSizeReducer) {
this.candidateManager = candidateManager;
this.vendorSoftwareProductManager = vendorSoftwareProductManager;
this.activityLogManager = activityLogManager;
+ this.artifactStorageManager = artifactStorageManager;
+ this.packageSizeReducer = packageSizeReducer;
+ }
+
+ private CsarPackageReducerConfiguration readPackageReducerConfiguration() {
+ final var commonConfigurationManager = CommonConfigurationManager.getInstance();
+ final List<String> foldersToStrip = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "foldersToStrip", new ArrayList<>());
+ final int sizeLimit = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "sizeLimit", 1000000);
+ LOGGER.info("Folders to strip: '{}'", String.join(", ", foldersToStrip));
+ final Set<Path> foldersToStripPathSet = foldersToStrip.stream().map(Path::of).collect(Collectors.toSet());
+ return new CsarPackageReducerConfiguration(foldersToStripPathSet, sizeLimit);
+ }
+
+ private ArtifactStorageConfig readArtifactStorageConfiguration() {
+ final var commonConfigurationManager = CommonConfigurationManager.getInstance();
+ final boolean isEnabled = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "storeCsarsExternally", false);
+ LOGGER.info("ArtifactConfig.isEnabled: '{}'", isEnabled);
+ final String storagePathString = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "fullPath", null);
+ LOGGER.info("ArtifactConfig.storagePath: '{}'", storagePathString);
+ if (isEnabled && storagePathString == null) {
+ throw new OrchestrationTemplateCandidateException(EXTERNAL_CSAR_STORE_CONFIGURATION_FAILURE_MISSING_FULL_PATH.getErrorMessage());
+ }
+ final var storagePath = storagePathString == null ? null : Path.of(storagePathString);
+ return new PersistentVolumeArtifactStorageConfig(isEnabled, storagePath);
}
@Override
public Response upload(final String vspId, final String versionId, final Attachment fileToUpload, final String user) {
- final byte[] fileToUploadBytes = fileToUpload.getObject(byte[].class);
- final DataHandler dataHandler = fileToUpload.getDataHandler();
- final String filename = ValidationUtils.sanitizeInputString(dataHandler.getName());
- final OnboardingPackageProcessor onboardingPackageProcessor =
- new OnboardingPackageProcessor(filename, fileToUploadBytes, new CnfPackageValidator());
+ final byte[] fileToUploadBytes;
+ final var filename = ValidationUtils.sanitizeInputString(fileToUpload.getDataHandler().getName());
+ ArtifactInfo artifactInfo = null;
+ if (artifactStorageManager.isEnabled()) {
+ final InputStream packageInputStream;
+ try {
+ packageInputStream = fileToUpload.getDataHandler().getInputStream();
+ } catch (final IOException e) {
+ return Response.status(INTERNAL_SERVER_ERROR).entity(buildUploadResponseWithError(new ErrorMessage(ErrorLevel.ERROR, UNEXPECTED_PROBLEM_HAPPENED_WHILE_GETTING.formatMessage(filename)))).build();
+ }
+ try {
+ artifactInfo = artifactStorageManager.upload(vspId, versionId, packageInputStream);
+ } catch (final BusinessException e) {
+ return Response.status(INTERNAL_SERVER_ERROR).entity(buildUploadResponseWithError(new ErrorMessage(ErrorLevel.ERROR, ERROR_HAS_OCCURRED_WHILE_PERSISTING_THE_ARTIFACT.formatMessage(filename)))).build();
+ }
+ try {
+ fileToUploadBytes = packageSizeReducer.reduce(artifactInfo.getPath());
+ } catch (final BusinessException e) {
+ return Response.status(INTERNAL_SERVER_ERROR).entity(buildUploadResponseWithError(new ErrorMessage(ErrorLevel.ERROR, ERROR_HAS_OCCURRED_WHILE_REDUCING_THE_ARTIFACT_SIZE.formatMessage(artifactInfo.getPath())))).build();
+ }
+ } else {
+ fileToUploadBytes = fileToUpload.getObject(byte[].class);
+ }
+
+ final var onboardingPackageProcessor = new OnboardingPackageProcessor(filename, fileToUploadBytes, new CnfPackageValidator(), artifactInfo);
final ErrorMessage[] errorMessages = onboardingPackageProcessor.getErrorMessages().toArray(new ErrorMessage[0]);
if (onboardingPackageProcessor.hasErrors()) {
- final UploadFileResponseDto uploadFileResponseDto = buildUploadResponseWithError(
- errorMessages);
- return Response.status(Status.NOT_ACCEPTABLE).entity(uploadFileResponseDto).build();
+ return Response.status(NOT_ACCEPTABLE).entity(buildUploadResponseWithError(errorMessages)).build();
}
- final OnboardPackageInfo onboardPackageInfo = onboardingPackageProcessor.getOnboardPackageInfo().orElse(null);
+ final var onboardPackageInfo = onboardingPackageProcessor.getOnboardPackageInfo().orElse(null);
if (onboardPackageInfo == null) {
- final UploadFileResponseDto uploadFileResponseDto = buildUploadResponseWithError(
- new ErrorMessage(ErrorLevel.ERROR, Messages.PACKAGE_PROCESS_ERROR.formatMessage(filename)));
- return Response.ok(uploadFileResponseDto).build();
+ return Response.ok(buildUploadResponseWithError(new ErrorMessage(ErrorLevel.ERROR, PACKAGE_PROCESS_ERROR.formatMessage(filename)))).build();
}
- final VspDetails vspDetails = new VspDetails(ValidationUtils.sanitizeInputString(vspId),
+ final var vspDetails = new VspDetails(ValidationUtils.sanitizeInputString(vspId),
new Version(ValidationUtils.sanitizeInputString(versionId)));
return processOnboardPackage(onboardPackageInfo, vspDetails, errorMessages);
}
- private Response processOnboardPackage(final OnboardPackageInfo onboardPackageInfo, final VspDetails vspDetails, final ErrorMessage... errorMessages) {
+ private Response processOnboardPackage(final OnboardPackageInfo onboardPackageInfo, final VspDetails vspDetails,
+ final ErrorMessage... errorMessages) {
final UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo);
final UploadFileResponseDto uploadFileResponseDto = new MapUploadFileResponseToUploadFileResponseDto()
.applyMapping(uploadFileResponse, UploadFileResponseDto.class);
@@ -151,10 +224,9 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
} else {
zipFile = vendorSoftwareProductManager.get(vspId, new Version((versionId)));
if (!zipFile.isPresent()) {
- ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR,
- getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), ""));
+ ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), ""));
LOGGER.error(errorMessage.getMessage());
- return Response.status(Response.Status.NOT_FOUND).build();
+ return Response.status(NOT_FOUND).build();
}
fileName = "Processed." + zipFile.get().getLeft();
}
@@ -183,8 +255,7 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
FilesDataStructure fileDataStructure = copyFilesDataStructureDtoToFilesDataStructure(fileDataStructureDto);
ValidationResponse response = candidateManager.updateFilesDataStructure(vspId, new Version(versionId), fileDataStructure);
if (!response.isValid()) {
- return Response.status(Response.Status.EXPECTATION_FAILED)
- .entity(new MapValidationResponseToDto().applyMapping(response, ValidationResponseDto.class)).build();
+ return Response.status(EXPECTATION_FAILED).entity(new MapValidationResponseToDto().applyMapping(response, ValidationResponseDto.class)).build();
}
return Response.ok(fileDataStructureDto).build();
}
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 41891dea74..b89756e501 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
@@ -7,9 +7,9 @@
* 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.
@@ -20,15 +20,21 @@
package org.openecomp.sdcrests.vsp.rest.services;
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.MockitoAnnotations.initMocks;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
@@ -40,14 +46,17 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.activitylog.ActivityLogManager;
+import org.openecomp.sdc.be.csar.storage.ArtifactStorageManager;
+import org.openecomp.sdc.be.csar.storage.PackageSizeReducer;
+import org.openecomp.sdc.be.csar.storage.PersistentStorageArtifactInfo;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
@@ -62,17 +71,20 @@ import org.openecomp.sdcrests.vendorsoftwareproducts.types.FileDataStructureDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.OrchestrationTemplateActionResponseDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.UploadFileResponseDto;
-public class OrchestrationTemplateCandidateImplTest {
+class OrchestrationTemplateCandidateImplTest {
- private Logger logger = LoggerFactory.getLogger(OrchestrationTemplateCandidateImplTest.class);
+ private final Logger logger = LoggerFactory.getLogger(OrchestrationTemplateCandidateImplTest.class);
@Mock
private OrchestrationTemplateCandidateManager candidateManager;
@Mock
private VendorSoftwareProductManager vendorSoftwareProductManager;
-
@Mock
private ActivityLogManager activityLogManager;
+ @Mock
+ private ArtifactStorageManager artifactStorageManager;
+ @Mock
+ private PackageSizeReducer packageSizeReducer;
private OrchestrationTemplateCandidateImpl orchestrationTemplateCandidate;
@@ -82,64 +94,59 @@ public class OrchestrationTemplateCandidateImplTest {
private final String user = "cs0008";
- @Before
- public void setUp(){
+ @BeforeEach
+ public void setUp() {
try {
- initMocks(this);
+ MockitoAnnotations.openMocks(this);
UploadFileResponse uploadFileResponse = new UploadFileResponse();
uploadFileResponse.setOnboardingType(OnboardingTypesEnum.ZIP);
uploadFileResponse.setNetworkPackageName("test");
when(candidateManager.upload(any(), any())).thenReturn(uploadFileResponse);
-
// get using the candidate manager.
- Optional<Pair<String,byte[]>> zipFile =
- Optional.of(Pair.of("Hello", "World".getBytes()));
+ Optional<Pair<String, byte[]>> zipFile = Optional.of(Pair.of("Hello", "World".getBytes()));
when(candidateManager.get(
- ArgumentMatchers.eq(candidateId),
- ArgumentMatchers.any())).thenReturn(zipFile);
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(zipFile);
when(vendorSoftwareProductManager.get(
- ArgumentMatchers.eq(softwareProductId),
- ArgumentMatchers.any())).thenReturn(zipFile);
-
+ ArgumentMatchers.eq(softwareProductId),
+ ArgumentMatchers.any())).thenReturn(zipFile);
- OrchestrationTemplateActionResponse processResponse =
- new OrchestrationTemplateActionResponse();
+ OrchestrationTemplateActionResponse processResponse = new OrchestrationTemplateActionResponse();
processResponse.setStatus(UploadFileStatus.Success);
when(candidateManager.process(
- ArgumentMatchers.eq(candidateId),
- ArgumentMatchers.any())).thenReturn(processResponse);
-
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(processResponse);
ValidationResponse vr = new ValidationResponse();
when(candidateManager.updateFilesDataStructure(
- ArgumentMatchers.eq(candidateId),
- ArgumentMatchers.any(),
- ArgumentMatchers.any())).thenReturn(vr);
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.any())).thenReturn(vr);
FilesDataStructure fds = new FilesDataStructure();
- fds.setArtifacts(Arrays.asList("a","b"));
+ fds.setArtifacts(Arrays.asList("a", "b"));
fds.setNested(Arrays.asList("foo", "bar"));
fds.setUnassigned(Arrays.asList("c", "d"));
fds.setModules(Arrays.asList(new Module(), new Module()));
when(candidateManager.getFilesDataStructure(
- ArgumentMatchers.eq(candidateId),
- ArgumentMatchers.any())).thenReturn(Optional.of(fds));
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(Optional.of(fds));
orchestrationTemplateCandidate =
- new OrchestrationTemplateCandidateImpl(candidateManager, vendorSoftwareProductManager, activityLogManager);
-
+ new OrchestrationTemplateCandidateImpl(candidateManager, vendorSoftwareProductManager, activityLogManager,
+ artifactStorageManager, packageSizeReducer);
- }catch (Exception e){
- logger.error(e.getMessage(), e);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
}
}
@Test
- public void uploadSignedTest() {
+ void uploadSignedTest() {
Response response = orchestrationTemplateCandidate
.upload("1", "1", mockAttachment("filename.zip", this.getClass().getResource("/files/sample-signed.zip")),
"1");
@@ -148,7 +155,21 @@ public class OrchestrationTemplateCandidateImplTest {
}
@Test
- public void uploadNotSignedTest() {
+ void uploadNotSignedTest() throws IOException {
+ Response response = orchestrationTemplateCandidate.upload("1", "1",
+ mockAttachment("filename.csar", this.getClass().getResource("/files/sample-not-signed.csar")), "1");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertTrue(((UploadFileResponseDto) response.getEntity()).getErrors().isEmpty());
+ }
+
+ @Test
+ void uploadNotSignedArtifactStorageManagerIsEnabledTest() throws IOException {
+ when(artifactStorageManager.isEnabled()).thenReturn(true);
+ final Path path = Path.of("src/test/resources/files/sample-not-signed.csar");
+ when(artifactStorageManager.upload(anyString(), anyString(), any())).thenReturn(new PersistentStorageArtifactInfo(path));
+ final byte[] bytes = Files.readAllBytes(path);
+ when(packageSizeReducer.reduce(any())).thenReturn(bytes);
+
Response response = orchestrationTemplateCandidate.upload("1", "1",
mockAttachment("filename.csar", this.getClass().getResource("/files/sample-not-signed.csar")), "1");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
@@ -167,7 +188,7 @@ public class OrchestrationTemplateCandidateImplTest {
bytes = IOUtils.toByteArray(fileToUpload);
} catch (final IOException e) {
logger.error("unexpected exception", e);
- Assert.fail("Not able to convert file to byte array");
+ fail("Not able to convert file to byte array");
}
}
when(attachment.getObject(ArgumentMatchers.any())).thenReturn(bytes);
@@ -175,7 +196,7 @@ public class OrchestrationTemplateCandidateImplTest {
}
@Test
- public void uploadSignNotValidTest() {
+ void uploadSignNotValidTest() {
Response response = orchestrationTemplateCandidate
.upload("1", "1", mockAttachment("filename.zip", null), "1");
assertEquals(Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatus());
@@ -183,82 +204,78 @@ public class OrchestrationTemplateCandidateImplTest {
}
@Test
- public void testCandidateGet() throws IOException {
+ void testCandidateGet() throws IOException {
Response rsp = orchestrationTemplateCandidate.get(candidateId, versionId, user);
- Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
- Assert.assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf("Candidate"),-1);
- byte[] content = (byte[])rsp.getEntity();
- Assert.assertEquals("World", new String(content));
+ assertEquals(Response.Status.OK.getStatusCode(), rsp.getStatus(), "Response status equals");
+ assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf("Candidate"), -1);
+ byte[] content = (byte[]) rsp.getEntity();
+ assertEquals("World", new String(content));
}
@Test
- public void testVendorSoftwareProductGet() throws IOException {
+ void testVendorSoftwareProductGet() throws IOException {
Response rsp = orchestrationTemplateCandidate.get(softwareProductId, versionId, user);
- Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
- Assert.assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf("Processed"),-1);
- byte[] content = (byte[])rsp.getEntity();
- Assert.assertEquals("World", new String(content));
+ assertEquals(Response.Status.OK.getStatusCode(), rsp.getStatus(), "Response status equals");
+ assertNotEquals(rsp.getHeaderString("Content-Disposition").indexOf("Processed"), -1);
+ byte[] content = (byte[]) rsp.getEntity();
+ assertEquals("World", new String(content));
}
@Test
- public void testMissingGet() throws IOException {
+ void testMissingGet() throws IOException {
Response rsp = orchestrationTemplateCandidate.get(UUID.randomUUID().toString(), versionId, user);
- Assert.assertEquals("Response status equals", Response.Status.NOT_FOUND.getStatusCode(), rsp.getStatus());
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rsp.getStatus(), "Response status equals");
}
@Test
- public void testAbort() {
+ void testAbort() {
try {
Response rsp = orchestrationTemplateCandidate.abort(candidateId, versionId);
- Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
- Assert.assertNull(rsp.getEntity());
- }
- catch (Exception ex) {
+ assertEquals(Response.Status.OK.getStatusCode(), rsp.getStatus(), "Response status equals");
+ assertNull(rsp.getEntity());
+ } catch (Exception ex) {
logger.error("unexpected exception", ex);
- Assert.fail("abort should not throw an exception");
+ fail("abort should not throw an exception");
}
}
@Test
- public void testProcess() {
+ void testProcess() {
try {
Response rsp = orchestrationTemplateCandidate.process(candidateId, versionId, user);
- Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
- Assert.assertNotNull(rsp.getEntity());
- OrchestrationTemplateActionResponseDto dto = (OrchestrationTemplateActionResponseDto)rsp.getEntity();
- Assert.assertEquals("status check", UploadFileStatus.Success, dto.getStatus());
- }
- catch (Exception ex) {
+ assertEquals(Response.Status.OK.getStatusCode(), rsp.getStatus(), "Response status equals");
+ assertNotNull(rsp.getEntity());
+ OrchestrationTemplateActionResponseDto dto = (OrchestrationTemplateActionResponseDto) rsp.getEntity();
+ assertEquals(UploadFileStatus.Success, dto.getStatus(), "status check");
+ } catch (Exception ex) {
logger.error("unexpected exception", ex);
- Assert.fail("abort should not throw an exception");
+ fail("abort should not throw an exception");
}
}
@Test
- public void testFilesDataStructureUpload() {
+ void testFilesDataStructureUpload() {
try {
FileDataStructureDto dto = new FileDataStructureDto();
dto.setArtifacts(Arrays.asList("a", "b", "c"));
Response rsp = orchestrationTemplateCandidate.updateFilesDataStructure(candidateId, versionId, dto, user);
- Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
- }
- catch (Exception ex) {
+ assertEquals(Response.Status.OK.getStatusCode(), rsp.getStatus(), "Response status equals");
+ } catch (Exception ex) {
logger.error("unexpected exception", ex);
- Assert.fail("abort should not throw an exception");
+ fail("abort should not throw an exception");
}
}
@Test
- public void testFilesDataStructureGet() {
+ void testFilesDataStructureGet() {
try {
FileDataStructureDto dto = new FileDataStructureDto();
dto.setArtifacts(Arrays.asList("a", "b", "c"));
Response rsp = orchestrationTemplateCandidate.getFilesDataStructure(candidateId, versionId, user);
- Assert.assertEquals("Response status equals", Response.Status.OK.getStatusCode(), rsp.getStatus());
- }
- catch (Exception ex) {
+ assertEquals(Response.Status.OK.getStatusCode(), rsp.getStatus(), "Response status equals");
+ } catch (Exception ex) {
logger.error("unexpected exception", ex);
- Assert.fail("abort should not throw an exception");
+ fail("abort should not throw an exception");
}
}