edu.sdsc.inca.agent
Class ReporterManagerStarter

java.lang.Object
  extended by java.lang.Thread
      extended by edu.sdsc.inca.agent.ReporterManagerStarter
All Implemented Interfaces:
java.lang.Runnable

public class ReporterManagerStarter
extends java.lang.Thread

Handles the creation of a remote reporter manager process on a specified resource.

Author:
Shava Smallen <ssmallen@sdsc.edu>

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String CURRENT_SUITE
           
protected static int DEFAULT_AGE
           
static java.lang.String LAST_CHANGE
           
protected static int MANUAL_WAIT_PERIOD
           
static java.lang.String RMBUILDSCRIPT
           
static java.lang.String RMCERT
           
static java.lang.String RMDIST
           
static java.lang.String RMKEY
           
static java.lang.String RMREQ
           
static java.lang.String RMTRUSTED
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ReporterManagerStarter(ReporterManagerStarter rmStarter)
          Create a new reporter manager starter object, whose configuration is identical to rmStarter
ReporterManagerStarter(java.lang.String resource, Agent agent)
          Create a new reporter manager starter object for a resource.
 
Method Summary
 void create()
          Start the reporter manager process on the remote resource using the method specified in the resource configuration file.
protected  java.lang.String createRmCertificate()
          Create a certificate for the reporter manager from the given certificate request
 void findBashLoginShellOption()
          Test for the bash login shell option on the reporter manager resource.
 java.lang.String getCurrentHost()
          Returns the currently selected host (chosen by the run method when the reporter manager is started).
 java.lang.String[] getEquivalentHosts()
          Returns the equivalent hosts for this resource.
 AccessMethod getProcessHandle()
          Return the process handle being used by this reporter manager starter.
 java.lang.String getRmRootPath()
          Return the path to the remote reporter manager installation directory.
 long getStartAttemptTime()
          Returns the amount of elapsed time since attempting a start of a remote reporter manager.
 java.lang.String getTemporaryDirectory()
          Gets the directory path where the temporary files can be stored.
 boolean isManual()
          Return whether the reporter manager is being controlled manually (and not by the agent)
 boolean isRunning()
          Return true if the reporter manager is currently registered and running.
 boolean isStaged()
          Checks to see if the reporter manager is available and installed on the machine.
 void nextHost()
          Assume the current host is not reachable and try the next host in the list (if there is one)
protected static java.lang.String parseWorkingDir(java.lang.String dir, AccessMethod method)
          Parse the working dir string and resolve different ways of expressing the home dir
 void refreshHosts()
          Set the resources document referenced by the reporter manager.
 void run()
          Starts a thread to create the reporter manager on the remote resource.
 void setBashLoginOption(java.lang.String bashLoginOption)
          For testing purposes only.
protected  void setHost(int hostId)
          Select the specified host for the resource and set the reporter manager attributes accordingly.
 void setRunning(boolean isRunning)
          Set the status of the reporter manager to running and notify any waiting threads.
 void setStartAttemptComplete()
          Set that the start attempt has been completed.
 void setStartAttemptTimeNow()
          Set the clock on when a start attempt has been made so we can time it out if it gets stuck.
 void setTempDir(java.lang.String tempDir)
          Set the location of the temporary directory.
 void stage(java.lang.String upgrade)
          Stage the Reporter Manager distribution over to the remote resource.
 boolean waitForReporterManager()
          To be used after the function create in order to wait for the remote reporter manager process to start up and connect to the agent.
 
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

RMBUILDSCRIPT

public static final java.lang.String RMBUILDSCRIPT
See Also:
Constant Field Values

RMCERT

public static final java.lang.String RMCERT
See Also:
Constant Field Values

RMDIST

public static final java.lang.String RMDIST
See Also:
Constant Field Values

RMKEY

public static final java.lang.String RMKEY
See Also:
Constant Field Values

RMREQ

public static final java.lang.String RMREQ
See Also:
Constant Field Values

RMTRUSTED

public static final java.lang.String RMTRUSTED
See Also:
Constant Field Values

LAST_CHANGE

public static final java.lang.String LAST_CHANGE
See Also:
Constant Field Values

CURRENT_SUITE

public static final java.lang.String CURRENT_SUITE
See Also:
Constant Field Values

DEFAULT_AGE

protected static final int DEFAULT_AGE
See Also:
Constant Field Values

MANUAL_WAIT_PERIOD

protected static final int MANUAL_WAIT_PERIOD
See Also:
Constant Field Values
Constructor Detail

ReporterManagerStarter

public ReporterManagerStarter(java.lang.String resource,
                              Agent agent)
Create a new reporter manager starter object for a resource.

Parameters:
resource - Name of the resource (from the resource configuration file) to start the reporter manager on.
agent - Path to a location where temporary/state files can be

ReporterManagerStarter

public ReporterManagerStarter(ReporterManagerStarter rmStarter)
Create a new reporter manager starter object, whose configuration is identical to rmStarter

Parameters:
rmStarter - A reporter manager starter object that will be used to configure this reporter manager starter object.
Method Detail

create

public void create()
            throws AccessMethodException
Start the reporter manager process on the remote resource using the method specified in the resource configuration file.

Throws:
AccessMethodException - if problem creating remote reporter manager process

findBashLoginShellOption

public void findBashLoginShellOption()
                              throws java.lang.InterruptedException,
                                     ReporterManagerException
