Skip to content

Commit 4142a84

Browse files
authored
Rename setters/getters/builders for Compute classes to meet proto conventions (#1322)
* Rename setters/getters/builders for Compute classes to meet proto conventions * Update Compute examples, snippets and READMEs to use renamed getters/setters/builders
1 parent 82b2951 commit 4142a84

File tree

122 files changed

+8166
-3442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+8166
-3442
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ if (disk != null) {
222222
String snapshotName = "disk-name-snapshot";
223223
Operation operation = disk.createSnapshot(snapshotName);
224224
operation = operation.waitFor();
225-
if (operation.errors() == null) {
225+
if (operation.getErrors() == null) {
226226
// use snapshot
227227
Snapshot snapshot = compute.getSnapshot(snapshotName);
228228
}
@@ -252,7 +252,7 @@ MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1")
252252
Operation operation =
253253
compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface));
254254
operation = operation.waitFor();
255-
if (operation.errors() == null) {
255+
if (operation.getErrors() == null) {
256256
// use instance
257257
Instance instance = compute.getInstance(instanceId);
258258
}

google-cloud-compute/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ operation = operation.waitFor();
119119
if (operation.errors() == null) {
120120
System.out.println("Address " + addressId + " was successfully created");
121121
} else {
122-
// inspect operation.errors()
122+
// inspect operation.getErrors()
123123
throw new RuntimeException("Address creation failed");
124124
}
125125
```
@@ -150,7 +150,7 @@ DiskInfo disk = DiskInfo.of(diskId, diskConfiguration);
150150
Operation operation = compute.create(disk);
151151
// Wait for operation to complete
152152
operation = operation.waitFor();
153-
if (operation.errors() == null) {
153+
if (operation.getErrors() == null) {
154154
System.out.println("Disk " + diskId + " was successfully created");
155155
} else {
156156
// inspect operation.errors()
@@ -185,18 +185,18 @@ Address externalIp = compute.getAddress(addressId);
185185
InstanceId instanceId = InstanceId.of("us-central1-a", "test-instance");
186186
NetworkId networkId = NetworkId.of("default");
187187
PersistentDiskConfiguration attachConfiguration =
188-
PersistentDiskConfiguration.builder(diskId).boot(true).build();
188+
PersistentDiskConfiguration.newBuilder(diskId).setBoot(true).build();
189189
AttachedDisk attachedDisk = AttachedDisk.of("dev0", attachConfiguration);
190-
NetworkInterface networkInterface = NetworkInterface.builder(networkId)
191-
.accessConfigurations(AccessConfig.of(externalIp.address()))
190+
NetworkInterface networkInterface = NetworkInterface.newBuilder(networkId)
191+
.setAccessConfigurations(AccessConfig.of(externalIp.getAddress()))
192192
.build();
193193
MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1");
194194
InstanceInfo instance =
195195
InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface);
196196
Operation operation = compute.create(instance);
197197
// Wait for operation to complete
198198
operation = operation.waitFor();
199-
if (operation.errors() == null) {
199+
if (operation.getErrors() == null) {
200200
System.out.println("Instance " + instanceId + " was successfully created");
201201
} else {
202202
// inspect operation.errors()

google-cloud-compute/src/main/java/com/google/cloud/compute/Address.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static class Builder extends AddressInfo.Builder {
5656
Builder(Compute compute, AddressId addressId) {
5757
this.compute = compute;
5858
this.infoBuilder = new AddressInfo.BuilderImpl();
59-
this.infoBuilder.addressId(addressId);
59+
this.infoBuilder.setAddressId(addressId);
6060
}
6161

6262
Builder(Address address) {
@@ -65,44 +65,62 @@ public static class Builder extends AddressInfo.Builder {
6565
}
6666

6767
@Override
68+
@Deprecated
6869
public Builder address(String address) {
69-
infoBuilder.address(address);
70+
return setAddress(address);
71+
}
72+
73+
@Override
74+
public Builder setAddress(String address) {
75+
infoBuilder.setAddress(address);
7076
return this;
7177
}
7278

7379
@Override
74-
Builder creationTimestamp(Long creationTimestamp) {
75-
infoBuilder.creationTimestamp(creationTimestamp);
80+
Builder setCreationTimestamp(Long creationTimestamp) {
81+
infoBuilder.setCreationTimestamp(creationTimestamp);
7682
return this;
7783
}
7884

7985
@Override
86+
@Deprecated
8087
public Builder description(String description) {
81-
infoBuilder.description(description);
88+
return setDescription(description);
89+
}
90+
91+
@Override
92+
public Builder setDescription(String description) {
93+
infoBuilder.setDescription(description);
8294
return this;
8395
}
8496

8597
@Override
86-
Builder generatedId(String generatedId) {
87-
infoBuilder.generatedId(generatedId);
98+
Builder setGeneratedId(String generatedId) {
99+
infoBuilder.setGeneratedId(generatedId);
88100
return this;
89101
}
90102

91103
@Override
104+
@Deprecated
92105
public Builder addressId(AddressId addressId) {
93-
infoBuilder.addressId(addressId);
106+
return setAddressId(addressId);
107+
}
108+
109+
@Override
110+
public Builder setAddressId(AddressId addressId) {
111+
infoBuilder.setAddressId(addressId);
94112
return this;
95113
}
96114

97115
@Override
98-
Builder status(Status status) {
99-
infoBuilder.status(status);
116+
Builder setStatus(Status status) {
117+
infoBuilder.setStatus(status);
100118
return this;
101119
}
102120

103121
@Override
104-
Builder usage(Usage usage) {
105-
infoBuilder.usage(usage);
122+
Builder setUsage(Usage usage) {
123+
infoBuilder.setUsage(usage);
106124
return this;
107125
}
108126

@@ -137,7 +155,7 @@ public boolean exists() {
137155
* @throws ComputeException upon failure
138156
*/
139157
public Address reload(AddressOption... options) {
140-
return compute.getAddress(addressId(), options);
158+
return compute.getAddress(getAddressId(), options);
141159
}
142160

143161
/**
@@ -148,13 +166,21 @@ public Address reload(AddressOption... options) {
148166
* @throws ComputeException upon failure
149167
*/
150168
public Operation delete(OperationOption... options) {
151-
return compute.deleteAddress(addressId(), options);
169+
return compute.deleteAddress(getAddressId(), options);
152170
}
153171

154172
/**
155173
* Returns the address's {@code Compute} object used to issue requests.
156174
*/
175+
@Deprecated
157176
public Compute compute() {
177+
return getCompute();
178+
}
179+
180+
/**
181+
* Returns the address's {@code Compute} object used to issue requests.
182+
*/
183+
public Compute getCompute() {
158184
return compute;
159185
}
160186

google-cloud-compute/src/main/java/com/google/cloud/compute/AddressId.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ enum Type {
5454
/**
5555
* Returns the type of this address identity.
5656
*/
57+
@Deprecated
5758
public abstract Type type();
5859

60+
/**
61+
* Returns the type of this address identity.
62+
*/
63+
public abstract Type getType();
64+
5965
/**
6066
* Returns the name of the address resource. The name must be 1-63 characters long and comply with
6167
* RFC1035. Specifically, the name must match the regular expression
@@ -65,7 +71,21 @@ enum Type {
6571
*
6672
* @see <a href="https://www.ietf.org/rfc/rfc1035.txt">RFC1035</a>
6773
*/
74+
@Deprecated
6875
public String address() {
76+
return getAddress();
77+
}
78+
79+
/**
80+
* Returns the name of the address resource. The name must be 1-63 characters long and comply with
81+
* RFC1035. Specifically, the name must match the regular expression
82+
* {@code [a-z]([-a-z0-9]*[a-z0-9])?} which means the first character must be a lowercase letter,
83+
* and all following characters must be a dash, lowercase letter, or digit, except the last
84+
* character, which cannot be a dash.
85+
*
86+
* @see <a href="https://www.ietf.org/rfc/rfc1035.txt">RFC1035</a>
87+
*/
88+
public String getAddress() {
6989
return address;
7090
}
7191

0 commit comments

Comments
 (0)