Skip to content
Permalink
Browse files
update blobstore-basics to use 2.0.0
update README with SL Object Storage example
address comments
  • Loading branch information
andreaturli committed Dec 13, 2016
1 parent acf8dbd commit 5662aae4e916fd519d3a4cfa9f9d9440d95e2b59
Showing 3 changed files with 27 additions and 19 deletions.
@@ -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

@@ -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>
@@ -18,6 +18,7 @@

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.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 static void main(String[] args) throws IOException {
}

} finally {
// delete cointainer
blobStore.deleteContainer(containerName);
// Close connecton
context.close();
}

0 comments on commit 5662aae

Please sign in to comment.