use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowStatisticsTest method testStatistics.
/**
* Tests whether the workflow service statistics are gathered correctly.
*/
@Test
public void testStatistics() throws Exception {
// Start the workflows and advance them in "random" order. With every definition, an instance is started for every
// operation that is part of the definition. So we end up with an instance per definition and operation, and there
// are no two workflows that are in the same operation.
int total = 0;
int paused = 0;
int failed = 0;
int failing = 0;
int instantiated = 0;
int running = 0;
int stopped = 0;
int succeeded = 0;
WorkflowStateListener listener = new WorkflowStateListener(WorkflowState.PAUSED);
service.addWorkflowListener(listener);
List<WorkflowInstance> instances = new ArrayList<WorkflowInstance>();
for (WorkflowDefinition def : workflowDefinitions) {
for (int j = 0; j < def.getOperations().size(); j++) {
mediaPackage.setIdentifier(new UUIDIdBuilderImpl().createNew());
instances.add(service.start(def, mediaPackage));
total++;
paused++;
}
}
// Wait for all the workflows to go into "paused" state
synchronized (listener) {
while (listener.countStateChanges() < WORKFLOW_DEFINITION_COUNT * OPERATION_COUNT) {
listener.wait();
}
}
service.removeWorkflowListener(listener);
// Resume all of them, so some will be finished, some won't
int j = 0;
for (WorkflowInstance instance : instances) {
WorkflowListener instanceListener = new IndividualWorkflowListener(instance.getId());
service.addWorkflowListener(instanceListener);
for (int k = 0; k <= (j % OPERATION_COUNT - 1); k++) {
synchronized (instanceListener) {
service.resume(instance.getId(), null);
instanceListener.wait();
}
}
j++;
}
// TODO: Add failed, failing, stopped etc. workflows as well
// Get the statistics
WorkflowStatistics stats = service.getStatistics();
assertEquals(failed, stats.getFailed());
assertEquals(failing, stats.getFailing());
assertEquals(instantiated, stats.getInstantiated());
assertEquals(succeeded, stats.getFinished());
assertEquals(paused, stats.getPaused());
assertEquals(running, stats.getRunning());
assertEquals(stopped, stats.getStopped());
assertEquals(total, stats.getTotal());
// TODO: Test the operations
// Make sure they are as expected
// for (WorkflowDefinitionReport report : stats.getDefinitions()) {
//
// }
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class AnalyzeTracksWorkflowOperationHandlerTest method testStart.
@Test
public void testStart() throws MediaPackageException, WorkflowOperationException {
MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
VideoStreamImpl videoStream = new VideoStreamImpl("234");
videoStream.setFrameWidth(1280);
videoStream.setFrameHeight(720);
videoStream.setFrameRate(30.0f);
TrackImpl track = new TrackImpl();
track.setFlavor(MediaPackageElementFlavor.parseFlavor("presenter/source"));
track.addStream(videoStream);
JobContext jobContext = EasyMock.createMock(JobContext.class);
EasyMock.replay(jobContext);
WorkflowOperationInstance operationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
String[][] config = { { AnalyzeTracksWorkflowOperationHandler.OPT_SOURCE_FLAVOR, "*/source" }, { AnalyzeTracksWorkflowOperationHandler.OPT_VIDEO_ASPECT, "4/3,16/9" } };
for (String[] cfg : config) {
EasyMock.expect(operationInstance.getConfiguration(cfg[0])).andReturn(cfg[1]).anyTimes();
}
EasyMock.expect(operationInstance.getConfiguration(AnalyzeTracksWorkflowOperationHandler.OPT_FAIL_NO_TRACK)).andReturn("true");
EasyMock.expect(operationInstance.getConfiguration(AnalyzeTracksWorkflowOperationHandler.OPT_FAIL_NO_TRACK)).andReturn("false").anyTimes();
EasyMock.replay(operationInstance);
WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflowInstance.getId()).andReturn(0L).anyTimes();
EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
EasyMock.replay(workflowInstance);
// With no matching track (should fail)
try {
operationHandler.start(workflowInstance, jobContext);
fail();
} catch (WorkflowOperationException e) {
logger.info("Fail on no tracks works");
}
WorkflowOperationResult workflowOperationResult = operationHandler.start(workflowInstance, jobContext);
Map<String, String> properties = workflowOperationResult.getProperties();
assertTrue(properties.isEmpty());
// With matching track
mediaPackage.add(track);
workflowOperationResult = operationHandler.start(workflowInstance, jobContext);
properties = workflowOperationResult.getProperties();
String[][] props = { { "presenter_source_media", "true" }, { "presenter_source_audio", "false" }, { "presenter_source_aspect", "16/9" }, { "presenter_source_resolution_y", "720" }, { "presenter_source_resolution_x", "1280" }, { "presenter_source_aspect_snap", "16/9" }, { "presenter_source_video", "true" }, { "presenter_source_framerate", "30.0" } };
for (String[] prop : props) {
assertEquals(prop[1], properties.get(prop[0]));
}
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class CleanupWorkflowOperationHandlerTest method createWorkflowInstance.
private WorkflowInstance createWorkflowInstance(Map<String, String> configuration, MediaPackage mp) {
WorkflowOperationInstance wfOpInst = new WorkflowOperationInstanceImpl();
if (configuration != null) {
for (String confKey : configuration.keySet()) {
wfOpInst.setConfiguration(confKey, configuration.get(confKey));
}
}
wfOpInst.setId(1L);
wfOpInst.setState(WorkflowOperationInstance.OperationState.RUNNING);
WorkflowInstance wfInst = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(wfInst.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(wfInst.getCurrentOperation()).andReturn(wfOpInst).anyTimes();
EasyMock.expect(wfInst.getOperations()).andReturn(Arrays.asList(wfOpInst)).anyTimes();
EasyMock.replay(wfInst);
return wfInst;
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowRestService method getWorkflowsAsXml.
@GET
@Produces(MediaType.TEXT_XML)
@Path("instances.xml")
@RestQuery(name = "workflowsasxml", description = "List all workflow instances matching the query parameters", returnDescription = "An XML representation of the set of workflows matching these query parameters", restParameters = { @RestParameter(name = "state", isRequired = false, description = "Filter results by workflows' current state", type = STRING), @RestParameter(name = "q", isRequired = false, description = "Filter results by free text query", type = STRING), @RestParameter(name = "seriesId", isRequired = false, description = "Filter results by series identifier", type = STRING), @RestParameter(name = "seriesTitle", isRequired = false, description = "Filter results by series title", type = STRING), @RestParameter(name = "creator", isRequired = false, description = "Filter results by the mediapackage's creator", type = STRING), @RestParameter(name = "contributor", isRequired = false, description = "Filter results by the mediapackage's contributor", type = STRING), @RestParameter(name = "fromdate", isRequired = false, description = "Filter results by workflow start date.", type = STRING), @RestParameter(name = "todate", isRequired = false, description = "Filter results by workflow start date.", type = STRING), @RestParameter(name = "language", isRequired = false, description = "Filter results by mediapackage's language.", type = STRING), @RestParameter(name = "license", isRequired = false, description = "Filter results by mediapackage's license.", type = STRING), @RestParameter(name = "title", isRequired = false, description = "Filter results by mediapackage's title.", type = STRING), @RestParameter(name = "subject", isRequired = false, description = "Filter results by mediapackage's subject.", type = STRING), @RestParameter(name = "workflowdefinition", isRequired = false, description = "Filter results by workflow definition.", type = STRING), @RestParameter(name = "mp", isRequired = false, description = "Filter results by mediapackage identifier.", type = STRING), @RestParameter(name = "op", isRequired = false, description = "Filter results by workflows' current operation.", type = STRING), @RestParameter(name = "sort", isRequired = false, description = "The sort order. May include any " + "of the following: DATE_CREATED, TITLE, SERIES_TITLE, SERIES_ID, MEDIA_PACKAGE_ID, WORKFLOW_DEFINITION_ID, CREATOR, " + "CONTRIBUTOR, LANGUAGE, LICENSE, SUBJECT. Add '_DESC' to reverse the sort order (e.g. TITLE_DESC).", type = STRING), @RestParameter(name = "startPage", isRequired = false, description = "The paging offset", type = INTEGER), @RestParameter(name = "count", isRequired = false, description = "The number of results to return.", type = INTEGER), @RestParameter(name = "compact", isRequired = false, description = "Whether to return a compact version of " + "the workflow instance, with mediapackage elements, workflow and workflow operation configurations and " + "non-current operations removed.", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the workflow set.") })
public // So for now, we disable checkstyle here.
Response getWorkflowsAsXml(@QueryParam("state") List<String> states, @QueryParam("q") String text, @QueryParam("seriesId") String seriesId, @QueryParam("seriesTitle") String seriesTitle, @QueryParam("creator") String creator, @QueryParam("contributor") String contributor, @QueryParam("fromdate") String fromDate, @QueryParam("todate") String toDate, @QueryParam("language") String language, @QueryParam("license") String license, @QueryParam("title") String title, @QueryParam("subject") String subject, @QueryParam("workflowdefinition") String workflowDefinitionId, @QueryParam("mp") String mediapackageId, @QueryParam("op") List<String> currentOperations, @QueryParam("sort") String sort, @QueryParam("startPage") int startPage, @QueryParam("count") int count, @QueryParam("compact") boolean compact) throws Exception {
// CHECKSTYLE:ON
if (count < 1)
count = DEFAULT_LIMIT;
WorkflowQuery q = new WorkflowQuery();
q.withCount(count);
q.withStartPage(startPage);
if (states != null && states.size() > 0) {
try {
for (String state : states) {
if (StringUtils.isBlank(state)) {
continue;
}
if (state.startsWith(NEGATE_PREFIX)) {
q.withoutState(WorkflowState.valueOf(state.substring(1).toUpperCase()));
} else {
q.withState(WorkflowState.valueOf(state.toUpperCase()));
}
}
} catch (IllegalArgumentException e) {
logger.debug("Unknown workflow state.", e);
}
}
q.withText(text);
q.withSeriesId(seriesId);
q.withSeriesTitle(seriesTitle);
q.withSubject(subject);
q.withMediaPackage(mediapackageId);
q.withCreator(creator);
q.withContributor(contributor);
q.withDateAfter(SolrUtils.parseDate(fromDate));
q.withDateBefore(SolrUtils.parseDate(toDate));
q.withLanguage(language);
q.withLicense(license);
q.withTitle(title);
q.withWorkflowDefintion(workflowDefinitionId);
if (currentOperations != null && currentOperations.size() > 0) {
for (String op : currentOperations) {
if (StringUtils.isBlank(op)) {
continue;
}
if (op.startsWith(NEGATE_PREFIX)) {
q.withoutCurrentOperation(op.substring(1));
} else {
q.withCurrentOperation(op);
}
}
}
if (StringUtils.isNotBlank(sort)) {
// Parse the sort field and direction
Sort sortField = null;
if (sort.endsWith(DESCENDING_SUFFIX)) {
String enumKey = sort.substring(0, sort.length() - DESCENDING_SUFFIX.length()).toUpperCase();
try {
sortField = Sort.valueOf(enumKey);
q.withSort(sortField, false);
} catch (IllegalArgumentException e) {
logger.debug("No sort enum matches '{}'", enumKey);
}
} else {
try {
sortField = Sort.valueOf(sort);
q.withSort(sortField);
} catch (IllegalArgumentException e) {
logger.debug("No sort enum matches '{}'", sort);
}
}
}
WorkflowSet set = service.getWorkflowInstances(q);
// Marshalling of a full workflow takes a long time. Therefore, we strip everything that's not needed.
if (compact) {
for (WorkflowInstance instance : set.getItems()) {
// Remove all operations but the current one
WorkflowOperationInstance currentOperation = instance.getCurrentOperation();
List<WorkflowOperationInstance> operations = instance.getOperations();
// instance.getOperations() is a copy
operations.clear();
if (currentOperation != null) {
for (String key : currentOperation.getConfigurationKeys()) {
currentOperation.removeConfiguration(key);
}
operations.add(currentOperation);
}
instance.setOperations(operations);
// Remove all mediapackage elements (but keep the duration)
MediaPackage mediaPackage = instance.getMediaPackage();
Long duration = instance.getMediaPackage().getDuration();
for (MediaPackageElement element : mediaPackage.elements()) {
mediaPackage.remove(element);
}
mediaPackage.setDuration(duration);
}
}
return Response.ok(set).build();
}
use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.
the class WorkflowOperationSkippingTest method testUnless.
@Test
@Ignore
public // Unless attribute is currently not being evaluated
void testUnless() throws Exception {
Map<String, String> properties1 = new HashMap<String, String>();
properties1.put("skipcondition", "true");
Map<String, String> properties2 = new HashMap<String, String>();
properties2.put("skipcondition", "false");
WorkflowInstance instance = startAndWait(workingDefinition, mediapackage1, properties1, WorkflowState.SUCCEEDED);
WorkflowInstance instance2 = startAndWait(workingDefinition, mediapackage1, properties2, WorkflowState.SUCCEEDED);
WorkflowInstance instance3 = startAndWait(workingDefinition, mediapackage1, null, WorkflowState.SUCCEEDED);
// See if the skip operation has been executed
WorkflowInstance instanceFromDb = service.getWorkflowById(instance.getId());
assertNotNull(instanceFromDb);
assertEquals(OperationState.SKIPPED, instanceFromDb.getOperations().get(1).getState());
// See if the skip operation has been skipped (skip value != "true")
WorkflowInstance instance2FromDb = service.getWorkflowById(instance2.getId());
assertNotNull(instance2FromDb);
assertEquals(OperationState.SKIPPED, instance2FromDb.getOperations().get(1).getState());
// See if the skip operation has been skipped (skip property is undefined)
WorkflowInstance instance3FromDb = service.getWorkflowById(instance3.getId());
assertNotNull(instance3FromDb);
assertEquals(OperationState.SUCCEEDED, instance3FromDb.getOperations().get(1).getState());
}
Aggregations