Search in sources :

Example 1 with DistributionException

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

the class SeriesUpdatedEventHandler method handleEvent.

public void handleEvent(final SeriesItem seriesItem) {
    // A series or its ACL has been updated. Find any mediapackages with that series, and update them.
    logger.debug("Handling {}", seriesItem);
    String seriesId = seriesItem.getSeriesId();
    // We must be an administrative user to make this query
    final User prevUser = securityService.getUser();
    final Organization prevOrg = securityService.getOrganization();
    try {
        securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
        SearchQuery q = new SearchQuery().withSeriesId(seriesId);
        SearchResult result = searchService.getForAdministrativeRead(q);
        for (SearchResultItem item : result.getItems()) {
            MediaPackage mp = item.getMediaPackage();
            Organization org = organizationDirectoryService.getOrganization(item.getOrganization());
            securityService.setOrganization(org);
            // to the distribution channels as well
            if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
                // Build a new XACML file for this mediapackage
                Attachment fileRepoCopy = authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl()).getB();
                // Distribute the updated XACML file
                Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, fileRepoCopy.getIdentifier());
                JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
                Result jobResult = barrier.waitForJobs();
                if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
                    mp.remove(fileRepoCopy);
                    mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
                } else {
                    logger.error("Unable to distribute XACML {}", fileRepoCopy.getIdentifier());
                    continue;
                }
            }
            // Update the series dublin core
            if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
                DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
                mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
                // Update the series dublin core
                Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
                if (seriesCatalogs.length == 1) {
                    Catalog c = seriesCatalogs[0];
                    String filename = FilenameUtils.getName(c.getURI().toString());
                    URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
                    c.setURI(uri);
                    // setting the URI to a new source so the checksum will most like be invalid
                    c.setChecksum(null);
                    // Distribute the updated series dc
                    Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, c.getIdentifier());
                    JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
                    Result jobResult = barrier.waitForJobs();
                    if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
                        mp.remove(c);
                        mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
                    } else {
                        logger.error("Unable to distribute series catalog {}", c.getIdentifier());
                        continue;
                    }
                }
            }
            // Remove the series catalog and isPartOf from episode catalog
            if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
                mp.setSeries(null);
                mp.setSeriesTitle(null);
                boolean retractSeriesCatalog = retractSeriesCatalog(mp);
                boolean updateEpisodeCatalog = updateEpisodeCatalog(mp);
                if (!retractSeriesCatalog || !updateEpisodeCatalog)
                    continue;
            }
            // Update the search index with the modified mediapackage
            Job searchJob = searchService.add(mp);
            JobBarrier barrier = new JobBarrier(null, serviceRegistry, searchJob);
            barrier.waitForJobs();
        }
    } catch (SearchException e) {
        logger.warn("Unable to find mediapackages in search: ", e.getMessage());
    } catch (UnauthorizedException e) {
        logger.warn(e.getMessage());
    } catch (MediaPackageException e) {
        logger.warn(e.getMessage());
    } catch (ServiceRegistryException e) {
        logger.warn(e.getMessage());
    } catch (NotFoundException e) {
        logger.warn(e.getMessage());
    } catch (IOException e) {
        logger.warn(e.getMessage());
    } catch (DistributionException e) {
        logger.warn(e.getMessage());
    } finally {
        securityService.setOrganization(prevOrg);
        securityService.setUser(prevUser);
    }
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) SearchResultItem(org.opencastproject.search.api.SearchResultItem) SearchException(org.opencastproject.search.api.SearchException) NotFoundException(org.opencastproject.util.NotFoundException) SearchResult(org.opencastproject.search.api.SearchResult) Attachment(org.opencastproject.mediapackage.Attachment) IOException(java.io.IOException) JobBarrier(org.opencastproject.job.api.JobBarrier) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Result(org.opencastproject.job.api.JobBarrier.Result) SearchResult(org.opencastproject.search.api.SearchResult) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 2 with DistributionException

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

the class WowzaAdaptiveStreamingDistributionService method retract.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.distribution.api.StreamingDistributionService#retract(java.lang.String,
 * org.opencastproject.mediapackage.MediaPackage, java.util.Set)
 */
