Skip to content

Commit ba184d0

Browse files
Fixed code
1 parent 61ffe38 commit ba184d0

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public static void main(String[] args)
3333
throws IOException, ExecutionException, InterruptedException, TimeoutException {
3434
// TODO(developer): Replace these variables before running the sample.
3535
// The project that contains the primary disk.
36-
String projectId = "YOUR_PROJECT_ID";
36+
String primaryProjectId = "PRIMARY_PROJECT_ID";
37+
// The project that contains the secondary disk.
38+
String secondaryProjectId = "SECONDARY_PROJECT_ID";
3739
// Name of the primary disk you want to use.
3840
String primaryDiskName = "PRIMARY_DISK_NAME";
3941
// Name of the disk you want to create.
@@ -52,26 +54,26 @@ public static void main(String[] args)
5254
// "projects/{projectId}/zones/{zone}/diskTypes/
5355
// (pd-standard|pd-ssd|pd-balanced|pd-extreme)".
5456
String diskType = String.format(
55-
"projects/%s/regions/%s/diskTypes/pd-balanced", projectId, secondaryDiskRegion);
57+
"projects/%s/regions/%s/diskTypes/pd-balanced", secondaryProjectId, secondaryDiskRegion);
5658

57-
createDiskSecondaryRegional(projectId, primaryDiskName, secondaryDiskName,
58-
primaryDiskRegion, secondaryDiskRegion, diskSizeGb, diskType);
59+
createDiskSecondaryRegional(primaryProjectId, secondaryProjectId, primaryDiskName,
60+
secondaryDiskName, primaryDiskRegion, secondaryDiskRegion, diskSizeGb, diskType);
5961
}
6062

6163
// Creates a secondary disk in a specified region.
62-
public static Disk createDiskSecondaryRegional(String projectId, String primaryDiskName,
63-
String secondaryDiskName, String primaryDiskRegion, String secondaryDiskRegion,
64-
long diskSizeGb, String diskType)
64+
public static Disk createDiskSecondaryRegional(String projectId, String secondaryProjectId,
65+
String primaryDiskName, String secondaryDiskName, String primaryDiskRegion,
66+
String secondaryDiskRegion, long diskSizeGb, String diskType)
6567
throws IOException, ExecutionException, InterruptedException, TimeoutException {
6668
// An iterable collection of zone names in which you want to keep
6769
// the new disks' replicas. One of the replica zones of the clone must match
6870
// the zone of the source disk.
6971
List<String> replicaZones = Arrays.asList(
70-
String.format("projects/%s/zones/%s-c", projectId, secondaryDiskRegion),
71-
String.format("projects/%s/zones/%s-b", projectId, secondaryDiskRegion));
72+
String.format("projects/%s/zones/%s-c", secondaryProjectId, secondaryDiskRegion),
73+
String.format("projects/%s/zones/%s-b", secondaryProjectId, secondaryDiskRegion));
7274

7375
String primaryDiskSource = String.format("projects/%s/regions/%s/disks/%s",
74-
projectId, primaryDiskRegion, primaryDiskName);
76+
projectId, primaryDiskRegion, primaryDiskName);
7577

7678
DiskAsyncReplication asyncReplication = DiskAsyncReplication.newBuilder()
7779
.setDisk(primaryDiskSource)
@@ -91,13 +93,13 @@ public static Disk createDiskSecondaryRegional(String projectId, String primaryD
9193
.build();
9294

9395
// Wait for the create disk operation to complete.
94-
Operation response = disksClient.insertAsync(projectId, secondaryDiskRegion, disk)
96+
Operation response = disksClient.insertAsync(secondaryProjectId, secondaryDiskRegion, disk)
9597
.get(3, TimeUnit.MINUTES);
9698

9799
if (response.hasError()) {
98100
return null;
99101
}
100-
return disksClient.get(projectId, secondaryDiskRegion, secondaryDiskName);
102+
return disksClient.get(secondaryProjectId, secondaryDiskRegion, secondaryDiskName);
101103
}
102104
}
103105
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ public void testCreateDiskSecondaryRegional()
310310
String diskType = String.format(
311311
"projects/%s/regions/%s/diskTypes/pd-balanced", PROJECT_ID, REGION);
312312
Disk disk = CreateDiskSecondaryRegional.createDiskSecondaryRegional(
313-
PROJECT_ID, REGIONAL_BLANK_DISK, SECONDARY_REGIONAL_DISK, REGION,
314-
"us-central1", DISK_SIZE, diskType);
313+
PROJECT_ID, PROJECT_ID, REGIONAL_BLANK_DISK, SECONDARY_REGIONAL_DISK,
314+
REGION, "us-central1", DISK_SIZE, diskType);
315+
315316
// Verify that the secondary disk was created.
316317
assertNotNull(disk);
317318
assertThat(disk.getAsyncPrimaryDisk().getDisk().contains(REGIONAL_BLANK_DISK));

0 commit comments

Comments
 (0)