org.glassfish.cluster.ssh.launcher
Class SSHLauncher

java.lang.Object
  extended by org.glassfish.cluster.ssh.launcher.SSHLauncher

@Service(name="SSHLauncher")
@Scoped(value=org.jvnet.hk2.component.PerLookup.class)
public class SSHLauncher
extends java.lang.Object

Author:
Rajiv Mordani

Constructor Summary
SSHLauncher()
           
 
Method Summary
 boolean checkConnection()
          Check if we can authenticate using public key auth
 boolean checkPasswordAuth()
          Check if we can connect using password auth
 java.lang.String expandPasswordAlias(java.lang.String alias)
           
 com.trilead.ssh2.SCPClient getSCPClient()
           
 SFTPClient getSFTPClient()
           
 void init(java.util.logging.Logger logger)
           
 void init(Node node, java.util.logging.Logger logger)
           
 void init(java.lang.String userName, java.lang.String host, int port, java.lang.String password, java.lang.String keyFile, java.lang.String keyPassPhrase, java.util.logging.Logger logger)
           
 boolean isPasswordAlias(java.lang.String alias)
           
 void pingConnection()
           
 int runCommand(java.util.List<java.lang.String> command, java.io.OutputStream os)
           
 int runCommand(java.util.List<java.lang.String> command, java.io.OutputStream os, java.util.List<java.lang.String> stdinLines)
          Executes a command on the remote system via ssh, optionally sending lines of data to the remote process's System.in.
 int runCommand(java.lang.String command, java.io.OutputStream os)
          WARNING! This method does not handle paths with spaces in them.
 int runCommand(java.lang.String command, java.io.OutputStream os, java.util.List<java.lang.String> stdinLines)
          Executes a command on the remote system via ssh, optionally sending lines of data to the remote process's System.in.
 void setupKey(java.lang.String node, java.lang.String pubKeyFile, boolean generateKey, java.lang.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(java.io.InputStream input)
           
 java.lang.String toString()
           
 void validate(java.lang.String host, int port, java.lang.String userName, java.lang.String password, java.lang.String keyFile, java.lang.String keyPassPhrase, java.lang.String installDir, java.util.logging.Logger logger)
           
 void validate(java.lang.String host, int port, java.lang.String userName, java.lang.String password, java.lang.String keyFile, java.lang.String keyPassPhrase, java.lang.String installDir, java.lang.String landmarkPath, java.util.logging.Logger logger)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SSHLauncher

public SSHLauncher()
Method Detail

init

public void init(java.util.logging.Logger logger)

init

public void init(Node node,
                 java.util.logging.Logger logger)

init

public void init(java.lang.String userName,
                 java.lang.String host,
                 int port,
                 java.lang.String password,
                 java.lang.String keyFile,
                 java.lang.String keyPassPhrase,
                 java.util.logging.Logger logger)

runCommand

public int runCommand(java.util.List<java.lang.String> command,
                      java.io.OutputStream os,
                      java.util.List<java.lang.String> stdinLines)
               throws java.io.IOException,
                      java.lang.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 list
os - stream to receive the output from the command
stdinLines - optional data to be sent to the process's System.in stream; null if no input should be sent
Returns:
Throws:
java.io.IOException
java.lang.InterruptedException

runCommand

public int runCommand(java.util.List<java.lang.String> command,
                      java.io.OutputStream os)
               throws java.io.IOException,
                      java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException

runCommand

public int runCommand(java.lang.String command,
                      java.io.OutputStream os)
               throws java.io.IOException,
                      java.lang.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:
java.io.IOException
java.lang.InterruptedException

runCommand

public int runCommand(java.lang.String command,
                      java.io.OutputStream os,
                      java.util.List<java.lang.String> stdinLines)
               throws java.io.IOException,
                      java.lang.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 execute
os - stream to receive the output from the command
stdinLines - optional data to be sent to the process's System.in stream; null if no input should be sent
Returns:
Throws:
java.io.IOException
java.lang.InterruptedException

pingConnection

public void pingConnection()
                    throws java.io.IOException,
                           java.lang.InterruptedException
Throws:
java.io.IOException
java.lang.InterruptedException

validate

public void validate(java.lang.String host,
                     int port,
                     java.lang.String userName,
                     java.lang.String password,
                     java.lang.String keyFile,
                     java.lang.String keyPassPhrase,
                     java.lang.String installDir,
                     java.lang.String landmarkPath,
                     java.util.logging.Logger logger)
              throws java.io.IOException
Throws:
java.io.IOException

validate

public void validate(java.lang.String host,
                     int port,
                     java.lang.String userName,
                     java.lang.String password,
                     java.lang.String keyFile,
                     java.lang.String keyPassPhrase,
                     java.lang.String installDir,
                     java.util.logging.Logger logger)
              throws java.io.IOException
Throws:
java.io.IOException

getSFTPClient

public SFTPClient getSFTPClient()
                         throws java.io.IOException
Throws:
java.io.IOException

getSCPClient

public com.trilead.ssh2.SCPClient getSCPClient()
                                        throws java.io.IOException
Throws:
java.io.IOException

expandPasswordAlias

public java.lang.String expandPasswordAlias(java.lang.String alias)

isPasswordAlias

public boolean isPasswordAlias(java.lang.String alias)

setupKey

public void setupKey(java.lang.String node,
                     java.lang.String pubKeyFile,
                     boolean generateKey,
                     java.lang.String passwd)
              throws java.io.IOException,
                     java.lang.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 host
pubKeyFile - - .pub file
generateKey - - flag to indicate if key needs to be generated or not
passwd - - ssh user password
Throws:
java.io.IOException
java.lang.InterruptedException

toByteArray

public static byte[] toByteArray(java.io.InputStream input)
                          throws java.io.IOException
Throws:
java.io.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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2012 GlassFish Community. All Rights Reserved.