Permalink
Browse files

Merge pull request #40 from mrdfuse/JENKINS-34593

JENKINS-34593 add an option to delete existing clients
  • Loading branch information...
mindjiver committed May 4, 2016
2 parents 74f4bbf + 63e4307 commit 9a62abb48b68ef2447af387b9ad6b195bb33dce7
@@ -8,9 +8,6 @@
import java.util.List;
import java.util.Map;

/**
*
*/
public class Options {

@Option(name = "-name", usage = "Name of the slave")
@@ -51,6 +48,9 @@
@Option(name = "-disableClientsUniqueId", usage = "Disables Clients unique ID.")
public boolean disableClientsUniqueId;

@Option(name = "-deleteExistingClients", usage = "Deletes any existing slave with the same name.")
public boolean deleteExistingClients;

@Option(
name = "-mode",
usage = "The mode controlling how Jenkins allocates jobs to slaves. Can be either '" + ModeOptionHandler.NORMAL + "' " +
@@ -323,6 +323,7 @@ protected void createSwarmSlave(Candidate target) throws IOException, Interrupte
+ "&secret=" + target.secret
+ param("mode", options.mode.toUpperCase(Locale.ENGLISH))
+ param("hash", hash)
+ param("deleteExistingClients", Boolean.toString(options.deleteExistingClients))
);

post.setDoAuthentication(true);
@@ -39,7 +39,7 @@
*/
public void doCreateSlave(StaplerRequest req, StaplerResponse rsp, @QueryParameter String name, @QueryParameter String description, @QueryParameter int executors,
@QueryParameter String remoteFsRoot, @QueryParameter String labels, @QueryParameter String secret, @QueryParameter Node.Mode mode,
@QueryParameter(fixEmpty = true) String hash) throws IOException {
@QueryParameter(fixEmpty = true) String hash, @QueryParameter boolean deleteExistingClients) throws IOException {

if (!getSwarmSecret().equals(secret)) {
rsp.setStatus(SC_FORBIDDEN);
@@ -58,7 +58,7 @@ public void doCreateSlave(StaplerRequest req, StaplerResponse rsp, @QueryParamet
nodeProperties = Lists.newArrayList(new ToolLocationNodeProperty(parsedToolLocations));
}

if (hash == null && jenkins.getNode(name) != null) {
if (hash == null && jenkins.getNode(name) != null && !deleteExistingClients) {
// this is a legacy client, they won't be able to pick up the new name, so throw them away
// perhaps they can find another master to connect to
rsp.setStatus(SC_CONFLICT);
@@ -75,7 +75,7 @@ public void doCreateSlave(StaplerRequest req, StaplerResponse rsp, @QueryParamet
// check for existing connections
{
Node n = jenkins.getNode(name);
if (n != null) {
if (n != null && !deleteExistingClients) {
Computer c = n.toComputer();
if (c != null && c.isOnline()) {
// this is an existing connection, we'll only cause issues if we trample over an online connection

0 comments on commit 9a62abb

Please sign in to comment.