com.xebialabs.deployit.hostsession.ssh
Class SshScpHostSession

java.lang.Object
  extended by com.xebialabs.deployit.hostsession.common.AbstractHostSession
      extended by com.xebialabs.deployit.hostsession.ssh.SshScpHostSession
All Implemented Interfaces:
HostSession

public class SshScpHostSession
extends AbstractHostSession

A session to a remote host using SSH w/ SCP.


Field Summary
protected  java.lang.String host
           
protected  java.lang.String password
           
protected  int port
           
protected  com.jcraft.jsch.Session sharedSession
           
protected  java.lang.String username
           
 
Fields inherited from class com.xebialabs.deployit.hostsession.common.AbstractHostSession
MAX_TEMP_RETRIES
 
Constructor Summary
SshScpHostSession(OperatingSystemFamily os, java.lang.String temporaryDirectoryPath, java.lang.String host, int port, java.lang.String username, java.lang.String password)
          Constructs an SshScpHostSession
 
Method Summary
 void close()
          Closes the host session.
protected  void disconnectSession(com.jcraft.jsch.Session session, java.lang.String purpose)
           
 void disconnectSharedSession()
           
static java.lang.String encodeCommandLine(boolean hidePassword, java.lang.String... commandLine)
           
 int execute(CommandExecutionCallbackHandler handler, java.util.Map<java.lang.String,java.lang.String> inputResponse, java.lang.String... commandLine)
          Executes a command and responds to any output with the provided responses.
 int execute(CommandExecutionCallbackHandler handler, java.lang.String... commandLine)
          Executes a command with its arguments.
 HostFile getFile(HostFile parent, java.lang.String child)
          Creates a reference to a file in a directory on the host.
protected  HostFile getFile(HostFile parent, java.lang.String child, boolean isTempFile)
           
 HostFile getFile(java.lang.String hostPath)
          Creates a reference to a file on the host.
protected  HostFile getFile(java.lang.String hostPath, boolean isTempFile)
           
 java.lang.String getHost()
           
protected  CommandExecutionCallbackHandler getInputResponseHandler(CommandExecutionCallbackHandler originalHandler, java.io.OutputStream remoteStdin, java.util.Map<java.lang.String,java.lang.String> inputResponse)
           
 java.lang.String getPassword()
           
 int getPort()
           
protected  com.jcraft.jsch.Session getSharedSession()
           
 HostFile getTempFile(java.lang.String prefix, java.lang.String suffix)
          Creates a reference to a temporary file on the host.
protected  com.jcraft.jsch.UserInfo getUserInfo()
           
 java.lang.String getUsername()
           
protected  com.jcraft.jsch.Session openSession(java.lang.String purpose)
           
 void setHost(java.lang.String host)
           
 void setPassword(java.lang.String password)
           
 void setPort(int port)
           
 void setUsername(java.lang.String username)
           
 CommandExecution startExecute(java.lang.String... commandLine)
          Starts the execution of a command and gives the caller full control over the execution.
 java.lang.String toString()
           
 
Methods inherited from class com.xebialabs.deployit.hostsession.common.AbstractHostSession
cleanupTemporaryFiles, copyToTemporaryFile, copyToTemporaryFile, createSessionTempDirectory, getHostOperatingSystem, getTempFile, getTemporaryDirectory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.xebialabs.deployit.hostsession.HostSession
copyToTemporaryFile, copyToTemporaryFile, getHostOperatingSystem, getTempFile
 

Field Detail

host

protected java.lang.String host

port

protected int port

username

protected java.lang.String username

password

protected java.lang.String password

sharedSession

protected com.jcraft.jsch.Session sharedSession
Constructor Detail

SshScpHostSession

public SshScpHostSession(OperatingSystemFamily os,
                         java.lang.String temporaryDirectoryPath,
                         java.lang.String host,
                         int port,
                         java.lang.String username,
                         java.lang.String password)
Constructs an SshScpHostSession

Parameters:
os - the operating system of the host
temporaryDirectoryPath - the path of the directory in which to store temporary files
host - the hostname or IP adress of the host
port - the port to connect to
username - the username to connect with
password - the password to connect with
Method Detail

getFile

protected HostFile getFile(java.lang.String hostPath,
                           boolean isTempFile)
                    throws RuntimeIOException
Throws:
RuntimeIOException

toString

public java.lang.String toString()

close

public void close()
Description copied from interface: HostSession
Closes the host session. Destroys any temporary files that may have been created on the host. Never throws an exception, not even a RuntimeException

