summaryrefslogtreecommitdiffstats
path: root/common-be/src
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-03-28 12:22:31 +0100
committerandre.schmid <andre.schmid@est.tech>2022-03-28 12:36:39 +0100
commit1a3ddb0a21f2ab6fc3bc6607e35ea2b703192ad9 (patch)
treef843771e2a502bcd2d9aa3b4e83da3c6130db6cd /common-be/src
parent55401bf89a8bc1c51f76554faac278186560724a (diff)
Check if the bucket exists before deleting VSP
Checks if the bucket exists before deleting VSP, ignoring the deletion if the bucket isn't present anymore. This avoids problems in case the artifact was already deleted from the artifact storage, but for some reason the VSP still present in the system. Change-Id: I7e88f227cc6786b451ca74519fa0dfe0659895c6 Issue-ID: SDC-3930 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'common-be/src')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java14
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java16
2 files changed, 26 insertions, 4 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 bc0792b472..78ee4bed23 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
@@ -92,7 +92,7 @@ public class MinIoStorageArtifactStorageManager implements ArtifactStorageManage
try {
// Make bucket if not exist.
- final boolean found = minioClient.bucketExists(BucketExistsArgs.builder().bucket(vspId).build());
+ final boolean found = bucketExists(vspId);
if (!found) {
// Make a new bucket ${vspId} .
@@ -174,6 +174,10 @@ public class MinIoStorageArtifactStorageManager implements ArtifactStorageManage
@Override
public void delete(final String vspId) {
LOGGER.debug("DELETE VSP - bucket: '{}'", vspId);
+ if (!bucketExists(vspId)) {
+ LOGGER.debug("VSP '{}' bucket was not found while trying to delete it", vspId);
+ return;
+ }
final var listObjects = minioClient.listObjects(ListObjectsArgs.builder().bucket(vspId).build());
listObjects.forEach(itemResult -> {
Item versionId;
@@ -193,6 +197,14 @@ public class MinIoStorageArtifactStorageManager implements ArtifactStorageManage
}
}
+ private boolean bucketExists(final String vspId) {
+ try {
+ return minioClient.bucketExists(BucketExistsArgs.builder().bucket(vspId).build());
+ } catch (final Exception e) {
+ throw new ArtifactStorageException(String.format("An unexpected error occurred while checking for 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/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java
index 09e62841e6..4d12a0be39 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java
@@ -27,6 +27,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import io.minio.BucketExistsArgs;
@@ -155,10 +156,19 @@ class MinIoStorageArtifactStorageManagerTest {
@Test
void testDeleteVspFail() throws Exception {
+ when(minioClient.bucketExists(BucketExistsArgs.builder().bucket(VSP_ID).build())).thenReturn(true);
doThrow(new RuntimeException()).when(minioClient).removeBucket(any(RemoveBucketArgs.class));
- assertThrows(ArtifactStorageException.class, () -> {
- testSubject.delete(VSP_ID);
- });
+ assertThrows(ArtifactStorageException.class, () -> testSubject.delete(VSP_ID));
+ }
+
+ @Test
+ void testDeleteVspBucketNotFound() throws Exception {
+ final BucketExistsArgs bucketExistsArgs = BucketExistsArgs.builder().bucket(VSP_ID).build();
+ //when
+ when(minioClient.bucketExists(bucketExistsArgs)).thenReturn(false);
+ testSubject.delete(VSP_ID);
+ //then
+ verify(minioClient).bucketExists(bucketExistsArgs);
}
@Test