@@ -61,8 +61,6 @@ 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" };
6664
6765 // Delete templates which starts with the given prefixToDelete and
6866 // has creation timestamp >24 hours.
@@ -87,22 +85,20 @@ public static void cleanUpExistingRegionalInstanceTemplates(
8785 throws IOException , ExecutionException , InterruptedException , TimeoutException {
8886 try (RegionInstanceTemplatesClient instanceTemplatesClient =
8987 RegionInstanceTemplatesClient .create ()) {
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 ();
88+ String region = zone .substring (0 , zone .lastIndexOf ('-' ));
89+ ListRegionInstanceTemplatesRequest request =
90+ ListRegionInstanceTemplatesRequest .newBuilder ()
91+ .setProject (projectId )
92+ .setRegion (region )
93+ .build ();
9794
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- }
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 ());
106102 }
107103 }
108104 }
@@ -114,17 +110,15 @@ public static void cleanUpExistingInstances(String prefixToDelete, String projec
114110 String instanceZone )
115111 throws IOException , ExecutionException , InterruptedException , TimeoutException {
116112 try (InstancesClient instancesClient = InstancesClient .create ()) {
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- }
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 ());
128122 }
129123 }
130124 }
@@ -199,12 +193,10 @@ public static void cleanUpExistingReservations(
199193 String prefixToDelete , String projectId , String zone )
200194 throws IOException , ExecutionException , InterruptedException , TimeoutException {
201195 try (ReservationsClient reservationsClient = ReservationsClient .create ()) {
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- }
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 ());
208200 }
209201 }
210202 }
@@ -216,12 +208,10 @@ public static void cleanUpExistingDisks(
216208 String prefixToDelete , String projectId , String zone )
217209 throws IOException , ExecutionException , InterruptedException , TimeoutException {
218210 try (DisksClient disksClient = DisksClient .create ()) {
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- }
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 ());
225215 }
226216 }
227217 }
@@ -247,12 +237,10 @@ public static void cleanUpExistingStoragePool(
247237 String prefixToDelete , String projectId , String zone )
248238 throws IOException , ExecutionException , InterruptedException , TimeoutException {
249239 try (StoragePoolsClient storagePoolsClient = StoragePoolsClient .create ()) {
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- }
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 ());
256244 }
257245 }
258246 }
0 commit comments