Specified by:
close in interface HostSession
Overrides:
close in class AbstractHostSession

getSharedSession

protected com.jcraft.jsch.Session getSharedSession()

disconnectSharedSession

public void disconnectSharedSession()

openSession

protected com.jcraft.jsch.Session openSession(java.lang.String purpose)
                                       throws com.jcraft.jsch.JSchException
Throws:
com.jcraft.jsch.JSchException

disconnectSession

protected void disconnectSession(com.jcraft.jsch.Session session,
                                 java.lang.String purpose)

getFile

public HostFile getFile(java.lang.String hostPath)
                 throws RuntimeIOException
Description copied from interface: HostSession
Creates a reference to a file on the host.

Specified by:
getFile in interface HostSession
Parameters:
hostPath - the path of the host
Returns:
a reference to the file
Throws:
RuntimeIOException - if an I/O error occurs

getFile

public HostFile getFile(HostFile parent,
                        java.lang.String child)
                 throws RuntimeIOException
Description copied from interface: HostSession
Creates a reference to a file in a directory on the host.

Specified by:
getFile in interface HostSession
Parameters:
parent - the reference to the directory on the host
child - the name of the file in the directory
Returns:
a reference to the file in the directory
Throws:
RuntimeIOException - if an I/O error occurs

getFile

protected HostFile getFile(HostFile parent,
                           java.lang.String child,
                           boolean isTempFile)
                    throws RuntimeIOException
Throws:
RuntimeIOException

getTempFile

public HostFile getTempFile(java.lang.String prefix,
                            java.lang.String suffix)
                     throws RuntimeIOException
Description copied from interface: HostSession
Creates a reference to a temporary file on the host. This file has a unique name and will be automatically removed when this session is closed. N.B.: The file is not actually created until a put method is invoked.

Specified by:
getTempFile in interface HostSession
Parameters:
prefix - the prefix string to be used in generating the file's name; must be at least three characters long
suffix - the suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
Returns:
a reference to the temporary file on the host
Throws:
RuntimeIOException - if an I/O error occurs

execute

public int execute(CommandExecutionCallbackHandler handler,
                   java.lang.String... commandLine)
            throws RuntimeIOException
Description copied from interface: HostSession
Executes a command with its arguments.

Specified by:
execute in interface HostSession
Parameters:
handler - the callback handler that will be invoked when the executed command generated output.
commandLine - the command line to execute. The first element is the command, the other elements are its arguments.
Returns:
the exit value of the executed command. Is 0 on succesfull execution.
Throws:
RuntimeIOException - if an I/O error occurs

execute

public int execute(CommandExecutionCallbackHandler handler,
                   java.util.Map<java.lang.String,java.lang.String> inputResponse,
                   java.lang.String... commandLine)
            throws RuntimeIOException
Description copied from interface: HostSession
Executes a command and responds to any output with the provided responses.

Specified by:
execute in interface HostSession
Parameters:
handler - the callback handler that will be invoked when the executed command generated output.
inputResponse - expected output and the response to send
commandLine - the command line to execute. The first element is the command, the other elements are its arguments.
Returns:
the exit value of the executed command. Is 0 on succesfull execution.
Throws:
RuntimeIOException - if an I/O error occurs

getInputResponseHandler

protected CommandExecutionCallbackHandler getInputResponseHandler(CommandExecutionCallbackHandler originalHandler,
                                                                  java.io.OutputStream remoteStdin,
                                                                  java.util.Map<java.lang.String,java.lang.String> inputResponse)

startExecute

public CommandExecution startExecute(java.lang.String... commandLine)
Description copied from interface: HostSession
Starts the execution of a command and gives the caller full control over the execution.

Specified by:
startExecute in interface HostSession
Parameters:
commandLine - the command line to execute. The first element is the command, the other elements are its arguments.
Returns:
an object representing the executing command or null if this is not supported by the host session.

getUserInfo

protected com.jcraft.jsch.UserInfo getUserInfo()

getHost

public java.lang.String getHost()

setHost

public void setHost(java.lang.String host)

getPort

public int getPort()

setPort

public void setPort(int port)

getUsername

public java.lang.String getUsername()

setUsername

public void setUsername(java.lang.String username)

getPassword

public java.lang.String getPassword()

setPassword

public void setPassword(java.lang.String password)

encodeCommandLine

public static java.lang.String encodeCommandLine(boolean hidePassword,
                                                 java.lang.String... commandLine)


Copyright © 2010. All Rights Reserved.