use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class EmailDataTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = EmailDataTest.class.getResource("/email_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
URI episodeURI = EmailDataTest.class.getResource("/episode_dublincore.xml").toURI();
URI seriesURI = EmailDataTest.class.getResource("/series_dublincore.xml").toURI();
DublinCoreCatalog episodeDc = DublinCores.read(episodeURI.toURL().openStream());
catalogs.put("episode", buildCatalogHash(episodeDc));
DublinCoreCatalog seriesDc = DublinCores.read(seriesURI.toURL().openStream());
catalogs.put("series", buildCatalogHash(seriesDc));
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("wfdef");
Map<String, String> props = new HashMap<String, String>();
props.put("emailAddress", "user@domain.com");
// Create some incidents
incident1 = EasyMock.createNiceMock(Incident.class);
List<Tuple<String, String>> details = new LinkedList<Tuple<String, String>>();
Tuple<String, String> detail = new Tuple<String, String>("detail-type", "error in operation1");
details.add(detail);
EasyMock.expect(incident1.getDetails()).andReturn(details);
incident2 = EasyMock.createNiceMock(Incident.class);
details = new LinkedList<Tuple<String, String>>();
detail = new Tuple<String, String>("detail-type", "error in operation2");
details.add(detail);
EasyMock.expect(incident2.getDetails()).andReturn(details);
// Link the incident and the subtree
incidents = new LinkedList<Incident>();
incidents.add(incident1);
incidents.add(incident2);
workflowInstance = new WorkflowInstanceImpl(def, null, null, null, null, props);
workflowInstance.setId(1);
workflowInstance.setState(WorkflowState.RUNNING);
workflowInstance.setMediaPackage(mp);
failedOperation = new WorkflowOperationInstanceImpl("operation1", OperationState.FAILED);
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("email", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(failedOperation);
operationList.add(operation);
workflowInstance.setOperations(operationList);
EasyMock.replay(incident1, incident2);
}
use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class EmailTemplateServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = EmailTemplateServiceImplTest.class.getResource("/email_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
service = new EmailTemplateServiceImpl();
URI episodeURI = EmailTemplateServiceImplTest.class.getResource("/episode_dublincore.xml").toURI();
URI seriesURI = EmailTemplateServiceImplTest.class.getResource("/series_dublincore.xml").toURI();
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.get(new URI("episode_dublincore.xml"))).andReturn(new File(episodeURI));
EasyMock.expect(workspace.get(new URI("series_dublincore.xml"))).andReturn(new File(seriesURI));
EasyMock.replay(workspace);
service.setWorkspace(workspace);
EmailTemplateScanner templateScanner = EasyMock.createMock(EmailTemplateScanner.class);
EasyMock.expect(templateScanner.getTemplate("templateBasic")).andReturn("Media package id: ${mediaPackage.identifier}, workflow id: ${workflow.id}, " + "title: ${mediaPackage.title}, series title: ${mediaPackage.seriesTitle}, " + "date: ${mediaPackage.date?datetime?iso_utc}");
EasyMock.expect(templateScanner.getTemplate("templateCatalog")).andReturn("EPISODE creator: ${catalogs[\"episode\"][\"creator\"]}, isPartOf: ${catalogs[\"episode\"][\"isPartOf\"]}, " + "title: ${catalogs[\"episode\"][\"title\"]}, created: ${catalogs[\"episode\"][\"created\"]}, " + "SERIES creator: ${catalogs[\"series\"][\"creator\"]}, description: ${catalogs[\"series\"][\"description\"]}, " + "subject: ${catalogs[\"series\"][\"subject\"]}");
EasyMock.expect(templateScanner.getTemplate("templateFailed")).andReturn("<#if failedOperation?has_content>Workflow failed in operation: ${failedOperation.template}</#if>, " + "Workflow errors: <#list incident as inc><#list inc.details as de>${de.b} </#list></#list>");
EasyMock.expect(templateScanner.getTemplate("templateSyntaxError")).andReturn("${mediaPackage");
EasyMock.replay(templateScanner);
service.setEmailTemplateScanner(templateScanner);
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("wfdef");
Map<String, String> props = new HashMap<String, String>();
props.put("emailAddress", "user@domain.com");
IncidentService is = EasyMock.createMock(IncidentService.class);
/*
* This is what we're building. EasyMock makes it ugly, of course /-------job1Tree / | / incident2 subtree |
* incident1
*/
// Create the tree and subtree
IncidentTree subtree = EasyMock.createNiceMock(IncidentTree.class);
IncidentTree job1Tree = EasyMock.createNiceMock(IncidentTree.class);
// Create the incidents
Incident incident1 = EasyMock.createNiceMock(Incident.class);
List<Tuple<String, String>> details = new LinkedList<Tuple<String, String>>();
Tuple<String, String> detail = new Tuple<String, String>("detail-type", "error in operation1");
details.add(detail);
EasyMock.expect(incident1.getDetails()).andReturn(details);
Incident incident2 = EasyMock.createNiceMock(Incident.class);
details = new LinkedList<Tuple<String, String>>();
detail = new Tuple<String, String>("detail-type", "error in operation2");
details.add(detail);
EasyMock.expect(incident2.getDetails()).andReturn(details);
// Link the incident and the subtree
LinkedList<Incident> incidents = new LinkedList<Incident>();
incidents.add(incident1);
EasyMock.expect(subtree.getIncidents()).andReturn(incidents).anyTimes();
// This is what Entwine wrote in the IncidentTree class, so rather than null we're using Immutables.nil()
List<IncidentTree> subtreeDecendants = Immutables.nil();
EasyMock.expect(subtree.getDescendants()).andReturn(subtreeDecendants).anyTimes();
// Link the incident and the parent tree
incidents = new LinkedList<Incident>();
incidents.add(incident2);
EasyMock.expect(job1Tree.getIncidents()).andReturn(incidents).anyTimes();
// Link the subtree and parent tree
LinkedList<IncidentTree> subtreeList = new LinkedList<IncidentTree>();
subtreeList.add(subtree);
EasyMock.expect(job1Tree.getDescendants()).andReturn(subtreeList).anyTimes();
service.setIncidentService(is);
workflowInstance = new WorkflowInstanceImpl(def, null, null, null, null, props);
workflowInstance.setId(1);
workflowInstance.setState(WorkflowState.RUNNING);
workflowInstance.setMediaPackage(mp);
WorkflowOperationInstanceImpl failedOperation1 = new WorkflowOperationInstanceImpl("operation1", OperationState.FAILED);
failedOperation1.setFailWorkflowOnException(true);
failedOperation1.setId(1L);
EasyMock.expect(is.getIncidentsOfJob(1L, true)).andReturn(subtree).anyTimes();
WorkflowOperationInstanceImpl failedOperation2 = new WorkflowOperationInstanceImpl("operation2", OperationState.FAILED);
failedOperation2.setFailWorkflowOnException(false);
failedOperation1.setId(2L);
EasyMock.expect(is.getIncidentsOfJob(2L, true)).andReturn(job1Tree).anyTimes();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("email", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(failedOperation1);
operationList.add(failedOperation2);
operationList.add(operation);
workflowInstance.setOperations(operationList);
EasyMock.replay(is, subtree, job1Tree, incident1, incident2);
}
use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunProgressState.
@Test
public void testWorkflowDispatcherRunProgressState() throws Exception {
InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PULLED_TRANSCRIPTION_FILE);
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), 0);
database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
EasyMock.expect(workspace.putInCollection(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://anything"));
EasyMock.replay(workspace);
HttpEntity httpEntity = EasyMock.createNiceMock(HttpEntity.class);
EasyMock.expect(httpEntity.getContent()).andReturn(stream);
CloseableHttpResponse response = EasyMock.createNiceMock(CloseableHttpResponse.class);
StatusLine status = EasyMock.createNiceMock(StatusLine.class);
EasyMock.expect(response.getStatusLine()).andReturn(status).anyTimes();
EasyMock.expect(response.getEntity()).andReturn(httpEntity).anyTimes();
EasyMock.expect(status.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
EasyMock.replay(httpEntity, response, status);
Capture<HttpGet> capturedGet = Capture.newInstance();
EasyMock.expect(httpClient.execute(EasyMock.capture(capturedGet))).andReturn(response);
EasyMock.replay(httpClient);
// enrich(q.select(q.snapshot()).where(q.mediaPackageId(mpId).and(q.version().isLatest())).run()).getSnapshots();
// Mocks for query, result, etc
Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId());
ARecord aRec = EasyMock.createNiceMock(ARecord.class);
EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot));
Stream<ARecord> recStream = Stream.mk(aRec);
Predicate p = EasyMock.createNiceMock(Predicate.class);
EasyMock.expect(p.and(p)).andReturn(p);
AResult r = EasyMock.createNiceMock(AResult.class);
EasyMock.expect(r.getSize()).andReturn(1L);
EasyMock.expect(r.getRecords()).andReturn(recStream);
Target t = EasyMock.createNiceMock(Target.class);
ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery);
EasyMock.expect(selectQuery.run()).andReturn(r);
AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
EasyMock.expect(query.snapshot()).andReturn(t);
EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p);
EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery);
VersionField v = EasyMock.createNiceMock(VersionField.class);
EasyMock.expect(v.isLatest()).andReturn(p);
EasyMock.expect(query.version()).andReturn(v);
EasyMock.expect(assetManager.createQuery()).andReturn(query);
EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v, assetManager);
Capture<Set<String>> capturedMpIds = Capture.newInstance();
WorkflowDefinition wfDef = new WorkflowDefinitionImpl();
EasyMock.expect(wfService.getWorkflowDefinitionById(IBMWatsonTranscriptionService.DEFAULT_WF_DEF)).andReturn(wfDef);
List<WorkflowInstance> wfList = new ArrayList<WorkflowInstance>();
wfList.add(new WorkflowInstanceImpl());
Stream<WorkflowInstance> wfListStream = Stream.mk(wfList);
Workflows wfs = EasyMock.createNiceMock(Workflows.class);
EasyMock.expect(wfs.applyWorkflowToLatestVersion(EasyMock.capture(capturedMpIds), EasyMock.anyObject(ConfiguredWorkflow.class))).andReturn(wfListStream);
service.setWfUtil(wfs);
EasyMock.replay(wfService, wfs);
WorkflowDispatcher dispatcher = service.new WorkflowDispatcher();
dispatcher.run();
// Check if it called the external service to get the results
Assert.assertEquals("https://stream.watsonplatform.net/speech-to-text/api/v1/recognitions/" + JOB_ID, capturedGet.getValue().getURI().toString());
// Check if only one mp has a workflow created for it
Assert.assertEquals(1, capturedMpIds.getValue().size());
// And if it was the correct one
Assert.assertEquals(MP_ID, capturedMpIds.getValue().iterator().next());
// Check if status in db was updated
TranscriptionJobControl job = database.findByJob(JOB_ID);
Assert.assertNotNull(job);
Assert.assertEquals(TranscriptionJobControl.Status.Closed.name(), job.getStatus());
}
use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class AttachTranscriptionOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// Media package set up
URI mediaPackageURI = StartTranscriptionOperationHandlerTest.class.getResource("/mp.xml").toURI();
mediaPackage = builder.loadFromXml(mediaPackageURI.toURL().openStream());
URI dfxpURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_dfxp.xml").toURI();
String dfxpXml = FileUtils.readFileToString(new File(dfxpURI));
Attachment captionDfxp = (Attachment) MediaPackageElementParser.getFromXml(dfxpXml);
URI vttURI = StartTranscriptionOperationHandlerTest.class.getResource("/attachment_vtt.xml").toURI();
String vttXml = FileUtils.readFileToString(new File(vttURI));
Attachment captionVtt = (Attachment) MediaPackageElementParser.getFromXml(vttXml);
// Service registry set up
job1 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job1.getId()).andReturn(1L);
EasyMock.expect(job1.getPayload()).andReturn(dfxpXml).anyTimes();
EasyMock.expect(job1.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job1.getDateCreated()).andReturn(new Date());
EasyMock.expect(job1.getDateStarted()).andReturn(new Date());
EasyMock.expect(job1.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job1);
job2 = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job2.getId()).andReturn(2L);
EasyMock.expect(job2.getPayload()).andReturn(vttXml).anyTimes();
EasyMock.expect(job2.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job2.getDateCreated()).andReturn(new Date());
EasyMock.expect(job2.getDateStarted()).andReturn(new Date());
EasyMock.expect(job2.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job2);
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job1);
EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job2);
EasyMock.replay(serviceRegistry);
// Transcription service set up
service = EasyMock.createStrictMock(TranscriptionService.class);
EasyMock.expect(service.getGeneratedTranscription("mpId1", "transcriptionJob")).andReturn(captionDfxp);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.expect(service.getGeneratedTranscription("mpId2", "transcriptionJob")).andReturn(captionVtt);
EasyMock.expect(service.getLanguage()).andReturn("en").once();
EasyMock.replay(service);
// Caption service set up
captionService = EasyMock.createNiceMock(CaptionService.class);
// Workspace set up
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo(EasyMock.anyObject(URI.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(// just something valid
new URI("http://opencast.server.com/captions.xml"));
EasyMock.replay(workspace);
// Workflow set up
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("DCE-start-transcription");
def.setPublished(true);
workflowInstance = new WorkflowInstanceImpl(def, mediaPackage, null, null, null, null);
workflowInstance.setId(1);
operation = new WorkflowOperationInstanceImpl("attach-transcript", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(operation);
workflowInstance.setOperations(operationList);
// Operation handler set up
operationHandler = new AttachTranscriptionOperationHandler();
operationHandler.setTranscriptionService(service);
operationHandler.setServiceRegistry(serviceRegistry);
operationHandler.setCaptionService(captionService);
operationHandler.setWorkspace(workspace);
operationHandler.setJobBarrierPollingInterval(1L);
}
use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class WorkflowServiceImplTest method testRetryStrategyFailover.
@Test
@Ignore
public void testRetryStrategyFailover() throws Exception {
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("workflow-definition-1");
def.setTitle("workflow-definition-1");
def.setDescription("workflow-definition-1");
def.setPublished(true);
service.registerWorkflowDefinition(def);
WorkflowOperationDefinitionImpl opDef = new WorkflowOperationDefinitionImpl("failOnHost", "fails on host", null, true);
opDef.setRetryStrategy(RetryStrategy.RETRY);
def.add(opDef);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
WorkflowInstance workflow = startAndWait(def, mp, WorkflowState.SUCCEEDED);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getState() == OperationState.SUCCEEDED);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getMaxAttempts() == 2);
Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getFailedAttempts() == 1);
}
Aggregations