You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/02/18 11:03:16 UTC

[3/5] jclouds-labs-google git commit: Updated DiskCreationOptions to AutoValue + Builder

Updated DiskCreationOptions to AutoValue + Builder


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/d0919c9b
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/d0919c9b
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/d0919c9b

Branch: refs/heads/master
Commit: d0919c9bbf3569e279380085e84b40ed23063726
Parents: 0eb54d4
Author: Daniel Broudy <br...@google.com>
Authored: Fri Jan 30 17:27:34 2015 -0800
Committer: Ignasi Barrera <na...@apache.org>
Committed: Wed Feb 18 10:58:37 2015 +0100

----------------------------------------------------------------------
 .../options/DiskCreationOptions.java            | 122 +++++++++----------
 .../options/ImageCreationOptions.java           |   2 +-
 .../binders/DiskCreationBinderTest.java         |   4 +-
 .../features/DiskApiLiveTest.java               |   4 +-
 .../features/DiskApiMockTest.java               |   8 +-
 .../features/ImageApiLiveTest.java              |   2 +-
 .../features/InstanceApiLiveTest.java           |   4 +-
 .../features/SnapshotApiLiveTest.java           |   2 +-
 8 files changed, 73 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DiskCreationOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DiskCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DiskCreationOptions.java
index 166d021..5acb015 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DiskCreationOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DiskCreationOptions.java
@@ -18,79 +18,77 @@ package org.jclouds.googlecomputeengine.options;
 
 import java.net.URI;
 
