aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-10-26 14:00:08 +0100
committerMichael Morris <michael.morris@est.tech>2022-10-27 12:02:27 +0000
commitf22f815d5c4e5d89049c6bbab781fec27ed1b894 (patch)
tree57dbd55a3f916443d1d8888abba804b208fdd1c7 /openecomp-be
parent813ac1c0dfa0f5c90210407c93d98076c86fc9ef (diff)
Remove temp file if Minio-upload failed
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Ib30f2b4643974c838d003db39c616fa82021cc6e Issue-ID: SDC-4232
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.java21
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java10
2 files changed, 21 insertions, 10 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 ec1e96e0bd..c4b55e5b4b 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
@@ -214,7 +214,7 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
throw new ArtifactStorageException(PACKAGE_REDUCER_NOT_CONFIGURED.getErrorMessage());
}
- final Path tempArtifactPath;
+ Path tempArtifactPath = null;
try {
final ArtifactStorageConfig storageConfiguration = artifactStorageManager.getStorageConfiguration();
@@ -228,12 +228,14 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
}
LOGGER.debug("FINISHED -> Transfer to '{}'", tempArtifactPath.toString());
} catch (final Exception e) {
+ deleteTempFile(tempArtifactPath);
throw new ArtifactStorageException(UNEXPECTED_PROBLEM_HAPPENED_WHILE_GETTING.formatMessage(filename));
}
final ArtifactInfo artifactInfo;
try (final InputStream inputStream = new FileInputStream(tempArtifactPath.toFile())) {
artifactInfo = artifactStorageManager.upload(vspId, versionId, inputStream);
} catch (final Exception e) {
+ deleteTempFile(tempArtifactPath);
LOGGER.error("Package Size Reducer not configured", e);
throw new ArtifactStorageException(ERROR_HAS_OCCURRED_WHILE_PERSISTING_THE_ARTIFACT.formatMessage(filename));
}
@@ -243,19 +245,26 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
artifactInfo.setBytes(packageSizeReducer.reduce(tempArtifactPath));
LOGGER.debug("FINISHED -> reducing '{}'", tempArtifactPath);
} catch (final Exception e) {
+ deleteTempFile(tempArtifactPath);
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.warn("Could not delete temporary package at '{}'", tempArtifactPath, e);
- }
+ deleteTempFile(tempArtifactPath);
return artifactInfo;
}
+ private void deleteTempFile(final Path tempArtifactPath) {
+ if (Files.exists(tempArtifactPath)) {
+ try {
+ Files.delete(tempArtifactPath);
+ } catch (final Exception e) {
+ LOGGER.warn("Could not delete temporary package at '{}'", tempArtifactPath, e);
+ }
+ }
+ }
+
private Response processOnboardPackage(final OnboardPackageInfo onboardPackageInfo, final VspDetails vspDetails,
final ErrorMessage... errorMessages) {
final UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java
index f16467f568..663801bd8e 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java
@@ -233,10 +233,12 @@ public class SecurityManager {
}
private void deleteFile(final Path filePath) {
- try {
- Files.delete(filePath);
- } catch (final IOException e) {
- LOGGER.warn("Failed to delete '{}' after verifying package signed data", filePath, e);
+ if (Files.exists(filePath)) {
+ try {
+ Files.delete(filePath);
+ } catch (final IOException e) {
+ LOGGER.warn("Failed to delete '{}' after verifying package signed data", filePath, e);
+ }
}
}