Search in sources :

Example 31 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class EventsLoader method addDublinCoreCatalog.

private MediaPackage addDublinCoreCatalog(InputStream in, MediaPackageElementFlavor flavor, MediaPackage mediaPackage) throws IOException {
    try {
        String elementId = UUID.randomUUID().toString();
        URI catalogUrl = workspace.put(mediaPackage.getIdentifier().compact(), elementId, "dublincore.xml", in);
        logger.info("Adding catalog with flavor {} to mediapackage {}", flavor, mediaPackage);
        MediaPackageElement mpe = mediaPackage.add(catalogUrl, MediaPackageElement.Type.Catalog, flavor);
        mpe.setIdentifier(elementId);
        mpe.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, workspace.get(catalogUrl)));
        return mediaPackage;
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) NotFoundException(org.opencastproject.util.NotFoundException) URI(java.net.URI)

Example 32 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class AbstractAssetManager method storeAssets.

/**
 * Store all elements of <code>pmp</code> under the given version.
 */
private void storeAssets(final PartialMediaPackage pmp, final Version version) throws Exception {
    final String mpId = pmp.getMediaPackage().getIdentifier().toString();
    final String orgId = getCurrentOrgId();
    for (final MediaPackageElement e : pmp.getElements()) {
        logger.debug(format("Archiving %s %s %s", e.getFlavor(), e.getMimeType(), e.getURI()));
        final StoragePath storagePath = StoragePath.mk(orgId, mpId, version, e.getIdentifier());
        final Opt<StoragePath> existingAssetOpt = findAssetInVersions(e.getChecksum().toString());
        if (existingAssetOpt.isSome()) {
            final StoragePath existingAsset = existingAssetOpt.get();
            logger.debug("Content of asset {} with checksum {} has been archived before", existingAsset.getMediaPackageElementId(), e.getChecksum());
            if (!getAssetStore().copy(existingAsset, storagePath)) {
                throw new AssetManagerException(format("An asset with checksum %s has already been archived but trying to copy or link asset %s to it failed", e.getChecksum(), existingAsset));
            }
        } else {
            final Opt<Long> size = e.getSize() > 0 ? Opt.some(e.getSize()) : Opt.<Long>none();
            getAssetStore().put(storagePath, Source.mk(e.getURI(), size, Opt.nul(e.getMimeType())));
        }
    }
}
Also used : StoragePath(org.opencastproject.assetmanager.impl.storage.StoragePath) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException)

Example 33 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement 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 34 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class WowzaAdaptiveStreamingDistributionService method distributeElements.

/**
 * Distribute Mediapackage elements to the download distribution service.
 *
 * @param channelId The id of the publication channel to be distributed to.
 * @param mediapackage The media package that contains the elements to be distributed.
 * @param elementIds The ids of the elements that should be distributed
 * contained within the media package.
 * @return A reference to the MediaPackageElements that have been distributed.
 * @throws DistributionException Thrown if the parent directory of the
 * MediaPackageElement cannot be created, if the MediaPackageElement cannot be
 * copied or another unexpected exception occurs.
 */
public MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException {
    notNull(mediapackage, "mediapackage");
    notNull(elementIds, "elementIds");
    notNull(channelId, "channelId");
    final Set<MediaPackageElement> elements = getElements(mediapackage, elementIds);
    List<MediaPackageElement> distributedElements = new ArrayList<>();
    for (MediaPackageElement element : elements) {
        MediaPackageElement[] distributed = distributeElement(channelId, mediapackage, element.getIdentifier());
        if (distributed != null) {
            for (MediaPackageElement e : distributed) {
                if (e != null)
                    distributedElements.add(e);
            }
        }
    }
    return distributedElements.toArray(new MediaPackageElement[distributedElements.size()]);
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList)

Example 35 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement 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)

Aggregations

MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)153 MediaPackage (org.opencastproject.mediapackage.MediaPackage)72 NotFoundException (org.opencastproject.util.NotFoundException)50 Job (org.opencastproject.job.api.Job)49 URI (java.net.URI)48 IOException (java.io.IOException)39 ArrayList (java.util.ArrayList)39 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)39 Test (org.junit.Test)36 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)27 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)25 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)24 File (java.io.File)21 Track (org.opencastproject.mediapackage.Track)21 DistributionException (org.opencastproject.distribution.api.DistributionException)20 InputStream (java.io.InputStream)19 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)19 HashSet (java.util.HashSet)18 URISyntaxException (java.net.URISyntaxException)16 Path (javax.ws.rs.Path)16