diff --git a/core/src/main/java/hudson/cli/ConnectNodeCommand.java b/core/src/main/java/hudson/cli/ConnectNodeCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..cd3a3bf8f96703d29dba6d3d5f1db4c397a353aa --- /dev/null +++ b/core/src/main/java/hudson/cli/ConnectNodeCommand.java @@ -0,0 +1,107 @@ +/* + * The MIT License + * + * Copyright (c) 2015 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 org.acegisecurity.AccessDeniedException; +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 ConnectNodeCommand extends CLICommand { + + @Argument(metaVar="NAME", usage="Slave name, or empty string for master; comama-separated list is supported", required=true, multiValued=true) + private List nodes; + + @Option(name="-f", usage="Cancel any currently pending connect operation and retry from scratch") + public boolean force = false; + + private static final Logger LOGGER = Logger.getLogger(ConnectNodeCommand.class.getName()); + + @Override + public String getShortDescription() { + return Messages.ConnectNodeCommand_ShortDescription(); + } + + @Override + protected int run() throws Exception { + boolean errorOccurred = false; + final Jenkins jenkins = Jenkins.getActiveInstance(); + + final HashSet hs = new HashSet(); + hs.addAll(nodes); + + List 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(); + 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.cliConnect(force); + } catch (Exception e) { + if (hs.size() == 1) { + throw e; + } + + final String errorMsg = String.format(node_s + ": " + e.getMessage()); + stderr.println(errorMsg); + errorOccurred = true; + continue; + } + } + + if (errorOccurred) { + throw new AbortException("Error occured while performing this command, see previous stderr output."); + } + return 0; + } +} diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 58f1dc10d7052808bd43bd0c8807633843a87709..3fbab43fe2355c4d628e47afb1662182b7761be9 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -448,10 +448,13 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces protected abstract Future _connect(boolean forceReconnect); /** - * CLI command to reconnect this node. + * @deprecated Implementation of CLI command "connect-node" moved to {@link hudson.cli.ConnectNodeCommand}. + * + * @param force + * If true cancel any currently pending connect operation and retry from scratch */ - @CLIMethod(name="connect-node") - public void cliConnect(@Option(name="-f",usage="Cancel any currently pending connect operation and retry from scratch") boolean force) throws ExecutionException, InterruptedException { + @Deprecated + public void cliConnect(boolean force) throws ExecutionException, InterruptedException { checkPermission(CONNECT); connect(force).get(); } diff --git a/core/src/main/resources/hudson/cli/Messages.properties b/core/src/main/resources/hudson/cli/Messages.properties index 985f6f78c255fc1ac1e037057815231a14ba99fe..cdced417b87e3ec34179c42c59b3c0a2d65ff4ff 100644 --- a/core/src/main/resources/hudson/cli/Messages.properties +++ b/core/src/main/resources/hudson/cli/Messages.properties @@ -82,12 +82,9 @@ BuildCommand.CLICause.CannotBuildUnknownReasons=\ Cannot build {0} for unknown reasons. DeleteNodeCommand.ShortDescription=Deletes node(s) - ReloadJobCommand.ShortDescription=Reload job(s) - OnlineNodeCommand.ShortDescription=Resume using a node for performing builds, to cancel out the earlier "offline-node" command. - ClearQueueCommand.ShortDescription=Clears the build queue. ReloadConfigurationCommand.ShortDescription=Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk. - +ConnectNodeCommand.ShortDescription=Reconnect to a node(s) DisconnectNodeCommand.ShortDescription=Disconnects from a node. diff --git a/core/src/main/resources/hudson/cli/Messages_da.properties b/core/src/main/resources/hudson/cli/Messages_da.properties index 24c7ecb750073a090a1733a22c95c2b87d42af49..a37d4248aab092a61c8dffeb02e5d3c5950951ad 100644 --- a/core/src/main/resources/hudson/cli/Messages_da.properties +++ b/core/src/main/resources/hudson/cli/Messages_da.properties @@ -1,11 +1,8 @@ DeleteNodeCommand.ShortDescription=Sletter en node DeleteJobCommand.ShortDescription=Sletter et job - OnlineNodeCommand.ShortDescription=Genoptag brugen af en byggenode, for at annullere en tidligere udstedt "offline-node" kommando. - ClearQueueCommand.ShortDescription=Ryd byggek\u00f8en ReloadConfigurationCommand.ShortDescription=Genindl\u00e6s alle data fra filsystemet. \ Nyttigt hvis du har modificeret konfigurationsfiler direkte, udenom Jenkins. - DisconnectNodeCommand.ShortDescription=Afbryder forbindelsen til en node - +ConnectNodeCommand.ShortDescription=Gentilslut en node diff --git a/core/src/main/resources/hudson/cli/Messages_de.properties b/core/src/main/resources/hudson/cli/Messages_de.properties index 2d54e32d1dcc1583d31b5baf5fff6b81da070d05..1ff6c4d60f28ad9f342b453fd140b5eab4b1c2e7 100644 --- a/core/src/main/resources/hudson/cli/Messages_de.properties +++ b/core/src/main/resources/hudson/cli/Messages_de.properties @@ -1,9 +1,7 @@ DeleteNodeCommand.ShortDescription=Knoten l\u00f6schen. DeleteJobCommand.ShortDescription=Job l\u00f6schen. - OnlineNodeCommand.ShortDescription=Knoten wird wieder f\u00fcr neue Builds verwendet. Hebt ein vorausgegangenes "offline-node"-Kommando auf. - ClearQueueCommand.ShortDescription=Build-Warteschlange l\u00f6schen. ReloadConfigurationCommand.ShortDescription=Alle Daten im Speicher verwerfen und Konfiguration neu von Festplatte laden. Dies ist n\u00fctzlich, wenn Sie \u00c4nderungen direkt im Dateisystem vorgenommen haben. - +ConnectNodeCommand.ShortDescription=Erneut mit Knoten verbinden. DisconnectNodeCommand.ShortDescription=Knoten trennen. diff --git a/core/src/main/resources/hudson/cli/Messages_es.properties b/core/src/main/resources/hudson/cli/Messages_es.properties index 74544043bd46f892809b39821b0078c6918c90e1..d99af615061548d4f87ab0df62252f1918f4b122 100644 --- a/core/src/main/resources/hudson/cli/Messages_es.properties +++ b/core/src/main/resources/hudson/cli/Messages_es.properties @@ -48,12 +48,9 @@ UpdateJobCommand.ShortDescription=Actualiza el fichero XML de la definici GroovyshCommand.ShortDescription=Ejecuta una shell interactiva de groovy. SetBuildDescriptionCommand.ShortDescription=Establece la descripción de una ejecución. DeleteJobCommand.ShortDescription=Borrar una tarea - DeleteNodeCommand.ShortDescription=Borrar un nodo - OnlineNodeCommand.ShortDescription=Continuar usando un nodo y candelar el comando "offline-node" mas reciente. - ClearQueueCommand.ShortDescription=Limpiar la cola de trabajos ReloadConfigurationCommand.ShortDescription=Descartar todos los datos presentes en memoria y recargar todo desde el disco duro. \u00datil cuando se han hecho modificaciones a mano en el disco duro. - +ConnectNodeCommand.ShortDescription=Reconectarse con un nodo DisconnectNodeCommand.ShortDescription=Desconectarse de un nodo diff --git a/core/src/main/resources/hudson/cli/Messages_it.properties b/core/src/main/resources/hudson/cli/Messages_it.properties index e7c801919afc68f346bc7f46fb0f5b208a02f10c..0b7c38c2b649808951306431b43d5cefe6cc2cfb 100644 --- a/core/src/main/resources/hudson/cli/Messages_it.properties +++ b/core/src/main/resources/hudson/cli/Messages_it.properties @@ -1,8 +1,6 @@ DeleteNodeCommand.ShortDescription=Cancella un nodo DeleteJobCommand.ShortDescription=Cancella un job - OnlineNodeCommand.ShortDescription=Resume using a node for performing builds, to cancel out the earlier "offline-node" command. - ClearQueueCommand.ShortDescription=Pulisce la coda di lavoro ReloadConfigurationCommand.ShortDescription=Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk. - +ConnectNodeCommand.ShortDescription=Riconnettersi ad un nodo diff --git a/core/src/main/resources/hudson/cli/Messages_ja.properties b/core/src/main/resources/hudson/cli/Messages_ja.properties index b51f1edfd78b2c52ccbc5c0ee6b598c0cbafff46..6ceaaf61a525a82269b6bcbc00637a897de9a924 100644 --- a/core/src/main/resources/hudson/cli/Messages_ja.properties +++ b/core/src/main/resources/hudson/cli/Messages_ja.properties @@ -69,13 +69,10 @@ BuildCommand.CLICause.CannotBuildConfigNotSaved=\ \u8a2d\u5b9a\u304c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067{0}\u3092\u30d3\u30eb\u30c9\u3067\u304d\u307e\u305b\u3093\u3002 BuildCommand.CLICause.CannotBuildUnknownReasons=\ \u30d3\u30eb\u30c9\u3067\u304d\u307e\u305b\u3093(\u539f\u56e0\u4e0d\u660e)\u3002 - DeleteNodeCommand.ShortDescription=\u30ce\u30fc\u30c9\u3092\u524a\u9664\u3057\u307e\u3059\u3002 DeleteJobCommand.ShortDescription=\u30b8\u30e7\u30d6\u3092\u524a\u9664\u3057\u307e\u3059\u3002 - OnlineNodeCommand.ShortDescription=\u76f4\u524d\u306b\u5b9f\u884c\u3057\u305f"online-node"\u30b3\u30de\u30f3\u30c9\u3092\u53d6\u308a\u6d88\u3057\u3001\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3059\u308b\u30ce\u30fc\u30c9\u306e\u4f7f\u7528\u3092\u518d\u958b\u3057\u307e\u3059\u3002 - ClearQueueCommand.ShortDescription=\u30d3\u30eb\u30c9\u30ad\u30e5\u30fc\u3092\u30af\u30ea\u30a2\u3057\u307e\u3059\u3002 ReloadConfigurationCommand.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 - +ConnectNodeCommand.ShortDescription=\u30ce\u30fc\u30c9\u3068\u518d\u63a5\u7d9a\u3057\u307e\u3059\u3002 DisconnectNodeCommand.ShortDescription=\u30ce\u30fc\u30c9\u3068\u306e\u63a5\u7d9a\u3092\u5207\u65ad\u3057\u307e\u3059\u3002 diff --git a/core/src/main/resources/hudson/cli/Messages_pt_BR.properties b/core/src/main/resources/hudson/cli/Messages_pt_BR.properties index 9d878637a00e363f1430792a3a8142ea902e6b56..afaaeb04356ba28fc046ebd82b1a73a4a37d3229 100644 --- a/core/src/main/resources/hudson/cli/Messages_pt_BR.properties +++ b/core/src/main/resources/hudson/cli/Messages_pt_BR.properties @@ -115,14 +115,10 @@ InstallPluginCommand.ShortDescription=Instala um plugin a partir de um arquivo, CLI.delete-node.shortDescription=Remover o n\u00f3 # Deletes a job DeleteJobCommand.ShortDescription=Remover uma job(s) - -ReloadJobCommand.ShortDescription=\ - Recarrega job(s) do disco. - +ReloadJobCommand.ShortDescription=Recarrega job(s) do disco. OnlineNodeCommand.ShortDescription=Continuar usando um n\u00f3 para realizar os builds - ClearQueueCommand.ShortDescription=Limpa a fila de builds ReloadConfigurationCommand.ShortDescription=Descarta todo o conte\u00fado de mem\u00f3ria e recarrega novamente a partir do arquivo. \ Indicado quando voc\u00ea modificou os arquivos diretamente no disco. - +ConnectNodeCommand.ShortDescription=Reconectar ao n\u00f3 DisconnectNodeCommand.ShortDescription=Desconectar do n\u00f3 diff --git a/core/src/main/resources/hudson/cli/Messages_zh_CN.properties b/core/src/main/resources/hudson/cli/Messages_zh_CN.properties index a36bb8e9a61847474d82a914d73d1397576d0108..5447072c0725192335dae835a2b585178d026e77 100644 --- a/core/src/main/resources/hudson/cli/Messages_zh_CN.properties +++ b/core/src/main/resources/hudson/cli/Messages_zh_CN.properties @@ -3,3 +3,4 @@ DeleteJobCommand.ShortDescription=Deletes a job ClearQueueCommand.ShortDescription=Clears the build queue ReloadConfigurationCommand.ShortDescription=Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk. +ConnectNodeCommand.ShortDescription=Reconnect to a node diff --git a/core/src/main/resources/hudson/cli/Messages_zh_TW.properties b/core/src/main/resources/hudson/cli/Messages_zh_TW.properties index d422030cf3517f1a3ea656c2e6d1eff4cc5a39f7..a8a573ea8ffc8ac738d3fb2758dceb82e99cdc5d 100644 --- a/core/src/main/resources/hudson/cli/Messages_zh_TW.properties +++ b/core/src/main/resources/hudson/cli/Messages_zh_TW.properties @@ -75,7 +75,7 @@ BuildCommand.CLICause.ShortDescription=\u7531 {0} \u7684\u547d\u4ee4\u5217\u4ecb 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 ReloadConfigurationCommand.ShortDescription=\u653e\u68c4\u6240\u6709\u8a18\u61b6\u9ad4\u88e1\u7684\u8cc7\u6599\uff0c\u7531\u6a94\u6848\u7cfb\u7d71\u4e2d\u91cd\u65b0\u8f09\u5165\u3002\u9069\u5408\u5728\u76f4\u63a5\u4fee\u6539\u8a2d\u5b9a\u6a94\u5f8c\u4f7f\u7528\u3002 +ConnectNodeCommand.ShortDescription=\u9023\u7dda\u5230\u6307\u5b9a\u7bc0\u9ede\u3002 diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index 062e96e5d287ee79cf03148aba38456adbd57cef..3e99de7cc11471576cf97b0f61c91fbd375d207d 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -93,7 +93,7 @@ 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.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. CLI.wait-node-online.shortDescription=Wait for a node to become online. CLI.wait-node-offline.shortDescription=Wait for a node to become offline. diff --git a/core/src/main/resources/hudson/model/Messages_bg.properties b/core/src/main/resources/hudson/model/Messages_bg.properties index 1a7096f590e668744dd9780b77f310d3b3363136..1262f9fad61b7953f1edc8dcafab3fd1b535db07 100644 --- a/core/src/main/resources/hudson/model/Messages_bg.properties +++ b/core/src/main/resources/hudson/model/Messages_bg.properties @@ -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.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=\ \u041e\u0442\u043d\u043e\u0432\u043e \u0434\u0430 \u0441\u0435 \u043f\u043e\u043b\u0437\u0432\u0430 \u043c\u0430\u0448\u0438\u043d\u0430 \u0437\u0430 \u0438\u0437\u0433\u0440\u0430\u0436\u0434\u0430\u043d\u0438\u044f. \u041e\u0442\u043c\u0435\u043d\u044f\u043d\u0435 \u043d\u0430 \u043f\u0440\u0435\u0434\u0445\u043e\u0434\u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\ \u201eoffline-node\u201c. diff --git a/core/src/main/resources/hudson/model/Messages_da.properties b/core/src/main/resources/hudson/model/Messages_da.properties index 630e3ed9c649911c927f3c9ddb93c30068902554..430b3cef93d86352a606ac29f0ce5f7b3b15aebe 100644 --- a/core/src/main/resources/hudson/model/Messages_da.properties +++ b/core/src/main/resources/hudson/model/Messages_da.properties @@ -54,7 +54,6 @@ UpdateCenter.Status.Success=Succes ParameterAction.DisplayName=Parametre UpdateCenter.init=Initialiserer opdateringscenteret ComputerSet.DisplayName=noder -CLI.connect-node.shortDescription=Gentilslut en node Run.DeletePermission.Description=Denne tilladelse g\u00f8r det muligt for brugerne at slette specifikke byg i byggehistorikken. Run.Summary.BrokenForALongTime=fejlet l\u00e6nge CLI.safe-restart.shortDescription=Sikker genstart af Jenkins diff --git a/core/src/main/resources/hudson/model/Messages_de.properties b/core/src/main/resources/hudson/model/Messages_de.properties index d57981c32808049258128937a1fa5b57a21e4ffd..68a066a22c632b4d703c5184759a81a6ea8afb3a 100644 --- a/core/src/main/resources/hudson/model/Messages_de.properties +++ b/core/src/main/resources/hudson/model/Messages_de.properties @@ -80,7 +80,7 @@ CLI.reload-configuration.shortDescription=Alle Daten im Speicher verwerfen und K CLI.clear-queue.shortDescription=Build-Warteschlange l\u00f6schen. 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 diff --git a/core/src/main/resources/hudson/model/Messages_es.properties b/core/src/main/resources/hudson/model/Messages_es.properties index 5fdcb09530df1a167c80248baa03fe3fed60ea21..bacab5ad9f00a049a4f18c87b9c149c5ec61f2fb 100644 --- a/core/src/main/resources/hudson/model/Messages_es.properties +++ b/core/src/main/resources/hudson/model/Messages_es.properties @@ -58,7 +58,7 @@ BallColor.Unstable=Inestable CLI.disable-job.shortDescription=Desactivar una tarea CLI.enable-job.shortDescription=Activar una tarea -CLI.connect-node.shortDescription=Reconectarse con un nodo +CLI.online-node.shortDescription=Continuar usando un nodo y candelar el comando "offline-node" mas reciente. CLI.offline-node.shortDescription=Dejar de utilizar un nodo temporalmente hasta que se ejecute el comando "online-node". Computer.Caption=Remoto {0} diff --git a/core/src/main/resources/hudson/model/Messages_it.properties b/core/src/main/resources/hudson/model/Messages_it.properties index ce28f41835b877fe66dd7af52e9c2c37c7479e95..f197229ed0a37d012581a4bfcf5fe5168ca58989 100644 --- a/core/src/main/resources/hudson/model/Messages_it.properties +++ b/core/src/main/resources/hudson/model/Messages_it.properties @@ -72,7 +72,7 @@ BallColor.Unstable=Instabile CLI.disable-job.shortDescription=Disabilita un job CLI.enable-job.shortDescription=Abilita un job -CLI.connect-node.shortDescription=Riconnettersi ad un nodo +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. CLI.wait-node-online.shortDescription=Attende che il nodo sia attivo CLI.wait-node-offline.shortDescription=Attende che un nodo sia disattivo diff --git a/core/src/main/resources/hudson/model/Messages_ja.properties b/core/src/main/resources/hudson/model/Messages_ja.properties index c14d955daeb5490dfb951da14458edcdc90220e7..470c1f21033981c349364b8ad9a8d5c3e6e1dbcd 100644 --- a/core/src/main/resources/hudson/model/Messages_ja.properties +++ b/core/src/main/resources/hudson/model/Messages_ja.properties @@ -296,7 +296,7 @@ CLI.reload-configuration.shortDescription=\u30e1\u30e2\u30ea\u306b\u3042\u308b\u CLI.clear-queue.shortDescription=\u30d3\u30eb\u30c9\u30ad\u30e5\u30fc\u3092\u30af\u30ea\u30a2\u3057\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.connect-node.shortDescription=\u30ce\u30fc\u30c9\u3068\u518d\u63a5\u7d9a\u3057\u307e\u3059\u3002 +CLI.online-node.shortDescription=\u76f4\u524d\u306b\u5b9f\u884c\u3057\u305f"online-node"\u30b3\u30de\u30f3\u30c9\u3092\u53d6\u308a\u6d88\u3057\u3001\u30d3\u30eb\u30c9\u3092\u5b9f\u884c\u3059\u308b\u30ce\u30fc\u30c9\u306e\u4f7f\u7528\u3092\u518d\u958b\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 CLI.wait-node-offline.shortDescription=\u30ce\u30fc\u30c9\u304c\u30aa\u30d5\u30e9\u30a4\u30f3\u306b\u306a\u308b\u306e\u3092\u5f85\u3061\u307e\u3059\u3002 diff --git a/core/src/main/resources/hudson/model/Messages_lt.properties b/core/src/main/resources/hudson/model/Messages_lt.properties index 9dd82f067e7f97708c2a606d497c3e79dcf68616..4cb96beb1e65f991c0376a72e2fe11481c35bd93 100644 --- a/core/src/main/resources/hudson/model/Messages_lt.properties +++ b/core/src/main/resources/hudson/model/Messages_lt.properties @@ -70,7 +70,6 @@ CLI.clear-queue.shortDescription=I\u0161valo vykdymo eil\u0119. CLI.disable-job.shortDescription=I\u0161jungia darb\u0105. CLI.enable-job.shortDescription=\u012ejungia darb\u0105. CLI.disconnect-node.shortDescription=Atsijungia nuo mazgo. -CLI.connect-node.shortDescription=I\u0161 naujo prisijungti prie mazgo. CLI.offline-node.shortDescription=Laikinai nebenaudoti mazgo darb\u0173 vykdymui, kol bus \u012fvykdyta kita \u201emazgas \u012fjungtas\u201c komanda. CLI.wait-node-online.shortDescription=Laukti, kol mazgas prisijungs. CLI.wait-node-offline.shortDescription=Laukti, kol mazgas atsijungs. diff --git a/core/src/main/resources/hudson/model/Messages_pt_BR.properties b/core/src/main/resources/hudson/model/Messages_pt_BR.properties index b108d0f52f3fb0a78a8c5c52a5217de68040a00b..43e5faa411009586e47051bf8ada0a54b7a50928 100644 --- a/core/src/main/resources/hudson/model/Messages_pt_BR.properties +++ b/core/src/main/resources/hudson/model/Messages_pt_BR.properties @@ -135,8 +135,6 @@ UpdateCenter.Status.Success=Sucesso UpdateCenter.init=Iniciando o Update Center # Parameters ParameterAction.DisplayName=Par\u00e2metros -# Reconnect to a node -CLI.connect-node.shortDescription=Reconectar ao n\u00f3 # nodes ComputerSet.DisplayName=N\u00f3s # \ diff --git a/core/src/main/resources/hudson/model/Messages_zh_CN.properties b/core/src/main/resources/hudson/model/Messages_zh_CN.properties index 83f27e43833d7c45ddc4409586d17c33c0d2ec8a..97493359c63512d22ff5ef0ae614a74340e827b9 100644 --- a/core/src/main/resources/hudson/model/Messages_zh_CN.properties +++ b/core/src/main/resources/hudson/model/Messages_zh_CN.properties @@ -62,7 +62,7 @@ BallColor.Unstable=Unstable CLI.disable-job.shortDescription=Disables a job CLI.enable-job.shortDescription=Enables a job -CLI.connect-node.shortDescription=Reconnect to a node +CLI.disconnect-node.shortDescription=Disconnects from 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. diff --git a/core/src/main/resources/hudson/model/Messages_zh_TW.properties b/core/src/main/resources/hudson/model/Messages_zh_TW.properties index bde8bb7bc101c143d99a0cb22e26f1afce5723df..77e1f44b1d6e3c1cf1157d6fc4a5c09cbb528586 100644 --- a/core/src/main/resources/hudson/model/Messages_zh_TW.properties +++ b/core/src/main/resources/hudson/model/Messages_zh_TW.properties @@ -78,7 +78,7 @@ BallColor.Unstable=\u4e0d\u7a69\u5b9a CLI.disable-job.shortDescription=\u505c\u7528\u4f5c\u696d\u3002 CLI.enable-job.shortDescription=\u555f\u7528\u4f5c\u696d\u3002 -CLI.connect-node.shortDescription=\u9023\u7dda\u5230\u6307\u5b9a\u7bc0\u9ede\u3002 +CLI.disconnect-node.shortDescription=\u4e2d\u65b7\u8207\u6307\u5b9a\u7bc0\u9ede\u7684\u9023\u7dda\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 CLI.wait-node-online.shortDescription=\u7b49\u5019\u6307\u5b9a\u7bc0\u9ede\u4e0a\u7dda\u3002 diff --git a/test/src/test/java/hudson/cli/ConnectNodeCommandTest.java b/test/src/test/java/hudson/cli/ConnectNodeCommandTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d35aef81c25a3e8cba5e332f392cf31255314564 --- /dev/null +++ b/test/src/test/java/hudson/cli/ConnectNodeCommandTest.java @@ -0,0 +1,191 @@ +/* + * The MIT License + * + * Copyright 2015 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. + */ + +/** + * @author pjanouse + */ + +package hudson.cli; + +import hudson.model.Computer; +import hudson.slaves.DumbSlave; +import jenkins.model.Jenkins; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; + +import static hudson.cli.CLICommandInvoker.Matcher.failedWith; +import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput; +import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; + +public class ConnectNodeCommandTest { + + private CLICommandInvoker command; + + @Rule public final JenkinsRule j = new JenkinsRule(); + + @Before public void setUp() { + command = new CLICommandInvoker(j, "connect-node"); + } + + @Test public void connectNodeShouldFailWithoutComputerConnectPermission() throws Exception { + j.createSlave("aNode", "", null); + + final CLICommandInvoker.Result result = command + .authorizedTo(Jenkins.READ) + .invokeWithArgs("aNode"); + assertThat(result, failedWith(6)); + assertThat(result, hasNoStandardOutput()); + assertThat(result.stderr(), containsString("ERROR: user is missing the Agent/Connect permission")); + assertThat(result.stderr(), not(containsString("ERROR: Error occured while performing this command, see previous stderr output."))); + } + + @Test public void connectNodeShouldFailIfNodeDoesNotExist() throws Exception { + final CLICommandInvoker.Result result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("never_created"); + assertThat(result, failedWith(3)); + assertThat(result, hasNoStandardOutput()); + assertThat(result.stderr(), containsString("ERROR: No such agent \"never_created\" exists.")); + assertThat(result.stderr(), not(containsString("ERROR: Error occured while performing this command, see previous stderr output."))); + } + + @Test public void connectNodeShouldSucceed() throws Exception { + DumbSlave slave = j.createSlave("aNode", "", null); + + CLICommandInvoker.Result result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("aNode"); + assertThat(result, succeededSilently()); + assertThat(slave.toComputer().isOnline(), equalTo(true)); + + result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("aNode"); + assertThat(result, succeededSilently()); + assertThat(slave.toComputer().isOnline(), equalTo(true)); + + slave.toComputer().disconnect(); + slave.toComputer().waitUntilOffline(); + assertThat(slave.toComputer().isOnline(), equalTo(false)); + assertThat(slave.toComputer().isOffline(), equalTo(true)); + + result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("aNode"); + assertThat(result, succeededSilently()); + assertThat(slave.toComputer().isOnline(), equalTo(true)); + } + + @Test public void connectNodeShouldSucceedWithForce() throws Exception { + DumbSlave slave = j.createSlave("aNode", "", null); + + CLICommandInvoker.Result result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("-f", "aNode"); + assertThat(result, succeededSilently()); + assertThat(slave.toComputer().isOnline(), equalTo(true)); + + result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("-f", "aNode"); + assertThat(result, succeededSilently()); + assertThat(slave.toComputer().isOnline(), equalTo(true)); + + slave.toComputer().disconnect(); + slave.toComputer().waitUntilOffline(); + assertThat(slave.toComputer().isOnline(), equalTo(false)); + assertThat(slave.toComputer().isOffline(), equalTo(true)); + + result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("-f", "aNode"); + assertThat(result, succeededSilently()); + assertThat(slave.toComputer().isOnline(), equalTo(true)); + } + + @Test public void connectNodeManyShouldSucceed() throws Exception { + DumbSlave slave1 = j.createSlave("aNode1", "", null); + DumbSlave slave2 = j.createSlave("aNode2", "", null); + DumbSlave slave3 = j.createSlave("aNode3", "", null); + + final CLICommandInvoker.Result result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("aNode1", "aNode2", "aNode3"); + assertThat(result, succeededSilently()); + assertThat(slave1.toComputer().isOnline(), equalTo(true)); + assertThat(slave2.toComputer().isOnline(), equalTo(true)); + assertThat(slave3.toComputer().isOnline(), equalTo(true)); + } + + + @Test public void connectNodeManyShouldFailIfANodeDoesNotExist() throws Exception { + DumbSlave slave1 = j.createSlave("aNode1", "", null); + DumbSlave slave2 = j.createSlave("aNode2", "", null); + + final CLICommandInvoker.Result result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("aNode1", "aNode2", "never_created"); + assertThat(result, failedWith(5)); + assertThat(result, hasNoStandardOutput()); + assertThat(result.stderr(), containsString("never_created: No such agent \"never_created\" exists. Did you mean \"aNode1\"?")); + assertThat(result.stderr(), containsString("ERROR: Error occured while performing this command, see previous stderr output.")); + assertThat(slave1.toComputer().isOnline(), equalTo(true)); + assertThat(slave2.toComputer().isOnline(), equalTo(true)); + } + + @Test public void connectNodeManyShouldSucceedEvenANodeIsSpecifiedTwice() throws Exception { + DumbSlave slave1 = j.createSlave("aNode1", "", null); + DumbSlave slave2 = j.createSlave("aNode2", "", null); + + final CLICommandInvoker.Result result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs("aNode1", "aNode2", "aNode1"); + assertThat(result, succeededSilently()); + assertThat(slave1.toComputer().isOnline(), equalTo(true)); + assertThat(slave2.toComputer().isOnline(), equalTo(true)); + } + + @Test public void connectNodeShouldSucceedOnMaster() throws Exception { + final Computer masterComputer = j.jenkins.getActiveInstance().getComputer(""); + + CLICommandInvoker.Result result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs(""); + assertThat(result, succeededSilently()); + assertThat(masterComputer.isOnline(), equalTo(true)); + + result = command + .authorizedTo(Computer.CONNECT, Jenkins.READ) + .invokeWithArgs(""); + assertThat(result, succeededSilently()); + assertThat(masterComputer.isOnline(), equalTo(true)); + } +}