Skip to content

Commit 22e51f4

Browse files
committed
Fix minor issues with ImageInfo, related classes and tests
1 parent 0149feb commit 22e51f4

File tree

7 files changed

+69
-27
lines changed

7 files changed

+69
-27
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* The deprecation status associated to a Google Compute Engine resource.
3232
*
33-
* @param <T> The Google Compute Engine resource identity to which the deprecation status refers to
33+
* @param <T> The Google Compute Engine resource identity to which the deprecation status refers
3434
*/
3535
public final class DeprecationStatus<T extends ResourceId> implements Serializable {
3636

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

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

8483
Builder() {}
8584

85+
Builder(DeprecationStatus<T> deprecationStatus) {
86+
this.deleted = deprecationStatus.deleted;
87+
this.deprecated = deprecationStatus.deprecated;
88+
this.obsolete = deprecationStatus.obsolete;
89+
this.replacement = deprecationStatus.replacement;
90+
this.status = deprecationStatus.status;
91+
}
92+
8693
/**
8794
* Sets the timestamp on or after which the deprecation state of this resource will be changed
8895
* to {@link Status#DELETED}. In milliseconds since epoch.
@@ -119,6 +126,9 @@ public Builder<T> replacement(T replacement) {
119126
return this;
120127
}
121128

129+
/**
130+
* Sets the status of the deprecated resource.
131+
*/
122132
public Builder<T> status(Status status) {
123133
this.status = checkNotNull(status);
124134
return this;
@@ -179,6 +189,13 @@ public Status status() {
179189
return status;
180190
}
181191

192+
/**
193+
* Returns a builder for the {@code DeprecationStatus} object.
194+
*/
195+
public Builder<T> toBuilder() {
196+
return new Builder<>(this);
197+
}
198+
182199
@Override
183200
public String toString() {
184201
return MoreObjects.toStringHelper(this)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ B sourceType(SourceType sourceType) {
8383
}
8484

8585
/**
86-
* Returns the source type of the disk. The default and only value is {@link SourceType#RAW}
86+
* Returns the source type of the disk. The default and only value is {@link SourceType#RAW}.
8787
*/
8888
public SourceType sourceType() {
8989
return sourceType;

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public class RawImageConfiguration extends ImageConfiguration {
3232
private static final long serialVersionUID = 8160447986545005880L;
3333

3434
private final ContainerType containerType;
35-
private final String sha1Checksum;
35+
private final String sha1;
3636
private final String source;
3737
private final Long archiveSizeBytes;
3838

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

5353
private ContainerType containerType;
54-
private String sha1Checksum;
54+
private String sha1;
5555
private String source;
5656
private Long archiveSizeBytes;
5757

@@ -60,22 +60,23 @@ private Builder() {}
6060
private Builder(RawImageConfiguration imageConfiguration) {
6161
super(imageConfiguration);
6262
this.containerType = imageConfiguration.containerType;
63-
this.sha1Checksum = imageConfiguration.sha1Checksum;
63+
this.sha1 = imageConfiguration.sha1;
6464
this.source = imageConfiguration.source;
65+
this.archiveSizeBytes = imageConfiguration.archiveSizeBytes;
6566
}
6667

6768
private Builder(Image imagePb) {
6869
super(imagePb);
6970
if (imagePb.getRawDisk().getContainerType() != null) {
7071
this.containerType = ContainerType.valueOf(imagePb.getRawDisk().getContainerType());
7172
}
72-
this.sha1Checksum = imagePb.getRawDisk().getSha1Checksum();
73+
this.sha1 = imagePb.getRawDisk().getSha1Checksum();
7374
this.source = imagePb.getRawDisk().getSource();
7475
this.archiveSizeBytes = imagePb.getArchiveSizeBytes();
7576
}
7677

7778
/**
78-
* Sets the format used to encode and transmit the block device. Supported value is only
79+
* Sets the format used to encode and transmit the block device. The only supported value is
7980
* {@code TAR}. This is just a container and transmission format, not a runtime format.
8081
*/
8182
public Builder containerType(ContainerType containerType) {
@@ -86,8 +87,8 @@ public Builder containerType(ContainerType containerType) {
8687
/**
8788
* Sets the SHA1 checksum of the disk image before unpackaging.
8889
*/
89-
public Builder sha1Checksum(String sha1Checksum) {
90-
this.sha1Checksum = sha1Checksum;
90+
public Builder sha1(String sha1) {
91+
this.sha1 = sha1;
9192
return this;
9293
}
9394

@@ -96,7 +97,7 @@ public Builder sha1Checksum(String sha1Checksum) {
9697
* {@code gs://bucket/file}).
9798
*/
9899
public Builder source(String source) {
99-
this.source = source;
100+
this.source = checkNotNull(source);
100101
return this;
101102
}
102103

@@ -118,7 +119,7 @@ private RawImageConfiguration(Builder builder) {
118119
super(builder);
119120
this.source = checkNotNull(builder.source);
120121
this.containerType = builder.containerType;
121-
this.sha1Checksum = builder.sha1Checksum;
122+
this.sha1 = builder.sha1;
122123
this.archiveSizeBytes = builder.archiveSizeBytes;
123124
}
124125

@@ -133,8 +134,8 @@ public ContainerType containerType() {
133134
/**
134135
* Returns the SHA1 checksum of the disk image before unpackaging.
135136
*/
136-
public String sha1Checksum() {
137-
return sha1Checksum;
137+
public String sha1() {
138+
return sha1;
138139
}
139140

140141
/**
@@ -162,13 +163,13 @@ MoreObjects.ToStringHelper toStringHelper() {
162163
return super.toStringHelper()
163164
.add("source", source)
164165
.add("containerType", containerType)
165-
.add("sha1Checksum", sha1Checksum)
166+
.add("sha1", sha1)
166167
.add("archiveSizeBytes", archiveSizeBytes);
167168
}
168169

169170
@Override
170171
public final int hashCode() {
171-
return Objects.hash(baseHashCode(), source, containerType, sha1Checksum, archiveSizeBytes);
172+
return Objects.hash(baseHashCode(), source, containerType, sha1, archiveSizeBytes);
172173
}
173174

174175
@Override
@@ -185,7 +186,7 @@ RawImageConfiguration setProjectId(String projectId) {
185186
Image toPb() {
186187
Image.RawDisk rawDiskPb = new Image.RawDisk();
187188
rawDiskPb.setSource(source);
188-
rawDiskPb.setSha1Checksum(sha1Checksum);
189+
rawDiskPb.setSha1Checksum(sha1);
189190
if (containerType != null) {
190191
rawDiskPb.setContainerType(containerType.name());
191192
}

gcloud-java-compute/src/test/java/com/google/gcloud/compute/DiskImageConfigurationTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ public class DiskImageConfigurationTest {
2929
private static final DiskId SOURCE_DISK = DiskId.of("project", "zone", "disk");
3030
private static final String SOURCE_DISK_ID = "diskId";
3131
private static final SourceType SOURCE_TYPE = SourceType.RAW;
32-
private static DiskImageConfiguration CONFIGURATION = DiskImageConfiguration.builder(SOURCE_DISK)
33-
.sourceDiskId(SOURCE_DISK_ID)
34-
.sourceType(SOURCE_TYPE)
35-
.build();
32+
private static final DiskImageConfiguration CONFIGURATION =
33+
DiskImageConfiguration.builder(SOURCE_DISK)
34+
.sourceDiskId(SOURCE_DISK_ID)
35+
.sourceType(SOURCE_TYPE)
36+
.build();
3637

3738
@Test
3839
public void testToBuilder() {
3940
compareDiskImageConfiguration(CONFIGURATION, CONFIGURATION.toBuilder().build());
40-
DiskId newDisk = DiskId.of("newProjet", "newZone", "newDisk");
41+
DiskId newDisk = DiskId.of("newProject", "newZone", "newDisk");
4142
String newDiskId = "newDiskId";
4243
DiskImageConfiguration configuration = CONFIGURATION.toBuilder()
4344
.sourceDisk(newDisk)

gcloud-java-compute/src/test/java/com/google/gcloud/compute/ImageInfoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ImageInfoTest {
4646
RawImageConfiguration.builder(RAW_SOURCE)
4747
.archiveSizeBytes(ARCHIVE_SIZE_BYTES)
4848
.containerType(RawImageConfiguration.ContainerType.TAR)
49-
.sha1Checksum(SHA1_CHECKSUM)
49+
.sha1(SHA1_CHECKSUM)
5050
.sourceType(SOURCE_TYPE)
5151
.build();
5252
private static final DiskImageConfiguration DISK_CONFIGURATION =

gcloud-java-compute/src/test/java/com/google/gcloud/compute/RawImageConfigurationTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@
2222
import static org.junit.Assert.assertTrue;
2323

2424
import com.google.gcloud.compute.ImageConfiguration.SourceType;
25+
import com.google.gcloud.compute.RawImageConfiguration.ContainerType;
2526

2627
import org.junit.Test;
2728

2829
public class RawImageConfigurationTest {
2930

3031
private static final String SOURCE = "source";
3132
private static final SourceType SOURCE_TYPE = SourceType.RAW;
32-
private static RawImageConfiguration CONFIGURATION = RawImageConfiguration.builder(SOURCE)
33+
private static final ContainerType CONTAINER_TYPE = ContainerType.TAR;
34+
private static final Long ARCHIVE_SIZE_BYTES = 42L;
35+
private static final String SHA1 = "sha1";
36+
private static final RawImageConfiguration CONFIGURATION = RawImageConfiguration.builder(SOURCE)
3337
.sourceType(SOURCE_TYPE)
38+
.containerType(CONTAINER_TYPE)
39+
.archiveSizeBytes(ARCHIVE_SIZE_BYTES)
40+
.sha1(SHA1)
3441
.build();
3542

3643
@Test
@@ -53,6 +60,9 @@ public void testToBuilderIncomplete() {
5360
public void testBuilder() {
5461
assertEquals(SOURCE_TYPE, CONFIGURATION.sourceType());
5562
assertEquals(SOURCE, CONFIGURATION.source());
63+
assertEquals(CONTAINER_TYPE, CONFIGURATION.containerType());
64+
assertEquals(ARCHIVE_SIZE_BYTES, CONFIGURATION.archiveSizeBytes());
65+
assertEquals(SHA1, CONFIGURATION.sha1());
5666
}
5767

5868
@Test
@@ -69,6 +79,9 @@ public void testOf() {
6979
RawImageConfiguration configuration = RawImageConfiguration.of(SOURCE);
7080
assertNull(configuration.sourceType());
7181
assertEquals(SOURCE, configuration.source());
82+
assertNull(configuration.containerType());
83+
assertNull(configuration.archiveSizeBytes());
84+
assertNull(configuration.sha1());
7285
}
7386

7487
@Test
@@ -81,6 +94,9 @@ private void compareRawImageConfiguration(RawImageConfiguration expected,
8194
assertEquals(expected, value);
8295
assertEquals(expected.source(), value.source());
8396
assertEquals(expected.sourceType(), value.sourceType());
97+
assertEquals(expected.containerType(), value.containerType());
98+
assertEquals(expected.archiveSizeBytes(), value.archiveSizeBytes());
99+
assertEquals(expected.sha1(), value.sha1());
84100
assertEquals(expected.hashCode(), value.hashCode());
85101
}
86102
}

gcloud-java-compute/src/test/java/com/google/gcloud/compute/SerializationTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ public class SerializationTest {
148148
private static final SnapshotInfo SNAPSHOT_INFO = SnapshotInfo.of(SNAPSHOT_ID, DISK_ID);
149149
private static final Snapshot SNAPSHOT =
150150
new Snapshot.Builder(COMPUTE, SNAPSHOT_ID, DISK_ID).build();
151+
private static final ImageId IMAGE_ID = ImageId.of("project", "image");
152+
private static final DiskImageConfiguration DISK_IMAGE_CONFIGURATION =
153+
DiskImageConfiguration.of(DISK_ID);
154+
private static final RawImageConfiguration RAW_IMAGE_CONFIGURATION =
155+
RawImageConfiguration.of("gs:/bucket/file");
156+
private static final ImageInfo IMAGE_INFO = ImageInfo.of(IMAGE_ID, DISK_IMAGE_CONFIGURATION);
151157
private static final Compute.DiskTypeOption DISK_TYPE_OPTION =
152158
Compute.DiskTypeOption.fields();
153159
private static final Compute.DiskTypeFilter DISK_TYPE_FILTER =
@@ -218,7 +224,8 @@ public void testModelAndRequests() throws Exception {
218224
REGION_OPERATION_ID, ZONE_OPERATION_ID, GLOBAL_OPERATION, REGION_OPERATION, ZONE_OPERATION,
219225
INSTANCE_ID, REGION_FORWARDING_RULE_ID, GLOBAL_FORWARDING_RULE_ID, GLOBAL_ADDRESS_ID,
220226
REGION_ADDRESS_ID, INSTANCE_USAGE, GLOBAL_FORWARDING_USAGE, REGION_FORWARDING_USAGE,
221-
ADDRESS_INFO, ADDRESS, DISK_ID, SNAPSHOT_ID, SNAPSHOT_INFO, SNAPSHOT, DISK_TYPE_OPTION,
227+
ADDRESS_INFO, ADDRESS, DISK_ID, SNAPSHOT_ID, SNAPSHOT_INFO, SNAPSHOT, IMAGE_ID,
228+
DISK_IMAGE_CONFIGURATION, RAW_IMAGE_CONFIGURATION, IMAGE_INFO, DISK_TYPE_OPTION,
222229
DISK_TYPE_FILTER, DISK_TYPE_LIST_OPTION, DISK_TYPE_AGGREGATED_LIST_OPTION,
223230
MACHINE_TYPE_OPTION, MACHINE_TYPE_FILTER, MACHINE_TYPE_LIST_OPTION,
224231
MACHINE_TYPE_AGGREGATED_LIST_OPTION, REGION_OPTION, REGION_FILTER, REGION_LIST_OPTION,

0 commit comments

Comments
 (0)