summaryrefslogtreecommitdiffstats
path: root/common-be/src/main/java
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-03-24 16:38:00 +0000
committerMichael Morris <michael.morris@est.tech>2022-03-28 08:37:43 +0000
commit4307dbb5f0dc5da60e55f3473259cfd059d14770 (patch)
treeacb1afb19475a772f9169ed0e8f49ea722905a6c /common-be/src/main/java
parent0902d2829ce984730085c816b649bed957ac0d99 (diff)
Implement VSP deletion from Storage
Change-Id: I06d86696570b2751f152dffc06fd580ef8c0c705 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3924
Diffstat (limited to 'common-be/src/main/java')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java32
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java5
2 files changed, 31 insertions, 6 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java
index 7b9cf087a6..bc0792b472 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java
@@ -24,11 +24,14 @@ import static org.openecomp.sdc.common.errors.Messages.EXTERNAL_CSAR_STORE_CONFI
import io.minio.BucketExistsArgs;
import io.minio.GetObjectArgs;
+import io.minio.ListObjectsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
+import io.minio.RemoveBucketArgs;
import io.minio.RemoveObjectArgs;
import io.minio.StatObjectArgs;
+import io.minio.messages.Item;
import java.io.InputStream;
import java.util.Map;
import lombok.Getter;
@@ -134,12 +137,7 @@ public class MinIoStorageArtifactStorageManager implements ArtifactStorageManage
@Override
public InputStream get(final ArtifactInfo artifactInfo) {
final MinIoArtifactInfo minioObject = (MinIoArtifactInfo) artifactInfo;
- try {
- return get(minioObject.getBucket(), minioObject.getObjectName());
- } catch (final Exception e) {
- LOGGER.error("Failed to get - bucket: '{}', object: '{}'", minioObject.getBucket(), minioObject.getObjectName(), e);
- throw new ArtifactStorageException("Failed to get Object", e);
- }
+ return get(minioObject.getBucket(), minioObject.getObjectName());
}
@Override
@@ -173,6 +171,28 @@ public class MinIoStorageArtifactStorageManager implements ArtifactStorageManage
}
+ @Override
+ public void delete(final String vspId) {
+ LOGGER.debug("DELETE VSP - bucket: '{}'", vspId);
+ final var listObjects = minioClient.listObjects(ListObjectsArgs.builder().bucket(vspId).build());
+ listObjects.forEach(itemResult -> {
+ Item versionId;
+ try {
+ versionId = itemResult.get();
+ } catch (final Exception e) {
+ LOGGER.error("Failed to get versionId for VSP - bucket: '{}'", vspId, e);
+ throw new ArtifactStorageException(String.format("Failed to delete VSP '%s'", vspId), e);
+ }
+ delete(new MinIoArtifactInfo(vspId, versionId.objectName()));
+ });
+ try {
+ minioClient.removeBucket(RemoveBucketArgs.builder().bucket(vspId).build());
+ } catch (final Exception e) {
+ LOGGER.error("Failed to delete VSP - bucket: '{}'", vspId, e);
+ throw new ArtifactStorageException(String.format("Failed to delete VSP '%s'", vspId), e);
+ }
+ }
+
private MinIoStorageArtifactStorageConfig readMinIoStorageArtifactStorageConfig() {
final var commonConfigurationManager = CommonConfigurationManager.getInstance();
final Map<String, Object> endpoint = commonConfigurationManager.getConfigValue(EXTERNAL_CSAR_STORE, ENDPOINT, null);
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java
index aec69d5bd7..562be2de14 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java
@@ -61,4 +61,9 @@ public class NoneStorageManager implements ArtifactStorageManager {
throw new UnsupportedOperationException();
}
+ @Override
+ public void delete(final String vspId) {
+ throw new UnsupportedOperationException();
+ }
+
}