Search in sources :

Example 26 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project azure-sdk-for-java by Azure.

the class ManageLinuxWebAppStorageAccountConnection method setUpStorageAccount.

private static CloudBlobContainer setUpStorageAccount(String connectionString, String containerName) {
    try {
        CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference(containerName);
        container.createIfNotExists();
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        // Include public access in the permissions object
        containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        return container;
    } catch (StorageException | URISyntaxException | InvalidKeyException e) {
        throw new RuntimeException(e);
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) BlobContainerPermissions(com.microsoft.azure.storage.blob.BlobContainerPermissions) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 27 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project jackrabbit-oak by apache.

the class DataStoreUtils method deleteAzureContainer.

public static void deleteAzureContainer(Map<String, ?> config, String containerName) throws Exception {
    String accountName = (String) config.get(AzureConstants.AZURE_STORAGE_ACCOUNT_NAME);
    String accountKey = (String) config.get(AzureConstants.AZURE_STORAGE_ACCOUNT_KEY);
    if (Strings.isNullOrEmpty(containerName) || Strings.isNullOrEmpty(accountName) || Strings.isNullOrEmpty(accountKey)) {
        return;
    }
    log.info("deleting container [" + containerName + "]");
    CloudBlobContainer container = org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.Utils.getBlobContainer(org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.Utils.getConnectionString(accountName, accountKey), containerName);
    if (container.deleteIfExists()) {
        log.info("container [ " + containerName + "] deleted");
    } else {
        log.info("container [" + containerName + "] doesn't exists");
    }
}
Also used : CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

Example 28 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project jackrabbit-oak by apache.

the class AzureDataStoreUtils method deleteContainer.

public static void deleteContainer(String containerName) throws Exception {
    if (Strings.isNullOrEmpty(containerName)) {
        log.warn("Cannot delete container with null or empty name. containerName={}", containerName);
        return;
    }
    log.info("Starting to delete container. containerName={}", containerName);
    Properties props = getAzureConfig();
    CloudBlobContainer container = Utils.getBlobContainer(Utils.getConnectionStringFromProperties(props), containerName);
    boolean result = container.deleteIfExists();
    log.info("Container deleted. containerName={} existed={}", containerName, result);
}
Also used : CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) Properties(java.util.Properties)

Example 29 with CloudBlobContainer

use of com.microsoft.azure.storage.blob.CloudBlobContainer in project jackrabbit-oak by apache.

the class AzureBlobStoreBackend method getAzureContainer.

protected CloudBlobContainer getAzureContainer() throws DataStoreException {
    CloudBlobContainer container = Utils.getBlobContainer(connectionString, containerName);
    RequestOptions requestOptions = container.getServiceClient().getDefaultRequestOptions();
    if (retryPolicy != null) {
        requestOptions.setRetryPolicyFactory(retryPolicy);
    }
    if (requestTimeout != null) {
        requestOptions.setTimeoutIntervalInMs(requestTimeout);
    }
    return container;
}
Also used : BlobRequestOptions(com.microsoft.azure.storage.blob.BlobRequestOptions) RequestOptions(com.microsoft.azure.storage.RequestOptions) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

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