summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/VnfDescriptorGeneratorImpl.java1
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/ArtifactStorageManager.java1
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/PackageSizeReducer.java6
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java12
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java24
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java17
-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.java43
-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/VendorSoftwareProductsImpl.java16
-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.java134
-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/VendorSoftwareProductsImplTest.java4
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java3
-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.java5
12 files changed, 161 insertions, 105 deletions
diff --git a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/VnfDescriptorGeneratorImpl.java b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/VnfDescriptorGeneratorImpl.java
index 053bdde73a..dac8130c46 100644
--- a/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/VnfDescriptorGeneratorImpl.java
+++ b/catalog-be-plugins/etsi-nfv-nsd-csar-plugin/src/main/java/org/openecomp/sdc/be/plugins/etsi/nfv/nsd/generator/VnfDescriptorGeneratorImpl.java
@@ -35,7 +35,6 @@
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.file.FileUtils;
- import org.openecomp.sdc.be.csar.storage.ArtifactStorageManager;
import org.openecomp.sdc.be.csar.storage.StorageFactory;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.plugins.etsi.nfv.nsd.builder.NsdToscaMetadataBuilder;
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/ArtifactStorageManager.java b/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/ArtifactStorageManager.java
index 9a4bc00162..1845f85e98 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/ArtifactStorageManager.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/ArtifactStorageManager.java
@@ -75,4 +75,5 @@ public interface ArtifactStorageManager {
* @param vspId - VSP ID
*/
void delete(String vspId);
+
}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/PackageSizeReducer.java b/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/PackageSizeReducer.java
index 290ca08d00..83fd8fdfbf 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/PackageSizeReducer.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/be/csar/storage/PackageSizeReducer.java
@@ -27,6 +27,12 @@ import java.nio.file.Path;
*/
public interface PackageSizeReducer {
+ /**
+ * Reduces the package in the given path based on the package reducer configuration.
+ *
+ * @param path the package path
+ * @return the reduced package in bytes
+ */
byte[] reduce(Path path);
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java
index cfbbc4fe4e..9e72522682 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageConfig.java
@@ -20,11 +20,9 @@
package org.openecomp.sdc.be.csar.storage;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
+import lombok.Data;
-@AllArgsConstructor
-@Getter
+@Data
public class MinIoStorageArtifactStorageConfig implements ArtifactStorageConfig {
private final boolean isEnabled;
@@ -33,8 +31,7 @@ public class MinIoStorageArtifactStorageConfig implements ArtifactStorageConfig
private final String tempPath;
private final int uploadPartSize;
- @AllArgsConstructor
- @Getter
+ @Data
public static class EndPoint {
private final String host;
@@ -42,8 +39,7 @@ public class MinIoStorageArtifactStorageConfig implements ArtifactStorageConfig
private final boolean secure;
}
- @AllArgsConstructor
- @Getter
+ @Data
public static class Credentials {
private final String accessKey;
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java
index 98c54988a0..63a6820634 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageCsarSizeReducer.java
@@ -26,6 +26,7 @@ import java.io.BufferedOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -40,6 +41,7 @@ import lombok.Getter;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.openecomp.sdc.be.csar.storage.exception.CsarSizeReducerException;
+import org.openecomp.sdc.common.CommonConfigurationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,15 +52,31 @@ public class MinIoStorageCsarSizeReducer implements PackageSizeReducer {
private static final Set<String> ALLOWED_CERTIFICATE_EXTENSIONS = Set.of("cert", "crt");
private static final String CSAR_EXTENSION = "csar";
private static final String UNEXPECTED_PROBLEM_HAPPENED_WHILE_READING_THE_CSAR = "An unexpected problem happened while reading the CSAR '%s'";
+ private static final String EXTERNAL_CSAR_STORE = "externalCsarStore";
+
@Getter
private final AtomicBoolean reduced = new AtomicBoolean(false);
private final CsarPackageReducerConfiguration configuration;
- public MinIoStorageCsarSizeReducer(final CsarPackageReducerConfiguration configuration) {
+ public MinIoStorageCsarSizeReducer() {
+ this.configuration = readPackageReducerConfiguration();
+ }
+
+ MinIoStorageCsarSizeReducer(final CsarPackageReducerConfiguration configuration) {
this.configuration = configuration;
}
+ 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);
+ final int thresholdEntries = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "thresholdEntries", 10000);
+ 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, thresholdEntries);
+ }
+
@Override
public byte[] reduce(final Path csarPackagePath) {
if (hasSignedPackageStructure(csarPackagePath)) {
@@ -76,7 +94,7 @@ public class MinIoStorageCsarSizeReducer implements PackageSizeReducer {
zf.entries().asIterator().forEachRemaining(zipProcessingFunction.getProcessZipConsumer(csarPackagePath, zf, zos));
} catch (final IOException ex1) {
rollback(reducedCsarPath);
- LOGGER.error("Could not read ZIP stream '{}'", csarPackagePath.toString(), ex1);
+ LOGGER.error("Could not read ZIP stream '{}'", csarPackagePath, ex1);
final var errorMsg = String.format(UNEXPECTED_PROBLEM_HAPPENED_WHILE_READING_THE_CSAR, csarPackagePath);
throw new CsarSizeReducerException(errorMsg, ex1);
}
@@ -190,7 +208,7 @@ public class MinIoStorageCsarSizeReducer implements PackageSizeReducer {
.map(ZipEntry::getName).map(Path::of)
.collect(Collectors.toList());
} catch (final IOException e) {
- LOGGER.error("Failed to read ZipFile '{}'", csarPackagePath.toString(), e);
+ LOGGER.error("Failed to read ZipFile '{}'", csarPackagePath, e);
final var errorMsg = String.format(UNEXPECTED_PROBLEM_HAPPENED_WHILE_READING_THE_CSAR, csarPackagePath);
throw new CsarSizeReducerException(errorMsg, e);
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java
index 8c86917e01..b1bf9ebf12 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/StorageFactory.java
@@ -23,12 +23,7 @@ package org.openecomp.sdc.be.csar.storage;
import static org.openecomp.sdc.be.csar.storage.StorageFactory.StorageType.NONE;
import static org.openecomp.sdc.be.csar.storage.StorageFactory.StorageType.findByName;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
import lombok.NoArgsConstructor;
import org.openecomp.sdc.common.CommonConfigurationManager;
import org.openecomp.sdc.logging.api.Logger;
@@ -52,7 +47,7 @@ public class StorageFactory {
public Optional<PackageSizeReducer> createPackageSizeReducer() {
switch (getConfiguredArtifactStorageType()) {
case MINIO: // MinIoStorage enabled
- return Optional.of(new MinIoStorageCsarSizeReducer(readPackageReducerConfiguration()));
+ return Optional.of(new MinIoStorageCsarSizeReducer());
default:// all configured, nothing enabled
return Optional.empty();
}
@@ -66,16 +61,6 @@ public class StorageFactory {
return findByName(storageType);
}
- 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);
- final int thresholdEntries = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, "thresholdEntries", 10000);
- 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, thresholdEntries);
- }
-
public enum StorageType {
NONE,
MINIO;
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 93483f3de1..ec1e96e0bd 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
@@ -29,6 +29,7 @@ import static org.openecomp.sdc.common.errors.Messages.ERROR_HAS_OCCURRED_WHILE_
import static org.openecomp.sdc.common.errors.Messages.ERROR_HAS_OCCURRED_WHILE_REDUCING_THE_ARTIFACT_SIZE;
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.PACKAGE_REDUCER_NOT_CONFIGURED;
import static org.openecomp.sdc.common.errors.Messages.UNEXPECTED_PROBLEM_HAPPENED_WHILE_GETTING;
import static org.openecomp.sdcrests.vsp.rest.exception.OrchestrationTemplateCandidateUploadManagerExceptionSupplier.vspUploadAlreadyInProgress;
@@ -103,21 +104,15 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
private final OrchestrationTemplateCandidateManager candidateManager;
private final VendorSoftwareProductManager vendorSoftwareProductManager;
private final ActivityLogManager activityLogManager;
- private final ArtifactStorageManager artifactStorageManager;
- private final StorageFactory storageFactory;
- private final PackageSizeReducer packageSizeReducer;
private final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager;
+ private final StorageFactory storageFactory;
@Autowired
public OrchestrationTemplateCandidateImpl(final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager) {
this.candidateManager = OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface();
this.vendorSoftwareProductManager = VspManagerFactory.getInstance().createInterface();
this.activityLogManager = ActivityLogManagerFactory.getInstance().createInterface();
- LOGGER.info("Instantiating artifactStorageManager");
this.storageFactory = new StorageFactory();
- this.artifactStorageManager = storageFactory.createArtifactStorageManager();
- LOGGER.info("Instantiating packageSizeReducer");
- this.packageSizeReducer = storageFactory.createPackageSizeReducer().orElse(null);
this.orchestrationTemplateCandidateUploadManager = orchestrationTemplateCandidateUploadManager;
}
@@ -125,15 +120,12 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
public OrchestrationTemplateCandidateImpl(final OrchestrationTemplateCandidateManager candidateManager,
final VendorSoftwareProductManager vendorSoftwareProductManager,
final ActivityLogManager activityLogManager,
- final ArtifactStorageManager artifactStorageManager,
- final PackageSizeReducer packageSizeReducer,
- final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager) {
+ final OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager,
+ final StorageFactory storageFactory) {
this.candidateManager = candidateManager;
this.vendorSoftwareProductManager = vendorSoftwareProductManager;
this.activityLogManager = activityLogManager;
- this.artifactStorageManager = artifactStorageManager;
- this.storageFactory = new StorageFactory();
- this.packageSizeReducer = packageSizeReducer;
+ this.storageFactory = storageFactory;
this.orchestrationTemplateCandidateUploadManager = orchestrationTemplateCandidateUploadManager;
}
@@ -156,7 +148,7 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
ArtifactInfo artifactInfo = null;
final ArtifactStorageManager artifactStorageManager = storageFactory.createArtifactStorageManager();
if (artifactStorageManager.isEnabled()) {
- artifactInfo = handleArtifactStorage(vspId, versionId, filename, dataHandler);
+ artifactInfo = handleArtifactStorage(vspId, versionId, filename, dataHandler, artifactStorageManager);
fileToUploadBytes = artifactInfo.getBytes();
} else {
fileToUploadBytes = fileToUpload.getObject(byte[].class);
@@ -215,7 +207,13 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
}
private ArtifactInfo handleArtifactStorage(final String vspId, final String versionId, final String filename,
- final DataHandler artifactDataHandler) {
+ final DataHandler artifactDataHandler,
+ final ArtifactStorageManager artifactStorageManager) {
+ final PackageSizeReducer packageSizeReducer = storageFactory.createPackageSizeReducer().orElse(null);
+ if (packageSizeReducer == null) {
+ throw new ArtifactStorageException(PACKAGE_REDUCER_NOT_CONFIGURED.getErrorMessage());
+ }
+
final Path tempArtifactPath;
try {
final ArtifactStorageConfig storageConfiguration = artifactStorageManager.getStorageConfiguration();
@@ -239,15 +237,22 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
LOGGER.error("Package Size Reducer not configured", e);
throw new ArtifactStorageException(ERROR_HAS_OCCURRED_WHILE_PERSISTING_THE_ARTIFACT.formatMessage(filename));
}
+
try {
- LOGGER.debug("STARTED -> reducing '{}'", tempArtifactPath.toString());
+ LOGGER.debug("STARTED -> reducing '{}'", tempArtifactPath);
artifactInfo.setBytes(packageSizeReducer.reduce(tempArtifactPath));
- LOGGER.debug("FINISHED -> reducing '{}'", tempArtifactPath.toString());
+ LOGGER.debug("FINISHED -> reducing '{}'", tempArtifactPath);
+ } catch (final Exception e) {
+ LOGGER.debug("ERROR -> reducing '{}'", tempArtifactPath, e);
+ throw new ArtifactStorageException(ERROR_HAS_OCCURRED_WHILE_REDUCING_THE_ARTIFACT_SIZE.formatMessage(filename), e);
+ }
+
+ try {
Files.delete(tempArtifactPath);
} catch (final Exception e) {
- LOGGER.error("Package Size Reducer not configured", e);
- throw new ArtifactStorageException(ERROR_HAS_OCCURRED_WHILE_REDUCING_THE_ARTIFACT_SIZE.formatMessage(filename));
+ LOGGER.warn("Could not delete temporary package at '{}'", tempArtifactPath, e);
}
+
return artifactInfo;
}
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/VendorSoftwareProductsImpl.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/VendorSoftwareProductsImpl.java
index 5540e0f315..9bb68f23af 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/VendorSoftwareProductsImpl.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/VendorSoftwareProductsImpl.java
@@ -133,10 +133,9 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
private final ActivityLogManager activityLogManager;
private final NotificationPropagationManager notifier;
private final UniqueValueUtil uniqueValueUtil;
- private final ArtifactStorageManager artifactStorageManager;
+ private final StorageFactory storageFactory;
private final CatalogVspClient catalogVspClient;
-
public VendorSoftwareProductsImpl() {
this.itemManager = AsdcItemManagerFactory.getInstance().createInterface();
this.permissionsManager = PermissionsManagerFactory.getInstance().createInterface();
@@ -145,7 +144,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
this.activityLogManager = ActivityLogManagerFactory.getInstance().createInterface();
this.notifier = NotificationPropagationManagerFactory.getInstance().createInterface();
this.uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface());
- this.artifactStorageManager = new StorageFactory().createArtifactStorageManager();
+ this.storageFactory = new StorageFactory();
this.catalogVspClient = new CatalogVspClientImpl();
}
@@ -156,7 +155,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
ActivityLogManager activityLogManager,
NotificationPropagationManager notifier,
UniqueValueUtil uniqueValueUtil,
- ArtifactStorageManager artifactStorageManager,
+ final StorageFactory storageFactory,
CatalogVspClient catalogVspClient) {
this.itemManager = itemManager;
this.permissionsManager = permissionsManager;
@@ -165,7 +164,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
this.activityLogManager = activityLogManager;
this.notifier = notifier;
this.uniqueValueUtil = uniqueValueUtil;
- this.artifactStorageManager = artifactStorageManager;
+ this.storageFactory = storageFactory;
this.catalogVspClient = catalogVspClient;
}
@@ -299,8 +298,9 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
}
Integer certifiedVersionsCounter = vsp.getVersionStatusCounters().get(VersionStatus.Certified);
+ final ArtifactStorageManager artifactStorageManager = storageFactory.createArtifactStorageManager();
if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) {
- if (artifactStorageManager.isEnabled() && !deleteVspFromStorage(vspId)) {
+ if (artifactStorageManager.isEnabled() && !deleteVspFromStorage(vspId, artifactStorageManager)) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(new Exception(Messages.DELETE_VSP_FROM_STORAGE_ERROR.formatMessage(vspId))).build();
}
@@ -308,7 +308,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
} else {
final var isVspArchived = getVspList(null, ItemStatus.ARCHIVED.name(), user).stream().anyMatch(item -> item.getId().equals(vspId));
if (isVspArchived) {
- if (artifactStorageManager.isEnabled() && !deleteVspFromStorage(vspId)) {
+ if (artifactStorageManager.isEnabled() && !deleteVspFromStorage(vspId, artifactStorageManager)) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(new Exception(Messages.DELETE_VSP_FROM_STORAGE_ERROR.formatMessage(vspId))).build();
}
@@ -318,7 +318,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
}
}
- private boolean deleteVspFromStorage(final String vspId) {
+ private boolean deleteVspFromStorage(final String vspId, final ArtifactStorageManager artifactStorageManager) {
try {
artifactStorageManager.delete(vspId);
} catch (final Exception e) {
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 8b31261d6a..8fd160a886 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
@@ -54,6 +54,8 @@ import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@@ -99,8 +101,6 @@ class OrchestrationTemplateCandidateImplTest {
@Mock
private ActivityLogManager activityLogManager;
@Mock
- private ArtifactStorageManager artifactStorageManager;
- @Mock
private PackageSizeReducer packageSizeReducer;
@Mock
private OrchestrationTemplateCandidateUploadManager orchestrationTemplateCandidateUploadManager;
@@ -108,54 +108,56 @@ class OrchestrationTemplateCandidateImplTest {
private StorageFactory storageFactory;
@Mock
private Attachment fileToUpload;
+ @Mock
+ private ArtifactStorageManager artifactStorageManager;
@InjectMocks
private OrchestrationTemplateCandidateImpl orchestrationTemplateCandidate;
+ @TempDir
+ Path tempDir;
+
@BeforeEach
- public void setUp() {
- try {
- 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()));
-
- when(candidateManager.get(
- ArgumentMatchers.eq(candidateId),
- ArgumentMatchers.any())).thenReturn(zipFile);
-
- when(vendorSoftwareProductManager.get(
- ArgumentMatchers.eq(softwareProductId),
- ArgumentMatchers.any())).thenReturn(zipFile);
-
- OrchestrationTemplateActionResponse processResponse = new OrchestrationTemplateActionResponse();
- processResponse.setStatus(UploadFileStatus.Success);
- when(candidateManager.process(
- ArgumentMatchers.eq(candidateId),
- ArgumentMatchers.any())).thenReturn(processResponse);
-
- ValidationResponse vr = new ValidationResponse();
- when(candidateManager.updateFilesDataStructure(
- ArgumentMatchers.eq(candidateId),
- ArgumentMatchers.any(),
- ArgumentMatchers.any())).thenReturn(vr);
-
- FilesDataStructure fds = new FilesDataStructure();
- 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));
-
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
+ public void setUp() throws IOException {
+ 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()));
+
+ when(candidateManager.get(
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(zipFile);
+
+ when(vendorSoftwareProductManager.get(
+ ArgumentMatchers.eq(softwareProductId),
+ ArgumentMatchers.any())).thenReturn(zipFile);
+
+ OrchestrationTemplateActionResponse processResponse = new OrchestrationTemplateActionResponse();
+ processResponse.setStatus(UploadFileStatus.Success);
+ when(candidateManager.process(
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any())).thenReturn(processResponse);
+
+ ValidationResponse vr = new ValidationResponse();
+ when(candidateManager.updateFilesDataStructure(
+ ArgumentMatchers.eq(candidateId),
+ ArgumentMatchers.any(),
+ ArgumentMatchers.any())).thenReturn(vr);
+
+ FilesDataStructure fds = new FilesDataStructure();
+ 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));
+ when(storageFactory.createArtifactStorageManager()).thenReturn(artifactStorageManager);
+ when(storageFactory.createPackageSizeReducer()).thenReturn(Optional.of(packageSizeReducer));
}
@Test
@@ -194,6 +196,45 @@ class OrchestrationTemplateCandidateImplTest {
assertTrue(((UploadFileResponseDto) response.getEntity()).getErrors().isEmpty());
}
+ @Test
+ void uploadArtifactStorageTest() throws IOException {
+ //given
+ final String vspId = "vspId";
+ final String versionId = "versionId";
+ when(orchestrationTemplateCandidateUploadManager.findLatestStatus(vspId, versionId, user)).thenReturn(Optional.empty());
+ final UUID lockId = UUID.randomUUID();
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProgress(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.UPLOADING));
+ when(orchestrationTemplateCandidateUploadManager.putUploadInValidation(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.VALIDATING));
+ when(orchestrationTemplateCandidateUploadManager.putUploadInProcessing(vspId, versionId, user))
+ .thenReturn(createVspUploadStatus(lockId, VspUploadStatus.PROCESSING));
+ when(artifactStorageManager.isEnabled()).thenReturn(true);
+ final MinIoStorageArtifactStorageConfig minIoConfig =
+ new MinIoStorageArtifactStorageConfig(true,
+ new EndPoint("", 9000, true),
+ new Credentials("", ""), tempDir.toString(), 1000
+ );
+
+ when(artifactStorageManager.getStorageConfiguration()).thenReturn(minIoConfig);
+ final MinIoArtifactInfo artifactInfo = new MinIoArtifactInfo(vspId, versionId);
+ final Attachment attachmentMock = mockAttachment("filename.csar", this.getClass().getResource("/files/sample-not-signed.csar"));
+ final byte[] attachmentBytes = attachmentMock.getObject(byte[].class);
+ artifactInfo.setBytes(attachmentBytes);
+ final ArgumentCaptor<Path> reduceTempDirectoryArg = ArgumentCaptor.forClass(Path.class);
+ when(packageSizeReducer.reduce(reduceTempDirectoryArg.capture())).thenReturn(attachmentBytes);
+ when(artifactStorageManager.upload(eq(vspId), eq(versionId), any(InputStream.class))).thenReturn(artifactInfo);
+ //when
+ Response response = orchestrationTemplateCandidate.upload(vspId, versionId, attachmentMock, user);
+ //then
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertTrue(((UploadFileResponseDto) response.getEntity()).getErrors().isEmpty());
+ final Path actualReduceTempFolder = reduceTempDirectoryArg.getValue();
+ final Path expectedReduceTempFolder = tempDir.resolve(Path.of(vspId, versionId));
+ assertTrue(actualReduceTempFolder.startsWith(expectedReduceTempFolder),
+ String.format("Reduce temporary directory should be '%s'", expectedReduceTempFolder));
+ }
+
@NotNull
private VspUploadStatusDto createVspUploadStatus(final UUID lockId, final VspUploadStatus uploadStatus) {
final VspUploadStatusDto vspUploadStatusProcessing = new VspUploadStatusDto();
@@ -204,7 +245,6 @@ class OrchestrationTemplateCandidateImplTest {
@Test
void uploadNotSignedArtifactStorageManagerIsEnabledTest() throws IOException {
- when(storageFactory.createArtifactStorageManager()).thenReturn(artifactStorageManager);
when(artifactStorageManager.isEnabled()).thenReturn(true);
when(artifactStorageManager.getStorageConfiguration()).thenReturn(new MinIoStorageArtifactStorageConfig
(true, new EndPoint("host", 9000, false), new Credentials("accessKey", "secretKey"), "tempPath", 10_000_000));
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/VendorSoftwareProductsImplTest.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/VendorSoftwareProductsImplTest.java
index f8af8df1ed..1936aaa7b4 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/VendorSoftwareProductsImplTest.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/VendorSoftwareProductsImplTest.java
@@ -50,6 +50,7 @@ import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.sdc.activitylog.ActivityLogManager;
import org.openecomp.sdc.be.csar.storage.ArtifactStorageManager;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.be.csar.storage.StorageFactory;
import org.openecomp.sdc.itempermissions.PermissionsManager;
import org.openecomp.sdc.notification.services.NotificationPropagationManager;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
@@ -87,6 +88,8 @@ class VendorSoftwareProductsImplTest {
private ArtifactStorageManager artifactStorageManager;
@Mock
private CatalogVspClient catalogVspClient;
+ @Mock
+ private StorageFactory storageFactory;
@InjectMocks
private VendorSoftwareProductsImpl vendorSoftwareProducts;
@@ -103,6 +106,7 @@ class VendorSoftwareProductsImplTest {
item.setType("vsp");
item.setId(vspId);
when(itemManager.get(vspId)).thenReturn(item);
+ when(storageFactory.createArtifactStorageManager()).thenReturn(artifactStorageManager);
}
@Test
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
index 65906bd3d2..2ed67b3963 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
@@ -210,7 +210,8 @@ public enum Messages {
EXTERNAL_CSAR_STORE_CONFIGURATION_FAILURE_MISSING("externalCsarStore configuration failure, missing '%s'"),
ERROR_HAS_OCCURRED_WHILE_PERSISTING_THE_ARTIFACT("An error has occurred while persisting the artifact: %s"),
ERROR_HAS_OCCURRED_WHILE_REDUCING_THE_ARTIFACT_SIZE("An error has occurred while reducing the artifact's size: %s"),
- UNEXPECTED_PROBLEM_HAPPENED_WHILE_GETTING("An unexpected problem happened while getting '%s'");
+ UNEXPECTED_PROBLEM_HAPPENED_WHILE_GETTING("An unexpected problem happened while getting '%s'"),
+ PACKAGE_REDUCER_NOT_CONFIGURED("Could not process the package. Package reducer is not configured");
// @formatter:on
private final String errorMessage;
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 fbb25de0da..f18e15efb7 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
@@ -54,12 +54,12 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl implements Orchestrat
private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateCandidateDaoZusammenImpl.class);
private static final String EMPTY_DATA = "{}";
private final ZusammenAdaptor zusammenAdaptor;
- private final ArtifactStorageManager artifactStorageManager;
+ private final StorageFactory storageFactory;
public OrchestrationTemplateCandidateDaoZusammenImpl(final ZusammenAdaptor zusammenAdaptor) {
this.zusammenAdaptor = zusammenAdaptor;
LOGGER.info("Instantiating artifactStorageManager");
- this.artifactStorageManager = new StorageFactory().createArtifactStorageManager();
+ this.storageFactory = new StorageFactory();
}
@Override
@@ -158,6 +158,7 @@ public class OrchestrationTemplateCandidateDaoZusammenImpl implements Orchestrat
final String originalFileSuffix = candidateData.getOriginalFileSuffix();
originalPackageElement.getInfo().addProperty(InfoPropertyName.ORIGINAL_FILE_NAME.getVal(), originalFileName);
originalPackageElement.getInfo().addProperty(InfoPropertyName.ORIGINAL_FILE_SUFFIX.getVal(), originalFileSuffix);
+ final ArtifactStorageManager artifactStorageManager = storageFactory.createArtifactStorageManager();
originalPackageElement.getInfo().addProperty("storeCsarsExternally", artifactStorageManager.isEnabled());
if (artifactStorageManager.isEnabled()) {
final ArtifactInfo candidateArtifactInfo = candidateData.getArtifactInfo();