com.azure.storage.blob.models.BlobStorageException Java Examples
The following examples show how to use
com.azure.storage.blob.models.BlobStorageException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzureStorageCompactorTest.java From ambry with Apache License 2.0 | 6 votes |
private void mockCheckpointDownload(boolean exists, String checkpointValue) throws IOException { when(mockBlockBlobClient.exists()).thenReturn(exists); if (exists) { BlobDownloadResponse mockResponse = mock(BlobDownloadResponse.class); when(mockBlockBlobClient.downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any())).thenAnswer( invocation -> { OutputStream outputStream = invocation.getArgument(0); if (outputStream != null) { outputStream.write(checkpointValue.getBytes()); } return mockResponse; }); } else { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND); doThrow(ex).when(mockBlockBlobClient) .downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any()); } }
Example #2
Source File: AzureTokenResetTool.java From ambry with Apache License 2.0 | 6 votes |
/** * Reset the offset token by deleting the blob from the container. * @param containerPrefix the prefix used to filter on Azure containers * (in case the storage account hosts multiple Ambry clusters). * @return the number of tokens successfully reset. */ public static int resetTokens(String containerPrefix) throws BlobStorageException { AtomicInteger tokensDeleted = new AtomicInteger(0); ListBlobContainersOptions listOptions = new ListBlobContainersOptions().setPrefix(containerPrefix); storageClient.listBlobContainers(listOptions, null).iterator().forEachRemaining(blobContainer -> { BlockBlobClient blobClient = storageClient.getBlobContainerClient(blobContainer.getName()) .getBlobClient(ReplicationConfig.REPLICA_TOKEN_FILE_NAME) .getBlockBlobClient(); try { if (blobClient.exists()) { blobClient.delete(); tokensDeleted.incrementAndGet(); logger.info("Deleted token for partition {}", blobContainer.getName()); } } catch (Exception ex) { logger.error("Failed delete for {}", blobContainer.getName(), ex); } }); return tokensDeleted.get(); }
Example #3
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 6 votes |
/** Test delete when record is in Cosmos but not ABS. */ @Test public void testDeleteAfterPartialCompaction() throws Exception { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND); when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenThrow(ex); // Rig Cosmos to return us a deleted blob on read request long deletionTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(10); CloudBlobMetadata deletedMetadata = new CloudBlobMetadata().setId(blobId.getID()).setDeletionTime(deletionTime); Observable<ResourceResponse<Document>> mockResponse = getMockedObservableForSingleResource(deletedMetadata); when(mockumentClient.readDocument(anyString(), any(RequestOptions.class))).thenReturn(mockResponse); // Now delete the puppy, Cosmos record should get purged. try { assertFalse("Expected update to recover and return false", azureDest.deleteBlob(blobId, deletionTime, (short) 0, dummyCloudUpdateValidator)); } catch (CloudStorageException cex) { assertTrue(cex.getCause() instanceof BlobStorageException); assertEquals(((BlobStorageException) cex.getCause()).getErrorCode(), BlobErrorCode.BLOB_NOT_FOUND); } assertEquals("Expected recovery", 1, azureMetrics.blobUpdateRecoverCount.getCount()); verify(mockumentClient).deleteDocument(anyString(), any()); }
Example #4
Source File: AzureStorageCompactorTest.java From ambry with Apache License 2.0 | 6 votes |
/** Test compaction progress methods, error cases */ @Test public void testCheckpointErrors() throws Exception { // Corrupted checkpoint mockCheckpointDownload(true, "You can't do this!"); Map<String, Long> checkpoints = azureStorageCompactor.getCompactionProgress(partitionPath); assertEquals(AzureStorageCompactor.emptyCheckpoints, checkpoints); assertEquals(1, azureMetrics.compactionProgressReadErrorCount.getCount()); // Upload error mockCheckpointDownload(false, null); BlobStorageException ex = mockStorageException(BlobErrorCode.CONTAINER_DISABLED); when(mockBlockBlobClient.uploadWithResponse(any(), anyLong(), any(), any(), any(), any(), any(), any(), any())).thenThrow(ex); long now = System.currentTimeMillis(); azureStorageCompactor.updateCompactionProgress(partitionPath, CloudBlobMetadata.FIELD_DELETION_TIME, now); assertEquals(1, azureMetrics.compactionProgressWriteErrorCount.getCount()); }
Example #5
Source File: AzureStorageCompactorTest.java From ambry with Apache License 2.0 | 6 votes |
/** Test purgeBlobs with ABS error */ @Test public void testPurgeWithStorageError() throws Exception { // Unsuccessful case BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_ARCHIVED); BlobBatch mockBatch = mock(BlobBatch.class); Response<Void> mockResponse = mock(Response.class); when(mockResponse.getStatusCode()).thenThrow(ex); when(mockBlobBatchClient.getBlobBatch()).thenReturn(mockBatch); when(mockBatch.deleteBlob(anyString(), anyString())).thenReturn(mockResponse); try { azureStorageCompactor.purgeBlobs(blobMetadataList); fail("Expected CloudStorageException"); } catch (CloudStorageException bex) { } assertEquals(0, azureMetrics.blobDeletedCount.getCount()); assertEquals(numBlobsPerQuery, azureMetrics.blobDeleteErrorCount.getCount()); }
Example #6
Source File: AzureCloudDestination.java From ambry with Apache License 2.0 | 6 votes |
static CloudStorageException toCloudStorageException(String message, Exception e, AzureMetrics azureMetrics) { Long retryDelayMs = null; int statusCode; if (e instanceof BlobStorageException) { azureMetrics.storageErrorCount.inc(); statusCode = ((BlobStorageException) e).getStatusCode(); } else if (e instanceof DocumentClientException) { azureMetrics.documentErrorCount.inc(); statusCode = ((DocumentClientException) e).getStatusCode(); retryDelayMs = ((DocumentClientException) e).getRetryAfterInMilliseconds(); } else { // Note: catch-all since ABS can throw things like IOException, IllegalStateException azureMetrics.storageErrorCount.inc(); statusCode = StatusCodes.INTERNAL_SERVER_ERROR; } // Everything is retryable except NOT_FOUND boolean isRetryable = (statusCode != StatusCodes.NOTFOUND && !(e instanceof StoreException)); return new CloudStorageException(message, e, statusCode, isRetryable, retryDelayMs); }
Example #7
Source File: AzureBlobDataAccessor.java From ambry with Apache License 2.0 | 6 votes |
/** * Get a reference to an Azure container, creating it if necessary. * @param containerName the container name. * @param autoCreate flag indicating whether to create the container if it does not exist. * @return the created {@link BlobContainerClient}. */ private BlobContainerClient getContainer(String containerName, boolean autoCreate) { BlobContainerClient containerClient = storageClient.getBlobContainerClient(containerName); if (autoCreate) { if (!knownContainers.contains(containerName)) { try { if (!containerClient.exists()) { containerClient.create(); logger.info("Created container {}", containerName); } } catch (BlobStorageException ex) { if (ex.getErrorCode() != BlobErrorCode.CONTAINER_ALREADY_EXISTS) { logger.error("Failed to create container {}", containerName); throw ex; } } knownContainers.add(containerName); } } return containerClient; }
Example #8
Source File: AzureBlobDataAccessor.java From ambry with Apache License 2.0 | 6 votes |
/** * Retrieve the metadata for the specified blob. * @param blobId The {@link BlobId} to retrieve. * @return The {@link CloudBlobMetadata} if the blob was found, or null otherwise. * @throws BlobStorageException */ public CloudBlobMetadata getBlobMetadata(BlobId blobId) throws BlobStorageException { BlockBlobClient blobClient = getBlockBlobClient(blobId, false); BlobProperties blobProperties = null; try { blobProperties = blobClient.getPropertiesWithResponse(defaultRequestConditions, requestTimeout, Context.NONE).getValue(); if (blobProperties == null) { logger.debug("Blob {} not found.", blobId); return null; } } catch (BlobStorageException e) { if (isNotFoundError(e.getErrorCode())) { logger.debug("Blob {} not found.", blobId); return null; } throw e; } Map<String, String> metadata = blobProperties.getMetadata(); return CloudBlobMetadata.fromMap(metadata); }
Example #9
Source File: AzureBlobDataAccessor.java From ambry with Apache License 2.0 | 6 votes |
/** * Download a file from blob storage. * @param containerName name of the container containing blob to download. * @param fileName name of the blob. * @param outputStream the output stream to use for download. * @param errorOnNotFound If {@code true}, throw BlobStorageException on blob not found, otherwise return false. * @return {@code true} if the download was successful, {@code false} if the blob was not found. * @throws BlobStorageException for any error on ABS side. * @throws UncheckedIOException for any error with supplied data stream. */ public boolean downloadFile(String containerName, String fileName, OutputStream outputStream, boolean errorOnNotFound) throws BlobStorageException { try { BlockBlobClient blobClient = getBlockBlobClient(containerName, fileName, false); // Might as well use same timeout for upload and download blobClient.downloadWithResponse(outputStream, null, null, defaultRequestConditions, false, uploadTimeout, Context.NONE); return true; } catch (BlobStorageException e) { if (!errorOnNotFound && isNotFoundError(e.getErrorCode())) { return false; } else { throw e; } } }
Example #10
Source File: AzureBlobSystemProducer.java From samza with Apache License 2.0 | 6 votes |
private void createContainerIfNotExists(BlobContainerAsyncClient containerClient) { try { containerClient.create().block(); } catch (BlobStorageException e) { //StorageErrorCode defines constants corresponding to all error codes returned by the service. if (e.getErrorCode() == BlobErrorCode.RESOURCE_NOT_FOUND) { HttpResponse response = e.getResponse(); LOG.error("Error creating the container url " + containerClient.getBlobContainerUrl().toString() + " with status code: " + response.getStatusCode(), e); } else if (e.getErrorCode() == BlobErrorCode.CONTAINER_BEING_DELETED) { LOG.error("Container is being deleted. Container URL is: " + containerClient.getBlobContainerUrl().toString(), e); } else if (e.getErrorCode() == BlobErrorCode.CONTAINER_ALREADY_EXISTS) { return; } throw e; } }
Example #11
Source File: AzureBlobPayloadStorage.java From conductor with Apache License 2.0 | 6 votes |
/** * Downloads the payload stored in an azure blob. * * @param path the path of the blob * @return an input stream containing the contents of the object * Caller is expected to close the input stream. */ @Override public InputStream download(String path) { try { BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(path).getBlockBlobClient(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // Avoid another call to the api to get the blob size // ByteArrayOutputStream outputStream = new ByteArrayOutputStream(blockBlobClient.getProperties().value().blobSize()); blockBlobClient.download(outputStream); return new ByteArrayInputStream(outputStream.toByteArray()); } catch (BlobStorageException | UncheckedIOException | NullPointerException e) { String msg = "Error communicating with Azure"; logger.error(msg, e); throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e); } }
Example #12
Source File: AzureBlobDataAccessor.java From ambry with Apache License 2.0 | 5 votes |
/** * Download the blob from Azure storage. * @param blobId id of the Ambry blob to be downloaded * @param outputStream outputstream to populate the downloaded data with * @throws BlobStorageException on Azure side error. * @throws UncheckedIOException on error writing to the output stream. */ public void downloadBlob(BlobId blobId, OutputStream outputStream) throws BlobStorageException { azureMetrics.blobDownloadRequestCount.inc(); Timer.Context storageTimer = azureMetrics.blobDownloadTime.time(); try { BlobLayout blobLayout = blobLayoutStrategy.getDataBlobLayout(blobId); downloadFile(blobLayout.containerName, blobLayout.blobFilePath, outputStream, true); azureMetrics.blobDownloadSuccessCount.inc(); } catch (Exception e) { azureMetrics.blobDownloadErrorCount.inc(); throw e; } finally { storageTimer.stop(); } }
Example #13
Source File: AzureBlobDataAccessorTest.java From ambry with Apache License 2.0 | 5 votes |
/** * Utility method to run some code and verify the expected exception was thrown. * @param runnable the code to run. */ private void expectBlobStorageException(TestUtils.ThrowingRunnable runnable) throws Exception { try { runnable.run(); fail("Expected BlobStorageException"); } catch (BlobStorageException e) { } }
Example #14
Source File: AzureBlobDataAccessorTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test update of nonexistent blob. */ @Test public void testUpdateNotExists() throws Exception { BlobStorageException ex = mock(BlobStorageException.class); when(ex.getErrorCode()).thenReturn(BlobErrorCode.BLOB_NOT_FOUND); when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenThrow(ex); expectBlobStorageException( () -> dataAccessor.updateBlobMetadata(blobId, Collections.singletonMap("expirationTime", expirationTime), eq(dummyCloudUpdateValidator))); }
Example #15
Source File: AzureBlobDataAccessorTest.java From ambry with Apache License 2.0 | 5 votes |
/** * Test download of non existent blob * @throws Exception */ @Test public void testDownloadNotExists() throws Exception { doThrow(BlobStorageException.class).when(mockBlockBlobClient) .downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any()); expectBlobStorageException(() -> downloadBlob(blobId)); }
Example #16
Source File: AzureBlobDataAccessorTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test upload of existing blob. */ @Test public void testUploadExists() throws Exception { BlobStorageException ex = mock(BlobStorageException.class); when(ex.getErrorCode()).thenReturn(BlobErrorCode.BLOB_ALREADY_EXISTS); when(mockBlockBlobClient.uploadWithResponse(any(), anyLong(), any(), any(), any(), any(), any(), any(), any())).thenThrow(ex); assertFalse("Upload of existing blob should return false", uploadDefaultBlob()); assertEquals(1, azureMetrics.blobUploadRequestCount.getCount()); assertEquals(0, azureMetrics.blobUploadSuccessCount.getCount()); assertEquals(1, azureMetrics.blobUploadConflictCount.getCount()); assertEquals(0, azureMetrics.backupErrorCount.getCount()); }
Example #17
Source File: AzureBlobDataAccessorTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test purge */ @Test public void testPurge() throws Exception { // purge 3 blobs, response status (202, 404, 503) String blobNameOkStatus = "andromeda"; String blobNameNotFoundStatus = "sirius"; String blobNameErrorStatus = "mutant"; BlobBatch mockBatch = mock(BlobBatch.class); when(mockBatchClient.getBlobBatch()).thenReturn(mockBatch); Response<Void> okResponse = mock(Response.class); when(okResponse.getStatusCode()).thenReturn(202); when(mockBatch.deleteBlob(anyString(), endsWith(blobNameOkStatus))).thenReturn(okResponse); BlobStorageException notFoundException = mock(BlobStorageException.class); when(notFoundException.getStatusCode()).thenReturn(404); Response<Void> notFoundResponse = mock(Response.class); when(notFoundResponse.getStatusCode()).thenThrow(notFoundException); when(mockBatch.deleteBlob(anyString(), endsWith(blobNameNotFoundStatus))).thenReturn(notFoundResponse); BlobStorageException badException = mock(BlobStorageException.class); when(badException.getStatusCode()).thenReturn(503); Response<Void> badResponse = mock(Response.class); when(badResponse.getStatusCode()).thenThrow(badException); when(mockBatch.deleteBlob(anyString(), endsWith(blobNameErrorStatus))).thenReturn(badResponse); List<CloudBlobMetadata> purgeList = new ArrayList<>(); purgeList.add(new CloudBlobMetadata().setId(blobNameOkStatus)); purgeList.add(new CloudBlobMetadata().setId(blobNameNotFoundStatus)); // Purge first 2 and expect success List<CloudBlobMetadata> purgeResponseList = dataAccessor.purgeBlobs(purgeList); assertEquals("Wrong response size", 2, purgeResponseList.size()); assertEquals("Wrong blob name", blobNameOkStatus, purgeResponseList.get(0).getId()); assertEquals("Wrong blob name", blobNameNotFoundStatus, purgeResponseList.get(1).getId()); // Including last one should fail purgeList.add(new CloudBlobMetadata().setId(blobNameErrorStatus)); try { dataAccessor.purgeBlobs(purgeList); fail("Expected purge to fail"); } catch (BlobStorageException bex) { assertEquals("Unexpected status code", 503, bex.getStatusCode()); } }
Example #18
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
private void mockBlobExistence(boolean exists) { when(mockBlockBlobClient.exists()).thenReturn(exists); if (exists) { BlobDownloadResponse mockResponse = mock(BlobDownloadResponse.class); doReturn(mockResponse).when(mockBlockBlobClient) .downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any()); } else { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND); doThrow(ex).when(mockBlockBlobClient) .downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any()); } }
Example #19
Source File: AzureBlobPayloadStorage.java From conductor with Apache License 2.0 | 5 votes |
/** * Uploads the payload to the given azure blob name. * It is expected that the caller retrieves the blob name * using {@link #getLocation(Operation, PayloadType, String)} before making this call. * * @param path the name of the blob to be uploaded * @param payload an {@link InputStream} containing the json payload which is to be uploaded * @param payloadSize the size of the json payload in bytes */ @Override public void upload(String path, InputStream payload, long payloadSize) { try { BlockBlobClient blockBlobClient = blobContainerClient.getBlobClient(path).getBlockBlobClient(); BlobHttpHeaders blobHttpHeaders = new BlobHttpHeaders() .setContentType(CONTENT_TYPE); blockBlobClient.uploadWithResponse(payload, payloadSize, blobHttpHeaders, null, null, null, null, null, Context.NONE); } catch (BlobStorageException | UncheckedIOException | UnexpectedLengthException e) { String msg = "Error communicating with Azure"; logger.error(msg, e); throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, msg, e); } }
Example #20
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test update methods when ABS throws exception. */ @Test public void testUpdateBlobException() { BlobStorageException ex = mockStorageException(BlobErrorCode.INTERNAL_ERROR); when(mockBlockBlobClient.setMetadataWithResponse(any(), any(), any(), any())).thenThrow(ex); expectCloudStorageException(() -> azureDest.deleteBlob(blobId, deletionTime, (short) 0, dummyCloudUpdateValidator), BlobStorageException.class); expectCloudStorageException(() -> azureDest.updateBlobExpiration(blobId, expirationTime, dummyCloudUpdateValidator), BlobStorageException.class); expectCloudStorageException(() -> azureDest.undeleteBlob(blobId, (short) 0, dummyCloudUpdateValidator), BlobStorageException.class); verifyUpdateErrorMetrics(3, false); }
Example #21
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test update of nonexistent blob. */ @Test public void testUpdateBlobNotFound() { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND); when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenThrow(ex); expectCloudStorageException(() -> azureDest.updateBlobExpiration(blobId, expirationTime, dummyCloudUpdateValidator), BlobStorageException.class); assertEquals(1, azureMetrics.blobUpdateErrorCount.getCount()); assertEquals(1, azureMetrics.storageErrorCount.getCount()); }
Example #22
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test undelete of nonexistent blob. */ @Test public void testUndeleteBlobNotFound() { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND); when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenThrow(ex); expectCloudStorageException(() -> azureDest.undeleteBlob(blobId, (short) 0, dummyCloudUpdateValidator), BlobStorageException.class); assertEquals(1, azureMetrics.blobUpdateErrorCount.getCount()); assertEquals(1, azureMetrics.storageErrorCount.getCount()); }
Example #23
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test delete of nonexistent blob. */ @Test public void testDeleteBlobNotFound() { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND); when(mockBlockBlobClient.getPropertiesWithResponse(any(), any(), any())).thenThrow(ex); expectCloudStorageException(() -> azureDest.deleteBlob(blobId, deletionTime, (short) 0, dummyCloudUpdateValidator), BlobStorageException.class); assertEquals(1, azureMetrics.blobUpdateErrorCount.getCount()); assertEquals(1, azureMetrics.storageErrorCount.getCount()); }
Example #24
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test download when blob throws exception. */ @Test public void testDownloadBlobException() throws Exception { BlobStorageException ex = mockStorageException(BlobErrorCode.INTERNAL_ERROR); doThrow(ex).when(mockBlockBlobClient).downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any()); expectCloudStorageException(() -> downloadBlob(blobId), BlobStorageException.class); verifyDownloadErrorMetrics(); }
Example #25
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** * Test download of non existent blob * @throws Exception */ @Test public void testDownloadNotFound() throws Exception { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_NOT_FOUND); doThrow(ex).when(mockBlockBlobClient).downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any()); expectCloudStorageException(() -> downloadBlob(blobId), BlobStorageException.class); verifyDownloadErrorMetrics(); }
Example #26
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test upload when blob throws exception. */ @Test public void testUploadBlobException() throws Exception { BlobStorageException ex = mockStorageException(BlobErrorCode.INTERNAL_ERROR); when(mockBlockBlobClient.uploadWithResponse(any(), anyLong(), any(), any(), any(), any(), any(), any(), any())).thenThrow(ex); expectCloudStorageException(() -> uploadDefaultBlob(), BlobStorageException.class); verifyUploadErrorMetrics(false); }
Example #27
Source File: AzureCloudDestinationTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test upload of existing blob. */ @Test public void testUploadExists() throws Exception { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_ALREADY_EXISTS); when(mockBlockBlobClient.uploadWithResponse(any(), anyLong(), any(), any(), any(), any(), any(), any(), any())).thenThrow(ex); assertFalse("Upload of existing blob should return false", uploadDefaultBlob()); assertEquals(1, azureMetrics.blobUploadRequestCount.getCount()); assertEquals(0, azureMetrics.blobUploadSuccessCount.getCount()); assertEquals(1, azureMetrics.blobUploadConflictCount.getCount()); assertEquals(0, azureMetrics.backupErrorCount.getCount()); // Make sure the metadata doc was created assertEquals(1, azureMetrics.documentCreateTime.getCount()); }
Example #28
Source File: BlobStorageOperations.java From ats-framework with Apache License 2.0 | 5 votes |
/** * Delete existing container * @param containerName - the container name * @param timeoutSec - the maximum amount of time (in seconds) to wait for container to be deleted. * @throws AtsBlobStorageException - if exception occurred * */ @PublicAtsApi public void deleteContainer( String containerName, long timeoutSec ) { long startTime = System.currentTimeMillis(); long timeoutMs = timeoutSec * 1000; BlobStorageException lastException = null; while (System.currentTimeMillis() - startTime <= timeoutMs) { try { this.deleteContainer(containerName); if (!this.doesContainerExist(containerName)) { return; } } catch (BlobStorageException bse) { lastException = bse; } try { Thread.sleep(1000); } catch (InterruptedException e) {} } throw new AtsBlobStorageException("Could not delete container '" + containerName + "' in " + timeoutSec + " seconds", lastException); }
Example #29
Source File: AzureStorageCompactorTest.java From ambry with Apache License 2.0 | 5 votes |
/** Test compaction on error reading checkpoint. */ @Test public void testCompactionFailsOnCheckpointReadError() throws Exception { BlobStorageException ex = mockStorageException(BlobErrorCode.INTERNAL_ERROR); when(mockBlockBlobClient.downloadWithResponse(any(), any(), any(), any(), anyBoolean(), any(), any())).thenThrow( ex); try { azureStorageCompactor.compactPartition(partitionPath); fail("Expected compaction to fail"); } catch (CloudStorageException cse) { // expected } }
Example #30
Source File: AzureBlobDataAccessor.java From ambry with Apache License 2.0 | 5 votes |
/** * Upload a file to blob storage. Any existing file with the same name will be replaced. * @param containerName name of the container where blob is stored. * @param fileName the blob filename. * @param inputStream the input stream to use for upload. * @throws BlobStorageException for any error on ABS side. * @throws IOException for any error with supplied data stream. */ public void uploadFile(String containerName, String fileName, InputStream inputStream) throws BlobStorageException, IOException { try { BlockBlobClient blobClient = getBlockBlobClient(containerName, fileName, true); blobClient.uploadWithResponse(inputStream, inputStream.available(), null, null, null, null, defaultRequestConditions, uploadTimeout, Context.NONE); } catch (UncheckedIOException e) { // error processing input stream throw e.getCause(); } }