Skip to content
Permalink
Browse files
Merge branch 'JENKINS-7543' of https://github.com/mrdfuse/swarm-plugin
…into JENKINS-7543
  • Loading branch information
mrdfuse committed Oct 1, 2014
2 parents c8f4d5c + 1c6bd42 commit d2e14a1a908f00739c8fa0a37045ebee75f08a5e
Showing 3 changed files with 36 additions and 37 deletions.
@@ -1,12 +1,13 @@
package hudson.plugins.swarm;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.InetAddress;

import javax.xml.parsers.ParserConfigurationException;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;

/**
* Swarm client.
* <p/>
@@ -49,6 +49,9 @@ public class Options {
handler = ModeOptionHandler.class
)
public String mode = ModeOptionHandler.NORMAL;

@Option(name = "-toolLocations", usage = "Whitespace-separated list of tool locations to be defined on this slave. A tool location is specified as 'toolName:location'")
public List<String> toolLocations = new ArrayList<String>();

@Option(name = "-username", usage = "The Jenkins username for authentication")
public String username;
@@ -2,24 +2,7 @@

import hudson.remoting.Launcher;
import hudson.remoting.jnlp.Main;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -45,9 +28,26 @@
import java.util.List;
import java.util.Random;

/**
*
*/
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.lang.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;

public class SwarmClient {

private final Options options;
@@ -57,7 +57,7 @@ public SwarmClient(Options options) {
}

public Candidate discoverFromBroadcast() throws IOException,
InterruptedException, RetryException, ParserConfigurationException {
RetryException, ParserConfigurationException {

DatagramSocket socket = new DatagramSocket();
socket.setBroadcast(true);
@@ -273,21 +273,17 @@ protected void createSwarmSlave(Candidate target) throws IOException, Interrupte
// ie. it does not return a 401 (Unauthorized)
// but immediately a 403 (Forbidden)

StringBuilder labelStr = new StringBuilder();
for (String l : options.labels) {
if (labelStr.length() > 0) {
labelStr.append(' ');
}
labelStr.append(l);
}
String labelStr = StringUtils.join(options.labels, ' ');
String toolLocationsStr = StringUtils.join(options.toolLocations, ' ');

PostMethod post = new PostMethod(target.url
+ "/plugin/swarm/createSlave?name=" + options.name + "&executors="
+ options.executors
+ "/plugin/swarm/createSlave?name=" + options.name
+ "&executors=" + options.executors
+ param("remoteFsRoot", options.remoteFsRoot.getAbsolutePath())
+ param("description", options.description)
+ param("labels", labelStr.toString()) + "&secret="
+ target.secret
+ param("labels", labelStr)
+ param("toolLocations", toolLocationsStr)
+ "&secret=" + target.secret
+ param("mode", options.mode.toUpperCase()));

post.setDoAuthentication(true);
@@ -301,7 +297,6 @@ protected void createSwarmSlave(Candidate target) throws IOException, Interrupte
if (responseCode != 200) {
throw new RetryException(
"Failed to create a slave on Jenkins CODE: " + responseCode);

}
}

0 comments on commit d2e14a1

Please sign in to comment.