Search in sources :

Example 16 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method getWorkflowDefinition.

private WorkflowDefinition getWorkflowDefinition(String workflowDefinitionID, MediaPackage mediapackage) throws NotFoundException, WorkflowDatabaseException, IngestException {
    // If the workflow definition and instance ID are null, use the default, or throw if there is none
    if (isBlank(workflowDefinitionID)) {
        String mediaPackageId = mediapackage.getIdentifier().compact();
        if (schedulerService != null) {
            logger.info("Determining workflow template for ingested mediapckage {} from capture event {}", mediapackage, mediaPackageId);
            try {
                Map<String, String> recordingProperties = schedulerService.getCaptureAgentConfiguration(mediaPackageId);
                workflowDefinitionID = recordingProperties.get(CaptureParameters.INGEST_WORKFLOW_DEFINITION);
                if (isBlank(workflowDefinitionID)) {
                    workflowDefinitionID = defaultWorkflowDefinionId;
                    logger.debug("No workflow set. Falling back to default.");
                }
                if (isBlank(workflowDefinitionID)) {
                    throw new IngestException("No value found for key '" + CaptureParameters.INGEST_WORKFLOW_DEFINITION + "' from capture event configuration of scheduler event '" + mediaPackageId + "'");
                }
                logger.info("Ingested event {} will be processed using workflow '{}'", mediapackage, workflowDefinitionID);
            } catch (NotFoundException e) {
                logger.warn("Specified capture event {} was not found", mediaPackageId);
            } catch (UnauthorizedException e) {
                throw new IllegalStateException(e);
            } catch (SchedulerException e) {
                logger.warn("Unable to get the workflow definition id from scheduler event {}: {}", mediaPackageId, ExceptionUtils.getMessage(e));
                throw new IngestException(e);
            }
        } else {
            logger.warn("Scheduler service not bound, unable to determine the workflow template to use for ingested mediapckage {}", mediapackage);
        }
    } else {
        logger.info("Ingested mediapackage {} is processed using workflow template '{}', specified during ingest", mediapackage, workflowDefinitionID);
    }
    // Use the default workflow definition if nothing was determined
    if (isBlank(workflowDefinitionID) && defaultWorkflowDefinionId != null) {
        logger.info("Using default workflow definition '{}' to process ingested mediapackage {}", defaultWorkflowDefinionId, mediapackage);
        workflowDefinitionID = defaultWorkflowDefinionId;
    }
    // Check if the workflow definition is valid
    if (StringUtils.isNotBlank(workflowDefinitionID) && StringUtils.isNotBlank(defaultWorkflowDefinionId)) {
        try {
            workflowService.getWorkflowDefinitionById(workflowDefinitionID);
        } catch (WorkflowDatabaseException e) {
            throw new IngestException(e);
        } catch (NotFoundException nfe) {
            logger.warn("Workflow definition {} not found, using default workflow {} instead", workflowDefinitionID, defaultWorkflowDefinionId);
            workflowDefinitionID = defaultWorkflowDefinionId;
        }
    }
    // Have we been able to find a workflow definition id?
    if (isBlank(workflowDefinitionID)) {
        ingestStatistics.failed();
        throw new IllegalStateException("Can not ingest a workflow without a workflow definition or an existing instance. No default definition is specified");
    }
    // Let's make sure the workflow definition exists
    return workflowService.getWorkflowDefinitionById(workflowDefinitionID);
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException)

Example 17 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method addPartialTrack.

@Override
public MediaPackage addPartialTrack(URI uri, MediaPackageElementFlavor flavor, long startTime, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK_FROM_URI, Arrays.asList(uri.toString(), flavor == null ? null : flavor.toString(), MediaPackageParser.getAsXml(mediaPackage)), null, false);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding partial track {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
        job.setStatus(Job.Status.FINISHED);
        // store startTime
        partialTrackStartTimes.put(elementId, startTime);
        logger.debug("Added start time {} for track {}", startTime, elementId);
        logger.info("Successful added partial track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 18 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method addTrack.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addTrack(java.io.InputStream, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addTrack(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK, null, null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding track {} from input stream on mediapackage {}", elementId, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getTrack(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (IOException e) {
        throw e;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 19 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method ingest.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#ingest(org.opencastproject.mediapackage.MediaPackage,
 *      java.lang.String, java.util.Map, java.lang.Long)
 */
@Override
public WorkflowInstance ingest(MediaPackage mp, String workflowDefinitionId, Map<String, String> properties, Long workflowInstanceId) throws IngestException, NotFoundException, UnauthorizedException {
    // Check for legacy media package id
    mp = checkForLegacyMediaPackageId(mp, properties);
    try {
        mp = createSmil(mp);
    } catch (IOException e) {
        throw new IngestException("Unable to add SMIL Catalog", e);
    }
    // Done, update the job status and return the created workflow instance
    if (workflowInstanceId != null) {
        logger.warn("Resuming workflow {} with ingested mediapackage {} is deprecated, skip resuming and start new workflow", workflowInstanceId, mp);
    }
    if (workflowDefinitionId == null) {
        logger.info("Starting a new workflow with ingested mediapackage {} based on the default workflow definition '{}'", mp, defaultWorkflowDefinionId);
    } else {
        logger.info("Starting a new workflow with ingested mediapackage {} based on workflow definition '{}'", mp, workflowDefinitionId);
    }
    try {
        // Determine the workflow definition
        WorkflowDefinition workflowDef = getWorkflowDefinition(workflowDefinitionId, mp);
        // Get the final set of workflow properties
        properties = mergeWorkflowConfiguration(properties, mp.getIdentifier().compact());
        // Remove potential workflow configuration prefixes from the workflow properties
        properties = removePrefixFromProperties(properties);
        // Merge scheduled mediapackage with ingested
        mp = mergeScheduledMediaPackage(mp);
        // Set public ACL if empty
        setPublicAclIfEmpty(mp);
        ingestStatistics.successful();
        if (workflowDef != null) {
            logger.info("Starting new workflow with ingested mediapackage '{}' using the specified template '{}'", mp.getIdentifier().toString(), workflowDefinitionId);
        } else {
            logger.info("Starting new workflow with ingested mediapackage '{}' using the default template '{}'", mp.getIdentifier().toString(), defaultWorkflowDefinionId);
        }
        return workflowService.start(workflowDef, mp, properties);
    } catch (WorkflowException e) {
        ingestStatistics.failed();
        throw new IngestException(e);
    }
}
Also used : WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException)

Aggregations

IngestException (org.opencastproject.ingest.api.IngestException)19 NotFoundException (org.opencastproject.util.NotFoundException)14 MediaPackage (org.opencastproject.mediapackage.MediaPackage)12 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)11 URI (java.net.URI)10 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)10 Job (org.opencastproject.job.api.Job)9 JobUtil.waitForJob (org.opencastproject.util.JobUtil.waitForJob)9 IOException (java.io.IOException)8 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)6 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)5 WorkflowException (org.opencastproject.workflow.api.WorkflowException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ZipArchiveInputStream (org.apache.commons.compress.archivers.zip.ZipArchiveInputStream)4 JDOMException (org.jdom.JDOMException)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 HandleException (org.opencastproject.mediapackage.identifier.HandleException)3