Search in sources :

Example 1 with StorageMetadata

use of org.jclouds.blobstore.domain.StorageMetadata in project camel by apache.

the class JcloudsBlobStoreConsumer method poll.

@Override
protected int poll() throws Exception {
    shutdownRunningTask = null;
    pendingExchanges = 0;
    Queue<Exchange> queue = new LinkedList<Exchange>();
    String directory = endpoint.getDirectory();
    ListContainerOptions opt = new ListContainerOptions();
    if (!Strings.isNullOrEmpty(directory)) {
        opt = opt.inDirectory(directory);
    }
    for (StorageMetadata md : blobStore.list(container, opt.maxResults(maxMessagesPerPoll).recursive())) {
        String blobName = md.getName();
        if (md.getType().equals(StorageType.BLOB)) {
            if (!Strings.isNullOrEmpty(blobName)) {
                InputStream body = JcloudsBlobStoreHelper.readBlob(blobStore, container, blobName);
                if (body != null) {
                    Exchange exchange = endpoint.createExchange();
                    CachedOutputStream cos = new CachedOutputStream(exchange);
                    IOHelper.copy(body, cos);
                    exchange.getIn().setBody(cos.newStreamCache());
                    exchange.setProperty(JcloudsConstants.BLOB_NAME, blobName);
                    queue.add(exchange);
                }
            }
        }
    }
    return queue.isEmpty() ? 0 : processBatch(CastUtils.cast(queue));
}
Also used : Exchange(org.apache.camel.Exchange) ListContainerOptions(org.jclouds.blobstore.options.ListContainerOptions) StorageMetadata(org.jclouds.blobstore.domain.StorageMetadata) InputStream(java.io.InputStream) LinkedList(java.util.LinkedList) CachedOutputStream(org.apache.camel.converter.stream.CachedOutputStream)

Example 2 with StorageMetadata

use of org.jclouds.blobstore.domain.StorageMetadata in project legacy-jclouds-examples by jclouds.

the class MainApp method main.

public static void main(String[] args) throws IOException {
    if (args.length < PARAMETERS)
        throw new IllegalArgumentException(INVALID_SYNTAX);
    // Args
    String provider = args[0];
    // note that you can check if a provider is present ahead of time
    checkArgument(contains(allKeys, provider), "provider %s not in supported list: %s", provider, allKeys);
    String identity = args[1];
    String credential = args[2];
    String containerName = args[3];
    // Init
    BlobStoreContext context = ContextBuilder.newBuilder(provider).credentials(identity, credential).buildView(BlobStoreContext.class);
    try {
        // Create Container
        BlobStore blobStore = context.getBlobStore();
        blobStore.createContainerInLocation(null, containerName);
        // Add Blob
        Blob blob = blobStore.blobBuilder("test").payload("testdata").build();
        blobStore.putBlob(containerName, blob);
        // List Container
        for (StorageMetadata resourceMd : blobStore.list()) {
            if (resourceMd.getType() == StorageType.CONTAINER || resourceMd.getType() == StorageType.FOLDER) {
                // Use Map API
                Map<String, InputStream> containerMap = context.createInputStreamMap(resourceMd.getName());
                System.out.printf("  %s: %s entries%n", resourceMd.getName(), containerMap.size());
            }
        }
        // Use Provider API
        if (context.getBackendType().getRawType().equals(RestContext.class)) {
            RestContext<?, ?> rest = context.unwrap();
            if (rest.getApi() instanceof S3Client) {
                RestContext<S3Client, S3AsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getBucketLogging(containerName);
            } else if (rest.getApi() instanceof SwiftClient) {
                RestContext<SwiftClient, SwiftAsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getObjectInfo(containerName, "test");
            } else if (rest.getApi() instanceof AzureBlobClient) {
                RestContext<AzureBlobClient, AzureBlobAsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getBlobProperties(containerName, "test");
            } else if (rest.getApi() instanceof AtmosClient) {
                RestContext<AtmosClient, AtmosAsyncClient> providerContext = context.unwrap();
                providerContext.getApi().getSystemMetadata(containerName + "/test");
            }
        }
    } finally {
        // Close connecton
        context.close();
        System.exit(0);
    }
}
Also used : StorageMetadata(org.jclouds.blobstore.domain.StorageMetadata) Blob(org.jclouds.blobstore.domain.Blob) SwiftClient(org.jclouds.openstack.swift.SwiftClient) InputStream(java.io.InputStream) RestContext(org.jclouds.rest.RestContext) AtmosClient(org.jclouds.atmos.AtmosClient) S3AsyncClient(org.jclouds.s3.S3AsyncClient) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) S3Client(org.jclouds.s3.S3Client) AzureBlobClient(org.jclouds.azureblob.AzureBlobClient) BlobStore(org.jclouds.blobstore.BlobStore) AzureBlobAsyncClient(org.jclouds.azureblob.AzureBlobAsyncClient)

Example 3 with StorageMetadata

use of org.jclouds.blobstore.domain.StorageMetadata in project jackrabbit-oak by apache.

the class CloudBlobStore method countDeleteChunks.

@Override
public long countDeleteChunks(List<String> chunkIds, long maxLastModifiedTime) throws Exception {
    Preconditions.checkNotNull(context);
    long count = 0;
    for (String chunkId : chunkIds) {
        final org.jclouds.blobstore.BlobStore blobStore = context.getBlobStore();
        StorageMetadata metadata = blobStore.blobMetadata(cloudContainer, chunkId);
        if ((maxLastModifiedTime <= 0) || (metadata.getLastModified().getTime() <= maxLastModifiedTime)) {
            blobStore.removeBlob(cloudContainer, chunkId);
            count++;
        }
    }
    return count;
}
Also used : StorageMetadata(org.jclouds.blobstore.domain.StorageMetadata)

Aggregations

StorageMetadata (org.jclouds.blobstore.domain.StorageMetadata)3 InputStream (java.io.InputStream)2 LinkedList (java.util.LinkedList)1 Exchange (org.apache.camel.Exchange)1 CachedOutputStream (org.apache.camel.converter.stream.CachedOutputStream)1 AtmosClient (org.jclouds.atmos.AtmosClient)1 AzureBlobAsyncClient (org.jclouds.azureblob.AzureBlobAsyncClient)1 AzureBlobClient (org.jclouds.azureblob.AzureBlobClient)1 BlobStore (org.jclouds.blobstore.BlobStore)1 BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)1 Blob (org.jclouds.blobstore.domain.Blob)1 ListContainerOptions (org.jclouds.blobstore.options.ListContainerOptions)1 SwiftClient (org.jclouds.openstack.swift.SwiftClient)1 RestContext (org.jclouds.rest.RestContext)1 S3AsyncClient (org.jclouds.s3.S3AsyncClient)1 S3Client (org.jclouds.s3.S3Client)1