Skip to content

Commit 366d833

Browse files
Fixed comments and parameters
1 parent b34ae5a commit 366d833

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,24 @@ public static void main(String[] args)
3232
// TODO(developer): Replace these variables before running the sample.
3333
// Project ID or project number of the Cloud project you want to use.
3434
String projectId = "YOUR_PROJECT_ID";
35-
// Name of the zone in which the instance you want to use resides.
36-
String zone = "zone-name";
37-
// Name of the compute instance you want to attach a disk to.
35+
// Name of the zone of your compute instance.
36+
String zone = "us-central1-a";
37+
// The name of the compute instance where you are adding the replicated disk.
3838
String instanceName = "YOUR_INSTANCE_NAME";
39-
// Full or partial URL of a persistent disk that you want to attach.
40-
String diskLink = String.format(
41-
"projects/%s/regions/DISK_REGION/disks/YOUR_DISK_NAME", projectId);
39+
// The region where your replicated disk is located.
40+
String region = "us-central1";
41+
// The name of the replicated disk.
42+
String diskName = "YOUR_DISK_NAME";
4243

43-
attachRegionalDiskForce(projectId, zone, instanceName, diskLink);
44+
attachRegionalDiskForce(projectId, zone, instanceName, region, diskName);
4445
}
4546

4647
// Attaches a regional disk to the instance,
4748
// forcing the attachment even if other VMs are using the disk.
48-
public static void attachRegionalDiskForce(
49-
String projectId, String zone, String instanceName, String diskLink)
49+
public static Operation.Status attachRegionalDiskForce(
50+
String projectId, String zone, String instanceName, String region, String diskName)
5051
throws IOException, InterruptedException, ExecutionException, TimeoutException {
52+
String diskLink = String.format("projects/%s/regions/%s/disks/%s", projectId, region, diskName);
5153
// Initialize client that will be used to send requests. This client only needs to be created
5254
// once, and can be reused for multiple requests.
5355
try (InstancesClient instancesClient = InstancesClient.create()) {
@@ -69,10 +71,9 @@ public static void attachRegionalDiskForce(
6971
.get(3, TimeUnit.MINUTES);
7072

7173
if (response.hasError()) {
72-
System.out.printf("Error attaching regional disk: %s%n", response.getError());
73-
return;
74+
throw new Error("Error attaching regional disk! " + response);
7475
}
75-
System.out.println("Regional disk attached successfully.");
76+
return response.getStatus();
7677
}
7778
}
7879
}

compute/cloud-client/src/test/java/compute/disks/DisksIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,9 @@ public void testDiskAttachResize()
317317
@Order(2)
318318
public void testAttachRegionalDiskForceAttach()
319319
throws IOException, ExecutionException, InterruptedException, TimeoutException {
320-
String diskLink = String.format("projects/%s/regions/%s/disks/%s",
321-
PROJECT_ID, REGION, REGIONAL_ATTACHED_DISK);
320+
Operation.Status status = AttachRegionalDiskForce
321+
.attachRegionalDiskForce(PROJECT_ID, ZONE, INSTANCE_NAME, REGION, REGIONAL_ATTACHED_DISK);
322322

323-
AttachRegionalDiskForce.attachRegionalDiskForce(PROJECT_ID, ZONE, INSTANCE_NAME, diskLink);
324-
325-
assertThat(stdOut.toString()).contains("Regional disk attached successfully.");
323+
assertThat(status).isEqualTo(Operation.Status.DONE);
326324
}
327325
}

0 commit comments

Comments
 (0)