Skip to content

Commit

Permalink
Fix minor issues with ImageInfo, related classes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Mar 29, 2016
1 parent 0149feb commit 22e51f4
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* The deprecation status associated to a Google Compute Engine resource.
*
* @param <T> The Google Compute Engine resource identity to which the deprecation status refers to
* @param <T> The Google Compute Engine resource identity to which the deprecation status refers
*/
public final class DeprecationStatus<T extends ResourceId> implements Serializable {

Expand Down Expand Up @@ -71,7 +71,6 @@ public enum Status {
* A builder for {@code DeprecationStatus} objects.
*
* @param <T> The Google Compute Engine resource identity to which the deprecation status refers
* to
*/
public static final class Builder<T extends ResourceId> {

Expand All @@ -83,6 +82,14 @@ public static final class Builder<T extends ResourceId> {

Builder() {}

Builder(DeprecationStatus<T> deprecationStatus) {
this.deleted = deprecationStatus.deleted;
this.deprecated = deprecationStatus.deprecated;
this.obsolete = deprecationStatus.obsolete;
this.replacement = deprecationStatus.replacement;
this.status = deprecationStatus.status;
}

/**
* Sets the timestamp on or after which the deprecation state of this resource will be changed
* to {@link Status#DELETED}. In milliseconds since epoch.
Expand Down Expand Up @@ -119,6 +126,9 @@ public Builder<T> replacement(T replacement) {
return this;
}

/**
* Sets the status of the deprecated resource.
*/
public Builder<T> status(Status status) {
this.status = checkNotNull(status);
return this;
Expand Down Expand Up @@ -179,6 +189,13 @@ public Status status() {
return status;
}

/**
* Returns a builder for the {@code DeprecationStatus} object.
*/
public Builder<T> toBuilder() {
return new Builder<>(this);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ B sourceType(SourceType sourceType) {
}

/**
* Returns the source type of the disk. The default and only value is {@link SourceType#RAW}
* Returns the source type of the disk. The default and only value is {@link SourceType#RAW}.
*/
public SourceType sourceType() {
return sourceType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public class RawImageConfiguration extends ImageConfiguration {
private static final long serialVersionUID = 8160447986545005880L;

private final ContainerType containerType;
private final String sha1Checksum;
private final String sha1;
private final String source;
private final Long archiveSizeBytes;

/**
* The format used to encode and transmit the block device. Supported value is only {@code TAR}.
* This is just a container and transmission format, not a runtime format.
* The format used to encode and transmit the block device. The only supported value is
* {@code TAR}. This is just a container and transmission format, not a runtime format.
*/
public enum ContainerType {
TAR
Expand All @@ -51,7 +51,7 @@ public static final class Builder
extends ImageConfiguration.Builder<RawImageConfiguration, Builder> {

private ContainerType containerType;
private String sha1Checksum;
private String sha1;
private String source;
private Long archiveSizeBytes;

Expand All @@ -60,22 +60,23 @@ private Builder() {}
private Builder(RawImageConfiguration imageConfiguration) {
super(imageConfiguration);
this.containerType = imageConfiguration.containerType;
this.sha1Checksum = imageConfiguration.sha1Checksum;
this.sha1 = imageConfiguration.sha1;
this.source = imageConfiguration.source;
this.archiveSizeBytes = imageConfiguration.archiveSizeBytes;
}

private Builder(Image imagePb) {
super(imagePb);
if (imagePb.getRawDisk().getContainerType() != null) {
this.containerType = ContainerType.valueOf(imagePb.getRawDisk().getContainerType());
}
this.sha1Checksum = imagePb.getRawDisk().getSha1Checksum();
this.sha1 = imagePb.getRawDisk().getSha1Checksum();
this.source = imagePb.getRawDisk().getSource();
this.archiveSizeBytes = imagePb.getArchiveSizeBytes();
}

/**
* Sets the format used to encode and transmit the block device. Supported value is only
* Sets the format used to encode and transmit the block device. The only supported value is
* {@code TAR}. This is just a container and transmission format, not a runtime format.
*/
public Builder containerType(ContainerType containerType) {
Expand All @@ -86,8 +87,8 @@ public Builder containerType(ContainerType containerType) {
/**
* Sets the SHA1 checksum of the disk image before unpackaging.
*/
public Builder sha1Checksum(String sha1Checksum) {
this.sha1Checksum = sha1Checksum;
public Builder sha1(String sha1) {
this.sha1 = sha1;
return this;
}

Expand All @@ -96,7 +97,7 @@ public Builder sha1Checksum(String sha1Checksum) {
* {@code gs://bucket/file}).
*/
public Builder source(String source) {
this.source = source;
this.source = checkNotNull(source);
return this;
}

Expand All @@ -118,7 +119,7 @@ private RawImageConfiguration(Builder builder) {
super(builder);
this.source = checkNotNull(builder.source);
this.containerType = builder.containerType;
this.sha1Checksum = builder.sha1Checksum;
this.sha1 = builder.sha1;
this.archiveSizeBytes = builder.archiveSizeBytes;
}

Expand All @@ -133,8 +134,8 @@ public ContainerType containerType() {
/**
* Returns the SHA1 checksum of the disk image before unpackaging.
*/
public String sha1Checksum() {
return sha1Checksum;
public String sha1() {
return sha1;
}

/**
Expand Down Expand Up @@ -162,13 +163,13 @@ MoreObjects.ToStringHelper toStringHelper() {
return super.toStringHelper()
.add("source", source)
.add("containerType", containerType)
.add("sha1Checksum", sha1Checksum)
.add("sha1", sha1)
.add("archiveSizeBytes", archiveSizeBytes);
}

@Override
public final int hashCode() {
return Objects.hash(baseHashCode(), source, containerType, sha1Checksum, archiveSizeBytes);
return Objects.hash(baseHashCode(), source, containerType, sha1, archiveSizeBytes);
}

@Override
Expand All @@ -185,7 +186,7 @@ RawImageConfiguration setProjectId(String projectId) {
Image toPb() {
Image.RawDisk rawDiskPb = new Image.RawDisk();
rawDiskPb.setSource(source);
rawDiskPb.setSha1Checksum(sha1Checksum);
rawDiskPb.setSha1Checksum(sha1);
if (containerType != null) {
rawDiskPb.setContainerType(containerType.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ public class DiskImageConfigurationTest {
private static final DiskId SOURCE_DISK = DiskId.of("project", "zone", "disk");
private static final String SOURCE_DISK_ID = "diskId";
private static final SourceType SOURCE_TYPE = SourceType.RAW;
private static DiskImageConfiguration CONFIGURATION = DiskImageConfiguration.builder(SOURCE_DISK)
.sourceDiskId(SOURCE_DISK_ID)
.sourceType(SOURCE_TYPE)
.build();
private static final DiskImageConfiguration CONFIGURATION =
DiskImageConfiguration.builder(SOURCE_DISK)
.sourceDiskId(SOURCE_DISK_ID)
.sourceType(SOURCE_TYPE)
.build();

@Test
public void testToBuilder() {
compareDiskImageConfiguration(CONFIGURATION, CONFIGURATION.toBuilder().build());
DiskId newDisk = DiskId.of("newProjet", "newZone", "newDisk");
DiskId newDisk = DiskId.of("newProject", "newZone", "newDisk");
String newDiskId = "newDiskId";
DiskImageConfiguration configuration = CONFIGURATION.toBuilder()
.sourceDisk(newDisk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ImageInfoTest {
RawImageConfiguration.builder(RAW_SOURCE)
.archiveSizeBytes(ARCHIVE_SIZE_BYTES)
.containerType(RawImageConfiguration.ContainerType.TAR)
.sha1Checksum(SHA1_CHECKSUM)
.sha1(SHA1_CHECKSUM)
.sourceType(SOURCE_TYPE)
.build();
private static final DiskImageConfiguration DISK_CONFIGURATION =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@
import static org.junit.Assert.assertTrue;

import com.google.gcloud.compute.ImageConfiguration.SourceType;
import com.google.gcloud.compute.RawImageConfiguration.ContainerType;

import org.junit.Test;

public class RawImageConfigurationTest {

private static final String SOURCE = "source";
private static final SourceType SOURCE_TYPE = SourceType.RAW;
private static RawImageConfiguration CONFIGURATION = RawImageConfiguration.builder(SOURCE)
private static final ContainerType CONTAINER_TYPE = ContainerType.TAR;
private static final Long ARCHIVE_SIZE_BYTES = 42L;
private static final String SHA1 = "sha1";
private static final RawImageConfiguration CONFIGURATION = RawImageConfiguration.builder(SOURCE)
.sourceType(SOURCE_TYPE)
.containerType(CONTAINER_TYPE)
.archiveSizeBytes(ARCHIVE_SIZE_BYTES)
.sha1(SHA1)
.build();

@Test
Expand All @@ -53,6 +60,9 @@ public void testToBuilderIncomplete() {
public void testBuilder() {
assertEquals(SOURCE_TYPE, CONFIGURATION.sourceType());
assertEquals(SOURCE, CONFIGURATION.source());
assertEquals(CONTAINER_TYPE, CONFIGURATION.containerType());
assertEquals(ARCHIVE_SIZE_BYTES, CONFIGURATION.archiveSizeBytes());
assertEquals(SHA1, CONFIGURATION.sha1());
}

@Test
Expand All @@ -69,6 +79,9 @@ public void testOf() {
RawImageConfiguration configuration = RawImageConfiguration.of(SOURCE);
assertNull(configuration.sourceType());
assertEquals(SOURCE, configuration.source());
assertNull(configuration.containerType());
assertNull(configuration.archiveSizeBytes());
assertNull(configuration.sha1());
}

@Test
Expand All @@ -81,6 +94,9 @@ private void compareRawImageConfiguration(RawImageConfiguration expected,
assertEquals(expected, value);
assertEquals(expected.source(), value.source());
assertEquals(expected.sourceType(), value.sourceType());
assertEquals(expected.containerType(), value.containerType());
assertEquals(expected.archiveSizeBytes(), value.archiveSizeBytes());
assertEquals(expected.sha1(), value.sha1());
assertEquals(expected.hashCode(), value.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ public class SerializationTest {
private static final SnapshotInfo SNAPSHOT_INFO = SnapshotInfo.of(SNAPSHOT_ID, DISK_ID);
private static final Snapshot SNAPSHOT =
new Snapshot.Builder(COMPUTE, SNAPSHOT_ID, DISK_ID).build();
private static final ImageId IMAGE_ID = ImageId.of("project", "image");
private static final DiskImageConfiguration DISK_IMAGE_CONFIGURATION =
DiskImageConfiguration.of(DISK_ID);
private static final RawImageConfiguration RAW_IMAGE_CONFIGURATION =
RawImageConfiguration.of("gs:/bucket/file");
private static final ImageInfo IMAGE_INFO = ImageInfo.of(IMAGE_ID, DISK_IMAGE_CONFIGURATION);
private static final Compute.DiskTypeOption DISK_TYPE_OPTION =
Compute.DiskTypeOption.fields();
private static final Compute.DiskTypeFilter DISK_TYPE_FILTER =
Expand Down Expand Up @@ -218,7 +224,8 @@ public void testModelAndRequests() throws Exception {
REGION_OPERATION_ID, ZONE_OPERATION_ID, GLOBAL_OPERATION, REGION_OPERATION, ZONE_OPERATION,
INSTANCE_ID, REGION_FORWARDING_RULE_ID, GLOBAL_FORWARDING_RULE_ID, GLOBAL_ADDRESS_ID,
REGION_ADDRESS_ID, INSTANCE_USAGE, GLOBAL_FORWARDING_USAGE, REGION_FORWARDING_USAGE,
ADDRESS_INFO, ADDRESS, DISK_ID, SNAPSHOT_ID, SNAPSHOT_INFO, SNAPSHOT, DISK_TYPE_OPTION,
ADDRESS_INFO, ADDRESS, DISK_ID, SNAPSHOT_ID, SNAPSHOT_INFO, SNAPSHOT, IMAGE_ID,
DISK_IMAGE_CONFIGURATION, RAW_IMAGE_CONFIGURATION, IMAGE_INFO, DISK_TYPE_OPTION,
DISK_TYPE_FILTER, DISK_TYPE_LIST_OPTION, DISK_TYPE_AGGREGATED_LIST_OPTION,
MACHINE_TYPE_OPTION, MACHINE_TYPE_FILTER, MACHINE_TYPE_LIST_OPTION,
MACHINE_TYPE_AGGREGATED_LIST_OPTION, REGION_OPTION, REGION_FILTER, REGION_LIST_OPTION,
Expand Down

0 comments on commit 22e51f4

Please sign in to comment.