Search in sources :

Example 16 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class AbstractIncidentService method getIncidentsOfJob.

@Override
public IncidentTree getIncidentsOfJob(long jobId, boolean cascade) throws NotFoundException, IncidentServiceException {
    List<Incident> incidents = getIncidentsOfJob(jobId);
    List<IncidentTree> childIncidents = new ArrayList<IncidentTree>();
    try {
        Job job = getServiceRegistry().getJob(jobId);
        if (cascade && !"START_WORKFLOW".equals(job.getOperation())) {
            childIncidents = getChildIncidents(jobId);
        } else if (cascade && "START_WORKFLOW".equals(job.getOperation())) {
            for (WorkflowOperationInstance operation : getWorkflowService().getWorkflowById(jobId).getOperations()) {
                if (operation.getState().equals(OperationState.INSTANTIATED))
                    continue;
                IncidentTree operationResult = getIncidentsOfJob(operation.getId(), true);
                if (hasIncidents(Collections.list(operationResult)))
                    childIncidents.add(operationResult);
            }
        }
        return new IncidentTreeImpl(incidents, childIncidents);
    } catch (NotFoundException ignore) {
        // Workflow deleted
        return new IncidentTreeImpl(incidents, childIncidents);
    } catch (Exception e) {
        logger.error("Error loading child jobs of {}: {}", jobId);
        throw new IncidentServiceException(e);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) IncidentTreeImpl(org.opencastproject.job.api.IncidentTreeImpl) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) Incident(org.opencastproject.job.api.Incident) Job(org.opencastproject.job.api.Job) IncidentServiceException(org.opencastproject.serviceregistry.api.IncidentServiceException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NotFoundException(org.opencastproject.util.NotFoundException) IncidentTree(org.opencastproject.job.api.IncidentTree)

Example 17 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class ComposeWorkflowOperationHandlerTest method getWorkflowOperationResult.

private WorkflowOperationResult getWorkflowOperationResult(MediaPackage mp, Map<String, String> configurations) throws WorkflowOperationException {
    // Add the mediapackage to a workflow instance
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("op", OperationState.RUNNING);
    operation.setTemplate("compose");
    operation.setState(OperationState.RUNNING);
    for (String key : configurations.keySet()) {
        operation.setConfiguration(key, configurations.get(key));
    }
    List<WorkflowOperationInstance> operationsList = new ArrayList<WorkflowOperationInstance>();
    operationsList.add(operation);
    workflowInstance.setOperations(operationsList);
    // Run the media package through the operation handler, ensuring that metadata gets added
    return operationHandler.start(workflowInstance, null);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Example 18 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class CompositeWorkflowOperationHandlerTest method getWorkflowOperationResult.

private WorkflowOperationResult getWorkflowOperationResult(MediaPackage mp, Map<String, String> configurations) throws WorkflowOperationException {
    // Add the mediapackage to a workflow instance
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("op", OperationState.RUNNING);
    operation.setTemplate("composite");
    operation.setState(OperationState.RUNNING);
    for (String key : configurations.keySet()) {
        operation.setConfiguration(key, configurations.get(key));
    }
    List<WorkflowOperationInstance> operationsList = new ArrayList<WorkflowOperationInstance>();
    operationsList.add(operation);
    workflowInstance.setOperations(operationsList);
    // Run the media package through the operation handler, ensuring that metadata gets added
    return operationHandler.start(workflowInstance, null);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Example 19 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class CoverImageWorkflowOperationHandlerBase method start.

@Override
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    MediaPackage mediaPackage = workflowInstance.getMediaPackage();
    WorkflowOperationInstance operation = workflowInstance.getCurrentOperation();
    logger.info("Cover Image Workflow started for media package '{}'", mediaPackage.getIdentifier());
    // User XML metadata from operation configuration, fallback to default metadata
    String xml = operation.getConfiguration(XML_METADATA);
    if (xml == null) {
        xml = getMetadataXml(mediaPackage);
        logger.debug("Metadata was not part of operation configuration, using Dublin Core as fallback");
    }
    logger.debug("Metadata set to: {}", xml);
    String xsl = loadXsl(operation);
    logger.debug("XSL for transforming metadata to SVG loaded: {}", xsl);
    // Read image dimensions
    int width = getIntConfiguration(operation, WIDTH);
    logger.debug("Image width set to {}px", width);
    int height = getIntConfiguration(operation, HEIGHT);
    logger.debug("Image height set to {}px", height);
    // Read optional poster image flavor
    String posterImgUri = getPosterImageFileUrl(operation.getConfiguration(POSTERIMAGE_URL));
    if (posterImgUri == null)
        posterImgUri = getPosterImageFileUrl(mediaPackage, operation.getConfiguration(POSTERIMAGE_FLAVOR));
    if (posterImgUri == null) {
        logger.debug("No optional poster image set");
    } else {
        logger.debug("Poster image found at '{}'", posterImgUri);
    }
    // Read target flavor
    String targetFlavor = operation.getConfiguration(TARGET_FLAVOR);
    if (StringUtils.isBlank(targetFlavor)) {
        logger.warn("Required configuration key '{}' is blank", TARGET_FLAVOR);
        throw new WorkflowOperationException("Configuration key '" + TARGET_FLAVOR + "' must be set");
    }
    try {
        MediaPackageElementFlavor.parseFlavor(targetFlavor);
    } catch (IllegalArgumentException e) {
        logger.warn("Given target flavor '{}' is not a valid flavor", targetFlavor);
        throw new WorkflowOperationException(e);
    }
    Job generate;
    try {
        generate = getCoverImageService().generateCoverImage(xml, xsl, String.valueOf(width), String.valueOf(height), posterImgUri, targetFlavor);
        logger.debug("Job for cover image generation created");
        if (!waitForStatus(generate).isSuccess()) {
            throw new WorkflowOperationException("'Cover image' job did not successfuly end");
        }
        generate = serviceRegistry.getJob(generate.getId());
        Attachment coverImage = (Attachment) MediaPackageElementParser.getFromXml(generate.getPayload());
        URI attachmentUri = getWorkspace().moveTo(coverImage.getURI(), mediaPackage.getIdentifier().compact(), UUID.randomUUID().toString(), COVERIMAGE_FILENAME);
        coverImage.setURI(attachmentUri);
        coverImage.setMimeType(MimeTypes.PNG);
        // Add tags
        final String targetTags = StringUtils.trimToNull(operation.getConfiguration(TARGET_TAGS));
        if (targetTags != null) {
            for (String tag : asList(targetTags)) {
                logger.trace("Tagging image with '{}'", tag);
                if (StringUtils.trimToNull(tag) != null)
                    coverImage.addTag(tag);
            }
        }
        mediaPackage.add(coverImage);
    } catch (MediaPackageException e) {
        throw new WorkflowOperationException(e);
    } catch (NotFoundException e) {
        throw new WorkflowOperationException(e);
    } catch (ServiceRegistryException e) {
        throw new WorkflowOperationException(e);
    } catch (CoverImageException e) {
        throw new WorkflowOperationException(e);
    } catch (IllegalArgumentException e) {
        throw new WorkflowOperationException(e);
    } catch (IOException e) {
        throw new WorkflowOperationException(e);
    }
    logger.info("Cover Image Workflow finished successfully for media package '{}' within {}ms", mediaPackage.getIdentifier(), generate.getQueueTime());
    return createResult(mediaPackage, Action.CONTINUE, generate.getQueueTime());
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) NotFoundException(org.opencastproject.util.NotFoundException) FileNotFoundException(java.io.FileNotFoundException) Attachment(org.opencastproject.mediapackage.Attachment) IOException(java.io.IOException) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) CoverImageException(org.opencastproject.coverimage.CoverImageException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Job(org.opencastproject.job.api.Job)

Example 20 with WorkflowOperationInstance

use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.

the class VideoEditorWorkflowOperationHandlerTest method getWorkflowInstance.

private WorkflowInstanceImpl getWorkflowInstance(MediaPackage mp, Map<String, String> configurations) {
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowInstance.WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("op", WorkflowOperationInstance.OperationState.RUNNING);
    operation.setTemplate("editor");
    operation.setState(WorkflowOperationInstance.OperationState.RUNNING);
    for (String key : configurations.keySet()) {
        operation.setConfiguration(key, configurations.get(key));
    }
    List<WorkflowOperationInstance> operations = new ArrayList<WorkflowOperationInstance>(1);
    operations.add(operation);
    workflowInstance.setOperations(operations);
    return workflowInstance;
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Aggregations

WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)104 ArrayList (java.util.ArrayList)51 MediaPackage (org.opencastproject.mediapackage.MediaPackage)48 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)37 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)33 Test (org.junit.Test)32 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)31 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)28 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)24 Job (org.opencastproject.job.api.Job)23 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)19 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)19 URI (java.net.URI)18 NotFoundException (org.opencastproject.util.NotFoundException)16 Track (org.opencastproject.mediapackage.Track)14 IOException (java.io.IOException)13 File (java.io.File)12 HashMap (java.util.HashMap)12 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)11 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)10