You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/11/05 17:34:54 UTC

git commit: Another cleanup of GCS.

Repository: jclouds-labs-google
Updated Branches:
  refs/heads/master 3a2ae5e97 -> 1e86ef644


Another cleanup of GCS.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/1e86ef64
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/1e86ef64
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/1e86ef64

Branch: refs/heads/master
Commit: 1e86ef6445002a750e2eba63c9c3080eade71fb3
Parents: 3a2ae5e
Author: Adrian Cole <ac...@twitter.com>
Authored: Tue Nov 4 11:15:31 2014 -0800
Committer: Adrian Cole <ac...@twitter.com>
Committed: Wed Nov 5 08:28:36 2014 -0800

----------------------------------------------------------------------
 .../GoogleCloudStorageFallbacks.java            | 52 ++++++++++++++++++++
 .../fallback/GCSFallbacks.java                  | 34 -------------
 .../googlecloudstorage/features/BucketApi.java  |  9 ++--
 .../googlecloudstorage/features/ObjectApi.java  | 11 ++---
 .../features/BucketApiExpectTest.java           |  7 +--
 .../features/ObjectApiLiveTest.java             | 14 +++---
 6 files changed, 72 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/1e86ef64/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageFallbacks.java
----------------------------------------------------------------------
diff --git a/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageFallbacks.java b/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageFallbacks.java
new file mode 100644
index 0000000..5855015
--- /dev/null
+++ b/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/GoogleCloudStorageFallbacks.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecloudstorage;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Throwables.propagate;
+import static org.jclouds.Fallbacks.valOnNotFoundOr404;
+
+import java.util.Iterator;
+
+import org.jclouds.Fallback;
+import org.jclouds.googlecloudstorage.domain.ListPage;
+
+import com.google.common.collect.Iterators;
+
+public final class GoogleCloudStorageFallbacks {
+
+   public static final class NullOnBucketAlreadyExists implements Fallback<Object> {
+      public Object createOrPropagate(Throwable t) throws Exception {
+         if (checkNotNull(t, "throwable") instanceof IllegalStateException) {
+            return null;
+         }
+         throw propagate(t);
+      }
+   }
+
+   public static final class EmptyListPageOnNotFoundOr404 implements Fallback<Object> {
+      @Override public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
+         return valOnNotFoundOr404(ListPage.create(null, null, null), t);
+      }
+   }
+
+   public static final class EmptyIteratorOnNotFoundOr404 implements Fallback<Object> {
+      @Override public Iterator<Object> createOrPropagate(Throwable t) throws Exception {
+         return valOnNotFoundOr404(Iterators.emptyIterator(), t);
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/1e86ef64/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/fallback/GCSFallbacks.java
----------------------------------------------------------------------
diff --git a/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/fallback/GCSFallbacks.java b/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/fallback/GCSFallbacks.java
deleted file mode 100644
index 88e24ca..0000000
--- a/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/fallback/GCSFallbacks.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.googlecloudstorage.fallback;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Throwables.propagate;
-
-import org.jclouds.Fallback;
-
-public final class GCSFallbacks {
-
-   public static final class NullOnBucketAlreadyExists implements Fallback<Object> {
-      public Object createOrPropagate(Throwable t) throws Exception {
-         if (checkNotNull(t, "throwable") instanceof IllegalStateException) {
-            return null;
-         }
-         throw propagate(t);
-      }
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/1e86ef64/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java
----------------------------------------------------------------------
diff --git a/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java b/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java
index ebb120d..a6dd146 100644
--- a/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java
+++ b/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java
@@ -35,10 +35,11 @@ import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
 import org.jclouds.Fallbacks.NullOnNotFoundOr404;
 import org.jclouds.Fallbacks.TrueOnNotFoundOr404;
 import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists;
+import org.jclouds.googlecloudstorage.GoogleCloudStorageFallbacks.EmptyListPageOnNotFoundOr404;
+import org.jclouds.googlecloudstorage.GoogleCloudStorageFallbacks.NullOnBucketAlreadyExists;
 import org.jclouds.googlecloudstorage.domain.Bucket;
 import org.jclouds.googlecloudstorage.domain.ListPage;
 import org.jclouds.googlecloudstorage.domain.templates.BucketTemplate;
-import org.jclouds.googlecloudstorage.fallback.GCSFallbacks.NullOnBucketAlreadyExists;
 import org.jclouds.googlecloudstorage.options.DeleteBucketOptions;
 import org.jclouds.googlecloudstorage.options.GetBucketOptions;
 import org.jclouds.googlecloudstorage.options.InsertBucketOptions;
@@ -202,8 +203,7 @@ public interface BucketApi {
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/b")
    @OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
-   @Fallback(NullOnNotFoundOr404.class)
-   @Nullable
+   @Fallback(EmptyListPageOnNotFoundOr404.class)
    ListPage<Bucket> listBucket(@QueryParam("project") String projectId);
 
    /**
@@ -220,8 +220,7 @@ public interface BucketApi {
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/b")
    @OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
-   @Fallback(NullOnNotFoundOr404.class)
-   @Nullable
+   @Fallback(EmptyListPageOnNotFoundOr404.class)
    ListPage<Bucket> listBucket(@QueryParam("project") String projectId, ListOptions options);
 
    /**

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/1e86ef64/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
----------------------------------------------------------------------
diff --git a/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java b/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
index 75cdf2d..e058647 100644
--- a/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
+++ b/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
@@ -34,6 +34,7 @@ import javax.ws.rs.core.MediaType;
 import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
 import org.jclouds.Fallbacks.NullOnNotFoundOr404;
 import org.jclouds.Fallbacks.TrueOnNotFoundOr404;
+import org.jclouds.googlecloudstorage.GoogleCloudStorageFallbacks.EmptyListPageOnNotFoundOr404;
 import org.jclouds.googlecloudstorage.binders.MultipartUploadBinder;
 import org.jclouds.googlecloudstorage.binders.UploadBinder;
 import org.jclouds.googlecloudstorage.domain.GCSObject;
@@ -48,8 +49,8 @@ import org.jclouds.googlecloudstorage.options.InsertObjectOptions;
 import org.jclouds.googlecloudstorage.options.ListObjectOptions;
 import org.jclouds.googlecloudstorage.options.UpdateObjectOptions;
 import org.jclouds.googlecloudstorage.parser.ParseToPayloadEnclosing;
-import org.jclouds.http.internal.PayloadEnclosingImpl;
 import org.jclouds.io.Payload;
+import org.jclouds.io.PayloadEnclosing;
 import org.jclouds.javax.annotation.Nullable;
 import org.jclouds.oauth.v2.config.OAuthScopes;
 import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
@@ -154,7 +155,7 @@ public interface ObjectApi {
    @ResponseParser(ParseToPayloadEnclosing.class)
    @Fallback(NullOnNotFoundOr404.class)
    @Nullable
-   PayloadEnclosingImpl download(@PathParam("bucket") String bucketName, @PathParam("object") String objectName);
+   PayloadEnclosing download(@PathParam("bucket") String bucketName, @PathParam("object") String objectName);
 
    /**
     * Retrieves objects
@@ -177,8 +178,7 @@ public interface ObjectApi {
    @ResponseParser(ParseToPayloadEnclosing.class)
    @OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
    @Fallback(NullOnNotFoundOr404.class)
-   @Nullable
-   PayloadEnclosingImpl download(@PathParam("bucket") String bucketName, @PathParam("object") String objectName,
+   @Nullable PayloadEnclosing download(@PathParam("bucket") String bucketName, @PathParam("object") String objectName,
             GetObjectOptions options);
 
    /**
@@ -254,8 +254,7 @@ public interface ObjectApi {
    @Produces(MediaType.APPLICATION_JSON)
    @Path("storage/v1/b/{bucket}/o")
    @OAuthScopes(STORAGE_FULLCONTROL_SCOPE)
-   @Fallback(NullOnNotFoundOr404.class)
-   @Nullable
+   @Fallback(EmptyListPageOnNotFoundOr404.class)
    ListPage<GCSObject> listObjects(@PathParam("bucket") String bucketName);
 
    /**

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/1e86ef64/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiExpectTest.java b/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiExpectTest.java
index ef41d71..cc42510 100644
--- a/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiExpectTest.java
+++ b/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiExpectTest.java
@@ -20,21 +20,22 @@ package org.jclouds.googlecloudstorage.features;
 import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_FULLCONTROL_SCOPE;
 import static org.jclouds.googlecloudstorage.reference.GoogleCloudStorageConstants.STORAGE_READONLY_SCOPE;
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
 import static org.testng.AssertJUnit.assertNull;
 
 import javax.ws.rs.core.MediaType;
 
 import org.jclouds.googlecloudstorage.domain.BucketAccessControls;
-import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Projection;
 import org.jclouds.googlecloudstorage.domain.BucketAccessControls.Role;
+import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Projection;
 import org.jclouds.googlecloudstorage.domain.templates.BucketTemplate;
 import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageApiExpectTest;
 import org.jclouds.googlecloudstorage.options.GetBucketOptions;
 import org.jclouds.googlecloudstorage.options.ListOptions;
 import org.jclouds.googlecloudstorage.options.UpdateBucketOptions;
 import org.jclouds.googlecloudstorage.parse.BucketUpdateTest;
-import org.jclouds.googlecloudstorage.parse.NoAclBucketTest;
 import org.jclouds.googlecloudstorage.parse.NoAclBucketListTest;
+import org.jclouds.googlecloudstorage.parse.NoAclBucketTest;
 import org.jclouds.http.HttpRequest;
 import org.jclouds.http.HttpResponse;
 import org.testng.annotations.Test;
@@ -126,7 +127,7 @@ public class BucketApiExpectTest extends BaseGoogleCloudStorageApiExpectTest {
       BucketApi api = requestsSendResponses(requestForScopes(STORAGE_FULLCONTROL_SCOPE), TOKEN_RESPONSE,
                LIST_BUCKET_REQUEST, listResponse).getBucketApi();
 
-      assertNull(api.listBucket(EXPECTED_TEST_PROJECT_NUMBER));
+      assertTrue(api.listBucket(EXPECTED_TEST_PROJECT_NUMBER).isEmpty());
    }
 
    // Test createBucket without options

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/1e86ef64/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java b/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
index b133b63..0fb79af 100644
--- a/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
+++ b/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
@@ -49,6 +49,7 @@ import org.jclouds.googlecloudstorage.options.UpdateObjectOptions;
 import org.jclouds.http.internal.PayloadEnclosingImpl;
 import org.jclouds.io.ByteStreams2;
 import org.jclouds.io.ContentMetadata;
+import org.jclouds.io.PayloadEnclosing;
 import org.jclouds.io.Payloads;
 import org.jclouds.io.payloads.ByteSourcePayload;
 import org.jclouds.utils.TestUtils;
@@ -74,7 +75,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
    private static final String COMPOSED_OBJECT = "ComposedObject1.txt";
    private static final String COMPOSED_OBJECT2 = "ComposedObject2.json";
 
-   private PayloadEnclosingImpl testPayload;
+   private PayloadEnclosing testPayload;
    private Long RANDOM_LONG = 100L;
 
    private Long metageneration;
@@ -105,8 +106,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
       ByteSource byteSource = TestUtils.randomByteSource().slice(0, contentLength);
       ByteSourcePayload byteSourcePayload = Payloads.newByteSourcePayload(byteSource);
 
-      PayloadEnclosingImpl payload = new PayloadEnclosingImpl();
-      payload.setPayload(byteSourcePayload);
+      PayloadEnclosing payload = new PayloadEnclosingImpl(byteSourcePayload);
       payload.getPayload().getContentMetadata().setContentLength(contentLength);
 
       this.testPayload = payload;
@@ -123,7 +123,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
 
    @Test(groups = "live", dependsOnMethods = "testSimpleUpload")
    public void testDownload() throws IOException {
-      PayloadEnclosingImpl impl = api().download(BUCKET_NAME, UPLOAD_OBJECT_NAME);
+      PayloadEnclosing impl = api().download(BUCKET_NAME, UPLOAD_OBJECT_NAME);
       ContentMetadata meta = impl.getPayload().getContentMetadata();
       assertNotNull(impl);
       assertNotNull(impl.getPayload());
@@ -196,7 +196,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
 
       // Test for data
 
-      PayloadEnclosingImpl impl = api().download(BUCKET_NAME2, COPIED_OBJECT_NAME);
+      PayloadEnclosing impl = api().download(BUCKET_NAME2, COPIED_OBJECT_NAME);
       assertNotNull(impl);
       assertEquals(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream()),
                ByteStreams2.toByteArrayAndClose(testPayload.getPayload().openStream()));
@@ -364,7 +364,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
       long contentLength = 32 * 1024L;
       ByteSource byteSource = TestUtils.randomByteSource().slice(0, contentLength);
       ByteSourcePayload payload = Payloads.newByteSourcePayload(byteSource);
-      PayloadEnclosingImpl payloadImpl = new PayloadEnclosingImpl(payload);
+      PayloadEnclosing payloadImpl = new PayloadEnclosingImpl(payload);
 
       ObjectTemplate template = new ObjectTemplate();
 
@@ -389,7 +389,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
       assertThat(gcsObject.metadata()).contains(entry("custommetakey1", "custommetavalue1"),
                entry("Adrian", "powderpuff")).doesNotContainKey("adrian");
 
-      PayloadEnclosingImpl impl = api().download(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT);
+      PayloadEnclosing impl = api().download(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT);
 
       assertThat(ByteStreams2.toByteArrayAndClose(impl.getPayload().openStream())).isEqualTo(
                ByteStreams2.toByteArrayAndClose(payloadImpl.getPayload().openStream()));