@Override
public Job retract(String channelId, MediaPackage mediaPackage, Set<String> elementIds) throws DistributionException {
    RequireUtil.notNull(mediaPackage, "mediaPackage");
    RequireUtil.notNull(elementIds, "elementIds");
    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 3 with DistributionException

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

the class WowzaAdaptiveStreamingDistributionService method saveSmilFile.

private void saveSmilFile(File smilFile, Document doc) throws DistributionException {
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult stream = new StreamResult(smilFile);
        transformer.transform(source, stream);
        logger.info("SMIL file for Wowza server saved at {}", smilFile);
    } catch (TransformerConfigurationException ex) {
        logger.error("Could not write SMIL file {} for distribution", smilFile);
        throw new DistributionException(format("Could not write SMIL file %s for distribution", smilFile));
    } catch (TransformerException ex) {
        logger.error("Could not write SMIL file {} for distribution", smilFile);
        throw new DistributionException(format("Could not write SMIL file %s for distribution", smilFile));
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) DistributionException(org.opencastproject.distribution.api.DistributionException) TransformerException(javax.xml.transform.TransformerException)

Example 4 with DistributionException

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

the class WowzaAdaptiveStreamingDistributionService method retractElement.

/**
 * Retracts the mediapackage with the given identifier from the distribution channel.
 *
 * @param channelId
 *          the channel id
 * @param mediapackage
 *          the mediapackage
 * @param elementId
 *          the element identifier
 * @return the retracted element or <code>null</code> if the element was not retracted
 */
protected MediaPackageElement[] retractElement(String channelId, final MediaPackage mediapackage, String elementId) throws DistributionException {
    notNull(mediapackage, "mediapackage");
    notNull(elementId, "elementId");
    notNull(channelId, "channelId");
    // Make sure the element exists
    final MediaPackageElement element = mediapackage.getElementById(elementId);
    if (element == null)
        throw new IllegalStateException("No element " + elementId + " found in mediapackage" + mediapackage.getIdentifier());
    logger.debug("Start element retraction for element \"{}\" with URI {}", elementId, element.getURI());
    ArrayList<MediaPackageElement> retractedElements = new ArrayList<MediaPackageElement>();
    // Has this element been distributed?
    if (element == null || (!(element instanceof TrackImpl)))
        return null;
    try {
        // Get the distribution path on the disk for this mediapackage element
        File elementFile = getDistributionFile(channelId, mediapackage, element);
        final File smilFile = getSmilFile(element, mediapackage, channelId);
        logger.debug("delete elementFile {}", elementFile);
        // or has been removed otherwise
        if (elementFile == null || !elementFile.exists()) {
            logger.warn("Deleting element file: File does not exist. Perhaps was it already deleted?: {}", elementFile);
            retractedElements.add(element);
            return retractedElements.toArray(new MediaPackageElement[0]);
        } else {
            // If a SMIL file is referenced by this element, delete first all the elements within
            if (elementFile.equals(smilFile)) {
                Document smilXml = getSmilDocument(smilFile);
                NodeList videoList = smilXml.getElementsByTagName("video");
                for (int i = 0; i < videoList.getLength(); i++) {
                    if (videoList.item(i) instanceof Element) {
                        String smilPathStr = ((Element) videoList.item(i)).getAttribute("src");
                        // Patch the streaming tags
                        if (smilPathStr.contains("mp4:"))
                            smilPathStr = smilPathStr.replace("mp4:", "");
                        if (!smilPathStr.endsWith(".mp4"))
                            smilPathStr += ".mp4";
                        elementFile = smilFile.toPath().resolveSibling(smilPathStr).toFile();
                        deleteElementFile(elementFile);
                    }
                }
                if (smilFile.isFile() && !smilFile.delete()) {
                    logger.warn("The SMIL file {} could not be succesfully deleted. Forcing quite deletion...");
                }
            } else {
                deleteElementFile(elementFile);
            }
        }
        logger.info("Finished rectracting element {} of media package {}", elementId, mediapackage);
        retractedElements.add(element);
        return retractedElements.toArray(new MediaPackageElement[0]);
    } catch (Exception e) {
        logger.warn("Error retracting element " + elementId + " of mediapackage " + mediapackage, e);
        if (e instanceof DistributionException) {
            throw (DistributionException) e;
        } else {
            throw new DistributionException(e);
        }
    }
}
Also used : TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) NodeList(org.w3c.dom.NodeList) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) 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) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) DistributionException(org.opencastproject.distribution.api.DistributionException) File(java.io.File)

Example 5 with DistributionException

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

the class AwsS3DistributionServiceImpl method retractElement.

/**
 * Retracts the media package element with the given identifier from the distribution channel.
 *
 * @param channelId
 *          the channel id
 * @param mediaPackage
 *          the media package
 * @param element
 *          the element
 * @return the retracted element or <code>null</code> if the element was not retracted
 */
protected MediaPackageElement retractElement(String channelId, MediaPackage mediaPackage, MediaPackageElement element) throws DistributionException {
    notNull(mediaPackage, "mediaPackage");
    notNull(element, "element");
    try {
        String objectName = getDistributedObjectName(element);
        if (objectName != null) {
            s3.deleteObject(bucketName, objectName);
            logger.info("Retracted element {}, object {}", element.getIdentifier(), objectName);
        }
        return element;
    } catch (AmazonClientException e) {
        throw new DistributionException("AWS error: " + e.getMessage(), e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) DistributionException(org.opencastproject.distribution.api.DistributionException)

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