diff --git a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryCustom.java b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryCustom.java index df5c74de9bf..b47f9866048 100644 --- a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryCustom.java +++ b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryCustom.java @@ -36,7 +36,9 @@ public static void main(String[] args) throws IOException, ExecutionException, InterruptedException, TimeoutException { // TODO(developer): Replace these variables before running the sample. // The project that contains the primary disk. - String projectId = "YOUR_PROJECT_ID"; + String primaryProjectId = "PRIMARY_PROJECT_ID"; + // The project that contains the secondary disk. + String secondaryProjectId = "SECONDARY_PROJECT_ID"; // Name of the primary disk you want to use. String primaryDiskName = "PRIMARY_DISK_NAME"; // Name of the zone in which your primary disk is located. @@ -48,24 +50,24 @@ public static void main(String[] args) // Name of the zone in which you want to create the secondary disk. String secondaryDiskZone = "us-east1-c"; // Size of the new disk in gigabytes. - long diskSizeGb = 10L; + long diskSizeGb = 30L; // The type of the disk you want to create. This value uses the following format: // "projects/{projectId}/zones/{zone}/diskTypes/ // (pd-standard|pd-ssd|pd-balanced|pd-extreme)". String diskType = String.format( - "projects/%s/zones/%s/diskTypes/pd-balanced", projectId, secondaryDiskZone); + "projects/%s/zones/%s/diskTypes/pd-balanced", secondaryProjectId, secondaryDiskZone); - createDiskSecondaryCustom(projectId, primaryDiskName, secondaryDiskName, - primaryDiskZone, secondaryDiskZone, diskSizeGb, diskType); + createDiskSecondaryCustom(primaryProjectId, secondaryProjectId, primaryDiskName, + secondaryDiskName, primaryDiskZone, secondaryDiskZone, diskSizeGb, diskType); } // Creates a secondary disk with specified custom parameters. - public static Disk createDiskSecondaryCustom(String projectId, String primaryDiskName, - String secondaryDiskName, String primaryDiskZone, String secondaryDiskZone, - long diskSizeGb, String diskType) + public static Disk createDiskSecondaryCustom(String primaryProjectId, String secondaryProjectId, + String primaryDiskName, String secondaryDiskName, String primaryDiskZone, + String secondaryDiskZone, long diskSizeGb, String diskType) throws IOException, ExecutionException, InterruptedException, TimeoutException { String primaryDiskSource = String.format("projects/%s/zones/%s/disks/%s", - projectId, primaryDiskZone, primaryDiskName); + primaryProjectId, primaryDiskZone, primaryDiskName); DiskAsyncReplication asyncReplication = DiskAsyncReplication.newBuilder() .setDisk(primaryDiskSource) @@ -96,13 +98,13 @@ public static Disk createDiskSecondaryCustom(String projectId, String primaryDis .build(); // Wait for the create disk operation to complete. - Operation response = disksClient.insertAsync(projectId, secondaryDiskZone, disk) + Operation response = disksClient.insertAsync(secondaryProjectId, secondaryDiskZone, disk) .get(3, TimeUnit.MINUTES); if (response.hasError()) { return null; } - return disksClient.get(projectId, secondaryDiskZone, secondaryDiskName); + return disksClient.get(secondaryProjectId, secondaryDiskZone, secondaryDiskName); } } } diff --git a/compute/cloud-client/src/test/java/compute/disks/DisksIT.java b/compute/cloud-client/src/test/java/compute/disks/DisksIT.java index 84461272693..0ad471458f8 100644 --- a/compute/cloud-client/src/test/java/compute/disks/DisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/DisksIT.java @@ -309,7 +309,8 @@ public void testCreateDiskSecondaryCustom() String diskType = String.format( "projects/%s/zones/%s/diskTypes/pd-ssd", PROJECT_ID, ZONE); Disk disk = CreateDiskSecondaryCustom.createDiskSecondaryCustom( - PROJECT_ID, EMPTY_DISK_NAME, SECONDARY_DISK_CUSTOM, ZONE, + PROJECT_ID, PROJECT_ID, EMPTY_DISK_NAME, + SECONDARY_DISK_CUSTOM, ZONE, "us-central1-c", DISK_SIZE, diskType); // Verify that the secondary disk was created.