diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java index 6224b29b1a53..0c48e3442515 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java @@ -109,7 +109,7 @@ public B sizeGb(Long sizeGb) { } /** - * Sets the identity of the disk type. + * Sets the identity of the disk type. If not set {@code pd-standard} will be used. */ public B diskType(DiskTypeId diskType) { this.diskType = diskType; diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java index bbcef7e01a2a..1f55b4256a30 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java @@ -147,7 +147,10 @@ static final class BuilderImpl extends Builder { private Long lastAttachTimestamp; private Long lastDetachTimestamp; - BuilderImpl() {} + BuilderImpl(DiskId diskId, DiskConfiguration configuration) { + this.diskId = checkNotNull(diskId); + this.configuration = checkNotNull(configuration); + } BuilderImpl(DiskInfo diskInfo) { this.id = diskInfo.id; @@ -258,10 +261,10 @@ public DiskInfo build() { DiskInfo(BuilderImpl builder) { this.id = builder.id; - this.configuration = checkNotNull(builder.configuration); + this.configuration = builder.configuration; this.creationTimestamp = builder.creationTimestamp; this.creationStatus = builder.creationStatus; - this.diskId = checkNotNull(builder.diskId); + this.diskId = builder.diskId; this.description = builder.description; this.licenses = builder.licenses; this.attachedInstances = builder.attachedInstances; @@ -383,7 +386,7 @@ public boolean equals(Object obj) { * {@link ImageDiskConfiguration} to create a disk from a disk image. */ public static Builder builder(DiskId diskId, DiskConfiguration configuration) { - return new BuilderImpl().diskId(diskId).configuration(configuration); + return new BuilderImpl(diskId, configuration); } /** diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java index 480e2a03dfd0..c738251bf7ac 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java @@ -44,8 +44,9 @@ public static class Builder private ImageId sourceImage; private String sourceImageId; - private Builder() { + private Builder(ImageId sourceImage) { super(Type.IMAGE); + this.sourceImage = checkNotNull(sourceImage); } private Builder(ImageDiskConfiguration configuration) { @@ -60,6 +61,17 @@ private Builder(Disk diskPb) { this.sourceImageId = diskPb.getSourceImageId(); } + /** + * Sets the size of the persistent disk, in GB. If not set the disk will have the size of the + * image. This value can be larger than the image's size. If the provided size is smaller than + * the image's size then disk creation will fail. + */ + @Override + public Builder sizeGb(Long sizeGb) { + super.sizeGb(sizeGb); + return this; + } + /** * Sets the identity of the source image used to create the disk. */ @@ -84,7 +96,7 @@ public ImageDiskConfiguration build() { private ImageDiskConfiguration(Builder builder) { super(builder); - this.sourceImage = checkNotNull(builder.sourceImage); + this.sourceImage = builder.sourceImage; this.sourceImageId = builder.sourceImageId; } @@ -145,7 +157,7 @@ Disk toPb() { * Returns a builder for an {@code ImageDiskConfiguration} object given the image identity. */ public static Builder builder(ImageId imageId) { - return new Builder().sourceImage(imageId); + return new Builder(imageId); } /** diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java index 53b2c5dfd552..2c298608206d 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java @@ -45,8 +45,9 @@ public static class Builder private SnapshotId sourceSnapshot; private String sourceSnapshotId; - private Builder() { + private Builder(SnapshotId sourceSnapshot) { super(Type.SNAPSHOT); + this.sourceSnapshot = checkNotNull(sourceSnapshot); } private Builder(SnapshotDiskConfiguration configuration) { @@ -61,6 +62,21 @@ private Builder(Disk diskPb) { this.sourceSnapshotId = diskPb.getSourceSnapshotId(); } + /** + * Sets the size of the persistent disk, in GB. If not set the disk will have the size of the + * snapshot. This value can be larger than the snapshot's size. If the provided size is smaller + * than the snapshot's size then disk creation will fail. + * + * @see + * Restoring a snapshot to a larger size + */ + @Override + public Builder sizeGb(Long sizeGb) { + super.sizeGb(sizeGb); + return this; + } + /** * Sets the identity of the source snapshot used to create the disk. */ @@ -85,7 +101,7 @@ public SnapshotDiskConfiguration build() { private SnapshotDiskConfiguration(Builder builder) { super(builder); - this.sourceSnapshot = checkNotNull(builder.sourceSnapshot); + this.sourceSnapshot = builder.sourceSnapshot; this.sourceSnapshotId = builder.sourceSnapshotId; } @@ -148,7 +164,7 @@ Disk toPb() { * Returns a builder for a {@code SnapshotDiskConfiguration} object given the snapshot identity. */ public static Builder builder(SnapshotId sourceSnapshot) { - return new Builder().sourceSnapshot(sourceSnapshot); + return new Builder(sourceSnapshot); } /** diff --git a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java index 84816ad64a41..1d1e0e56bb6b 100644 --- a/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java +++ b/gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java @@ -48,6 +48,15 @@ private Builder(Disk diskPb) { super(Type.STANDARD, diskPb); } + /** + * Sets the size of the persistent disk, in GB. If not set, 500GB is used. + */ + @Override + public Builder sizeGb(Long sizeGb) { + super.sizeGb(sizeGb); + return this; + } + /** * Creates a {@code StandardDiskConfiguration} object. */