Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit562324a

Browse files
committed
Refactor image configuration classes
- Move archiveSizeBytes to ImageConfiguration- Add Type enum to ImageConfiguration and type field- Rename RawImageConfiguration to ComputeImageConfiguration- Update tests- Add getClass() equality check to ImageConfiguration.baseEquals
1 parent9a13683 commit562324a

File tree

9 files changed

+165
-103
lines changed

9 files changed

+165
-103
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public static <T extends ResourceId> DeprecationStatus<T> of(Status status, T re
344344
static <TextendsResourceId>DeprecationStatus<T>fromPb(
345345
com.google.api.services.compute.model.DeprecationStatusdeprecationStatusPb,
346346
Function<String,T>fromUrl) {
347-
Builder<T>builder =newBuilder<T>();
347+
Builder<T>builder =newBuilder<>();
348348
builder.deleted(deprecationStatusPb.getDeleted());
349349
builder.deprecated(deprecationStatusPb.getDeprecated());
350350
builder.obsolete(deprecationStatusPb.getObsolete());

‎gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskImageConfiguration.java‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ public static final class Builder
4343
privateDiskIdsourceDisk;
4444
privateStringsourceDiskId;
4545

46-
privateBuilder() {}
46+
privateBuilder() {
47+
super(Type.DISK);
48+
}
4749

4850
privateBuilder(DiskImageConfigurationimageConfiguration) {
49-
super(imageConfiguration);
51+
super(Type.DISK,imageConfiguration);
5052
this.sourceDisk =imageConfiguration.sourceDisk;
5153
this.sourceDiskId =imageConfiguration.sourceDiskId;
5254
}
5355

5456
privateBuilder(ImageimagePb) {
55-
super(imagePb);
57+
super(Type.DISK,imagePb);
5658
this.sourceDisk =DiskId.fromUrl(imagePb.getSourceDisk());
5759
this.sourceDiskId =imagePb.getSourceDiskId();
5860
}
@@ -124,8 +126,10 @@ public final boolean equals(Object obj) {
124126

125127
@Override
126128
DiskImageConfigurationsetProjectId(StringprojectId) {
127-
Builderbuilder =toBuilder().sourceDisk(sourceDisk.setProjectId(projectId));
128-
returnbuilder.build();
129+
if (sourceDisk.project() !=null) {
130+
returnthis;
131+
}
132+
returntoBuilder().sourceDisk(sourceDisk.setProjectId(projectId)).build();
129133
}
130134

131135
@Override

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

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,31 @@
2424

2525
/**
2626
* Base class for Google Compute Engine image configuration. Use {@link DiskImageConfiguration} to
27-
* create an image from an existing Google Compute Engine disk. Use {@link RawImageConfiguration} to
28-
* create an image from a file stored in Google Cloud Storage.
27+
* create an image from an existing Google Compute Engine disk. Use
28+
*{@link StorageImageConfiguration} tocreate an image from a file stored in Google Cloud Storage.
2929
*/
3030
publicabstractclassImageConfigurationimplementsSerializable {
3131

3232
privatestaticfinallongserialVersionUID = -9154332316597745316L;
3333

34+
privatefinalTypetype;
3435
privatefinalSourceTypesourceType;
36+
privatefinalLongarchiveSizeBytes;
37+
38+
/**
39+
* Type of a Google Compute Engine image.
40+
*/
41+
publicenumType {
42+
/**
43+
* A Google Compute Engine image created from a Google Compute Engine disk.
44+
*/
45+
DISK,
46+
47+
/**
48+
* A Google Compute Engine image created from a file saved in Google Cloud Storage.
49+
*/
50+
STORAGE
51+
}
3552

3653
/**
3754
* Image source type. The only admissible value is {@code RAW}.
@@ -48,38 +65,67 @@ public enum SourceType {
4865
*/
4966
publicabstractstaticclassBuilder<TextendsImageConfiguration,BextendsBuilder<T,B>> {
5067

68+
privateTypetype;
5169
privateSourceTypesourceType;
70+
privateLongarchiveSizeBytes;
5271

53-
Builder() {}
72+
Builder(Typetype) {
73+
this.type =type;
74+
}
5475

55-
Builder(ImageConfigurationimageConfiguration) {
76+
Builder(Typetype,ImageConfigurationimageConfiguration) {
77+
this.type =type;
5678
this.sourceType =imageConfiguration.sourceType;
79+
this.archiveSizeBytes =imageConfiguration.archiveSizeBytes;
5780
}
5881

59-
Builder(ImageimagePb) {
82+
Builder(Typetype,ImageimagePb) {
83+
this.type =type;
6084
if (imagePb.getSourceType() !=null) {
6185
this.sourceType =SourceType.valueOf(imagePb.getSourceType());
6286
}
87+
this.archiveSizeBytes =imagePb.getArchiveSizeBytes();
6388
}
6489

6590
@SuppressWarnings("unchecked")
6691
Bself() {
6792
return (B)this;
6893
}
6994

95+
Btype(Typetype) {
96+
this.type =type;
97+
returnself();
98+
}
99+
70100
BsourceType(SourceTypesourceType) {
71101
this.sourceType =sourceType;
72102
returnself();
73103
}
74104

105+
BarchiveSizeBytes(LongarchiveSizeBytes) {
106+
this.archiveSizeBytes =archiveSizeBytes;
107+
returnself();
108+
}
109+
75110
/**
76111
* Creates a configuration object.
77112
*/
78113
publicabstractTbuild();
79114
}
80115

81116
ImageConfiguration(Builderbuilder) {
117+
this.type =builder.type;
82118
this.sourceType =builder.sourceType;
119+
this.archiveSizeBytes =builder.archiveSizeBytes;
120+
}
121+
122+
/**
123+
* Returns the image's type. This method returns {@link Type#DISK} if this image was created from
124+
* an existing disk. This method returns {@link Type#STORAGE} if this image was created from a
125+
* file in Google Cloud Storage.
126+
*/
127+
publicTypetype() {
128+
returntype;
83129
}
84130

85131
/**
@@ -89,13 +135,23 @@ public SourceType sourceType() {
89135
returnsourceType;
90136
}
91137

138+
/**
139+
* Returns the size of the image archive stored in Google Cloud Storage (in bytes).
140+
*/
141+
publicLongarchiveSizeBytes() {
142+
returnarchiveSizeBytes;
143+
}
144+
92145
/**
93146
* Returns a builder for the object.
94147
*/
95148
publicabstractBuildertoBuilder();
96149

97150
MoreObjects.ToStringHelpertoStringHelper() {
98-
returnMoreObjects.toStringHelper(this).add("sourceType",sourceType);
151+
returnMoreObjects.toStringHelper(this)
152+
.add("type",type)
153+
.add("sourceType",sourceType)
154+
.add("archiveSizeBytes",archiveSizeBytes);
99155
}
100156

101157
@Override
@@ -104,11 +160,13 @@ public String toString() {
104160
}
105161

106162
finalintbaseHashCode() {
107-
returnObjects.hash(sourceType);
163+
returnObjects.hash(type,sourceType,archiveSizeBytes);
108164
}
109165

110166
finalbooleanbaseEquals(ImageConfigurationimageConfiguration) {
111-
returnObjects.equals(toPb(),imageConfiguration.toPb());
167+
returnimageConfiguration !=null
168+
&&getClass().equals(imageConfiguration.getClass())
169+
&&Objects.equals(toPb(),imageConfiguration.toPb());
112170
}
113171

114172
abstractImageConfigurationsetProjectId(StringprojectId);
@@ -118,6 +176,7 @@ Image toPb() {
118176
if (sourceType !=null) {
119177
imagePb.setSourceType(sourceType.name());
120178
}
179+
imagePb.setArchiveSizeBytes(archiveSizeBytes);
121180
returnimagePb;
122181
}
123182

@@ -126,6 +185,6 @@ static <T extends ImageConfiguration> T fromPb(Image imagePb) {
126185
if (imagePb.getSourceDisk() !=null) {
127186
return (T)DiskImageConfiguration.fromPb(imagePb);
128187
}
129-
return (T)RawImageConfiguration.fromPb(imagePb);
188+
return (T)StorageImageConfiguration.fromPb(imagePb);
130189
}
131190
}

‎gcloud-java-compute/src/main/java/com/google/gcloud/compute/ImageInfo.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* images of certain operating systems that you can use, or you can create a custom image. A custom
3939
* image is an image created from one of your virtual machine instances that contains your specific
4040
* instance configurations. Use {@link DiskImageConfiguration} to create an image from an existing
41-
* disk. Use {@linkRawImageConfiguration} to create an image from a raw image stored in Google
41+
* disk. Use {@linkStorageImageConfiguration} to create an image from a raw image stored in Google
4242
* Cloud Storage.
4343
*
4444
* @see <a href="https://cloud.google.com/compute/docs/images">Images</a>
@@ -115,8 +115,8 @@ public abstract static class Builder {
115115

116116
/**
117117
* Sets the image configuration. Use {@link DiskImageConfiguration} to create an image from an
118-
* existing disk. Use {@linkRawImageConfiguration} to create an image from a raw image stored
119-
* in Google Cloud Storage.
118+
* existing disk. Use {@linkStorageImageConfiguration} to create an image from a raw image
119+
*storedin Google Cloud Storage.
120120
*/
121121
publicabstractBuilderconfiguration(ImageConfigurationconfiguration);
122122

@@ -286,8 +286,8 @@ public String description() {
286286
/**
287287
* Returns the image configuration. This method returns an instance of
288288
* {@link DiskImageConfiguration} if the the image was created from a Google Compute Engine disk.
289-
* This method returns an instance of {@linkRawImageConfiguration} if the image was created from
290-
* a raw image stored in Google Cloud Storage.
289+
* This method returns an instance of {@linkStorageImageConfiguration} if the image was created
290+
*froma raw image stored in Google Cloud Storage.
291291
*/
292292
@SuppressWarnings("unchecked")
293293
public <TextendsImageConfiguration>Tconfiguration() {
@@ -393,7 +393,7 @@ Image toPb() {
393393
/**
394394
* Returns a builder for an {@code ImageInfo} object given the image identity and an image
395395
* configuration. Use {@link DiskImageConfiguration} to create an image from an existing disk. Use
396-
* {@linkRawImageConfiguration} to create an image from a raw image stored in Google Cloud
396+
* {@linkStorageImageConfiguration} to create an image from a raw image stored in Google Cloud
397397
* Storage.
398398
*/
399399
publicstaticBuilderbuilder(ImageIdimageId,ImageConfigurationconfiguration) {
@@ -403,7 +403,7 @@ public static Builder builder(ImageId imageId, ImageConfiguration configuration)
403403
/**
404404
* Returns an {@code ImageInfo} object given the image identity and an image configuration. Use
405405
* {@link DiskImageConfiguration} to create an image from an existing disk. Use
406-
* {@linkRawImageConfiguration} to create an image from a raw image stored in Google Cloud
406+
* {@linkStorageImageConfiguration} to create an image from a raw image stored in Google Cloud
407407
* Storage.
408408
*/
409409
publicstaticImageInfoof(ImageIdimageId,ImageConfigurationconfiguration) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp