From 62ad9f7a11f851ea72daab640bcfe2c68c8f891c Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Fri, 7 May 2021 11:08:05 +0200 Subject: [PATCH 1/2] Terminology update --- README.md | 4 +- .../java/hudson/slaves/CommandConnector.java | 4 +- .../java/hudson/slaves/CommandLauncher.java | 4 +- .../slaves/CommandLauncher/help-command.html | 4 +- .../slaves/CommandLauncher/help.properties | 4 +- .../slaves/CommandLauncher/help_bg.properties | 2 - .../command_launcher/Messages.properties | 2 +- .../hudson/slaves/CommandLauncherTest.java | 42 +++++++++---------- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 3c1bef5..d14d627 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Allows agents to be launched using a specified command. ## Usage -The plugin adds a new agent _Launch method_ which starts an agent by having Jenkins execute a command from the master. -Use this when the master is capable of remotely executing a process on another machine, e.g. via SSH or RSH. +The plugin adds a new agent _Launch method_ which starts an agent by having Jenkins execute a command from the controller. +Use this when the controller is capable of remotely executing a process on another machine, e.g. via SSH or RSH. ![Configuration](/docs/images/command-launcher.png) diff --git a/src/main/java/hudson/slaves/CommandConnector.java b/src/main/java/hudson/slaves/CommandConnector.java index b214cee..05af038 100644 --- a/src/main/java/hudson/slaves/CommandConnector.java +++ b/src/main/java/hudson/slaves/CommandConnector.java @@ -38,7 +38,7 @@ import org.kohsuke.stapler.QueryParameter; /** - * Executes a program on the master and expect that script to connect. + * Executes a program on the controller and expect that script to connect. * * @author Kohsuke Kawaguchi */ @@ -60,7 +60,7 @@ private Object readResolve() { @Override public CommandLauncher launch(String host, TaskListener listener) throws IOException, InterruptedException { // no need to call ScriptApproval.using here; CommandLauncher.launch will do that - return new CommandLauncher(new EnvVars("SLAVE", host), command); + return new CommandLauncher(new EnvVars("SLAVE", host,"AGENT", host), command); } @Extension @Symbol("command") diff --git a/src/main/java/hudson/slaves/CommandLauncher.java b/src/main/java/hudson/slaves/CommandLauncher.java index 4d70be2..0b35560 100644 --- a/src/main/java/hudson/slaves/CommandLauncher.java +++ b/src/main/java/hudson/slaves/CommandLauncher.java @@ -59,7 +59,7 @@ public class CommandLauncher extends ComputerLauncher { /** * Command line to launch the agent, like - * "ssh myslave java -jar /path/to/hudson-remoting.jar" + * "ssh my-agent java -jar /path/to/agent.jar" */ private final String agentCommand; @@ -138,7 +138,7 @@ public void launch(SlaveComputer computer, final TaskListener listener) { ProcessBuilder pb = new ProcessBuilder(Util.tokenize(command)); final EnvVars cookie = _cookie = EnvVars.createCookie(); pb.environment().putAll(cookie); - pb.environment().put("WORKSPACE", StringUtils.defaultString(computer.getAbsoluteRemoteFs(), node.getRemoteFS())); //path for local slave log + pb.environment().put("WORKSPACE", StringUtils.defaultString(computer.getAbsoluteRemoteFs(), node.getRemoteFS())); //path for local agent log {// system defined variables pb.environment().put("NODE_NAME", computer.getName()); diff --git a/src/main/resources/hudson/slaves/CommandLauncher/help-command.html b/src/main/resources/hudson/slaves/CommandLauncher/help-command.html index 55fc869..d375200 100644 --- a/src/main/resources/hudson/slaves/CommandLauncher/help-command.html +++ b/src/main/resources/hudson/slaves/CommandLauncher/help-command.html @@ -1,6 +1,6 @@
Single command to launch an agent program, which controls the agent - computer and communicates with the master. Jenkins assumes that + computer and communicates with the controller. Jenkins assumes that the executed program launches the agent.jar program on the correct machine. @@ -32,7 +32,7 @@

