@@ -91,7 +91,7 @@ public DnsBatchResult<Page<Zone>> listZones(Dns.ZoneListOption... options) {
91
91
public DnsBatchResult <Zone > createZone (ZoneInfo zone , Dns .ZoneOption ... options ) {
92
92
DnsBatchResult <Zone > result = new DnsBatchResult <>();
93
93
// todo this can cause misleading report of a failure, intended to be fixed within #924
94
- RpcBatch .Callback <ManagedZone > callback = createZoneCallback (this .options , result , true );
94
+ RpcBatch .Callback <ManagedZone > callback = createZoneCallback (this .options , result , false , true );
95
95
Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
96
96
batch .addCreateZone (zone .toPb (), callback , optionMap );
97
97
return result ;
@@ -118,7 +118,7 @@ public DnsBatchResult<Boolean> deleteZone(String zoneName) {
118
118
*/
119
119
public DnsBatchResult <Zone > getZone (String zoneName , Dns .ZoneOption ... options ) {
120
120
DnsBatchResult <Zone > result = new DnsBatchResult <>();
121
- RpcBatch .Callback <ManagedZone > callback = createZoneCallback (this .options , result , true );
121
+ RpcBatch .Callback <ManagedZone > callback = createZoneCallback (this .options , result , true , true );
122
122
Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
123
123
batch .addGetZone (zoneName , callback , optionMap );
124
124
return result ;
@@ -186,7 +186,7 @@ public DnsBatchResult<Page<ChangeRequest>> listChangeRequests(String zoneName,
186
186
public DnsBatchResult <ChangeRequest > getChangeRequest (String zoneName , String changeRequestId ,
187
187
Dns .ChangeRequestOption ... options ) {
188
188
DnsBatchResult <ChangeRequest > result = new DnsBatchResult <>();
189
- RpcBatch .Callback <Change > callback = createChangeRequestCallback (zoneName , result , true );
189
+ RpcBatch .Callback <Change > callback = createChangeRequestCallback (zoneName , result , true , true );
190
190
Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
191
191
batch .addGetChangeRequest (zoneName , changeRequestId , callback , optionMap );
192
192
return result ;
@@ -203,14 +203,15 @@ public DnsBatchResult<ChangeRequest> getChangeRequest(String zoneName, String ch
203
203
public DnsBatchResult <ChangeRequest > applyChangeRequest (String zoneName ,
204
204
ChangeRequestInfo changeRequest , Dns .ChangeRequestOption ... options ) {
205
205
DnsBatchResult <ChangeRequest > result = new DnsBatchResult <>();
206
- RpcBatch .Callback <Change > callback = createChangeRequestCallback (zoneName , result , false );
206
+ RpcBatch .Callback <Change > callback =
207
+ createChangeRequestCallback (zoneName , result , false , false );
207
208
Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
208
209
batch .addApplyChangeRequest (zoneName , changeRequest .toPb (), callback , optionMap );
209
210
return result ;
210
211
}
211
212
212
213
/**
213
- * Submits this batch for processing using a single HTTP request.
214
+ * Submits this batch for processing using a single RPC request.
214
215
*/
215
216
public void submit () {
216
217
batch .submit ();
@@ -259,7 +260,7 @@ public void onFailure(GoogleJsonError googleJsonError) {
259
260
* A joint callback for both "get zone" and "create zone" operations.
260
261
*/
261
262
private RpcBatch .Callback <ManagedZone > createZoneCallback (final DnsOptions serviceOptions ,
262
- final DnsBatchResult <Zone > result , final boolean idempotent ) {
263
+ final DnsBatchResult <Zone > result , final boolean nullForNotFound , final boolean idempotent ) {
263
264
return new RpcBatch .Callback <ManagedZone >() {
264
265
@ Override
265
266
public void onSuccess (ManagedZone response ) {
@@ -268,7 +269,12 @@ public void onSuccess(ManagedZone response) {
268
269
269
270
@ Override
270
271
public void onFailure (GoogleJsonError googleJsonError ) {
271
- result .error (new DnsException (googleJsonError , idempotent ));
272
+ DnsException serviceException = new DnsException (googleJsonError , idempotent );
273
+ if (nullForNotFound && serviceException .code () == HTTP_NOT_FOUND ) {
274
+ result .success (null );
275
+ } else {
276
+ result .error (serviceException );
277
+ }
272
278
}
273
279
};
274
280
}
@@ -337,17 +343,28 @@ public void onFailure(GoogleJsonError googleJsonError) {
337
343
* A joint callback for both "get change request" and "create change request" operations.
338
344
*/
339
345
private RpcBatch .Callback <Change > createChangeRequestCallback (final String zoneName ,
340
- final DnsBatchResult <ChangeRequest > result , final boolean idempotent ) {
346
+ final DnsBatchResult <ChangeRequest > result , final boolean nullForNotFound ,
347
+ final boolean idempotent ) {
341
348
return new RpcBatch .Callback <Change >() {
342
349
@ Override
343
350
public void onSuccess (Change response ) {
344
- result .success (response == null ? null : ChangeRequest .fromPb (options .service (),
345
- zoneName , response ));
351
+ result .success (response == null ? null : ChangeRequest .fromPb (options .service (), zoneName ,
352
+ response ));
346
353
}
347
354
348
355
@ Override
349
356
public void onFailure (GoogleJsonError googleJsonError ) {
350
- result .error (new DnsException (googleJsonError , idempotent ));
357
+ DnsException serviceException = new DnsException (googleJsonError , idempotent );
358
+ if (nullForNotFound && serviceException .code () == HTTP_NOT_FOUND
359
+ && ("entity.parameters.changeId" .equals (serviceException .location ())
360
+ || serviceException .getMessage () != null
361
+ && serviceException .getMessage ().contains ("parameters.changeId" ))) {
362
+ // the change id was not found, but the zone exists
363
+ result .success (null );
364
+ } else {
365
+ // the zone does not exist, so throw an exception
366
+ result .error (serviceException );
367
+ }
351
368
}
352
369
};
353
370
}
0 commit comments