Search in sources :

Example 1 with BlobListingDetails

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

the class BlobServiceProducer method listBlobs.

private void listBlobs(Exchange exchange) throws Exception {
    CloudBlobContainer client = BlobServiceUtil.createBlobContainerClient(getConfiguration());
    BlobServiceRequestOptions opts = BlobServiceUtil.getRequestOptions(exchange);
    LOG.trace("Getting the blob list from the container [{}] from exchange [{}]...", getConfiguration().getContainerName(), exchange);
    BlobServiceConfiguration cfg = getConfiguration();
    EnumSet<BlobListingDetails> details = null;
    Object detailsObject = exchange.getIn().getHeader(BlobServiceConstants.BLOB_LISTING_DETAILS);
    if (detailsObject instanceof EnumSet) {
        @SuppressWarnings("unchecked") EnumSet<BlobListingDetails> theDetails = (EnumSet<BlobListingDetails>) detailsObject;
        details = theDetails;
    } else if (detailsObject instanceof BlobListingDetails) {
        details = EnumSet.of((BlobListingDetails) detailsObject);
    }
    Iterable<ListBlobItem> items = client.listBlobs(cfg.getBlobPrefix(), cfg.isUseFlatListing(), details, opts.getRequestOpts(), opts.getOpContext());
    ExchangeUtil.getMessageForResponse(exchange).setBody(items);
}
Also used : BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) EnumSet(java.util.EnumSet) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer)

Example 2 with BlobListingDetails

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

the class AzureStorageService method listBlobsByPrefix.

public Map<String, BlobMetadata> listBlobsByPrefix(String container, String keyPath, String prefix) throws URISyntaxException, StorageException {
    // NOTE: this should be here: if (prefix == null) prefix = "";
    // however, this is really inefficient since deleteBlobsByPrefix enumerates everything and
    // then does a prefix match on the result; it should just call listBlobsByPrefix with the prefix!
    final var blobsBuilder = new HashMap<String, BlobMetadata>();
    final EnumSet<BlobListingDetails> enumBlobListingDetails = EnumSet.of(BlobListingDetails.METADATA);
    final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
    final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
    LOGGER.trace(() -> new ParameterizedMessage("listing container [{}], keyPath [{}], prefix [{}]", container, keyPath, prefix));
    for (final ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix == null ? "" : prefix), false, enumBlobListingDetails, null, client.v2().get())) {
        final URI uri = blobItem.getUri();
        LOGGER.trace(() -> new ParameterizedMessage("blob url [{}]", uri));
        // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
        // this requires 1 + container.length() + 1, with each 1 corresponding to one of the /
        final String blobPath = uri.getPath().substring(1 + container.length() + 1);
        if (blobItem instanceof CloudBlob) {
            final BlobProperties properties = ((CloudBlob) blobItem).getProperties();
            final String name = blobPath.substring(keyPath.length());
            LOGGER.trace(() -> new ParameterizedMessage("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength()));
            blobsBuilder.put(name, new PlainBlobMetadata(name, properties.getLength()));
        }
    }
    return Map.copyOf(blobsBuilder);
}
Also used : BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) HashMap(java.util.HashMap) URI(java.net.URI) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) BlobProperties(com.microsoft.azure.storage.blob.BlobProperties) PlainBlobMetadata(org.elasticsearch.common.blobstore.support.PlainBlobMetadata) Supplier(java.util.function.Supplier) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 3 with BlobListingDetails

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

the class AzureStorageService method children.

public Set<String> children(String account, String container, BlobPath path) throws URISyntaxException, StorageException {
    final var blobsBuilder = new HashSet<String>();
    final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client();
    final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
    final String keyPath = path.buildAsString();
    final EnumSet<BlobListingDetails> enumBlobListingDetails = EnumSet.of(BlobListingDetails.METADATA);
    for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath, false, enumBlobListingDetails, null, client.v2().get())) {
        if (blobItem instanceof CloudBlobDirectory) {
            final URI uri = blobItem.getUri();
            LOGGER.trace(() -> new ParameterizedMessage("blob url [{}]", uri));
            // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/
            // this requires 1 + container.length() + 1, with each 1 corresponding to one of the /.
            // Lastly, we add the length of keyPath to the offset to strip this container's path.
            final String uriPath = uri.getPath();
            blobsBuilder.add(uriPath.substring(1 + container.length() + 1 + keyPath.length(), uriPath.length() - 1));
        }
    }
    return Set.copyOf(blobsBuilder);
}
Also used : CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) URI(java.net.URI) Supplier(java.util.function.Supplier) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) HashSet(java.util.HashSet)

Aggregations

BlobListingDetails (com.microsoft.azure.storage.blob.BlobListingDetails)3 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)3 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)3 CloudBlobClient (com.microsoft.azure.storage.blob.CloudBlobClient)2 URI (java.net.URI)2 Supplier (java.util.function.Supplier)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 BlobProperties (com.microsoft.azure.storage.blob.BlobProperties)1 CloudBlob (com.microsoft.azure.storage.blob.CloudBlob)1 CloudBlobDirectory (com.microsoft.azure.storage.blob.CloudBlobDirectory)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 PlainBlobMetadata (org.elasticsearch.common.blobstore.support.PlainBlobMetadata)1