Skip to content
Permalink
Browse files

JENKINS-32439 Incorrect slave template (AMI) found when launching slave

JENKINS-30284 EC2 plugin too aggressive in timing in contacting new AWS instance over SSH (parameterized timeouts, added logging)
  • Loading branch information...
Francis Upton IV
Francis Upton IV committed Jan 14, 2016
1 parent 848fec3 commit 86f1defc1edb6c85f6e0a1ab99c969e875148f72
@@ -82,6 +82,8 @@
public final String tmpDir;
public final String remoteAdmin; // e.g. 'ubuntu'

public final String templateDescription;

public final String jvmopts; // e.g. -Xmx1g
public final boolean stopOnTerminate;
public final String idleTerminationMinutes;
@@ -126,6 +128,7 @@ public EC2AbstractSlave(String name, String instanceId, String description, Stri
super(name, "", remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);

this.instanceId = instanceId;
this.templateDescription = description;
this.initScript = initScript;
this.tmpDir = tmpDir;
this.remoteAdmin = remoteAdmin;
@@ -23,12 +23,16 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -38,10 +42,13 @@
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import javax.servlet.ServletException;

import hudson.model.TaskListener;
import jenkins.model.Jenkins;

import org.apache.commons.lang.StringUtils;
@@ -247,8 +254,6 @@ public HttpResponse doProvision(@QueryParameter String template) throws ServletE
throw HttpResponses.error(SC_BAD_REQUEST, "No such template: " + template);
}

StringWriter sw = new StringWriter();
StreamTaskListener listener = new StreamTaskListener(sw);
try {
EC2AbstractSlave node = provisionSlaveIfPossible(t);
if (node == null)
@@ -672,4 +677,21 @@ public FormValidation doGenerateKey(StaplerResponse rsp, URL ec2EndpointUrl, boo
}
}

private static final SimpleFormatter sf = new SimpleFormatter();

public static void log(Logger logger, Level level, TaskListener listener, String message) {
log(logger, level, listener, message, null);
}

public static void log(Logger logger, Level level, TaskListener listener, String message, Throwable exception) {
logger.log(level, message, exception);
if (listener != null) {
if (exception != null)
message += " Exception: " + exception;
LogRecord lr = new LogRecord(level, message);
PrintStream printStream = listener.getLogger();
printStream.print(sf.format(lr));
}
}

}
@@ -72,10 +72,16 @@ public String getSpotInstanceRequestId() {
}

public EC2Cloud getCloud() {
EC2AbstractSlave node = (EC2AbstractSlave) super.getNode();
EC2AbstractSlave node = getNode();
if (node == null)
return null;
return node.getCloud();
}

public SlaveTemplate getSlaveTemplate() {
return getCloud().getTemplate(getNode().templateDescription);
}

/**
* Gets the EC2 console output.
*/
@@ -31,6 +31,7 @@
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.amazonaws.AmazonClientException;
@@ -50,8 +51,6 @@
public void launch(SlaveComputer _computer, TaskListener listener) {
try {
EC2Computer computer = (EC2Computer) _computer;
PrintStream logger = listener.getLogger();

final String baseMsg = "Node " + computer.getName() + "(" + computer.getInstanceId() + ")";
String msg;

@@ -65,13 +64,11 @@ public void launch(SlaveComputer _computer, TaskListener listener) {
break;
case RUNNING:
msg = baseMsg + " is ready";
LOGGER.finer(msg);
logger.println(msg);
((EC2Computer) _computer).getCloud().log(LOGGER, Level.FINER, listener, msg);
break OUTER;
case STOPPED:
msg = baseMsg + " is stopped, sending start request";
LOGGER.finer(msg);
logger.println(msg);
((EC2Computer) _computer).getCloud().log(LOGGER, Level.INFO, listener, msg);

AmazonEC2 ec2 = computer.getCloud().connect();
List<String> instances = new ArrayList<String>();
@@ -81,15 +78,13 @@ public void launch(SlaveComputer _computer, TaskListener listener) {
StartInstancesResult siResult = ec2.startInstances(siRequest);

msg = baseMsg + ": sent start request, result: " + siResult;
LOGGER.finer(baseMsg);
logger.println(baseMsg);
((EC2Computer) _computer).getCloud().log(LOGGER, Level.INFO, listener, msg);
continue OUTER;
case SHUTTING_DOWN:
case TERMINATED:
// abort
msg = baseMsg + " is terminated or terminating, aborting launch";
LOGGER.info(msg);
logger.println(msg);
((EC2Computer) _computer).getCloud().log(LOGGER, Level.INFO, listener, msg);
return;
default:
msg = baseMsg + " is in an unknown state, retrying in 5s";
@@ -99,8 +94,7 @@ public void launch(SlaveComputer _computer, TaskListener listener) {
// check every 5 secs
Thread.sleep(5000);
// and report to system log and console
LOGGER.finest(msg);
logger.println(msg);
((EC2Computer) _computer).getCloud().log(LOGGER, Level.FINEST, listener, msg);
}

launch(computer, listener, computer.describeInstance());
Oops, something went wrong.

0 comments on commit 86f1def

Please sign in to comment.
You can’t perform that action at this time.