Class ServiceRegistryInMemoryImpl
- java.lang.Object
-
- org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl
-
- All Implemented Interfaces:
ServiceRegistry
public class ServiceRegistryInMemoryImpl extends Object implements ServiceRegistry
Simple and in-memory implementation of a the service registry intended for testing scenarios.
-
-
Field Summary
Fields Modifier and Type Field Description protected Job
currentJob
Holds the current running jobstatic long
DEFAULT_DISPATCHER_TIMEOUT
Default dispatcher timeout (1 second)protected ScheduledExecutorService
dispatcher
The thread pool to use for dispatching queued jobs.protected Map<String,HostRegistrationInMemory>
hosts
The hostsprotected AtomicLong
idCounter
The job identifierprotected Incidents
incidents
protected static List<Job.Status>
JOB_STATUSES_INFLUENCING_LOAD_BALANCING
A static list of statuses that influence how load balancing is calculatedprotected Map<ServiceRegistrationInMemoryImpl,Set<Job>>
jobHosts
A mapping of services to jobsprotected Map<Long,String>
jobs
The serialized jobsprotected OrganizationDirectoryService
organizationDirectoryService
The organization directory serviceprotected SecurityService
securityService
An (optional) security service.protected Map<String,List<ServiceRegistrationInMemoryImpl>>
services
The service registrationsprotected UserDirectoryService
userDirectoryService
The user directory service
-
Constructor Summary
Constructors Constructor Description ServiceRegistryInMemoryImpl(JobProducer service, float maxLoad, SecurityService securityService, UserDirectoryService userDirectoryService, OrganizationDirectoryService organizationDirectoryService, IncidentService incidentService)
ServiceRegistryInMemoryImpl(JobProducer service, SecurityService securityService, UserDirectoryService userDirectoryService, OrganizationDirectoryService organizationDirectoryService, IncidentService incidentService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
count(String serviceType, String host, String operation, Job.Status status)
Count the number of jobs executing the given operation in thisJob.Status
on this host.long
count(String serviceType, Job.Status status)
Count the number of jobs that match the specified parameters.long
countByHost(String serviceType, String host, Job.Status status)
Count the number of jobs in thisJob.Status
on this hostlong
countByOperation(String serviceType, String operation, Job.Status status)
Count the number of jobs running the given operation in thisJob.Status
.Job
createJob(String type, String operation)
Create and store a new job that will be dispatched as soon as possible.Job
createJob(String type, String operation, List<String> arguments)
Create and store a new job that will be dispatched as soon as possible.Job
createJob(String type, String operation, List<String> arguments, Float jobLoad)
Create and store a new job that will be dispatched as soon as possible.Job
createJob(String type, String operation, List<String> arguments, String payload)
Job
createJob(String type, String operation, List<String> arguments, String payload, boolean queueable)
Create and store a new job.Job
createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Float jobLoad)
Create and store a new job.Job
createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Job parentJob, Float jobLoad)
Create and store a new job.void
deactivate()
Shuts down this service registry, logging all jobs and their statuses.void
disableHost(String host)
Disables a Opencast server from service.protected boolean
dispatchJob(Job job)
Dispatches the job to the least loaded service or throws aServiceUnavailableException
if there is no such service.void
dispose()
This method shuts down the service registry.void
enableHost(String host)
Enable an inactive host as a provider of Opencast services.List<Job>
getActiveJobs()
Get the list of active jobs.List<Job>
getChildJobs(long id)
Get all child jobs from a jobSystemLoad
getCurrentHostLoads()
Gets a map of hosts to the number of jobs currently loading that hostJob
getCurrentJob()
Gets the current running jobHostRegistration
getHostRegistration(String hostname)
Finds host registration for the given hostname.List<HostRegistration>
getHostRegistrations()
Finds all host registrations, including offline hosts and those in maintenance mode.HostStatistics
getHostStatistics()
Get statistics about jobs active on hosts.Job
getJob(long id)
Gets a receipt by its ID, or null if not foundint
getJobCount(String operation)
Return the number of jobs for a specified operation type.List<String>
getJobPayloads(String operation)
Return the payload of all jobs for a specified operation type.List<String>
getJobPayloads(String operation, int limit, int offset)
Return the payload of a specified number of jobs for a specified operation type.List<Job>
getJobs(String serviceType, Job.Status status)
Gets the list of jobs that match the specified parameters.SystemLoad.NodeLoad
getMaxLoadOnNode(String host)
Returns the maximum load that can be handled by a given node.SystemLoad
getMaxLoads()
Returns the maximum load that can be handled by the currently registered hosts.float
getOwnLoad()
Gets the load value for the current host (ie, the host this service registry lives onString
getRegistryHostname()
Returns the service regstry's hostname.ServiceRegistration
getServiceRegistration(String serviceType, String host)
Finds a single service registration by host and type, even if the service is offline or in maintenance mode.List<ServiceRegistration>
getServiceRegistrations()
Finds all service registrations, including offline services and those in maintenance mode.List<ServiceRegistration>
getServiceRegistrationsByHost(String host)
Finds the service registrations on the given host, including offline services and those in maintenance mode.List<ServiceRegistration>
getServiceRegistrationsByLoad(String serviceType)
Finds the service registrations for this kind of job, ordered by load (lightest to heaviest).List<ServiceRegistration>
getServiceRegistrationsByType(String serviceType)
Finds the service registrations for this kind of job, including offline services and those in maintenance mode.List<ServiceStatistics>
getServiceStatistics()
Gets performance and runtime statistics for each known service registration.Incidents
incident()
Return a facility to record job incidents.void
registerHost(String host, String address, String nodeName, long memory, int cores, float maxLoad)
Registers a host as a provider of Opencast services.ServiceRegistration
registerService(String serviceType, String host, String path)
Registers a host to handle a specific type of jobServiceRegistration
registerService(String serviceType, String host, String path, boolean jobProducer)
Registers a host to handle a specific type of jobServiceRegistration
registerService(JobProducer localService)
Method to register locally running services.ServiceRegistration
registerService(JobProducer localService, float maxLoad)
Method to register locally running services.void
removeJobs(List<Long> ids)
Deletes the given jobs from the service registryvoid
removeParentlessJobs(int lifetime)
Removes all jobs which do not have a parent job (except workflow instance jobs) and which have passed their lifetime.void
sanitize(String serviceType, String host)
Sets the given service to NORMAL statevoid
setCurrentJob(Job job)
Sets the current running jobvoid
setMaintenanceStatus(String host, boolean maintenance)
Sets a registered host's maintenance statusvoid
setSecurityService(SecurityService securityService)
Sets the security service.void
unregisterHost(String host)
Removes an Opencast server from service.void
unregisterService(JobProducer localService)
Removes the job producer from the service registry.void
unRegisterService(String serviceType, String host)
Unregisters a host from handling a specific type of jobJob
updateJob(Job job)
Update the job in the database
-
-
-
Field Detail
-
DEFAULT_DISPATCHER_TIMEOUT
public static final long DEFAULT_DISPATCHER_TIMEOUT
Default dispatcher timeout (1 second)- See Also:
- Constant Field Values
-
hosts
protected Map<String,HostRegistrationInMemory> hosts
The hosts
-
services
protected Map<String,List<ServiceRegistrationInMemoryImpl>> services
The service registrations
-
jobHosts
protected Map<ServiceRegistrationInMemoryImpl,Set<Job>> jobHosts
A mapping of services to jobs
-
dispatcher
protected ScheduledExecutorService dispatcher
The thread pool to use for dispatching queued jobs.
-
idCounter
protected AtomicLong idCounter
The job identifier
-
currentJob
protected Job currentJob
Holds the current running job
-
securityService
protected SecurityService securityService
An (optional) security service. If set to a non-null value, this will be used to obtain the current user when creating new jobs.
-
userDirectoryService
protected UserDirectoryService userDirectoryService
The user directory service
-
organizationDirectoryService
protected OrganizationDirectoryService organizationDirectoryService
The organization directory service
-
incidents
protected Incidents incidents
-
JOB_STATUSES_INFLUENCING_LOAD_BALANCING
protected static final List<Job.Status> JOB_STATUSES_INFLUENCING_LOAD_BALANCING
A static list of statuses that influence how load balancing is calculated
-
-
Constructor Detail
-
ServiceRegistryInMemoryImpl
public ServiceRegistryInMemoryImpl(JobProducer service, float maxLoad, SecurityService securityService, UserDirectoryService userDirectoryService, OrganizationDirectoryService organizationDirectoryService, IncidentService incidentService) throws ServiceRegistryException
- Throws:
ServiceRegistryException
-
ServiceRegistryInMemoryImpl
public ServiceRegistryInMemoryImpl(JobProducer service, SecurityService securityService, UserDirectoryService userDirectoryService, OrganizationDirectoryService organizationDirectoryService, IncidentService incidentService) throws ServiceRegistryException
- Throws:
ServiceRegistryException
-
-
Method Detail
-
dispose
public void dispose()
This method shuts down the service registry.
-
enableHost
public void enableHost(String host) throws ServiceRegistryException, NotFoundException
Enable an inactive host as a provider of Opencast services.- Specified by:
enableHost
in interfaceServiceRegistry
- Parameters:
host
- The base URL for this server- Throws:
ServiceRegistryException
- if communication with the service registry failsNotFoundException
- if the host does not exist- See Also:
ServiceRegistry.enableHost(String)
-
disableHost
public void disableHost(String host) throws ServiceRegistryException, NotFoundException
Disables a Opencast server from service.- Specified by:
disableHost
in interfaceServiceRegistry
- Parameters:
host
- The base URL for this server- Throws:
ServiceRegistryException
- if communication with the service registry failsNotFoundException
- if the host does not exist- See Also:
ServiceRegistry.disableHost(String)
-
registerHost
public 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.- Specified by:
registerHost
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.registerHost(String, String, String, long, int, float)
-
unregisterHost
public void unregisterHost(String host) throws ServiceRegistryException
Removes an Opencast server from service.- Specified by:
unregisterHost
in interfaceServiceRegistry
- Parameters:
host
- The base URL for this server- Throws:
ServiceRegistryException
- if communication with the service registry fails- See Also:
ServiceRegistry.unregisterHost(java.lang.String)
-
registerService
public ServiceRegistration registerService(JobProducer localService) throws ServiceRegistryException
Method to register locally running services.- Parameters:
localService
- the service instance- Returns:
- the service registration
- Throws:
ServiceRegistryException
-
registerService
public ServiceRegistration registerService(JobProducer localService, float maxLoad) throws ServiceRegistryException
Method to register locally running services.- Parameters:
localService
- the service instancemaxLoad
- the maximum load the host can support- Returns:
- the service registration
- Throws:
ServiceRegistryException
-
unregisterService
public void unregisterService(JobProducer localService) throws ServiceRegistryException
Removes the job producer from the service registry.- Parameters:
localService
- the service- Throws:
ServiceRegistryException
- if removing the service fails
-
registerService
public ServiceRegistration registerService(String serviceType, String host, String path) throws ServiceRegistryException
Registers a host to handle a specific type of job- Specified by:
registerService
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.registerService(java.lang.String, java.lang.String, java.lang.String)
-
registerService
public ServiceRegistration registerService(String serviceType, String host, String path, boolean jobProducer) throws ServiceRegistryException
Registers a host to handle a specific type of job- Specified by:
registerService
in interfaceServiceRegistry
- 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 producesJob
s to track long running operations- Returns:
- the service registration
- Throws:
ServiceRegistryException
- if communication with the service registry fails- See Also:
ServiceRegistry.registerService(java.lang.String, java.lang.String, java.lang.String, boolean)
-
unRegisterService
public void unRegisterService(String serviceType, String host) throws ServiceRegistryException
Unregisters a host from handling a specific type of job- Specified by:
unRegisterService
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.unRegisterService(java.lang.String, java.lang.String)
-
setMaintenanceStatus
public void setMaintenanceStatus(String host, boolean maintenance) throws NotFoundException
Sets a registered host's maintenance status- Specified by:
setMaintenanceStatus
in interfaceServiceRegistry
- 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:
NotFoundException
- if the host does not exist- See Also:
ServiceRegistry.setMaintenanceStatus(java.lang.String, boolean)
-
createJob
public Job createJob(String type, String operation) throws ServiceRegistryException
Create and store a new job that will be dispatched as soon as possible. This is equivalent to callingServiceRegistry.createJob(String, String, List, String, boolean)
with an empty argument list.Note that this job will be linked to the current job as its parent.
- Specified by:
createJob
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.createJob(java.lang.String, java.lang.String)
-
createJob
public 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 callingServiceRegistry.createJob(String, String, List, String, boolean)
.Note that this job will be linked to the current job as its parent.
- Specified by:
createJob
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.createJob(java.lang.String, java.lang.String, java.util.List)
-
createJob
public 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 callingServiceRegistry.createJob(String, String, List, String, boolean)
.Note that this job will be linked to the current job as its parent.
- Specified by:
createJob
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.createJob(java.lang.String, java.lang.String, java.util.List, Float)
-
createJob
public Job createJob(String type, String operation, List<String> arguments, String payload) throws ServiceRegistryException
- Throws:
ServiceRegistryException
-
createJob
public Job createJob(String type, String operation, List<String> arguments, String payload, boolean queueable) throws ServiceRegistryException
Create and store a new job. IfenqueueImmediately
is true, the job will be in theJob.Status.QUEUED
state 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.
- Specified by:
createJob
in interfaceServiceRegistry
- 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.INSTANTIATED
and will not be dispatched.- Returns:
- the job
- Throws:
ServiceRegistryException
- if there is a problem creating the job- See Also:
ServiceRegistry.createJob(java.lang.String, java.lang.String, java.util.List, java.lang.String, boolean)
-
createJob
public Job createJob(String type, String operation, List<String> arguments, String payload, boolean queueable, Float jobLoad) throws ServiceRegistryException
Create and store a new job. IfenqueueImmediately
is true, the job will be in theJob.Status.QUEUED
state 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.
- Specified by:
createJob
in interfaceServiceRegistry
- 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.INSTANTIATED
and 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- See Also:
ServiceRegistry.createJob(java.lang.String, java.lang.String, java.util.List, java.lang.String, boolean, Float)
-
createJob
public 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. IfenqueueImmediately
is true, the job will be in theJob.Status.QUEUED
state and will be dispatched as soon as possible. Otherwise, it will beJob.Status.INSTANTIATED
.- Specified by:
createJob
in interfaceServiceRegistry
- 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.INSTANTIATED
and 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- See Also:
ServiceRegistry.createJob(java.lang.String, java.lang.String, java.util.List, java.lang.String, boolean, org.opencastproject.job.api.Job, Float)
-
removeJobs
public void removeJobs(List<Long> ids) throws NotFoundException, ServiceRegistryException
Description copied from interface:ServiceRegistry
Deletes the given jobs from the service registry- Specified by:
removeJobs
in interfaceServiceRegistry
- Parameters:
ids
- the job ids- Throws:
NotFoundException
ServiceRegistryException
-
dispatchJob
protected boolean dispatchJob(Job job) throws ServiceUnavailableException, ServiceRegistryException, UndispatchableJobException
Dispatches the job to the least loaded service or throws aServiceUnavailableException
if there is no such service.- Parameters:
job
- the job to dispatch- Returns:
- whether the job was dispatched
- Throws:
ServiceUnavailableException
- if no service is available to dispatch the jobServiceRegistryException
- if the service registrations are unavailable or dispatching of the job failsUndispatchableJobException
-
updateJob
public Job updateJob(Job job) throws NotFoundException, ServiceRegistryException
Update the job in the database- Specified by:
updateJob
in interfaceServiceRegistry
- Returns:
- the updated job
- Throws:
NotFoundException
- if the job does not existServiceRegistryException
- if there is a problem updating the job- See Also:
ServiceRegistry.updateJob(org.opencastproject.job.api.Job)
-
getJob
public Job getJob(long id) throws NotFoundException, ServiceRegistryException
Gets a receipt by its ID, or null if not found- Specified by:
getJob
in interfaceServiceRegistry
- Parameters:
id
- the job id- Returns:
- the job or null
- Throws:
NotFoundException
ServiceRegistryException
- See Also:
ServiceRegistry.getJob(long)
-
getChildJobs
public List<Job> getChildJobs(long id) throws ServiceRegistryException
Get all child jobs from a job- Specified by:
getChildJobs
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.getChildJobs(long)
-
getJobs
public List<Job> getJobs(String serviceType, Job.Status status) throws ServiceRegistryException
Gets the list of jobs that match the specified parameters.- Specified by:
getJobs
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.getJobs(java.lang.String, org.opencastproject.job.api.Job.Status)
-
getJobPayloads
public List<String> getJobPayloads(String operation) throws ServiceRegistryException
Description copied from interface:ServiceRegistry
Return the payload of all jobs for a specified operation type.- Specified by:
getJobPayloads
in interfaceServiceRegistry
- Parameters:
operation
- Operation type to get payload for- Returns:
- Serialized workflows
- Throws:
ServiceRegistryException
- if there is a problem accessing the service registry
-
getJobPayloads
public List<String> getJobPayloads(String operation, int limit, int offset) throws ServiceRegistryException
Description copied from interface:ServiceRegistry
Return the payload of a specified number of jobs for a specified operation type.- Specified by:
getJobPayloads
in interfaceServiceRegistry
- 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
public int getJobCount(String operation) throws ServiceRegistryException
Description copied from interface:ServiceRegistry
Return the number of jobs for a specified operation type.- Specified by:
getJobCount
in interfaceServiceRegistry
- Parameters:
operation
- Operation type to check for- Returns:
- Number of jobs for the specified operation type.
- Throws:
ServiceRegistryException
-
getActiveJobs
public List<Job> getActiveJobs() throws ServiceRegistryException
Get the list of active jobs.- Specified by:
getActiveJobs
in interfaceServiceRegistry
- Returns:
- list of active jobs
- Throws:
ServiceRegistryException
- if there is a problem accessing the service registry- See Also:
ServiceRegistry.getActiveJobs()
-
incident
public Incidents incident()
Description copied from interface:ServiceRegistry
Return a facility to record job incidents.- Specified by:
incident
in interfaceServiceRegistry
- See Also:
Incident
-
getServiceRegistrationsByLoad
public List<ServiceRegistration> getServiceRegistrationsByLoad(String serviceType) throws ServiceRegistryException
Finds the service registrations for this kind of job, ordered by load (lightest to heaviest).- Specified by:
getServiceRegistrationsByLoad
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.getServiceRegistrationsByLoad(java.lang.String)
-
getServiceRegistrationsByType
public List<ServiceRegistration> getServiceRegistrationsByType(String serviceType) throws ServiceRegistryException
Finds the service registrations for this kind of job, including offline services and those in maintenance mode.- Specified by:
getServiceRegistrationsByType
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.getServiceRegistrationsByType(java.lang.String)
-
getServiceRegistrationsByHost
public List<ServiceRegistration> getServiceRegistrationsByHost(String host) throws ServiceRegistryException
Finds the service registrations on the given host, including offline services and those in maintenance mode.- Specified by:
getServiceRegistrationsByHost
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.getServiceRegistrationsByHost(java.lang.String)
-
getServiceRegistration
public 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.- Specified by:
getServiceRegistration
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.getServiceRegistration(java.lang.String, java.lang.String)
-
getServiceRegistrations
public List<ServiceRegistration> getServiceRegistrations() throws ServiceRegistryException
Finds all service registrations, including offline services and those in maintenance mode.- Specified by:
getServiceRegistrations
in interfaceServiceRegistry
- Returns:
- A list of service registrations
- Throws:
ServiceRegistryException
- if there is a problem accessing the service registry- See Also:
ServiceRegistry.getServiceRegistrations()
-
getServiceStatistics
public List<ServiceStatistics> getServiceStatistics() throws ServiceRegistryException
Gets performance and runtime statistics for each known service registration.- Specified by:
getServiceStatistics
in interfaceServiceRegistry
- Returns:
- the service statistics
- Throws:
ServiceRegistryException
- if there is a problem accessing the service registry- See Also:
ServiceRegistry.getServiceStatistics()
-
count
public long count(String serviceType, Job.Status status) throws ServiceRegistryException
Count the number of jobs that match the specified parameters.- Specified by:
count
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.count(java.lang.String, org.opencastproject.job.api.Job.Status)
-
countByOperation
public long countByOperation(String serviceType, String operation, Job.Status status) throws ServiceRegistryException
Count the number of jobs running the given operation in thisJob.Status
.- Specified by:
countByOperation
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.countByOperation(java.lang.String, java.lang.String, org.opencastproject.job.api.Job.Status)
-
countByHost
public long countByHost(String serviceType, String host, Job.Status status) throws ServiceRegistryException
Count the number of jobs in thisJob.Status
on this host- Specified by:
countByHost
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.countByHost(java.lang.String, java.lang.String, org.opencastproject.job.api.Job.Status)
-
count
public long count(String serviceType, String host, String operation, Job.Status status) throws ServiceRegistryException
Count the number of jobs executing the given operation in thisJob.Status
on this host.- Specified by:
count
in interfaceServiceRegistry
- 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- See Also:
ServiceRegistry.count(java.lang.String, java.lang.String, java.lang.String, org.opencastproject.job.api.Job.Status)
-
deactivate
public void deactivate()
Shuts down this service registry, logging all jobs and their statuses.
-
getMaxLoads
public SystemLoad getMaxLoads() throws ServiceRegistryException
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.- Specified by:
getMaxLoads
in interfaceServiceRegistry
- Returns:
- the total load that can be processed concurrently
- Throws:
ServiceRegistryException
- if communication with the service registry fails- See Also:
ServiceRegistry.getMaxLoads()
-
getMaxLoadOnNode
public SystemLoad.NodeLoad getMaxLoadOnNode(String host) throws ServiceRegistryException
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.- Specified by:
getMaxLoadOnNode
in interfaceServiceRegistry
- 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 fails- See Also:
ServiceRegistry.getMaxLoadOnNode(java.lang.String)
-
setSecurityService
public void setSecurityService(SecurityService securityService)
Sets the security service.- Parameters:
securityService
- the securityService to set
-
sanitize
public void sanitize(String serviceType, String host)
Description copied from interface:ServiceRegistry
Sets the given service to NORMAL state- Specified by:
sanitize
in interfaceServiceRegistry
- Parameters:
serviceType
- the service typehost
- the host
-
getCurrentJob
public Job getCurrentJob()
Description copied from interface:ServiceRegistry
Gets the current running job- Specified by:
getCurrentJob
in interfaceServiceRegistry
- Returns:
- the current job
-
setCurrentJob
public void setCurrentJob(Job job)
Description copied from interface:ServiceRegistry
Sets the current running job- Specified by:
setCurrentJob
in interfaceServiceRegistry
- Parameters:
job
- the current job
-
getHostRegistrations
public List<HostRegistration> getHostRegistrations() throws ServiceRegistryException
Description copied from interface:ServiceRegistry
Finds all host registrations, including offline hosts and those in maintenance mode.- Specified by:
getHostRegistrations
in interfaceServiceRegistry
- Returns:
- A list of host registrations
- Throws:
ServiceRegistryException
- if there is a problem accessing the service registry
-
getHostStatistics
public HostStatistics getHostStatistics()
Description copied from interface:ServiceRegistry
Get statistics about jobs active on hosts.- Specified by:
getHostStatistics
in interfaceServiceRegistry
- Returns:
- Host statistics
-
getHostRegistration
public HostRegistration getHostRegistration(String hostname) throws ServiceRegistryException
Description copied from interface:ServiceRegistry
Finds host registration for the given hostname.- Specified by:
getHostRegistration
in interfaceServiceRegistry
- Parameters:
hostname
- to lookup- Returns:
- host registrations
- Throws:
ServiceRegistryException
- if there is a problem accessing the service registry or the hostname is not found
-
getCurrentHostLoads
public SystemLoad getCurrentHostLoads()
Description copied from interface:ServiceRegistry
Gets a map of hosts to the number of jobs currently loading that host- Specified by:
getCurrentHostLoads
in interfaceServiceRegistry
- Returns:
- the map of hosts to job counts
-
removeParentlessJobs
public void removeParentlessJobs(int lifetime) throws ServiceRegistryException
Description copied from interface:ServiceRegistry
Removes all jobs which do not have a parent job (except workflow instance jobs) and which have passed their lifetime.- Specified by:
removeParentlessJobs
in interfaceServiceRegistry
- Parameters:
lifetime
- lifetime in days- Throws:
ServiceRegistryException
- if removing the jobs fails
-
getOwnLoad
public float getOwnLoad()
Description copied from interface:ServiceRegistry
Gets the load value for the current host (ie, the host this service registry lives on- Specified by:
getOwnLoad
in interfaceServiceRegistry
- Returns:
- the load value for this host
-
getRegistryHostname
public String getRegistryHostname()
Description copied from interface:ServiceRegistry
Returns the service regstry's hostname. This can be used to fetch the list of services on the local host.- Specified by:
getRegistryHostname
in interfaceServiceRegistry
- Returns:
- The hostname that the service registry is running on.
-
-