Skip to content

Commit

Permalink
Allow termination to complete even if release not possible
Browse files Browse the repository at this point in the history
- If cloudname is not defined, we can never release node
  and therefore can never terminate node.
- This allows the termination to continue.

[FIXED JENKINS-37989]
  • Loading branch information
scoheb committed Sep 6, 2016
1 parent 2e5dccb commit 84b925f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/redhat/foreman/ForemanComputer.java
Expand Up @@ -29,6 +29,11 @@ public void taskCompletedWithProblems(Executor executor, Task task, long duratio
eagerlyReturnNode(executor);
}

@Override
public ForemanSharedNode getNode() {
return super.getNode();
}

@Override
protected void kill() {
setTemporarilyOffline(true,
Expand All @@ -48,6 +53,8 @@ protected void kill() {
/**
* Utility method to terminate a Foreman shared node.
* @param c Computer
* @throws IOException if occurs.
* @throws InterruptedException if occurs.
*/
static void terminateForemanComputer(Computer c) throws IOException, InterruptedException {
if (c instanceof ForemanComputer) {
Expand Down
Expand Up @@ -4,7 +4,6 @@

import hudson.Extension;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.slaves.ComputerListener;

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/redhat/foreman/ForemanSharedNode.java
Expand Up @@ -27,7 +27,11 @@ public class ForemanSharedNode extends AbstractCloudSlave {
@Override
public void terminate() throws InterruptedException, IOException {
ForemanSharedNodeCloud cloud = ForemanSharedNodeCloud.getByName(cloudName);
cloud.getForemanAPI().release(name);
if (cloud != null) {
cloud.getForemanAPI().release(name);
} else {
LOGGER.warn("Foreman Shared Node " + name + " is not part of a Foreman Shared Node Cloud");
}
super.terminate();
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/redhat/foreman/ForemanSharedNodeCloud.java
Expand Up @@ -296,11 +296,14 @@ private String getHostToReserve(Label label) {
* @throws IllegalArgumentException if occurs.
*/
public static ForemanSharedNodeCloud getByName(String name) throws IllegalArgumentException {
if (name == null) {
return null;
}
Cloud cloud = Jenkins.getInstance().clouds.getByName(name);
if (cloud instanceof ForemanSharedNodeCloud) {
return (ForemanSharedNodeCloud)cloud;
}
throw new IllegalArgumentException(name + " is not an Foreman Shared Node cloud: " + cloud);
throw new IllegalArgumentException(name + " is not a Foreman Shared Node cloud");
}

/**
Expand Down

0 comments on commit 84b925f

Please sign in to comment.