use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ServiceRegistryJpaImpl method getChildJobs.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#getChildJobs(long)
*/
@Override
public List<Job> getChildJobs(long id) throws ServiceRegistryException {
EntityManager em = null;
try {
em = emf.createEntityManager();
TypedQuery<JpaJob> query = em.createNamedQuery("Job.root.children", JpaJob.class);
query.setParameter("id", id);
List<JpaJob> jobs = query.getResultList();
if (jobs.size() == 0) {
jobs = getChildren(em, id);
}
return $(jobs).sort(new Comparator<JpaJob>() {
@Override
public int compare(JpaJob job1, JpaJob job2) {
if (job1.getDateCreated() == null || job2.getDateCreated() == null) {
return 0;
} else {
return job1.getDateCreated().compareTo(job2.getDateCreated());
}
}
}).map(fnSetJobUri()).map(fnToJob()).toList();
} catch (Exception e) {
throw new ServiceRegistryException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class SilenceDetectionServiceImpl method detect.
/**
* {@inheritDoc}
*
* @see org.opencastproject.silencedetection.api.SilenceDetectionService#detect(
* org.opencastproject.mediapackage.Track, org.opencastproject.mediapackage.Track[])
*/
@Override
public Job detect(Track sourceTrack, Track[] referenceTracks) throws SilenceDetectionFailedException {
try {
if (sourceTrack == null) {
throw new SilenceDetectionFailedException("Source track is null!");
}
List<String> arguments = new LinkedList<String>();
// put source track as job argument
arguments.add(0, MediaPackageElementParser.getAsXml(sourceTrack));
// put reference tracks as second argument
if (referenceTracks != null) {
arguments.add(1, MediaPackageElementParser.getArrayAsXml(Arrays.asList(referenceTracks)));
}
return serviceRegistry.createJob(getJobType(), Operation.SILENCE_DETECTION.toString(), arguments, jobload);
} catch (ServiceRegistryException ex) {
throw new SilenceDetectionFailedException("Unable to create job! " + ex.getMessage());
} catch (MediaPackageException ex) {
throw new SilenceDetectionFailedException("Unable to serialize track!");
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ServiceRegistryEndpoint method getMaxLoadOnNode.
@GET
@Path("maxload")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "maxload", description = "Returns the maximum load that servers in this service registry can execute concurrently. " + "If there is only one server in this service registry this will be the maximum load that one server is able to handle at one time. " + "If it is a distributed install across many servers then this number will be the maximum load the cluster can process concurrently.", returnDescription = "The maximum load of the cluster or server", restParameters = { @RestParameter(name = "host", isRequired = false, type = Type.STRING, description = "The host you want to know the maximum load for.") }, reponses = { @RestResponse(responseCode = SC_OK, description = "Maximum load for the cluster.") })
public Response getMaxLoadOnNode(@QueryParam("host") String host) throws NotFoundException {
try {
if (StringUtils.isEmpty(host)) {
return Response.ok(serviceRegistry.getMaxLoads()).build();
} else {
SystemLoad systemLoad = new SystemLoad();
systemLoad.addNodeLoad(serviceRegistry.getMaxLoadOnNode(host));
return Response.ok(systemLoad).build();
}
} catch (ServiceRegistryException e) {
throw new WebApplicationException(e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ServiceRegistryEndpoint method getHealthStatus.
@GET
@Path("health.xml")
@Produces(MediaType.APPLICATION_XML)
@RestQuery(name = "health", description = "Checks the status of the registered services", returnDescription = "Returns NO_CONTENT if services are in a proper state", restParameters = { @RestParameter(name = "serviceType", isRequired = false, type = Type.STRING, description = "The service type identifier"), @RestParameter(name = "host", isRequired = false, type = Type.STRING, description = "The host, including the http(s) protocol") }, reponses = { @RestResponse(responseCode = SC_OK, description = "Service states returned"), @RestResponse(responseCode = SC_NOT_FOUND, description = "No service of that type on that host is registered."), @RestResponse(responseCode = SC_SERVICE_UNAVAILABLE, description = "An error has occurred during stats processing") })
public Response getHealthStatus(@QueryParam("serviceType") String serviceType, @QueryParam("host") String host) throws NotFoundException {
try {
List<ServiceRegistration> services = null;
if (isNotBlank(serviceType) && isNotBlank(host)) {
// This is a request for one specific service. Return it, or SC_NOT_FOUND if not found
ServiceRegistration reg = serviceRegistry.getServiceRegistration(serviceType, host);
if (reg == null)
throw new NotFoundException();
services = new LinkedList<ServiceRegistration>();
services.add(reg);
} else if (isBlank(serviceType) && isBlank(host)) {
// This is a request for all service registrations
services = serviceRegistry.getServiceRegistrations();
} else if (isNotBlank(serviceType)) {
// This is a request for all service registrations of a particular type
services = serviceRegistry.getServiceRegistrationsByType(serviceType);
} else if (isNotBlank(host)) {
// This is a request for all service registrations of a particular host
services = serviceRegistry.getServiceRegistrationsByHost(host);
}
int healthy = 0;
int warning = 0;
int error = 0;
for (ServiceRegistration reg : services) {
if (ServiceState.NORMAL == reg.getServiceState()) {
healthy++;
} else if (ServiceState.WARNING == reg.getServiceState()) {
warning++;
} else if (ServiceState.ERROR == reg.getServiceState()) {
error++;
} else {
error++;
}
}
JaxbServiceHealth stats = new JaxbServiceHealth(healthy, warning, error);
return Response.ok(stats).build();
} catch (ServiceRegistryException e) {
throw new WebApplicationException(e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ServiceRegistryJpaImpl method disableHost.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#disableHost(String)
*/
@Override
public void disableHost(String host) throws ServiceRegistryException, NotFoundException {
EntityManager em = null;
EntityTransaction tx = null;
try {
em = emf.createEntityManager();
tx = em.getTransaction();
tx.begin();
HostRegistrationJpaImpl hostRegistration = fetchHostRegistration(em, host);
if (hostRegistration == null) {
throw new NotFoundException("Host '" + host + "' is not currently registered, so it can not be disabled");
} else {
hostRegistration.setActive(false);
for (ServiceRegistration serviceRegistration : getServiceRegistrationsByHost(host)) {
ServiceRegistrationJpaImpl registration = (ServiceRegistrationJpaImpl) serviceRegistration;
registration.setActive(false);
em.merge(registration);
servicesStatistics.updateService(registration);
}
em.merge(hostRegistration);
}
logger.info("Disabling {}", host);
tx.commit();
hostsStatistics.updateHost(hostRegistration);
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
if (tx != null && tx.isActive()) {
tx.rollback();
}
throw new ServiceRegistryException(e);
} finally {
if (em != null)
em.close();
}
}
Aggregations