Skip to content

Commit

Permalink
Merge pull request #337 from opencloud/JENKINS-56443-check-shutdown-mode
Browse files Browse the repository at this point in the history
[JENKINS-56443] Don't provision a node if Jenkins is shutting down
  • Loading branch information
thoulen committed Apr 9, 2019
2 parents 20450d8 + 1ec5220 commit 0462bb5
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ public HttpResponse doProvision(@QueryParameter String template) throws ServletE
throw HttpResponses.error(SC_BAD_REQUEST, "No such template: " + template);
}

final Jenkins jenkinsInstance = Jenkins.getInstance();
if (jenkinsInstance.isQuietingDown()) {
throw HttpResponses.error(SC_BAD_REQUEST, "Jenkins instance is quieting down");
}
if (jenkinsInstance.isTerminating()) {
throw HttpResponses.error(SC_BAD_REQUEST, "Jenkins instance is terminating");
}
try {
List<EC2AbstractSlave> nodes = getNewOrExistingAvailableSlave(t, 1, true);
if (nodes == null || nodes.isEmpty())
Expand All @@ -349,7 +356,7 @@ public HttpResponse doProvision(@QueryParameter String template) throws ServletE
if (nodes.get(0).getStopOnTerminate() && c != null) {
c.connect(false);
}
Jenkins.getInstance().addNode(nodes.get(0));
jenkinsInstance.addNode(nodes.get(0));

return HttpResponses.redirectViaContextPath("/computer/" + nodes.get(0).getNodeName());
} catch (AmazonClientException e) {
Expand Down Expand Up @@ -590,6 +597,18 @@ public Collection<PlannedNode> provision(final Label label, int excessWorkload)
final SlaveTemplate t = getTemplate(label);
List<PlannedNode> plannedNodes = new ArrayList<>();

Jenkins jenkinsInstance = Jenkins.getInstance();
if (jenkinsInstance != null) {
if (jenkinsInstance.isQuietingDown()) {
LOGGER.log(Level.FINE, "Not provisioning nodes, Jenkins instance is quieting down");
return Collections.emptyList();
}
else if (jenkinsInstance.isTerminating()) {
LOGGER.log(Level.FINE, "Not provisioning nodes, Jenkins instance is terminating");
return Collections.emptyList();
}
}

try {
LOGGER.log(Level.INFO, "{0}. Attempting to provision slave needed by excess workload of " + excessWorkload + " units", t);
int number = Math.max(excessWorkload / t.getNumExecutors(), 1);
Expand Down

0 comments on commit 0462bb5

Please sign in to comment.