use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ServiceRegistryJpaImpl method getMaxLoadOnNode.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#getMaxLoadOnNode(java.lang.String)
*/
@Override
public NodeLoad getMaxLoadOnNode(String host) throws ServiceRegistryException, NotFoundException {
Query query = null;
EntityManager em = null;
try {
em = emf.createEntityManager();
query = em.createNamedQuery("HostRegistration.getMaxLoadByHostName");
query.setParameter("host", host);
return new NodeLoad(host, ((Number) query.getSingleResult()).floatValue());
} catch (NoResultException e) {
throw new NotFoundException(e);
} 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 SoxServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
TrackImpl audioTrack = null;
final String serialized;
switch(op) {
case Analyze:
audioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(arguments.get(0));
serialized = analyze(job, audioTrack).map(MediaPackageElementParser.<Track>getAsXml()).getOrElse("");
break;
case Normalize:
audioTrack = (TrackImpl) MediaPackageElementParser.getFromXml(arguments.get(0));
Float targetRmsLevDb = new Float(arguments.get(1));
serialized = normalize(job, audioTrack, targetRmsLevDb).map(MediaPackageElementParser.<Track>getAsXml()).getOrElse("");
break;
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
return serialized;
} catch (IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ServiceRegistryJpaImpl method count.
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#count(java.lang.String, Status)
*/
@Override
public long count(String serviceType, Status status) throws ServiceRegistryException {
EntityManager em = null;
try {
em = emf.createEntityManager();
Query query;
if (serviceType == null && status == null) {
query = em.createNamedQuery("Job.count.all");
} else if (serviceType == null) {
query = em.createNamedQuery("Job.count.nullType");
query.setParameter("status", status.ordinal());
} else if (status == null) {
query = em.createNamedQuery("Job.count.nullStatus");
query.setParameter("serviceType", serviceType);
} else {
query = em.createNamedQuery("Job.count");
query.setParameter("status", status.ordinal());
query.setParameter("serviceType", serviceType);
}
Number countResult = (Number) query.getSingleResult();
return countResult.longValue();
} 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 ServiceRegistryJpaImpl method getJobsByStatus.
/**
* Get the list of jobs with status from the given statuses.
*
* @param em
* the entity manager
* @param statuses
* variable sized array of status values to test on jobs
* @return list of jobs with status from statuses
* @throws ServiceRegistryException
* if there is a problem communicating with the jobs database
*/
public List<JpaJob> getJobsByStatus(EntityManager em, Status... statuses) throws ServiceRegistryException {
if (statuses == null || statuses.length < 1)
throw new IllegalArgumentException("At least one job status must be given.");
List<Integer> ordinalStatuses = new ArrayList<>();
for (Status status : statuses) {
ordinalStatuses.add(status.ordinal());
}
TypedQuery<JpaJob> query = null;
try {
query = em.createNamedQuery("Job.statuses", JpaJob.class);
query.setParameter("statuses", ordinalStatuses);
List<JpaJob> jpaJobs = query.getResultList();
for (JpaJob jpaJob : jpaJobs) {
setJobUri(jpaJob);
}
return jpaJobs;
} catch (Exception e) {
throw new ServiceRegistryException(e);
}
}
use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.
the class ServiceRegistryJpaImpl method getRelatedWarningServices.
/**
* Gets the services in WARNING state triggered by this job
*
* @param job
* the given job to get the related services
* @return a list of services triggered by the job
* @throws IllegalArgumentException
* if the given job was null
* @throws ServiceRegistryException
* if the there was a problem with the query
*/
private List<ServiceRegistrationJpaImpl> getRelatedWarningServices(JpaJob job) throws IllegalArgumentException, ServiceRegistryException {
if (job == null)
throw new IllegalArgumentException("job must not be null!");
Query query = null;
EntityManager em = null;
logger.debug("Finding services put in WARNING state by job {}", job.toJob().getSignature());
try {
em = emf.createEntityManager();
// TODO: modify the query to avoid to go through the list here
query = em.createNamedQuery("ServiceRegistration.relatedservices.warning");
query.setParameter("serviceType", job.getJobType());
List<ServiceRegistrationJpaImpl> jpaServices = new ArrayList<ServiceRegistrationJpaImpl>();
@SuppressWarnings("unchecked") List<ServiceRegistrationJpaImpl> jobResults = query.getResultList();
for (ServiceRegistrationJpaImpl relatedService : jobResults) {
if (relatedService.getWarningStateTrigger() == job.toJob().getSignature()) {
jpaServices.add(relatedService);
}
}
return jpaServices;
} catch (NoResultException e) {
return null;
} catch (Exception e) {
throw new ServiceRegistryException(e);
} finally {
if (em != null)
em.close();
}
}
Aggregations