Skip to content

Commit

Permalink
Fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
TetyanaYahodska committed Nov 10, 2024
1 parent 7570e73 commit 55ba406
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 55ba406

Please sign in to comment.