Skip to content

Commit

Permalink
Merge pull request jenkinsci#135 from techdragon/log-improve
Browse files Browse the repository at this point in the history
Small cleanup in logging statements
  • Loading branch information
francisu committed Mar 31, 2015
2 parents 8a52ac5 + 8b35def commit aad454f
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/main/java/hudson/plugins/ec2/SlaveTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ private EC2AbstractSlave provisionOndemand(TaskListener listener) throws AmazonC
AmazonEC2 ec2 = getParent().connect();

try {
String msg = "Launching " + ami + " for template " + description;
logger.println(msg);
LOGGER.info(msg);
logger.println("Launching " + ami + " for template " + description);
LOGGER.info("Launching " + ami + " for template " + description);

KeyPair keyPair = getKeyPair(ec2);

Expand Down Expand Up @@ -392,9 +391,8 @@ private EC2AbstractSlave provisionOndemand(TaskListener listener) throws AmazonC
InstanceStateName.Stopping.toString()));
diRequest.setFilters(diFilters);

msg = "Looking for existing instances with describe-instance: "+diRequest;
logger.println(msg);
LOGGER.fine(msg);
logger.println("Looking for existing instances with describe-instance: "+diRequest);
LOGGER.fine("Looking for existing instances with describe-instance: "+diRequest);

DescribeInstancesResult diResult = ec2.describeInstances(diRequest);

Expand Down Expand Up @@ -427,38 +425,33 @@ private EC2AbstractSlave provisionOndemand(TaskListener listener) throws AmazonC
// That was a remote request - we should also update our local instance data.
inst.setTags(inst_tags);
}
msg = "No existing instance found - created: "+inst;
logger.println(msg);
LOGGER.info(msg);
logger.println("No existing instance found - created: "+inst);
LOGGER.info("No existing instance found - created: "+inst);
return newOndemandSlave(inst);
}

msg = "Found existing stopped instance: "+existingInstance;
logger.println(msg);
LOGGER.info(msg);
logger.println("Found existing stopped instance: "+existingInstance);
LOGGER.info("Found existing stopped instance: "+existingInstance);

List<String> instances = new ArrayList<String>();
instances.add(existingInstance.getInstanceId());
StartInstancesRequest siRequest = new StartInstancesRequest(instances);
StartInstancesResult siResult = ec2.startInstances(siRequest);

msg = "Starting existing instance: "+existingInstance+ " result:"+siResult;
logger.println(msg);
LOGGER.fine(msg);
logger.println("Starting existing instance: "+existingInstance+ " result:"+siResult);
LOGGER.fine("Starting existing instance: "+existingInstance+ " result:"+siResult);

for (EC2AbstractSlave ec2Node: NodeIterator.nodes(EC2AbstractSlave.class)){
if (ec2Node.getInstanceId().equals(existingInstance.getInstanceId())) {
msg = "Found existing corresponding Jenkins slave: "+ec2Node;
logger.println(msg);
LOGGER.finer(msg);
logger.println("Found existing corresponding Jenkins slave: "+ec2Node);
LOGGER.finer("Found existing corresponding Jenkins slave: "+ec2Node);
return ec2Node;
}
}

// Existing slave not found
msg = "Creating new Jenkins slave for existing instance: "+existingInstance;
logger.println(msg);
LOGGER.info(msg);
logger.println("Creating new Jenkins slave for existing instance: "+existingInstance);
LOGGER.info("Creating new Jenkins slave for existing instance: "+existingInstance);
return newOndemandSlave(existingInstance);

} catch (FormException e) {
Expand Down Expand Up @@ -532,7 +525,9 @@ private EC2AbstractSlave provisionSpot(TaskListener listener) throws AmazonClien
AmazonEC2 ec2 = getParent().connect();

try{
logger.println("Launching " + ami + " for template " + description);
logger.println("Launching " + ami + " for template " + description);
LOGGER.info("Launching " + ami + " for template " + description);

KeyPair keyPair = getKeyPair(ec2);

RequestSpotInstancesRequest spotRequest = new RequestSpotInstancesRequest();
Expand Down Expand Up @@ -673,6 +668,7 @@ private EC2AbstractSlave provisionSpot(TaskListener listener) throws AmazonClien
}

logger.println("Spot instance id in provision: " + spotInstReq.getSpotInstanceRequestId());
LOGGER.info("Spot instance id in provision: " + spotInstReq.getSpotInstanceRequestId());

return newSpotSlave(spotInstReq, slaveName);

Expand Down Expand Up @@ -780,6 +776,7 @@ public EC2AbstractSlave attach(String instanceId, TaskListener listener) throws

try {
logger.println("Attaching to "+instanceId);
LOGGER.info("Attaching to "+instanceId);
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.setInstanceIds(Collections.singletonList(instanceId));
Instance inst = ec2.describeInstances(request).getReservations().get(0).getInstances().get(0);
Expand Down

0 comments on commit aad454f

Please sign in to comment.