Search in sources :

Example 91 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class WorkflowsStatistics method updateWorkflow.

public void updateWorkflow(WorkflowStatistics workflowStatistics, List<WorkflowInstance> workflows) {
    this.workflowStatistics = workflowStatistics;
    for (WorkflowInstance wf : workflows) {
        Long count = workflowCounts.get(wf.getTemplate());
        if (count == null) {
            workflowCounts.put(wf.getTemplate(), 1L);
        } else {
            workflowCounts.put(wf.getTemplate(), count++);
        }
    }
    sendNotification(JmxUtil.createUpdateNotification(this, sequenceNumber++, "Workflow updated"));
}
Also used : WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Example 92 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class CountWorkflowsTest method testHoldAndResume.

@Test
public void testHoldAndResume() throws Exception {
    // Wait for all workflows to be in paused state
    WorkflowStateListener listener = new WorkflowStateListener(WorkflowState.PAUSED);
    service.addWorkflowListener(listener);
    Map<String, String> initialProps = new HashMap<String, String>();
    initialProps.put("testproperty", "foo");
    WorkflowInstance workflow1 = null;
    synchronized (listener) {
        workflow1 = service.start(def, mp, initialProps);
        listener.wait();
        mp.setIdentifier(new UUIDIdBuilderImpl().createNew());
        service.start(def, mp, initialProps);
        listener.wait();
    }
    service.removeWorkflowListener(listener);
    // Test for two paused workflows in "op1"
    assertEquals(2, service.countWorkflowInstances());
    assertEquals(2, service.countWorkflowInstances(WorkflowState.PAUSED, null));
    assertEquals(2, service.countWorkflowInstances(null, "op1"));
    assertEquals(2, service.countWorkflowInstances(WorkflowState.PAUSED, "op1"));
    assertEquals(0, service.countWorkflowInstances(WorkflowState.SUCCEEDED, null));
    assertEquals(0, service.countWorkflowInstances(null, "op2"));
    assertEquals(0, service.countWorkflowInstances(WorkflowState.SUCCEEDED, "op1"));
    // Continue one of the two workflows, waiting for success
    listener = new WorkflowStateListener(WorkflowState.SUCCEEDED);
    service.addWorkflowListener(listener);
    synchronized (listener) {
        service.resume(workflow1.getId());
        listener.wait();
    }
    service.removeWorkflowListener(listener);
    // Make sure one workflow is still on hold, the other is finished.
    assertEquals(2, service.countWorkflowInstances());
    assertEquals(1, service.countWorkflowInstances(WorkflowState.PAUSED, null));
    assertEquals(1, service.countWorkflowInstances(WorkflowState.PAUSED, "op1"));
    assertEquals(1, service.countWorkflowInstances(WorkflowState.SUCCEEDED, null));
}
Also used : WorkflowStateListener(org.opencastproject.workflow.api.WorkflowStateListener) HashMap(java.util.HashMap) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) UUIDIdBuilderImpl(org.opencastproject.mediapackage.identifier.UUIDIdBuilderImpl) Test(org.junit.Test)

Example 93 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class WorkflowOperationSkippingTest method startAndWait.

protected WorkflowInstance startAndWait(WorkflowDefinition definition, MediaPackage mp, Map<String, String> properties, WorkflowState stateToWaitFor) throws Exception {
    WorkflowStateListener stateListener = new WorkflowStateListener(stateToWaitFor);
    service.addWorkflowListener(stateListener);
    WorkflowInstance instance = null;
    synchronized (stateListener) {
        instance = service.start(definition, mp, properties);
        stateListener.wait();
    }
    service.removeWorkflowListener(stateListener);
    return instance;
}
Also used : WorkflowStateListener(org.opencastproject.workflow.api.WorkflowStateListener) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Example 94 with WorkflowInstance

use of org.opencastproject.workflow.api.WorkflowInstance in project opencast by opencast.

the class WorkflowServiceImplAuthzTest method testWorkflowWithSecurityPolicy.

@Test
public void testWorkflowWithSecurityPolicy() throws Exception {
    // Create an ACL for the authorization service to return
    AccessControlList acl = new AccessControlList();
    acl.getEntries().add(new AccessControlEntry("ROLE_INSTRUCTOR", Permissions.Action.READ.toString(), true));
    acl.getEntries().add(new AccessControlEntry("ROLE_INSTRUCTOR", Permissions.Action.WRITE.toString(), true));
    // Mock up an authorization service that always returns "true" for hasPermission()
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.expect(authzService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
    EasyMock.replay(authzService);
    service.setAuthorizationService(authzService);
    dao.setAuthorizationService(authzService);
    // Create the workflow and its dependent object graph
    WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
    def.add(new WorkflowOperationDefinitionImpl("op1", "op1", null, true));
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    // As an instructor, create a workflow. We don't care if it passes or fails. We just care about access to it.
    userResponder.setResponse(instructor1);
    WorkflowInstance workflow = service.start(def, mp);
    service.suspend(workflow.getId());
    // Ensure that this instructor can access the workflow
    try {
        service.getWorkflowById(workflow.getId());
        assertEquals(1, service.countWorkflowInstances());
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // Ensure the organization admin can access that workflow
    userResponder.setResponse(DEFAULT_ORG_ADMIN);
    try {
        service.getWorkflowById(workflow.getId());
        assertEquals(1, service.countWorkflowInstances());
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // Ensure the global admin can access that workflow
    userResponder.setResponse(globalAdmin);
    try {
        service.getWorkflowById(workflow.getId());
        assertEquals(1, service.countWorkflowInstances());
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // Ensure the other instructor from this organization can also see the workflow, since this is specified in the
    // security policy
    userResponder.setResponse(instructor2);
    try {
        service.getWorkflowById(workflow.getId());
        assertEquals(1, service.countWorkflowInstances());
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // TODO change to answer show in episode or series how to do it. Cool stuff
    // Ensure the instructor from a different org can not see the workflow, even though they share the same role
    organizationResponder.setResponse(otherOrganization);
    userResponder.setResponse(instructorFromDifferentOrg);
    try {
        service.getWorkflowById(workflow.getId());
        fail();
    } catch (Exception e) {
    // expected
    }
    assertEquals(0, service.countWorkflowInstances());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Test(org.junit.Test)

Aggregations

WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)94 Test (org.junit.Test)48 MediaPackage (org.opencastproject.mediapackage.MediaPackage)40 NotFoundException (org.opencastproject.util.NotFoundException)26 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)24 HashMap (java.util.HashMap)22 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)20 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)19 ArrayList (java.util.ArrayList)16 WorkflowQuery (org.opencastproject.workflow.api.WorkflowQuery)16 IOException (java.io.IOException)15 Organization (org.opencastproject.security.api.Organization)15 WorkflowSet (org.opencastproject.workflow.api.WorkflowSet)14 WorkflowException (org.opencastproject.workflow.api.WorkflowException)13 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)12 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)12 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)11 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)10 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)9 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)9