You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2015/08/06 00:56:57 UTC

jclouds-examples git commit: Use real location for openstack-swift

Repository: jclouds-examples
Updated Branches:
  refs/heads/master dfb1c6e62 -> 8a0718e77


Use real location for openstack-swift


Project: http://git-wip-us.apache.org/repos/asf/jclouds-examples/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-examples/commit/8a0718e7
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-examples/tree/8a0718e7
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-examples/diff/8a0718e7

Branch: refs/heads/master
Commit: 8a0718e7761a1af2f14f3d1dcc93c7da47ae7d2e
Parents: dfb1c6e
Author: Andrew Gaul <ga...@apache.org>
Authored: Wed Aug 5 15:53:00 2015 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Wed Aug 5 15:56:04 2015 -0700

----------------------------------------------------------------------
 .../org/jclouds/examples/blobstore/basics/MainApp.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/8a0718e7/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 1c91976..91d6777 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
@@ -33,6 +33,7 @@ import org.jclouds.blobstore.BlobStore;
 import org.jclouds.blobstore.BlobStoreContext;
 import org.jclouds.blobstore.domain.Blob;
 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;
@@ -81,7 +82,6 @@ public class MainApp {
       String identity = args[1];
       String credential = args[2];
       String containerName = args[3];
-      String region = "some-region";
 
       // Init
       BlobStoreContext context = ContextBuilder.newBuilder(provider)
@@ -90,9 +90,14 @@ public class MainApp {
 
       try {
 
+         ApiMetadata apiMetadata = context.unwrap().getProviderMetadata().getApiMetadata();
          // Create Container
          BlobStore blobStore = context.getBlobStore();
-         blobStore.createContainerInLocation(null, containerName);
+         Location location = null;
+         if (apiMetadata instanceof SwiftApiMetadata) {
+            location = Iterables.getFirst(blobStore.listAssignableLocations(), null);
+         }
+         blobStore.createContainerInLocation(location, containerName);
          String blobName = "test";
          ByteSource payload = ByteSource.wrap("testdata".getBytes(Charsets.UTF_8));
 
@@ -111,14 +116,13 @@ public class MainApp {
          blobStore.putBlob(containerName, blob);
 
          // Use Provider API
-         ApiMetadata apiMetadata = context.unwrap().getProviderMetadata().getApiMetadata();
          Object object = null;
          if (apiMetadata instanceof S3ApiMetadata) {
             S3Client api = context.unwrapApi(S3Client.class);
             object = api.headObject(containerName, blobName);
          } else if (apiMetadata instanceof SwiftApiMetadata) {
             SwiftApi api = context.unwrapApi(SwiftApi.class);
-            object = api.getObjectApi(region, containerName).getWithoutBody(blobName);
+            object = api.getObjectApi(location.getId(), containerName).getWithoutBody(blobName);
          } else if (apiMetadata instanceof AzureBlobApiMetadata) {
             AzureBlobClient api = context.unwrapApi(AzureBlobClient.class);
             object = api.getBlobProperties(containerName, blobName);