Search in sources :

Example 21 with WorkflowInstance

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

the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunTranscriptionCompletedState.

@Test
public void testWorkflowDispatcherRunTranscriptionCompletedState() throws Exception {
    database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
    database.updateJobControl(JOB_ID, TranscriptionJobControl.Status.TranscriptionComplete.name());
    // 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 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());
}
Also used : TranscriptionJobControl(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionJobControl) Set(java.util.Set) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) Workflows(org.opencastproject.assetmanager.util.Workflows) VersionField(org.opencastproject.assetmanager.api.query.VersionField) ArrayList(java.util.ArrayList) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowDispatcher(org.opencastproject.transcription.ibmwatson.IBMWatsonTranscriptionService.WorkflowDispatcher) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) ConfiguredWorkflow(org.opencastproject.workflow.api.ConfiguredWorkflow) Predicate(org.opencastproject.assetmanager.api.query.Predicate) Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecord(org.opencastproject.assetmanager.api.query.ARecord) Target(org.opencastproject.assetmanager.api.query.Target) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) AResult(org.opencastproject.assetmanager.api.query.AResult) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Test(org.junit.Test)

Example 22 with WorkflowInstance

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

the class CommentWorkflowOperationHandlerTest method testDifferentCaseAction.

@Test
public void testDifferentCaseAction() throws WorkflowOperationException, EventCommentException {
    // Testing that a duplicate comment won't be created but a different one will still be created.
    Long workflowId = 10L;
    String mediaPackageId = "abc-def";
    String reason = "Waiting for Trim";
    String description = "The comment description";
    Organization org = createNiceMock(Organization.class);
    expect(org.getId()).andStubReturn("demo");
    replay(org);
    SecurityService secSrv = createNiceMock(SecurityService.class);
    expect(secSrv.getOrganization()).andStubReturn(org);
    replay(secSrv);
    // Setup WorkflowOperation Instance
    WorkflowOperationInstance workflowOperationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
    // Standard
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("create");
    // Mixed case
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("CrEaTe");
    // All Caps
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("CREATE");
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.REASON)).andReturn(reason).anyTimes();
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.DESCRIPTION)).andReturn(description).anyTimes();
    // Setup mediaPackage
    MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediaPackage.getIdentifier()).andReturn(new IdImpl(mediaPackageId)).anyTimes();
    // Setup user
    User creator = EasyMock.createMock(User.class);
    // Setup WorkflowInstance
    WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getId()).andReturn(workflowId).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(workflowOperationInstance).anyTimes();
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCreator()).andReturn(creator).anyTimes();
    EasyMock.replay(creator, mediaPackage, workflowInstance, workflowOperationInstance);
    // Test no previous comments
    EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    Capture<EventComment> comment = EasyMock.newCapture();
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
    EasyMock.replay(eventCommentService);
    CommentWorkflowOperationHandler commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    comment = EasyMock.newCapture();
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), mediaPackageId, org.getId(), description, creator));
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    comment = EasyMock.newCapture();
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(19L), mediaPackageId, org.getId(), description, creator));
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
}
Also used : Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) EventComment(org.opencastproject.event.comment.EventComment) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) EventCommentService(org.opencastproject.event.comment.EventCommentService) Test(org.junit.Test)

Example 23 with WorkflowInstance

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

the class CommentWorkflowOperationHandlerTest method testPossibleActions.

