Package net.sf.basedb.opengrid.service
Class OpenGridService
java.lang.Object
net.sf.basedb.opengrid.service.OpenGridService
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
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Task for checking current status of jobs that has been sent to the cluster.(package private) static class
(package private) static class
Task for checking current status of jobs that has been sent to the cluster. -
Field Summary
Modifier and TypeFieldDescriptionprivate TimerTask
private final Map<String,
OpenGridCluster> private Extension<ServiceControllerAction>
static final String
The ID of the service extension.private static OpenGridService
private boolean
private TimerTask
private final Set<JobIdentifier>
private final Set<JobIdentifier>
private long
private long
private static final ExtensionsLogger
private static final long
private static final long
private static final long
private static final long
private final Map<JobIdentifier,
JobStatusUpdater> private SessionControl
private SessionControl
private final Set<JobIdentifier>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
asyncJobAbort
(JobIdentifier jobId) Register a job that should be aborted.void
Register a status update request for a job.void
asyncJobStatusUpdate
(JobIdentifier jobId, JobStatusUpdater updater) Register a status update request for a job that is is not an Open Grid job.getClusterById
(DbControl dc, String clusterId) Get information about a cluster with known id.getClusters
(Collection<JobAgent> jobAgents) 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.getClusters
(DbControl dc, Collection<Include> include) getClusters
(DbControl dc, Collection<Include> include, Filter<OpenGridCluster> filter) Get all clusters that the logged in user is allowed to use.static final OpenGridService
Get the singleton instance of the service.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.boolean
Check if a cluster with the given id has been defined and registered with this service.boolean
Is the Open Grid service running or not?(package private) void
Process async requests since the last time.(package private) void
private boolean
setErrorOnBaseJob
(JobIdentifier jobId, String msg) Set ERROR status on a BASE job.private boolean
setProgressOnBaseJob
(JobIdentifier jobId, int progress, String msg) Update the progress status on a BASE job.(package private) void
start
(SessionControl systemSc, Extension<ServiceControllerAction> ext) Start the service if it is not running.(package private) void
stop()
Stop the service if it is running.private void
private OpenGridSession
tryConnect
(JobIdentifier jobId) Try to connect to the cluster referenced by the job identifier.private boolean
updateJobStatusInBase
(JobStatus jobStatus, OpenGridSession session, OpenGridService.JobCompletionInvoker jobCompletionInvoker)
-
Field Details
-
ID
The ID of the service extension.- Since:
- 1.10
- See Also:
-
logger
-
instance
-
MIN_WAIT_INTERVAL_NORMAL
private static final long MIN_WAIT_INTERVAL_NORMAL- See Also:
-
MIN_WAIT_INTERVAL_DEBUG
private static final long MIN_WAIT_INTERVAL_DEBUG- See Also:
-
MIN_CLEANUP_INTERVAL_NORMAL
private static final long MIN_CLEANUP_INTERVAL_NORMAL- See Also:
-
MIN_CLEANUP_INTERVAL_DEBUG
private static final long MIN_CLEANUP_INTERVAL_DEBUG- See Also:
-
clusters
-
isRunning
private volatile boolean isRunning -
jobStatusTimer
-
cleanupTimer
-
lastJobStatusUpdate
private long lastJobStatusUpdate -
lastCleanup
private long lastCleanup -
systemSc
-
rootSc
-
ext
-
jobsToAbort
-
jobsToUpdate
-
nonGridJobsToUpdate
-
unknownJobs
-
-
Constructor Details
-
OpenGridService
private OpenGridService()
-
-
Method Details
-
getInstance
Get the singleton instance of the service. If the service has not been created yet it is created at this time. -
isDefined
Check if a cluster with the given id has been defined and registered with this service. -
getClusterById
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 foundPermissionDeniedException
- If the cluster is linked to a job agent that the user doens't have permission to use
-
getClusters
- 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 DbControlinclude
- 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
- 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 returnedfilter
- 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
Start the service if it is not running. -
stop
void stop()Stop the service if it is running. -
stopInternal
private void stopInternal() -
asyncJobAbort
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
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
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 theJobIdentifier.getClusterId()
is found theJobStatusUpdater.getJobStatus(OpenGridSession, JobIdentifier)
is provided with a connected session, otherwise that parameter is null. TheJobIdentifier.getClusterJobId()
can always be substituted with some other ID.- Parameters:
jobId
- A job identifier with exceptions as noted aboveupdater
- 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
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
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
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
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)
-