Skip to content

Commit

Permalink
Merge pull request #19 from Vlatombe/BEE-2435
Browse files Browse the repository at this point in the history
[JENKINS-65398] Terminology update
  • Loading branch information
jglick authored May 7, 2021
2 parents f8e1162 + 695cc37 commit 21744c9
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/slaves/CommandConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/slaves/CommandLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div>
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 <code>agent.jar</code> program on the correct
machine.

Expand Down Expand Up @@ -32,7 +32,7 @@

<p>
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 <code>java -jar ~/bin/agent.jar</code> on the agent machine eventually.
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
42 changes: 21 additions & 21 deletions src/test/java/hudson/slaves/CommandLauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
}

0 comments on commit 21744c9

Please sign in to comment.