Skip to content
Permalink
Browse files
JENKINS-19845, EC2 plugin incorrectly reports current instance count
- Now using the specific 'ec2slave' tag
  • Loading branch information
rolandgroen committed Sep 11, 2014
1 parent 58fbb7f commit deffa182c4d64fcaf187010814b86df40d61a6a2
Showing 2 changed files with 18 additions and 7 deletions.
@@ -229,7 +229,7 @@ public int countCurrentEC2Slaves(String ami) throws AmazonClientException {
/**
* This method checks if the slave is provisioned by this plugin.
* It does so by: 1) checking if the ami matches and 2) checking
* for a tag with the key ec2slave. The value of the tag will be ignored.
* for a tag with the key jenkins_slave_type. The value of the tag will be ignored.
*
* See also JENKINS-19845
*
@@ -242,7 +242,7 @@ private boolean isEc2ProvisionedSlave(Instance i, String ami) {
if (ami == null || StringUtils.equals(ami, i.getImageId())) {
// Check if there is a ec2slave tag...
for (Tag tag : i.getTags()) {
if (StringUtils.equals(tag.getKey(), "ec2slave")) {
if (StringUtils.equals(tag.getKey(), "jenkins_slave_type")) {
return true;
}
}
@@ -62,7 +62,8 @@
* @author Kohsuke Kawaguchi
*/
public class SlaveTemplate implements Describable<SlaveTemplate> {
public final String ami;
public static final String TAG_NAME_JENKINS_SLAVE_TYPE = "jenkins_slave_type";
public final String ami;
public final String description;
public final String zone;
public final SpotConfiguration spotConfig;
@@ -364,16 +365,21 @@ private EC2AbstractSlave provisionOndemand(TaskListener listener) throws AmazonC
riRequest.withNetworkInterfaces(net);
}

boolean hasCustomTypeTag = false;
HashSet<Tag> inst_tags = null;
if (tags != null && !tags.isEmpty()) {
inst_tags = new HashSet<Tag>();
for(EC2Tag t : tags) {
inst_tags.add(new Tag(t.getName(), t.getValue()));
diFilters.add(new Filter("tag:"+t.getName()).withValues(t.getValue()));
if (StringUtils.equals(t.getName(), TAG_NAME_JENKINS_SLAVE_TYPE)) {
hasCustomTypeTag = true;
}
}
}

inst_tags.add(new Tag("ec2slave", "demand"));
if (!hasCustomTypeTag) {
inst_tags.add(new Tag(TAG_NAME_JENKINS_SLAVE_TYPE, "demand"));
}

DescribeInstancesRequest diRequest = new DescribeInstancesRequest();
diFilters.add(new Filter("instance-state-name").withValues(InstanceStateName.Stopped.toString(),
@@ -584,15 +590,20 @@ private EC2AbstractSlave provisionSpot(TaskListener listener) throws AmazonClien
launchSpecification.setKeyName(keyPair.getKeyName());
launchSpecification.setInstanceType(type.toString());

boolean hasCustomTypeTag = false;
HashSet<Tag> inst_tags = null;
if (tags != null && !tags.isEmpty()) {
inst_tags = new HashSet<Tag>();
for(EC2Tag t : tags) {
inst_tags.add(new Tag(t.getName(), t.getValue()));
if (StringUtils.equals(t.getName(), TAG_NAME_JENKINS_SLAVE_TYPE)) {
hasCustomTypeTag = true;
}
}
}

inst_tags.add(new Tag("ec2slave", "spot"));
if (!hasCustomTypeTag) {
inst_tags.add(new Tag(TAG_NAME_JENKINS_SLAVE_TYPE, "spot"));
}

if (StringUtils.isNotBlank(getIamInstanceProfile())) {
launchSpecification.setIamInstanceProfile(new IamInstanceProfileSpecification().withArn(getIamInstanceProfile()));

0 comments on commit deffa18

Please sign in to comment.