Test for the bash login shell option on the reporter manager resource. Since we're not guaranteed that all access methods will source the users's initialization file and we invoke processes that rely on the user's environment (e.g., to find the openssl the user has specified in their initialization file), we invoke these processes with bash using the login shell option. Since the bash login option is not portable (i.e., -l or --login), we have to test each option by running a small echo command and checking the result.

Throws:
java.lang.InterruptedException - if interrupted while determining remote bash login option
ReporterManagerException - if unable to determine remote bash login option.

getCurrentHost

public java.lang.String getCurrentHost()
Returns the currently selected host (chosen by the run method when the reporter manager is started).

Returns:
The host that the reporter manager is currently executing on.

getEquivalentHosts

public java.lang.String[] getEquivalentHosts()
Returns the equivalent hosts for this resource.

Returns:
The list of equivalent hosts for this resource

getRmRootPath

public java.lang.String getRmRootPath()
Return the path to the remote reporter manager installation directory.

Returns:
The path to the root reporter manager directory

getProcessHandle

public AccessMethod getProcessHandle()
Return the process handle being used by this reporter manager starter. For testing purposed mostly.

Returns:
the process handle being used by this reporter manager starter

getStartAttemptTime

public long getStartAttemptTime()
Returns the amount of elapsed time since attempting a start of a remote reporter manager.

Returns:
Elapsed time in milliseconds;

getTemporaryDirectory

public java.lang.String getTemporaryDirectory()
Gets the directory path where the temporary files can be stored.

Returns:
A path to a local directory.

isManual

public boolean isManual()
Return whether the reporter manager is being controlled manually (and not by the agent)

Returns:
True if the reporter manager is being controlled manually and false if it is not.

isRunning

public boolean isRunning()
Return true if the reporter manager is currently registered and running.

Returns:
True if the reporter manager is currently registered and running and false otherwise.

isStaged

public boolean isStaged()
                 throws java.lang.InterruptedException
Checks to see if the reporter manager is available and installed on the machine.

Returns:
True if the reporter manager distribution is found on the machine.
Throws:
java.lang.InterruptedException - if interrupted while determining if remote reporter manager is staged.

nextHost

public void nextHost()
              throws edu.sdsc.inca.ConfigurationException
Assume the current host is not reachable and try the next host in the list (if there is one)

Throws:
edu.sdsc.inca.ConfigurationException - if configuration related problem with the next host selected

run

public void run()
Starts a thread to create the reporter manager on the remote resource. If there is more than one host, it will choose the first one that it can successfully create a reporter manager on. If unable to create a reporter manager on any resource, will wait 10 minutes and then try again.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

refreshHosts

public void refreshHosts()
Set the resources document referenced by the reporter manager.


setBashLoginOption

public void setBashLoginOption(java.lang.String bashLoginOption)
For testing purposes only. Set correct flag for remote bash login option.

Parameters:
bashLoginOption - flag for remote bash login option.

setStartAttemptTimeNow

public void setStartAttemptTimeNow()
Set the clock on when a start attempt has been made so we can time it out if it gets stuck.


setStartAttemptComplete

public void setStartAttemptComplete()
Set that the start attempt has been completed.


setRunning

public void setRunning(boolean isRunning)
Set the status of the reporter manager to running and notify any waiting threads.

Parameters:
isRunning - True indicates the reporter manager is running on the remote machine and available; false otherwise.

setTempDir

public void setTempDir(java.lang.String tempDir)
Set the location of the temporary directory.

Parameters:
tempDir - A path to a directory where temporary files can be stored.

stage

public void stage(java.lang.String upgrade)
           throws java.lang.InterruptedException,
                  ReporterManagerException
Stage the Reporter Manager distribution over to the remote resource. Will first put over the reporter manager tarball and build script, invoke the build script, and wait for completion.

Parameters:
upgrade - If not null, runs the buildRM.sh script with the upgrade option turned on. Otherwise a regular full install is done.
Throws:
java.lang.InterruptedException - if interrupted while executing build script
ReporterManagerException - if build fails

waitForReporterManager

public boolean waitForReporterManager()
                               throws java.lang.InterruptedException
To be used after the function create in order to wait for the remote reporter manager process to start up and connect to the agent. Will wait up to startAttemptWaitPeriod milliseconds before returning false.

Returns:
True if the remote reporter manager has registered and false if startAttemptWaitPeriod milliseconds have passed and the remote reporter manager has still not registered.
Throws:
java.lang.InterruptedException - if interrupted while waiting for remote reporter manager to check in.

createRmCertificate

protected java.lang.String createRmCertificate()
                                        throws java.security.GeneralSecurityException,
                                               java.io.IOException
Create a certificate for the reporter manager from the given certificate request

Returns:
The directory where the public and private key are stored.
Throws:
java.security.GeneralSecurityException - if unable to create certificate
java.io.IOException - if unable to store certificate

parseWorkingDir

protected static java.lang.String parseWorkingDir(java.lang.String dir,
                                                  AccessMethod method)
Parse the working dir string and resolve different ways of expressing the home dir

Parameters:
dir - A string containing the raw value of working dir
method - An access method that will be used to resolve home
Returns:
A string containing a valid rm working dir

setHost

protected void setHost(int hostId)
                throws edu.sdsc.inca.ConfigurationException
Select the specified host for the resource and set the reporter manager attributes accordingly.

Parameters:
hostId - The host id to select to execute the reporter manager on.
Throws:
edu.sdsc.inca.ConfigurationException - If unable to get host configuration info