Repository: jclouds-examples Updated Branches: refs/heads/master acf8dbdc9 -> 5662aae4e
update blobstore-basics to use 2.0.0 update README with SL Object Storage example address comments Project: http://git-wip-us.apache.org/repos/asf/jclouds-examples/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-examples/commit/5662aae4 Tree: http://git-wip-us.apache.org/repos/asf/jclouds-examples/tree/5662aae4 Diff: http://git-wip-us.apache.org/repos/asf/jclouds-examples/diff/5662aae4 Branch: refs/heads/master Commit: 5662aae4e916fd519d3a4cfa9f9d9440d95e2b59 Parents: acf8dbd Author: Andrea Turli <[email protected]> Authored: Thu Nov 24 11:23:58 2016 +0100 Committer: Andrea Turli <[email protected]> Committed: Tue Dec 13 16:51:20 2016 +0100 ---------------------------------------------------------------------- blobstore-basics/README.md | 11 ++++--- blobstore-basics/pom.xml | 4 +-- .../examples/blobstore/basics/MainApp.java | 31 ++++++++++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/5662aae4/blobstore-basics/README.md ---------------------------------------------------------------------- diff --git a/blobstore-basics/README.md b/blobstore-basics/README.md index 32cb8fd..e61e9c2 100755 --- a/blobstore-basics/README.md +++ b/blobstore-basics/README.md @@ -10,14 +10,17 @@ Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to bu Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-s3, googlestorage), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the container you'd like to create. -Ex. for Amazon S3 +For Amazon S3 -java -jar target/blobstore-basics-jar-with-dependencies.jar aws-s3 accesskey secretkey myfavoritecontainer + java -jar target/blobstore-basics-jar-with-dependencies.jar aws-s3 accesskey secretkey myfavoritecontainer -Ex. for Rackspace CloudFiles +For Rackspace CloudFiles -java -jar target/blobstore-basics-jar-with-dependencies.jar cloudfiles-us username apikey myfavoritecontainer + java -jar target/blobstore-basics-jar-with-dependencies.jar cloudfiles-us username apikey myfavoritecontainer +For IBM SoftLayer ObjectStore in `ams01` + + java -Djclouds.keystone.credential-type=tempAuthCredentials -Djclouds.endpoint=https://ams01.objectstorage.softlayer.net/auth/v1.0/ -jar target/blobstore-basics-jar-with-dependencies.jar openstack-swift username apikey myfavoritecontainer https://ams01.objectstorage.softlayer.net/auth/v1.0/ ## License http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/5662aae4/blobstore-basics/pom.xml ---------------------------------------------------------------------- diff --git a/blobstore-basics/pom.xml b/blobstore-basics/pom.xml index 7861ef7..4a63568 100644 --- a/blobstore-basics/pom.xml +++ b/blobstore-basics/pom.xml @@ -22,12 +22,12 @@ <modelVersion>4.0.0</modelVersion> <groupId>org.apache.jclouds.examples</groupId> <artifactId>blobstore-basics</artifactId> - <version>1.8.0</version> + <version>2.0.0</version> <name>blobstore-basics</name> <description>jclouds blobstore example that creates a container, then displays the size of each container</description> <properties> - <jclouds.version>1.9.1</jclouds.version> + <jclouds.version>2.0.0</jclouds.version> </properties> <dependencies> http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/5662aae4/blobstore-basics/src/main/java/org/jclouds/examples/blobstore/basics/MainApp.java ---------------------------------------------------------------------- diff --git a/blobstore-basics/src/main/java/org/jclouds/examples/blobstore/basics/MainApp.java b/blobstore-basics/src/main/java/org/jclouds/examples/blobstore/basics/MainApp.java index 91d6777..b72f0bd 100755 --- a/blobstore-basics/src/main/java/org/jclouds/examples/blobstore/basics/MainApp.java +++ b/blobstore-basics/src/main/java/org/jclouds/examples/blobstore/basics/MainApp.java @@ -18,6 +18,7 @@ package org.jclouds.examples.blobstore.basics; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Iterables.contains; + import java.io.IOException; import java.util.Map; import java.util.Set; @@ -36,8 +37,8 @@ import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.domain.Location; import org.jclouds.googlecloudstorage.GoogleCloudStorageApi; import org.jclouds.googlecloudstorage.GoogleCloudStorageApiMetadata; -import org.jclouds.openstack.swift.SwiftApiMetadata; import org.jclouds.openstack.swift.v1.SwiftApi; +import org.jclouds.openstack.swift.v1.SwiftApiMetadata; import org.jclouds.providers.ProviderMetadata; import org.jclouds.providers.Providers; import org.jclouds.s3.S3ApiMetadata; @@ -65,34 +66,36 @@ public class MainApp { public static final Set<String> allKeys = ImmutableSet.copyOf(Iterables.concat(appProviders.keySet(), allApis.keySet())); public static int PARAMETERS = 4; - public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: \"provider\" \"identity\" \"credential\" \"containerName\" "; + public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax is: \"provider\" \"identity\" \"credential\" \"containerName\"."; public static void main(String[] args) throws IOException { + String provider; + String identity; + String credential; + String containerName; + if (args.length < PARAMETERS) throw new IllegalArgumentException(INVALID_SYNTAX); // Args - - String provider = args[0]; - + 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]; + identity = args[1]; + credential = args[2]; + containerName = args[3]; // Init BlobStoreContext context = ContextBuilder.newBuilder(provider) - .credentials(identity, credential) - .buildView(BlobStoreContext.class); + .credentials(identity, credential) + .buildView(BlobStoreContext.class); + BlobStore blobStore = null; try { - ApiMetadata apiMetadata = context.unwrap().getProviderMetadata().getApiMetadata(); + blobStore = context.getBlobStore(); // Create Container - BlobStore blobStore = context.getBlobStore(); Location location = null; if (apiMetadata instanceof SwiftApiMetadata) { location = Iterables.getFirst(blobStore.listAssignableLocations(), null); @@ -138,6 +141,8 @@ public class MainApp { } } finally { + // delete cointainer + blobStore.deleteContainer(containerName); // Close connecton context.close(); }
