Class SSHLauncher
- java.lang.Object
-
- org.glassfish.cluster.ssh.launcher.SSHLauncher
-
@Service(name="SSHLauncher") @PerLookup public class SSHLauncher extends Object
- Author:
- Rajiv Mordani
-
-
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_TIMEOUT_MSECprotected static intMINIMUM_TIMEOUT_MSECprotected static StringTIMEOUT_PROPERTY
-
Constructor Summary
Constructors Constructor Description SSHLauncher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckConnection()Check if we can authenticate using public key authbooleancheckPasswordAuth()Check if we can connect using password authStringexpandPasswordAlias(String alias)com.trilead.ssh2.SCPClientgetSCPClient()SFTPClientgetSFTPClient()protected intgetTimeout()Gets the timeout to use for SSH in milliseconds.voidinit(Node node, Logger logger)Initialize the SSHLauncher use a Node config objectvoidinit(String userName, String host, int port, String password, char[] privateKey, Logger logger)Initialize the SSHLauncher using a private keyvoidinit(String userName, String host, int port, String password, String keyFile, String keyPassPhrase, Logger logger)Initialize the SSHLauncher using a private key filevoidinit(Logger logger)booleanisPasswordAlias(String alias)voidpingConnection()intrunCommand(String command, OutputStream os)WARNING! This method does not handle paths with spaces in them.intrunCommand(String command, OutputStream os, List<String> stdinLines)Executes a command on the remote system via ssh, optionally sending lines of data to the remote process's System.in.intrunCommand(List<String> command, OutputStream os)intrunCommand(List<String> command, OutputStream os, List<String> stdinLines)Executes a command on the remote system via ssh, optionally sending lines of data to the remote process's System.in.intrunCommandAsIs(List<String> command, OutputStream os, List<String> stdinLines)Executes a command on the remote system via ssh without normalizing the command lineintrunCommandAsIs(List<String> command, OutputStream os, List<String> stdinLines, String[] env)Executes a command on the remote system via ssh without normalizing the command linevoidsetupKey(String node, String pubKeyFile, boolean generateKey, String passwd)Setting up the key involves the following steps: -If a key exists and we can connect using the key, do nothing.static byte[]toByteArray(InputStream input)StringtoString()voidvalidate(String host, int port, String userName, String password, String keyFile, String keyPassPhrase, String installDir, String landmarkPath, Logger logger)voidvalidate(String host, int port, String userName, String password, String keyFile, String keyPassPhrase, String installDir, Logger logger)
-
-
-
Field Detail
-
TIMEOUT_PROPERTY
protected static final String TIMEOUT_PROPERTY
- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT_MSEC
protected static final int DEFAULT_TIMEOUT_MSEC
- See Also:
- Constant Field Values
-
MINIMUM_TIMEOUT_MSEC
protected static final int MINIMUM_TIMEOUT_MSEC
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(Logger logger)
-
init
public void init(Node node, Logger logger)
Initialize the SSHLauncher use a Node config object- Parameters:
node-logger-
-
init
public void init(String userName, String host, int port, String password, char[] privateKey, Logger logger)
Initialize the SSHLauncher using a private key- Parameters:
userName-host-port-password-privateKey-logger-
-
init
public void init(String userName, String host, int port, String password, String keyFile, String keyPassPhrase, Logger logger)
Initialize the SSHLauncher using a private key file- Parameters:
userName-host-port-password-keyFile-keyPassPhrase-logger-
-
runCommand
public int runCommand(List<String> command, OutputStream os, List<String> stdinLines) throws IOException, InterruptedException
Executes a command on the remote system via ssh, optionally sending lines of data to the remote process's System.in.- Parameters:
command- the command to execute in the form of an argv style listos- stream to receive the output from the commandstdinLines- optional data to be sent to the process's System.in stream; null if no input should be sent- Returns:
- Throws:
IOExceptionInterruptedException
-
runCommand
public int runCommand(List<String> command, OutputStream os) throws IOException, InterruptedException
- Throws:
IOExceptionInterruptedException
-
runCommand
public int runCommand(String command, OutputStream os) throws IOException, InterruptedException
WARNING! This method does not handle paths with spaces in them. To use this method you must make sure all paths in the command string are quoted correctly. Otherwise use the methods that take command as a list instead.- Throws:
IOExceptionInterruptedException
-
runCommand
public int runCommand(String command, OutputStream os, List<String> stdinLines) throws IOException, InterruptedException
Executes a command on the remote system via ssh, optionally sending lines of data to the remote process's System.in. WARNING! This method does not handle paths with spaces in them. To use this method you must make sure all paths in the command string are quoted correctly. Otherwise use the methods that take command as a list instead.- Parameters:
command- the command to executeos- stream to receive the output from the commandstdinLines- optional data to be sent to the process's System.in stream; null if no input should be sent- Returns:
- Throws:
IOExceptionInterruptedException
-
runCommandAsIs
public int runCommandAsIs(List<String> command, OutputStream os, List<String> stdinLines) throws IOException, InterruptedException
Executes a command on the remote system via ssh without normalizing the command line- Parameters:
command- the command to executeos- stream to receive the output from the commandstdinLines- optional data to be sent to the process's System.in stream; null if no input should be sent- Returns:
- Throws:
IOExceptionInterruptedException
-
runCommandAsIs
public int runCommandAsIs(List<String> command, OutputStream os, List<String> stdinLines, String[] env) throws IOException, InterruptedException
Executes a command on the remote system via ssh without normalizing the command line- Parameters:
command- the command to executeos- stream to receive the output from the commandstdinLines- optional data to be sent to the process's System.in stream; null if no input should be sentenv- list of environment variables to set before executing the command. each array cell is like varname=varvalue. This only supports on csh, t-csh and bash- Returns:
- Throws:
IOExceptionInterruptedException
-
pingConnection
public void pingConnection() throws IOException, InterruptedException- Throws:
IOExceptionInterruptedException
-
validate
public void validate(String host, int port, String userName, String password, String keyFile, String keyPassPhrase, String installDir, String landmarkPath, Logger logger) throws IOException
- Throws:
IOException
-
validate
public void validate(String host, int port, String userName, String password, String keyFile, String keyPassPhrase, String installDir, Logger logger) throws IOException
- Throws:
IOException
-
getSFTPClient
public SFTPClient getSFTPClient() throws IOException
- Throws:
IOException
-
getSCPClient
public com.trilead.ssh2.SCPClient getSCPClient() throws IOException- Throws:
IOException
-
isPasswordAlias
public boolean isPasswordAlias(String alias)
-
setupKey
public void setupKey(String node, String pubKeyFile, boolean generateKey, String passwd) throws IOException, InterruptedException
Setting up the key involves the following steps: -If a key exists and we can connect using the key, do nothing. -Generate a key pair if there isn't one -Connect to remote host using password auth and do the following: 1. create .ssh directory if it doesn't exist 2. copy over the key as key.tmp 3. Append the key to authorized_keys file 4. Remove the temporary key file key.tmp 5. Fix permissions for home, .ssh and authorized_keys- Parameters:
node- - remote hostpubKeyFile- - .pub filegenerateKey- - flag to indicate if key needs to be generated or notpasswd- - ssh user password- Throws:
IOExceptionInterruptedException
-
toByteArray
public static byte[] toByteArray(InputStream input) throws IOException
- Throws:
IOException
-
checkConnection
public boolean checkConnection()
Check if we can authenticate using public key auth- Returns:
- true|false
-
checkPasswordAuth
public boolean checkPasswordAuth()
Check if we can connect using password auth- Returns:
- true|false
-
getTimeout
protected int getTimeout()
Gets the timeout to use for SSH in milliseconds. The value is obtained from the "fish.payara.node.ssh.timeout" property, defaulting to 120000 if this is invalid or unspecified.- Returns:
- The timeout in milliseconds.
-
-