Search in sources :

Example 6 with CloudPageBlob

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

the class BlobServiceProducer method deletePageBlob.

private void deletePageBlob(Exchange exchange) throws Exception {
    CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration());
    doDeleteBlock(client, exchange);
}
Also used : CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 7 with CloudPageBlob

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

the class BlobServiceProducer method getPageBlobRanges.

private void getPageBlobRanges(Exchange exchange) throws Exception {
    CloudPageBlob client = BlobServiceUtil.createPageBlobClient(getConfiguration());
    BlobServiceUtil.configureCloudBlobForRead(client, getConfiguration());
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    LOG.trace("Getting the page blob ranges [{}] from exchange [{}]...", getConfiguration().getBlobName(), exchange);
    List<PageRange> ranges = client.downloadPageRanges(opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
    ExchangeUtil.getMessageForResponse(exchange).setBody(ranges);
}
Also used : CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) PageRange(com.microsoft.azure.storage.blob.PageRange)

Example 8 with CloudPageBlob

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

the class BlobServiceProducer method createPageBlob.

private void createPageBlob(Exchange exchange) throws Exception {
    CloudPageBlob client = BlobServiceUtil.createPageBlobClient(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());
    }
    doCreatePageBlob(client, opts, exchange);
}
Also used : CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Example 9 with CloudPageBlob

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

the class BlobServiceUtil method createPageBlobClient.

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

Example 10 with CloudPageBlob

use of com.microsoft.azure.storage.blob.CloudPageBlob in project hadoop by apache.

the class PageBlobOutputStream method conditionalExtendFile.

/**
   * Extend the page blob file if we are close to the end.
   */
private void conditionalExtendFile() {
    // maximum allowed size of an Azure page blob (1 terabyte)
    final long MAX_PAGE_BLOB_SIZE = 1024L * 1024L * 1024L * 1024L;
    // If blob is already at the maximum size, then don't try to extend it.
    if (currentBlobSize == MAX_PAGE_BLOB_SIZE) {
        return;
    }
    // If we are within the maximum write size of the end of the file,
    if (currentBlobSize - currentBlobOffset <= MAX_RAW_BYTES_PER_REQUEST) {
        // Extend the file. Retry up to 3 times with back-off.
        CloudPageBlob cloudPageBlob = (CloudPageBlob) blob.getBlob();
        long newSize = currentBlobSize + configuredPageBlobExtensionSize;
        // Make sure we don't exceed maximum blob size.
        if (newSize > MAX_PAGE_BLOB_SIZE) {
            newSize = MAX_PAGE_BLOB_SIZE;
        }
        final int MAX_RETRIES = 3;
        int retries = 1;
        boolean resizeDone = false;
        while (!resizeDone && retries <= MAX_RETRIES) {
            try {
                cloudPageBlob.resize(newSize);
                resizeDone = true;
                currentBlobSize = newSize;
            } catch (StorageException e) {
                LOG.warn("Failed to extend size of " + cloudPageBlob.getUri());
                try {
                    // sleep 2, 8, 18 seconds for up to 3 retries
                    Thread.sleep(2000 * retries * retries);
                } catch (InterruptedException e1) {
                    // Restore the interrupted status
                    Thread.currentThread().interrupt();
                }
            } finally {
                retries++;
            }
        }
    }
}
Also used : StorageException(com.microsoft.azure.storage.StorageException) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob)

Aggregations

CloudPageBlob (com.microsoft.azure.storage.blob.CloudPageBlob)10 PageRange (com.microsoft.azure.storage.blob.PageRange)3 InputStream (java.io.InputStream)2 StorageCredentials (com.microsoft.azure.storage.StorageCredentials)1 StorageException (com.microsoft.azure.storage.StorageException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1