summaryrefslogtreecommitdiffstats
path: root/common-be/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-03-31 19:05:00 +0100
committerMichael Morris <michael.morris@est.tech>2022-04-04 14:06:04 +0000
commitf2e43fb0a2c36b484b686d6c22342e72da66f679 (patch)
tree9570618007c9266729ebaa98e1626a56c7285917 /common-be/src
parent8c565b9d5396e86d431f51952b476007ff4fbe8e (diff)
Implement restore of partially deleted VSP
Change-Id: I790b6cd8494e8f35c3b9891304f15272e9769a68 Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3935
Diffstat (limited to 'common-be/src')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManager.java6
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/csar/storage/NoneStorageManager.java5
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/csar/storage/MinIoStorageArtifactStorageManagerTest.java24
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/csar/storage/NoneStorageManagerTest.java33
4 files changed, 63 insertions, 5 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 78ee4bed23..991b3b24a1 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
@@ -205,6 +205,12 @@ public class MinIoStorageArtifactStorageManager implements ArtifactStorageManage
}
}
+ @Override
+ public boolean exists(final String vspId) {
+ LOGGER.debug("exists - bucket: '{}'", vspId);
+ return bucketExists(vspId);
+ }
+
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 562be2de14..e718b7a5fd 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
@@ -66,4 +66,9 @@ public class NoneStorageManager implements ArtifactStorageManager {
throw new UnsupportedOperationException();
}
+ @Override
+ public boolean exists(final String vspId) {
+ throw new UnsupportedOperationException();
+ }
+
}
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 4d12a0be39..d6a52c5bda 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
@@ -35,9 +35,11 @@ import io.minio.GetObjectArgs;
import io.minio.GetObjectResponse;
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 java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -142,6 +144,14 @@ class MinIoStorageArtifactStorageManagerTest {
}
@Test
+ void testPutFail() throws Exception {
+ doThrow(new RuntimeException()).when(minioClient).putObject(any(PutObjectArgs.class));
+ assertThrows(ArtifactStorageException.class, () -> {
+ testSubject.put(VSP_ID, VERSION_ID, new ByteArrayInputStream(new byte[0]));
+ });
+ }
+
+ @Test
void testIsEnabled() {
Assertions.assertTrue(testSubject.isEnabled());
}
@@ -188,6 +198,20 @@ class MinIoStorageArtifactStorageManagerTest {
});
}
+ @Test
+ void testIsExistsOK() throws Exception {
+ when(minioClient.bucketExists(any(BucketExistsArgs.class))).thenReturn(true);
+ Assertions.assertTrue(testSubject.exists(VSP_ID));
+ }
+
+ @Test
+ void testIsExistsFail() throws Exception {
+ doThrow(new RuntimeException()).when(minioClient).bucketExists(any(BucketExistsArgs.class));
+ assertThrows(ArtifactStorageException.class, () -> {
+ Assertions.assertTrue(testSubject.exists(VSP_ID));
+ });
+ }
+
private Attachment mockAttachment() throws IOException {
final Attachment attachment = Mockito.mock(Attachment.class);
final DataHandler dataHandler = Mockito.mock(DataHandler.class);
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/NoneStorageManagerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/NoneStorageManagerTest.java
index 58394b9b76..994cbb541b 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/NoneStorageManagerTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/csar/storage/NoneStorageManagerTest.java
@@ -30,7 +30,9 @@ import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class NoneStorageManagerTest {
- public static final MinIoArtifactInfo UPLOADED_ARTIFACT_INFO = new MinIoArtifactInfo("bucket", "object");
+ public static final String VSP_ID = "vsp-id";
+ public static final String VERSION_ID = "version-id";
+ public static final MinIoArtifactInfo UPLOADED_ARTIFACT_INFO = new MinIoArtifactInfo(VSP_ID, VERSION_ID);
private NoneStorageManager testSubject;
@BeforeEach
@@ -46,13 +48,19 @@ class NoneStorageManagerTest {
@Test
void testPersist() {
Assertions.assertThrows(UnsupportedOperationException.class,
- () -> testSubject.persist("vspId", "versionId", UPLOADED_ARTIFACT_INFO));
+ () -> testSubject.persist(VSP_ID, VERSION_ID, UPLOADED_ARTIFACT_INFO));
}
@Test
void testUpload() {
Assertions.assertThrows(UnsupportedOperationException.class,
- () -> testSubject.upload("vspId", "versionId", new ByteArrayInputStream(new byte[0])));
+ () -> testSubject.upload(VSP_ID, VERSION_ID, new ByteArrayInputStream(new byte[0])));
+ }
+
+ @Test
+ void testPut() {
+ Assertions.assertThrows(UnsupportedOperationException.class,
+ () -> testSubject.put(VSP_ID, VERSION_ID, new ByteArrayInputStream(new byte[0])));
}
@Test
@@ -61,16 +69,31 @@ class NoneStorageManagerTest {
}
@Test
- void testGet() {
+ void testGetArtifactInfo() {
Assertions.assertThrows(UnsupportedOperationException.class, () -> testSubject.get(UPLOADED_ARTIFACT_INFO));
}
@Test
- void testDelete() {
+ void testGetString() {
+ Assertions.assertThrows(UnsupportedOperationException.class, () -> testSubject.get(VSP_ID, VERSION_ID));
+ }
+
+ @Test
+ void testDeleteArtifactInfo() {
Assertions.assertThrows(UnsupportedOperationException.class, () -> testSubject.delete(UPLOADED_ARTIFACT_INFO));
}
@Test
+ void testDeleteString() {
+ Assertions.assertThrows(UnsupportedOperationException.class, () -> testSubject.delete(VSP_ID));
+ }
+
+ @Test
+ void testIsExists() {
+ Assertions.assertThrows(UnsupportedOperationException.class, () -> testSubject.exists(VSP_ID));
+ }
+
+ @Test
void testIsEnabled() {
Assertions.assertFalse(testSubject.isEnabled());
}