You can use any command to run a process on the agent machine, such as RSH, - as long as stdin/stdout of the process on the master will be connected to + as long as stdin/stdout of the process on the controller will be connected to those of java -jar ~/bin/agent.jar on the agent machine eventually.

diff --git a/src/main/resources/hudson/slaves/CommandLauncher/help.properties b/src/main/resources/hudson/slaves/CommandLauncher/help.properties index ea17495..9c8ee2d 100644 --- a/src/main/resources/hudson/slaves/CommandLauncher/help.properties +++ b/src/main/resources/hudson/slaves/CommandLauncher/help.properties @@ -20,5 +20,5 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -blurb=Starts an agent by having Jenkins execute a command from the master. \ - Use this when the master is capable of remotely executing a process on another machine, e.g. via SSH or RSH. +blurb=Starts an agent by having Jenkins execute a command from the controller. \ + Use this when the controller is capable of remotely executing a process on another machine, e.g. via SSH or RSH. diff --git a/src/main/resources/hudson/slaves/CommandLauncher/help_bg.properties b/src/main/resources/hudson/slaves/CommandLauncher/help_bg.properties index 8efdbd5..00293ab 100644 --- a/src/main/resources/hudson/slaves/CommandLauncher/help_bg.properties +++ b/src/main/resources/hudson/slaves/CommandLauncher/help_bg.properties @@ -20,8 +20,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Starts an agent by having Jenkins execute a command from the master. \ -# Use this when the master is capable of remotely executing a process on another machine, e.g. via SSH or RSH. blurb=\ \u0421\u0442\u0430\u0440\u0442\u0438\u0440\u0430\u043d\u0435 \u043d\u0430 \u0430\u0433\u0435\u043d\u0442 \u043a\u0430\u0442\u043e Jenkins \u0438\u0437\u043f\u044a\u043b\u043d\u044f\u0432\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0432\u0430\u0449\u0438\u044f \u043a\u043e\u043c\u043f\u044e\u0442\u044a\u0440.\ \u041f\u043e\u043b\u0437\u0432\u0430\u0439\u0442\u0435 \u0442\u043e\u0437\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u043e\u0433\u0430\u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0432\u0430\u0449\u0438\u044f\u0442 \u043a\u043e\u043c\u043f\u044e\u0442\u044a\u0440 \u043c\u043e\u0436\u0435 \u0434\u0430 \u0438\u0437\u043f\u044a\u043b\u043d\u044f\u0432\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0438\ diff --git a/src/main/resources/org/jenkinsci/plugins/command_launcher/Messages.properties b/src/main/resources/org/jenkinsci/plugins/command_launcher/Messages.properties index 2901ceb..ab215f8 100644 --- a/src/main/resources/org/jenkinsci/plugins/command_launcher/Messages.properties +++ b/src/main/resources/org/jenkinsci/plugins/command_launcher/Messages.properties @@ -24,5 +24,5 @@ Slave.Launching={0} Launching agent CommandLauncher.unexpectedError=Unexpected error in launching an agent. This is probably a bug in Jenkins CommandLauncher.abortedLaunch=Launching agent process aborted. CommandLauncher.NoLaunchCommand=No launch command specified -CommandLauncher.displayName=Launch agent via execution of command on the master +CommandLauncher.displayName=Launch agent via execution of command on the controller Slave.UnableToLaunch=Unable to launch the agent for {0}{1} diff --git a/src/test/java/hudson/slaves/CommandLauncherTest.java b/src/test/java/hudson/slaves/CommandLauncherTest.java index be7bb94..23c9872 100644 --- a/src/test/java/hudson/slaves/CommandLauncherTest.java +++ b/src/test/java/hudson/slaves/CommandLauncherTest.java @@ -55,10 +55,10 @@ public class CommandLauncherTest { // TODO sometimes gets EOFException as in commandSucceedsWithoutChannel public void commandFails() throws Exception { assumeTrue(!Functions.isWindows()); - DumbSlave slave = createSlaveTimeout("false"); + DumbSlave agent = createAgentTimeout("false"); - String log = slave.toComputer().getLog(); - assertTrue(log, slave.toComputer().isOffline()); + String log = agent.toComputer().getLog(); + assertTrue(log, agent.toComputer().isOffline()); assertThat(log, containsString("ERROR: Process terminated with exit code")); assertThat(log, not(containsString("ERROR: Process terminated with exit code 0"))); } @@ -67,16 +67,16 @@ public void commandFails() throws Exception { @Test public void commandSucceedsWithoutChannel() throws Exception { assumeTrue(!Functions.isWindows()); - DumbSlave slave = createSlaveTimeout("true"); + DumbSlave agent = createAgentTimeout("true"); - String log = slave.toComputer().getLog(); - assertTrue(log, slave.toComputer().isOffline()); + String log = agent.toComputer().getLog(); + assertTrue(log, agent.toComputer().isOffline()); assertThat(log, containsString("ERROR: Process terminated with exit code 0")); } - private static void connectToComputer(DumbSlave slave) { + private static void connectToComputer(DumbSlave agent) { try { - slave.toComputer().connect(false).get(); + agent.toComputer().connect(false).get(); } catch (Exception e) { System.err.println("uninteresting error (not running an actual agent.jar): " + e); } @@ -120,10 +120,10 @@ private void hasEnvVar(String name, String value, String workspacePath) throws E command = posixCommand.format(args); } - DumbSlave slave = createSlave(command, workspacePath); - connectToComputer(slave); + DumbSlave agent = createAgent(command, workspacePath); + connectToComputer(agent); String content = new Scanner(canary).useDelimiter("\\Z").next(); - j.jenkins.removeNode(slave); + j.jenkins.removeNode(agent); assertEquals(value, content); } @@ -132,28 +132,28 @@ private String createWorkspace() throws IOException { return tempDir.getAbsolutePath(); } - public DumbSlave createSlave(String command, String workspacePath) throws Exception { - DumbSlave slave; + public DumbSlave createAgent(String command, String workspacePath) throws Exception { + DumbSlave agent; if (workspacePath == null) workspacePath = createWorkspace(); synchronized (j.jenkins) { // TODO this lock smells like a bug post 1.607 - slave = new DumbSlave("dummy", workspacePath, new CommandLauncher(command)); - j.jenkins.addNode(slave); + agent = new DumbSlave("dummy", workspacePath, new CommandLauncher(command)); + j.jenkins.addNode(agent); } - return slave; + return agent; } - public DumbSlave createSlaveTimeout(String command) throws Exception { - DumbSlave slave = createSlave(command, null); + public DumbSlave createAgentTimeout(String command) throws Exception { + DumbSlave agent = createAgent(command, null); try { - slave.toComputer().connect(false).get(1, TimeUnit.SECONDS); - fail("the slave was not supposed to connect successfully"); + agent.toComputer().connect(false).get(1, TimeUnit.SECONDS); + fail("the agent was not supposed to connect successfully"); } catch (ExecutionException e) { // ignore, we just want to } - return slave; + return agent; } } From 695cc379e5f60c22efd57e068c4235aeb871fcaf Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Fri, 7 May 2021 16:10:55 +0200 Subject: [PATCH 2/2] Update src/main/java/hudson/slaves/CommandConnector.java Co-authored-by: Jesse Glick --- src/main/java/hudson/slaves/CommandConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hudson/slaves/CommandConnector.java b/src/main/java/hudson/slaves/CommandConnector.java index 05af038..6cb5311 100644 --- a/src/main/java/hudson/slaves/CommandConnector.java +++ b/src/main/java/hudson/slaves/CommandConnector.java @@ -60,7 +60,7 @@ private Object readResolve() { @Override public CommandLauncher launch(String host, TaskListener listener) throws IOException, InterruptedException { // no need to call ScriptApproval.using here; CommandLauncher.launch will do that - return new CommandLauncher(new EnvVars("SLAVE", host,"AGENT", host), command); + return new CommandLauncher(new EnvVars("SLAVE", host, "AGENT", host), command); } @Extension @Symbol("command")