Skip to content

Commit deac27a

Browse files
Fixed code
1 parent db06098 commit deac27a

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public static void main(String[] args)
3131
throws IOException, ExecutionException, InterruptedException, TimeoutException {
3232
// TODO(developer): Replace these variables before running the sample.
3333
// The project that contains the primary disk.
34-
String projectId = "YOUR_PROJECT_ID";
34+
String primaryProjectId = "PRIMARY_PROJECT_ID";
35+
// The project that contains the secondary disk.
36+
String secondaryProjectId = "SECONDARY_PROJECT_ID";
3537
// Name of the primary disk you want to use.
3638
String primaryDiskName = "PRIMARY_DISK_NAME";
3739
// Name of the zone in which your primary disk is located.
@@ -43,28 +45,28 @@ public static void main(String[] args)
4345
// Name of the zone in which you want to create the secondary disk.
4446
String secondaryDiskZone = "us-east1-c";
4547
// Size of the new disk in gigabytes.
46-
long diskSizeGb = 10L;
48+
long diskSizeGb = 30L;
4749
// The type of the disk you want to create. This value uses the following format:
4850
// "projects/{projectId}/zones/{zone}/diskTypes/
4951
// (pd-standard|pd-ssd|pd-balanced|pd-extreme)".
5052
String diskType = String.format(
51-
"projects/%s/zones/%s/diskTypes/pd-balanced", projectId, secondaryDiskZone);
53+
"projects/%s/zones/%s/diskTypes/pd-balanced", secondaryProjectId, secondaryDiskZone);
5254

53-
createDiskSecondary(projectId, primaryDiskName, secondaryDiskName,
55+
createDiskSecondary(primaryProjectId, secondaryProjectId, primaryDiskName, secondaryDiskName,
5456
primaryDiskZone, secondaryDiskZone, diskSizeGb, diskType);
5557
}
5658

5759
// Creates a secondary disk in a specified zone.
58-
public static Disk createDiskSecondary(String projectId, String primaryDiskName,
59-
String secondaryDiskName, String primaryDiskZone, String secondaryDiskZone,
60-
long diskSizeGb, String diskType)
60+
public static Disk createDiskSecondary(String primaryProjectId, String secondaryProjectId,
61+
String primaryDiskName, String secondaryDiskName, String primaryDiskZone,
62+
String secondaryDiskZone, long diskSizeGb, String diskType)
6163
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6264
String primaryDiskSource = String.format("projects/%s/zones/%s/disks/%s",
63-
projectId, primaryDiskZone, primaryDiskName);
65+
primaryProjectId, primaryDiskZone, primaryDiskName);
6466

6567
DiskAsyncReplication asyncReplication = DiskAsyncReplication.newBuilder()
66-
.setDisk(primaryDiskSource)
67-
.build();
68+
.setDisk(primaryDiskSource)
69+
.build();
6870

6971
// Initialize client that will be used to send requests. This client only needs to be created
7072
// once, and can be reused for multiple requests.
@@ -78,13 +80,13 @@ public static Disk createDiskSecondary(String projectId, String primaryDiskName,
7880
.build();
7981

8082
// Wait for the create disk operation to complete.
81-
Operation response = disksClient.insertAsync(projectId, secondaryDiskZone, disk)
83+
Operation response = disksClient.insertAsync(secondaryProjectId, secondaryDiskZone, disk)
8284
.get(3, TimeUnit.MINUTES);
8385

8486
if (response.hasError()) {
8587
return null;
8688
}
87-
return disksClient.get(projectId, secondaryDiskZone, secondaryDiskName);
89+
return disksClient.get(secondaryProjectId, secondaryDiskZone, secondaryDiskName);
8890
}
8991
}
9092
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public void testCreateDiskSecondary()
308308
String diskType = String.format(
309309
"projects/%s/zones/%s/diskTypes/pd-ssd", PROJECT_ID, ZONE);
310310
Disk disk = CreateDiskSecondary.createDiskSecondary(
311-
PROJECT_ID, EMPTY_DISK_NAME, SECONDARY_DISK, ZONE,
311+
PROJECT_ID, PROJECT_ID, EMPTY_DISK_NAME, SECONDARY_DISK, ZONE,
312312
"us-central1-c", DISK_SIZE, diskType);
313313

314314
// Verify that the secondary disk was created.

0 commit comments

Comments
 (0)