Commit 5dd68db0 authored by MANISH KUMAR's avatar MANISH KUMAR
Browse files

Merge branch 'containerCreationAndDeletion' into 'master'

Container creation and deletion in BlobStore

See merge request !71
parents aa76045d 3f7a0f83
Pipeline #35047 passed with stages
in 3 minutes and 3 seconds
......@@ -200,6 +200,44 @@ public class BlobStore {
}
}
/**
* @param dataPartitionId Data partition id
* @param containerName Name of the storage container
* @return boolean indicating whether the creation of the given container was successful or not.
* Throws exception in case of failure.
*/
public boolean createBlobContainer(
final String dataPartitionId,
final String containerName) {
BlobServiceClient blobServiceClient = blobServiceClientFactory.getBlobServiceClient(dataPartitionId);
try {
blobServiceClient.createBlobContainer(containerName);
CoreLoggerFactory.getInstance().getLogger(LOGGER_NAME).info("{}", MessageFormatter.format("Done creating container with name {}", containerName).getMessage());
return true;
} catch (BlobStorageException ex) {
throw handleBlobStoreException(500, "Failed to create blob container", ex);
}
}
/**
* @param dataPartitionId Data partition id
* @param containerName Name of the storage container
* @return boolean indicating whether the deletion of the given container was successful or not.
* Throws exception in case of failure.
*/
public boolean deleteBlobContainer(
final String dataPartitionId,
final String containerName) {
BlobServiceClient blobServiceClient = blobServiceClientFactory.getBlobServiceClient(dataPartitionId);
try {
blobServiceClient.deleteBlobContainer(containerName);
CoreLoggerFactory.getInstance().getLogger(LOGGER_NAME).info("{}", MessageFormatter.format("Done deleting container with name {}", containerName).getMessage());
return true;
} catch (BlobStorageException ex) {
throw handleBlobStoreException(500, "Failed to delete blob container", ex);
}
}
/**
* @param dataPartitionId Data partition id
* @param filePath Path of file (blob) for which SAS token needs to be generated
......
......@@ -312,6 +312,58 @@ public class BlobStoreTest {
assertEquals(copyInfo, null);
}
@Test
public void createBlobContainer_Failure() {
BlobStorageException exception = mockStorageException(BlobErrorCode.INTERNAL_ERROR);
doThrow(exception).when(blobServiceClient).createBlobContainer(anyString());
String containerName = "containerName";
try {
blobStore.createBlobContainer(PARTITION_ID, containerName);
} catch (AppException ex) {
assertEquals(500, ex.getError().getCode());
} catch (Exception ex) {
fail("should not get different error code");
}
}
@Test
public void createBlobContainer_Success() {
String containerName = "containerName";
boolean status = blobStore.createBlobContainer(PARTITION_ID, containerName);
ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
verify(blobServiceClient).createBlobContainer(containerNameCaptor.capture());
assertEquals(containerNameCaptor.getValue(), containerName);
assertEquals(status, true);
}
@Test
public void deleteBlobContainer_Failure() {
BlobStorageException exception = mockStorageException(BlobErrorCode.INTERNAL_ERROR);
doThrow(exception).when(blobServiceClient).deleteBlobContainer(anyString());
String containerName = "containerName";
try {
blobStore.deleteBlobContainer(PARTITION_ID, containerName);
} catch (AppException ex) {
assertEquals(500, ex.getError().getCode());
} catch (Exception ex) {
fail("should not get different error code");
}
}
@Test
public void deleteBlobContainer_Success() {
String containerName = "containerName";
boolean status = blobStore.deleteBlobContainer(PARTITION_ID, containerName);
ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
verify(blobServiceClient).deleteBlobContainer(containerNameCaptor.capture());
assertEquals(containerNameCaptor.getValue(), containerName);
assertEquals(status, true);
}
@Test
public void getSasToken_NullSasTokenObtained() {
int expiryDays = 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment