Skip to content

Commit

Permalink
JENKINS-50105 EC2 Step provisioning incorrectly specifies a label (#268)
Browse files Browse the repository at this point in the history
JENKINS-47130 EC2 plugin 1.37 fails to provision previously defined slaves
  • Loading branch information
Francis Upton IV committed Mar 12, 2018
1 parent a7a07aa commit affb7f4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
24 changes: 11 additions & 13 deletions src/main/java/hudson/plugins/ec2/EC2Cloud.java
Expand Up @@ -553,21 +553,19 @@ public Collection<PlannedNode> provision(Label label, int excessWorkload) {
if (slave == null)
break;
LOGGER.log(Level.INFO, String.format("We have now %s computers", Jenkins.getInstance().getComputers().length));
if (t.isNode()) {
Jenkins.getInstance().addNode(slave);
LOGGER.log(Level.INFO, String.format("Added node named: %s, We have now %s computers", slave.getNodeName(), Jenkins.getInstance().getComputers().length));
r.add(new PlannedNode(t.getDisplayName(), Computer.threadPoolForRemoting.submit(new Callable<Node>() {

public Node call() throws Exception {
long startTime = System.currentTimeMillis(); // fetch starting time
while ((System.currentTimeMillis() - startTime) < slave.launchTimeout * 1000) {
return tryToCallSlave(slave, t);
}
LOGGER.log(Level.WARNING, "Expected - Instance - failed to connect within launch timeout");
Jenkins.getInstance().addNode(slave);
LOGGER.log(Level.INFO, String.format("Added node named: %s, We have now %s computers", slave.getNodeName(), Jenkins.getInstance().getComputers().length));
r.add(new PlannedNode(t.getDisplayName(), Computer.threadPoolForRemoting.submit(new Callable<Node>() {

public Node call() throws Exception {
long startTime = System.currentTimeMillis(); // fetch starting time
while ((System.currentTimeMillis() - startTime) < slave.launchTimeout * 1000) {
return tryToCallSlave(slave, t);
}
}), t.getNumExecutors()));
}
LOGGER.log(Level.WARNING, "Expected - Instance - failed to connect within launch timeout");
return tryToCallSlave(slave, t);
}
}), t.getNumExecutors()));

excessWorkload -= t.getNumExecutors();
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/hudson/plugins/ec2/EC2Step.java
Expand Up @@ -141,14 +141,13 @@ protected Instance run() throws Exception {
SlaveTemplate t;
t = ((AmazonEC2Cloud) cl).getTemplate(this.template);
if (t != null) {
t.setNode(false);
LabelAtom lbl = new LabelAtom(this.template);
SlaveTemplate.ProvisionOptions universe = SlaveTemplate.ProvisionOptions.ALLOW_CREATE;
EnumSet<SlaveTemplate.ProvisionOptions> opt = EnumSet.noneOf(SlaveTemplate.ProvisionOptions.class);
opt.add(universe);

EC2AbstractSlave instance = t.provision(TaskListener.NULL, lbl, opt);
Instance myInstance = EC2AbstractSlave.getInstance(instance.getInstanceId(), instance.getCloud());
EC2AbstractSlave node = t.provision(TaskListener.NULL, null, opt);
Jenkins.getInstance().addNode(node);
Instance myInstance = EC2AbstractSlave.getInstance(node.getInstanceId(), node.getCloud());
return myInstance;
} else {
throw new IllegalArgumentException("Error in AWS Cloud. Please review AWS template defined in Jenkins configuration.");
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Expand Up @@ -128,8 +128,6 @@ public class SlaveTemplate implements Describable<SlaveTemplate> {

public final boolean connectUsingPublicIp;

private boolean node = true;

private transient/* almost final */Set<LabelAtom> labelSet;

private transient/* almost final */Set<String> securityGroupSet;
Expand Down Expand Up @@ -393,15 +391,6 @@ public String getIamInstanceProfile() {
return iamInstanceProfile;
}

public void setNode(Boolean node) {
this.node = node;
}

public Boolean isNode() {
return this.node;
}


public enum ProvisionOptions { ALLOW_CREATE, FORCE_CREATE }

/**
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/hudson/plugins/ec2/EC2StepTest.java
Expand Up @@ -55,6 +55,8 @@ public void setup () throws Exception {
when(cl.getTemplates()).thenReturn(templates);
when(cl.getTemplate(anyString())).thenReturn(st);
r.addCloud(cl);

when(instance.getNodeName()).thenReturn("nodeName");
}


Expand Down

0 comments on commit affb7f4

Please sign in to comment.