Search in sources :

Example 31 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project camel by apache.

the class BlobServiceProducer method updateBlockBlob.

private void updateBlockBlob(Exchange exchange) throws Exception {
    CloudBlockBlob client = BlobServiceUtil.createBlockBlobClient(getConfiguration());
    configureCloudBlobForWrite(client);
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    InputStream inputStream = getInputStreamFromExchange(exchange);
    LOG.trace("Putting a block blob [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange);
    try {
        client.upload(inputStream, -1, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
    } finally {
        closeInputStreamIfNeeded(inputStream);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

Example 32 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project camel by apache.

the class BlobServiceProducer method commitBlobBlockList.

private void commitBlobBlockList(Exchange exchange) throws Exception {
    Object object = exchange.getIn().getMandatoryBody();
    List<BlockEntry> blockEntries = null;
    if (object instanceof List) {
        blockEntries = (List<BlockEntry>) blockEntries;
    } else if (object instanceof BlockEntry) {
        blockEntries = Collections.singletonList((BlockEntry) object);
    }
    if (blockEntries == null || blockEntries.isEmpty()) {
        throw new IllegalArgumentException("Illegal commit block list payload");
    }
    CloudBlockBlob client = BlobServiceUtil.createBlockBlobClient(getConfiguration());
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    LOG.trace("Putting a blob [{}] block list from exchange [{}]...", getConfiguration().getBlobName(), exchange);
    client.commitBlockList(blockEntries, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
}
Also used : BlockEntry(com.microsoft.azure.storage.blob.BlockEntry) LinkedList(java.util.LinkedList) List(java.util.List) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob)

Example 33 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project camel by apache.

the class BlobServiceUtil method createBlockBlobClient.

public static CloudBlockBlob createBlockBlobClient(BlobServiceConfiguration cfg) throws Exception {
    CloudBlockBlob client = (CloudBlockBlob) getConfiguredClient(cfg);
    if (client == null) {
        URI uri = prepareStorageBlobUri(cfg);
        StorageCredentials creds = getAccountCredentials(cfg);
        client = new CloudBlockBlob(uri, creds);
    }
    return client;
}
Also used : StorageCredentials(com.microsoft.azure.storage.StorageCredentials) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) URI(java.net.URI)

Example 34 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project camel by apache.

the class BlobServiceComponentConfigurationTest method testClientWithoutCredentialsPublicRead.

@Test
public void testClientWithoutCredentialsPublicRead() throws Exception {
    CloudBlockBlob client = new CloudBlockBlob(URI.create("https://camelazure.blob.core.windows.net/container/blob"));
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("azureBlobClient", client);
    BlobServiceComponent component = new BlobServiceComponent(context);
    BlobServiceEndpoint endpoint = (BlobServiceEndpoint) component.createEndpoint("azure-blob://camelazure/container/blob?azureBlobClient=#azureBlobClient&publicForRead=true");
    assertTrue(endpoint.getConfiguration().isPublicForRead());
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Example 35 with CloudBlockBlob

use of com.microsoft.azure.storage.blob.CloudBlockBlob in project camel by apache.

the class BlobServiceComponentConfigurationTest method testCreateEndpointWithMinConfigForClientOnly.

@Test
public void testCreateEndpointWithMinConfigForClientOnly() throws Exception {
    CloudBlockBlob client = new CloudBlockBlob(URI.create("https://camelazure.blob.core.windows.net/container/blob"), newAccountKeyCredentials());
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("azureBlobClient", client);
    BlobServiceComponent component = new BlobServiceComponent(context);
    BlobServiceEndpoint endpoint = (BlobServiceEndpoint) component.createEndpoint("azure-blob://camelazure/container/blob?azureBlobClient=#azureBlobClient");
    doTestCreateEndpointWithMinConfig(endpoint, true);
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Test(org.junit.Test)

Aggregations

CloudBlockBlob (com.microsoft.azure.storage.blob.CloudBlockBlob)42 Test (org.junit.Test)17 StorageException (com.microsoft.azure.storage.StorageException)11 Path (org.apache.hadoop.fs.Path)11 URISyntaxException (java.net.URISyntaxException)10 BlobOutputStream (com.microsoft.azure.storage.blob.BlobOutputStream)9 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)9 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)8 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)6 FileNotFoundException (java.io.FileNotFoundException)5 BlockEntry (com.microsoft.azure.storage.blob.BlockEntry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 JndiRegistry (org.apache.camel.impl.JndiRegistry)4 URI (java.net.URI)3 InvalidKeyException (java.security.InvalidKeyException)3 CloudStorageAccount (com.microsoft.azure.storage.CloudStorageAccount)2 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)2