From e51d2134d9f3464dbd8f2ff42b281db7fb454938 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Mon, 4 Nov 2024 21:44:13 +0100 Subject: [PATCH 01/20] implemented compute_disk_start_replication sample --- .../compute/disks/CreateDiskSecondary.java | 74 +++++++++++++++++++ .../compute/disks/StartDiskReplication.java | 67 +++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java create mode 100644 compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java diff --git a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java new file mode 100644 index 00000000000..38278b0cec3 --- /dev/null +++ b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java @@ -0,0 +1,74 @@ +package compute.disks; + +import com.google.cloud.compute.v1.Disk; +import com.google.cloud.compute.v1.DisksClient; +import com.google.cloud.compute.v1.Operation; +import com.google.cloud.compute.v1.RegionDisksClient; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CreateDiskSecondary { + 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 = "tyaho-softserve-project";//"YOUR_PROJECT_ID"; + // Name of the zone in which you want to create the secondary disk. + String disksRegion = "us-central1"; + // Name of the disk you want to create. + String secondaryDiskName = "second-disk";//"SECONDARY_DISK_NAME"; + // Size of the new disk in gigabytes. + long diskSizeGb = 100; + // Name of the primary disk you want to use as a source for the new disk. + String primaryDiskName = "primary-disk";//"PRIMARY_DISK_NAME"; + // 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/regions/%s/diskTypes/pd-balanced", projectId, disksRegion); + String disksRegion2 = "us-east1"; + createDiskSecondaryRegional(projectId, secondaryDiskName, disksRegion, + diskSizeGb, primaryDiskName, diskType, disksRegion2); + } + + // Creates a secondary disk in a specified zone with the source disk information. + public static Disk createDiskSecondaryRegional(String projectId, String secondaryDiskName, + String disksRegion, long diskSizeGb, String primaryDiskName, String diskType, String disksRegion2) + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // An iterable collection of zone names in which you want to keep + // the new disks' replicas. One of the replica zones of the clone must match + // the zone of the source disk. + List replicaZones = Arrays.asList( + String.format("projects/%s/zones/%s-a", projectId, disksRegion2), + String.format("projects/%s/zones/%s-b", projectId, disksRegion2)); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. + try (RegionDisksClient disksClient = RegionDisksClient.create()) { + String primaryDiskSource = String.format("projects/%s/regions/%s/disks/%s", + projectId, disksRegion, primaryDiskName); + // Create the disk object with the source disk information. + Disk disk = Disk.newBuilder() + .addAllReplicaZones(replicaZones) + .setName(secondaryDiskName) + .setSizeGb(diskSizeGb) + .setType(diskType) + .setRegion(disksRegion2) + .setSourceDisk(primaryDiskSource).build(); + + // Wait for the create disk operation to complete. + Operation response = disksClient.insertAsync(projectId, disksRegion2, disk) + .get(3, TimeUnit.MINUTES); + + if (response.hasError()) { + return null; + } + return disksClient.get(projectId, disksRegion, secondaryDiskName); + } + } +} \ No newline at end of file diff --git a/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java new file mode 100644 index 00000000000..773ac08392b --- /dev/null +++ b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java @@ -0,0 +1,67 @@ +package compute.disks; + +import com.google.cloud.compute.v1.Operation; +import com.google.cloud.compute.v1.RegionDisksClient; +import com.google.cloud.compute.v1.RegionDisksStartAsyncReplicationRequest; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public class StartDiskReplication { + + public static void main(String[] args) + throws IOException, ExecutionException, InterruptedException { + // TODO(developer): Replace these variables before running the sample. + // The project that contains the primary disk. + String projectId = "tyaho-softserve-project";//"YOUR_PROJECT_ID"; + String primaryZone = "us-central1"; + String primaryDiskName = "primary-disk";//"PRIMARY_DISK_NAME"; + // Name of the zone in which you want to create the secondary disk. + String secondaryZone = "us-central1"; + // Name of the disk you want to create. + String secondaryDiskName = "second-disk";//"SECONDARY_DISK_NAME"; + + startDiskAsyncReplication( + projectId, + primaryZone, + primaryDiskName, + secondaryZone, + secondaryDiskName); + } + + // Starts asynchronous replication for the specified disk. + public static void startDiskAsyncReplication( + String projectId, + String primaryZone, + String primaryDiskName, + String secondaryZone, + String secondaryDiskName) + throws IOException, ExecutionException, InterruptedException { + try (RegionDisksClient disksClient = RegionDisksClient.create()) { + + String asyncSecondaryDisk = String.format( + "projects/%s/regions/%s/disks/%s", + projectId, + secondaryZone, + secondaryDiskName); + + RegionDisksStartAsyncReplicationRequest startAsyncReplicationRequest = + RegionDisksStartAsyncReplicationRequest.newBuilder() + .setAsyncSecondaryDisk(asyncSecondaryDisk) + .build(); + + Operation response = + disksClient.startAsyncReplicationAsync( + projectId, + primaryZone, + primaryDiskName, + startAsyncReplicationRequest).get(); + + + if (response.hasError()) { + return; + } + System.out.println("Async replication started successfully."); + } + } +} From f0d969e54768ed5b328b1f195f4076b5c9f4b49f Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Tue, 5 Nov 2024 13:41:44 +0100 Subject: [PATCH 02/20] Fixed code --- .../compute/disks/CreateDiskSecondary.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java index 38278b0cec3..7575c13cde4 100644 --- a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java +++ b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java @@ -1,10 +1,8 @@ package compute.disks; import com.google.cloud.compute.v1.Disk; -import com.google.cloud.compute.v1.DisksClient; import com.google.cloud.compute.v1.Operation; import com.google.cloud.compute.v1.RegionDisksClient; - import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -18,57 +16,60 @@ public static void main(String[] args) // TODO(developer): Replace these variables before running the sample. // The project that contains the primary disk. String projectId = "tyaho-softserve-project";//"YOUR_PROJECT_ID"; - // Name of the zone in which you want to create the secondary disk. - String disksRegion = "us-central1"; + // Name of the region in which you want to create the secondary disk. + // Learn more about zones and regions: + // https://cloud.google.com/compute/docs/disks/async-pd/about#supported_region_pairs + String primaryDiskRegion = "us-central1"; // Name of the disk you want to create. String secondaryDiskName = "second-disk";//"SECONDARY_DISK_NAME"; // Size of the new disk in gigabytes. - long diskSizeGb = 100; + // It should be less than or equal to 32 TiB. + long diskSizeGb = 30; // Name of the primary disk you want to use as a source for the new disk. - String primaryDiskName = "primary-disk";//"PRIMARY_DISK_NAME"; + String primaryDiskName = "disk-1";//"PRIMARY_DISK_NAME"; + String secondaryDiskRegion = "us-east1"; // 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/regions/%s/diskTypes/pd-balanced", projectId, disksRegion); - String disksRegion2 = "us-east1"; - createDiskSecondaryRegional(projectId, secondaryDiskName, disksRegion, - diskSizeGb, primaryDiskName, diskType, disksRegion2); + "projects/%s/regions/%s/diskTypes/pd-balanced", projectId, secondaryDiskRegion); + createDiskSecondaryRegional(projectId, secondaryDiskName, primaryDiskRegion, + diskSizeGb, primaryDiskName, diskType, secondaryDiskRegion); } // Creates a secondary disk in a specified zone with the source disk information. public static Disk createDiskSecondaryRegional(String projectId, String secondaryDiskName, - String disksRegion, long diskSizeGb, String primaryDiskName, String diskType, String disksRegion2) + String primaryDiskRegion, long diskSizeGb, String primaryDiskName, String diskType, String secondaryDiskRegion) throws IOException, ExecutionException, InterruptedException, TimeoutException { // An iterable collection of zone names in which you want to keep // the new disks' replicas. One of the replica zones of the clone must match // the zone of the source disk. List replicaZones = Arrays.asList( - String.format("projects/%s/zones/%s-a", projectId, disksRegion2), - String.format("projects/%s/zones/%s-b", projectId, disksRegion2)); + String.format("projects/%s/zones/%s-c", projectId, secondaryDiskRegion), + String.format("projects/%s/zones/%s-b", projectId, secondaryDiskRegion)); // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. try (RegionDisksClient disksClient = RegionDisksClient.create()) { String primaryDiskSource = String.format("projects/%s/regions/%s/disks/%s", - projectId, disksRegion, primaryDiskName); + projectId, primaryDiskRegion, primaryDiskName); // Create the disk object with the source disk information. Disk disk = Disk.newBuilder() .addAllReplicaZones(replicaZones) .setName(secondaryDiskName) .setSizeGb(diskSizeGb) .setType(diskType) - .setRegion(disksRegion2) + .setRegion(secondaryDiskRegion) .setSourceDisk(primaryDiskSource).build(); // Wait for the create disk operation to complete. - Operation response = disksClient.insertAsync(projectId, disksRegion2, disk) + Operation response = disksClient.insertAsync(projectId, secondaryDiskRegion, disk) .get(3, TimeUnit.MINUTES); if (response.hasError()) { return null; } - return disksClient.get(projectId, disksRegion, secondaryDiskName); + return disksClient.get(projectId, primaryDiskRegion, secondaryDiskName); } } } \ No newline at end of file From 73ecc63f115492a2adea56f5806f8a5eaa70f0d0 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Tue, 5 Nov 2024 21:45:30 +0100 Subject: [PATCH 03/20] Implemented compute_disk_start_replication and compute_disk_stop_replication samples --- .../compute/disks/CreateDiskSecondary.java | 75 ------------------- .../compute/disks/StartDiskReplication.java | 73 ++++++++++-------- .../disks/StopDiskAsyncReplication.java | 56 ++++++++++++++ 3 files changed, 96 insertions(+), 108 deletions(-) delete mode 100644 compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java create mode 100644 compute/cloud-client/src/main/java/compute/disks/StopDiskAsyncReplication.java diff --git a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java deleted file mode 100644 index 7575c13cde4..00000000000 --- a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondary.java +++ /dev/null @@ -1,75 +0,0 @@ -package compute.disks; - -import com.google.cloud.compute.v1.Disk; -import com.google.cloud.compute.v1.Operation; -import com.google.cloud.compute.v1.RegionDisksClient; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -public class CreateDiskSecondary { - 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 = "tyaho-softserve-project";//"YOUR_PROJECT_ID"; - // Name of the region in which you want to create the secondary disk. - // Learn more about zones and regions: - // https://cloud.google.com/compute/docs/disks/async-pd/about#supported_region_pairs - String primaryDiskRegion = "us-central1"; - // Name of the disk you want to create. - String secondaryDiskName = "second-disk";//"SECONDARY_DISK_NAME"; - // Size of the new disk in gigabytes. - // It should be less than or equal to 32 TiB. - long diskSizeGb = 30; - // Name of the primary disk you want to use as a source for the new disk. - String primaryDiskName = "disk-1";//"PRIMARY_DISK_NAME"; - String secondaryDiskRegion = "us-east1"; - // 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/regions/%s/diskTypes/pd-balanced", projectId, secondaryDiskRegion); - createDiskSecondaryRegional(projectId, secondaryDiskName, primaryDiskRegion, - diskSizeGb, primaryDiskName, diskType, secondaryDiskRegion); - } - - // Creates a secondary disk in a specified zone with the source disk information. - public static Disk createDiskSecondaryRegional(String projectId, String secondaryDiskName, - String primaryDiskRegion, long diskSizeGb, String primaryDiskName, String diskType, String secondaryDiskRegion) - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // An iterable collection of zone names in which you want to keep - // the new disks' replicas. One of the replica zones of the clone must match - // the zone of the source disk. - List replicaZones = Arrays.asList( - String.format("projects/%s/zones/%s-c", projectId, secondaryDiskRegion), - String.format("projects/%s/zones/%s-b", projectId, secondaryDiskRegion)); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. - try (RegionDisksClient disksClient = RegionDisksClient.create()) { - String primaryDiskSource = String.format("projects/%s/regions/%s/disks/%s", - projectId, primaryDiskRegion, primaryDiskName); - // Create the disk object with the source disk information. - Disk disk = Disk.newBuilder() - .addAllReplicaZones(replicaZones) - .setName(secondaryDiskName) - .setSizeGb(diskSizeGb) - .setType(diskType) - .setRegion(secondaryDiskRegion) - .setSourceDisk(primaryDiskSource).build(); - - // Wait for the create disk operation to complete. - Operation response = disksClient.insertAsync(projectId, secondaryDiskRegion, disk) - .get(3, TimeUnit.MINUTES); - - if (response.hasError()) { - return null; - } - return disksClient.get(projectId, primaryDiskRegion, secondaryDiskName); - } - } -} \ No newline at end of file diff --git a/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java index 773ac08392b..0d6b3e3a606 100644 --- a/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java +++ b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java @@ -1,9 +1,25 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package compute.disks; +// [START compute_disk_start_replication] import com.google.cloud.compute.v1.Operation; import com.google.cloud.compute.v1.RegionDisksClient; import com.google.cloud.compute.v1.RegionDisksStartAsyncReplicationRequest; - import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -13,50 +29,40 @@ public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. // The project that contains the primary disk. - String projectId = "tyaho-softserve-project";//"YOUR_PROJECT_ID"; - String primaryZone = "us-central1"; - String primaryDiskName = "primary-disk";//"PRIMARY_DISK_NAME"; - // Name of the zone in which you want to create the secondary disk. - String secondaryZone = "us-central1"; - // Name of the disk you want to create. - String secondaryDiskName = "second-disk";//"SECONDARY_DISK_NAME"; + String projectId = "YOUR_PROJECT_ID"; + // Name of the primary disk. + String primaryDiskName = "PRIMARY_DISK_NAME"; + // Name of the secondary disk. + String secondaryDiskName = "SECONDARY_DISK_NAME"; + // Name of the zone in which your primary disk is located. + // Learn more about zones and regions: + // https://cloud.google.com/compute/docs/disks/async-pd/about#supported_region_pairs + String primaryDiskRegion = "us-central1"; + // Name of the zone in which your secondary disk is located. + String secondaryDiskRegion = "us-east1"; - startDiskAsyncReplication( - projectId, - primaryZone, - primaryDiskName, - secondaryZone, - secondaryDiskName); + startDiskAsyncReplication(projectId, primaryDiskRegion, + primaryDiskName, secondaryDiskRegion, secondaryDiskName); } // Starts asynchronous replication for the specified disk. - public static void startDiskAsyncReplication( - String projectId, - String primaryZone, - String primaryDiskName, - String secondaryZone, - String secondaryDiskName) + public static void startDiskAsyncReplication(String projectId, String primaryDiskRegion, + String primaryDiskName, String secondaryDiskRegion, String secondaryDiskName) throws IOException, ExecutionException, InterruptedException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. try (RegionDisksClient disksClient = RegionDisksClient.create()) { - String asyncSecondaryDisk = String.format( - "projects/%s/regions/%s/disks/%s", - projectId, - secondaryZone, - secondaryDiskName); + String asyncSecondaryDiskPath = String.format("projects/%s/regions/%s/disks/%s", + projectId, secondaryDiskRegion, secondaryDiskName); RegionDisksStartAsyncReplicationRequest startAsyncReplicationRequest = RegionDisksStartAsyncReplicationRequest.newBuilder() - .setAsyncSecondaryDisk(asyncSecondaryDisk) + .setAsyncSecondaryDisk(asyncSecondaryDiskPath) .build(); - Operation response = - disksClient.startAsyncReplicationAsync( - projectId, - primaryZone, - primaryDiskName, - startAsyncReplicationRequest).get(); - + Operation response = disksClient.startAsyncReplicationAsync( + projectId, primaryDiskRegion, primaryDiskName, startAsyncReplicationRequest).get(); if (response.hasError()) { return; @@ -65,3 +71,4 @@ public static void startDiskAsyncReplication( } } } +// [END compute_disk_start_replication] diff --git a/compute/cloud-client/src/main/java/compute/disks/StopDiskAsyncReplication.java b/compute/cloud-client/src/main/java/compute/disks/StopDiskAsyncReplication.java new file mode 100644 index 00000000000..bde8d502c64 --- /dev/null +++ b/compute/cloud-client/src/main/java/compute/disks/StopDiskAsyncReplication.java @@ -0,0 +1,56 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package compute.disks; + +// [START compute_disk_stop_replication] +import com.google.cloud.compute.v1.Operation; +import com.google.cloud.compute.v1.RegionDisksClient; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +public class StopDiskAsyncReplication { + + public static void main(String[] args) + throws IOException, ExecutionException, InterruptedException { + // TODO(developer): Replace these variables before running the sample. + // The project that contains the primary disk. + String projectId = "YOUR_PROJECT_ID"; + // Name of the zone in which your secondary disk is located. + String secondaryDiskRegion = "us-east1"; + // Name of the secondary disk. + String secondaryDiskName = "SECONDARY_DISK_NAME"; + stopDiskAsyncReplication(projectId, secondaryDiskRegion, secondaryDiskName); + } + + // Stops asynchronous replication for the specified disk. + public static void stopDiskAsyncReplication( + String project, String secondaryDiskRegion, String secondaryDiskName) + throws IOException, ExecutionException, InterruptedException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. + try (RegionDisksClient disksClient = RegionDisksClient.create()) { + Operation response = disksClient.stopAsyncReplicationAsync( + project, secondaryDiskRegion, secondaryDiskName).get(); + + if (response.hasError()) { + return; + } + System.out.println("Async replication stopped successfully."); + } + } +} +// [END compute_disk_stop_replication] \ No newline at end of file From 49bc4b1d58039947d16f64ab7a150cd0ec30d752 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Wed, 6 Nov 2024 09:28:53 +0100 Subject: [PATCH 04/20] Created test --- .../java/compute/disks/DiskReplicationIT.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java diff --git a/compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java b/compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java new file mode 100644 index 00000000000..57ba4a31926 --- /dev/null +++ b/compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java @@ -0,0 +1,89 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package compute.disks; + +import com.google.cloud.compute.v1.Disk; +import com.google.cloud.compute.v1.RegionDisksClient; +import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Timeout; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.IOException; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; + +@RunWith(JUnit4.class) +@Timeout(value = 3, unit = TimeUnit.MINUTES) +public class DiskReplicationIT { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); + private static final String ZONE = "us-central1-a"; + private static final String REGION = "us-central1"; + private static final String DISK_TYPE = + String.format("projects/%s/zones/%s/diskTypes/pd-standard", PROJECT_ID, ZONE); + private static String PRIMARY_DISK_NAME; + private static String SECONDARY_DISK_NAME; + + // Check if the required environment variables are set. + public static void requireEnvVar(String envVarName) { + assertWithMessage(String.format("Missing environment variable '%s' ", envVarName)) + .that(System.getenv(envVarName)).isNotEmpty(); + } + + @BeforeAll + public static void setUp() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("GOOGLE_CLOUD_PROJECT"); + + PRIMARY_DISK_NAME = "test-disk-" + UUID.randomUUID().toString().substring(0, 8); + SECONDARY_DISK_NAME = "test-disk-" + UUID.randomUUID().toString().substring(0, 8); + // Create a primary disk to replicate from. + CreateEmptyDisk.createEmptyDisk(PROJECT_ID, ZONE, PRIMARY_DISK_NAME, DISK_TYPE, 1L); + } + + @AfterAll + public static void cleanup() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // Delete disks created for testing. + DeleteDisk.deleteDisk(PROJECT_ID, REGION, SECONDARY_DISK_NAME); + DeleteDisk.deleteDisk(PROJECT_ID, ZONE, PRIMARY_DISK_NAME); + } + + @Test + public void testStartDiskAsyncReplication() + throws IOException, ExecutionException, InterruptedException { + StartDiskReplication.startDiskAsyncReplication(PROJECT_ID, REGION, PRIMARY_DISK_NAME, REGION, + SECONDARY_DISK_NAME); + + // Assert that the secondary disk is now replicating from the primary disk. + try (RegionDisksClient regionDisksClient = RegionDisksClient.create()) { + Disk disk = regionDisksClient.get(PROJECT_ID, REGION, SECONDARY_DISK_NAME); + assertThat(disk.getAsyncPrimaryDisk()).isNotNull(); + assertThat(disk.getAsyncPrimaryDisk().getDisk()) + .isEqualTo(String.format("projects/%s/regions/%s/disks/%s", PROJECT_ID, REGION, + PRIMARY_DISK_NAME)); + } + } +} From 400f8ccdf154290d4687ff95a84686a056648127 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Wed, 6 Nov 2024 18:01:29 +0100 Subject: [PATCH 05/20] Created tests --- .../disks/CreateDiskSecondaryRegional.java | 104 +++++++++++++++++ .../compute/disks/StartDiskReplication.java | 16 +-- ...lication.java => StopDiskReplication.java} | 4 +- .../java/compute/disks/DiskReplicationIT.java | 110 ++++++++++++------ 4 files changed, 187 insertions(+), 47 deletions(-) create mode 100644 compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryRegional.java rename compute/cloud-client/src/main/java/compute/disks/{StopDiskAsyncReplication.java => StopDiskReplication.java} (95%) diff --git a/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryRegional.java b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryRegional.java new file mode 100644 index 00000000000..a71d70b827b --- /dev/null +++ b/compute/cloud-client/src/main/java/compute/disks/CreateDiskSecondaryRegional.java @@ -0,0 +1,104 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package compute.disks; + +// [START compute_disk_create_secondary_regional] +import com.google.cloud.compute.v1.Disk; +import com.google.cloud.compute.v1.DiskAsyncReplication; +import com.google.cloud.compute.v1.Operation; +import com.google.cloud.compute.v1.RegionDisksClient; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CreateDiskSecondaryRegional { + 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"; + // Name of the primary disk you want to use. + String primaryDiskName = "PRIMARY_DISK_NAME"; + // Name of the disk you want to create. + String secondaryDiskName = "SECONDARY_DISK_NAME"; + // Name of the region in which your primary disk is located. + // Learn more about zones and regions: + // https://cloud.google.com/compute/docs/disks/async-pd/about#supported_region_pairs + String primaryDiskRegion = "us-central1"; + // Name of the region in which you want to create the secondary disk. + String secondaryDiskRegion = "us-east1"; + // Size of the new disk in gigabytes. + // Learn more about disk requirements: + // https://cloud.google.com/compute/docs/disks/async-pd/configure?authuser=0#disk_requirements + 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/regions/%s/diskTypes/pd-balanced", projectId, secondaryDiskRegion); + + createDiskSecondaryRegional(projectId, primaryDiskName, secondaryDiskName, + primaryDiskRegion, secondaryDiskRegion, diskSizeGb, diskType); + } + + // Creates a secondary disk in a specified region. + public static Disk createDiskSecondaryRegional(String projectId, String primaryDiskName, + String primaryDiskRegion, String secondaryDiskName, String secondaryDiskRegion, + long diskSizeGb, String diskType) + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // An iterable collection of zone names in which you want to keep + // the new disks' replicas. One of the replica zones of the clone must match + // the zone of the source disk. + List replicaZones = Arrays.asList( + String.format("projects/%s/zones/%s-c", projectId, secondaryDiskRegion), + String.format("projects/%s/zones/%s-b", projectId, secondaryDiskRegion)); + + String primaryDiskSource = String.format("projects/%s/regions/%s/disks/%s", + projectId, primaryDiskRegion, primaryDiskName); + + DiskAsyncReplication asyncReplication = DiskAsyncReplication.newBuilder() + .setDisk(primaryDiskSource) + .build(); + + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. + try (RegionDisksClient disksClient = RegionDisksClient.create()) { + + Disk disk = Disk.newBuilder() + .addAllReplicaZones(replicaZones) + .setName(secondaryDiskName) + .setSizeGb(diskSizeGb) + .setType(diskType) + .setRegion(secondaryDiskRegion) + .setAsyncPrimaryDisk(asyncReplication) + .build(); + + // Wait for the create disk operation to complete. + Operation response = disksClient.insertAsync(projectId, secondaryDiskRegion, disk) + .get(3, TimeUnit.MINUTES); + + if (response.hasError()) { + return null; + } + return disksClient.get(projectId, secondaryDiskRegion, secondaryDiskName); + } + } +} +// [END compute_disk_create_secondary_regional] diff --git a/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java index 0d6b3e3a606..3de847820ba 100644 --- a/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java +++ b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java @@ -34,20 +34,20 @@ public static void main(String[] args) String primaryDiskName = "PRIMARY_DISK_NAME"; // Name of the secondary disk. String secondaryDiskName = "SECONDARY_DISK_NAME"; - // Name of the zone in which your primary disk is located. + // Name of the region in which your primary disk is located. // Learn more about zones and regions: // https://cloud.google.com/compute/docs/disks/async-pd/about#supported_region_pairs - String primaryDiskRegion = "us-central1"; - // Name of the zone in which your secondary disk is located. - String secondaryDiskRegion = "us-east1"; + String primaryDiskRegion = "us-central1-a"; + // Name of the region in which your secondary disk is located. + String secondaryDiskRegion = "us-east1-c"; - startDiskAsyncReplication(projectId, primaryDiskRegion, - primaryDiskName, secondaryDiskRegion, secondaryDiskName); + startDiskAsyncReplication(projectId, primaryDiskName, primaryDiskRegion, + secondaryDiskName, secondaryDiskRegion); } // Starts asynchronous replication for the specified disk. - public static void startDiskAsyncReplication(String projectId, String primaryDiskRegion, - String primaryDiskName, String secondaryDiskRegion, String secondaryDiskName) + public static void startDiskAsyncReplication(String projectId, String primaryDiskName, + String primaryDiskRegion, String secondaryDiskName, String secondaryDiskRegion) throws IOException, ExecutionException, InterruptedException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. diff --git a/compute/cloud-client/src/main/java/compute/disks/StopDiskAsyncReplication.java b/compute/cloud-client/src/main/java/compute/disks/StopDiskReplication.java similarity index 95% rename from compute/cloud-client/src/main/java/compute/disks/StopDiskAsyncReplication.java rename to compute/cloud-client/src/main/java/compute/disks/StopDiskReplication.java index bde8d502c64..b7bd1553623 100644 --- a/compute/cloud-client/src/main/java/compute/disks/StopDiskAsyncReplication.java +++ b/compute/cloud-client/src/main/java/compute/disks/StopDiskReplication.java @@ -22,14 +22,14 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -public class StopDiskAsyncReplication { +public class StopDiskReplication { public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { // TODO(developer): Replace these variables before running the sample. // The project that contains the primary disk. String projectId = "YOUR_PROJECT_ID"; - // Name of the zone in which your secondary disk is located. + // Name of the region in which your secondary disk is located. String secondaryDiskRegion = "us-east1"; // Name of the secondary disk. String secondaryDiskName = "SECONDARY_DISK_NAME"; diff --git a/compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java b/compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java index 57ba4a31926..8c6c76aae06 100644 --- a/compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/DiskReplicationIT.java @@ -16,34 +16,47 @@ package compute.disks; -import com.google.cloud.compute.v1.Disk; -import com.google.cloud.compute.v1.RegionDisksClient; -import org.junit.Test; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Timeout; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; +import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.PrintStream; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - -import static com.google.common.truth.Truth.assertThat; -import static com.google.common.truth.Truth.assertWithMessage; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.Timeout; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; @RunWith(JUnit4.class) @Timeout(value = 3, unit = TimeUnit.MINUTES) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class DiskReplicationIT { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String ZONE = "us-central1-a"; - private static final String REGION = "us-central1"; - private static final String DISK_TYPE = - String.format("projects/%s/zones/%s/diskTypes/pd-standard", PROJECT_ID, ZONE); - private static String PRIMARY_DISK_NAME; - private static String SECONDARY_DISK_NAME; + private static final String PRIMARY_REGION = "us-central1"; + private static final String SECONDARY_REGION = "us-east1"; + private static final String DISK_TYPE = String.format( + "projects/%s/regions/%s/diskTypes/pd-balanced", PROJECT_ID, SECONDARY_REGION); + private static final List replicaZones = Arrays.asList( + String.format("projects/%s/zones/%s-c", PROJECT_ID, PRIMARY_REGION), + String.format("projects/%s/zones/%s-b", PROJECT_ID, PRIMARY_REGION)); + static String templateUUID = UUID.randomUUID().toString().substring(0, 8); + private static final String PRIMARY_DISK_NAME = "test-disk-primary-" + templateUUID; + private static final String SECONDARY_DISK_NAME = "test-disk-secondary-" + templateUUID; + private static ByteArrayOutputStream stdOut; // Check if the required environment variables are set. public static void requireEnvVar(String envVarName) { @@ -57,33 +70,56 @@ public static void setUp() requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); requireEnvVar("GOOGLE_CLOUD_PROJECT"); - PRIMARY_DISK_NAME = "test-disk-" + UUID.randomUUID().toString().substring(0, 8); - SECONDARY_DISK_NAME = "test-disk-" + UUID.randomUUID().toString().substring(0, 8); // Create a primary disk to replicate from. - CreateEmptyDisk.createEmptyDisk(PROJECT_ID, ZONE, PRIMARY_DISK_NAME, DISK_TYPE, 1L); + RegionalCreateFromSource.createRegionalDisk(PROJECT_ID, PRIMARY_REGION, replicaZones, + PRIMARY_DISK_NAME, DISK_TYPE, 10, + Optional.empty(), Optional.empty()); + TimeUnit.SECONDS.sleep(10); + CreateDiskSecondaryRegional.createDiskSecondaryRegional(PROJECT_ID, PRIMARY_DISK_NAME, + PRIMARY_REGION, SECONDARY_DISK_NAME, SECONDARY_REGION, 10L, DISK_TYPE); + TimeUnit.SECONDS.sleep(10); } - @AfterAll - public static void cleanup() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // Delete disks created for testing. - DeleteDisk.deleteDisk(PROJECT_ID, REGION, SECONDARY_DISK_NAME); - DeleteDisk.deleteDisk(PROJECT_ID, ZONE, PRIMARY_DISK_NAME); + @BeforeEach + public void beforeEach() { + stdOut = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stdOut)); + } + + @AfterEach + public void afterEach() { + stdOut = null; + System.setOut(null); } @Test + @Order(1) public void testStartDiskAsyncReplication() throws IOException, ExecutionException, InterruptedException { - StartDiskReplication.startDiskAsyncReplication(PROJECT_ID, REGION, PRIMARY_DISK_NAME, REGION, - SECONDARY_DISK_NAME); - - // Assert that the secondary disk is now replicating from the primary disk. - try (RegionDisksClient regionDisksClient = RegionDisksClient.create()) { - Disk disk = regionDisksClient.get(PROJECT_ID, REGION, SECONDARY_DISK_NAME); - assertThat(disk.getAsyncPrimaryDisk()).isNotNull(); - assertThat(disk.getAsyncPrimaryDisk().getDisk()) - .isEqualTo(String.format("projects/%s/regions/%s/disks/%s", PROJECT_ID, REGION, - PRIMARY_DISK_NAME)); - } + StartDiskReplication.startDiskAsyncReplication(PROJECT_ID, PRIMARY_DISK_NAME, + PRIMARY_REGION, SECONDARY_DISK_NAME, SECONDARY_REGION); + + assertThat(stdOut.toString().contains("Async replication started successfully.")); + } + + @Test + @Order(2) + public void testStopPrimaryDiskAsyncReplication() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + StopDiskReplication.stopDiskAsyncReplication(PROJECT_ID, PRIMARY_REGION, PRIMARY_DISK_NAME); + + assertThat(stdOut.toString().contains("Async replication stopped successfully.")); + + RegionalDelete.deleteRegionalDisk(PROJECT_ID, PRIMARY_REGION, PRIMARY_DISK_NAME); + } + + @Test + @Order(2) + public void testStopSecondaryDiskAsyncReplication() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + StopDiskReplication.stopDiskAsyncReplication(PROJECT_ID, SECONDARY_REGION, SECONDARY_DISK_NAME); + + assertThat(stdOut.toString().contains("Async replication stopped successfully.")); + RegionalDelete.deleteRegionalDisk(PROJECT_ID, SECONDARY_REGION, SECONDARY_DISK_NAME); } } From 11379e75820845c481aebb1b514094b6c7f13e12 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Thu, 7 Nov 2024 15:12:44 +0100 Subject: [PATCH 06/20] Fixed region --- .../src/main/java/compute/disks/StartDiskReplication.java | 4 ++-- .../src/test/java/compute/disks/HyperdisksIT.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java index 3de847820ba..58e63d6a40a 100644 --- a/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java +++ b/compute/cloud-client/src/main/java/compute/disks/StartDiskReplication.java @@ -37,9 +37,9 @@ public static void main(String[] args) // Name of the region in which your primary disk is located. // Learn more about zones and regions: // https://cloud.google.com/compute/docs/disks/async-pd/about#supported_region_pairs - String primaryDiskRegion = "us-central1-a"; + String primaryDiskRegion = "us-central1"; // Name of the region in which your secondary disk is located. - String secondaryDiskRegion = "us-east1-c"; + String secondaryDiskRegion = "us-east1"; startDiskAsyncReplication(projectId, primaryDiskName, primaryDiskRegion, secondaryDiskName, secondaryDiskRegion); diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 1ec9e09aff6..2b04c61e4dc 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -72,6 +72,8 @@ public static void cleanup() DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME); Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME); + Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, ZONE); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); } @Test From 3e9aaa4ea70b147fb3b414c50167661878970d1e Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Thu, 7 Nov 2024 16:20:10 +0100 Subject: [PATCH 07/20] Fixed region --- .../src/test/java/compute/disks/HyperdisksIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 2b04c61e4dc..f8394f13909 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -62,6 +62,8 @@ public static void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException { requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); requireEnvVar("GOOGLE_CLOUD_PROJECT"); + Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, ZONE); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); } @AfterAll @@ -72,8 +74,6 @@ public static void cleanup() DeleteDisk.deleteDisk(PROJECT_ID, ZONE, HYPERDISK_IN_POOL_NAME); Util.deleteStoragePool(PROJECT_ID, ZONE, STORAGE_POOL_NAME); - Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, ZONE); - Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); } @Test From 40088ec512e4a2578ee78d553eb30568a5634987 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Thu, 7 Nov 2024 16:48:12 +0100 Subject: [PATCH 08/20] Fixed region --- compute/cloud-client/src/test/java/compute/Util.java | 2 +- .../src/test/java/compute/disks/HyperdisksIT.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/compute/cloud-client/src/test/java/compute/Util.java b/compute/cloud-client/src/test/java/compute/Util.java index 5c89de8faa8..dc181bfc16e 100644 --- a/compute/cloud-client/src/test/java/compute/Util.java +++ b/compute/cloud-client/src/test/java/compute/Util.java @@ -57,7 +57,7 @@ public abstract class Util { // resources // and delete the listed resources based on the timestamp. - private static final int DELETION_THRESHOLD_TIME_MINUTES = 30; + private static final int DELETION_THRESHOLD_TIME_MINUTES = 15; // comma separate list of zone names private static final String TEST_ZONES_NAME = "JAVA_DOCS_COMPUTE_TEST_ZONES"; private static final String DEFAULT_ZONES = "us-central1-a,us-west1-a,asia-south1-a"; diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index f8394f13909..306bcaddb2e 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -63,7 +63,11 @@ public static void setUp() requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, ZONE); + Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, "us-west1-a"); + Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, "asia-south1-a"); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-west1-a"); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "asia-south1-a"); } @AfterAll From 7b9b41f915321b5524b79a8e17f6467a3665dce5 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Thu, 7 Nov 2024 17:15:16 +0100 Subject: [PATCH 09/20] Fixed region --- .../src/test/java/compute/disks/HyperdisksIT.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 306bcaddb2e..2e8e2af63bf 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -44,7 +44,7 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HyperdisksIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String ZONE = "us-central1-a"; + private static final String ZONE = "us-west1-a"; private static final String HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID(); @@ -63,11 +63,7 @@ public static void setUp() requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, ZONE); - Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, "us-west1-a"); - Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, "asia-south1-a"); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); - Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-west1-a"); - Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "asia-south1-a"); } @AfterAll From e146528d4bf2e15674d99a0c91df6d648ed8e032 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Thu, 7 Nov 2024 19:46:51 +0100 Subject: [PATCH 10/20] Changed zone for HyperdisksIT --- .../cloud-client/src/test/java/compute/disks/HyperdisksIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 2e8e2af63bf..f8394f13909 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -44,7 +44,7 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HyperdisksIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String ZONE = "us-west1-a"; + private static final String ZONE = "us-central1-a"; private static final String HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID(); From 49984773b66ee09ef955ee11be9202f7d49b1d08 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Thu, 7 Nov 2024 22:15:30 +0100 Subject: [PATCH 11/20] Added cleanup methods --- .../cloud-client/src/test/java/compute/disks/HyperdisksIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index f8394f13909..027b2a4c480 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -64,6 +64,8 @@ public static void setUp() requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); + Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, "us-west1-a"); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-west1-a"); } @AfterAll From 8258333d36d824ce38fc7a8f04c1b72cf99050ba Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sat, 9 Nov 2024 12:22:25 +0100 Subject: [PATCH 12/20] Fixed code --- .../src/test/java/compute/disks/HyperdisksIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 027b2a4c480..f0e80ed8d95 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -62,9 +62,9 @@ public static void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException { requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); requireEnvVar("GOOGLE_CLOUD_PROJECT"); - Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, ZONE); + Util.cleanUpExistingStoragePool("ttest-storage-pool-enc-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); - Util.cleanUpExistingStoragePool("test-storage-", PROJECT_ID, "us-west1-a"); + Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "us-west1-a"); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-west1-a"); } From f3d7bd95b7d2b841b04b6877f8bd586b40ee3807 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sat, 9 Nov 2024 12:49:54 +0100 Subject: [PATCH 13/20] Fixed code --- .../src/test/java/compute/disks/HyperdisksIT.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index f0e80ed8d95..f066203294f 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -44,7 +44,7 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HyperdisksIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String ZONE = "us-central1-a"; + private static final String ZONE = "us-west1-a"; private static final String HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID(); @@ -64,8 +64,6 @@ public static void setUp() requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("ttest-storage-pool-enc-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); - Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "us-west1-a"); - Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-west1-a"); } @AfterAll From bf0b05d851d3b14075c30478e600db4de5994c21 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sat, 9 Nov 2024 12:51:19 +0100 Subject: [PATCH 14/20] Fixed code --- compute/cloud-client/src/test/java/compute/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compute/cloud-client/src/test/java/compute/Util.java b/compute/cloud-client/src/test/java/compute/Util.java index dc181bfc16e..5c89de8faa8 100644 --- a/compute/cloud-client/src/test/java/compute/Util.java +++ b/compute/cloud-client/src/test/java/compute/Util.java @@ -57,7 +57,7 @@ public abstract class Util { // resources // and delete the listed resources based on the timestamp. - private static final int DELETION_THRESHOLD_TIME_MINUTES = 15; + private static final int DELETION_THRESHOLD_TIME_MINUTES = 30; // comma separate list of zone names private static final String TEST_ZONES_NAME = "JAVA_DOCS_COMPUTE_TEST_ZONES"; private static final String DEFAULT_ZONES = "us-central1-a,us-west1-a,asia-south1-a"; From 63ee179344bfb6521df8acf9e796485fc8f1c8a3 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sun, 10 Nov 2024 14:05:01 +0100 Subject: [PATCH 15/20] Fixed code --- .../cloud-client/src/test/java/compute/disks/HyperdisksIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index f066203294f..3f598b37f71 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -62,7 +62,7 @@ public static void setUp() throws IOException, ExecutionException, InterruptedException, TimeoutException { requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); requireEnvVar("GOOGLE_CLOUD_PROJECT"); - Util.cleanUpExistingStoragePool("ttest-storage-pool-enc-", PROJECT_ID, ZONE); + Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); } From 6f7e127ff403af19d8691aca53d63128ecdc38f3 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sun, 10 Nov 2024 14:05:36 +0100 Subject: [PATCH 16/20] Fixed code --- .../cloud-client/src/test/java/compute/disks/HyperdisksIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 3f598b37f71..baec13797c1 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -64,6 +64,8 @@ public static void setUp() requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); + Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "ua-central1-a"); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "ua-central1-a"); } @AfterAll From 29452e66f4ae3217e0f24890f280ad208254e310 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sun, 10 Nov 2024 14:59:17 +0100 Subject: [PATCH 17/20] Fixed code --- .../src/test/java/compute/disks/HyperdisksIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index baec13797c1..3826ff5a394 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -64,8 +64,8 @@ public static void setUp() requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); - Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "ua-central1-a"); - Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "ua-central1-a"); + Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "us-central1-a"); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-central1-a"); } @AfterAll From 998a6d163b90d10f1f1c7dda129905fd96f90f92 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sun, 10 Nov 2024 15:34:08 +0100 Subject: [PATCH 18/20] Fixed code --- .../src/test/java/compute/disks/HyperdisksIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 3826ff5a394..9592a6e4ce4 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -44,7 +44,7 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HyperdisksIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String ZONE = "us-west1-a"; + private static final String ZONE = "us-central1-a"; private static final String HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID(); @@ -64,8 +64,8 @@ public static void setUp() requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); - Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "us-central1-a"); - Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-central1-a"); + Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "us-west1-a"); + Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-west1-a"); } @AfterAll From 109dafa60e50a6142537cec614c82bbcf64e5751 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sun, 10 Nov 2024 16:34:41 +0100 Subject: [PATCH 19/20] Fixed code --- .../src/test/java/compute/disks/HyperdisksIT.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 9592a6e4ce4..08ce176f56e 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -44,7 +44,7 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HyperdisksIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String ZONE = "us-central1-a"; + private static final String ZONE = "us-central1-b"; private static final String HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String HYPERDISK_IN_POOL_NAME = "test-hyperdisk-enc-" + UUID.randomUUID(); private static final String STORAGE_POOL_NAME = "test-storage-pool-enc-" + UUID.randomUUID(); @@ -64,8 +64,6 @@ public static void setUp() requireEnvVar("GOOGLE_CLOUD_PROJECT"); Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, ZONE); Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, ZONE); - Util.cleanUpExistingStoragePool("test-storage-pool-enc-", PROJECT_ID, "us-west1-a"); - Util.cleanUpExistingDisks("test-hyperdisk-enc-", PROJECT_ID, "us-west1-a"); } @AfterAll From e71858a0c8447708592f9708f8795ae17bf84c33 Mon Sep 17 00:00:00 2001 From: Tetiana Yahodska Date: Sun, 10 Nov 2024 17:06:17 +0100 Subject: [PATCH 20/20] Fixed code --- .../cloud-client/src/test/java/compute/disks/HyperdisksIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java index 08ce176f56e..2f774a8fd4d 100644 --- a/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java +++ b/compute/cloud-client/src/test/java/compute/disks/HyperdisksIT.java @@ -43,6 +43,7 @@ @Timeout(value = 6, unit = TimeUnit.MINUTES) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HyperdisksIT { + private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String ZONE = "us-central1-b"; private static final String HYPERDISK_NAME = "test-hyperdisk-enc-" + UUID.randomUUID();