Search in sources :

Example 56 with ServiceRegistryException

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

the class StreamingDistributionServiceImpl method retract.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.distribution.api.DistributionService#retract(String,
 *      org.opencastproject.mediapackage.MediaPackage, String) java.lang.String)
 */
@Override
public Job retract(String channelId, MediaPackage mediaPackage, Set<String> elementIds) throws DistributionException {
    if (locations.isNone())
        return null;
    RequireUtil.notNull(mediaPackage, "mediaPackage");
    RequireUtil.notNull(elementIds, "elementId");
    RequireUtil.notNull(channelId, "channelId");
    // 
    try {
        return serviceRegistry.createJob(JOB_TYPE, Operation.Retract.toString(), Arrays.asList(channelId, MediaPackageParser.getAsXml(mediaPackage), gson.toJson(elementIds)), retractJobLoad);
    } 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 57 with ServiceRegistryException

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

the class WowzaAdaptiveStreamingDistributionService 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);
                if (logger.isDebugEnabled()) {
                    for (MediaPackageElement element : distributedElements) if (element != null)
                        logger.debug("Distributed element {} with URL {}", element.getIdentifier(), element.getURI());
                }
                ArrayList<MediaPackageElement> distributedElementsList = new ArrayList<MediaPackageElement>();
                if (distributedElements != null) {
                    for (int i = 0; i < distributedElements.length; i++) {
                        if (distributedElements[i] != null)
                            distributedElementsList.add(distributedElements[i]);
                    }
                }
                return (!distributedElementsList.isEmpty()) ? MediaPackageElementParser.getArrayAsXml(distributedElementsList) : null;
            case Retract:
                MediaPackageElement[] retractedElements = null;
                if (distributionDirectory != null) {
                    if (streamingUri != null || adaptiveStreamingUri != null) {
                        retractedElements = retractElements(channelId, mediapackage, elementIds);
                        if (logger.isDebugEnabled()) {
                            for (MediaPackageElement element : retractedElements) if (element != null)
                                logger.debug("Retracted element {} with URL {}", element.getIdentifier(), element.getURI());
                        }
                    }
                }
                ArrayList<MediaPackageElement> retractedElementsList = new ArrayList<MediaPackageElement>();
                if (retractedElements != null) {
                    for (MediaPackageElement element : retractedElements) {
                        if (element != null) {
                            retractedElementsList.add(element);
                        }
                    }
                }
                return (!retractedElementsList.isEmpty()) ? MediaPackageElementParser.getArrayAsXml(retractedElementsList) : 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 : ArrayList(java.util.ArrayList) 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) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) DistributionException(org.opencastproject.distribution.api.DistributionException) DOMException(org.w3c.dom.DOMException) NotFoundException(org.opencastproject.util.NotFoundException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TypeToken(com.google.gson.reflect.TypeToken) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 58 with ServiceRegistryException

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

the class WowzaAdaptiveStreamingDistributionService method distribute.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.distribution.api.StreamingDistributionService#distribute(java.lang.String,
 * org.opencastproject.mediapackage.MediaPackage, java.util.Set)
 */
@Override
public Job distribute(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException, MediaPackageException {
    notNull(mediapackage, "mediapackage");
    notNull(elementIds, "elementIds");
    notNull(channelId, "channelId");
    if (streamingUri == null && adaptiveStreamingUri == null)
        throw new IllegalStateException("A least one streaming url must be set (org.opencastproject.streaming.url,org.opencastproject.adaptive-streaming.url)");
    if (distributionDirectory == null)
        throw new IllegalStateException("Streaming distribution directory must be set (org.opencastproject.streaming.directory)");
    try {
        return serviceRegistry.createJob(JOB_TYPE, Operation.Distribute.toString(), Arrays.asList(channelId, MediaPackageParser.getAsXml(mediapackage), gson.toJson(elementIds)), 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 59 with ServiceRegistryException

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

the class AwsS3DistributionServiceImpl method distribute.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.distribution.api.DownloadDistributionService#distribute(String,
 *      org.opencastproject.mediapackage.MediaPackage, String, boolean)
 */
@Override
public Job distribute(String channelId, MediaPackage mediaPackage, Set<String> elementIds, boolean checkAvailability) 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)));
    } 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 60 with ServiceRegistryException

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

the class AwsS3DistributionServiceImpl method retract.

@Override
public Job retract(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException {
    notNull(mediapackage, "mediapackage");
    notNull(elementIds, "elementIds");
    notNull(channelId, "channelId");
    try {
        return serviceRegistry.createJob(JOB_TYPE, Operation.Retract.toString(), Arrays.asList(channelId, MediaPackageParser.getAsXml(mediapackage), gson.toJson(elementIds)));
    } 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)

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