Skip to content

Commit 520d7b2

Browse files
committed
Minor fixes to DiskInfo and configuration
- Add required fields to Builder constructors - Remove redundant checkNotNull - Better document sizeGb and diskType setters
1 parent 1fb53fa commit 520d7b2

5 files changed

Lines changed: 51 additions & 11 deletions

File tree

gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public B sizeGb(Long sizeGb) {
109109
}
110110

111111
/**
112-
* Sets the identity of the disk type.
112+
* Sets the identity of the disk type. If not set {@code pd-standard} will be used.
113113
*/
114114
public B diskType(DiskTypeId diskType) {
115115
this.diskType = diskType;

gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskInfo.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ static final class BuilderImpl extends Builder {
147147
private Long lastAttachTimestamp;
148148
private Long lastDetachTimestamp;
149149

150-
BuilderImpl() {}
150+
BuilderImpl(DiskId diskId, DiskConfiguration configuration) {
151+
this.diskId = checkNotNull(diskId);
152+
this.configuration = checkNotNull(configuration);
153+
}
151154

152155
BuilderImpl(DiskInfo diskInfo) {
153156
this.id = diskInfo.id;
@@ -258,10 +261,10 @@ public DiskInfo build() {
258261

259262
DiskInfo(BuilderImpl builder) {
260263
this.id = builder.id;
261-
this.configuration = checkNotNull(builder.configuration);
264+
this.configuration = builder.configuration;
262265
this.creationTimestamp = builder.creationTimestamp;
263266
this.creationStatus = builder.creationStatus;
264-
this.diskId = checkNotNull(builder.diskId);
267+
this.diskId = builder.diskId;
265268
this.description = builder.description;
266269
this.licenses = builder.licenses;
267270
this.attachedInstances = builder.attachedInstances;
@@ -383,7 +386,7 @@ public boolean equals(Object obj) {
383386
* {@link ImageDiskConfiguration} to create a disk from a disk image.
384387
*/
385388
public static Builder builder(DiskId diskId, DiskConfiguration configuration) {
386-
return new BuilderImpl().diskId(diskId).configuration(configuration);
389+
return new BuilderImpl(diskId, configuration);
387390
}
388391

389392
/**

gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageDiskConfiguration.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public static class Builder
4444
private ImageId sourceImage;
4545
private String sourceImageId;
4646

47-
private Builder() {
47+
private Builder(ImageId sourceImage) {
4848
super(Type.IMAGE);
49+
this.sourceImage = checkNotNull(sourceImage);
4950
}
5051

5152
private Builder(ImageDiskConfiguration configuration) {
@@ -60,6 +61,17 @@ private Builder(Disk diskPb) {
6061
this.sourceImageId = diskPb.getSourceImageId();
6162
}
6263

64+
/**
65+
* Sets the size of the persistent disk, in GB. If not set the disk will have the size of the
66+
* image. This value can be larger than the image's size. If the provided size is smaller than
67+
* the image's size then disk creation will fail.
68+
*/
69+
@Override
70+
public Builder sizeGb(Long sizeGb) {
71+
super.sizeGb(sizeGb);
72+
return this;
73+
}
74+
6375
/**
6476
* Sets the identity of the source image used to create the disk.
6577
*/
@@ -84,7 +96,7 @@ public ImageDiskConfiguration build() {
8496

8597
private ImageDiskConfiguration(Builder builder) {
8698
super(builder);
87-
this.sourceImage = checkNotNull(builder.sourceImage);
99+
this.sourceImage = builder.sourceImage;
88100
this.sourceImageId = builder.sourceImageId;
89101
}
90102

@@ -145,7 +157,7 @@ Disk toPb() {
145157
* Returns a builder for an {@code ImageDiskConfiguration} object given the image identity.
146158
*/
147159
public static Builder builder(ImageId imageId) {
148-
return new Builder().sourceImage(imageId);
160+
return new Builder(imageId);
149161
}
150162

151163
/**

gcloud-java-compute/src/main/java/com/google/gcloud/compute/SnapshotDiskConfiguration.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public static class Builder
4545
private SnapshotId sourceSnapshot;
4646
private String sourceSnapshotId;
4747

48-
private Builder() {
48+
private Builder(SnapshotId sourceSnapshot) {
4949
super(Type.SNAPSHOT);
50+
this.sourceSnapshot = checkNotNull(sourceSnapshot);
5051
}
5152

5253
private Builder(SnapshotDiskConfiguration configuration) {
@@ -61,6 +62,21 @@ private Builder(Disk diskPb) {
6162
this.sourceSnapshotId = diskPb.getSourceSnapshotId();
6263
}
6364

65+
/**
66+
* Sets the size of the persistent disk, in GB. If not set the disk will have the size of the
67+
* snapshot. This value can be larger than the snapshot's size. If the provided size is smaller
68+
* than the snapshot's size then disk creation will fail.
69+
*
70+
* @see <a href=
71+
* "https://cloud.google.com/compute/docs/disks/persistent-disks#restoresnapshotlargersize">
72+
* Restoring a snapshot to a larger size</a>
73+
*/
74+
@Override
75+
public Builder sizeGb(Long sizeGb) {
76+
super.sizeGb(sizeGb);
77+
return this;
78+
}
79+
6480
/**
6581
* Sets the identity of the source snapshot used to create the disk.
6682
*/
@@ -85,7 +101,7 @@ public SnapshotDiskConfiguration build() {
85101

86102
private SnapshotDiskConfiguration(Builder builder) {
87103
super(builder);
88-
this.sourceSnapshot = checkNotNull(builder.sourceSnapshot);
104+
this.sourceSnapshot = builder.sourceSnapshot;
89105
this.sourceSnapshotId = builder.sourceSnapshotId;
90106
}
91107

@@ -148,7 +164,7 @@ Disk toPb() {
148164
* Returns a builder for a {@code SnapshotDiskConfiguration} object given the snapshot identity.
149165
*/
150166
public static Builder builder(SnapshotId sourceSnapshot) {
151-
return new Builder().sourceSnapshot(sourceSnapshot);
167+
return new Builder(sourceSnapshot);
152168
}
153169

154170
/**

gcloud-java-compute/src/main/java/com/google/gcloud/compute/StandardDiskConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ private Builder(Disk diskPb) {
4848
super(Type.STANDARD, diskPb);
4949
}
5050

51+
/**
52+
* Sets the size of the persistent disk, in GB. If not set, 500GB is used.
53+
*/
54+
@Override
55+
public Builder sizeGb(Long sizeGb) {
56+
super.sizeGb(sizeGb);
57+
return this;
58+
}
59+
5160
/**
5261
* Creates a {@code StandardDiskConfiguration} object.
5362
*/

0 commit comments

Comments
 (0)