Search in sources :

Example 21 with DistributionException

use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.

the class StreamingDistributionServiceImpl method distribute.

@Override
public Job distribute(String channelId, MediaPackage mediapackage, Set<String> elementIds) 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)), 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 22 with DistributionException

use of org.opencastproject.distribution.api.DistributionException 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 23 with DistributionException

use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.

the class ConfigurablePublishWorkflowOperationHandler method distribute.

private Set<MediaPackageElement> distribute(Collection<MediaPackageElement> elements, MediaPackage mediapackage, String channelId, String mode, boolean checkAvailability) throws WorkflowOperationException {
    Set<MediaPackageElement> result = new HashSet<>();
    Set<String> bulkElementIds = new HashSet<>();
    Set<String> singleElementIds = new HashSet<>();
    for (MediaPackageElement element : elements) {
        if (MODE_BULK.equals(mode) || (MODE_MIXED.equals(mode) && (element.getElementType() != MediaPackageElement.Type.Track))) {
            bulkElementIds.add(element.getIdentifier());
        } else {
            singleElementIds.add(element.getIdentifier());
        }
    }
    Set<Job> jobs = new HashSet<>();
    if (bulkElementIds.size() > 0) {
        logger.info("Start bulk publishing of {} elements of media package '{}' to publication channel '{}'", bulkElementIds.size(), mediapackage, channelId);
        try {
            Job job = distributionService.distribute(channelId, mediapackage, bulkElementIds, checkAvailability);
            jobs.add(job);
        } catch (DistributionException | MediaPackageException e) {
            logger.error("Creating the distribution job for {} elements of media package '{}' failed: {}", bulkElementIds.size(), mediapackage, getStackTrace(e));
            throw new WorkflowOperationException(e);
        }
    }
    if (singleElementIds.size() > 0) {
        logger.info("Start single publishing of {} elements of media package '{}' to publication channel '{}'", singleElementIds.size(), mediapackage, channelId);
        for (String elementId : singleElementIds) {
            try {
                Job job = distributionService.distribute(channelId, mediapackage, elementId, checkAvailability);
                jobs.add(job);
            } catch (DistributionException | MediaPackageException e) {
                logger.error("Creating the distribution job for element '{}' of media package '{}' failed: {}", elementId, mediapackage, getStackTrace(e));
                throw new WorkflowOperationException(e);
            }
        }
    }
    if (jobs.size() > 0) {
        if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) {
            throw new WorkflowOperationException("At least one of the distribution jobs did not complete successfully");
        }
        for (Job job : jobs) {
            try {
                List<? extends MediaPackageElement> elems = MediaPackageElementParser.getArrayFromXml(job.getPayload());
                result.addAll(elems);
            } catch (MediaPackageException e) {
                logger.error("Job '{}' returned payload ({}) that could not be parsed to media package elements: {}", job, job.getPayload(), ExceptionUtils.getStackTrace(e));
                throw new WorkflowOperationException(e);
            }
        }
        logger.info("Published {} elements of media package {} to publication channel {}", bulkElementIds.size() + singleElementIds.size(), mediapackage, channelId);
    }
    return result;
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet)

Example 24 with DistributionException

use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.

the class ConfigurableWorkflowOperationHandlerBase method retractPublicationElements.

/**
 * Remove the {@link Publication}'s {@link MediaPackageElement}s from a given channel.
 *
 * @param channelId
 *          The channel to remove the {@link MediaPackageElement}s from.
 * @param publication
 *          The {@link Publication} that is being removed.
 * @param mp
 *          The {@link MediaPackage} that the {@link Publication} is part of.
 * @return the number of {@link MediaPackageElement}s that have been retracted
 * @throws WorkflowOperationException
 *           Thrown if unable to retract the {@link MediaPackageElement}s.
 */
