Skip to content

Commit

Permalink
slave termination and cacthing exception fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mavlyutov committed Jan 28, 2014
1 parent 54258e7 commit 8db7f95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ public void run() {
logger.log(Level.INFO, "Deleting pending node " + c.getName());
try {
((JCloudsComputer) c).deleteSlave();
} catch (IOException e) {
} catch (IOException | InterruptedException e) {
logger.log(Level.WARNING, "Failed to disconnect and delete " + c.getName() + ": " + e.getMessage());
}
}
});

deletedNodesBuilder.add(f);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public HttpResponse doDoDelete() throws IOException {
}

/**
* Delete the slave, terminate the instance. Can be called eitehr by doDoDelete() or from JCloudsRetentionStrategy.
* Delete the slave, terminate the instance. Can be called either by doDoDelete() or from JCloudsRetentionStrategy.
*
* @throws InterruptedException
*/
public void deleteSlave() throws IOException {
public void deleteSlave() throws IOException, InterruptedException {
LOGGER.info("Terminating " + getName() + " slave");
JCloudsSlave slave = getNode();
if (slave.getChannel() != null) {
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/jenkins/plugins/jclouds/compute/JCloudsSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,6 @@ public AbstractCloudComputer<JCloudsSlave> createComputer() {
return new JCloudsComputer(this);
}

/**
* Destroy the node calls {@link ComputeService#destroyNode}
*
*/
@Override
public void terminate() {
final ComputeService compute = JCloudsCloud.getByName(cloudName).getCompute();
if (compute.getNodeMetadata(nodeId) != null && compute.getNodeMetadata(nodeId).getStatus().equals(NodeMetadata.Status.RUNNING)) {
if (stopOnTerminate) {
LOGGER.info("Suspending the Slave : " + getNodeName());
compute.suspendNode(nodeId);
} else {
LOGGER.info("Terminating the Slave : " + getNodeName());
compute.destroyNode(nodeId);
}
} else {
LOGGER.info("Slave " + getNodeName() + " is already not running.");
}
}

@Extension
public static final class JCloudsSlaveDescriptor extends SlaveDescriptor {

Expand All @@ -188,9 +168,23 @@ public boolean isInstantiable() {
}
}

/**
* Destroy the node calls {@link ComputeService#destroyNode}
*
*/
@Override
protected void _terminate(TaskListener listener) throws IOException, InterruptedException {
// TODO Auto-generated method stub

final ComputeService compute = JCloudsCloud.getByName(cloudName).getCompute();
if (compute.getNodeMetadata(nodeId) != null && compute.getNodeMetadata(nodeId).getStatus().equals(NodeMetadata.Status.RUNNING)) {
if (stopOnTerminate) {
LOGGER.info("Suspending the Slave : " + getNodeName());
compute.suspendNode(nodeId);
} else {
LOGGER.info("Terminating the Slave : " + getNodeName());
compute.destroyNode(nodeId);
}
} else {
LOGGER.info("Slave " + getNodeName() + " is already not running.");
}
}
}

0 comments on commit 8db7f95

Please sign in to comment.