Search in sources :

Example 26 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class AwsS3DistributionServiceImpl 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);
        String channelId = arguments.get(0);
        MediaPackage mediaPackage = MediaPackageParser.getFromXml(arguments.get(1));
        Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
        }.getType());
        switch(op) {
            case Distribute:
                Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
                MediaPackageElement[] distributedElements = distributeElements(channelId, mediaPackage, elementIds, checkAvailability);
                return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
            case Retract:
                MediaPackageElement[] retractedElements = retractElements(channelId, mediaPackage, elementIds);
                return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
            /*
         * TODO
         * Commented out due to changes in the way the element IDs are passed (ie, a list rather than individual ones
         * per job). This code is still useful long term, but I don't have time to write the necessary wrapper code
         * around it right now.
         * case Restore:
         * String fileName = arguments.get(3);
         * MediaPackageElement restoredElement = null;
         * if (StringUtils.isNotBlank(fileName)) {
         * restoredElement = restoreElement(channelId, mediaPackage, elementIds, fileName);
         * } else {
         * restoredElement = restoreElement(channelId, mediaPackage, elementIds, null);
         * }
         * return (restoredElement != null) ? MediaPackageElementParser.getAsXml(restoredElement) : null;
         */
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
        }
    } catch (IllegalArgumentException e) {
        throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
    } catch (IndexOutOfBoundsException e) {
        throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
    } catch (Exception e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) URISyntaxException(java.net.URISyntaxException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) AmazonServiceException(com.amazonaws.AmazonServiceException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) AmazonClientException(com.amazonaws.AmazonClientException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) ConfigurationException(org.opencastproject.util.ConfigurationException) IOException(java.io.IOException) TypeToken(com.google.gson.reflect.TypeToken) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 27 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class DownloadDistributionServiceImpl method distribute.

@Override
public Job distribute(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability, boolean preserveReference) throws DistributionException, MediaPackageException {
    notNull(mediapackage, "mediapackage");
    notNull(elementIds, "elementIds");
    notNull(channelId, "channelId");
    try {
        return serviceRegistry.createJob(JOB_TYPE, Operation.Distribute.toString(), Arrays.asList(channelId, MediaPackageParser.getAsXml(mediapackage), gson.toJson(elementIds), Boolean.toString(checkAvailability), Boolean.toString(preserveReference)), distributeJobLoad);
    } catch (ServiceRegistryException e) {
        throw new DistributionException("Unable to create a job", e);
    }
}
Also used : DistributionException(org.opencastproject.distribution.api.DistributionException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 28 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class DownloadDistributionServiceImpl 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);
        String channelId = arguments.get(0);
        MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
        Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
        }.getType());
        switch(op) {
            case Distribute:
                Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
                Boolean preserveReference = Boolean.parseBoolean(arguments.get(4));
                MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds, checkAvailability, preserveReference);
                return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
            case Retract:
                MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
                return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
        }
    } catch (IllegalArgumentException e) {
        throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
    } catch (IndexOutOfBoundsException e) {
        throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
    } catch (Exception e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) TypeToken(com.google.gson.reflect.TypeToken) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 29 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class StreamingDistributionServiceImpl 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);
        String channelId = arguments.get(0);
        MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
        Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
        }.getType());
        switch(op) {
            case Distribute:
                MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds);
                return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
            case Retract:
                MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
                return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
        }
    } catch (IllegalArgumentException e) {
        throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
    } catch (IndexOutOfBoundsException e) {
        throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
    } catch (Exception e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) TypeToken(com.google.gson.reflect.TypeToken) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 30 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class ServiceRegistryJpaImpl method setOnlineStatus.

/**
 * Sets the online status of a service registration.
 *
 * @param serviceType
 *          The job type
 * @param baseUrl
 *          the host URL
 * @param online
 *          whether the service is online or off
 * @param jobProducer
 *          whether this service produces jobs for long running operations
 * @return the service registration
 */
protected ServiceRegistration setOnlineStatus(String serviceType, String baseUrl, String path, boolean online, Boolean jobProducer) throws ServiceRegistryException {
    if (isBlank(serviceType) || isBlank(baseUrl)) {
        throw new IllegalArgumentException("serviceType and baseUrl must not be blank");
    }
    EntityManager em = null;
    EntityTransaction tx = null;
    try {
        em = emf.createEntityManager();
        tx = em.getTransaction();
        tx.begin();
        HostRegistrationJpaImpl hostRegistration = fetchHostRegistration(em, baseUrl);
        if (hostRegistration == null) {
            throw new IllegalStateException("A service registration can not be updated when it has no associated host registration");
        }
        ServiceRegistrationJpaImpl registration = getServiceRegistration(em, serviceType, baseUrl);
        if (registration == null) {
            if (isBlank(path)) {
                // we can not create a new registration without a path
                throw new IllegalArgumentException("path must not be blank when registering new services");
            }
            if (jobProducer == null) {
                // if we are not provided a value, consider it to be false
                registration = new ServiceRegistrationJpaImpl(hostRegistration, serviceType, path, false);
            } else {
                registration = new ServiceRegistrationJpaImpl(hostRegistration, serviceType, path, jobProducer);
            }
            em.persist(registration);
        } else {
            if (StringUtils.isNotBlank(path))
                registration.setPath(path);
            registration.setOnline(online);
            if (jobProducer != null) {
                // if we are not provided a value, don't update the persistent value
                registration.setJobProducer(jobProducer);
            }
            em.merge(registration);
        }
        tx.commit();
        hostsStatistics.updateHost(hostRegistration);
        servicesStatistics.updateService(registration);
        return registration;
    } 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) 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)

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