Skip to content

Commit a346a5f

Browse files
author
Max Shaposhnik
authored
CHE-3621 Move SSH machine implementation to separate plugin (eclipse-che#3946)
1 parent 24b11c3 commit a346a5f

13 files changed

Lines changed: 445 additions & 299 deletions

File tree

agents/exec/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@
4848
<groupId>org.eclipse.che.core</groupId>
4949
<artifactId>che-core-api-machine</artifactId>
5050
</dependency>
51-
<dependency>
52-
<groupId>org.eclipse.che.core</groupId>
53-
<artifactId>che-core-api-workspace</artifactId>
54-
</dependency>
55-
<dependency>
56-
<groupId>org.slf4j</groupId>
57-
<artifactId>slf4j-api</artifactId>
58-
</dependency>
5951
</dependencies>
6052
<build>
6153
<plugins>

agents/exec/src/main/java/org/eclipse/che/api/agent/SshMachineExecAgentLauncher.java

Lines changed: 0 additions & 134 deletions
This file was deleted.

assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.eclipse.che.api.agent.LSTypeScriptAgent;
2424
import org.eclipse.che.api.agent.SshAgent;
2525
import org.eclipse.che.api.agent.SshAgentLauncher;
26-
import org.eclipse.che.api.agent.SshMachineExecAgentLauncher;
2726
import org.eclipse.che.api.agent.UnisonAgent;
2827
import org.eclipse.che.api.agent.WsAgent;
2928
import org.eclipse.che.api.agent.WsAgentLauncher;
@@ -136,7 +135,6 @@ protected void configure() {
136135
Multibinder<AgentLauncher> launchers = Multibinder.newSetBinder(binder(), AgentLauncher.class);
137136
launchers.addBinding().to(WsAgentLauncher.class);
138137
launchers.addBinding().to(ExecAgentLauncher.class);
139-
launchers.addBinding().to(SshMachineExecAgentLauncher.class);
140138
launchers.addBinding().to(SshAgentLauncher.class);
141139

142140
bindConstant().annotatedWith(Names.named("machine.ws_agent.run_command"))

plugins/plugin-ssh-machine/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
<groupId>com.google.code.gson</groupId>
3131
<artifactId>gson</artifactId>
3232
</dependency>
33+
<dependency>
34+
<groupId>com.google.guava</groupId>
35+
<artifactId>guava</artifactId>
36+
</dependency>
3337
<dependency>
3438
<groupId>com.google.inject</groupId>
3539
<artifactId>guice</artifactId>
@@ -54,6 +58,10 @@
5458
<groupId>javax.ws.rs</groupId>
5559
<artifactId>javax.ws.rs-api</artifactId>
5660
</dependency>
61+
<dependency>
62+
<groupId>org.eclipse.che.core</groupId>
63+
<artifactId>che-core-api-agent-shared</artifactId>
64+
</dependency>
5765
<dependency>
5866
<groupId>org.eclipse.che.core</groupId>
5967
<artifactId>che-core-api-core</artifactId>
@@ -66,6 +74,10 @@
6674
<groupId>org.eclipse.che.core</groupId>
6775
<artifactId>che-core-api-model</artifactId>
6876
</dependency>
77+
<dependency>
78+
<groupId>org.eclipse.che.core</groupId>
79+
<artifactId>che-core-api-workspace</artifactId>
80+
</dependency>
6981
<dependency>
7082
<groupId>org.eclipse.che.core</groupId>
7183
<artifactId>che-core-commons-annotations</artifactId>
@@ -74,6 +86,10 @@
7486
<groupId>org.eclipse.che.core</groupId>
7587
<artifactId>che-core-commons-lang</artifactId>
7688
</dependency>
89+
<dependency>
90+
<groupId>org.slf4j</groupId>
91+
<artifactId>slf4j-api</artifactId>
92+
</dependency>
7793
<dependency>
7894
<groupId>ch.qos.logback</groupId>
7995
<artifactId>logback-classic</artifactId>

plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineFactory.java

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,38 @@
1010
*******************************************************************************/
1111
package org.eclipse.che.plugin.machine.ssh;
1212

13-
import com.google.inject.assistedinject.Assisted;
13+
import com.jcraft.jsch.JSch;
1414

1515
import org.eclipse.che.api.core.model.machine.Command;
1616
import org.eclipse.che.api.core.model.machine.Machine;
17+
import org.eclipse.che.api.core.model.machine.ServerConf;
1718
import org.eclipse.che.api.core.util.LineConsumer;
1819
import org.eclipse.che.api.machine.server.exception.MachineException;
19-
import org.eclipse.che.api.machine.server.spi.Instance;
20+
import org.eclipse.che.plugin.machine.ssh.jsch.JschSshClient;
2021

22+
import javax.inject.Inject;
23+
import javax.inject.Named;
2124
import java.util.Map;
25+
import java.util.Set;
2226

2327
/**
2428
* Provides ssh machine implementation instances.
2529
*
2630
* @author Alexander Garagatyi
31+
* @author Max Shaposhnik
2732
*/
28-
public interface SshMachineFactory {
33+
public class SshMachineFactory {
34+
35+
private final int connectionTimeoutMs;
36+
private final Set<ServerConf> machinesServers;
37+
38+
@Inject
39+
public SshMachineFactory(@Named("che.workspace.ssh_connection_timeout_ms") int connectionTimeoutMs,
40+
@Named("machine.ssh.machine_servers") Set<ServerConf> machinesServers) {
41+
this.connectionTimeoutMs = connectionTimeoutMs;
42+
this.machinesServers = machinesServers;
43+
}
44+
2945

3046
/**
3147
* Creates {@link SshClient} to communicate with machine over SSH protocol.
@@ -35,31 +51,39 @@ public interface SshMachineFactory {
3551
* @param envVars
3652
* environment variables that should be injected into machine
3753
*/
38-
SshClient createSshClient(@Assisted SshMachineRecipe sshMachineRecipe,
39-
@Assisted Map<String, String> envVars);
54+
public SshClient createSshClient(SshMachineRecipe sshMachineRecipe, Map<String, String> envVars) {
55+
return new JschSshClient(sshMachineRecipe, envVars, new JSch(), connectionTimeoutMs);
56+
}
4057

4158
/**
42-
* Creates ssh machine implementation of {@link Instance}.
59+
* Creates ssh machine implementation instance.
4360
*
44-
* @param machine description of machine
45-
* @param sshClient ssh client of machine
46-
* @param outputConsumer consumer of output from container main process
47-
* @throws MachineException if error occurs on creation of {@code Instance}
61+
* @param machine
62+
* description of machine
63+
* @param sshClient
64+
* ssh client of machine
65+
* @param outputConsumer
66+
* consumer of output from container main process
67+
* @throws MachineException
68+
* if error occurs on creation of {@code Instance}
4869
*/
49-
SshMachineInstance createInstance(@Assisted Machine machine,
50-
@Assisted SshClient sshClient,
51-
@Assisted LineConsumer outputConsumer) throws MachineException;
70+
public SshMachineInstance createInstance(Machine machine, SshClient sshClient, LineConsumer outputConsumer) throws MachineException {
71+
return new SshMachineInstance(machine, sshClient, outputConsumer, this, machinesServers);
72+
}
5273

5374
/**
54-
* Creates ssh machine implementation of {@link org.eclipse.che.api.machine.server.spi.InstanceProcess}.
75+
* Creates ssh machine implementation of {@link SshMachineProcess}.
5576
*
56-
* @param command command that should be executed on process start
57-
* @param outputChannel channel where output will be available on process execution
58-
* @param pid virtual id of that process
59-
* @param sshClient client to communicate with machine
77+
* @param command
78+
* command that should be executed on process start
79+
* @param outputChannel
80+
* channel where output will be available on process execution
81+
* @param pid
82+
* virtual id of that process
83+
* @param sshClient
84+
* client to communicate with machine
6085
*/
61-
SshMachineProcess createInstanceProcess(@Assisted Command command,
62-
@Assisted("outputChannel") String outputChannel,
63-
@Assisted int pid,
64-
@Assisted SshClient sshClient);
86+
public SshMachineProcess createInstanceProcess(Command command, String outputChannel, int pid, SshClient sshClient) {
87+
return new SshMachineProcess(command, outputChannel, pid, sshClient);
88+
}
6589
}

0 commit comments

Comments
 (0)