Skip to content

Commit 6026993

Browse files
committed
---
yaml --- r: 2775 b: refs/heads/compute-alpha c: d3deaf9 h: refs/heads/master i: 2773: f5d3751 2771: 6585811 2767: e4244f6
1 parent 19a2f57 commit 6026993

25 files changed

Lines changed: 2948 additions & 1 deletion

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
1010
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2
1212
refs/tags/v0.0.12: 2fd8066e891fb3dfea69b65f6bf6461db79342b9
13-
refs/heads/compute-alpha: ba5467f0da8bd3743dfd5f1222d3fb56cab46e89
13+
refs/heads/compute-alpha: d3deaf90ef22161f1803592501988c1388642a3a
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.compute;
18+
19+
import com.google.common.base.Function;
20+
import com.google.common.base.MoreObjects;
21+
22+
import java.io.Serializable;
23+
import java.math.BigInteger;
24+
import java.util.Objects;
25+
26+
/**
27+
* Google Compute Engine Disk type. A disk type represents the type of disk to use, such as a
28+
* {@code pd-ssd} or {@code pd-standard}.
29+
*/
30+
public final class DiskType implements Serializable {
31+
32+
static final Function<com.google.api.services.compute.model.DiskType, DiskType> FROM_PB_FUNCTION =
33+
new Function<com.google.api.services.compute.model.DiskType, DiskType>() {
34+
@Override
35+
public DiskType apply(com.google.api.services.compute.model.DiskType pb) {
36+
return DiskType.fromPb(pb);
37+
}
38+
};
39+
static final Function<DiskType, com.google.api.services.compute.model.DiskType> TO_PB_FUNCTION =
40+
new Function<DiskType, com.google.api.services.compute.model.DiskType>() {
41+
@Override
42+
public com.google.api.services.compute.model.DiskType apply(DiskType diskType) {
43+
return diskType.toPb();
44+
}
45+
};
46+
47+
private static final long serialVersionUID = -944042261695072026L;
48+
49+
private final Long id;
50+
private final DiskTypeId diskTypeId;
51+
private final String creationTimestamp;
52+
private final String description;
53+
private final String validDiskSize;
54+
private final String selfLink;
55+
private final Long defaultDiskSizeGb;
56+
57+
static final class Builder {
58+
59+
private Long id;
60+
private DiskTypeId diskTypeId;
61+
private String creationTimestamp;
62+
private String description;
63+
private String validDiskSize;
64+
private String selfLink;
65+
private Long defaultDiskSizeGb;
66+
67+
private Builder() {}
68+
69+
Builder id(Long id) {
70+
this.id = id;
71+
return this;
72+
}
73+
74+
Builder creationTimestamp(String creationTimestamp) {
75+
this.creationTimestamp = creationTimestamp;
76+
return this;
77+
}
78+
79+
Builder diskTypeId(DiskTypeId diskTypeId) {
80+
this.diskTypeId = diskTypeId;
81+
return this;
82+
}
83+
84+
Builder description(String description) {
85+
this.description = description;
86+
return this;
87+
}
88+
89+
Builder validDiskSize(String validDiskSize) {
90+
this.validDiskSize = validDiskSize;
91+
return this;
92+
}
93+
94+
Builder selfLink(String selfLink) {
95+
this.selfLink = selfLink;
96+
return this;
97+
}
98+
99+
Builder defaultDiskSizeGb(Long defaultDiskSizeGb) {
100+
this.defaultDiskSizeGb = defaultDiskSizeGb;
101+
return this;
102+
}
103+
104+
/**
105+
* Creates a {@code DiskType} object.
106+
*/
107+
DiskType build() {
108+
return new DiskType(this);
109+
}
110+
}
111+
112+
private DiskType(Builder builder) {
113+
this.id = builder.id;
114+
this.creationTimestamp = builder.creationTimestamp;
115+
this.diskTypeId = builder.diskTypeId;
116+
this.description = builder.description;
117+
this.validDiskSize = builder.validDiskSize;
118+
this.selfLink = builder.selfLink;
119+
this.defaultDiskSizeGb = builder.defaultDiskSizeGb;
120+
}
121+
122+
/**
123+
* Returns the creation timestamp in RFC3339 text format.
124+
*
125+
* @see <a href="https://www.ietf.org/rfc/rfc3339.txt">RFC3339</a>
126+
*/
127+
public String creationTimestamp() {
128+
return creationTimestamp;
129+
}
130+
131+
/**
132+
* Returns the disk type's identity.
133+
*/
134+
public DiskTypeId diskTypeId() {
135+
return diskTypeId;
136+
}
137+
138+
/**
139+
* Returns an unique identifier for the disk type; defined by the service.
140+
*/
141+
public Long id() {
142+
return id;
143+
}
144+
145+
/**
146+
* Returns a textual description of the disk type.
147+
*/
148+
public String description() {
149+
return description;
150+
}
151+
152+
/**
153+
* Returns an optional textual description of the valid disk size, such as "10GB-10TB".
154+
*/
155+
public String validDiskSize() {
156+
return validDiskSize;
157+
}
158+
159+
/**
160+
* Returns a service-defined URL for the disk type.
161+
*/
162+
public String selfLink() {
163+
return selfLink;
164+
}
165+
166+
/**
167+
* Returns the service-defined default disk size in GB.
168+
*/
169+
public Long defaultDiskSizeGb() {
170+
return defaultDiskSizeGb;
171+
}
172+
173+
@Override
174+
public String toString() {
175+
return MoreObjects.toStringHelper(this)
176+
.add("id", id)
177+
.add("creationTimestamp", creationTimestamp)
178+
.add("description", description)
179+
.add("validDiskSize", validDiskSize)
180+
.add("selfLink", selfLink)
181+
.add("defaultDiskSizeGb", defaultDiskSizeGb)
182+
.toString();
183+
}
184+
185+
@Override
186+
public int hashCode() {
187+
return Objects.hash(id);
188+
}
189+
190+
@Override
191+
public boolean equals(Object obj) {
192+
return obj instanceof DiskType && Objects.equals(toPb(), ((DiskType) obj).toPb());
193+
}
194+
195+
com.google.api.services.compute.model.DiskType toPb() {
196+
com.google.api.services.compute.model.DiskType diskTypePb =
197+
new com.google.api.services.compute.model.DiskType();
198+
if (id != null) {
199+
diskTypePb.setId(BigInteger.valueOf(id));
200+
}
201+
diskTypePb.setCreationTimestamp(creationTimestamp);
202+
diskTypePb.setDescription(description);
203+
diskTypePb.setValidDiskSize(validDiskSize);
204+
diskTypePb.setSelfLink(selfLink);
205+
diskTypePb.setDefaultDiskSizeGb(defaultDiskSizeGb);
206+
diskTypePb.setZone(diskTypeId.zoneId().toUrl());
207+
return diskTypePb;
208+
}
209+
210+
static Builder builder() {
211+
return new Builder();
212+
}
213+
214+
static DiskType fromPb(com.google.api.services.compute.model.DiskType diskTypePb) {
215+
Builder builder = builder();
216+
if (diskTypePb.getId() != null ) {
217+
builder.id(diskTypePb.getId().longValue());
218+
}
219+
builder.creationTimestamp(diskTypePb.getCreationTimestamp());
220+
builder.diskTypeId(DiskTypeId.fromUrl(diskTypePb.getSelfLink()));
221+
builder.description(diskTypePb.getDescription());
222+
builder.validDiskSize(diskTypePb.getValidDiskSize());
223+
builder.selfLink(diskTypePb.getSelfLink());
224+
builder.defaultDiskSizeGb(diskTypePb.getDefaultDiskSizeGb());
225+
return builder.build();
226+
}
227+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.compute;
18+
19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
21+
import com.google.common.base.MoreObjects;
22+
23+
import java.util.Objects;
24+
25+
/**
26+
* Identity for a Google Compute Engine disk type.
27+
*/
28+
public final class DiskTypeId extends ZoneResourceId {
29+
30+
private static final long serialVersionUID = 7337881474103686219L;
31+
32+
private final String diskType;
33+
34+
DiskTypeId(String project, String zone, String diskType) {
35+
super(project, zone);
36+
this.diskType = checkNotNull(diskType);
37+
}
38+
39+
/**
40+
* Returns the name of the disk type resource. The name must be 1-63 characters long, and comply
41+
* with RFC1035. Specifically, the name must be 1-63 characters long and match the regular
42+
* expression {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a
43+
* lowercase letter, and all following characters must be a dash, lowercase letter, or digit,
44+
* except the last character, which cannot be a dash.
45+
*
46+
* @see <a href="https://www.ietf.org/rfc/rfc1035.txt">RFC1035</a>
47+
*/
48+
public String diskType() {
49+
return diskType;
50+
}
51+
52+
@Override
53+
public String toUrl() {
54+
return super.toUrl() + "/diskTypes/" + diskType;
55+
}
56+
57+
@Override
58+
MoreObjects.ToStringHelper toStringHelper() {
59+
return super.toStringHelper().add("diskType", diskType);
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return Objects.hash(super.hashCode(), diskType);
65+
}
66+
67+
@Override
68+
public boolean equals(Object obj) {
69+
return obj instanceof DiskTypeId && baseEquals((DiskTypeId) obj);
70+
}
71+
72+
@Override
73+
DiskTypeId setProjectId(String projectId) {
74+
if (project() != null) {
75+
return this;
76+
}
77+
return DiskTypeId.of(projectId, zone(), diskType);
78+
}
79+
80+
/**
81+
* Returns a disk type identity given the zone identity and the disk type name.
82+
*/
83+
public static DiskTypeId of(ZoneId zoneId, String diskType) {
84+
return new DiskTypeId(zoneId.project(), zoneId.zone(), diskType);
85+
}
86+
87+
/**
88+
* Returns a disk type identity given the zone disk and disk type.
89+
*/
90+
public static DiskTypeId of(String zone, String diskType) {
91+
return of(ZoneId.of(null, zone), diskType);
92+
}
93+
94+
/**
95+
* Returns a disk type identity given project disk, zone disk and disk type.
96+
*/
97+
public static DiskTypeId of(String project, String zone, String diskType) {
98+
return of(ZoneId.of(project, zone), diskType);
99+
}
100+
101+
static DiskTypeId fromUrl(String url) {
102+
int projectsIndex = url.indexOf("/projects/");
103+
int zonesIndex = url.indexOf("/zones/");
104+
int diskTypesIndex = url.indexOf("/diskTypes/");
105+
String project = url.substring(projectsIndex + 10, zonesIndex);
106+
String zone = url.substring(zonesIndex + 7, diskTypesIndex);
107+
String diskType = url.substring(diskTypesIndex + 11, url.length());
108+
return DiskTypeId.of(project, zone, diskType);
109+
}
110+
}

0 commit comments

Comments
 (0)