Skip to content

Commit

Permalink
Merge pull request jenkinsci#133 from jjrussell/fix/catch-null-ids-fo…
Browse files Browse the repository at this point in the history
…r-spot-instances

Check more places where passing a null instanceID can do a search of random spot instances.
  • Loading branch information
francisu committed Apr 11, 2015
2 parents a8ea19f + ee35f16 commit c4abeb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/main/java/hudson/plugins/ec2/EC2AbstractSlave.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public abstract class EC2AbstractSlave extends Slave {
public final String initScript;
public final String tmpDir;
public final String remoteAdmin; // e.g. 'ubuntu'


public final String jvmopts; //e.g. -Xmx1g
public final boolean stopOnTerminate;
public final String idleTerminationMinutes;
Expand Down Expand Up @@ -139,14 +139,14 @@ protected Object readResolve() {
if (instanceId == null) {
instanceId = getNodeName();
}

if (amiType == null) {
amiType = new UnixData(rootCommandPrefix, Integer.toString(sshPort));
}

return this;
}

public EC2Cloud getCloud() {
return (EC2Cloud) Hudson.getInstance().getCloud(cloudName);
}
Expand Down Expand Up @@ -198,12 +198,13 @@ public Computer createComputer() {
}

public static Instance getInstance(String instanceId, EC2Cloud cloud) {
if (instanceId == null || instanceId == "" || cloud == null)
return null;

Instance i = null;
try {
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.setInstanceIds(Collections.<String>singletonList(instanceId));
if (cloud == null)
return null;
AmazonEC2 ec2 = cloud.connect();
List<Reservation> reservations = ec2.describeInstances(request).getReservations();
if (reservations.size() > 0) {
Expand Down Expand Up @@ -302,7 +303,7 @@ public int getSshPort() {
String sshPort = amiType.isUnix() ? ((UnixData)amiType).getSshPort() : "22";
if (sshPort == null || sshPort.length() == 0)
return 22;

int port = 0;
try {
port = Integer.parseInt(sshPort);
Expand Down Expand Up @@ -393,7 +394,7 @@ protected void pushLiveInstancedata() throws AmazonClientException {
Instance inst = getInstance(getInstanceId(), getCloud());

/* Now that we have our instance, we can set tags on it */
if (tags != null && !tags.isEmpty()) {
if (inst != null && tags != null && !tags.isEmpty()) {
HashSet<Tag> inst_tags = new HashSet<Tag>();

for(EC2Tag t : tags) {
Expand Down Expand Up @@ -429,7 +430,7 @@ public long getCreatedTime() {
public boolean getUsePrivateDnsName() {
return usePrivateDnsName;
}

public String getAdminPassword() {
return amiType.isWindows() ? ((WindowsData)amiType).getPassword() : "";
}
Expand Down Expand Up @@ -481,7 +482,7 @@ public ListBoxModel doFillZoneItems(@QueryParameter boolean useInstanceProfileFo
AWSCredentialsProvider credentialsProvider = EC2Cloud.createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
return fillZoneItems(credentialsProvider, region);
}

public List<Descriptor<AMITypeData>> getAMITypeDescriptors()
{
return Hudson.getInstance().<AMITypeData,Descriptor<AMITypeData>>getDescriptorList(AMITypeData.class);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ private EC2AbstractSlave provisionSpot(TaskListener listener) throws AmazonClien
}
}
if (!hasCustomTypeTag) {
inst_tags.add(new Tag(EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE, "spot"));
if (inst_tags != null)
inst_tags.add(new Tag(EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE, "spot"));
}

if (StringUtils.isNotBlank(getIamInstanceProfile())) {
Expand Down

0 comments on commit c4abeb7

Please sign in to comment.