@@ -235,6 +235,14 @@ private static Operation deleteInstance(Compute compute, String instanceName) th
235
235
return delete .execute ();
236
236
}
237
237
238
+ public static String getLastWordFromUrl (String url ) {
239
+ if (url != null ) {
240
+ String [] bits = url .split ("/" );
241
+ url = bits [bits .length - 1 ];
242
+ }
243
+ return url ;
244
+ }
245
+
238
246
// [START wait_until_complete]
239
247
/**
240
248
* Wait until {@code operation} is completed.
@@ -250,11 +258,8 @@ public static Operation.Error blockUntilComplete(
250
258
Compute compute , Operation operation , long timeout ) throws Exception {
251
259
long start = System .currentTimeMillis ();
252
260
final long pollInterval = 5 * 1000 ;
253
- String zone = operation .getZone (); // null for global/regional operations
254
- if (zone != null ) {
255
- String [] bits = zone .split ("/" );
256
- zone = bits [bits .length - 1 ];
257
- }
261
+ String zone = getLastWordFromUrl (operation .getZone ()); // null for global/regional operations
262
+ String region = getLastWordFromUrl (operation .getRegion ());
258
263
String status = operation .getStatus ();
259
264
String opId = operation .getName ();
260
265
while (operation != null && !status .equals ("DONE" )) {
@@ -267,6 +272,9 @@ public static Operation.Error blockUntilComplete(
267
272
if (zone != null ) {
268
273
Compute .ZoneOperations .Get get = compute .zoneOperations ().get (PROJECT_ID , zone , opId );
269
274
operation = get .execute ();
275
+ } else if (region != null ) {
276
+ Compute .RegionOperations .Get get = compute .regionOperations ().get (PROJECT_ID , region , opId );
277
+ operation = get .execute ();
270
278
} else {
271
279
Compute .GlobalOperations .Get get = compute .globalOperations ().get (PROJECT_ID , opId );
272
280
operation = get .execute ();
0 commit comments