Class OpenGridService

java.lang.Object
net.sf.basedb.opengrid.service.OpenGridService

public class OpenGridService extends Object
Service class for asynchronous communication with Open Grid Scheduler clusters. When the service is running it will at regular intervals query the registered clusters for waiting and running jobs. The service will also maintain a list of available Open Grid Clusters that are configured in the opengrid-config.xml file (should located in the WEB-INF/classes directory).
Since:
1.0
Author:
nicklas
  • Field Details

  • Constructor Details

    • OpenGridService

      private OpenGridService()
  • Method Details

    • getInstance

      public static final OpenGridService getInstance()
      Get the singleton instance of the service. If the service has not been created yet it is created at this time.
    • isDefined

      public boolean isDefined(String clusterId)
      Check if a cluster with the given id has been defined and registered with this service.
    • getClusterById

      public OpenGridCluster getClusterById(DbControl dc, String clusterId)
      Get information about a cluster with known id. If the cluster is linked to a job agent, a permission check is made to see if the logged in user has USE permission on the job agent.
      Parameters:
      dc - An open DbControl for permission check against job agents (null is allowed if the cluster is not linked to a job agent)
      clusterId - The ID of the cluster
      Returns:
      A cluster instance or null if not found
      Throws:
      ItemNotFoundException - If a cluster is found but the job agent it is linked to is not found
      PermissionDeniedException - If the cluster is linked to a job agent that the user doens't have permission to use
    • getClusters

      public Collection<OpenGridCluster> getClusters(DbControl dc, Collection<Include> include)
      See Also:
    • getClusters

      public Collection<OpenGridCluster> getClusters(DbControl dc, Collection<Include> include, Filter<OpenGridCluster> filter)
      Get all clusters that the logged in user is allowed to use. This method uses a query for job agents with the given include settings (for example, Include.IN_PROJECT). Clusters that are open to all are always included.
      Parameters:
      dc - An open DbControl
      include - A set of include options for the job agent query (if null the default query options are used)
      filter - Optional filter, if not specified all clusters are returned
      Since:
      1.4
    • getClusters

      public Collection<OpenGridCluster> getClusters(Collection<JobAgent> jobAgents)
      See Also:
    • getClusters

      public Collection<OpenGridCluster> getClusters(Collection<JobAgent> jobAgents, Filter<OpenGridCluster> filter)
      Get a collection with all registered clusters that are either open to all or referencing one of the listed job agents where the logged in user has at least USE permission.
      Parameters:
      jobAgents - A list of job agents (must exist in the database) If null or empty, only clusters that are open to all are returned
      filter - Optional filter, if not specified all clusters are returned
      Since:
      1.4
    • isRunning

      public boolean isRunning()
      Is the Open Grid service running or not?
    • start

      void start(SessionControl systemSc, Extension<ServiceControllerAction> ext)
      Start the service if it is not running.
    • stop

      void stop()
      Stop the service if it is running.
    • stopInternal

      private void stopInternal()
    • asyncJobAbort

      public void asyncJobAbort(JobIdentifier jobId)
      Register a job that should be aborted. The job identifier may or may not include a BASE job id. If a BASE job id is specified the information in the database is updated once the job has been aborted on the cluster.
      Parameters:
      jobId - The job identifier
    • asyncJobStatusUpdate

      public void asyncJobStatusUpdate(JobIdentifier jobId)
      Register a status update request for a job. The job identifier may or may not include a BASE job id. If a BASE job id is specified the information in the database is updated once the job information has been retrieved from the cluster.
      Parameters:
      jobId - The job identifier
    • asyncJobStatusUpdate

      public void asyncJobStatusUpdate(JobIdentifier jobId, JobStatusUpdater updater)
      Register a status update request for a job that is is not an Open Grid job. This exists as a service to other extensions that need to connect to a remote host and make some checks via SSH. If a cluster that matches the JobIdentifier.getClusterId() is found the JobStatusUpdater.getJobStatus(OpenGridSession, JobIdentifier) is provided with a connected session, otherwise that parameter is null. The JobIdentifier.getClusterJobId() can always be substituted with some other ID.
      Parameters:
      jobId - A job identifier with exceptions as noted above
      updater - The actual instance that performs the update check
    • processAsyncRequests

      void processAsyncRequests()
      Process async requests since the last time. ABORT requests are always processed. STATUS requests are only processed if it was more the MIN_WAIT_INTERVAL milliseconds since that last update.
    • processCleanupTasks

      void processCleanupTasks()
    • getSession

      private OpenGridSession getSession(JobIdentifier jobId, Map<String,OpenGridSession> sessions)
      Get an existing session from the cache or create a new connection if it doesn't exists. If no connection could be created null is returned.
    • tryConnect

      private OpenGridSession tryConnect(JobIdentifier jobId)
      Try to connect to the cluster referenced by the job identifier. Exceptions are handled inside the method which only return null if no connection could be established.
    • setErrorOnBaseJob

      private boolean setErrorOnBaseJob(JobIdentifier jobId, String msg)
      Set ERROR status on a BASE job. This is done in a separate transaction. Exceptions are logged but not re-thrown out of this method.
      Returns:
      TRUE if the operation succeeded, FALSE if not
    • setProgressOnBaseJob

      private boolean setProgressOnBaseJob(JobIdentifier jobId, int progress, String msg)
      Update the progress status on a BASE job. This is done in a separate transaction. Exceptions are logged but not re-thrown out of this method.
      Returns:
      TRUE if the operation succeeded, FALSE if not
    • updateJobStatusInBase

      private boolean updateJobStatusInBase(JobStatus jobStatus, OpenGridSession session, OpenGridService.JobCompletionInvoker jobCompletionInvoker)