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);
}
}
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();
}
}
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();
}
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();
}
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();
}
Aggregations