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);
}
}
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);
}
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);
}
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());
}
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;
}
Aggregations