Search in sources :

Example 6 with LiveScheduleException

use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.

the class LiveScheduleServiceImpl method addAndDistributeElements.

MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException {
    try {
        MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone();
        Set<String> elementIds = new HashSet<String>();
        // Then, add series catalog if needed
        if (StringUtils.isNotEmpty(mp.getSeries())) {
            DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries());
            // Create temporary catalog and save to workspace
            mp.add(catalog);
            URI uri = workspace.put(mp.getIdentifier().toString(), catalog.getIdentifier(), "series.xml", dublinCoreService.serialize(catalog));
            catalog.setURI(uri);
            catalog.setChecksum(null);
            catalog.setFlavor(MediaPackageElements.SERIES);
            elementIds.add(catalog.getIdentifier());
        }
        if (mp.getCatalogs(MediaPackageElements.EPISODE).length > 0)
            elementIds.add(mp.getCatalogs(MediaPackageElements.EPISODE)[0].getIdentifier());
        if (mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE).length > 0)
            elementIds.add(mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE)[0].getIdentifier());
        // Distribute element(s)
        Job distributionJob = downloadDistributionService.distribute(CHANNEL_ID, mp, elementIds, false);
        if (!waitForStatus(distributionJob).isSuccess())
            throw new LiveScheduleException("Element(s) for live media package " + mp.getIdentifier() + " could not be distributed");
        for (String id : elementIds) {
            MediaPackageElement e = mp.getElementById(id);
            // Cleanup workspace/wfr
            mp.remove(e);
            workspace.delete(e.getURI());
        }
        // Add distributed element(s) to mp
        List<MediaPackageElement> distributedElements = (List<MediaPackageElement>) MediaPackageElementParser.getArrayFromXml(distributionJob.getPayload());
        for (MediaPackageElement mpe : distributedElements) mp.add(mpe);
        return mp;
    } catch (LiveScheduleException e) {
        throw e;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) List(java.util.List) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) HashSet(java.util.HashSet)

Example 7 with LiveScheduleException

use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.

the class LiveScheduleServiceImpl method replaceAndDistributeAcl.

MediaPackage replaceAndDistributeAcl(MediaPackage previousMp, AccessControlList acl) throws LiveScheduleException {
    try {
        // This is the mp from the search index
        MediaPackage mp = (MediaPackage) previousMp.clone();
        // Remove previous Acl from the mp
        Attachment[] atts = mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
        if (atts.length > 0)
            mp.remove(atts[0]);
        // Attach current ACL to mp, acl will be created in the ws/wfr
        authService.setAcl(mp, AclScope.Episode, acl);
        atts = mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
        if (atts.length > 0) {
            String aclId = atts[0].getIdentifier();
            // Distribute new acl
            Job distributionJob = downloadDistributionService.distribute(CHANNEL_ID, mp, aclId, false);
            if (!waitForStatus(distributionJob).isSuccess())
                throw new LiveScheduleException("Acl for live media package " + mp.getIdentifier() + " could not be distributed");
            MediaPackageElement e = mp.getElementById(aclId);
            // Cleanup workspace/wfr
            mp.remove(e);
            workspace.delete(e.getURI());
            // Add distributed acl to mp
            mp.add(MediaPackageElementParser.getFromXml(distributionJob.getPayload()));
        }
        return mp;
    } catch (LiveScheduleException e) {
        throw e;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) Job(org.opencastproject.job.api.Job) URISyntaxException(java.net.URISyntaxException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 8 with LiveScheduleException

use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.

the class LiveScheduleServiceImpl method getSnapshot.

Snapshot getSnapshot(String mpId) throws LiveScheduleException {
    AQueryBuilder query = assetManager.createQuery();
    AResult result = query.select(query.snapshot()).where(query.mediaPackageId(mpId).and(query.version().isLatest())).run();
    if (result.getSize() == 0) {
        // Media package not archived?.
        throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
    }
    Opt<ARecord> record = result.getRecords().head();
    if (record.isNone()) {
        // No snapshot?
        throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
    }
    return record.get().getSnapshot().get();
}
Also used : ARecord(org.opencastproject.assetmanager.api.query.ARecord) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException)

Example 9 with LiveScheduleException

use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.

the class LiveScheduleServiceImpl method retractLiveEvent.

boolean retractLiveEvent(MediaPackage mp) throws LiveScheduleException {
    if (!isLive(mp)) {
        logger.debug("Media package {} is not live. Not retracting.", mp.getIdentifier().compact());
        return false;
    }
    retract(mp);
    // Get latest mp from the asset manager if there to remove the publication
    try {
        String mpId = mp.getIdentifier().toString();
        Snapshot snapshot = getSnapshot(mpId);
        MediaPackage archivedMp = snapshot.getMediaPackage();
        removeLivePublicationChannel(archivedMp);
        logger.debug("Removed live pub channel from archived media package {}", mp);
        // Take a snapshot with the publication removed and put its version in our local cache
        // so that we ignore notifications for this snapshot version.
        snapshotVersionCache.put(mpId, assetManager.takeSnapshot(archivedMp).getVersion());
    } catch (LiveScheduleException e) {
    // It was not found in asset manager. This is ok.
    }
    return true;
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException)

Example 10 with LiveScheduleException

use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.

the class LiveScheduleServiceImpl method getMediaPackageFromSearch.

/**
 * Retrieves the media package from the search index.
 *
 * @param mediaPackageId
 *          the media package id
 * @return the media package in the search index or null if not there
 * @throws LiveException
 *           if found many media packages with the same id
 */
MediaPackage getMediaPackageFromSearch(String mediaPackageId) throws LiveScheduleException {
    // Look for the media package in the search index
    SearchQuery query = new SearchQuery().withId(mediaPackageId);
    SearchResult result = searchService.getByQuery(query);
    if (result.size() == 0) {
        logger.debug("The search service doesn't know live mediapackage {}", mediaPackageId);
        return null;
    } else if (result.size() > 1) {
        logger.warn("More than one live mediapackage with id {} returned from search service", mediaPackageId);
        throw new LiveScheduleException("More than one live mediapackage with id " + mediaPackageId + " found");
    }
    return result.getItems()[0].getMediaPackage();
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) SearchResult(org.opencastproject.search.api.SearchResult) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException)

Aggregations

LiveScheduleException (org.opencastproject.liveschedule.api.LiveScheduleException)11 URISyntaxException (java.net.URISyntaxException)7 DistributionException (org.opencastproject.distribution.api.DistributionException)6 NotFoundException (org.opencastproject.util.NotFoundException)6 Job (org.opencastproject.job.api.Job)5 MediaPackage (org.opencastproject.mediapackage.MediaPackage)4 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)4 HashSet (java.util.HashSet)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Snapshot (org.opencastproject.assetmanager.api.Snapshot)2 List (java.util.List)1 Properties (java.util.Properties)1 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)1 ARecord (org.opencastproject.assetmanager.api.query.ARecord)1 AResult (org.opencastproject.assetmanager.api.query.AResult)1 Attachment (org.opencastproject.mediapackage.Attachment)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 Publication (org.opencastproject.mediapackage.Publication)1 Track (org.opencastproject.mediapackage.Track)1