Search in sources :

Example 1 with CloudAppendBlob

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

the class BlobServiceProducer method updateAppendBlob.

private void updateAppendBlob(Exchange exchange) throws Exception {
    CloudAppendBlob client = BlobServiceUtil.createAppendBlobClient(getConfiguration());
    configureCloudBlobForWrite(client);
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    if (opts.getAccessCond() == null) {
        // Default: do not reset the blob content if the blob already exists
        opts.setAccessCond(AccessCondition.generateIfNotExistsCondition());
    }
    Boolean appendBlobCreated = exchange.getIn().getHeader(BlobServiceConstants.APPEND_BLOCK_CREATED, Boolean.class);
    if (Boolean.TRUE != appendBlobCreated) {
        doCreateAppendBlob(client, opts, exchange);
    }
    InputStream inputStream = getInputStreamFromExchange(exchange);
    try {
        client.appendBlock(inputStream, -1, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
    } finally {
        closeInputStreamIfNeeded(inputStream);
    }
}
Also used : CloudAppendBlob(com.microsoft.azure.storage.blob.CloudAppendBlob) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 2 with CloudAppendBlob

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

the class BlobServiceUtil method getAppendBlob.

private static void getAppendBlob(Exchange exchange, BlobServiceConfiguration cfg) throws Exception {
    CloudAppendBlob client = createAppendBlobClient(cfg);
    doGetBlob(client, exchange, cfg);
}
Also used : CloudAppendBlob(com.microsoft.azure.storage.blob.CloudAppendBlob)

Example 3 with CloudAppendBlob

use of com.microsoft.azure.storage.blob.CloudAppendBlob in project wildfly-camel by wildfly-extras.

the class AzureIntegrationTest method testAppendBlob.

@Test
public void testAppendBlob() throws Exception {
    StorageCredentials creds = getStorageCredentials("camelblob", System.getenv(AZURE_STORAGE_BLOB));
    Assume.assumeNotNull("Credentials not null", creds);
    CamelContext camelctx = createCamelContext(creds);
    camelctx.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from("direct:start").to("azure-blob://camelblob/container1/blobAppend?credentials=#creds&operation=updateAppendBlob");
            from("azure-blob://camelblob/container1/blobAppend?credentials=#creds&blobType=appendblob").to("mock:read");
            from("direct:list").to("azure-blob://camelblob/container1?credentials=#creds&operation=listBlobs");
        }
    });
    camelctx.start();
    try {
        MockEndpoint mockRead = camelctx.getEndpoint("mock:read", MockEndpoint.class);
        mockRead.expectedBodiesReceived("Append Blob");
        mockRead.expectedMessageCount(1);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Iterator<?> it = producer.requestBody("direct:list", null, Iterable.class).iterator();
        Assert.assertFalse("No Blob exists", it.hasNext());
        // append to blob
        producer.sendBody("direct:start", "Append Blob");
        mockRead.assertIsSatisfied();
        it = producer.requestBody("direct:list", null, Iterable.class).iterator();
        Assert.assertTrue("Blob exists", it.hasNext());
        CloudBlob blob = (CloudAppendBlob) it.next();
        blob.delete();
        it = producer.requestBody("direct:list", null, Iterable.class).iterator();
        Assert.assertFalse("No Blob exists", it.hasNext());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) StorageCredentials(com.microsoft.azure.storage.StorageCredentials) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CloudAppendBlob(com.microsoft.azure.storage.blob.CloudAppendBlob) Test(org.junit.Test)

Example 4 with CloudAppendBlob

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

the class AzureJournalFile method getJournalBlobs.

private List<CloudAppendBlob> getJournalBlobs() throws IOException {
    try {
        List<CloudAppendBlob> result = new ArrayList<>();
        for (ListBlobItem b : directory.listBlobs(journalNamePrefix)) {
            if (b instanceof CloudAppendBlob) {
                result.add((CloudAppendBlob) b);
            } else {
                log.warn("Invalid blob type: {} {}", b.getUri(), b.getClass());
            }
        }
        result.sort(Comparator.<CloudAppendBlob, String>comparing(AzureUtilities::getName).reversed());
        return result;
    } catch (URISyntaxException | StorageException e) {
        throw new IOException(e);
    }
}
Also used : ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudAppendBlob(com.microsoft.azure.storage.blob.CloudAppendBlob) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with CloudAppendBlob

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

the class BlobServiceProducer method createAppendBlob.

private void createAppendBlob(Exchange exchange) throws Exception {
    CloudAppendBlob client = BlobServiceUtil.createAppendBlobClient(getConfiguration());
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    if (opts.getAccessCond() == null) {
        // Default: do not reset the blob content if the blob already exists
        opts.setAccessCond(AccessCondition.generateIfNotExistsCondition());
    }
    doCreateAppendBlob(client, opts, exchange);
}
Also used : CloudAppendBlob(com.microsoft.azure.storage.blob.CloudAppendBlob)

Aggregations

CloudAppendBlob (com.microsoft.azure.storage.blob.CloudAppendBlob)10 StorageException (com.microsoft.azure.storage.StorageException)3 IOException (java.io.IOException)3 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)1 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Random (java.util.Random)1 CamelContext (org.apache.camel.CamelContext)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 JndiRegistry (org.apache.camel.impl.JndiRegistry)1 AzureJournalFile (org.apache.jackrabbit.oak.segment.azure.AzureJournalFile)1