Interface ServiceRegistry
- All Known Implementing Classes:
ServiceRegistryInMemoryImpl,ServiceRegistryJpaImpl
public interface ServiceRegistry
Manages clustered services and the
Jobs they may create to enable asynchronous job handling.-
Method Summary
Modifier and TypeMethodDescriptionlongcount(String serviceType, String host, String operation, Job.Status status) Count the number of jobs executing the given operation in thisJob.Statuson this host.longcount(String serviceType, Job.Status status) Count the number of jobs that match the specified parameters.Count active jobs and group them by organization and host.countActiveTypeByOrganization(String operation) Count active jobs of a given operation type and group them by organization.longcountByHost(String serviceType, String host, Job.Status status) Count the number of jobs in thisJob.Statuson this hostlongcountByOperation(String serviceType, String operation, Job.Status status) Count the number of jobs running the given operation in thisJob.Status.Create and store a new job that will be dispatched as soon as possible.Create and store a new job that will be dispatched as soon as possible.Create and store a new job that will be dispatched as soon as possible.Create and store a new job.createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Float jobLoad) Create and store a new job.createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Job parentJob, Float jobLoad) Create and store a new job.voiddisableHost(String host) Disables a Opencast server from service.voidenableHost(String host) Enable an inactive host as a provider of Opencast services.Get the list of active jobs.getChildJobs(long id) Get all child jobs from a jobGets a map of hosts to the number of jobs currently loading that hostGets the current running jobgetHostRegistration(String hostname) Finds host registration for the given hostname.Finds all host registrations, including offline hosts and those in maintenance mode.Get statistics about jobs active on hosts.getJob(long id) Gets a receipt by its ID, or null if not foundintgetJobCount(String operation) Return the number of jobs for a specified operation type.getJobPayloads(String operation) Return the payload of all jobs for a specified operation type.getJobPayloads(String operation, int limit, int offset) Return the payload of a specified number of jobs for a specified operation type.getJobs(String serviceType, Job.Status status) Gets the list of jobs that match the specified parameters.getMaxLoadOnNode(String host) Returns the maximum load that can be handled by a given node.Returns the maximum load that can be handled by the currently registered hosts.floatGets the load value for the current host (ie, the host this service registry lives onReturns the service regstry's hostname.getServiceRegistration(String serviceType, String host) Finds a single service registration by host and type, even if the service is offline or in maintenance mode.Finds all service registrations, including offline services and those in maintenance mode.Finds the service registrations on the given host, including offline services and those in maintenance mode.getServiceRegistrationsByLoad(String serviceType) Finds the service registrations for this kind of job, ordered by load (lightest to heaviest).getServiceRegistrationsByType(String serviceType) Finds the service registrations for this kind of job, including offline services and those in maintenance mode.Gets performance and runtime statistics for each known service registration.incident()Return a facility to record job incidents.voidregisterHost(String host, String address, String nodeName, long memory, int cores, float maxLoad) Registers a host as a provider of Opencast services.registerService(String serviceType, String host, String path) Registers a host to handle a specific type of jobregisterService(String serviceType, String host, String path, boolean jobProducer) Registers a host to handle a specific type of jobvoidremoveJobs(List<Long> ids) Deletes the given jobs from the service registryvoidremoveParentlessJobs(int lifetime) Removes all jobs which do not have a parent job (except workflow instance jobs) and which have passed their lifetime.voidSets the given service to NORMAL statevoidsetCurrentJob(Job job) Sets the current running jobvoidsetMaintenanceStatus(String host, boolean maintenance) Sets a registered host's maintenance statusvoidunregisterHost(String host) Removes an Opencast server from service.voidunRegisterService(String serviceType, String host) Unregisters a host from handling a specific type of jobUpdate the job in the database
-
Method Details
-
registerHost
void registerHost(String host, String address, String nodeName, long memory, int cores, float maxLoad) throws ServiceRegistryException Registers a host as a provider of Opencast services.- Parameters:
host- The base URL for this serveraddress- The IP address of this hostnodeName- Human readable description of this nodememory- The allocated memory of this hostcores- The available cores of this hostmaxLoad- the maximum load this host can support- Throws:
ServiceRegistryException- if communication with the service registry fails
-
unregisterHost
Removes an Opencast server from service.- Parameters:
host- The base URL for this server- Throws:
ServiceRegistryException- if communication with the service registry fails
-
enableHost
Enable an inactive host as a provider of Opencast services.- Parameters:
host- The base URL for this server- Throws:
NotFoundException- if the host does not existServiceRegistryException- if communication with the service registry fails
-
disableHost
Disables a Opencast server from service.- Parameters:
host- The base URL for this server- Throws:
NotFoundException- if the host does not existServiceRegistryException- if communication with the service registry fails
-
getMaxLoads
Returns the maximum load that can be handled by the currently registered hosts. Note that this load is *not* 1-to-1 equivalent with number of jobs. A job may take up more than one load.- Returns:
- the total load that can be processed concurrently
- Throws:
ServiceRegistryException- if communication with the service registry fails
-
getMaxLoadOnNode
SystemLoad.NodeLoad getMaxLoadOnNode(String host) throws ServiceRegistryException, NotFoundException Returns the maximum load that can be handled by a given node. Note that this load is *not* 1-to-1 equivalent with number of jobs. A job may take up more than one load.- Parameters:
host- The base URL for this server- Returns:
- the total load that can be processed concurrently on that node
- Throws:
ServiceRegistryException- if communication with the service registry failsNotFoundException
-
getCurrentHostLoads
Gets a map of hosts to the number of jobs currently loading that host- Returns:
- the map of hosts to job counts
- Throws:
ServiceRegistryException
-
getOwnLoad
Gets the load value for the current host (ie, the host this service registry lives on- Returns:
- the load value for this host
- Throws:
ServiceRegistryException
-
registerService
ServiceRegistration registerService(String serviceType, String host, String path) throws ServiceRegistryException Registers a host to handle a specific type of job- Parameters:
serviceType- The job typehost- The base URL where the service that can handle this service type can be foundpath- The path to the service endpoint- Returns:
- the service registration
- Throws:
ServiceRegistryException- if communication with the service registry fails
-
registerService
ServiceRegistration registerService(String serviceType, String host, String path, boolean jobProducer) throws ServiceRegistryException Registers a host to handle a specific type of job- Parameters:
serviceType- The service typehost- The base URL where the service that can handle this job type can be foundpath- The path to the service endpointjobProducer- Whether this service registration producesJobs to track long running operations- Returns:
- the service registration
- Throws:
ServiceRegistryException- if communication with the service registry fails
-
unRegisterService
Unregisters a host from handling a specific type of job- Parameters:
serviceType- The service typehost- The base URL where the service that can handle this job type can be found- Throws:
ServiceRegistryException- if communication with the service registry fails
-
setMaintenanceStatus
void setMaintenanceStatus(String host, boolean maintenance) throws ServiceRegistryException, NotFoundException Sets a registered host's maintenance status- Parameters:
host- The base URL where the service that can handle this service type can be foundmaintenance- the new maintenance status for this service- Throws:
ServiceRegistryException- if communication with the service registry failsNotFoundException- if the host does not exist
-
createJob
Create and store a new job that will be dispatched as soon as possible. This is equivalent to callingcreateJob(String, String, List, String, boolean)with an empty argument list.Note that this job will be linked to the current job as its parent.
- Parameters:
type- the type of service responsible for this joboperation- the operation for this service to run- Returns:
- the job
- Throws:
ServiceRegistryException- if there is a problem creating the job
-
createJob
Job createJob(String type, String operation, List<String> arguments) throws ServiceRegistryException Create and store a new job that will be dispatched as soon as possible. This is equivalent to callingcreateJob(String, String, List, String, boolean).Note that this job will be linked to the current job as its parent.
- Parameters:
type- the type of service responsible for this joboperation- the operation for this service to runarguments- the arguments to the operation- Returns:
- the job
- Throws:
ServiceRegistryException- if there is a problem creating the job
-
createJob
Job createJob(String type, String operation, List<String> arguments, Float jobLoad) throws ServiceRegistryException Create and store a new job that will be dispatched as soon as possible. This is equivalent to callingcreateJob(String, String, List, String, boolean).Note that this job will be linked to the current job as its parent.
- Parameters:
type- the type of service responsible for this joboperation- the operation for this service to runarguments- the arguments to the operationjobLoad- the load caused by this job, roughly equivalent to the number of cores used this job- Returns:
- the job
- Throws:
ServiceRegistryException- if there is a problem creating the job
-
createJob
Job createJob(String type, String operation, List<String> arguments, String payload, boolean queueable) throws ServiceRegistryException Create and store a new job. IfenqueueImmediatelyis true, the job will be in theJob.Status.QUEUEDstate and will be dispatched as soon as possible. Otherwise, it will beJob.Status.INSTANTIATED.Note that this job will be linked to the current job as its parent.
- Parameters:
type- the type of service responsible for this joboperation- the operation for this service to runarguments- the arguments to the operationpayload- an optional initial payloadqueueable- whether the job can be enqueued for dispatch. If false, the job's initial state will beJob.Status.INSTANTIATEDand will not be dispatched.- Returns:
- the job
- Throws:
ServiceRegistryException- if there is a problem creating the job
-
createJob
Job createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Float jobLoad) throws ServiceRegistryException Create and store a new job. IfenqueueImmediatelyis true, the job will be in theJob.Status.QUEUEDstate and will be dispatched as soon as possible. Otherwise, it will beJob.Status.INSTANTIATED.Note that this job will be linked to the current job as its parent.
- Parameters:
type- the type of service responsible for this joboperation- the operation for this service to runarguments- the arguments to the operationpayload- an optional initial payloadqueueable- whether the job can be enqueued for dispatch. If false, the job's initial state will beJob.Status.INSTANTIATEDand will not be dispatched.jobLoad- the load caused by this job, roughly equivalent to the number of cores used this job- Returns:
- the job
- Throws:
ServiceRegistryException- if there is a problem creating the job
-
createJob
Job createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Job parentJob, Float jobLoad) throws ServiceRegistryException Create and store a new job. IfenqueueImmediatelyis true, the job will be in theJob.Status.QUEUEDstate and will be dispatched as soon as possible. Otherwise, it will beJob.Status.INSTANTIATED.- Parameters:
type- the type of service responsible for this joboperation- the operation for this service to runarguments- the arguments to the operationpayload- an optional initial payloadqueueable- whether the job can be enqueued for dispatch. If false, the job's initial state will beJob.Status.INSTANTIATEDand will not be dispatched.parentJob- the parent jobjobLoad- the load caused by this job, roughly equivalent to the number of cores used this job- Returns:
- the job
- Throws:
ServiceRegistryException- if there is a problem creating the job
-
updateJob
Update the job in the database- Parameters:
job-- Returns:
- the updated job
- Throws:
NotFoundException- if the job does not existServiceRegistryException- if there is a problem updating the job
-
getJob
Gets a receipt by its ID, or null if not found- Parameters:
id- the job id- Returns:
- the job or null
- Throws:
NotFoundExceptionServiceRegistryException
-
removeJobs
Deletes the given jobs from the service registry- Parameters:
ids- the job ids- Throws:
NotFoundExceptionServiceRegistryException
-
removeParentlessJobs
Removes all jobs which do not have a parent job (except workflow instance jobs) and which have passed their lifetime.- Parameters:
lifetime- lifetime in days- Throws:
ServiceRegistryException- if removing the jobs fails
-
getCurrentJob
Job getCurrentJob()Gets the current running job- Returns:
- the current job
-
setCurrentJob
Sets the current running job- Parameters:
job- the current job
-
getJobs
Gets the list of jobs that match the specified parameters.- Parameters:
serviceType- The jobs run by this type of service. If null, jobs from all hosts will be returned.status- The status of the jobs. If null, jobs in all status will be returned.- Returns:
- the jobs matching these criteria
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getJobPayloads
Return the payload of all jobs for a specified operation type.- Parameters:
operation- Operation type to get payload for- Returns:
- Serialized workflows
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getJobPayloads
List<String> getJobPayloads(String operation, int limit, int offset) throws ServiceRegistryException Return the payload of a specified number of jobs for a specified operation type.- Parameters:
operation- Operation type to get payload forlimit- How many results to returnoffset- Offset for the set of returned results- Returns:
- Serialized workflows
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getJobCount
Return the number of jobs for a specified operation type.- Parameters:
operation- Operation type to check for- Returns:
- Number of jobs for the specified operation type.
- Throws:
ServiceRegistryException
-
getActiveJobs
Get the list of active jobs.- Returns:
- list of active jobs
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getChildJobs
Get all child jobs from a job- Parameters:
id- the parent job id- Returns:
- a list of the child jobs ordered by execution
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
incident
Incidents incident()Return a facility to record job incidents.- See Also:
-
getServiceRegistrationsByLoad
List<ServiceRegistration> getServiceRegistrationsByLoad(String serviceType) throws ServiceRegistryException Finds the service registrations for this kind of job, ordered by load (lightest to heaviest).- Parameters:
serviceType- The type of service that must be handled by the hosts- Returns:
- A list of hosts that handle this job type, in order of their running and queued job load
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getServiceRegistrationsByType
List<ServiceRegistration> getServiceRegistrationsByType(String serviceType) throws ServiceRegistryException Finds the service registrations for this kind of job, including offline services and those in maintenance mode.- Parameters:
serviceType- The type of service that must be handled by the hosts- Returns:
- A list of hosts that handle this job type
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getServiceRegistrationsByHost
List<ServiceRegistration> getServiceRegistrationsByHost(String host) throws ServiceRegistryException Finds the service registrations on the given host, including offline services and those in maintenance mode.- Parameters:
host- The host- Returns:
- A list of service registrations on a single host
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getServiceRegistration
ServiceRegistration getServiceRegistration(String serviceType, String host) throws ServiceRegistryException Finds a single service registration by host and type, even if the service is offline or in maintenance mode.- Parameters:
serviceType- The type of servicehost- the base URL of the host- Returns:
- The service registration, or null
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getServiceRegistrations
Finds all service registrations, including offline services and those in maintenance mode.- Returns:
- A list of service registrations
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getRegistryHostname
String getRegistryHostname()Returns the service regstry's hostname. This can be used to fetch the list of services on the local host.- Returns:
- The hostname that the service registry is running on.
-
getHostRegistrations
Finds all host registrations, including offline hosts and those in maintenance mode.- Returns:
- A list of host registrations
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
getHostStatistics
HostStatistics getHostStatistics()Get statistics about jobs active on hosts.- Returns:
- Host statistics
-
getHostRegistration
Finds host registration for the given hostname.- Parameters:
hostname- to lookup- Returns:
- host registrations
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry or the hostname is not found
-
getServiceStatistics
Gets performance and runtime statistics for each known service registration.- Returns:
- the service statistics
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
count
Count the number of jobs that match the specified parameters.- Parameters:
serviceType- The jobs run by this type of service. If null, the returned count will refer to all types of jobs.status- The status of the receipts. If null, the returned count will refer to jobs in any status.- Returns:
- the number of jobs
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
countByOperation
long countByOperation(String serviceType, String operation, Job.Status status) throws ServiceRegistryException Count the number of jobs running the given operation in thisJob.Status.- Parameters:
serviceType- The jobs run by this type of serviceoperation- the operationstatus- The status of the jobs- Returns:
- the number of jobs
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
countByHost
long countByHost(String serviceType, String host, Job.Status status) throws ServiceRegistryException Count the number of jobs in thisJob.Statuson this host- Parameters:
serviceType- The jobs run by this type of servicehost- The server that created and will be handling the jobstatus- The status of the jobs- Returns:
- the number of jobs
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
count
long count(String serviceType, String host, String operation, Job.Status status) throws ServiceRegistryException Count the number of jobs executing the given operation in thisJob.Statuson this host.- Parameters:
serviceType- The jobs run by this type of servicehost- The server that created and will be handling the joboperation- the operationstatus- The status of the jobs- Returns:
- the number of jobs
- Throws:
ServiceRegistryException- if there is a problem accessing the service registry
-
countActiveByOrganizationAndHost
Count active jobs and group them by organization and host.- Returns:
- Map of organizations, hosts and the number of jobs.
-
countActiveTypeByOrganization
Count active jobs of a given operation type and group them by organization.- Returns:
- Map of organizations and the number of jobs.
-
sanitize
Sets the given service to NORMAL state- Parameters:
serviceType- the service typehost- the host- Throws:
NotFoundException- if the service does not exist
-