Skip to content
Permalink
Browse files
[JENKINS-34328] CLI command disconnect-node extracted from core to CLI
disconnect-node extended to accept multiple node names
disconnect-node covered by test-cases
  • Loading branch information
pjanouse committed May 5, 2016
1 parent 31ad770 commit 6feaea8647fe328eb47ea764764897cdb212f3fb
Showing with 428 additions and 15 deletions.
  1. +106 −0 core/src/main/java/hudson/cli/DisconnectNodeCommand.java
  2. +6 −3 core/src/main/java/hudson/model/Computer.java
  3. +1 −0 core/src/main/resources/hudson/cli/Messages.properties
  4. +3 −0 core/src/main/resources/hudson/cli/Messages_bg.properties
  5. +2 −0 core/src/main/resources/hudson/cli/Messages_da.properties
  6. +1 −0 core/src/main/resources/hudson/cli/Messages_de.properties
  7. +1 −0 core/src/main/resources/hudson/cli/Messages_es.properties
  8. +1 −0 core/src/main/resources/hudson/cli/Messages_ja.properties
  9. +1 −0 core/src/main/resources/hudson/cli/Messages_pt_BR.properties
  10. +1 −0 core/src/main/resources/hudson/cli/Messages_zh_CN.properties
  11. +2 −0 core/src/main/resources/hudson/cli/Messages_zh_TW.properties
  12. +1 −1 core/src/main/resources/hudson/model/Messages.properties
  13. +0 −2 core/src/main/resources/hudson/model/Messages_bg.properties
  14. +0 −1 core/src/main/resources/hudson/model/Messages_da.properties
  15. +0 −1 core/src/main/resources/hudson/model/Messages_de.properties
  16. +0 −1 core/src/main/resources/hudson/model/Messages_es.properties
  17. +0 −1 core/src/main/resources/hudson/model/Messages_it.properties
  18. +0 −1 core/src/main/resources/hudson/model/Messages_ja.properties
  19. +0 −2 core/src/main/resources/hudson/model/Messages_pt_BR.properties
  20. +0 −1 core/src/main/resources/hudson/model/Messages_zh_CN.properties
  21. +0 −1 core/src/main/resources/hudson/model/Messages_zh_TW.properties
  22. +302 −0 test/src/test/java/hudson/cli/DisconnectNodeCommandTest.java
@@ -0,0 +1,106 @@
/*
* The MIT License
*
* Copyright (c) 2016 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.cli;

import hudson.AbortException;
import hudson.Extension;
import hudson.model.Computer;
import hudson.util.EditDistance;
import jenkins.model.Jenkins;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.logging.Logger;

/**
* @author pjanouse
* @since TODO
*/
@Extension
public class DisconnectNodeCommand extends CLICommand {
@Argument(metaVar = "NAME", usage = "Slave name, or empty string for master; comama-separated list is supported", required = true, multiValued = true)
private List<String> nodes;

@Option(name = "-m", usage = "Record the note about why you are disconnecting this node")
public String cause;

private static final Logger LOGGER = Logger.getLogger(DisconnectNodeCommand.class.getName());

@Override
public String getShortDescription() {
return Messages.DisconnectNodeCommand_ShortDescription();
}

@Override
protected int run() throws Exception {
boolean errorOccurred = false;
final Jenkins jenkins = Jenkins.getActiveInstance();

final HashSet<String> hs = new HashSet<String>();
hs.addAll(nodes);

List<String> names = null;

for (String node_s : hs) {
Computer computer = null;

try {
computer = jenkins.getComputer(node_s);

if (computer == null) {
if (names == null) {
names = new ArrayList<String>();
for (Computer c : jenkins.getComputers()) {
if (!c.getName().isEmpty()) {
names.add(c.getName());
}
}
}
String adv = EditDistance.findNearest(node_s, names);
throw new IllegalArgumentException(adv == null ?
hudson.model.Messages.Computer_NoSuchSlaveExistsWithoutAdvice(node_s) :
hudson.model.Messages.Computer_NoSuchSlaveExists(node_s, adv));
}

computer.cliDisconnect(cause);
} catch (Exception e) {
if (hs.size() == 1) {
throw e;
}

stderr.println(String.format(node_s + ": " + e.getMessage()));
errorOccurred = true;
continue;
}
}

if (errorOccurred) {
throw new AbortException("Error occured while performing this command, see previous stderr output.");
}
return 0;
}
}
@@ -506,10 +506,13 @@ public final long getConnectTime() {
}

