Search in sources :

Example 76 with ServiceRegistryException

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) JpaJob(org.opencastproject.job.jpa.JpaJob) URISyntaxException(java.net.URISyntaxException) NoResultException(javax.persistence.NoResultException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) PersistenceException(javax.persistence.PersistenceException) RollbackException(javax.persistence.RollbackException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Comparator(java.util.Comparator)

Example 77 with ServiceRegistryException

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!");
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) LinkedList(java.util.LinkedList) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 78 with ServiceRegistryException

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SystemLoad(org.opencastproject.serviceregistry.api.SystemLoad) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 79 with ServiceRegistryException

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) JaxbServiceHealth(org.opencastproject.serviceregistry.api.JaxbServiceHealth) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) JaxbServiceRegistration(org.opencastproject.serviceregistry.api.JaxbServiceRegistration) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 80 with ServiceRegistryException

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();
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistrationJpaImpl(org.opencastproject.serviceregistry.impl.jpa.ServiceRegistrationJpaImpl) HostRegistrationJpaImpl(org.opencastproject.serviceregistry.impl.jpa.HostRegistrationJpaImpl) URISyntaxException(java.net.URISyntaxException) NoResultException(javax.persistence.NoResultException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) PersistenceException(javax.persistence.PersistenceException) RollbackException(javax.persistence.RollbackException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration)

Aggregations

ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)99 NotFoundException (org.opencastproject.util.NotFoundException)61 ConfigurationException (org.osgi.service.cm.ConfigurationException)41 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)30 URISyntaxException (java.net.URISyntaxException)29 Job (org.opencastproject.job.api.Job)29 PersistenceException (javax.persistence.PersistenceException)26 RollbackException (javax.persistence.RollbackException)26 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)26 NoResultException (javax.persistence.NoResultException)25 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)25 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)24 EntityManager (javax.persistence.EntityManager)22 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 URI (java.net.URI)16 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)14 DistributionException (org.opencastproject.distribution.api.DistributionException)13 Attachment (org.opencastproject.mediapackage.Attachment)12 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)12