Search in sources :

Example 16 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project druid by druid-io.

the class AzureStorage method emptyCloudBlobDirectory.

public List<String> emptyCloudBlobDirectory(final String containerName, final String virtualDirPath) throws StorageException, URISyntaxException {
    List<String> deletedFiles = new ArrayList<>();
    CloudBlobContainer container = getCloudBlobContainer(containerName);
    for (ListBlobItem blobItem : container.listBlobs(virtualDirPath, true, null, null, null)) {
        CloudBlob cloudBlob = (CloudBlob) blobItem;
        log.info("Removing file[%s] from Azure.", cloudBlob.getName());
        if (cloudBlob.deleteIfExists()) {
            deletedFiles.add(cloudBlob.getName());
        }
    }
    if (deletedFiles.isEmpty()) {
        log.warn("No files were deleted on the following Azure path: [%s]", virtualDirPath);
    }
    return deletedFiles;
}
Also used : CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) ArrayList(java.util.ArrayList) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

Example 17 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project elasticsearch by elastic.

the class AzureStorageServiceImpl method createContainer.

@Override
public void createContainer(String account, LocationMode mode, String container) throws URISyntaxException, StorageException {
    try {
        CloudBlobClient client = this.getSelectedClient(account, mode);
        CloudBlobContainer blobContainer = client.getContainerReference(container);
        logger.trace("creating container [{}]", container);
        SocketAccess.doPrivilegedException(blobContainer::createIfNotExists);
    } catch (IllegalArgumentException e) {
        logger.trace((Supplier<?>) () -> new ParameterizedMessage("fails creating container [{}]", container), e);
        throw new RepositoryException(container, e.getMessage(), e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) RepositoryException(org.elasticsearch.repositories.RepositoryException)

Example 18 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project elasticsearch by elastic.

the class AzureStorageServiceImpl method removeContainer.

@Override
public void removeContainer(String account, LocationMode mode, String container) throws URISyntaxException, StorageException {
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlobContainer blobContainer = client.getContainerReference(container);
    logger.trace("removing container [{}]", container);
    SocketAccess.doPrivilegedException(blobContainer::deleteIfExists);
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

Example 19 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project elasticsearch by elastic.

the class AzureStorageServiceImpl method blobExists.

@Override
public boolean blobExists(String account, LocationMode mode, String container, String blob) throws URISyntaxException, StorageException {
    // Container name must be lower case.
    CloudBlobClient client = this.getSelectedClient(account, mode);
    CloudBlobContainer blobContainer = client.getContainerReference(container);
    if (blobContainer.exists()) {
        CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blob);
        return SocketAccess.doPrivilegedException(azureBlob::exists);
    }
    return false;
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

Example 20 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project hadoop by apache.

the class LocalSASKeyGeneratorImpl method getRelativeBlobSASUri.

/**
   * Implementation for generation of Relative Path Blob SAS Uri.
   */
@Override
public URI getRelativeBlobSASUri(String accountName, String container, String relativePath) throws SASKeyGenerationException {
    CloudBlobContainer sc = null;
    CloudBlobClient client = null;
    try {
        CloudStorageAccount account = getSASKeyBasedStorageAccountInstance(accountName);
        client = account.createCloudBlobClient();
        sc = client.getContainerReference(container);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException " + "while getting container references for container " + container + " inside storage account : " + accountName, uriSyntaxEx);
    } catch (StorageException stoEx) {
        throw new SASKeyGenerationException("Encountered StorageException while " + "getting  container references for container " + container + " inside storage account : " + accountName, stoEx);
    }
    CloudBlockBlob blob = null;
    try {
        blob = sc.getBlockBlobReference(relativePath);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException while " + "getting Block Blob references for container " + container + " inside storage account : " + accountName, uriSyntaxEx);
    } catch (StorageException stoEx) {
        throw new SASKeyGenerationException("Encountered StorageException while " + "getting Block Blob references for container " + container + " inside storage account : " + accountName, stoEx);
    }
    try {
        return client.getCredentials().transformUri(blob.getUri());
    } catch (StorageException stoEx) {
        throw new SASKeyGenerationException("Encountered StorageException while " + "generating SAS key for Blob: " + relativePath + " inside " + "container : " + container + " in Storage Account : " + accountName, stoEx);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException " + "while generating SAS key for Blob: " + relativePath + " inside " + "container: " + container + " in Storage Account : " + accountName, uriSyntaxEx);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) URISyntaxException(java.net.URISyntaxException) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)29 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)13 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)9 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)7 StorageException (com.microsoft.azure.storage.StorageException)7 URISyntaxException (java.net.URISyntaxException)6 Test (org.junit.Test)6 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 Path (org.apache.hadoop.fs.Path)5 InvalidKeyException (java.security.InvalidKeyException)4 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 URI (java.net.URI)3 WebApp (com.microsoft.azure.management.appservice.WebApp)2 BlobContainerPermissions (com.microsoft.azure.storage.blob.BlobContainerPermissions)2 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)2 ArrayList (java.util.ArrayList)2 RepositoryException (org.elasticsearch.repositories.RepositoryException)2