Skip to content

Commit

Permalink
Minor changes to AttachedDisk
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Apr 22, 2016
1 parent 75fa8e2 commit ba8b011
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public AttachedDisk apply(
};
static final Function<AttachedDisk, com.google.api.services.compute.model.AttachedDisk>
TO_PB_FUNCTION =
new Function<AttachedDisk,
com.google.api.services.compute.model.AttachedDisk>() {
new Function<AttachedDisk, com.google.api.services.compute.model.AttachedDisk>() {
@Override
public com.google.api.services.compute.model.AttachedDisk apply(
AttachedDisk attachedDisk) {
Expand Down Expand Up @@ -233,7 +232,9 @@ public static final class Builder {
private Boolean boot;
private Boolean autoDelete;

private Builder() {}
private Builder(DiskId sourceDisk) {
this.sourceDisk = checkNotNull(sourceDisk);
}

private Builder(PersistentDiskConfiguration configuration) {
sourceDisk = configuration.sourceDisk;
Expand Down Expand Up @@ -261,8 +262,8 @@ public Builder mode(Mode mode) {

/**
* Sets whether to use the attached disk as a boot disk. If {@code true} the virtual machine
* will use the first partition of the disk for its root filesystem. If not specified, the
* disk is not used as a boot disk.
* instance will use the first partition of the disk for its root filesystem. If not
* specified, the isk is not used as a boot disk.
*/
public Builder boot(boolean boot) {
this.boot = boot;
Expand All @@ -286,9 +287,9 @@ public PersistentDiskConfiguration build() {
}
}

PersistentDiskConfiguration(Builder builder) {
private PersistentDiskConfiguration(Builder builder) {
super(Type.PERSISTENT, null, builder.boot, builder.autoDelete);
this.sourceDisk = checkNotNull(builder.sourceDisk);
this.sourceDisk = builder.sourceDisk;
this.mode = builder.mode;
}

Expand Down Expand Up @@ -353,7 +354,7 @@ com.google.api.services.compute.model.AttachedDisk toPb() {
* persistent disk to attach.
*/
public static Builder builder(DiskId sourceDisk) {
return new Builder().sourceDisk(sourceDisk);
return new Builder(sourceDisk);
}

/**
Expand All @@ -367,8 +368,7 @@ public static PersistentDiskConfiguration of(DiskId sourceDisk) {
@SuppressWarnings("unchecked")
static PersistentDiskConfiguration fromPb(
com.google.api.services.compute.model.AttachedDisk diskPb) {
Builder builder = new Builder();
builder.sourceDisk(DiskId.fromUrl(diskPb.getSource()));
Builder builder = new Builder(DiskId.fromUrl(diskPb.getSource()));
if (diskPb.getMode() != null) {
builder.mode(Mode.valueOf(diskPb.getMode()));
}
Expand All @@ -385,7 +385,9 @@ static PersistentDiskConfiguration fromPb(
/**
* An attached disk configuration for bootable persistent disks that must be created with the
* instance they are attached to. Attached disks that use this configuration can only be attached
* to an instance upon creation.
* to an instance upon creation. A {@code CreateDiskConfiguration} object is never returned by the
* service: after the instance is created the corresponding attached disk will be returned with a
* {@link PersistentDiskConfiguration}.
*/
public static final class CreateDiskConfiguration extends AttachedDiskConfiguration {

Expand All @@ -407,7 +409,9 @@ public static final class Builder {
private ImageId sourceImage;
private Boolean autoDelete;

private Builder() {}
private Builder(ImageId sourceImage) {
this.sourceImage = checkNotNull(sourceImage);
}

private Builder(CreateDiskConfiguration configuration) {
this.diskName = configuration.diskName;
Expand Down Expand Up @@ -436,8 +440,8 @@ public Builder diskType(DiskTypeId diskType) {

/**
* 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 instance creation will fail.
* source image. This value can be larger than the image's size. If the provided size is
* smaller than the image's size, then instance creation will fail.
*/
public Builder diskSizeGb(Long diskSizeGb) {
this.diskSizeGb = diskSizeGb;
Expand Down Expand Up @@ -469,12 +473,12 @@ public CreateDiskConfiguration build() {
}
}

CreateDiskConfiguration(Builder builder) {
private CreateDiskConfiguration(Builder builder) {
super(Type.PERSISTENT, null, true, builder.autoDelete);
this.diskName = builder.diskName;
this.diskType = builder.diskType;
this.diskSizeGb = builder.diskSizeGb;
this.sourceImage = checkNotNull(builder.sourceImage);
this.sourceImage = builder.sourceImage;
}

/**
Expand All @@ -494,8 +498,8 @@ public DiskTypeId diskType() {

/**
* Returns 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 instance creation will fail.
* source image. This value can be larger than the image's size. If the provided size is smaller
* than the image's size then instance creation will fail.
*/
public Long diskSizeGb() {
return diskSizeGb;
Expand Down Expand Up @@ -568,7 +572,7 @@ com.google.api.services.compute.model.AttachedDisk toPb() {
* will be used to create the disk.
*/
public static Builder builder(ImageId sourceImage) {
return new Builder().sourceImage(sourceImage);
return new Builder(sourceImage);
}

/**
Expand Down Expand Up @@ -623,7 +627,7 @@ private Builder(ScratchDiskConfiguration configuration) {
}

/**
* Sets the identity of the disk type.
* Sets the identity of the disk type for the scratch disk to attach.
*/
public Builder diskType(DiskTypeId diskType) {
this.diskType = diskType;
Expand All @@ -646,7 +650,7 @@ public ScratchDiskConfiguration build() {
}
}

ScratchDiskConfiguration(Builder builder) {
private ScratchDiskConfiguration(Builder builder) {
super(Type.SCRATCH, builder.interfaceType, false, true);
this.diskType = builder.diskType;
}
Expand Down Expand Up @@ -827,7 +831,7 @@ public Integer index() {
}

/**
* Sets the attached disk configuration. Returns {@link ScratchDiskConfiguration} to attach a
* Returns the attached disk configuration. Returns {@link ScratchDiskConfiguration} to attach a
* scratch disk to the instance. Returns {@link PersistentDiskConfiguration} to attach a
* persistent disk to the instance. Returns {@link CreateDiskConfiguration} to create and attach
* a new persistent disk.
Expand All @@ -838,7 +842,7 @@ public <T extends AttachedDiskConfiguration> T configuration() {
}

/**
* Returns a list of publicly accessible licenses.
* Returns a list of publicly accessible licenses for the attached disk.
*/
public List<LicenseId> licenses() {
return licenses;
Expand Down Expand Up @@ -903,7 +907,7 @@ public static AttachedDisk of(AttachedDiskConfiguration configuration) {
}

/**
* Returns an {@code AttachedDisk} object given its configuration and the device name.
* Returns an {@code AttachedDisk} object given the device name and its configuration.
*/
public static AttachedDisk of(String deviceName, AttachedDiskConfiguration configuration) {
return builder(configuration).deviceName(deviceName).build();
Expand Down

0 comments on commit ba8b011

Please sign in to comment.