Skip to content

Commit dc94374

Browse files
ludochOremGLGeapl-gemugamiTetyanaYahodskaiennae
authored
Sync with main. (#9972)
* chore(job): migrate regions by associating them with an official product with a job_ prefix (#9883) * chore(endpoints): delete region 'swagger' in endpoints/multiple-versions (#9857) * chore(endpoints): delete region swagger to openapi-v1.yaml * chore(endpoints): delete region swagger to openapi-v2.yaml * chore(job): delete sample jobs_java_dependencies_beta (#9810) * chore(job): delete sample jobs_java_dependencies_beta * chore(job): delete region_tab 'jobs_java_dependencies_beta' and update 'google-api-services-jobs' version * feat(compute): add compute disk regional replicated sample (#9697) * Implemented compute_disk_regional_replicated sample, created test * Fixed zone * Fixed test * Fixed test * Fixed disk size * Fixed code as requested in the comment * feat(compute): add compute disk start/stop replication samples (#9650) * Implemented compute_disk_start_replication and compute_disk_stop_replication samples, created tests * Fixed test * Deleted not related classes * Fixed lint issue * Increased timeout * Split samples for zonal location * Fixed code * Fixed code * Increased timeout * Increased timeout * feat(tpu): add tpu vm create spot sample. (#9610) * Changed package, added information to CODEOWNERS * Added information to CODEOWNERS * Added timeout * Fixed parameters for test * Fixed DeleteTpuVm and naming * Added comment, created Util class * Fixed naming * Fixed whitespace * Split PR into smaller, deleted redundant code * Implemented tpu_vm_create_spot sample, created test * changed zone * Changed zone * Fixed empty lines and tests, deleted cleanup method * Changed zone * Deleted redundant test class * Increased timeout * Fixed test * feat(tpu): add tpu vm create startup script sample. (#9612) * Changed package, added information to CODEOWNERS * Added information to CODEOWNERS * Added timeout * Fixed parameters for test * Fixed DeleteTpuVm and naming * Added comment, created Util class * Fixed naming * Fixed whitespace * Split PR into smaller, deleted redundant code * Implemented tpu_vm_create_startup_script sample, created test * Fixed tests and empty lines * Changed zone * Deleted redundant test classes * Increased timeout * Fixed code * feat(tpu): add tpu queued resources create/get/delete samples (#9613) * Changed package, added information to CODEOWNERS * Added information to CODEOWNERS * Added timeout * Fixed parameters for test * Fixed DeleteTpuVm and naming * Added comment, created Util class * Fixed naming * Fixed whitespace * Split PR into smaller, deleted redundant code * Implemented tpu_queued_resources_create, tpu_queued_resources_get, tpu_queued_resources_delete_force and tpu_queued_resources_delete samples, created tests * Fixed test * Fixed tests * Fixed error massage * Fixed typo * Fixed zone * Fixed test * Fixed code * Deleted commented imports * Fixed code as requested in comments * feat(tpu): add tpu queued resources create spot (#9615) Add a code sample for tpu_queued_resources_create_spot * chore: add translate dev team for translate samples (#9888) b/385243174 * feat(securitycenter): Add Resource SCC Management API Org ETD Custom Module code samples (Create, Delete, List, Get) (#9743) * sample codes for event threat detection custom modules * addressed comments * addressed comments * addressed comments * addressed comments * fix(compute): fixed compute_reservation_create_shared sample and test to use mocked client (#9840) * Fixed sample and test to use mocked client * Fixed code as requested in the comments * feat(compute): add compute instance create replicated boot disk sample (#9735) * Implemented compute_instance_create_replicated_boot_disk sample, created test * Fixed test * Fixed code as requested in the comments * Fixed Util class * Fixed code * feat(compute): add compute consistency group stop replication (#9694) * Implemented compute_consistency_group_create and compute_consistency_group_delete samples, created test * Implemented compute_consistency_group_stop_replication sample * Implemented compute_consistency_group_stop_replication sample * Created test and added needed classes for testing * Fixed test * Moved clean up methods * Added clean up methods for reservations * Fixed clean up method * Fixed clean up method * Added timeout * Reverted not related changes * Reverted not related changes * Reverted not related changes * Reverted not related changes * Fixed code * Split samples for zonal location * Added comments for methods * Fixed comments * feat(secretmanager): add optional ttl to create secret sample (#9889) * feat(secretmanager): add optional ttl to create secret sample * nit: Update secretmanager/src/main/java/secretmanager/CreateSecret.java Co-authored-by: code-review-assist[bot] <182814678+code-review-assist[bot]@users.noreply.github.com> * fix(secretmanager): fix comment indentation to resolve linting issues --------- Co-authored-by: Jennifer Davis <[email protected]> Co-authored-by: code-review-assist[bot] <182814678+code-review-assist[bot]@users.noreply.github.com> * feat(tpu): add tpu queued resources list sample (#9614) * Changed package, added information to CODEOWNERS * Added information to CODEOWNERS * Added timeout * Fixed parameters for test * Fixed DeleteTpuVm and naming * Added comment, created Util class * Fixed naming * Fixed whitespace * Split PR into smaller, deleted redundant code * Implemented tpu_queued_resources_create, tpu_queued_resources_get, tpu_queued_resources_delete_force and tpu_queued_resources_delete samples, created tests * Implemented tpu_queued_resources_list sample, created test * Fixed test * Fixed tests, deleted cleanup method * Fixed test * Fixed imports * feat(compute): add compute disk create secondary regional sample (#9641) * Implemented compute_disk_create_secondary_regional. created test * Fixed test * Fixed test * Fixed test * Fixed zone * Fixed naming * Fixed spaces * Fixed code * Fixed indentations * Fixed variable * Fixed code * Added cleanup methods * Fixed lint issue * Fixed lint issue * Fixed test * Fixed code * Fixed code * Fixed code * Deleted duplicated assertion * feat(compute): add compute disk create secondary sample. (#9643) * Implemented compute_disk_create_secondary sample, created test * Fixed code * Fixed variable * Fixed code * Merged changes from main * Fixed lint issue * fix(storage): migrate old region all to storagetransfer_transfer_all step 1 (#9917) * fix(job): remove old region create_job (#9914) * feat(compute): attach/ remove snapshot schedule to disk (#9791) * Implemented compute_snapshot_schedule_attach sample, created test * Implemented compute_snapshot_schedule_remove sample, created test * Fixed code * Fixed code as requested in the comments * feat(compute): add compute consistency group clone sample (#9885) * Implemented compute_consistency_group_clone and compute_consistency_group_clone_regional_disk samples, created tests * Fixed naming * feat(compute): add compute instance attach regional disk force sample (#9730) * Implemented compute_instance_attach_regional_disk_force sample, created test * Added clean up method * Fixed comments and parameters * Test order deleted * Fixed code * Fixed code * Fixed code * Increased timeout * Increased timeout * Increased timeout * Fixed code * Fixed code * Fixed code * Fixed naming * feat(compute): add compute disk create secondary custom sample (#9644) * Implemented compute_disk_create_secondary_custom sample, created test * Fixed code * Fixed variable * Fixed code * Fixed whitespace * Fixed whitespace * feat(compute): add compute snapshot schedule create/get/edit/list/delete samples (#9742) * Implemented compute_snapshot_schedule_delete and compute_snapshot_schedule_create samples, created test * Fixed test * Added compute_snapshot_schedule_get sample, created test * Fixed naming * Implemented compute_snapshot_schedule_edit, created test * Fixed naming * Implemented compute_snapshot_schedule_list sample, created test * Cleaned resources * Cleaned resources * Cleaned resources * Cleaned resources * Fixed test * Added comment * Fixed tests * Fixed code * Fixed code as requested in the comments * feat(compute): add compute disk create with snapshot schedule (#9788) * Implemented compute_disk_create_with_snapshot_schedule sample, created test * Fixed code * Fixed code * Fixed test * Fixed code * Fixed code as requested in the comments * Fixed lint issue * Fixed lint issue * Deleted redundant code * feat(tpu): add tpu queued resources time bound sample. (#9617) * Changed package, added information to CODEOWNERS * Added information to CODEOWNERS * Added timeout * Fixed parameters for test * Fixed DeleteTpuVm and naming * Added comment, created Util class * Fixed naming * Fixed whitespace * Split PR into smaller, deleted redundant code * Implemented tpu_queued_resources_create, tpu_queued_resources_get, tpu_queued_resources_delete_force and tpu_queued_resources_delete samples, created tests * Implemented tpu_queued_resources_time_bound sample, created test * Changed zone for tpu * Cleanup resources * Fixed tests * Fixed test * Fixed code as requested in the comments * Fixed code as requested in the comments * fix(job): delete old region tag update_job_with_field_mask (#9940) * feat(job): migrate region tags to include product prefix (#9966) * fix(endpoints): migrate all regions (#9943) * fix: disable flakybot reporting (#9968) * chore(job): remove unused region tags (#9969) * feat(securitycenter): Add Resource SCC Management API Org ETD Custom Module code samples (Update, Get Eff, List Eff, List Desc, Validate) (#9912) * sample codes for event threat detection custom modules * fixed lint * addressed comments * lint fix * addressed comments --------- Co-authored-by: OremGLG <[email protected]> Co-authored-by: eapl.me <[email protected]> Co-authored-by: Тетяна Ягодська <[email protected]> Co-authored-by: Jennifer Davis <[email protected]> Co-authored-by: lovenishs04 <[email protected]> Co-authored-by: alarconesparza <[email protected]> Co-authored-by: Jennifer Davis <[email protected]> Co-authored-by: code-review-assist[bot] <182814678+code-review-assist[bot]@users.noreply.github.com> Co-authored-by: Brian Dorsey <[email protected]>
1 parent b492db1 commit dc94374

File tree

70 files changed

+4375
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4375
-214
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
/speech @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/cloud-samples-reviewers
8080
/talent @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/cloud-samples-reviewers
8181
/texttospeech @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/cloud-samples-reviewers
82-
/translate @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/cloud-samples-reviewers
82+
/translate @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-ml-translate-dev
8383
/video @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/cloud-samples-reviewers
8484
/vision @GoogleCloudPlatform/java-samples-reviewers @yoshi-approver @GoogleCloudPlatform/cloud-samples-reviewers
8585

.kokoro/tests/run_prptst_tests.sh

-7
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,4 @@ else
9090
echo -e "\n Testing completed.\n"
9191
fi
9292

93-
# If this is a periodic build, send the test log to the FlakyBot except for Java 8
94-
# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot.
95-
if [[ $JAVA_VERSION != "1.8" && $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
96-
chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot
97-
$KOKORO_GFILE_DIR/linux_amd64/flakybot
98-
fi
99-
10093
exit $RTN

.kokoro/tests/run_test_java.sh

-7
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,4 @@ if [[ "$file" == *"run/"* && ("$file" != *"run/filesystem"* && "$file" != *"run/
9696
fi
9797
fi
9898

99-
# If this is a periodic build, send the test log to the FlakyBot except for Java 8
100-
# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot.
101-
if [[ $JAVA_VERSION != "1.8" && $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
102-
chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot
103-
$KOKORO_GFILE_DIR/linux_amd64/flakybot
104-
fi
105-
10699
exit $RTN
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package compute;
18+
19+
// [START compute_instance_create_replicated_boot_disk]
20+
import com.google.cloud.compute.v1.AttachedDisk;
21+
import com.google.cloud.compute.v1.AttachedDiskInitializeParams;
22+
import com.google.cloud.compute.v1.Instance;
23+
import com.google.cloud.compute.v1.InstancesClient;
24+
import com.google.cloud.compute.v1.NetworkInterface;
25+
import com.google.cloud.compute.v1.Operation;
26+
import com.google.cloud.compute.v1.Operation.Status;
27+
import java.io.IOException;
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
import java.util.concurrent.ExecutionException;
31+
import java.util.concurrent.TimeUnit;
32+
import java.util.concurrent.TimeoutException;
33+
34+
public class CreateInstanceWithRegionalDiskFromSnapshot {
35+
36+
public static void main(String[] args) throws IOException, ExecutionException,
37+
InterruptedException, TimeoutException {
38+
// TODO(developer): Replace these variables before running the sample
39+
// Project ID or project number of the Cloud project you want to use.
40+
String projectId = "YOUR_PROJECT_ID";
41+
// Name of the zone in which you want to create the instance.
42+
String zone = "us-central1-a";
43+
// Name of the instance you want to create.
44+
String instanceName = "YOUR_INSTANCE_NAME";
45+
// Name for the replicated disk.
46+
String diskName = "YOUR_REPLICATED_DISK_NAME";
47+
String region = zone.substring(0, zone.length() - 2);
48+
// Type of the disk.
49+
String diskType = String.format(
50+
"projects/%s/regions/%s/diskTypes/pd-standard", projectId, region);
51+
// The full path and name of the snapshot that you want to use as the source for the new disk.
52+
String snapshotLink = String.format("projects/%s/global/snapshots/%s", projectId,
53+
"SNAPSHOT_NAME");
54+
// An iterable collection of zone names in which you want to keep
55+
// the new disks' replicas. One of the replica zones of the clone must match
56+
// the zone of the source disk.
57+
List<String> replicaZones = new ArrayList<>();
58+
59+
createInstanceWithRegionalDiskFromSnapshot(projectId, zone, instanceName, diskName, diskType,
60+
snapshotLink, replicaZones);
61+
}
62+
63+
// Creates a new VM instance with regional disk from a snapshot and specifies replica zones.
64+
public static Status createInstanceWithRegionalDiskFromSnapshot(
65+
String projectId, String zone, String instanceName, String diskName,
66+
String diskType, String snapshotLink, List<String> replicaZones)
67+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
68+
// Initialize client that will be used to send requests. This client only needs to be created
69+
// once, and can be reused for multiple requests.
70+
try (InstancesClient instancesClient = InstancesClient.create()) {
71+
AttachedDiskInitializeParams initializeParams = AttachedDiskInitializeParams.newBuilder()
72+
.setSourceSnapshot(snapshotLink)
73+
.setDiskType(diskType)
74+
.setDiskName(diskName)
75+
.addAllReplicaZones(replicaZones)
76+
.build();
77+
78+
// Boot disk configuration
79+
AttachedDisk bootDisk = AttachedDisk.newBuilder()
80+
.setBoot(true)
81+
.setAutoDelete(true) // Optional: Delete disk when instance is deleted.
82+
.setType(AttachedDisk.Type.PERSISTENT.toString())
83+
.setInitializeParams(initializeParams)
84+
.build();
85+
86+
// Network interface configuration (using the default network)
87+
NetworkInterface networkInterface = NetworkInterface.newBuilder()
88+
.setNetwork("global/networks/default")
89+
.build();
90+
91+
// Create the instance resource
92+
Instance instanceResource = Instance.newBuilder()
93+
.setName(instanceName)
94+
.setMachineType(String.format("zones/%s/machineTypes/n1-standard-1", zone))
95+
.addDisks(bootDisk)
96+
.addNetworkInterfaces(networkInterface)
97+
.build();
98+
99+
Operation response = instancesClient.insertAsync(projectId, zone, instanceResource).get(3,
100+
TimeUnit.MINUTES);
101+
102+
if (response.hasError()) {
103+
throw new Error("Error creating instance! " + response.getError());
104+
}
105+
return response.getStatus();
106+
}
107+
}
108+
}
109+
// [END compute_instance_create_replicated_boot_disk]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package compute.disks;
18+
19+
// [START compute_instance_attach_regional_disk_force]
20+
import com.google.cloud.compute.v1.AttachDiskInstanceRequest;
21+
import com.google.cloud.compute.v1.AttachedDisk;
22+
import com.google.cloud.compute.v1.InstancesClient;
23+
import com.google.cloud.compute.v1.Operation;
24+
import com.google.cloud.compute.v1.Operation.Status;
25+
import java.io.IOException;
26+
import java.util.concurrent.ExecutionException;
27+
import java.util.concurrent.TimeUnit;
28+
import java.util.concurrent.TimeoutException;
29+
30+
public class AttachRegionalDiskForce {
31+
public static void main(String[] args)
32+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
33+
// TODO(developer): Replace these variables before running the sample.
34+
// Project ID or project number of the Cloud project you want to use.
35+
String projectId = "YOUR_PROJECT_ID";
36+
// Name of the zone of your compute instance.
37+
String zone = "us-central1-a";
38+
// The name of the compute instance where you are adding the replicated disk.
39+
String instanceName = "YOUR_INSTANCE_NAME";
40+
// The region where your replicated disk is located.
41+
String region = "us-central1";
42+
// The name of the replicated disk.
43+
String diskName = "YOUR_DISK_NAME";
44+
45+
attachRegionalDiskForce(projectId, zone, instanceName, region, diskName);
46+
}
47+
48+
// Attaches a regional disk to the instance,
49+
// forcing the attachment even if other VMs are using the disk.
50+
public static Status attachRegionalDiskForce(String projectId,
51+
String zone, String instanceName, String region, String diskName)
52+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
53+
String diskLink = String.format("projects/%s/regions/%s/disks/%s",
54+
projectId, region, diskName);
55+
// Initialize client that will be used to send requests. This client only needs to be created
56+
// once, and can be reused for multiple requests.
57+
try (InstancesClient instancesClient = InstancesClient.create()) {
58+
AttachedDisk attachedDisk = AttachedDisk.newBuilder()
59+
.setSource(diskLink)
60+
.setMode(AttachedDisk.Mode.READ_WRITE.toString())
61+
.build();
62+
63+
AttachDiskInstanceRequest attachDiskRequest = AttachDiskInstanceRequest.newBuilder()
64+
.setProject(projectId)
65+
.setZone(zone)
66+
.setInstance(instanceName)
67+
.setAttachedDiskResource(attachedDisk)
68+
.setForceAttach(true) // Force the attachment
69+
.build();
70+
71+
Operation response = instancesClient.attachDiskAsync(attachDiskRequest)
72+
.get(3, TimeUnit.MINUTES);
73+
74+
if (response.hasError()) {
75+
throw new Error("Error attaching regional disk! " + response);
76+
}
77+
return response.getStatus();
78+
}
79+
}
80+
}
81+
// [END compute_instance_attach_regional_disk_force]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package compute.disks;
18+
19+
// [START compute_disk_create_secondary_regional]
20+
import com.google.cloud.compute.v1.Disk;
21+
import com.google.cloud.compute.v1.DiskAsyncReplication;
22+
import com.google.cloud.compute.v1.Operation;
23+
import com.google.cloud.compute.v1.Operation.Status;
24+
import com.google.cloud.compute.v1.RegionDisksClient;
25+
import java.io.IOException;
26+
import java.util.Arrays;
27+
import java.util.List;
28+
import java.util.concurrent.ExecutionException;
29+
import java.util.concurrent.TimeUnit;
30+
import java.util.concurrent.TimeoutException;
31+
32+
public class CreateDiskSecondaryRegional {
33+
public static void main(String[] args)
34+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
35+
// TODO(developer): Replace these variables before running the sample.
36+
// The project that contains the primary disk.
37+
String primaryProjectId = "PRIMARY_PROJECT_ID";
38+
// The project that contains the secondary disk.
39+
String secondaryProjectId = "SECONDARY_PROJECT_ID";
40+
// Name of the primary disk you want to use.
41+
String primaryDiskName = "PRIMARY_DISK_NAME";
42+
// Name of the disk you want to create.
43+
String secondaryDiskName = "SECONDARY_DISK_NAME";
44+
// Name of the region in which your primary disk is located.
45+
// Learn more about zones and regions:
46+
// https://cloud.google.com/compute/docs/disks/async-pd/about#supported_region_pairs
47+
String primaryDiskRegion = "us-central1";
48+
// Name of the region in which you want to create the secondary disk.
49+
String secondaryDiskRegion = "us-east1";
50+
// Size of the new disk in gigabytes.
51+
// Learn more about disk requirements:
52+
// https://cloud.google.com/compute/docs/disks/async-pd/configure?authuser=0#disk_requirements
53+
long diskSizeGb = 30L;
54+
// The type of the disk you want to create. This value uses the following format:
55+
// "projects/{projectId}/zones/{zone}/diskTypes/
56+
// (pd-standard|pd-ssd|pd-balanced|pd-extreme)".
57+
String diskType = String.format(
58+
"projects/%s/regions/%s/diskTypes/pd-balanced", secondaryProjectId, secondaryDiskRegion);
59+
60+
createDiskSecondaryRegional(primaryProjectId, secondaryProjectId, primaryDiskName,
61+
secondaryDiskName, primaryDiskRegion, secondaryDiskRegion, diskSizeGb, diskType);
62+
}
63+
64+
// Creates a secondary disk in a specified region.
65+
public static Status createDiskSecondaryRegional(String projectId,
66+
String secondaryProjectId, String primaryDiskName, String secondaryDiskName,
67+
String primaryDiskRegion, String secondaryDiskRegion, long diskSizeGb, String diskType)
68+
throws IOException, ExecutionException, InterruptedException, TimeoutException {
69+
List<String> replicaZones = Arrays.asList(
70+
String.format("projects/%s/zones/%s-c", secondaryProjectId, secondaryDiskRegion),
71+
String.format("projects/%s/zones/%s-b", secondaryProjectId, secondaryDiskRegion));
72+
73+
String primaryDiskSource = String.format("projects/%s/regions/%s/disks/%s",
74+
projectId, primaryDiskRegion, primaryDiskName);
75+
76+
// Initialize client that will be used to send requests. This client only needs to be created
77+
// once, and can be reused for multiple requests.
78+
try (RegionDisksClient disksClient = RegionDisksClient.create()) {
79+
DiskAsyncReplication asyncReplication = DiskAsyncReplication.newBuilder()
80+
.setDisk(primaryDiskSource)
81+
.build();
82+
83+
Disk disk = Disk.newBuilder()
84+
.addAllReplicaZones(replicaZones)
85+
.setName(secondaryDiskName)
86+
.setSizeGb(diskSizeGb)
87+
.setType(diskType)
88+
.setRegion(secondaryDiskRegion)
89+
.setAsyncPrimaryDisk(asyncReplication)
90+
.build();
91+
92+
// Wait for the create disk operation to complete.
93+
Operation response = disksClient.insertAsync(secondaryProjectId, secondaryDiskRegion, disk)
94+
.get(3, TimeUnit.MINUTES);
95+
96+
if (response.hasError()) {
97+
throw new Error("Error creating secondary disks! " + response.getError());
98+
}
99+
return response.getStatus();
100+
}
101+
}
102+
}
103+
// [END compute_disk_create_secondary_regional]

0 commit comments

Comments
 (0)