-public final class DiskCreationOptions {
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
 
-   private URI type;
-   private Integer sizeGb;
-   private URI sourceSnapshot;
-   private String description;
+import com.google.auto.value.AutoValue;
 
+@AutoValue
+public abstract class DiskCreationOptions {
 
-   /**
-    * The disk type, fully qualified URL for the disk type.
-    *
-    * @return the disk type
-    */
-   public URI type() {
-      return type;
-   }
+   @Nullable public abstract URI type();
+   @Nullable public abstract Integer sizeGb();
+   @Nullable public abstract URI sourceSnapshot();
+   @Nullable public abstract String description();
 
-   /**
-    * Size of the persistent disk, specified in GB.
-    * You can also specify this when creating a persistent disk
-    * using the sourceImage or sourceSnapshot parameter.
-    */
-   public Integer sizeGb() {
-      return sizeGb;
+   @SerializedNames({"type", "sizeGb", "sourceSnapshot", "description"})
+   static DiskCreationOptions create(URI type, Integer sizeGb, URI sourceSnapshot,
+         String description){
+      return new AutoValue_DiskCreationOptions(type, sizeGb, sourceSnapshot, description);
    }
 
-   /**
-    * The source snapshot
-    *
-    * @return sourceSnapshot, fully qualified URL for the snapshot to be copied.
-    */
-   public URI sourceSnapshot() {
-      return sourceSnapshot;
+   DiskCreationOptions(){
    }
 
-   /**
-    * The description
-    *
-    * @return description, An optional textual description of the resource.
-    */
-   public String description() {
-      return description;
-   }
+   public static class Builder {
 
-   /**
-    * @see DiskCreationOptions#type()
-    */
-   public DiskCreationOptions type(URI type) {
-      this.type = type;
-      return this;
-   }
+      private URI type;
+      private Integer sizeGb;
+      private URI sourceSnapshot;
+      private String description;
 
-   /**
-    * @see DiskCreationOptions#sizeGb()
-    */
-   public DiskCreationOptions sizeGb(Integer sizeGb) {
-      this.sizeGb = sizeGb;
-      return this;
-   }
+      /**
+       * The disk type, fully qualified URL for the disk type.
+       *
+       * @return the disk type
+       */
+      public Builder type(URI type) {
+         this.type = type;
+         return this;
+      }
 
-   /**
-    * @see DiskCreationOptions#sourceSnapshot()
-    */
-   public DiskCreationOptions sourceSnapshot(URI sourceSnapshot) {
-      this.sourceSnapshot = sourceSnapshot;
-      return this;
-   }
+      /**
+       * Size of the persistent disk, specified in GB.
+       * You can also specify this when creating a persistent disk
+       * using the sourceImage or sourceSnapshot parameter.
+       */
+      public Builder sizeGb(Integer sizeGb) {
+         this.sizeGb = sizeGb;
+         return this;
+      }
+
+      /**
+       * The source snapshot
+       *
+       * @return sourceSnapshot, fully qualified URL for the snapshot to be copied.
+       */
+      public Builder sourceSnapshot(URI sourceSnapshot) {
+         this.sourceSnapshot = sourceSnapshot;
+         return this;
+      }
+
+      /**
+       * The description
+       *
+       * @return description, An optional textual description of the resource.
+       */
+      public Builder description(String description) {
+         this.description = description;
+         return this;
+      }
 
-   /**
-    * @see DiskCreationOptions#description()
-    */
-   public DiskCreationOptions description(String description) {
-      this.description = description;
-      return this;
+      public DiskCreationOptions build(){
+         return create(type, sizeGb, sourceSnapshot, description);
+      }
    }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ImageCreationOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ImageCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ImageCreationOptions.java
index cb75d1d..0a33ada 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ImageCreationOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ImageCreationOptions.java
@@ -42,7 +42,7 @@ public abstract class ImageCreationOptions {
       return new AutoValue_ImageCreationOptions(name, description, sourceType, rawDisk, deprecated, sourceDisk);
    }
 
-   public static class Builder{
+   public static class Builder {
       public String name;
       public String description;
       public String sourceType;

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinderTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinderTest.java
index 3467ab4..a8b614e 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinderTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/DiskCreationBinderTest.java
@@ -38,8 +38,8 @@ public class DiskCreationBinderTest extends BaseGoogleComputeEngineExpectTest<Ob
 
    @Test
    public void testMap() throws SecurityException, NoSuchMethodException {
-      DiskCreationOptions diskCreationOptions = new DiskCreationOptions()
-         .sourceSnapshot(URI.create(FAKE_SOURCE_SNAPSHOT)).sizeGb(15).description(null);
+      DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder()
+         .sourceSnapshot(URI.create(FAKE_SOURCE_SNAPSHOT)).sizeGb(15).description(null).build();
 
       HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
       Map<String, Object> postParams = ImmutableMap.of("name", "testName", "options", diskCreationOptions);

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
index b071f20..ec020bc 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
@@ -42,7 +42,7 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
 
    @Test(groups = "live")
    public void testInsertDisk() {
-      DiskCreationOptions options = new DiskCreationOptions().sizeGb( SIZE_GB);
+      DiskCreationOptions options = new DiskCreationOptions.Builder().sizeGb( SIZE_GB).build();
       assertOperationDoneSuccessfully(api().create(DISK_NAME, options));
    }
 
@@ -78,7 +78,7 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
    @Test(groups = "live")
    public void testInsertSSDDisk() {
       URI diskType = getDiskTypeUrl(DEFAULT_ZONE_NAME, "pd-ssd");
-      DiskCreationOptions diskCreationOptions = new DiskCreationOptions().type(diskType).sizeGb(SIZE_GB);
+      DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder().type(diskType).sizeGb(SIZE_GB).build();
       assertOperationDoneSuccessfully(api().create(SSD_DISK_NAME, diskCreationOptions));
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java
index 9c5a1e6..13f9d25 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java
@@ -52,7 +52,7 @@ public class DiskApiMockTest extends BaseGoogleComputeEngineApiMockTest {
    public void insert() throws Exception {
       server.enqueue(jsonResponse("/zone_operation.json"));
 
-      DiskCreationOptions options = new DiskCreationOptions().sizeGb(1);
+      DiskCreationOptions options = new DiskCreationOptions.Builder().sizeGb(1).build();
       assertEquals(diskApi().create("testimage1", options),
             new ParseZoneOperationTest().expected(url("/projects")));
 
@@ -63,7 +63,7 @@ public class DiskApiMockTest extends BaseGoogleComputeEngineApiMockTest {
    public void insertFromImage() throws Exception {
       server.enqueue(jsonResponse("/zone_operation.json"));
 
-      DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sizeGb(1).description("testing 123");
+      DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder().sizeGb(1).description("testing 123").build();
 
       assertEquals(diskApi().create("testimage1", url(IMAGE_URL), diskCreationOptions),
             new ParseZoneOperationTest().expected(url("/projects")));
@@ -76,8 +76,8 @@ public class DiskApiMockTest extends BaseGoogleComputeEngineApiMockTest {
    public void insertFromSSD() throws Exception {
       server.enqueue(jsonResponse("/zone_operation.json"));
 
-      DiskCreationOptions diskCreationOptions = new DiskCreationOptions()
-         .type(URI.create(url(SSD_URL))).sizeGb(1);
+      DiskCreationOptions diskCreationOptions = new DiskCreationOptions.Builder()
+         .type(URI.create(url(SSD_URL))).sizeGb(1).build();
 
       assertEquals(diskApi().create("testimage1", diskCreationOptions),
             new ParseZoneOperationTest().expected(url("/projects")));

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
index 3b6494d..db6346d 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
@@ -70,7 +70,7 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
    @Test(groups = "live")
    public void testInsertDisk() {
       assertOperationDoneSuccessfully(diskApi().create(DISK_NAME,
-            new DiskCreationOptions().sizeGb(sizeGb)));
+            new DiskCreationOptions.Builder().sizeGb(sizeGb).build()));
       Disk disk = diskApi().get(DISK_NAME);
       diskURI = disk.selfLink();
    }

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
index 266d759..4c74a3d 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
@@ -122,7 +122,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
               (INSTANCE_NETWORK_NAME, IPV4_RANGE));
 
       assertOperationDoneSuccessfully(diskApi().create(DISK_NAME,
-            new DiskCreationOptions().sizeGb(DEFAULT_DISK_SIZE_GB)));
+            new DiskCreationOptions.Builder().sizeGb(DEFAULT_DISK_SIZE_GB).build()));
       assertOperationDoneSuccessfully(api().create(instance));
       assertOperationDoneSuccessfully(api().create(instance2));
    }
@@ -236,7 +236,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
    @Test(groups = "live", dependsOnMethods = "testSetMetadataForInstance")
    public void testAttachDiskToInstance() {
       assertOperationDoneSuccessfully(diskApi().create(ATTACH_DISK_NAME,
-            new DiskCreationOptions().sizeGb(1)));
+            new DiskCreationOptions.Builder().sizeGb(1).build()));
 
       Instance originalInstance = api().get(INSTANCE_NAME);
       assertOperationDoneSuccessfully(api().attachDisk(INSTANCE_NAME,

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d0919c9b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
index cec6ffa..57c76cb 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
@@ -46,7 +46,7 @@ public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
    @Test(groups = "live")
    public void testCreateSnapshot() {
       assertOperationDoneSuccessfully(diskApi().create(DISK_NAME,
-            new DiskCreationOptions().sizeGb(1)));
+            new DiskCreationOptions.Builder().sizeGb(1).build()));
       disk = diskApi().get(DISK_NAME);
 
       assertOperationDoneSuccessfully(diskApi().createSnapshot(DISK_NAME, SNAPSHOT_NAME));