Search in sources :

Example 31 with MediaPackageException

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

the class OaiPmhPublicationServiceRemoteImpl method publish.

@Override
public Job publish(MediaPackage mediaPackage, String repository, Set<String> downloadIds, Set<String> streamingIds, boolean checkAvailability) throws PublicationException, MediaPackageException {
    final String mediapackageXml = MediaPackageParser.getAsXml(mediaPackage);
    final List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("mediapackage", mediapackageXml));
    params.add(new BasicNameValuePair("channel", repository));
    params.add(new BasicNameValuePair("downloadElementIds", StringUtils.join(downloadIds, ";;")));
    params.add(new BasicNameValuePair("streamingElementIds", StringUtils.join(streamingIds, ";;")));
    params.add(new BasicNameValuePair("checkAvailability", Boolean.toString(checkAvailability)));
    final HttpPost post = new HttpPost();
    HttpResponse response = null;
    try {
        post.setEntity(new UrlEncodedFormEntity(params, UTF_8));
        response = getResponse(post);
        if (response != null) {
            logger.info("Publishing media package {} to OAI-PMH channel {} using a remote publication service", mediaPackage, repository);
            try {
                return JobParser.parseJob(response.getEntity().getContent());
            } catch (Exception e) {
                throw new PublicationException("Unable to publish media package '" + mediaPackage + "' using a remote OAI-PMH publication service", e);
            }
        }
    } catch (Exception e) {
        throw new PublicationException("Unable to publish media package " + mediaPackage + " using a remote OAI-PMH publication service.", e);
    } finally {
        closeConnection(response);
    }
    throw new PublicationException("Unable to publish mediapackage " + mediaPackage + " using a remote OAI-PMH publication service.");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) PublicationException(org.opencastproject.publication.api.PublicationException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) PublicationException(org.opencastproject.publication.api.PublicationException)

Example 32 with MediaPackageException

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

the class MatterhornRecordHandler method handle.

