-
-
Notifications
You must be signed in to change notification settings - Fork 94
Terminate the instance when 404 occured. #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b14ecd1
5ba199e
ec6f4b3
627fda8
f6fc88c
ce2791c
d811f6c
181e799
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,11 @@ | |
|
|
||
| package com.google.jenkins.plugins.computeengine; | ||
|
|
||
| import static com.google.jenkins.plugins.computeengine.ComputeEngineCloud.CLOUD_ID_LABEL_KEY; | ||
|
|
||
| import com.google.cloud.graphite.platforms.plugin.client.ComputeClient.OperationException; | ||
| import com.google.common.base.Strings; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.jenkins.plugins.computeengine.ssh.GoogleKeyCredential; | ||
| import edu.umd.cs.findbugs.annotations.Nullable; | ||
| import hudson.Extension; | ||
|
|
@@ -30,6 +33,7 @@ | |
| import hudson.slaves.RetentionStrategy; | ||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
@@ -130,9 +134,16 @@ protected void _terminate(TaskListener listener) throws IOException, Interrupted | |
| .createSnapshotSync(cloud.getProjectId(), this.zone, this.getNodeName(), createSnapshotTimeout); | ||
| } | ||
|
|
||
| // If the instance is running, attempt to terminate it. This is an async call and we | ||
| 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. | ||
| cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name); | ||
| if (instanceExistsInCloud) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? Is it just to avoid an unnecessary error message in the logs in case the instance does not exist in the cloud?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is based on another branch (see #470) but I don't think this condition is useful. Theoretically we could even verify the instance exists in the cloud but when running the Please @Theoderich if we're missing cases, please tell us.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done into f6fc88c
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is part of the fix for #471 and should not be removed. When trying to delete this Zombie node, Jenkins calls The Solution: Why not just catch the exception thrown by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks for the detailed explanation. |
||
| cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name); | ||
| } | ||
| } catch (CloudNotFoundException cnfe) { | ||
| listener.error(cnfe.getMessage()); | ||
| } catch (OperationException oe) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.