edu.sdsc.inca.agent.access
Class Local

java.lang.Object
  extended by edu.sdsc.inca.agent.AccessMethod
      extended by edu.sdsc.inca.agent.access.Local

public class Local
extends AccessMethod

A class that implements AccessMethod using the Java Runtime and IO API


Constructor Summary
Local(java.lang.String resource, edu.sdsc.inca.util.ResourcesWrapper resources)
          Create a local process controlling it via Java Runtime class.
 
Method Summary
static void copy(java.io.File src, java.io.File dst)
          Copies a local file since Java does not seem to have a copy file function.
 void get(java.lang.String[] localFiles, java.lang.String localDir)
          Copy a list of local files to a local directory on this machine.
 boolean isActive()
          Checks to see if the current ssh session is active.
 java.lang.String prependHome(java.lang.String path)
          Given a path relative to the home directory, prepend the home directory to the path and return the new string.
 void put(java.lang.String[] localFiles, java.lang.String localDir)
          Copy a list of local files to a local directory on this machine.
 AccessMethodOutput run(java.lang.String executable, java.lang.String[] arguments, java.lang.String stdin, java.lang.String directory)
          Execute the specified process on this resource.
 void start(java.lang.String executable, java.lang.String[] arguments, java.lang.String stdin, java.lang.String directory)
          Start a process on this machine.
 void stop()
          This call should kill the remote process that was started by the start() call.
 void transfer(java.lang.String[] localFiles, java.lang.String localDir)
          Copy a list of local files to a directory on this machine.
 
Methods inherited from class edu.sdsc.inca.agent.AccessMethod
create, get, put, run, run, start, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Local

public Local(java.lang.String resource,
             edu.sdsc.inca.util.ResourcesWrapper resources)
Create a local process controlling it via Java Runtime class. The given resource should exist in the resource configuration file. This constructor doesn't do anything but is needed because the interface defines it.

Parameters:
resource - The name of the resource to start the process on
resources - The resource configuration information
Method Detail

get

public void get(java.lang.String[] localFiles,
                java.lang.String localDir)
         throws AccessMethodException
Copy a list of local files to a local directory on this machine.

Overrides:
get in class AccessMethod
Parameters:
localFiles - List of paths to local files that will be transfered
localDir - Path to the local directory where the remote files will be placed
Throws:
AccessMethodException

put

public void put(java.lang.String[] localFiles,
                java.lang.String localDir)
         throws AccessMethodException
Copy a list of local files to a local directory on this machine.

Overrides:
put in class AccessMethod
Parameters:
localFiles - List of paths to local files that will be transfered
localDir - Path to the local directory where the remote files will be placed
Throws:
AccessMethodException

transfer

public void transfer(java.lang.String[] localFiles,
                     java.lang.String localDir)
              throws AccessMethodException
Copy a list of local files to a directory on this machine.

Parameters:
localFiles - List of paths to local files that will be transfered
localDir - Path to the directory where the local file will be placed
Throws:
AccessMethodException - If trouble fetching files

prependHome

public java.lang.String prependHome(java.lang.String path)
Given a path relative to the home directory, prepend the home directory to the path and return the new string.

Overrides:
prependHome in class AccessMethod
Parameters:
path - A path relative to the user's home directory
Returns:
A new string that contains the home directory prepended to the provided path.

run

public AccessMethodOutput run(java.lang.String executable,
                              java.lang.String[] arguments,
                              java.lang.String stdin,
                              java.lang.String directory)
                       throws AccessMethodException,
                              java.lang.InterruptedException
Execute the specified process on this resource. This call will block until the process has completed.

Specified by:
run in class AccessMethod
Parameters:
executable - Path to the executable.
arguments - Contains the arguments that should be passed to the executable
stdin - A string that will be passedd in as stdin to the process when it is started
directory - Path to the directory where the process will be executed from
Returns:
The stdout and stderr of the executed process in AccessMethodOutput
Throws:
AccessMethodException - if unable to execute remote process
java.lang.InterruptedException - if interrupted while running remote process

start

public void start(java.lang.String executable,
                  java.lang.String[] arguments,
                  java.lang.String stdin,
                  java.lang.String directory)
           throws AccessMethodException
Start a process on this machine. This is a non-blocking call. Important note: this process will not be killed on call to stop()

Specified by:
start in class AccessMethod
Parameters:
executable - Path to the remote executable.
arguments - Contains the arguments that should be passed to the executable
directory - Path to the directory where the process will be executed
stdin - A string that will be passedd in as stdin to the process when it is started
Throws:
AccessMethodException

stop

public void stop()
          throws AccessMethodException
This call should kill the remote process that was started by the start() call. However, since a remote process won't be killed when the ssh client session is closed, the remote process will persist. Will try to figure out if there is a SSH configuration mechanism that can be turned on so that the process will be killed upon disconnect. This call does disconnect the active SSH session.

Specified by:
stop in class AccessMethod
Throws:
AccessMethodException

isActive

public boolean isActive()
                 throws AccessMethodException
Checks to see if the current ssh session is active. Does not indicate whether the remote process is alive (for now).

Specified by:
isActive in class AccessMethod
Returns:
true if the SSH session is alive; false otherwise.
Throws:
AccessMethodException - if unable to determine if process is active

copy

public static void copy(java.io.File src,
                        java.io.File dst)
                 throws java.io.IOException
Copies a local file since Java does not seem to have a copy file function. Code comes from the Java Almanac. http://javaalmanac.com/egs/java.io/CopyFile.html?l=new

Parameters:
src - File to copy
dst - Destination of file
Throws:
java.io.IOException - If trouble copying a file