@Test
public void testPossibleActions() throws WorkflowOperationException, EventCommentException, NotFoundException {
    // Testing that a duplicate comment won't be created but a different one will still be created.
    Long workflowId = 10L;
    Long deleteCommentId = 21L;
    String mediaPackageId = "abc-def";
    String reason = "Waiting for Trim";
    String description = "The comment description";
    Organization org = createNiceMock(Organization.class);
    expect(org.getId()).andStubReturn("demo");
    replay(org);
    SecurityService secSrv = createNiceMock(SecurityService.class);
    expect(secSrv.getOrganization()).andStubReturn(org);
    replay(secSrv);
    // Setup WorkflowOperation Instance
    WorkflowOperationInstance workflowOperationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
    // Create
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.create.toString());
    // Resolve
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.resolve.toString());
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.resolve.toString());
    // Deletes
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.REASON)).andReturn(reason).anyTimes();
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.DESCRIPTION)).andReturn(description).anyTimes();
    // Setup mediaPackage
    MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediaPackage.getIdentifier()).andReturn(new IdImpl(mediaPackageId)).anyTimes();
    // Setup user
    User creator = EasyMock.createMock(User.class);
    // Setup WorkflowInstance
    WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getId()).andReturn(workflowId).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(workflowOperationInstance).anyTimes();
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCreator()).andReturn(creator).anyTimes();
    EasyMock.replay(creator, mediaPackage, workflowInstance, workflowOperationInstance);
    // Test create
    EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    Capture<EventComment> comment = EasyMock.newCapture();
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), mediaPackageId, org.getId(), description, creator));
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(19L), mediaPackageId, org.getId(), description, creator));
    EasyMock.replay(eventCommentService);
    CommentWorkflowOperationHandler commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
    assertEquals(false, comment.getValue().isResolvedStatus());
    // Test resolve
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    List<EventComment> comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(deleteCommentId), mediaPackageId, org.getId(), description, creator, reason, false));
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
    comment = EasyMock.newCapture();
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), mediaPackageId, org.getId(), description, creator));
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
    assertEquals(true, comment.getValue().isResolvedStatus());
    // Test resolve with no comment
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    // Test delete with no result, no delete
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    // Test delete with result
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(deleteCommentId), mediaPackageId, org.getId(), description, creator, reason, false));
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
    eventCommentService.deleteComment(deleteCommentId);
    EasyMock.expectLastCall();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    // Test delete with unrelated comments
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(35L), mediaPackageId, org.getId(), description, creator, "", false));
    comments.add(EventComment.create(Option.option(37L), mediaPackageId, org.getId(), "Different Description", creator, reason, false));
    comments.add(EventComment.create(Option.option(39L), mediaPackageId, org.getId(), description, creator, "Different Reason", false));
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
}
Also used : Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) EventComment(org.opencastproject.event.comment.EventComment) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) EventCommentService(org.opencastproject.event.comment.EventCommentService) Test(org.junit.Test)

Example 24 with WorkflowInstance

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

the class WorkflowServiceImpl method getHoldWorkflows.

