Search in sources :

Example 61 with CloudBlobClient

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

the class AzureNativeFileSystemProvider method createBlobClient.

@Nonnull
private CloudBlobClient createBlobClient(@Nonnull final URI uri, @Nonnull final Configuration conf) {
    // Determine endpoint
    final String httpScheme = StringUtils.equalsAnyIgnoreCase(uri.getScheme(), "asvs", "wasbs") ? "https" : "http";
    final URI blobEndPoint = URI.create(httpScheme + "://" + uri.getRawAuthority());
    // Create client
    final CloudBlobClient client = new CloudBlobClient(blobEndPoint, getCredentials(uri, conf));
    final RetryPolicyFactory retryPolicyFactory = new RetryExponentialRetry(conf.getInt("fs.azure.io.retry.min.backoff.interval", 3 * 1000), conf.getInt("fs.azure.io.retry.backoff.interval", 3 * 1000), conf.getInt("fs.azure.io.retry.max.backoff.interval", 30 * 1000), conf.getInt("fs.azure.io.retry.max.retries", 30));
    client.getDefaultRequestOptions().setRetryPolicyFactory(retryPolicyFactory);
    final int storageConnectionTimeout = conf.getInt("fs.azure.storage.timeout", 0);
    if (storageConnectionTimeout > 0) {
        client.getDefaultRequestOptions().setTimeoutIntervalInMs(storageConnectionTimeout * 1000);
    }
    return client;
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) URI(java.net.URI) RetryPolicyFactory(com.microsoft.azure.storage.RetryPolicyFactory) RetryExponentialRetry(com.microsoft.azure.storage.RetryExponentialRetry) Nonnull(javax.annotation.Nonnull)

Example 62 with CloudBlobClient

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

the class AzureNativeFileSystemProviderTest method listFiles.

/**
 * Verify listing containers using the wasb scheme.
 */
@Test
@SuppressWarnings("unchecked")
public void listFiles() {
    // Test listing containers
    final AzureNativeFileSystemProvider provider = new AzureNativeFileSystemProvider() {

        @Nonnull
        @Override
        protected Iterable<CloudBlobContainer> listContainers(@Nonnull final CloudBlobClient client) {
            return Arrays.asList(createContainer("container1", client), createContainer("container2", client));
        }
    };
    final List<DataSetFile> files = provider.listFiles(new Path(WASB), new Configuration(false));
    Assert.assertThat(files, CoreMatchers.hasItems(isDataSetFile("container1"), isDataSetFile("container2")));
    Assert.assertEquals(2, files.size());
}
Also used : Path(org.apache.hadoop.fs.Path) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) Configuration(org.apache.hadoop.conf.Configuration) Nonnull(javax.annotation.Nonnull) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) DataSetFile(com.thinkbiganalytics.kylo.catalog.rest.model.DataSetFile) Test(org.junit.Test)

Example 63 with CloudBlobClient

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

the class AzureStorageDruidModuleTest method testBothAccountKeyAndSAStokenUnset.

@Test
public void testBothAccountKeyAndSAStokenUnset() {
    Properties properties = initializePropertes();
    properties.remove("druid.azure.key");
    expectedException.expect(ProvisionException.class);
    expectedException.expectMessage("Either set 'key' or 'sharedAccessStorageToken' in the azure config but not both");
    makeInjectorWithProperties(properties).getInstance(Key.get(new TypeLiteral<Supplier<CloudBlobClient>>() {
    }));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) TypeLiteral(com.google.inject.TypeLiteral) Properties(java.util.Properties) Test(org.junit.Test)

Example 64 with CloudBlobClient

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

the class AzureStorageDruidModuleTest method testGetBlobClientExpectedClient.

@Test
public void testGetBlobClientExpectedClient() {
    injector = makeInjectorWithProperties(PROPERTIES);
    Supplier<CloudBlobClient> cloudBlobClient = injector.getInstance(Key.get(new TypeLiteral<Supplier<CloudBlobClient>>() {
    }));
    StorageCredentials storageCredentials = cloudBlobClient.get().getCredentials();
    Assert.assertEquals(AZURE_ACCOUNT_NAME, storageCredentials.getAccountName());
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) StorageCredentials(com.microsoft.azure.storage.StorageCredentials) TypeLiteral(com.google.inject.TypeLiteral) Test(org.junit.Test)

Example 65 with CloudBlobClient

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

the class AzureStorageDruidModuleTest method testBothAccountKeyAndSAStokenSet.

@Test
public void testBothAccountKeyAndSAStokenSet() {
    Properties properties = initializePropertes();
    properties.setProperty("druid.azure.sharedAccessStorageToken", AZURE_SHARED_ACCESS_TOKEN);
    expectedException.expect(ProvisionException.class);
    expectedException.expectMessage("Either set 'key' or 'sharedAccessStorageToken' in the azure config but not both");
    makeInjectorWithProperties(properties).getInstance(Key.get(new TypeLiteral<Supplier<CloudBlobClient>>() {
    }));
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) TypeLiteral(com.google.inject.TypeLiteral) Properties(java.util.Properties) Test(org.junit.Test)

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