/**
* CLI command to disconnects this node.
* Deprecated - implementation of CLI command "disconnect-node" moved to {@link hudson.cli.DisconnectNodeCommand}.
*
* @param cause
* Record the note about why you are disconnecting this node
*/
@CLIMethod(name="disconnect-node")
public void cliDisconnect(@Option(name="-m",usage="Record the note about why you are disconnecting this node") String cause) throws ExecutionException, InterruptedException {
@Deprecated
public void cliDisconnect(String cause) throws ExecutionException, InterruptedException {
checkPermission(DISCONNECT);
disconnect(new ByCLI(cause)).get();
}
@@ -89,3 +89,4 @@ OnlineNodeCommand.ShortDescription=Resume using a node for performing builds, to

ClearQueueCommand.ShortDescription=Clears the build queue.

DisconnectNodeCommand.ShortDescription=Disconnects from a node.
@@ -125,3 +125,6 @@ BuildCommand.CLICause.CannotBuildUnknownReasons=\

ClearQueueCommand.ShortDescription=\
\u0418\u0437\u0447\u0438\u0441\u0442\u0432\u0430\u043d\u0435 \u043d\u0430 \u043e\u043f\u0430\u0448\u043a\u0430\u0442\u0430 \u0441\u044a\u0441 \u0437\u0430\u0434\u0430\u0447\u0438.

DisconnectNodeCommand.ShortDescription=\
\u041f\u0440\u0435\u043a\u044a\u0441\u0432\u0430\u043d\u0435 \u043d\u0430 \u0432\u0440\u044a\u0437\u043a\u0430\u0442\u0430 \u0441 \u043c\u0430\u0448\u0438\u043d\u0430.
@@ -5,3 +5,5 @@ OnlineNodeCommand.ShortDescription=Genoptag brugen af en byggenode, for at annul

ClearQueueCommand.ShortDescription=Ryd byggek\u00f8en

DisconnectNodeCommand.ShortDescription=Afbryder forbindelsen til en node

@@ -5,3 +5,4 @@ OnlineNodeCommand.ShortDescription=Knoten wird wieder f\u00fcr neue Builds verwe

ClearQueueCommand.ShortDescription=Build-Warteschlange l\u00f6schen.

DisconnectNodeCommand.ShortDescription=Knoten trennen.
@@ -55,3 +55,4 @@ OnlineNodeCommand.ShortDescription=Continuar usando un nodo y candelar el comand

ClearQueueCommand.ShortDescription=Limpiar la cola de trabajos

DisconnectNodeCommand.ShortDescription=Desconectarse de un nodo
@@ -77,3 +77,4 @@ OnlineNodeCommand.ShortDescription=\u76f4\u524d\u306b\u5b9f\u884c\u3057\u305f"on

ClearQueueCommand.ShortDescription=\u30d3\u30eb\u30c9\u30ad\u30e5\u30fc\u3092\u30af\u30ea\u30a2\u3057\u307e\u3059\u3002

DisconnectNodeCommand.ShortDescription=\u30ce\u30fc\u30c9\u3068\u306e\u63a5\u7d9a\u3092\u5207\u65ad\u3057\u307e\u3059\u3002
@@ -123,3 +123,4 @@ OnlineNodeCommand.ShortDescription=Continuar usando um n\u00f3 para realizar os

ClearQueueCommand.ShortDescription=Limpa a fila de builds

DisconnectNodeCommand.ShortDescription=Desconectar do n\u00f3
@@ -2,3 +2,4 @@ DeleteNodeCommand.ShortDescription=Deletes a node
DeleteJobCommand.ShortDescription=Deletes a job

ClearQueueCommand.ShortDescription=Clears the build queue

@@ -77,3 +77,5 @@ DeleteNodeCommand.ShortDescription=\u522a\u9664\u6307\u5b9a\u7bc0\u9ede\u3002
DeleteJobCommand.ShortDescription=\u522a\u9664\u4f5c\u696d\u3002

ClearQueueCommand.ShortDescription=\u6e05\u9664\u5efa\u7f6e\u4f47\u5217\u3002

DisconnectNodeCommand.ShortDescription=\u4e2d\u65b7\u8207\u6307\u5b9a\u7bc0\u9ede\u7684\u9023\u7dda\u3002
@@ -93,14 +93,14 @@ Build.post_build_steps_failed=Post-build steps failed
CLI.clear-queue.shortDescription=Clears the build queue.
CLI.disable-job.shortDescription=Disables a job.
CLI.enable-job.shortDescription=Enables a job.
CLI.disconnect-node.shortDescription=Disconnects from a node.
CLI.connect-node.shortDescription=Reconnect to a node.
CLI.offline-node.shortDescription=Stop using a node for performing builds temporarily, until the next "online-node" command.
CLI.wait-node-online.shortDescription=Wait for a node to become online.
CLI.wait-node-offline.shortDescription=Wait for a node to become offline.

Computer.Caption=Agent {0}
Computer.NoSuchSlaveExists=No such agent "{0}" exists. Did you mean "{1}"?
Computer.NoSuchSlaveExistsWithoutAdvice=No such agent "{0}" exists.
Computer.Permissions.Title=Agent
Computer.ExtendedReadPermission.Description=This permission allows users to read agent configuration.
Computer.ConfigurePermission.Description=This permission allows users to configure agents.
@@ -145,8 +145,6 @@ CLI.enable-job.shortDescription=\
\u0412\u043a\u043b\u044e\u0447\u0432\u0430\u043d\u0435 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430.
CLI.delete-node.shortDescription=\
\u0418\u0437\u0442\u0440\u0438\u0432\u0430\u043d\u0435 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430.
CLI.disconnect-node.shortDescription=\
\u041f\u0440\u0435\u043a\u044a\u0441\u0432\u0430\u043d\u0435 \u043d\u0430 \u0432\u0440\u044a\u0437\u043a\u0430\u0442\u0430 \u0441 \u043c\u0430\u0448\u0438\u043d\u0430.
CLI.connect-node.shortDescription=\
\u0421\u0432\u044a\u0440\u0437\u0432\u0430\u043d\u0435 \u043a\u044a\u043c \u043c\u0430\u0448\u0438\u043d\u0430.
CLI.online-node.shortDescription=\
@@ -186,7 +186,6 @@ LoadStatistics.Legends.QueueLength=K\u00f8 l\u00e6ngde
Hudson.ViewName=Alle
Job.BuildStability=Bygge stabilitet: {0}
Job.Pronoun=Projekt
CLI.disconnect-node.shortDescription=Afbryder forbindelsen til en node
CLI.restart.shortDescription=Genstart Jenkins
Permalink.LastStableBuild=Sidste stabile byg
Hudson.NoJavaInPath=Java er ikke i din sti. M\u00e5ske mangler du at <a href=''{0}/configure''>konfigurere JDK</a>?
@@ -80,7 +80,6 @@ CLI.reload-configuration.shortDescription=Alle Daten im Speicher verwerfen und K
CLI.disable-job.shortDescription=Job deaktivieren.
CLI.enable-job.shortDescription=Job aktivieren.
CLI.connect-node.shortDescription=Erneut mit Knoten verbinden.
CLI.disconnect-node.shortDescription=Knoten trennen.
CLI.offline-node.shortDescription=Knoten wird bis zum n\u00e4chsten "online-node"-Kommando f\u00fcr keine neuen Builds verwendet.
CLI.safe-restart.shortDescription=Startet Jenkins neu.
Queue.init=Build-Warteschlange neu initialisieren
@@ -58,7 +58,6 @@ BallColor.Unstable=Inestable

CLI.disable-job.shortDescription=Desactivar una tarea
CLI.enable-job.shortDescription=Activar una tarea
CLI.disconnect-node.shortDescription=Desconectarse de un nodo
CLI.connect-node.shortDescription=Reconectarse con un nodo
CLI.offline-node.shortDescription=Dejar de utilizar un nodo temporalmente hasta que se ejecute el comando "online-node".

@@ -72,7 +72,6 @@ BallColor.Unstable=Instabile

CLI.disable-job.shortDescription=Disabilita un job
CLI.enable-job.shortDescription=Abilita un job
CLI.disconnect-node.shortDescription=Disconnects from a node
CLI.connect-node.shortDescription=Riconnettersi ad un nodo
CLI.offline-node.shortDescription=Stop using a node for performing builds temporarily, until the next "online-node" command.
CLI.wait-node-online.shortDescription=Attende che il nodo sia attivo
@@ -295,7 +295,6 @@ CLI.cancel-quiet-down.shortDescription="quite-down"\u30b3\u30de\u30f3\u30c9\u306
CLI.reload-configuration.shortDescription=\u30e1\u30e2\u30ea\u306b\u3042\u308b\u3059\u3079\u3066\u306e\u30c7\u30fc\u30bf\u3092\u7834\u68c4\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u518d\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u76f4\u63a5\u4fee\u6b63\u3057\u305f\u5834\u5408\u306b\u5f79\u306b\u7acb\u3061\u307e\u3059\u3002
CLI.disable-job.shortDescription=\u30b8\u30e7\u30d6\u3092\u7121\u52b9\u5316\u3057\u307e\u3059\u3002
CLI.enable-job.shortDescription=\u30b8\u30e7\u30d6\u3092\u6709\u52b9\u5316\u3057\u307e\u3059\u3002
CLI.disconnect-node.shortDescription=\u30ce\u30fc\u30c9\u3068\u306e\u63a5\u7d9a\u3092\u5207\u65ad\u3057\u307e\u3059\u3002
CLI.connect-node.shortDescription=\u30ce\u30fc\u30c9\u3068\u518d\u63a5\u7d9a\u3057\u307e\u3059\u3002
CLI.offline-node.shortDescription="online-node"\u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u308b\u307e\u3067\u3001\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3059\u308b\u30ce\u30fc\u30c9\u306e\u4f7f\u7528\u3092\u4e00\u6642\u7684\u306b\u505c\u6b62\u3057\u307e\u3059\u3002
CLI.wait-node-online.shortDescription=\u30ce\u30fc\u30c9\u304c\u30aa\u30f3\u30e9\u30a4\u30f3\u306b\u306a\u308b\u306e\u3092\u5f85\u3061\u307e\u3059\u3002
@@ -302,8 +302,6 @@ Hudson.NotANumber=n\u00e3o \u00e9 um n\u00famero
View.CreatePermission.Description=Permite aos usu\u00e1rios criarem novas views
# Queue length
LoadStatistics.Legends.QueueLength=Comprimento da fila
# Disconnects from a node
CLI.disconnect-node.shortDescription=Desconectar do n\u00f3
# Restart Jenkins
CLI.restart.shortDescription=Reiniciar o Jenkins
# {0} is offline
@@ -62,7 +62,6 @@ BallColor.Unstable=Unstable

CLI.disable-job.shortDescription=Disables a job
CLI.enable-job.shortDescription=Enables a job
CLI.disconnect-node.shortDescription=Disconnects from a node
CLI.connect-node.shortDescription=Reconnect to a node
CLI.online-node.shortDescription=Resume using a node for performing builds, to cancel out the earlier "offline-node" command.
CLI.offline-node.shortDescription=Stop using a node for performing builds temporarily, until the next "online-node" command.
@@ -78,7 +78,6 @@ BallColor.Unstable=\u4e0d\u7a69\u5b9a

CLI.disable-job.shortDescription=\u505c\u7528\u4f5c\u696d\u3002
CLI.enable-job.shortDescription=\u555f\u7528\u4f5c\u696d\u3002
CLI.disconnect-node.shortDescription=\u4e2d\u65b7\u8207\u6307\u5b9a\u7bc0\u9ede\u7684\u9023\u7dda\u3002
CLI.connect-node.shortDescription=\u9023\u7dda\u5230\u6307\u5b9a\u7bc0\u9ede\u3002
CLI.online-node.shortDescription=\u7e7c\u7e8c\u4f7f\u7528\u6307\u5b9a\u7bc0\u9ede\u4f86\u5efa\u7f6e\uff0c\u53d6\u6d88\u5148\u524d\u7684 "offline-node" \u6307\u4ee4\u3002
CLI.offline-node.shortDescription=\u66ab\u6642\u4e0d\u4f7f\u7528\u6307\u5b9a\u7bc0\u9ede\u4f86\u5efa\u7f6e\uff0c\u76f4\u5230\u57f7\u884c "online-node" \u6307\u4ee4\u70ba\u6b62\u3002

0 comments on commit 6feaea8

Please sign in to comment.