Search in sources :

Example 1 with LiveScheduleException

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

the class LiveScheduleServiceImpl method publish.

void publish(MediaPackage mp) throws LiveScheduleException {
    try {
        // Add media package to the search index
        logger.info("Publishing LIVE media package {} to search index", mp);
        Job publishJob = searchService.add(mp);
        if (!waitForStatus(publishJob).isSuccess())
            throw new LiveScheduleException("Live media package " + mp.getIdentifier() + " could not be published");
    } catch (LiveScheduleException e) {
        throw e;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : 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 2 with LiveScheduleException

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

the class LiveScheduleServiceImpl method retract.

void retract(MediaPackage mp) throws LiveScheduleException {
    try {
        List<Job> jobs = new ArrayList<Job>();
        Set<String> elementIds = new HashSet<String>();
        // Remove media package from the search index
        String mpId = mp.getIdentifier().compact();
        logger.info("Removing LIVE media package {} from the search index", mpId);
        jobs.add(searchService.delete(mpId));
        // Retract elements
        for (MediaPackageElement mpe : mp.getElements()) {
            if (!MediaPackageElement.Type.Publication.equals(mpe.getElementType()))
                elementIds.add(mpe.getIdentifier());
        }
        jobs.add(downloadDistributionService.retract(CHANNEL_ID, mp, elementIds));
        if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess())
            throw new LiveScheduleException("Removing live media package from search did not complete successfully");
    } catch (LiveScheduleException e) {
        throw e;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList) 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) HashSet(java.util.HashSet)

Example 3 with LiveScheduleException

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

the class LiveScheduleServiceImpl method addLivePublicationChannel.

void addLivePublicationChannel(Organization currentOrg, MediaPackage mp) throws LiveScheduleException {
    logger.debug("Adding live channel publication element to media package {}", mp);
    String engageUrlString = null;
    String playerPath = null;
    if (currentOrg != null) {
        engageUrlString = StringUtils.trimToNull(currentOrg.getProperties().get(ENGAGE_URL_PROPERTY));
        playerPath = StringUtils.trimToNull(currentOrg.getProperties().get(PLAYER_PROPERTY));
    }
    if (engageUrlString == null) {
        engageUrlString = serverUrl;
        logger.info("Using 'server.url' as a fallback for the non-existing organization level key '{}' for the publication url", ENGAGE_URL_PROPERTY);
    }
    if (playerPath == null)
        playerPath = DEFAULT_PLAYER_PATH;
    try {
        // Create new distribution element
        URI engageUri = URIUtils.resolve(new URI(engageUrlString), playerPath + "?id=" + mp.getIdentifier().compact());
        Publication publicationElement = PublicationImpl.publication(UUID.randomUUID().toString(), CHANNEL_ID, engageUri, MimeTypes.parseMimeType("text/html"));
        mp.add(publicationElement);
    } catch (URISyntaxException e) {
        throw new LiveScheduleException(e);
    }
}
Also used : Publication(org.opencastproject.mediapackage.Publication) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 4 with LiveScheduleException

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

the class LiveScheduleServiceImpl method createLiveEvent.

boolean createLiveEvent(String mpId, DublinCoreCatalog episodeDC) throws LiveScheduleException {
    try {
        logger.info("Creating live media package {}", mpId);
        // Get latest mp from the asset manager
        Snapshot snapshot = getSnapshot(mpId);
        // Temporary mp
        MediaPackage tempMp = (MediaPackage) snapshot.getMediaPackage().clone();
        // Set duration (used by live tracks)
        setDuration(tempMp, episodeDC);
        // Add live tracks to media package
        addLiveTracks(tempMp, episodeDC.getFirst(DublinCore.PROPERTY_SPATIAL));
        // Add and distribute catalogs/acl, this creates a new mp object
        MediaPackage mp = addAndDistributeElements(snapshot);
        // Add tracks from tempMp
        for (Track t : tempMp.getTracks()) mp.add(t);
        // Publish mp to engage search index
        publish(mp);
        // Add engage-live publication channel to archived mp
        Organization currentOrg = null;
        try {
            currentOrg = organizationService.getOrganization(snapshot.getOrganizationId());
        } catch (NotFoundException e) {
            logger.warn("Organization in snapshot not found: {}", snapshot.getOrganizationId());
        }
        MediaPackage archivedMp = snapshot.getMediaPackage();
        addLivePublicationChannel(currentOrg, archivedMp);
        // Take a snapshot with the publication added and put its version in our local cache
        // so that we ignore notifications for this snapshot version.
        snapshotVersionCache.put(mpId, assetManager.takeSnapshot(archivedMp).getVersion());
        return true;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Organization(org.opencastproject.security.api.Organization) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) Track(org.opencastproject.mediapackage.Track) URISyntaxException(java.net.URISyntaxException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 5 with LiveScheduleException

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

the class LiveScheduleServiceImpl method retractPreviousElements.

void retractPreviousElements(MediaPackage previousMp, MediaPackage newMp) throws LiveScheduleException {
    try {
        // Now can retract elements from previous publish. Before creating a retraction
        // job, check if the element url is still used by the new media package.
        Set<String> elementIds = new HashSet<String>();
        for (MediaPackageElement element : previousMp.getElements()) {
            // We don't retract tracks because they are just live links
            if (!Track.TYPE.equals(element.getElementType())) {
                boolean canBeDeleted = true;
                for (MediaPackageElement newElement : newMp.getElements()) {
                    if (element.getURI().equals(newElement.getURI())) {
                        logger.debug("Not retracting element {} with URI {} from download distribution because it is still used by updated live media package", element.getIdentifier(), element.getURI());
                        canBeDeleted = false;
                        break;
                    }
                }
                if (canBeDeleted)
                    elementIds.add(element.getIdentifier());
            }
        }
        if (elementIds.size() > 0) {
            Job job = downloadDistributionService.retract(CHANNEL_ID, previousMp, elementIds);
            // Wait for retraction to finish
            if (!waitForStatus(job).isSuccess())
                logger.warn("One of the download retract jobs did not complete successfully");
            else
                logger.debug("Retraction of previously published elements complete");
        }
    } catch (DistributionException e) {
        throw new LiveScheduleException(e);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) DistributionException(org.opencastproject.distribution.api.DistributionException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet)

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