Skip to content

Commit 92670ce

Browse files
Fixed compute_disk_stop_replication sample
1 parent 2c9b306 commit 92670ce

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

compute/cloud-client/src/main/java/compute/disks/StopDiskReplication.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package compute.disks;
1818

1919
// [START compute_disk_stop_replication]
20-
// Uncomment this line if your disk has zonal location.
21-
// import com.google.cloud.compute.v1.DisksClient;
20+
import com.google.cloud.compute.v1.DisksClient;
2221
import com.google.cloud.compute.v1.Operation;
2322
import com.google.cloud.compute.v1.RegionDisksClient;
2423
import java.io.IOException;
@@ -43,21 +42,24 @@ public static void main(String[] args)
4342
public static Operation.Status stopDiskAsyncReplication(
4443
String project, String diskLocation, String diskName)
4544
throws IOException, ExecutionException, InterruptedException {
46-
47-
// Uncomment this line if your disk has zonal location.
48-
//try (DisksClient disksClient = DisksClient.create()) {
49-
50-
// Initialize client that will be used to send requests. This client only needs to be created
51-
// once, and can be reused for multiple requests.
52-
try (RegionDisksClient disksClient = RegionDisksClient.create()) {
53-
Operation response = disksClient.stopAsyncReplicationAsync(
54-
project, diskLocation, diskName).get();
55-
56-
if (response.hasError()) {
57-
throw new Error("Error stopping disk replication! " + response.getError());
45+
Operation response;
46+
if (Character.isDigit(diskLocation.charAt(diskLocation.length() - 1))) {
47+
// Initialize client that will be used to send requests. This client only needs to be created
48+
// once, and can be reused for multiple requests.
49+
try (RegionDisksClient disksClient = RegionDisksClient.create()) {
50+
response = disksClient.stopAsyncReplicationAsync(
51+
project, diskLocation, diskName).get();
5852
}
59-
return response.getStatus();
53+
} else {
54+
try (DisksClient disksClient = DisksClient.create()) {
55+
response = disksClient.stopAsyncReplicationAsync(
56+
project, diskLocation, diskName).get();
57+
}
58+
}
59+
if (response.hasError()) {
60+
throw new Error("Error stopping disk replication! " + response.getError());
6061
}
62+
return response.getStatus();
6163
}
6264
}
6365
// [END compute_disk_stop_replication]

0 commit comments

Comments
 (0)