use of org.opencastproject.workflow.api.WorkflowInstanceImpl in project opencast by opencast.
the class CloneWorkflowOperationHandlerTest 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("clone");
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.WorkflowInstanceImpl in project opencast by opencast.
the class WorkflowServiceSolrIndexTest method setUp.
@Before
public void setUp() throws Exception {
// security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(securityService);
OrganizationDirectoryService orgDirectroy = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectroy.getOrganization((String) EasyMock.anyObject())).andReturn(securityService.getOrganization()).anyTimes();
EasyMock.replay(orgDirectroy);
// Create a job with a workflow as its payload
List<Job> jobs = new ArrayList<>();
Job job = new JobImpl();
WorkflowInstanceImpl workflow = new WorkflowInstanceImpl();
workflow.setId(123);
workflow.setCreator(securityService.getUser());
workflow.setOrganization(securityService.getOrganization());
workflow.setState(WorkflowState.INSTANTIATED);
workflow.setMediaPackage(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
String jobPayload = WorkflowParser.toXml(workflow);
job.setPayload(jobPayload);
job.setOrganization(securityService.getOrganization().getId());
jobs.add(job);
// Mock up the service registry to return the job
ServiceRegistry serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.count(WorkflowService.JOB_TYPE, null)).andReturn(1L);
EasyMock.expect(serviceRegistry.getJobs(WorkflowService.JOB_TYPE, null)).andReturn(jobs);
EasyMock.expect(serviceRegistry.getJob(123)).andReturn(job);
EasyMock.expect(serviceRegistry.getJobPayloads("START_WORKFLOW")).andReturn(Collections.singletonList(jobPayload));
EasyMock.replay(serviceRegistry);
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
EasyMock.replay(messageSender);
// Now create the dao
dao = new WorkflowServiceSolrIndex();
dao.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
dao.setServiceRegistry(serviceRegistry);
dao.setSecurityService(securityService);
dao.setOrgDirectory(orgDirectroy);
dao.activate("System Admin");
}
use of org.opencastproject.workflow.api.WorkflowInstanceImpl in project opencast by opencast.
the class WorkflowServiceImpl method suspend.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#suspend(long)
*/
@Override
public WorkflowInstance suspend(long workflowInstanceId) throws WorkflowException, NotFoundException, UnauthorizedException {
final Lock lock = this.lock.get(workflowInstanceId);
lock.lock();
try {
WorkflowInstanceImpl instance = getWorkflowById(workflowInstanceId);
instance.setState(PAUSED);
update(instance);
return instance;
} finally {
lock.unlock();
}
}
use of org.opencastproject.workflow.api.WorkflowInstanceImpl in project opencast by opencast.
the class WorkflowServiceImpl method stop.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#stop(long)
*/
@Override
public WorkflowInstance stop(long workflowInstanceId) throws WorkflowException, NotFoundException, UnauthorizedException {
final Lock lock = this.lock.get(workflowInstanceId);
lock.lock();
try {
WorkflowInstanceImpl instance = getWorkflowById(workflowInstanceId);
if (instance.getState() != STOPPED) {
// Update the workflow instance
instance.setState(STOPPED);
update(instance);
}
try {
removeTempFiles(instance);
} catch (Exception e) {
logger.warn("Cannot remove temp files for workflow instance {}: {}", workflowInstanceId, e.getMessage());
}
return instance;
} finally {
lock.unlock();
}
}
use of org.opencastproject.workflow.api.WorkflowInstanceImpl in project opencast by opencast.
the class IngestServiceImplTest method testLegacyMediaPackageId.
@Test
public void testLegacyMediaPackageId() throws Exception {
SchedulerService schedulerService = EasyMock.createNiceMock(SchedulerService.class);
Map<String, String> properties = new HashMap<>();
properties.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, "sample");
properties.put("agent-name", "matterhorn-agent");
EasyMock.expect(schedulerService.getCaptureAgentConfiguration(EasyMock.anyString())).andReturn(properties).anyTimes();
EasyMock.expect(schedulerService.getDublinCore(EasyMock.anyString())).andReturn(DublinCores.read(urlCatalog1.toURL().openStream())).anyTimes();
MediaPackage schedulerMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/source-manifest.xml"), "UTF-8"));
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andThrow(new NotFoundException()).once();
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(schedulerMediaPackage).once();
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andThrow(new NotFoundException()).anyTimes();
EasyMock.replay(schedulerService);
service.setSchedulerService(schedulerService);
final Capture<Map<String, String>> captureConfig = EasyMock.newCapture();
WorkflowService workflowService = EasyMock.createNiceMock(WorkflowService.class);
EasyMock.expect(workflowService.start(EasyMock.anyObject(WorkflowDefinition.class), EasyMock.anyObject(MediaPackage.class), EasyMock.capture(captureConfig))).andReturn(new WorkflowInstanceImpl()).once();
EasyMock.replay(workflowService);
service.setWorkflowService(workflowService);
MediaPackage ingestMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/target-manifest.xml"), "UTF-8"));
Map<String, String> wfConfig = new HashMap<>();
wfConfig.put(IngestServiceImpl.LEGACY_MEDIAPACKAGE_ID_KEY, "6f7a7850-3232-4719-9064-24c9bad2832f");
service.ingest(ingestMediaPackage, null, wfConfig);
Assert.assertFalse(captureConfig.getValue().containsKey(IngestServiceImpl.LEGACY_MEDIAPACKAGE_ID_KEY));
}
Aggregations