Search in sources :

Example 71 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.

the class AzureStorageService method deleteFiles.

public void deleteFiles(String container, String path) throws URISyntaxException, StorageException {
    final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
    // container name must be lower case.
    LOGGER.trace(() -> new ParameterizedMessage("delete files container [{}], path [{}]", container, path));
    // list the blobs using a flat blob listing mode
    final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
    for (final ListBlobItem blobItem : blobContainer.listBlobs(path, true, EnumSet.noneOf(BlobListingDetails.class), null, client.v2().get())) {
        final String blobName = blobNameFromUri(blobItem.getUri());
        LOGGER.trace(() -> new ParameterizedMessage("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri()));
        // don't call {@code #deleteBlob}, use the same client
        final CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blobName);
        azureBlob.delete(DeleteSnapshotsOption.NONE, null, null, client.v2().get());
    }
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) Supplier(java.util.function.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

Example 72 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.

the class AzureStorageServiceTests method testGetSelectedClientBackoffPolicy.

public void testGetSelectedClientBackoffPolicy() {
    final AzureStorageService azureStorageService = storageServiceWithSettings(buildClientCredSettings());
    final CloudBlobClient client = azureStorageService.client().v1();
    assertThat(client.getDefaultRequestOptions().getRetryPolicyFactory(), is(notNullValue()));
    assertThat(client.getDefaultRequestOptions().getRetryPolicyFactory(), instanceOf(RetryExponentialRetry.class));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) RetryExponentialRetry(com.microsoft.azure.storage.RetryExponentialRetry)

Example 73 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.

the class AzureStorageServiceTests method testCreateClientWithEndpointSuffix.

public void testCreateClientWithEndpointSuffix() {
    final Settings settings = Settings.builder().put(buildClientCredSettings()).put("endpoint_suffix", "my_endpoint_suffix").build();
    final AzureStorageService azureStorageService = storageServiceWithSettings(settings);
    final CloudBlobClient client = azureStorageService.client().v1();
    assertThat(client.getEndpoint().toString(), equalTo("https://myaccount1.blob.my_endpoint_suffix"));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) Settings(org.elasticsearch.common.settings.Settings)

Example 74 with CloudBlobClient

use of com.microsoft.azure.storage.blob.CloudBlobClient in project crate by crate.

the class AzureStorageServiceTests method testGetSelectedClientNoTimeout.

public void testGetSelectedClientNoTimeout() {
    final AzureStorageService azureStorageService = storageServiceWithSettings(buildClientCredSettings());
    final CloudBlobClient client = azureStorageService.client().v1();
    assertThat(client.getDefaultRequestOptions().getTimeoutIntervalInMs(), is(nullValue()));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient)

Aggregations

CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)74 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)42 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)19 StorageException (com.microsoft.azure.storage.StorageException)19 URISyntaxException (java.net.URISyntaxException)17 CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)16 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)10 URI (java.net.URI)10 Supplier (java.util.function.Supplier)9 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)8 InvalidKeyException (java.security.InvalidKeyException)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)6 TypeLiteral (com.google.inject.TypeLiteral)5 RetryExponentialRetry (com.microsoft.azure.storage.RetryExponentialRetry)5 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)5 BlobListingDetails (com.microsoft.azure.storage.blob.BlobListingDetails)5 IOException (java.io.IOException)5 BlobProperties (com.microsoft.azure.storage.blob.BlobProperties)4