Skip to content

Commit

Permalink
ComputeEnginerInstance terminate instance without checking if it stil…
Browse files Browse the repository at this point in the history
…l exists.
  • Loading branch information
Artmorse committed Dec 9, 2024
1 parent 627fda8 commit f6fc88c
Showing 1 changed file with 1 addition and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,8 @@ protected void _terminate(TaskListener listener) throws IOException, Interrupted
.createSnapshotSync(cloud.getProjectId(), this.zone, this.getNodeName(), createSnapshotTimeout);
}

Map<String, String> filterLabel = ImmutableMap.of(CLOUD_ID_LABEL_KEY, cloud.getInstanceId());
var instanceExistsInCloud =
cloud.getClient().listInstancesWithLabel(cloud.getProjectId(), filterLabel).stream()
.anyMatch(instance -> instance.getName().equals(name));

// If the instance exists in the cloud, attempt to terminate it. This is an async call and we
// return immediately, hoping for the best.
if (instanceExistsInCloud) {
cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name);
}
cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name);
} catch (CloudNotFoundException cnfe) {
listener.error(cnfe.getMessage());
} catch (OperationException oe) {
Expand Down

0 comments on commit f6fc88c

Please sign in to comment.