Skip to content

Commit

Permalink
Minor fixes to DiskInfo and configuration
Browse files Browse the repository at this point in the history
- Add required fields to Builder constructors
- Remove redundant checkNotNull
- Better document sizeGb and diskType setters
  • Loading branch information
mziccard committed Apr 7, 2016
1 parent 1fb53fa commit 759c17a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
*/
Expand All @@ -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;
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 <a href="
* https://cloud.google.com/compute/docs/disks/persistent-disks#restoresnapshotlargersize">
* Restoring a snapshot to a larger size</a>
*/
@Override
public Builder sizeGb(Long sizeGb) {
super.sizeGb(sizeGb);
return this;
}

/**
* Sets the identity of the source snapshot used to create the disk.
*/
Expand All @@ -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;
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 759c17a

Please sign in to comment.