@@ -61,6 +61,8 @@ public abstract class Util {
6161 // comma separate list of zone names
6262 private static final String TEST_ZONES_NAME = "JAVA_DOCS_COMPUTE_TEST_ZONES" ;
6363 private static final String DEFAULT_ZONES = "us-central1-a,us-west1-a,asia-south1-a" ;
64+ private static final String [] zones = new String []
65+ {"us-central1-a" , "us-west1-a" , "asia-south1-a" , "us-central1-b" };
6466
6567 // Delete templates which starts with the given prefixToDelete and
6668 // has creation timestamp >24 hours.
@@ -85,20 +87,22 @@ public static void cleanUpExistingRegionalInstanceTemplates(
8587 throws IOException , ExecutionException , InterruptedException , TimeoutException {
8688 try (RegionInstanceTemplatesClient instanceTemplatesClient =
8789 RegionInstanceTemplatesClient .create ()) {
88- String region = zone .substring (0 , zone .lastIndexOf ('-' ));
89- ListRegionInstanceTemplatesRequest request =
90- ListRegionInstanceTemplatesRequest .newBuilder ()
91- .setProject (projectId )
92- .setRegion (region )
93- .build ();
90+ for (String zoneItem : zones ) {
91+ String region = zoneItem .substring (0 , zoneItem .lastIndexOf ('-' ));
92+ ListRegionInstanceTemplatesRequest request =
93+ ListRegionInstanceTemplatesRequest .newBuilder ()
94+ .setProject (projectId )
95+ .setRegion (region )
96+ .build ();
9497
95- for (InstanceTemplate instanceTemplate :
96- instanceTemplatesClient .list (request ).iterateAll ()) {
97- if (containPrefixToDeleteAndZone (instanceTemplate , prefixToDelete , zone )
98- && isCreatedBeforeThresholdTime (instanceTemplate .getCreationTimestamp ())
99- && instanceTemplate .isInitialized ()) {
100- DeleteRegionalInstanceTemplate .deleteRegionalInstanceTemplate (
101- projectId , region , instanceTemplate .getName ());
98+ for (InstanceTemplate instanceTemplate :
99+ instanceTemplatesClient .list (request ).iterateAll ()) {
100+ if (containPrefixToDeleteAndZone (instanceTemplate , prefixToDelete , zoneItem )
101+ && isCreatedBeforeThresholdTime (instanceTemplate .getCreationTimestamp ())
102+ && instanceTemplate .isInitialized ()) {
103+ DeleteRegionalInstanceTemplate .deleteRegionalInstanceTemplate (
104+ projectId , region , instanceTemplate .getName ());
105+ }
102106 }
103107 }
104108 }
@@ -107,18 +111,20 @@ && isCreatedBeforeThresholdTime(instanceTemplate.getCreationTimestamp())
107111 // Delete instances which starts with the given prefixToDelete and
108112 // has creation timestamp >24 hours.
109113 public static void cleanUpExistingInstances (String prefixToDelete , String projectId ,
110- String instanceZone )
114+ String instanceZone )
111115 throws IOException , ExecutionException , InterruptedException , TimeoutException {
112116 try (InstancesClient instancesClient = InstancesClient .create ()) {
113- for (Instance instance : instancesClient .list (projectId , instanceZone ).iterateAll ()) {
114- if (instance .getDeletionProtection ()
115- && isCreatedBeforeThresholdTime (instance .getCreationTimestamp ())) {
116- SetDeleteProtection .setDeleteProtection (
117- projectId , instanceZone , instance .getName (), false );
118- }
119- if (containPrefixToDeleteAndZone (instance , prefixToDelete , instanceZone )
120- && isCreatedBeforeThresholdTime (instance .getCreationTimestamp ())) {
121- DeleteInstance .deleteInstance (projectId , instanceZone , instance .getName ());
117+ for (String zoneItem : zones ) {
118+ for (Instance instance : instancesClient .list (projectId , zoneItem ).iterateAll ()) {
119+ if (instance .getDeletionProtection ()
120+ && isCreatedBeforeThresholdTime (instance .getCreationTimestamp ())) {
121+ SetDeleteProtection .setDeleteProtection (
122+ projectId , zoneItem , instance .getName (), false );
123+ }
124+ if (containPrefixToDeleteAndZone (instance , prefixToDelete , zoneItem )
125+ && isCreatedBeforeThresholdTime (instance .getCreationTimestamp ())) {
126+ DeleteInstance .deleteInstance (projectId , zoneItem , instance .getName ());
127+ }
122128 }
123129 }
124130 }
@@ -193,10 +199,12 @@ public static void cleanUpExistingReservations(
193199 String prefixToDelete , String projectId , String zone )
194200 throws IOException , ExecutionException , InterruptedException , TimeoutException {
195201 try (ReservationsClient reservationsClient = ReservationsClient .create ()) {
196- for (Reservation reservation : reservationsClient .list (projectId , zone ).iterateAll ()) {
197- if (containPrefixToDeleteAndZone (reservation , prefixToDelete , zone )
198- && isCreatedBeforeThresholdTime (reservation .getCreationTimestamp ())) {
199- DeleteReservation .deleteReservation (projectId , zone , reservation .getName ());
202+ for (String zoneItem : zones ) {
203+ for (Reservation reservation : reservationsClient .list (projectId , zoneItem ).iterateAll ()) {
204+ if (containPrefixToDeleteAndZone (reservation , prefixToDelete , zoneItem )
205+ && isCreatedBeforeThresholdTime (reservation .getCreationTimestamp ())) {
206+ DeleteReservation .deleteReservation (projectId , zoneItem , reservation .getName ());
207+ }
200208 }
201209 }
202210 }
@@ -208,10 +216,12 @@ public static void cleanUpExistingDisks(
208216 String prefixToDelete , String projectId , String zone )
209217 throws IOException , ExecutionException , InterruptedException , TimeoutException {
210218 try (DisksClient disksClient = DisksClient .create ()) {
211- for (Disk disk : disksClient .list (projectId , zone ).iterateAll ()) {
212- if (containPrefixToDeleteAndZone (disk , prefixToDelete , zone )
213- && isCreatedBeforeThresholdTime (disk .getCreationTimestamp ())) {
214- DeleteDisk .deleteDisk (projectId , zone , disk .getName ());
219+ for (String zoneItem : zones ) {
220+ for (Disk disk : disksClient .list (projectId , zoneItem ).iterateAll ()) {
221+ if (containPrefixToDeleteAndZone (disk , prefixToDelete , zoneItem )
222+ && isCreatedBeforeThresholdTime (disk .getCreationTimestamp ())) {
223+ DeleteDisk .deleteDisk (projectId , zoneItem , disk .getName ());
224+ }
215225 }
216226 }
217227 }
@@ -237,10 +247,12 @@ public static void cleanUpExistingStoragePool(
237247 String prefixToDelete , String projectId , String zone )
238248 throws IOException , ExecutionException , InterruptedException , TimeoutException {
239249 try (StoragePoolsClient storagePoolsClient = StoragePoolsClient .create ()) {
240- for (StoragePool storagePool : storagePoolsClient .list (projectId , zone ).iterateAll ()) {
241- if (containPrefixToDeleteAndZone (projectId , prefixToDelete , zone )
242- && isCreatedBeforeThresholdTime (storagePool .getCreationTimestamp ())) {
243- deleteStoragePool (projectId , zone , storagePool .getName ());
250+ for (String zoneItem : zones ) {
251+ for (StoragePool storagePool : storagePoolsClient .list (projectId , zoneItem ).iterateAll ()) {
252+ if (containPrefixToDeleteAndZone (projectId , prefixToDelete , zoneItem )
253+ && isCreatedBeforeThresholdTime (storagePool .getCreationTimestamp ())) {
254+ deleteStoragePool (projectId , zoneItem , storagePool .getName ());
255+ }
244256 }
245257 }
246258 }
@@ -276,7 +288,7 @@ public static boolean containPrefixToDeleteAndZone(
276288 }
277289 if (resource instanceof InstanceTemplate ) {
278290 containPrefixAndZone = ((InstanceTemplate ) resource ).getName ().contains (prefixToDelete )
279- && ((InstanceTemplate ) resource ).getRegion ()
291+ && ((InstanceTemplate ) resource ).getRegion ()
280292 .contains (zone .substring (0 , zone .lastIndexOf ('-' )));
281293 }
282294 if (resource instanceof Reservation ) {
0 commit comments