aboutsummaryrefslogtreecommitdiffstats
path: root/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
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-03-25 19:30:14 +0000
committerandre.schmid <andre.schmid@est.tech>2022-03-31 18:19:04 +0100
commit115b2ef065fa652b380093e4f2571e53c3f0bc19 (patch)
treec325e09c003f2d8d55b09692ffbd4e79e53da3aa /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
parent6cffd9e3eecb10281d880ea7d217f0ecddf8fb5a (diff)
Fix package storage and reducer config reload
The package storage configuration was not being reloaded when a configuration file change was made. Increases OrchestrationTemplateCandidateImpl coverage by testing the upload to the artifact storage. Issue-ID: SDC-3934 Change-Id: I533b3c3a92cdadb60a375890da85ee053364e8af Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to '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')
-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
2 files changed, 32 insertions, 27 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 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) {