edu.sdsc.inca
Class Agent

java.lang.Object
  extended by edu.sdsc.inca.Component
      extended by edu.sdsc.inca.Server
          extended by edu.sdsc.inca.Agent

public class Agent
extends edu.sdsc.inca.Server

The agent is the Inca component that provides centralized control of the reporters running on the monitored resources. A client of the agent (usually thru incat) can

  1. request specific reporters be executed on the monitored resources by submitting suites
  2. configure the agent with a list of reporter repositories where it can find reporters requested in the suites
  3. configure the agent with information about the resources it is monitoring (e.g., the access method to use to start up a remote reporter manager process)
Note: The Agent is subclass of the Server component whose command threads (which service client requests) do not have access to the server object. Therefore, we have a static Agent object which can be accessed by the command threads to perform actions requested by the clients.


Nested Class Summary
 
Nested classes/interfaces inherited from class edu.sdsc.inca.Server
edu.sdsc.inca.Server.ClientDispatcher, edu.sdsc.inca.Server.ServerShutdownHook
 
Field Summary
protected  java.lang.String checkReporterManagers
           
static java.lang.String GLOBUS_IP_PROPERTY
           
static int PING_PERIOD
           
protected  boolean ranShutdown
           
static java.lang.String REPOSITORIES_PATH
           
static java.lang.String REPOSITORY_CACHE
           
static java.lang.String RESOURCES_PATH
           
static java.lang.String RMDIR
           
static int START_ATTEMPT_PERIOD
           
static java.lang.String SUITEDIR_PATH
           
protected  java.lang.String upgradeReporterManagers
           
protected  java.lang.String upgradeTargets
           
 
Fields inherited from class edu.sdsc.inca.Server
ACCEPT_TIMEOUT, cd, CLIENT_TIMEOUT, SERVER_OPTS, ssocket, tempPath, workerCount, workers, workQueue
 
Fields inherited from class edu.sdsc.inca.Component
authenticate, cert, certPath, COMPONENT_OPTS, hostname, key, keyPath, logFile, password, port, trusted, trustedPath
 
Constructor Summary
Agent()
           
 
Method Summary
 void checkReporterManagers(java.lang.String resourcesToCheck)
          Check to see if the reporter manager has been staged to all resources in the specified resource group
 void distributePackageUpdate(java.lang.String packageName)
          Send a newer version of the specified package to all remote reporter managers.
 void distributeSuites(java.util.HashMap suites)
          Send the suites to all reporter managers.
 java.lang.String getAdminEmail()
          Return the email address used to send notifications upon reporter manager restart.
 edu.sdsc.inca.DepotClient getDepotClient()
          Returns the depot client object to use to communicate to the depot (currently to send suite expanded documents).
 java.lang.String[] getDepots()
          Get the URIs for the depots.
static Agent getGlobalAgent()
           
 int getPingPeriod()
          Return the current wait period between pinging of a reporter manager.
 ReporterManagerController getReporterManager(java.lang.String resource)
          Get the controller for the remote reporter manager.
 ReporterManagerTable getReporterManagerTable()
           
 edu.sdsc.inca.repository.Repositories getRepositories()
          Returns the list of reporter repositories the agent knows about.
 RepositoryCache getRepositoryCache()
          Return the repository cache which provides access to packages cached locally on the Agent as they are requested in suites.
 edu.sdsc.inca.util.ResourcesWrapper getResources()
          Retrieves the current resource configuration stored on the agent.
 int getStartAttemptWaitPeriod()
          Return the current wait period between start attempts.
 SuiteTable getSuites()
          Returns the suites stored at the agent.
 boolean hasCredentials()
           
static void main(java.lang.String[] args)
           
 void registerReporterManager(java.lang.String resource, edu.sdsc.inca.protocol.ProtocolReader reader, edu.sdsc.inca.protocol.ProtocolWriter writer)
          Register the given reporter manager with the agent so that the agent can begin to send it requests.
static void reinitialize()
           
 void reinitializeManagerWorkQueue(java.lang.String resource, edu.sdsc.inca.util.WorkQueue queue)
          Called when a remote reporter manager registers with the agent in order to get the existing suites for this resource.
 void restartSuites()
          Read the existing suites from disk and restart them.
 void runServer()
          Starts the Agent server.
 void setAdminEmail(java.lang.String adminEmail)
          Set the email address of the Inca administrator who should be notified when reporter managers are restarted.
 void setAgentTempPath(java.lang.String path)
          Sets the directory path where the Agent stores state files such as its list of reporter repositories, reporter cache files, resources, and suites.
 void setConfiguration(java.util.Properties config)
          Overrides the server's setConfiguration function to configure the agent specific properties.
 void setDepots(java.lang.String[] depots)
          Set the URIs for the depots.
