use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class VideoEditorWorkflowOperationHandlerTest method testEditorOperationSkip.
@Test
public void testEditorOperationSkip() throws WorkflowOperationException {
WorkflowInstanceImpl workflowInstance = getWorkflowInstance(mp, getDefaultConfiguration(true));
WorkflowOperationResult result = videoEditorWorkflowOperationHandler.skip(workflowInstance, null);
Assert.assertNotNull("VideoEditor workflow operation returns null but should be an instantiated WorkflowOperationResult", result);
// mediapackage should contain new derived track with flavor given by "target-flavor-subtype" configuration
WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
String targetFlavorSubtypeProperty = worflowOperationInstance.getConfiguration("target-flavor-subtype");
String skippedFlavorsProperty = worflowOperationInstance.getConfiguration("skipped-flavors");
TrackSelector trackSelector = new TrackSelector();
trackSelector.addFlavor(skippedFlavorsProperty);
Collection<Track> skippedTracks = trackSelector.select(result.getMediaPackage(), false);
Assert.assertTrue("Mediapackage does not contain any tracks matching flavor " + skippedFlavorsProperty, skippedTracks != null && !skippedTracks.isEmpty());
for (Track skippedTrack : skippedTracks) {
MediaPackageElementFlavor derivedTrackFlavor = MediaPackageElementFlavor.flavor(skippedTrack.getFlavor().getType(), targetFlavorSubtypeProperty);
MediaPackageElement[] derivedElements = result.getMediaPackage().getDerived(skippedTrack, derivedTrackFlavor);
Assert.assertTrue("Media package should contain track with flavor " + derivedTrackFlavor.toString(), derivedElements != null && derivedElements.length > 0);
}
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class VideoEditorWorkflowOperationHandlerTest method testEditorOperationSkipWithModifiedSkippedFlavorsAndTargetFlavorProperty.
@Test
@Ignore
public void testEditorOperationSkipWithModifiedSkippedFlavorsAndTargetFlavorProperty() throws WorkflowOperationException {
Map<String, String> configuration = getDefaultConfiguration(true);
configuration.put("skipped-flavors", "*/preview");
configuration.put("target-flavor-subtype", "edited");
WorkflowInstanceImpl workflowInstance = getWorkflowInstance(mp, configuration);
WorkflowOperationResult result = videoEditorWorkflowOperationHandler.skip(workflowInstance, null);
Assert.assertNotNull("VideoEditor workflow operation returns null but should be an instantiated WorkflowOperationResult", result);
// mediapackage should contain new derived track with flavor given by "target-flavor-subtype" configuration
WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
String targetFlavorSubtypeProperty = worflowOperationInstance.getConfiguration("target-flavor-subtype");
String skippedFlavorsProperty = worflowOperationInstance.getConfiguration("skipped-flavors");
TrackSelector trackSelector = new TrackSelector();
trackSelector.addFlavor(skippedFlavorsProperty);
Collection<Track> skippedTracks = trackSelector.select(result.getMediaPackage(), false);
Assert.assertTrue("Mediapackage does not contain any tracks matching flavor " + skippedFlavorsProperty, skippedTracks != null && !skippedTracks.isEmpty());
for (Track skippedTrack : skippedTracks) {
MediaPackageElementFlavor derivedTrackFlavor = MediaPackageElementFlavor.flavor(skippedTrack.getFlavor().getType(), targetFlavorSubtypeProperty);
MediaPackageElement[] derivedElements = result.getMediaPackage().getDerived(skippedTrack, derivedTrackFlavor);
Assert.assertTrue("Media package should contain track with flavor " + derivedTrackFlavor.toString(), derivedElements != null && derivedElements.length > 0);
Assert.assertTrue("Mediapackage schould contain a derived track with flavor subtype " + targetFlavorSubtypeProperty, derivedElements[0].getFlavor().getSubtype().equals(targetFlavorSubtypeProperty));
}
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class VideoEditorWorkflowOperationHandlerTest method testEditorOperationStart.
@Test
public void testEditorOperationStart() throws WorkflowOperationException, IOException {
// uri for new preview track smil file
EasyMock.expect(workspaceMock.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(URI.create("http://localhost:8080/foo/presenter.smil"));
// uri for new episode smil file
String episodeSmilUri = "http://localhost:8080/foo/episode.smil";
EasyMock.expect(workspaceMock.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(URI.create(episodeSmilUri));
EasyMock.replay(workspaceMock);
WorkflowInstanceImpl workflowInstance = getWorkflowInstance(mp, getDefaultConfiguration(true));
WorkflowOperationResult result = videoEditorWorkflowOperationHandler.start(workflowInstance, null);
Assert.assertNotNull("VideoEditor workflow operation returns null but should be an instantiated WorkflowOperationResult", result);
EasyMock.verify(workspaceMock);
WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
String smillFlavorsProperty = worflowOperationInstance.getConfiguration("smil-flavors");
String previewFlavorsProperty = worflowOperationInstance.getConfiguration("preview-flavors");
MediaPackageElementFlavor smilFlavor = MediaPackageElementFlavor.parseFlavor(smillFlavorsProperty);
MediaPackageElementFlavor previewFlavor = MediaPackageElementFlavor.parseFlavor(previewFlavorsProperty);
// each preview track (e.g. presenter/preview) should have an own smil catalog in media package
Catalog[] previewSmilCatalogs = result.getMediaPackage().getCatalogs(new MediaPackageElementFlavor("presenter", "smil"));
Assert.assertTrue(previewSmilCatalogs != null && previewSmilCatalogs.length > 0);
for (Track track : result.getMediaPackage().getTracks()) {
if (track.getFlavor().matches(previewFlavor)) {
boolean smilCatalogFound = false;
MediaPackageElementFlavor trackSmilFlavor = new MediaPackageElementFlavor(track.getFlavor().getType(), smilFlavor.getSubtype());
for (Catalog previewSmilCatalog : previewSmilCatalogs) {
if (previewSmilCatalog.getFlavor().matches(trackSmilFlavor)) {
smilCatalogFound = true;
break;
}
}
Assert.assertTrue("Mediapackage doesn't contain a smil catalog with flavor " + trackSmilFlavor.toString(), smilCatalogFound);
}
}
// an "target-smil-flavor catalog" schould be in media package
String targetSmilFlavorProperty = worflowOperationInstance.getConfiguration("target-smil-flavor");
Catalog[] episodeSmilCatalogs = result.getMediaPackage().getCatalogs(MediaPackageElementFlavor.parseFlavor(targetSmilFlavorProperty));
Assert.assertTrue("Mediapackage should contain catalog with flavor " + targetSmilFlavorProperty, episodeSmilCatalogs != null && episodeSmilCatalogs.length > 0);
Assert.assertTrue("Target smil catalog URI does not match", episodeSmilCatalogs[0].getURI().compareTo(URI.create(episodeSmilUri)) == 0);
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class WorkflowServiceImpl method findIfFailedState.
/**
* Finds a given operation position in a WorkflowInstance if the operation is failed.
*
* @param workflowInstance
* The workflow instance to search for the failed operation.
* @param operation
* The operation template id to look for.
* @return The operation if it can be found, null if it is missing.
*/
protected WorkflowOperationInstance findIfFailedState(WorkflowInstance workflowInstance, String operation) {
WorkflowOperationInstance result = null;
WorkflowOperationInstance last = null;
for (WorkflowOperationInstance current : workflowInstance.getOperations()) {
if (current.getState().equals(OperationState.PAUSED) && operation.equals(current.getTemplate()) && last != null && last.getState().equals(OperationState.FAILED)) {
result = current;
break;
}
last = current;
}
return result;
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class WorkflowOperationWorker method execute.
/**
* Executes the workflow operation logic.
*/
public WorkflowInstance execute() {
WorkflowOperationInstance operation = workflow.getCurrentOperation();
try {
WorkflowOperationResult result = null;
switch(operation.getState()) {
case INSTANTIATED:
case RETRY:
result = start();
break;
case PAUSED:
result = resume();
break;
default:
throw new IllegalStateException("Workflow operation '" + operation + "' is in unexpected state '" + operation.getState() + "'");
}
if (result == null || Action.CONTINUE.equals(result.getAction()) || Action.SKIP.equals(result.getAction())) {
if (handler != null) {
handler.destroy(workflow, null);
}
}
workflow = service.handleOperationResult(workflow, result);
return workflow;
} catch (JobCanceledException e) {
logger.info(e.getMessage());
return workflow;
} catch (WorkflowOperationAbortedException e) {
// Don't log it as error because it was aborted by the user
logger.info("Workflow operation '" + operation + "' aborted by user");
} catch (Exception e) {
Throwable t = e.getCause();
if (t != null) {
logger.error("Workflow operation '" + operation + "' failed", t);
} else {
logger.error("Workflow operation '" + operation + "' failed", e);
}
// the associated job shares operation's id
service.getServiceRegistry().incident().unhandledException(operation.getId(), Severity.FAILURE, e);
}
try {
workflow = service.handleOperationException(workflow, operation);
} catch (Exception e2) {
logger.error("Error handling workflow operation '{}' failure: {}", operation, e2.getMessage(), e2);
}
return workflow;
}
Aggregations