@Override
public void handle(Node record) {
    Node mediaPackageNode = ListRecordsResponse.metadataOfRecord(record);
    final MediaPackage mediaPackage;
    try {
        mediaPackage = mediaPackageBuilder.loadFromXml(mediaPackageNode);
    } catch (MediaPackageException e) {
        throw new RuntimeException(e);
    }
    logger.info("Harvested mediapackage " + mediaPackage.getIdentifier().toString());
    try {
        logger.error("This record handler is outdated and doesn't work: It need to be re-implemented");
    // searchService.add(mediaPackage);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) Node(org.w3c.dom.Node) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException)

Example 33 with MediaPackageException

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

the class WorkflowServiceImpl method update.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowService#update(org.opencastproject.workflow.api.WorkflowInstance)
 */
@Override
public void update(final WorkflowInstance workflowInstance) throws WorkflowException, UnauthorizedException {
    final Lock lock = updateLock.get(workflowInstance.getId());
    lock.lock();
    try {
        WorkflowInstance originalWorkflowInstance = null;
        try {
            originalWorkflowInstance = getWorkflowById(workflowInstance.getId());
        } catch (NotFoundException e) {
        // That's fine, it's a new workflow instance
        }
        if (originalWorkflowInstance != null) {
            try {
                assertPermission(originalWorkflowInstance, Permissions.Action.WRITE.toString());
            } catch (MediaPackageException e) {
                throw new WorkflowParsingException(e);
            }
        }
        MediaPackage updatedMediaPackage = null;
        try {
            // Before we persist this, extract the metadata
            updatedMediaPackage = workflowInstance.getMediaPackage();
            populateMediaPackageMetadata(updatedMediaPackage);
            String seriesId = updatedMediaPackage.getSeries();
            if (seriesId != null && workflowInstance.getCurrentOperation() != null) {
                // If the mediapackage contains a series, find the series ACLs and add the security information to the
                // mediapackage
                AccessControlList acl = seriesService.getSeriesAccessControl(seriesId);
                Option<AccessControlList> activeSeriesAcl = authorizationService.getAcl(updatedMediaPackage, AclScope.Series);
                if (activeSeriesAcl.isNone() || !AccessControlUtil.equals(activeSeriesAcl.get(), acl))
                    authorizationService.setAcl(updatedMediaPackage, AclScope.Series, acl);
            }
        } catch (SeriesException e) {
            throw new WorkflowDatabaseException(e);
        } catch (NotFoundException e) {
            logger.warn("Metadata for mediapackage {} could not be updated because it wasn't found", updatedMediaPackage, e);
        } catch (Exception e) {
            logger.error("Metadata for mediapackage {} could not be updated", updatedMediaPackage, e);
        }
        // Synchronize the job status with the workflow
        WorkflowState workflowState = workflowInstance.getState();
        String xml;
        try {
            xml = WorkflowParser.toXml(workflowInstance);
        } catch (Exception e) {
            // Can't happen, since we are converting from an in-memory object
            throw new IllegalStateException("In-memory workflow instance could not be serialized", e);
        }
        Job job = null;
        try {
            job = serviceRegistry.getJob(workflowInstance.getId());
            job.setPayload(xml);
            // Synchronize workflow and job state
            switch(workflowState) {
                case FAILED:
                    job.setStatus(Status.FAILED);
                    break;
                case FAILING:
                    break;
                case INSTANTIATED:
                    job.setDispatchable(true);
                    job.setStatus(Status.QUEUED);
                    break;
                case PAUSED:
                    job.setStatus(Status.PAUSED);
                    break;
                case RUNNING:
                    job.setStatus(Status.RUNNING);
                    break;
                case STOPPED:
                    job.setStatus(Status.CANCELED);
                    break;
                case SUCCEEDED:
                    job.setStatus(Status.FINISHED);
                    break;
                default:
                    throw new IllegalStateException("Found a workflow state that is not handled");
            }
        } catch (ServiceRegistryException e) {
            logger.error(e, "Unable to read workflow job %s from service registry", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        } catch (NotFoundException e) {
            logger.error("Job for workflow %s not found in service registry", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        }
        // Update both workflow and workflow job
        try {
            job = serviceRegistry.updateJob(job);
            messageSender.sendObjectMessage(WorkflowItem.WORKFLOW_QUEUE, MessageSender.DestinationType.Queue, WorkflowItem.updateInstance(workflowInstance));
            index(workflowInstance);
        } catch (ServiceRegistryException e) {
            logger.error("Update of workflow job %s in the service registry failed, service registry and workflow index may be out of sync", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        } catch (NotFoundException e) {
            logger.error("Job for workflow %s not found in service registry", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        } catch (Exception e) {
            logger.error("Update of workflow job %s in the service registry failed, service registry and workflow index may be out of sync", job.getId());
            throw new WorkflowException(e);
        }
        if (workflowStatsCollect) {
            workflowsStatistics.updateWorkflow(getBeanStatistics(), getHoldWorkflows());
        }
        try {
            WorkflowInstance clone = WorkflowParser.parseWorkflowInstance(WorkflowParser.toXml(workflowInstance));
            fireListeners(originalWorkflowInstance, clone);
        } catch (Exception e) {
            // Can't happen, since we are converting from an in-memory object
            throw new IllegalStateException("In-memory workflow instance could not be serialized", e);
        }
    } finally {
        lock.unlock();
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) NotFoundException(org.opencastproject.util.NotFoundException) Collections.mkString(org.opencastproject.util.data.Collections.mkString) SeriesException(org.opencastproject.series.api.SeriesException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) UndispatchableJobException(org.opencastproject.serviceregistry.api.UndispatchableJobException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Lock(java.util.concurrent.locks.Lock) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowState(org.opencastproject.workflow.api.WorkflowInstance.WorkflowState) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException)

Example 34 with MediaPackageException

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

the class VideoEditorWorkflowOperationHandler method resume.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.ResumableWorkflowOperationHandler#resume(org.opencastproject.workflow.api.WorkflowInstance,
 *      JobContext, java.util.Map)
 */
@Override
public WorkflowOperationResult resume(WorkflowInstance workflowInstance, JobContext context, Map<String, String> properties) throws WorkflowOperationException {
    MediaPackage mp = workflowInstance.getMediaPackage();
    logger.info("Resume video editor operation for mediapackage {}", mp.getIdentifier().compact());
    // Get configuration
    WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
    String sourceTrackFlavorsProperty = StringUtils.trimToNull(worflowOperationInstance.getConfiguration(SOURCE_FLAVORS_PROPERTY));
    if (sourceTrackFlavorsProperty == null) {
        throw new WorkflowOperationException(format("Required configuration property %s not set.", SOURCE_FLAVORS_PROPERTY));
    }
    String targetSmilFlavorProperty = StringUtils.trimToNull(worflowOperationInstance.getConfiguration(TARGET_SMIL_FLAVOR_PROPERTY));
    if (targetSmilFlavorProperty == null) {
        throw new WorkflowOperationException(format("Required configuration property %s not set.", TARGET_SMIL_FLAVOR_PROPERTY));
    }
    String targetFlavorSybTypeProperty = StringUtils.trimToNull(worflowOperationInstance.getConfiguration(TARGET_FLAVOR_SUBTYPE_PROPERTY));
    if (targetFlavorSybTypeProperty == null) {
        throw new WorkflowOperationException(format("Required configuration property %s not set.", TARGET_FLAVOR_SUBTYPE_PROPERTY));
    }
    boolean skipIfNoTrim = BooleanUtils.toBoolean(worflowOperationInstance.getConfiguration(SKIP_NOT_TRIMMED_PROPERTY));
    // Get source tracks
    TrackSelector trackSelector = new TrackSelector();
    for (String flavor : asList(sourceTrackFlavorsProperty)) {
        trackSelector.addFlavor(flavor);
    }
    Collection<Track> sourceTracks = trackSelector.select(mp, false);
    if (sourceTracks.isEmpty()) {
        throw new WorkflowOperationException(format("No source tracks found in mediapacksge %s with flavors %s.", mp.getIdentifier().compact(), sourceTrackFlavorsProperty));
    }
    // Get SMIL file
    MediaPackageElementFlavor smilTargetFlavor = MediaPackageElementFlavor.parseFlavor(targetSmilFlavorProperty);
    Catalog[] smilCatalogs = mp.getCatalogs(smilTargetFlavor);
    if (smilCatalogs == null || smilCatalogs.length == 0) {
        throw new WorkflowOperationException(format("No SMIL catalog found in mediapackage %s with flavor %s.", mp.getIdentifier().compact(), targetSmilFlavorProperty));
    }
    File smilFile = null;
    Smil smil = null;
    try {
        smilFile = workspace.get(smilCatalogs[0].getURI());
        smil = smilService.fromXml(smilFile).getSmil();
        smil = replaceAllTracksWith(smil, sourceTracks.toArray(new Track[sourceTracks.size()]));
        InputStream is = null;
        try {
            is = IOUtils.toInputStream(smil.toXML(), "UTF-8");
            // Remove old SMIL
            workspace.delete(mp.getIdentifier().compact(), smilCatalogs[0].getIdentifier());
            mp.remove(smilCatalogs[0]);
            // put modified SMIL into workspace
            URI newSmilUri = workspace.put(mp.getIdentifier().compact(), smil.getId(), SMIL_FILE_NAME, is);
            Catalog catalog = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().elementFromURI(newSmilUri, MediaPackageElement.Type.Catalog, smilCatalogs[0].getFlavor());
            catalog.setIdentifier(smil.getId());
            mp.add(catalog);
        } catch (Exception ex) {
            throw new WorkflowOperationException(ex);
        } finally {
            IOUtils.closeQuietly(is);
        }
    } catch (NotFoundException ex) {
        throw new WorkflowOperationException(format("Failed to get SMIL catalog %s from mediapackage %s.", smilCatalogs[0].getIdentifier(), mp.getIdentifier().compact()), ex);
    } catch (IOException ex) {
        throw new WorkflowOperationException(format("Can't open SMIL catalog %s from mediapackage %s.", smilCatalogs[0].getIdentifier(), mp.getIdentifier().compact()), ex);
    } catch (SmilException ex) {
        throw new WorkflowOperationException(ex);
    }
    if (skipIfNoTrim) {
        // We should not modify the SMIL file as we traverse through its elements, so we make a copy and modify it instead
        try {
            Smil filteredSmil = smilService.fromXml(smil.toXML()).getSmil();
            for (SmilMediaObject element : smil.getBody().getMediaElements()) {
                // body should contain par elements
                if (element.isContainer()) {
                    SmilMediaContainer container = (SmilMediaContainer) element;
                    if (SmilMediaContainer.ContainerType.PAR == container.getContainerType()) {
                        continue;
                    }
                }
                filteredSmil = smilService.removeSmilElement(filteredSmil, element.getId()).getSmil();
            }
            // one that takes the whole video size
            switch(filteredSmil.getBody().getMediaElements().size()) {
                case 0:
                    logger.info("Skipping SMIL job generation for mediapackage '{}', " + "because the SMIL does not define any trimming points", mp.getIdentifier());
                    return skip(workflowInstance, context);
                case 1:
                    // component represents the whole duration or not, therefore we don't bother to try
                    if (mp.getDuration() < 0)
                        break;
                    SmilMediaContainer parElement = (SmilMediaContainer) filteredSmil.getBody().getMediaElements().get(0);
                    boolean skip = true;
                    for (SmilMediaObject elementChild : parElement.getElements()) {
                        if (!elementChild.isContainer()) {
                            SmilMediaElement media = (SmilMediaElement) elementChild;
                            // If they don't represent the whole length, then we break --we have a trimming point
                            if ((media.getClipBeginMS() != 0) || (media.getClipEndMS() != mp.getDuration())) {
                                skip = false;
                                break;
                            }
                        }
                    }
                    if (skip) {
                        logger.info("Skipping SMIL job generation for mediapackage '{}', " + "because the trimming points in the SMIL correspond " + "to the beginning and the end of the video", mp.getIdentifier());
                        return skip(workflowInstance, context);
                    }
                    break;
                default:
                    break;
            }
        } catch (MalformedURLException | SmilException | JAXBException | SAXException e) {
            logger.warn("Error parsing input SMIL to determine if it has trimpoints. " + "We will assume it does and go on creating jobs.");
        }
    }
    // Create video edit jobs and run them
    List<Job> jobs = null;
    try {
        logger.info("Create processing jobs for SMIL file: {}", smilCatalogs[0].getIdentifier());
        jobs = videoEditorService.processSmil(smil);
        if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) {
            throw new WorkflowOperationException(format("Processing SMIL file failed: %s", smilCatalogs[0].getIdentifier()));
        }
        logger.info("Finished processing of SMIL file: {}", smilCatalogs[0].getIdentifier());
    } catch (ProcessFailedException ex) {
        throw new WorkflowOperationException(format("Finished processing of SMIL file: %s", smilCatalogs[0].getIdentifier()), ex);
    }
    // Move edited tracks to work location and set target flavor
    Track editedTrack = null;
    boolean mpAdded = false;
    for (Job job : jobs) {
        try {
            editedTrack = (Track) MediaPackageElementParser.getFromXml(job.getPayload());
            MediaPackageElementFlavor editedTrackFlavor = editedTrack.getFlavor();
            editedTrack.setFlavor(new MediaPackageElementFlavor(editedTrackFlavor.getType(), targetFlavorSybTypeProperty));
            URI editedTrackNewUri = workspace.moveTo(editedTrack.getURI(), mp.getIdentifier().compact(), editedTrack.getIdentifier(), FilenameUtils.getName(editedTrack.getURI().toString()));
            editedTrack.setURI(editedTrackNewUri);
            for (Track track : sourceTracks) {
                if (track.getFlavor().getType().equals(editedTrackFlavor.getType())) {
                    mp.addDerived(editedTrack, track);
                    mpAdded = true;
                    break;
                }
            }
            if (!mpAdded) {
                mp.add(editedTrack);
            }
        } catch (MediaPackageException ex) {
            throw new WorkflowOperationException("Failed to get information about the edited track(s)", ex);
        } catch (NotFoundException | IOException | IllegalArgumentException ex) {
            throw new WorkflowOperationException("Moving edited track to work location failed.", ex);
        } catch (Exception ex) {
            throw new WorkflowOperationException(ex);
        }
    }
    logger.info("VideoEdit workflow {} finished", workflowInstance.getId());
    return createResult(mp, Action.CONTINUE);
}
Also used : MalformedURLException(java.net.MalformedURLException) TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) NotFoundException(org.opencastproject.util.NotFoundException) URI(java.net.URI) SAXException(org.xml.sax.SAXException) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) SmilException(org.opencastproject.smil.api.SmilException) SmilMediaObject(org.opencastproject.smil.entity.media.api.SmilMediaObject) Job(org.opencastproject.job.api.Job) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Catalog(org.opencastproject.mediapackage.Catalog) SmilException(org.opencastproject.smil.api.SmilException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Smil(org.opencastproject.smil.entity.api.Smil) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) File(java.io.File) Track(org.opencastproject.mediapackage.Track)

Example 35 with MediaPackageException

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

the class WaveformWorkflowOperationHandler method cleanupWorkspace.

/**
 * Remove all files created by the given jobs
 * @param jobs
 *          Jobs to clean up for
 */
private void cleanupWorkspace(List<Job> jobs) {
    for (Job job : jobs) {
        String jobPayload = job.getPayload();
        if (StringUtils.isNotEmpty(jobPayload)) {
            try {
                MediaPackageElement waveformMpe = MediaPackageElementParser.getFromXml(jobPayload);
                URI waveformUri = waveformMpe.getURI();
                workspace.delete(waveformUri);
            } catch (MediaPackageException ex) {
                // unexpected job payload
                logger.error("Can't parse waveform attachment from job {}", job.getId());
            } catch (NotFoundException ex) {
            // this is ok, because we want delete the file
            } catch (IOException ex) {
                logger.warn("Deleting waveform image file from workspace failed: {}", ex.getMessage());
            // this is ok, because workspace cleaner will remove old files if they exist
            }
        }
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Job(org.opencastproject.job.api.Job) URI(java.net.URI)

Aggregations

MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)72 Job (org.opencastproject.job.api.Job)42 IOException (java.io.IOException)34 MediaPackage (org.opencastproject.mediapackage.MediaPackage)33 NotFoundException (org.opencastproject.util.NotFoundException)31 URI (java.net.URI)25 ArrayList (java.util.ArrayList)25 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)21 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)20 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)19 Track (org.opencastproject.mediapackage.Track)17 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)15 File (java.io.File)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 HttpResponse (org.apache.http.HttpResponse)12 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)12 HttpPost (org.apache.http.client.methods.HttpPost)12 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)12 EncoderException (org.opencastproject.composer.api.EncoderException)12