Search in sources :

Example 1 with BlobStoreContext

use of org.jclouds.blobstore.BlobStoreContext 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 2 with BlobStoreContext

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

the class MainApp method upload.

/**
    * @param provider
    * @param identity
    * @param credential
    * @param hdfsUrl
    * @param containerName
    * @param objectName
    * @param plainhttp
    * @param threadcount
    * @throws IOException
    */
private void upload(String provider, String identity, String credential, String hdfsUrl, String containerName, String objectName, boolean plainhttp, String threadcount) throws IOException {
    // Init
    Properties overrides = new Properties();
    if (plainhttp)
        // default is https
        overrides.putAll(PLAIN_HTTP_ENDPOINTS);
    if (threadcount != null)
        // without setting,
        overrides.setProperty("jclouds.mpu.parallel.degree", threadcount);
    // default is 4 threads
    overrides.setProperty(provider + ".identity", identity);
    overrides.setProperty(provider + ".credential", credential);
    BlobStoreContext context = new BlobStoreContextFactory().createContext(provider, HDFS_MODULES, overrides);
    try {
        long start = System.currentTimeMillis();
        Configuration conf = getConf();
        if (conf == null) {
            conf = new Configuration();
            setConf(conf);
        }
        // Create Container
        // it can be changed to sync
        BlobStore blobStore = context.getBlobStore();
        // BlobStore
        blobStore.createContainerInLocation(null, containerName);
        Blob blob = blobStore.blobBuilder(objectName).payload(new HdfsPayload(new Path(hdfsUrl), conf)).contentType(MediaType.APPLICATION_OCTET_STREAM).contentDisposition(objectName).build();
        long length = blob.getPayload().getContentMetadata().getContentLength();
        blobStore.putBlob(containerName, blob, multipart());
        printSpeed("Sucessfully uploaded", start, length);
    } finally {
        // Close connection
        context.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Blob(org.jclouds.blobstore.domain.Blob) BlobStoreContextFactory(org.jclouds.blobstore.BlobStoreContextFactory) Configuration(org.apache.hadoop.conf.Configuration) HdfsPayload(org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Properties(java.util.Properties) BlobStore(org.jclouds.blobstore.BlobStore)

Example 3 with BlobStoreContext

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

the class UploadLargeObject method init.

private void init(String[] args) {
    // The provider configures jclouds To use the Rackspace Cloud (US)
    // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
    String provider = "cloudfiles-us";
    String username = args[0];
    String apiKey = args[1];
    Properties overrides = new Properties();
    // This property controls the number of parts being uploaded in parallel, the default is 4
    overrides.setProperty("jclouds.mpu.parallel.degree", "5");
    // This property controls the size (in bytes) of parts being uploaded in parallel, the default is 33554432 bytes = 32 MB 
    // 64 MB
    overrides.setProperty("jclouds.mpu.parts.size", "67108864");
    BlobStoreContext context = ContextBuilder.newBuilder(provider).credentials(username, apiKey).buildView(BlobStoreContext.class);
    storage = context.getBlobStore();
}
Also used : BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Properties(java.util.Properties)

Example 4 with BlobStoreContext

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

the class UploadObjects method init.

private void init(String[] args) {
    // The provider configures jclouds To use the Rackspace Cloud (US)
    // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
    String provider = "cloudfiles-us";
    String username = args[0];
    String apiKey = args[1];
    BlobStoreContext context = ContextBuilder.newBuilder(provider).credentials(username, apiKey).buildView(BlobStoreContext.class);
    storage = context.getBlobStore();
    swift = context.unwrap();
}
Also used : BlobStoreContext(org.jclouds.blobstore.BlobStoreContext)

Example 5 with BlobStoreContext

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

the class CloudFilesPublish method init.

private void init(String[] args) {
    // The provider configures jclouds To use the Rackspace Cloud (US)
    // To use the Rackspace Cloud (UK) set the provider to "cloudfiles-uk"
    String provider = "cloudfiles-us";
    String username = args[0];
    String apiKey = args[1];
    BlobStoreContext context = ContextBuilder.newBuilder(provider).credentials(username, apiKey).buildView(BlobStoreContext.class);
    storage = context.getBlobStore();
    swift = context.unwrap();
    rackspace = context.unwrap(CloudFilesApiMetadata.CONTEXT_TOKEN).getApi();
}
Also used : BlobStoreContext(org.jclouds.blobstore.BlobStoreContext)

Aggregations

BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)11 Properties (java.util.Properties)4 Blob (org.jclouds.blobstore.domain.Blob)3 BlobStore (org.jclouds.blobstore.BlobStore)2 BlobStoreContextFactory (org.jclouds.blobstore.BlobStoreContextFactory)2 File (java.io.File)1 InputStream (java.io.InputStream)1 ExecutionException (java.util.concurrent.ExecutionException)1 PostConstruct (javax.annotation.PostConstruct)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 AtmosClient (org.jclouds.atmos.AtmosClient)1 AzureBlobAsyncClient (org.jclouds.azureblob.AzureBlobAsyncClient)1 AzureBlobClient (org.jclouds.azureblob.AzureBlobClient)1 AsyncBlobStore (org.jclouds.blobstore.AsyncBlobStore)1 StorageMetadata (org.jclouds.blobstore.domain.StorageMetadata)1 Credentials (org.jclouds.domain.Credentials)1 Location (org.jclouds.domain.Location)1 LocationBuilder (org.jclouds.domain.LocationBuilder)1 HdfsPayload (org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload)1