Updated DiskCreationOptions to AutoValue + Builder

This commit is contained in:
Daniel Broudy 2015-01-30 17:27:34 -08:00 committed by Ignasi Barrera
parent adf6999899
commit a26a721575
8 changed files with 73 additions and 75 deletions

View File

@ -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();
@SerializedNames({"type", "sizeGb", "sourceSnapshot", "description"})
static DiskCreationOptions create(URI type, Integer sizeGb, URI sourceSnapshot,
String description){
return new AutoValue_DiskCreationOptions(type, sizeGb, sourceSnapshot, 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;
DiskCreationOptions(){
}
/**
* The source snapshot
*
* @return sourceSnapshot, fully qualified URL for the snapshot to be copied.
*/
public URI sourceSnapshot() {
return sourceSnapshot;
}
public static class Builder {
/**
* The description
*
* @return description, An optional textual description of the resource.
*/
public String description() {
return description;
}
private URI type;
private Integer sizeGb;
private URI sourceSnapshot;
private String description;
/**
* @see DiskCreationOptions#type()
*/
public DiskCreationOptions type(URI type) {
this.type = type;
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#sizeGb()
*/
public DiskCreationOptions sizeGb(Integer sizeGb) {
this.sizeGb = sizeGb;
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;
}
/**
* @see DiskCreationOptions#sourceSnapshot()
*/
public DiskCreationOptions sourceSnapshot(URI sourceSnapshot) {
this.sourceSnapshot = sourceSnapshot;
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;
}
/**
* @see DiskCreationOptions#description()
*/
public DiskCreationOptions description(String description) {
this.description = description;
return this;
/**
* The description
*
* @return description, An optional textual description of the resource.
*/
public Builder description(String description) {
this.description = description;
return this;
}
public DiskCreationOptions build(){
return create(type, sizeGb, sourceSnapshot, description);
}
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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));
}

View File

@ -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")));

View File

@ -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();
}

View File

@ -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,

View File

@ -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));