Search in sources :

Example 26 with WorkflowInstanceImpl

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);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Example 27 with WorkflowInstanceImpl

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");
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) JobImpl(org.opencastproject.job.api.JobImpl) SecurityService(org.opencastproject.security.api.SecurityService) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 28 with WorkflowInstanceImpl

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();
    }
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) Lock(java.util.concurrent.locks.Lock)

Example 29 with WorkflowInstanceImpl

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();
    }
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) UndispatchableJobException(org.opencastproject.serviceregistry.api.UndispatchableJobException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) Lock(java.util.concurrent.locks.Lock)

Example 30 with WorkflowInstanceImpl

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));
}
Also used : SchedulerService(org.opencastproject.scheduler.api.SchedulerService) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) HashMap(java.util.HashMap) WorkflowService(org.opencastproject.workflow.api.WorkflowService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)57 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)37 ArrayList (java.util.ArrayList)34 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)31 Test (org.junit.Test)27 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)17 MediaPackage (org.opencastproject.mediapackage.MediaPackage)12 Job (org.opencastproject.job.api.Job)9 Track (org.opencastproject.mediapackage.Track)9 URI (java.net.URI)8 Before (org.junit.Before)8 HashMap (java.util.HashMap)7 NotFoundException (org.opencastproject.util.NotFoundException)7 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)7 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)6 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)6 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)6 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)5 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)5 File (java.io.File)4