Skip to content

Commit

Permalink
Give Jenkins nodes useful names.
Browse files Browse the repository at this point in the history
EC2 slave nodes will now include their template name and EC2 instance
identifiers in the node name used throughout the Jenkins UI.

Addresses [JENKINS-15078].
  • Loading branch information
kpfleming committed Feb 12, 2013
1 parent f0d1e98 commit 8822256
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/ec2/EC2Computer.java
Expand Up @@ -55,7 +55,8 @@ public EC2Slave getNode() {
}

public String getInstanceId() {
return getName();
EC2Slave node = (EC2Slave) super.getNode();
return node.getInstanceId();
}

/**
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/hudson/plugins/ec2/EC2Slave.java
Expand Up @@ -61,6 +61,7 @@
* @author Kohsuke Kawaguchi
*/
public final class EC2Slave extends Slave {
public final String instanceId;
/**
* Comes from {@link SlaveTemplate#initScript}.
*/
Expand Down Expand Up @@ -106,8 +107,9 @@ public EC2Slave(String instanceId, String description, String remoteFS, int sshP
@DataBoundConstructor
public EC2Slave(String instanceId, String description, String remoteFS, int sshPort, int numExecutors, Mode mode, String labelString, String initScript, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String rootCommandPrefix, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, boolean usePrivateDnsName) throws FormException, IOException {

super(instanceId, description, remoteFS, numExecutors, mode, labelString, new EC2UnixLauncher(), new EC2RetentionStrategy(idleTerminationMinutes), nodeProperties);
super(description + " (" + instanceId + ")", "", remoteFS, numExecutors, mode, labelString, new EC2UnixLauncher(), new EC2RetentionStrategy(idleTerminationMinutes), nodeProperties);

this.instanceId = instanceId;
this.initScript = initScript;
this.remoteAdmin = remoteAdmin;
this.rootCommandPrefix = rootCommandPrefix;
Expand Down Expand Up @@ -153,7 +155,7 @@ public EC2Slave(String instanceId) throws FormException, IOException {
* EC2 instance ID.
*/
public String getInstanceId() {
return getNodeName();
return instanceId;
}

@Override
Expand Down Expand Up @@ -225,15 +227,15 @@ boolean terminateInstance() {
}
}

void idleTimeout() {
LOGGER.info("EC2 instance idle time expired: "+getInstanceId());
if (!stopOnTerminate) {
terminate();
}
else {
stop();
}
void idleTimeout() {
LOGGER.info("EC2 instance idle time expired: "+getInstanceId());
if (!stopOnTerminate) {
terminate();
}
else {
stop();
}
}

String getRemoteAdmin() {
if (remoteAdmin == null || remoteAdmin.length() == 0)
Expand Down Expand Up @@ -275,7 +277,7 @@ private void fetchLiveInstanceData( boolean force ) throws AmazonClientException
return;
}

Instance i = getInstance(getNodeName());
Instance i = getInstance(getInstanceId());

lastFetchTime = now;
lastFetchInstance = i;
Expand All @@ -294,7 +296,7 @@ private void fetchLiveInstanceData( boolean force ) throws AmazonClientException

/* Clears all existing tag data so that we can force the instance into a known state */
private void clearLiveInstancedata() throws AmazonClientException {
Instance inst = getInstance(getNodeName());
Instance inst = getInstance(getInstanceId());

/* Now that we have our instance, we can clear the tags on it */
if (!tags.isEmpty()) {
Expand All @@ -313,7 +315,7 @@ private void clearLiveInstancedata() throws AmazonClientException {

/* Sets tags on an instance. This will not clear existing tag data, so call clearLiveInstancedata if needed */
private void pushLiveInstancedata() throws AmazonClientException {
Instance inst = getInstance(getNodeName());
Instance inst = getInstance(getInstanceId());

/* Now that we have our instance, we can set tags on it */
if (tags != null && !tags.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Expand Up @@ -225,7 +225,7 @@ public EC2Slave provision(TaskListener listener) throws AmazonClientException, I
AmazonEC2 ec2 = getParent().connect();

try {
logger.println("Launching "+ami);
logger.println("Launching " + ami + " for template " + description);
KeyPair keyPair = parent.getPrivateKey().find(ec2);
if(keyPair==null) {
throw new AmazonClientException("No matching keypair found on EC2. Is the EC2 private key a valid one?");
Expand Down

0 comments on commit 8822256

Please sign in to comment.