static void setGlobalAgent(Agent a)
          Set a new global agent.
 void setPingPeriod(int pingPeriod)
          Set the period for how often to ping the reporter manager.
 void setRepositories(edu.sdsc.inca.repository.Repository[] repos)
          Set the repositories the agent should download reporters from upon receiving a suite (if it hasn't downloaded them before).
 void setRepositoryCache(RepositoryCache repositoryCache)
          Set the repository cache which provides access to packages cached locally on the Agent as they are requested in suites.
 void setResources(edu.sdsc.inca.util.ResourcesWrapper resources)
          Sets the resource configuration for the agent.
 void setStartAttemptWaitPeriod(int startAttemptWaitPeriod)
          Set the current wait period between start attempts.
 void setSuites(java.lang.String path)
          Create a suite directory for storing the results of suites
 void shutdown()
          Overrides the server shutdown in order to shutdown the reporter manager's before the general server shutdown.
 void updateCachedPackages()
          Check for updates on all packages in the repository cache including reporters.
 void updateResources(edu.sdsc.inca.util.ResourcesWrapper resources)
          Updates the resource configuration on the agent.
 void updateSuite(edu.sdsc.inca.util.SuiteWrapper suite)
          Receive a set suite request from client and validate the XML.
 java.math.BigInteger updateSuiteOnDepot(edu.sdsc.inca.dataModel.suite.SuiteDocument expanded)
          Send the suite changes to the depot.
 void upgradeReporterManagers(java.lang.String resourcesToUpgrade, java.lang.String targetsToExecute)
          Upgrade the reporter manager distributions on the specified resources read upon configuration.
 
Methods inherited from class edu.sdsc.inca.Server
getTempPath, getWorkerCount, isRunning, setTempPath, setWorkerCount
 
Methods inherited from class edu.sdsc.inca.Component
addTrustedCert, configComponent, createSocket, getAuthenticate, getCertificate, getCertificatePath, getHostname, getKey, getKeyPath, getLogFile, getPassword, getPort, getTrustedCertificates, getTrustedPath, getUri, openResourceStream, readCredentials, readVersion, setAuthenticate, setCertificatePath, setHostname, setKeyPath, setLogFile, setPassword, setPort, setTrustedPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLOBUS_IP_PROPERTY

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

PING_PERIOD

public static final int PING_PERIOD
See Also:
Constant Field Values

REPOSITORY_CACHE

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

REPOSITORIES_PATH

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

RESOURCES_PATH

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

RMDIR

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

START_ATTEMPT_PERIOD

public static final int START_ATTEMPT_PERIOD
See Also:
Constant Field Values

SUITEDIR_PATH

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

ranShutdown

protected boolean ranShutdown

upgradeReporterManagers

protected java.lang.String upgradeReporterManagers

upgradeTargets

protected java.lang.String upgradeTargets

checkReporterManagers

protected java.lang.String checkReporterManagers
Constructor Detail

Agent

public Agent()
Method Detail

checkReporterManagers

public void checkReporterManagers(java.lang.String resourcesToCheck)
                           throws edu.sdsc.inca.ConfigurationException,
                                  java.lang.InterruptedException
Check to see if the reporter manager has been staged to all resources in the specified resource group

Parameters:
resourcesToCheck - A resource or resource group to check
Throws:
ConfigurationException - if missing information about a resource
java.lang.InterruptedException - if receives interrupt

distributePackageUpdate

public void distributePackageUpdate(java.lang.String packageName)
Send a newer version of the specified package to all remote reporter managers.

Parameters:
packageName - The name of the package to update.

distributeSuites

public void distributeSuites(java.util.HashMap suites)
Send the suites to all reporter managers.

Parameters:
suites - A HashMap where the resources are the keys and each entry is the SuiteDocument that should be distributed to the resource.

getAdminEmail

public java.lang.String getAdminEmail()
Return the email address used to send notifications upon reporter manager restart.

Returns:
The email address of the administrator or null if no emails should be sent.

getDepotClient

public edu.sdsc.inca.DepotClient getDepotClient()
Returns the depot client object to use to communicate to the depot (currently to send suite expanded documents).

Returns:
a depot client object.

getDepots

public java.lang.String[] getDepots()
Get the URIs for the depots. For now this is one depot, but in the future we will have a list of depots. The first depot in the list will be used unless it is unreachable. In that case, subsequent depots in the list will be tried until one is reachable.

Returns:
A list of depot URIs in the format: inca[s]://host:port

getGlobalAgent

public static Agent getGlobalAgent()

getPingPeriod

public int getPingPeriod()
Return the current wait period between pinging of a reporter manager.

Returns:
the current ping wait period

getReporterManager

public ReporterManagerController getReporterManager(java.lang.String resource)
Get the controller for the remote reporter manager. If the reporter manager does not exist already, create it.

Parameters:
resource - The name of the resource.
Returns:
A reporter manager controller for the remote reporter manager process. If we have just created the reporter manager process, will not wait for reporter manager to register.

getReporterManagerTable

public ReporterManagerTable getReporterManagerTable()

getRepositories

public edu.sdsc.inca.repository.Repositories getRepositories()
Returns the list of reporter repositories the agent knows about.

Returns:
A list of repository objects.

getRepositoryCache

public RepositoryCache getRepositoryCache()
Return the repository cache which provides access to packages cached locally on the Agent as they are requested in suites.

Returns:
The repository cache object.

getResources

public edu.sdsc.inca.util.ResourcesWrapper getResources()
Retrieves the current resource configuration stored on the agent.

Returns:
A ResourcesWrapper object which holds the current resource configuration.

getStartAttemptWaitPeriod

public int getStartAttemptWaitPeriod()
Return the current wait period between start attempts.

Returns:
the current start attempt wait period

getSuites

public SuiteTable getSuites()
Returns the suites stored at the agent.

Returns:
A table of suites where the keys are the names of the suites and the entries are SuiteDocuments.

runServer

public void runServer()
               throws java.lang.Exception
Starts the Agent server. This overrides the Server call in order to do some post configuration.

Overrides:
runServer in class edu.sdsc.inca.Server
Throws:
java.lang.Exception

setConfiguration

public void setConfiguration(java.util.Properties config)
                      throws edu.sdsc.inca.ConfigurationException
Overrides the server's setConfiguration function to configure the agent specific properties.

Overrides:
setConfiguration in class edu.sdsc.inca.Server
Parameters:
config - contains configuration values
Throws:
ConfigurationException - on a faulty configuration property value

setDepots

public void setDepots(java.lang.String[] depots)
Set the URIs for the depots. The first depot in the list will be used unless it is unreachable. In that case, subsequent depots in the list will be tried until one is reachable.

Parameters:
depots - A list of depot URIs in the format: inca[s]://host:port

setGlobalAgent

public static void setGlobalAgent(Agent a)
Set a new global agent.

Parameters:
a - The new agent object

setPingPeriod

public void setPingPeriod(int pingPeriod)
Set the period for how often to ping the reporter manager.

Parameters:
pingPeriod - The period to wait in between pings to the reporter manager.

setRepositories

public void setRepositories(edu.sdsc.inca.repository.Repository[] repos)
                     throws java.io.IOException
Set the repositories the agent should download reporters from upon receiving a suite (if it hasn't downloaded them before).

Parameters:
repos - A list of repositories.
Throws:
java.io.IOException - if trouble contacting repositories

setRepositoryCache

public void setRepositoryCache(RepositoryCache repositoryCache)
Set the repository cache which provides access to packages cached locally on the Agent as they are requested in suites.

Parameters:
repositoryCache - A repository cache object.

updateCachedPackages

public void updateCachedPackages()
Check for updates on all packages in the repository cache including reporters. A series config is identified by the reporter context and version of the reporter. So, if a series config in a suite uses the latest version of a package and there is a reporter update, we will need to delete the existing series config (with its current version) and add a new series config (with the updated package version). This function will iterate thru the agent's existing suites and perform the needed adds and deletes.


updateResources

public void updateResources(edu.sdsc.inca.util.ResourcesWrapper resources)
                     throws org.apache.xmlbeans.XmlException,
                            edu.sdsc.inca.protocol.ProtocolException,
                            edu.sdsc.inca.ConfigurationException,
                            edu.sdsc.inca.util.CrypterException,
                            java.io.IOException
Updates the resource configuration on the agent.

Parameters:
resources - A ResourcesWrapper object which contains the new resource configuration for the agent to utilize.
Throws:
ConfigurationException - if trouble reading info about resources
edu.sdsc.inca.util.CrypterException - if trouble reading resource information
java.io.IOException - if trouble communicating with resources
edu.sdsc.inca.protocol.ProtocolException - if problem communicating with resources
org.apache.xmlbeans.XmlException - if trouble updating resources

registerReporterManager

public void registerReporterManager(java.lang.String resource,
                                    edu.sdsc.inca.protocol.ProtocolReader reader,
                                    edu.sdsc.inca.protocol.ProtocolWriter writer)
                             throws java.io.IOException
Register the given reporter manager with the agent so that the agent can begin to send it requests.

Parameters:
resource - The resource the reporter manager is running on.
reader - the ProtocolReader for reading responses from the remote reporter manager.
writer - the ProtocolWriter for sending commands to the remote reporter manager.
Throws:
java.io.IOException - if trouble writing response to reporter manager

reinitialize

public static void reinitialize()

reinitializeManagerWorkQueue

public void reinitializeManagerWorkQueue(java.lang.String resource,
                                         edu.sdsc.inca.util.WorkQueue queue)
Called when a remote reporter manager registers with the agent in order to get the existing suites for this resource. Since we don't know if this is a restart, we empty its queue and get the suites from the table (since the suites contain any changes that might be in the queue). Since this function is sychronized, it should be safe from race conditions (e.g., that might result in a suite being added twice).

Parameters:
resource - The resource the remote reporter manager is executing on.
queue - The reporter manager's work queue.

restartSuites

public void restartSuites()
Read the existing suites from disk and restart them.


setAdminEmail

public void setAdminEmail(java.lang.String adminEmail)
Set the email address of the Inca administrator who should be notified when reporter managers are restarted.

Parameters:
adminEmail - An email address of the Inca administrator.

setAgentTempPath

public void setAgentTempPath(java.lang.String path)
                      throws java.io.IOException
Sets the directory path where the Agent stores state files such as its list of reporter repositories, reporter cache files, resources, and suites.

Parameters:
path - the temporary directory path
Throws:
java.io.IOException - if the path does not exist and cannot be created

setStartAttemptWaitPeriod

public void setStartAttemptWaitPeriod(int startAttemptWaitPeriod)
Set the current wait period between start attempts.

Parameters:
startAttemptWaitPeriod - the new start attempt wait period

setSuites

public void setSuites(java.lang.String path)
Create a suite directory for storing the results of suites

Parameters:
path - A string containing the path to store suites

shutdown

public void shutdown()
              throws java.lang.InterruptedException
Overrides the server shutdown in order to shutdown the reporter manager's before the general server shutdown.

Overrides:
shutdown in class edu.sdsc.inca.Server
Throws:
java.lang.InterruptedException - (see server javadoc)

setResources

public void setResources(edu.sdsc.inca.util.ResourcesWrapper resources)
                  throws org.apache.xmlbeans.XmlException,
                         edu.sdsc.inca.util.CrypterException,
                         java.io.IOException
Sets the resource configuration for the agent.

Parameters:
resources - The resource configuration information.
Throws:
edu.sdsc.inca.util.CrypterException - if trouble encrypting/decrypting resources
java.io.IOException - if trouble communicating with reporter managers
org.apache.xmlbeans.XmlException - if trouble reading resources

updateSuite

public void updateSuite(edu.sdsc.inca.util.SuiteWrapper suite)
Receive a set suite request from client and validate the XML. Then: 1) resolve the reporter names into reporter uris using available repos 2) set the guid of the suite 3) apply the expanded suite to the existing suite and hold onto the applied changes 4) create resource suites 5) test the resources if no RM running now 6) send the suite expanded to the depot 7) return ok to the client 8) load the reporters into our cache 9) send the suites to the reporter managers

Parameters:
suite - An update to a suite or a new suite.

updateSuiteOnDepot

public java.math.BigInteger updateSuiteOnDepot(edu.sdsc.inca.dataModel.suite.SuiteDocument expanded)
                                        throws edu.sdsc.inca.ConfigurationException,
                                               java.io.IOException,
                                               edu.sdsc.inca.protocol.ProtocolException
Send the suite changes to the depot.

Parameters:
expanded - An expanded suite document that should be sent to depot
Returns:
the new suite version number
Throws:
ConfigurationException - if trouble reading config info
java.io.IOException - if trouble communicating with depot
edu.sdsc.inca.protocol.ProtocolException - if unexpected responses from depot

upgradeReporterManagers

public void upgradeReporterManagers(java.lang.String resourcesToUpgrade,
                                    java.lang.String targetsToExecute)
                             throws edu.sdsc.inca.ConfigurationException
Upgrade the reporter manager distributions on the specified resources read upon configuration.

Parameters:
resourcesToUpgrade - A resource name or group to upgrade
targetsToExecute - The makefile target to execute for the upgrade
Throws:
ConfigurationException - if trouble reading resource config info

hasCredentials

public boolean hasCredentials()

main

public static void main(java.lang.String[] args)