From fdec72118c4074f8a16720e07dfd3b1e4727d9a6 Mon Sep 17 00:00:00 2001 From: ckim328 Date: Wed, 2 Feb 2022 14:36:43 -0500 Subject: [PATCH 1/9] Created Util to delete old clusters --- .../cloud/container/v1/it/ITSystemTest.java | 1 + .../google/cloud/container/v1/it/Util.java | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java index 84e1a8ab..ec3a71cb 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java @@ -61,6 +61,7 @@ public class ITSystemTest { @BeforeClass public static void beforeClass() throws Exception { client = ClusterManagerClient.create(); + Util.cleanUpExistingInstanceCluster(PROJECT_ID, ZONE, client); /** create node pool* */ NodePool nodePool = diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java new file mode 100644 index 00000000..944ea267 --- /dev/null +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 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 com.google.cloud.container.v1.it; + +import com.google.container.v1.Cluster; +import com.google.cloud.container.v1.ClusterManagerClient; +import com.google.container.v1.ListClustersResponse; +import java.io.IOException; +import java.time.Instant; +import java.util.List; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; +import java.util.concurrent.ExecutionException; + +public class Util { + // Cleans existing test resources if any. + private static final int DELETION_THRESHOLD_TIME_HOURS = 24; + + /** tear down any clusters that are older than 24 hours **/ + public static void cleanUpExistingInstanceCluster(String projectId, String zone, ClusterManagerClient client) + throws IOException, ExecutionException, InterruptedException { + + ListClustersResponse clustersResponse = client.listClusters(projectId, zone); + List clusters = clustersResponse.getClustersList(); + + for (Cluster cluster : clusters) { + if (isCreatedBeforeThresholdTime(cluster.getCreateTime())){ + client.deleteCluster(projectId, zone, cluster.getName()); + } + } + } + + public static boolean isCreatedBeforeThresholdTime(String timestamp) { + return OffsetDateTime.parse(timestamp).toInstant().isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); + } +} + From e61554b33d8229a6da96cf16fc61217a9aa3bb6f Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 7 Feb 2022 22:57:38 +0000 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../google/cloud/container/v1/it/Util.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java index 944ea267..a1e58794 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -16,36 +16,38 @@ package com.google.cloud.container.v1.it; -import com.google.container.v1.Cluster; import com.google.cloud.container.v1.ClusterManagerClient; +import com.google.container.v1.Cluster; import com.google.container.v1.ListClustersResponse; import java.io.IOException; import java.time.Instant; -import java.util.List; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; +import java.util.List; import java.util.concurrent.ExecutionException; public class Util { - // Cleans existing test resources if any. - private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - - /** tear down any clusters that are older than 24 hours **/ - public static void cleanUpExistingInstanceCluster(String projectId, String zone, ClusterManagerClient client) - throws IOException, ExecutionException, InterruptedException { + // Cleans existing test resources if any. + private static final int DELETION_THRESHOLD_TIME_HOURS = 24; + + /** tear down any clusters that are older than 24 hours * */ + public static void cleanUpExistingInstanceCluster( + String projectId, String zone, ClusterManagerClient client) + throws IOException, ExecutionException, InterruptedException { - ListClustersResponse clustersResponse = client.listClusters(projectId, zone); - List clusters = clustersResponse.getClustersList(); + ListClustersResponse clustersResponse = client.listClusters(projectId, zone); + List clusters = clustersResponse.getClustersList(); - for (Cluster cluster : clusters) { - if (isCreatedBeforeThresholdTime(cluster.getCreateTime())){ - client.deleteCluster(projectId, zone, cluster.getName()); - } - } + for (Cluster cluster : clusters) { + if (isCreatedBeforeThresholdTime(cluster.getCreateTime())) { + client.deleteCluster(projectId, zone, cluster.getName()); + } } + } - public static boolean isCreatedBeforeThresholdTime(String timestamp) { - return OffsetDateTime.parse(timestamp).toInstant().isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); - } + public static boolean isCreatedBeforeThresholdTime(String timestamp) { + return OffsetDateTime.parse(timestamp) + .toInstant() + .isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); + } } - From e6e0947ade5c19752530d4a10989bfd61d233fbf Mon Sep 17 00:00:00 2001 From: ckim328 Date: Thu, 10 Feb 2022 08:57:21 -0500 Subject: [PATCH 3/9] Fixed nit --- .../java/com/google/cloud/container/v1/it/ITSystemTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java index ec3a71cb..27dc8dcc 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java @@ -63,7 +63,7 @@ public static void beforeClass() throws Exception { client = ClusterManagerClient.create(); Util.cleanUpExistingInstanceCluster(PROJECT_ID, ZONE, client); - /** create node pool* */ + /** create node pool**/ NodePool nodePool = NodePool.newBuilder() .setInitialNodeCount(INITIAL_NODE_COUNT) From e978ef408dddbd6572fe3d6b09dbedc0d24972bb Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 10 Feb 2022 14:11:42 +0000 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/container/v1/it/ITSystemTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java index 27dc8dcc..ec3a71cb 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java @@ -63,7 +63,7 @@ public static void beforeClass() throws Exception { client = ClusterManagerClient.create(); Util.cleanUpExistingInstanceCluster(PROJECT_ID, ZONE, client); - /** create node pool**/ + /** create node pool* */ NodePool nodePool = NodePool.newBuilder() .setInitialNodeCount(INITIAL_NODE_COUNT) From a2b54f722dfccf374569def58c1a32d0c082e092 Mon Sep 17 00:00:00 2001 From: ckim328 Date: Fri, 11 Feb 2022 09:45:53 -0500 Subject: [PATCH 5/9] Update nit per discussion --- .../src/test/java/com/google/cloud/container/v1/it/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java index a1e58794..a2465c7d 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -30,7 +30,7 @@ public class Util { // Cleans existing test resources if any. private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - /** tear down any clusters that are older than 24 hours * */ + /** tear down any clusters that are older than 24 hours **/ public static void cleanUpExistingInstanceCluster( String projectId, String zone, ClusterManagerClient client) throws IOException, ExecutionException, InterruptedException { From 0d8a9f1dd8b5b2ed67a0ff0db3a74f00f0f74b2f Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 11 Feb 2022 14:50:28 +0000 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../src/test/java/com/google/cloud/container/v1/it/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java index a2465c7d..a1e58794 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -30,7 +30,7 @@ public class Util { // Cleans existing test resources if any. private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - /** tear down any clusters that are older than 24 hours **/ + /** tear down any clusters that are older than 24 hours * */ public static void cleanUpExistingInstanceCluster( String projectId, String zone, ClusterManagerClient client) throws IOException, ExecutionException, InterruptedException { From ec90b491a6d05ca19ed2172cf91506594fc3267a Mon Sep 17 00:00:00 2001 From: ckim328 Date: Fri, 11 Feb 2022 10:15:52 -0500 Subject: [PATCH 7/9] changed method to private --- .../src/test/java/com/google/cloud/container/v1/it/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java index a2465c7d..5a6ae509 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -45,7 +45,7 @@ public static void cleanUpExistingInstanceCluster( } } - public static boolean isCreatedBeforeThresholdTime(String timestamp) { + private static boolean isCreatedBeforeThresholdTime(String timestamp) { return OffsetDateTime.parse(timestamp) .toInstant() .isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); From 716b481ce5010225b149be48d3772143a408e72e Mon Sep 17 00:00:00 2001 From: ckim328 Date: Fri, 11 Feb 2022 10:48:12 -0500 Subject: [PATCH 8/9] Remove white space --- .../java/com/google/cloud/container/v1/it/ITSystemTest.java | 2 +- .../src/test/java/com/google/cloud/container/v1/it/Util.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java index ec3a71cb..27dc8dcc 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java @@ -63,7 +63,7 @@ public static void beforeClass() throws Exception { client = ClusterManagerClient.create(); Util.cleanUpExistingInstanceCluster(PROJECT_ID, ZONE, client); - /** create node pool* */ + /** create node pool**/ NodePool nodePool = NodePool.newBuilder() .setInitialNodeCount(INITIAL_NODE_COUNT) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java index 426bd42f..5a6ae509 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -30,7 +30,7 @@ public class Util { // Cleans existing test resources if any. private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - /** tear down any clusters that are older than 24 hours * */ + /** tear down any clusters that are older than 24 hours **/ public static void cleanUpExistingInstanceCluster( String projectId, String zone, ClusterManagerClient client) throws IOException, ExecutionException, InterruptedException { From 467b4d5cda2286a65ce98b5b9bd6cdfb30715a56 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 11 Feb 2022 15:51:51 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/container/v1/it/ITSystemTest.java | 2 +- .../src/test/java/com/google/cloud/container/v1/it/Util.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java index 27dc8dcc..ec3a71cb 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/ITSystemTest.java @@ -63,7 +63,7 @@ public static void beforeClass() throws Exception { client = ClusterManagerClient.create(); Util.cleanUpExistingInstanceCluster(PROJECT_ID, ZONE, client); - /** create node pool**/ + /** create node pool* */ NodePool nodePool = NodePool.newBuilder() .setInitialNodeCount(INITIAL_NODE_COUNT) diff --git a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java index 5a6ae509..426bd42f 100644 --- a/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java +++ b/google-cloud-container/src/test/java/com/google/cloud/container/v1/it/Util.java @@ -30,7 +30,7 @@ public class Util { // Cleans existing test resources if any. private static final int DELETION_THRESHOLD_TIME_HOURS = 24; - /** tear down any clusters that are older than 24 hours **/ + /** tear down any clusters that are older than 24 hours * */ public static void cleanUpExistingInstanceCluster( String projectId, String zone, ClusterManagerClient client) throws IOException, ExecutionException, InterruptedException {