@@ -91,7 +91,7 @@ public DnsBatchResult<Page<Zone>> listZones(Dns.ZoneListOption... options) {
9191 public DnsBatchResult <Zone > createZone (ZoneInfo zone , Dns .ZoneOption ... options ) {
9292 DnsBatchResult <Zone > result = new DnsBatchResult <>();
9393 // 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 );
9595 Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
9696 batch .addCreateZone (zone .toPb (), callback , optionMap );
9797 return result ;
@@ -118,7 +118,7 @@ public DnsBatchResult<Boolean> deleteZone(String zoneName) {
118118 */
119119 public DnsBatchResult <Zone > getZone (String zoneName , Dns .ZoneOption ... options ) {
120120 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 );
122122 Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
123123 batch .addGetZone (zoneName , callback , optionMap );
124124 return result ;
@@ -186,7 +186,7 @@ public DnsBatchResult<Page<ChangeRequest>> listChangeRequests(String zoneName,
186186 public DnsBatchResult <ChangeRequest > getChangeRequest (String zoneName , String changeRequestId ,
187187 Dns .ChangeRequestOption ... options ) {
188188 DnsBatchResult <ChangeRequest > result = new DnsBatchResult <>();
189- RpcBatch .Callback <Change > callback = createChangeRequestCallback (zoneName , result , true );
189+ RpcBatch .Callback <Change > callback = createChangeRequestCallback (zoneName , result , true , true );
190190 Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
191191 batch .addGetChangeRequest (zoneName , changeRequestId , callback , optionMap );
192192 return result ;
@@ -203,14 +203,15 @@ public DnsBatchResult<ChangeRequest> getChangeRequest(String zoneName, String ch
203203 public DnsBatchResult <ChangeRequest > applyChangeRequest (String zoneName ,
204204 ChangeRequestInfo changeRequest , Dns .ChangeRequestOption ... options ) {
205205 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 );
207208 Map <DnsRpc .Option , ?> optionMap = DnsImpl .optionMap (options );
208209 batch .addApplyChangeRequest (zoneName , changeRequest .toPb (), callback , optionMap );
209210 return result ;
210211 }
211212
212213 /**
213- * Submits this batch for processing using a single HTTP request.
214+ * Submits this batch for processing using a single RPC request.
214215 */
215216 public void submit () {
216217 batch .submit ();
@@ -259,7 +260,7 @@ public void onFailure(GoogleJsonError googleJsonError) {
259260 * A joint callback for both "get zone" and "create zone" operations.
260261 */
261262 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 ) {
263264 return new RpcBatch .Callback <ManagedZone >() {
264265 @ Override
265266 public void onSuccess (ManagedZone response ) {
@@ -268,7 +269,12 @@ public void onSuccess(ManagedZone response) {
268269
269270 @ Override
270271 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+ }
272278 }
273279 };
274280 }
@@ -337,17 +343,29 @@ public void onFailure(GoogleJsonError googleJsonError) {
337343 * A joint callback for both "get change request" and "create change request" operations.
338344 */
339345 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 ) {
341348 return new RpcBatch .Callback <Change >() {
342349 @ Override
343350 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 ));
346353 }
347354
348355 @ Override
349356 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+ if ("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+ return ;
365+ }
366+ // the zone does not exist, so throw an exception
367+ }
368+ result .error (serviceException );
351369 }
352370 };
353371 }
0 commit comments