1010 *******************************************************************************/
1111package org .eclipse .che .plugin .machine .ssh ;
1212
13- import com .google . inject . assistedinject . Assisted ;
13+ import com .jcraft . jsch . JSch ;
1414
1515import org .eclipse .che .api .core .model .machine .Command ;
1616import org .eclipse .che .api .core .model .machine .Machine ;
17+ import org .eclipse .che .api .core .model .machine .ServerConf ;
1718import org .eclipse .che .api .core .util .LineConsumer ;
1819import 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 ;
2124import 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