private List<WorkflowInstance> getHoldWorkflows() throws WorkflowDatabaseException {
    List<WorkflowInstance> workflows = new ArrayList<WorkflowInstance>();
    Organization organization = securityService.getOrganization();
    try {
        for (Organization org : organizationDirectoryService.getOrganizations()) {
            securityService.setOrganization(org);
            WorkflowQuery workflowQuery = new WorkflowQuery().withState(WorkflowInstance.WorkflowState.PAUSED).withCount(Integer.MAX_VALUE);
            WorkflowSet workflowSet = getWorkflowInstances(workflowQuery);
            workflows.addAll(Arrays.asList(workflowSet.getItems()));
        }
    } finally {
        securityService.setOrganization(organization);
    }
    return workflows;
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Example 25 with WorkflowInstance

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

the class WorkflowServiceImpl method update.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowService#update(org.opencastproject.workflow.api.WorkflowInstance)
 */
@Override
public void update(final WorkflowInstance workflowInstance) throws WorkflowException, UnauthorizedException {
    final Lock lock = updateLock.get(workflowInstance.getId());
    lock.lock();
    try {
        WorkflowInstance originalWorkflowInstance = null;
        try {
            originalWorkflowInstance = getWorkflowById(workflowInstance.getId());
        } catch (NotFoundException e) {
        // That's fine, it's a new workflow instance
        }
        if (originalWorkflowInstance != null) {
            try {
                assertPermission(originalWorkflowInstance, Permissions.Action.WRITE.toString());
            } catch (MediaPackageException e) {
                throw new WorkflowParsingException(e);
            }
        }
        MediaPackage updatedMediaPackage = null;
        try {
            // Before we persist this, extract the metadata
            updatedMediaPackage = workflowInstance.getMediaPackage();
            populateMediaPackageMetadata(updatedMediaPackage);
            String seriesId = updatedMediaPackage.getSeries();
            if (seriesId != null && workflowInstance.getCurrentOperation() != null) {
                // If the mediapackage contains a series, find the series ACLs and add the security information to the
                // mediapackage
                AccessControlList acl = seriesService.getSeriesAccessControl(seriesId);
                Option<AccessControlList> activeSeriesAcl = authorizationService.getAcl(updatedMediaPackage, AclScope.Series);
                if (activeSeriesAcl.isNone() || !AccessControlUtil.equals(activeSeriesAcl.get(), acl))
                    authorizationService.setAcl(updatedMediaPackage, AclScope.Series, acl);
            }
        } catch (SeriesException e) {
            throw new WorkflowDatabaseException(e);
        } catch (NotFoundException e) {
            logger.warn("Metadata for mediapackage {} could not be updated because it wasn't found", updatedMediaPackage, e);
        } catch (Exception e) {
            logger.error("Metadata for mediapackage {} could not be updated", updatedMediaPackage, e);
        }
        // Synchronize the job status with the workflow
        WorkflowState workflowState = workflowInstance.getState();
        String xml;
        try {
            xml = WorkflowParser.toXml(workflowInstance);
        } catch (Exception e) {
            // Can't happen, since we are converting from an in-memory object
            throw new IllegalStateException("In-memory workflow instance could not be serialized", e);
        }
        Job job = null;
        try {
            job = serviceRegistry.getJob(workflowInstance.getId());
            job.setPayload(xml);
            // Synchronize workflow and job state
            switch(workflowState) {
                case FAILED:
                    job.setStatus(Status.FAILED);
                    break;
                case FAILING:
                    break;
                case INSTANTIATED:
                    job.setDispatchable(true);
                    job.setStatus(Status.QUEUED);
                    break;
                case PAUSED:
                    job.setStatus(Status.PAUSED);
                    break;
                case RUNNING:
                    job.setStatus(Status.RUNNING);
                    break;
                case STOPPED:
                    job.setStatus(Status.CANCELED);
                    break;
                case SUCCEEDED:
                    job.setStatus(Status.FINISHED);
                    break;
                default:
                    throw new IllegalStateException("Found a workflow state that is not handled");
            }
        } catch (ServiceRegistryException e) {
            logger.error(e, "Unable to read workflow job %s from service registry", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        } catch (NotFoundException e) {
            logger.error("Job for workflow %s not found in service registry", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        }
        // Update both workflow and workflow job
        try {
            job = serviceRegistry.updateJob(job);
            messageSender.sendObjectMessage(WorkflowItem.WORKFLOW_QUEUE, MessageSender.DestinationType.Queue, WorkflowItem.updateInstance(workflowInstance));
            index(workflowInstance);
        } catch (ServiceRegistryException e) {
            logger.error("Update of workflow job %s in the service registry failed, service registry and workflow index may be out of sync", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        } catch (NotFoundException e) {
            logger.error("Job for workflow %s not found in service registry", workflowInstance.getId());
            throw new WorkflowDatabaseException(e);
        } catch (Exception e) {
            logger.error("Update of workflow job %s in the service registry failed, service registry and workflow index may be out of sync", job.getId());
            throw new WorkflowException(e);
        }
        if (workflowStatsCollect) {
            workflowsStatistics.updateWorkflow(getBeanStatistics(), getHoldWorkflows());
        }
        try {
            WorkflowInstance clone = WorkflowParser.parseWorkflowInstance(WorkflowParser.toXml(workflowInstance));
            fireListeners(originalWorkflowInstance, clone);
        } catch (Exception e) {
            // Can't happen, since we are converting from an in-memory object
            throw new IllegalStateException("In-memory workflow instance could not be serialized", e);
        }
    } finally {
        lock.unlock();
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) NotFoundException(org.opencastproject.util.NotFoundException) Collections.mkString(org.opencastproject.util.data.Collections.mkString) SeriesException(org.opencastproject.series.api.SeriesException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) 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) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Lock(java.util.concurrent.locks.Lock) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowState(org.opencastproject.workflow.api.WorkflowInstance.WorkflowState) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException)

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