Search in sources :

Example 1 with Response

use of com.azure.core.http.rest.Response in project ambry by linkedin.

the class StorageClient method deleteBatchAsync.

/**
 * Deletes a list of blobs asynchronously. This method will block for now until classes like
 * {@link com.github.ambry.cloud.CloudDestination} are refactored to handle responses asynchronously.
 * @param batchOfBlobs {@link List} of {@link CloudBlobMetadata} objects.
 * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised.
 * @return {@link List} of {@link Response}s for the blobs in the batch.
 * @throws RuntimeException If the {@code timeout} duration completes before a response is returned.
 * @throws BlobStorageException If the batch request is malformed.
 * @throws BlobBatchStorageException If {@code throwOnAnyFailure} is {@code true} and any request in the
 * {@link BlobBatch} failed.
 */
public List<Response<Void>> deleteBatchAsync(List<CloudBlobMetadata> batchOfBlobs, Duration timeout) {
    List<Response<Void>> responseList = new ArrayList<>();
    doStorageClientOperation(() -> {
        BlobBatch blobBatch = blobBatchAsyncClientRef.get().getBlobBatch();
        for (CloudBlobMetadata blobMetadata : batchOfBlobs) {
            AzureBlobLayoutStrategy.BlobLayout blobLayout = blobLayoutStrategy.getDataBlobLayout(blobMetadata);
            responseList.add(blobBatch.deleteBlob(blobLayout.containerName, blobLayout.blobFilePath));
        }
        blobBatchAsyncClientRef.get().submitBatchWithResponse(blobBatch, false).toFuture().get(timeout.toMillis(), TimeUnit.MILLISECONDS);
        return null;
    });
    return responseList;
}
Also used : Response(com.azure.core.http.rest.Response) CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) ArrayList(java.util.ArrayList) BlobBatch(com.azure.storage.blob.batch.BlobBatch)

Example 2 with Response

use of com.azure.core.http.rest.Response in project ambry by linkedin.

the class StorageClient method deleteBatch.

/**
 * Deletes a list of blobs.
 * @param batchOfBlobs {@link List} of {@link CloudBlobMetadata} objects.
 * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised.
 * @return {@link List} of {@link Response}s for the blobs in the batch.
 * @throws RuntimeException If the {@code timeout} duration completes before a response is returned.
 * @throws BlobStorageException If the batch request is malformed.
 * @throws BlobBatchStorageException If {@code throwOnAnyFailure} is {@code true} and any request in the
 * {@link BlobBatch} failed.
 */
public List<Response<Void>> deleteBatch(List<CloudBlobMetadata> batchOfBlobs, Duration timeout) {
    if (azureCloudConfig.useAsyncAzureAPIs) {
        return deleteBatchAsync(batchOfBlobs, timeout);
    }
    List<Response<Void>> responseList = new ArrayList<>();
    doStorageClientOperation(() -> {
        BlobBatch blobBatch = blobBatchClientRef.get().getBlobBatch();
        for (CloudBlobMetadata blobMetadata : batchOfBlobs) {
            AzureBlobLayoutStrategy.BlobLayout blobLayout = blobLayoutStrategy.getDataBlobLayout(blobMetadata);
            responseList.add(blobBatch.deleteBlob(blobLayout.containerName, blobLayout.blobFilePath));
        }
        blobBatchClientRef.get().submitBatchWithResponse(blobBatch, false, timeout, Context.NONE);
        return null;
    });
    return responseList;
}
Also used : Response(com.azure.core.http.rest.Response) CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) ArrayList(java.util.ArrayList) BlobBatch(com.azure.storage.blob.batch.BlobBatch)

Example 3 with Response

use of com.azure.core.http.rest.Response in project ambry by linkedin.

the class AzureBlobDataAccessor method purgeBlobs.

/**
 * Permanently delete the specified blobs in Azure storage.
 * @param blobMetadataList the list of {@link CloudBlobMetadata} referencing the blobs to purge.
 * @return list of {@link CloudBlobMetadata} referencing the blobs successfully purged.
 * @throws BlobStorageException if the purge operation fails.
 * @throws RuntimeException if the request times out before a response is received.
 */
public List<CloudBlobMetadata> purgeBlobs(List<CloudBlobMetadata> blobMetadataList) throws BlobStorageException {
    List<CloudBlobMetadata> deletedBlobs = new ArrayList<>();
    List<List<CloudBlobMetadata>> partitionedLists = Utils.partitionList(blobMetadataList, purgeBatchSize);
    for (List<CloudBlobMetadata> batchOfBlobs : partitionedLists) {
        List<Response<Void>> responseList = storageClient.deleteBatch(batchOfBlobs, batchTimeout);
        for (int j = 0; j < responseList.size(); j++) {
            Response<Void> response = responseList.get(j);
            CloudBlobMetadata blobMetadata = batchOfBlobs.get(j);
            // Note: Response.getStatusCode() throws exception on any error.
            try {
                response.getStatusCode();
            } catch (BlobStorageException bex) {
                int statusCode = bex.getStatusCode();
                // Don't worry if blob is already gone
                if (statusCode != HttpURLConnection.HTTP_NOT_FOUND && statusCode != HttpURLConnection.HTTP_GONE) {
                    logger.error("Deleting blob {} got status {}", blobMetadata.getId(), statusCode);
                    throw bex;
                }
            }
            deletedBlobs.add(blobMetadata);
        }
    }
    return deletedBlobs;
}
Also used : Response(com.azure.core.http.rest.Response) CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BlobStorageException(com.azure.storage.blob.models.BlobStorageException)

Aggregations

Response (com.azure.core.http.rest.Response)3 CloudBlobMetadata (com.github.ambry.cloud.CloudBlobMetadata)3 ArrayList (java.util.ArrayList)3 BlobBatch (com.azure.storage.blob.batch.BlobBatch)2 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)1 List (java.util.List)1