Search in sources :

Example 6 with WorkflowDefinitionImpl

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

the class WorkflowServiceImplTest method testRetryStrategyNone.

@Test
public void testRetryStrategyNone() 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("failOneTime", "fails once", null, true);
    def.add(opDef);
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    WorkflowInstance workflow = startAndWait(def, mp, WorkflowState.FAILED);
    Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getState() == OperationState.FAILED);
    Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getMaxAttempts() == 1);
    Assert.assertTrue(service.getWorkflowById(workflow.getId()).getOperations().get(0).getFailedAttempts() == 1);
}
Also used : WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 7 with WorkflowDefinitionImpl

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

the class WorkflowServiceImplTest method testRetryStrategyRetry.

@Test
public void testRetryStrategyRetry() 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("failOneTime", "fails once", 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);
}
Also used : WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 8 with WorkflowDefinitionImpl

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

the class WorkflowServiceImplTest method testRetryStrategyHoldMaxAttemptsThree.

@Test
public void testRetryStrategyHoldMaxAttemptsThree() 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("failTwice", "fails twice", null, true);
    opDef.setRetryStrategy(RetryStrategy.HOLD);
    opDef.setMaxAttempts(3);
    def.add(opDef);
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    WorkflowInstance workflow = startAndWait(def, mp, WorkflowState.PAUSED);
    WorkflowOperationInstance errorResolutionOperation = service.getWorkflowById(workflow.getId()).getOperations().get(0);
    WorkflowOperationInstance failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(1);
    Assert.assertTrue(errorResolutionOperation.getTemplate().equals(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID));
    Assert.assertTrue(errorResolutionOperation.getState() == OperationState.PAUSED);
    Assert.assertTrue(errorResolutionOperation.getFailedAttempts() == 0);
    Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
    Assert.assertTrue(failTwiceOperation.getState() == OperationState.RETRY);
    Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
    Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 1);
    // Try operation a second time, simulate user selecting RETRY
    retryAndWait(service.getWorkflowById(workflow.getId()), "RETRY", WorkflowState.PAUSED);
    errorResolutionOperation = service.getWorkflowById(workflow.getId()).getOperations().get(1);
    failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(2);
    Assert.assertTrue(errorResolutionOperation.getTemplate().equals(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID));
    Assert.assertTrue(errorResolutionOperation.getState() == OperationState.PAUSED);
    Assert.assertTrue(errorResolutionOperation.getFailedAttempts() == 0);
    Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
    Assert.assertTrue(failTwiceOperation.getState() == OperationState.RETRY);
    Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
    Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 2);
    // Try operation a third time, it should succeed, simulate user selecting RETRY
    retryAndWait(service.getWorkflowById(workflow.getId()), "RETRY", WorkflowState.SUCCEEDED);
    failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(2);
    Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
    Assert.assertTrue(failTwiceOperation.getState() == OperationState.SUCCEEDED);
    Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
    Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 2);
}
Also used : WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 9 with WorkflowDefinitionImpl

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

the class WorkflowStatisticsTest method setUp.

@Before
public void setUp() throws Exception {
    // always start with a fresh solr root directory
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    workflowDefinitions = new ArrayList<WorkflowDefinition>();
    workflowHandlers = new HashSet<HandlerRegistration>();
    String opId = "op";
    WorkflowOperationDefinition op = new WorkflowOperationDefinitionImpl(opId, "Pausing operation", null, true);
    WorkflowOperationHandler opHandler = new ResumableTestWorkflowOperationHandler(opId, Action.PAUSE, Action.CONTINUE);
    HandlerRegistration handler = new HandlerRegistration(opId, opHandler);
    workflowHandlers.add(handler);
    // create operation handlers for our workflows
    for (int i = 1; i <= WORKFLOW_DEFINITION_COUNT; i++) {
        WorkflowDefinition workflowDef = new WorkflowDefinitionImpl();
        workflowDef.setId("def-" + i);
        for (int opCount = 1; opCount <= OPERATION_COUNT; opCount++) {
            workflowDef.add(op);
        }
        workflowDefinitions.add(workflowDef);
    }
    // instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
    service = new WorkflowServiceImpl() {

        @Override
        public Set<HandlerRegistration> getRegisteredHandlers() {
            return workflowHandlers;
        }
    };
    scanner = new WorkflowDefinitionScanner();
    service.addWorkflowDefinitionScanner(scanner);
    // security service
    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);
    service.setSecurityService(securityService);
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.replay(authzService);
    service.setAuthorizationService(authzService);
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(organization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    service.setMessageSender(messageSender);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    // Register the workflow definitions
    for (WorkflowDefinition workflowDefinition : workflowDefinitions) {
        service.registerWorkflowDefinition(workflowDefinition);
    }
    // Mock the workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    // Mock the service registry
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    // Create the workflow database (solr)
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
    dao.setSecurityService(securityService);
    dao.setServiceRegistry(serviceRegistry);
    dao.setAuthorizationService(authzService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setServiceRegistry(serviceRegistry);
    service.setSecurityService(securityService);
    service.activate(null);
    // Crate a media package
    InputStream is = null;
    try {
        MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
        mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
        is = WorkflowStatisticsTest.class.getResourceAsStream("/mediapackage-1.xml");
        mediaPackage = mediaPackageBuilder.loadFromXml(is);
        IOUtils.closeQuietly(is);
        Assert.assertNotNull(mediaPackage.getIdentifier());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    // Register the workflow service with the service registry
    serviceRegistry.registerService(service);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) Set(java.util.Set) HashSet(java.util.HashSet) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) WorkflowOperationHandler(org.opencastproject.workflow.api.WorkflowOperationHandler) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) InputStream(java.io.InputStream) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowOperationDefinition(org.opencastproject.workflow.api.WorkflowOperationDefinition) IOException(java.io.IOException) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 10 with WorkflowDefinitionImpl

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

the class WorkflowServiceImplAuthzTest method testWorkflowWithoutSecurityPolicy.

@Test
public void testWorkflowWithoutSecurityPolicy() throws Exception {
    // Mock up an authorization service that always returns "false" for hasPermission()
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(new AccessControlList(), AclScope.Series)).anyTimes();
    EasyMock.expect(authzService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(false).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
    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 can not see the workflow, since there is no security policy granting access
    userResponder.setResponse(instructor2);
    try {
        service.getWorkflowById(workflow.getId());
        fail();
    } catch (UnauthorizedException e) {
    // expected
    }
    assertEquals(0, service.countWorkflowInstances());
    // Ensure the instructor from a different org can not see the workflow, even though they share a 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) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Test(org.junit.Test)

Aggregations

WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)18 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)12 Test (org.junit.Test)11 MediaPackage (org.opencastproject.mediapackage.MediaPackage)10 WorkflowOperationDefinitionImpl (org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)7 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)7 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)7 URI (java.net.URI)5 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)5 HashMap (java.util.HashMap)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Set (java.util.Set)3 AuthorizationService (org.opencastproject.security.api.AuthorizationService)3 WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)3 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Date (java.util.Date)2