Class AzureBlobDataAccessor


  • public class AzureBlobDataAccessor
    extends java.lang.Object
    Data accessor class for Azure Blob Storage.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void downloadBlob​(com.github.ambry.commons.BlobId blobId, java.io.OutputStream outputStream)
      Download the blob from Azure storage.
      boolean downloadFile​(java.lang.String containerName, java.lang.String fileName, java.io.OutputStream outputStream, boolean errorOnNotFound)
      Download a file from blob storage.
      CloudBlobMetadata getBlobMetadata​(com.github.ambry.commons.BlobId blobId)
      Retrieve the metadata for the specified blob.
      com.azure.storage.blob.BlobServiceClient getStorageClient()
      Visible for testing.
      java.util.List<CloudBlobMetadata> purgeBlobs​(java.util.List<CloudBlobMetadata> blobMetadataList)
      Permanently delete the specified blobs in Azure storage.
      com.github.ambry.cloud.azure.AzureCloudDestination.UpdateResponse updateBlobMetadata​(com.github.ambry.commons.BlobId blobId, java.util.Map<java.lang.String,​java.lang.Object> updateFields, CloudUpdateValidator cloudUpdateValidator)
      Update the metadata for the specified blob.
      void uploadFile​(java.lang.String containerName, java.lang.String fileName, java.io.InputStream inputStream)
      Upload a file to blob storage.
      boolean uploadIfNotExists​(com.github.ambry.commons.BlobId blobId, long inputLength, CloudBlobMetadata cloudBlobMetadata, java.io.InputStream blobInputStream)
      Upload the blob to Azure storage if it does not already exist in the designated container.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AzureBlobDataAccessor

        public AzureBlobDataAccessor​(com.github.ambry.config.CloudConfig cloudConfig,
                                     AzureCloudConfig azureCloudConfig,
                                     AzureBlobLayoutStrategy blobLayoutStrategy,
                                     AzureMetrics azureMetrics)
                              throws java.lang.ReflectiveOperationException
        Production constructor
        Parameters:
        cloudConfig - the CloudConfig to use.
        azureCloudConfig - the AzureCloudConfig to use.
        blobLayoutStrategy - the AzureBlobLayoutStrategy to use.
        azureMetrics - the AzureMetrics to use.
        Throws:
        java.lang.ReflectiveOperationException
    • Method Detail

      • getStorageClient

        public com.azure.storage.blob.BlobServiceClient getStorageClient()
        Visible for testing.
        Returns:
        the underlying BlobServiceClient.
      • uploadIfNotExists

        public boolean uploadIfNotExists​(com.github.ambry.commons.BlobId blobId,
                                         long inputLength,
                                         CloudBlobMetadata cloudBlobMetadata,
                                         java.io.InputStream blobInputStream)
                                  throws com.azure.storage.blob.models.BlobStorageException,
                                         java.io.IOException
        Upload the blob to Azure storage if it does not already exist in the designated container.
        Parameters:
        blobId - the blobId to upload
        inputLength - the input stream length, if known (-1 if not)
        cloudBlobMetadata - the blob metadata
        blobInputStream - the input stream
        Returns:
        true if the upload was successful, false if the blob already exists.
        Throws:
        com.azure.storage.blob.models.BlobStorageException - for any error on ABS side.
        java.io.IOException - for any error with supplied data stream.
      • uploadFile

        public void uploadFile​(java.lang.String containerName,
                               java.lang.String fileName,
                               java.io.InputStream inputStream)
                        throws com.azure.storage.blob.models.BlobStorageException,
                               java.io.IOException
        Upload a file to blob storage. Any existing file with the same name will be replaced.
        Parameters:
        containerName - name of the container where blob is stored.
        fileName - the blob filename.
        inputStream - the input stream to use for upload.
        Throws:
        com.azure.storage.blob.models.BlobStorageException - for any error on ABS side.
        java.io.IOException - for any error with supplied data stream.
      • downloadFile

        public boolean downloadFile​(java.lang.String containerName,
                                    java.lang.String fileName,
                                    java.io.OutputStream outputStream,
                                    boolean errorOnNotFound)
                             throws com.azure.storage.blob.models.BlobStorageException
        Download a file from blob storage.
        Parameters:
        containerName - name of the container containing blob to download.
        fileName - name of the blob.
        outputStream - the output stream to use for download.
        errorOnNotFound - If true, throw BlobStorageException on blob not found, otherwise return false.
        Returns:
        true if the download was successful, false if the blob was not found.
        Throws:
        com.azure.storage.blob.models.BlobStorageException - for any error on ABS side.
        java.io.UncheckedIOException - for any error with supplied data stream.
      • downloadBlob

        public void downloadBlob​(com.github.ambry.commons.BlobId blobId,
                                 java.io.OutputStream outputStream)
                          throws com.azure.storage.blob.models.BlobStorageException
        Download the blob from Azure storage.
        Parameters:
        blobId - id of the Ambry blob to be downloaded
        outputStream - outputstream to populate the downloaded data with
        Throws:
        com.azure.storage.blob.models.BlobStorageException - on Azure side error.
        java.io.UncheckedIOException - on error writing to the output stream.
      • getBlobMetadata

        public CloudBlobMetadata getBlobMetadata​(com.github.ambry.commons.BlobId blobId)
                                          throws com.azure.storage.blob.models.BlobStorageException
        Retrieve the metadata for the specified blob.
        Parameters:
        blobId - The BlobId to retrieve.
        Returns:
        The CloudBlobMetadata if the blob was found, or null otherwise.
        Throws:
        com.azure.storage.blob.models.BlobStorageException
      • updateBlobMetadata

        public com.github.ambry.cloud.azure.AzureCloudDestination.UpdateResponse updateBlobMetadata​(com.github.ambry.commons.BlobId blobId,
                                                                                                    java.util.Map<java.lang.String,​java.lang.Object> updateFields,
                                                                                                    CloudUpdateValidator cloudUpdateValidator)
                                                                                             throws java.lang.Exception
        Update the metadata for the specified blob.
        Parameters:
        blobId - The BlobId to update.
        updateFields - Map of field names and new values to modify.
        cloudUpdateValidator - CloudUpdateValidator validator for the update passed by the caller.
        Returns:
        a AzureCloudDestination.UpdateResponse with the updated metadata.
        Throws:
        com.azure.storage.blob.models.BlobStorageException - if the blob does not exist or an error occurred.
        java.lang.IllegalStateException - on request timeout.
        java.lang.Exception
      • purgeBlobs

        public java.util.List<CloudBlobMetadata> purgeBlobs​(java.util.List<CloudBlobMetadata> blobMetadataList)
                                                     throws com.azure.storage.blob.models.BlobStorageException
        Permanently delete the specified blobs in Azure storage.
        Parameters:
        blobMetadataList - the list of CloudBlobMetadata referencing the blobs to purge.
        Returns:
        list of CloudBlobMetadata referencing the blobs successfully purged.
        Throws:
        com.azure.storage.blob.models.BlobStorageException - if the purge operation fails.
        java.lang.RuntimeException - if the request times out before a response is received.