Skip to content

Commit 8ad3e89

Browse files
committed
Fixed the snipped and README. Removed possible NPE.
Added @throws docs.
1 parent 3becc74 commit 8ad3e89

4 files changed

Lines changed: 18 additions & 29 deletions

File tree

gcloud-java-dns/README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,17 @@ while (recordIterator.hasNext()) {
300300
// Build and apply the change request to our zone if it contains records to delete
301301
ChangeRequestInfo changeRequest = changeBuilder.build();
302302
if (!changeRequest.deletions().isEmpty()) {
303-
changeRequest = dns.applyChangeRequest(zoneName, changeRequest);
303+
ChangeRequest pendingRequest = dns.applyChangeRequest(zoneName, changeRequest);
304304

305-
// Wait for change to finish, but save data traffic by transferring only ID and status
306-
Dns.ChangeRequestOption option =
307-
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS);
308-
while (ChangeRequestInfo.Status.PENDING.equals(changeRequest.status())) {
305+
// Wait for the change request to complete
306+
while (!pendingRequest.isDone()) {
309307
System.out.println("Waiting for change to complete. Going to sleep for 500ms...");
310308
try {
311309
Thread.sleep(500);
312310
} catch (InterruptedException e) {
313311
System.err.println("The thread was interrupted while waiting for change request to be "
314312
+ "processed.");
315313
}
316-
317-
// Update the change, but fetch only change ID and status
318-
changeRequest = dns.getChangeRequest(zoneName, changeRequest.generatedId(), option);
319314
}
320315
}
321316

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ChangeRequest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,27 @@ public ChangeRequest applyTo(String zoneName, Dns.ChangeRequestOption... options
162162
* {@code options} will be {@code null} regardless of whether they are initialized or not in
163163
* {@code this} instance.
164164
*
165-
* @return an object containing the updated information
165+
* @return an object with the updated information or {@code null} if it does not exist
166+
* @throws DnsException upon failure of the API call or if the associated zone was not found
166167
*/
167168
public ChangeRequest reload(Dns.ChangeRequestOption... options) {
168169
return dns.getChangeRequest(zone, generatedId(), options);
169170
}
170171

171172
/**
172173
* Returns {@code true} if the change request has been completed. The function makes an API call
173-
* to Google Cloud DNS in order request the status update only if the status of the change request
174-
* is {@link Status#PENDING}. If the status is already {@link Status#DONE}, the method returns
175-
* {@code true} without an API call.
174+
* to Google Cloud DNS in order to request the status update only if the status of the change
175+
* request is {@link Status#PENDING}. If the status is already {@link Status#DONE}, the method
176+
* returns {@code true} without an API call.
177+
*
178+
* @throws DnsException upon failure of the API call or if the associated zone was not found
176179
*/
177180
public boolean isDone() {
178181
if (status() == Status.DONE) {
179182
return true;
180183
}
181184
ChangeRequest updated = reload(Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS));
182-
return updated.status() == Status.DONE;
183-
185+
return updated == null || updated.status() == Status.DONE;
184186
}
185187

186188
@Override

gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/DeleteZone.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package com.google.gcloud.examples.dns.snippets;
2424

25+
import com.google.gcloud.dns.ChangeRequest;
2526
import com.google.gcloud.dns.ChangeRequestInfo;
2627
import com.google.gcloud.dns.Dns;
2728
import com.google.gcloud.dns.DnsOptions;
@@ -59,21 +60,17 @@ public static void main(String... args) {
5960
// Build and apply the change request to our zone if it contains records to delete
6061
ChangeRequestInfo changeRequest = changeBuilder.build();
6162
if (!changeRequest.deletions().isEmpty()) {
62-
changeRequest = dns.applyChangeRequest(zoneName, changeRequest);
63+
ChangeRequest pendingRequest = dns.applyChangeRequest(zoneName, changeRequest);
6364

64-
// Wait for change to finish, but save data traffic by transferring only ID and status
65-
Dns.ChangeRequestOption option =
66-
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS);
67-
while (ChangeRequestInfo.Status.PENDING.equals(changeRequest.status())) {
65+
// Wait for the change request to complete
66+
while (!pendingRequest.isDone()) {
6867
System.out.println("Waiting for change to complete. Going to sleep for 500ms...");
6968
try {
7069
Thread.sleep(500);
7170
} catch (InterruptedException e) {
7271
System.err.println("The thread was interrupted while waiting for change request to be "
7372
+ "processed.");
7473
}
75-
// Update the change, but fetch only change ID and status
76-
changeRequest = dns.getChangeRequest(zoneName, changeRequest.generatedId(), option);
7774
}
7875
}
7976

gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/snippets/ManipulateZonesAndRecordSets.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,17 @@ public static void main(String... args) {
128128
// Build and apply the change request to our zone if it contains records to delete
129129
changeRequest = changeBuilder.build();
130130
if (!changeRequest.deletions().isEmpty()) {
131-
changeRequest = dns.applyChangeRequest(zoneName, changeRequest);
131+
ChangeRequest pendingRequest = dns.applyChangeRequest(zoneName, changeRequest);
132132

133-
// Wait for change to finish, but save data traffic by transferring only ID and status
134-
Dns.ChangeRequestOption option =
135-
Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS);
136-
while (ChangeRequest.Status.PENDING.equals(changeRequest.status())) {
133+
// Wait for the change request to complete
134+
while (!pendingRequest.isDone()) {
137135
System.out.println("Waiting for change to complete. Going to sleep for 500ms...");
138136
try {
139137
Thread.sleep(500);
140138
} catch (InterruptedException e) {
141139
System.err.println("The thread was interrupted while waiting for change request to be "
142140
+ "processed.");
143141
}
144-
145-
// Update the change, but fetch only change ID and status
146-
changeRequest = dns.getChangeRequest(zoneName, changeRequest.generatedId(), option);
147142
}
148143
}
149144

0 commit comments

Comments
 (0)