Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 9a62abb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions client/src/main/java/hudson/plugins/swarm/Options.java
Expand Up @@ -8,9 +8,6 @@
import java.util.List;
import java.util.Map;

/**
*
*/
public class Options {

@Option(name = "-name", usage = "Name of the slave")
Expand Down Expand Up @@ -51,6 +48,9 @@ public class Options {
@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 + "' " +
Expand Down
1 change: 1 addition & 0 deletions client/src/main/java/hudson/plugins/swarm/SwarmClient.java
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/main/java/hudson/plugins/swarm/PluginImpl.java
Expand Up @@ -39,7 +39,7 @@ public class PluginImpl extends Plugin {
*/
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);
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 9a62abb

Please sign in to comment.