edu.washington.cs.pl_if.ssh
Class SshConnection

java.lang.Object
  extended by java.lang.Thread
      extended by edu.washington.cs.pl_if.ssh.SshConnection
All Implemented Interfaces:
ConnectionMonitor, Runnable

public class SshConnection
extends Thread
implements ConnectionMonitor


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static String EXIT_CODE_IDENTIFIER
           
static int LOG_DEVEL
           
static int LOG_ERROR
           
static int LOG_FULL
           
static int LOG_LEVEL
           
static int SSH_CONNECT_TIMEOUT
           
static int SSH_KEY_EXCHANGE_TIMEOUT
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SshConnection(ConnectionController controller, PlanetLabHost hostname)
          create a new instance of a SSHConnection Thread
 
Method Summary
 void connectionLost(Throwable reason)
           
 void disconnect()
           
 boolean download(String remotePath, File localBaseDir, String fileFilter, String localNamingType, CommandSpec commandSpec)
           
 String getCommand(int num)
           
 int getCommandExitStatus(int commandIndex)
           
 String getCommandExitStatusString(int commandIndex)
           
 CommandSpec getCommandSpec(int commandIndex)
           
 Object[] getCommandStats()
           
 Connection getConnection()
           
 int getCurrentCommandNum()
           
 double getExecutionTime(int commandNum)
           
 PlanetLabHost getHost()
           
 String getHostname()
           
 String getLastOutput()
           
 List<Map> getOutput(int fromRow)
          Get output from the ssh connection
 int getOutputRowNum(int command)
           
 String getStatus()
           
 void halt()
          Closes the connction and removes all commands from the execution queue
 boolean isCommandCompleted(int commandIndex)
           
 boolean isConnected()
           
 boolean isHalted()
           
 int killCommand(int commandId)
           
static void main(String[] args)
          used for debugging...
 boolean mirrorDir(File baseDir)
           
 int queueCommand(String command)
          Lazy wrapper for queueCommand, - identical to calling queueCommand(command, 0,false).
 int queueCommand(String command, double timeout, boolean stopOnError)
          Add command to the queue of commands to execute
 void run()
           
 int runCommand(CommandSpec commandSpec, Session session)
          Run a command in the given session
 Session startShell()
          starts a shell using the connection
 boolean upload(File fileOrDir, CommandSpec commandSpec)
           
 boolean wasConnected()
          checks if this connection is or was successfully connected
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG_ERROR

public static final int LOG_ERROR
See Also:
Constant Field Values

LOG_FULL

public static final int LOG_FULL
See Also:
Constant Field Values

LOG_DEVEL

public static final int LOG_DEVEL
See Also:
Constant Field Values

LOG_LEVEL

public static final int LOG_LEVEL
See Also:
Constant Field Values

SSH_CONNECT_TIMEOUT

public static final int SSH_CONNECT_TIMEOUT
See Also:
Constant Field Values

SSH_KEY_EXCHANGE_TIMEOUT

public static final int SSH_KEY_EXCHANGE_TIMEOUT
See Also:
Constant Field Values

EXIT_CODE_IDENTIFIER

public static final String EXIT_CODE_IDENTIFIER
See Also:
Constant Field Values
Constructor Detail

SshConnection

public SshConnection(ConnectionController controller,
                     PlanetLabHost hostname)
create a new instance of a SSHConnection Thread

Parameters:
hostname - hostname to connect to
Method Detail

main

public static void main(String[] args)
used for debugging...

Parameters:
args -

connectionLost

public void connectionLost(Throwable reason)
Specified by:
connectionLost in interface ConnectionMonitor

disconnect

public void disconnect()

getCommand

public String getCommand(int num)

getCommandExitStatus

public int getCommandExitStatus(int commandIndex)

getCommandExitStatusString

public String getCommandExitStatusString(int commandIndex)

getCommandSpec

public CommandSpec getCommandSpec(int commandIndex)

getCommandStats

public Object[] getCommandStats()

getConnection

public Connection getConnection()

getCurrentCommandNum

public int getCurrentCommandNum()

getExecutionTime

public double getExecutionTime(int commandNum)

getHost

public PlanetLabHost getHost()

getHostname

public String getHostname()

getLastOutput

public String getLastOutput()

getOutput

public List<Map> getOutput(int fromRow)
Get output from the ssh connection

Returns:
a String with all data written to stdout and stderr by the remote system

getOutputRowNum

public int getOutputRowNum(int command)

getStatus

public String getStatus()

halt

public void halt()
Closes the connction and removes all commands from the execution queue


isCommandCompleted

public boolean isCommandCompleted(int commandIndex)

isConnected

public boolean isConnected()

isHalted

public boolean isHalted()

mirrorDir

public boolean mirrorDir(File baseDir)

queueCommand

public int queueCommand(String command)
Lazy wrapper for queueCommand, - identical to calling queueCommand(command, 0,false).

Parameters:
command - The command to execute
Returns:
The command number (used to check exit status)

queueCommand

public int queueCommand(String command,
                        double timeout,
                        boolean stopOnError)
Add command to the queue of commands to execute

Parameters:
command - The command to execute
timeout - Maximum time allowed for the command to execute without any data beeing written to stdout. 0 disable
stopOnError - controller if subsequent commands should be executed if a non-zero exit code is returned
Returns:
The command number (used to check exit status)

killCommand

public int killCommand(int commandId)

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

runCommand

public int runCommand(CommandSpec commandSpec,
                      Session session)
               throws IOException,
                      InterruptedException
Run a command in the given session

Parameters:
commandSpec -
session -
Returns:
exit code of the command, or CommandSpec.RETURN_KILLED if killed or CommandSpec.RETURN_TIMEDOUT if timedout
Throws:
IOException
InterruptedException

startShell

public Session startShell()
starts a shell using the connection

Returns:
a session with a shell, or null if not connected or an error occurs

wasConnected

public boolean wasConnected()
checks if this connection is or was successfully connected

Returns:
true if the connection sequence was initiated and successful, false otherwise

upload

public boolean upload(File fileOrDir,
                      CommandSpec commandSpec)

download

public boolean download(String remotePath,
                        File localBaseDir,
                        String fileFilter,
                        String localNamingType,
                        CommandSpec commandSpec)