private int retractPublicationElements(String channelId, Publication publication, MediaPackage mp) throws WorkflowOperationException {
    assert ((channelId != null) && (publication != null) && (mp != null));
    MediaPackage mediapackageWithPublicationElements = (MediaPackage) mp.clone();
    // Add the publications to the mediapackage so that we can use the standard retract
    addPublicationElementsToMediaPackage(publication, mediapackageWithPublicationElements);
    Set<String> elementIds = new HashSet<>();
    for (Attachment attachment : publication.getAttachments()) {
        elementIds.add(attachment.getIdentifier());
    }
    for (Catalog catalog : publication.getCatalogs()) {
        elementIds.add(catalog.getIdentifier());
    }
    for (Track track : publication.getTracks()) {
        elementIds.add(track.getIdentifier());
    }
    if (elementIds.size() > 0) {
        logger.info("Retracting {} elements of media package {} from publication channel {}", elementIds.size(), mp, channelId);
        Job job = null;
        try {
            job = getDistributionService().retract(channelId, mediapackageWithPublicationElements, elementIds);
        } catch (DistributionException e) {
            logger.error("Error while retracting '{}' elements from channel '{}' of distribution '{}': {}", elementIds.size(), channelId, getDistributionService(), getStackTrace(e));
            throw new WorkflowOperationException("The retraction job did not complete successfully");
        }
        if (!waitForStatus(job).isSuccess()) {
            throw new WorkflowOperationException("The retraction job did not complete successfully");
        }
    } else {
        logger.debug("No publication elements were found for retraction");
    }
    return elementIds.size();
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Attachment(org.opencastproject.mediapackage.Attachment) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job) Catalog(org.opencastproject.mediapackage.Catalog) Track(org.opencastproject.mediapackage.Track) HashSet(java.util.HashSet)

Example 25 with DistributionException

use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.

the class WowzaAdaptiveStreamingDistributionService method getSmilDocument.

private Document getSmilDocument(File smilFile) throws DistributionException {
    if (!smilFile.isFile()) {
        try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            Document doc = docBuilder.newDocument();
            Element smil = doc.createElement("smil");
            doc.appendChild(smil);
            Element head = doc.createElement("head");
            smil.appendChild(head);
            Element body = doc.createElement("body");
            smil.appendChild(body);
            Element switchElement = doc.createElement("switch");
            body.appendChild(switchElement);
            return doc;
        } catch (ParserConfigurationException ex) {
            logger.error("Could not create XML file for {}.", smilFile);
            throw new DistributionException("Could not create XML file for " + smilFile);
        }
    }
    try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(smilFile);
        if (!"smil".equalsIgnoreCase(doc.getDocumentElement().getNodeName())) {
            logger.error("XML-File {} is not a SMIL file.", smilFile);
            throw new DistributionException(format("XML-File %s is not an SMIL file.", smilFile.getName()));
        }
        return doc;
    } catch (IOException e) {
        logger.error("Could not open SMIL file {}", smilFile);
        throw new DistributionException(format("Could not open SMIL file %s", smilFile));
    } catch (ParserConfigurationException e) {
        logger.error("Could not parse SMIL file {}", smilFile);
        throw new DistributionException(format("Could not parse SMIL file %s", smilFile));
    } catch (SAXException e) {
        logger.error("Could not parse XML file {}", smilFile);
        throw new DistributionException(format("Could not parse XML file %s", smilFile));
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Element(org.w3c.dom.Element) DistributionException(org.opencastproject.distribution.api.DistributionException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

DistributionException (org.opencastproject.distribution.api.DistributionException)35 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)17 Job (org.opencastproject.job.api.Job)16 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)14 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)11 NotFoundException (org.opencastproject.util.NotFoundException)11 IOException (java.io.IOException)9 File (java.io.File)7 URISyntaxException (java.net.URISyntaxException)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 HttpPost (org.apache.http.client.methods.HttpPost)7 MediaPackage (org.opencastproject.mediapackage.MediaPackage)7 URI (java.net.URI)6 ConfigurationException (org.osgi.service.cm.ConfigurationException)6 Publication (org.opencastproject.mediapackage.Publication)4 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3