Search in sources :

Example 26 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceReader method buildExclusiveGroupInstance.

private ExclusiveGroupInstance buildExclusiveGroupInstance(KogitoTypesProtobuf.NodeInstanceGroup group, Function<String, KogitoNodeInstance> finder) {
    ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
    for (String nodeInstanceId : group.getGroupNodeInstanceIdList()) {
        KogitoNodeInstance kogitoNodeInstance = finder.apply(nodeInstanceId);
        if (kogitoNodeInstance == null) {
            throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
        }
        exclusiveGroupInstance.addNodeInstance(kogitoNodeInstance);
    }
    return exclusiveGroupInstance;
}
Also used : ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance)

Example 27 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceWriter method buildGroups.

private List<KogitoTypesProtobuf.NodeInstanceGroup> buildGroups(List<ContextInstance> exclusiveGroupInstances) {
    if (exclusiveGroupInstances == null) {
        return Collections.emptyList();
    }
    List<KogitoTypesProtobuf.NodeInstanceGroup> groupProtobuf = new ArrayList<>();
    for (ContextInstance contextInstance : exclusiveGroupInstances) {
        KogitoTypesProtobuf.NodeInstanceGroup.Builder exclusiveNodeInstanceGroup = KogitoTypesProtobuf.NodeInstanceGroup.newBuilder();
        ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
        Collection<KogitoNodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
        for (KogitoNodeInstance nodeInstance : groupNodeInstances) {
            exclusiveNodeInstanceGroup.addGroupNodeInstanceId(nodeInstance.getStringId());
        }
        groupProtobuf.add(exclusiveNodeInstanceGroup.build());
    }
    return groupProtobuf;
}
Also used : ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) ArrayList(java.util.ArrayList) ContextInstance(org.jbpm.process.instance.ContextInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)

Example 28 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonUserTaskViolated.

@Test
public void testSLAonUserTaskViolated() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLAOnTask.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    kruntime.getProcessEventManager().addEventListener(listener);
    KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    boolean slaViolated = latch.await(10, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA was not violated while it is expected");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    Collection<KogitoNodeInstance> active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances();
    assertEquals(1, active.size());
    KogitoNodeInstance userTaskNode = active.iterator().next();
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) Test(org.junit.jupiter.api.Test)

Example 29 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonCatchEventViolated.

@Test
public void testSLAonCatchEventViolated() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    final KogitoProcessEventListener listener = new DefaultKogitoProcessEventListener() {

        @Override
        public void afterSLAViolated(SLAViolatedEvent event) {
            latch.countDown();
        }
    };
    kruntime = createKogitoProcessRuntime("BPMN2-IntermediateCatchEventSignalWithSLAOnEvent.bpmn2");
    kruntime.getProcessEventManager().addEventListener(listener);
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    KogitoProcessInstance processInstance = kruntime.startProcess("IntermediateCatchEvent");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    boolean slaViolated = latch.await(5, TimeUnit.SECONDS);
    assertTrue(slaViolated, "SLA should be violated by timer");
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    Collection<KogitoNodeInstance> active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances();
    assertEquals(1, active.size());
    KogitoNodeInstance eventNode = active.iterator().next();
    kruntime.signalEvent("MyMessage", null, processInstance.getStringId());
    assertProcessInstanceFinished(processInstance, kruntime);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 0);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) eventNode, 1);
    assertEquals(KogitoProcessInstance.SLA_VIOLATED, slaCompliance);
}
Also used : SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) Test(org.junit.jupiter.api.Test)

Example 30 with KogitoNodeInstance

use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.

the class SLAComplianceTest method testSLAonUserTaskMet.

@Test
public void testSLAonUserTaskMet() throws Exception {
    kruntime = createKogitoProcessRuntime("BPMN2-UserTaskWithSLAOnTask.bpmn2");
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    kruntime.getKogitoWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    KogitoProcessInstance processInstance = kruntime.startProcess("UserTask");
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    KogitoWorkItem workItem = workItemHandler.getWorkItem();
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameter("ActorId"));
    processInstance = kruntime.getProcessInstance(processInstance.getStringId());
    assertEquals(KogitoProcessInstance.STATE_ACTIVE, processInstance.getState());
    Collection<KogitoNodeInstance> active = ((KogitoWorkflowProcessInstance) processInstance).getKogitoNodeInstances();
    assertEquals(1, active.size());
    KogitoNodeInstance userTaskNode = active.iterator().next();
    kruntime.getKogitoWorkItemManager().completeWorkItem(workItem.getStringId(), null);
    assertProcessInstanceFinished(processInstance, kruntime);
    int slaCompliance = getSLAComplianceForProcessInstance(processInstance);
    assertEquals(KogitoProcessInstance.SLA_NA, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0);
    // Whereas in memory it is already met
    assertEquals(KogitoProcessInstance.SLA_MET, slaCompliance);
    slaCompliance = getSLAComplianceForNodeInstance(processInstance.getStringId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1);
    assertEquals(KogitoProcessInstance.SLA_MET, slaCompliance);
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) Test(org.junit.jupiter.api.Test)

Aggregations

KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)33 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)15 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)14 Map (java.util.Map)12 SLAViolatedEvent (org.kie.api.event.process.SLAViolatedEvent)12 KogitoProcessEventListener (org.kie.kogito.internal.process.event.KogitoProcessEventListener)12 List (java.util.List)11 HumanTaskWorkItem (org.kie.kogito.process.workitem.HumanTaskWorkItem)9 WorkUnit (org.kie.kogito.uow.WorkUnit)9 AbstractEventSupport (org.drools.core.event.AbstractEventSupport)8 MessageEventImpl (org.drools.core.event.MessageEventImpl)8 ProcessCompletedEventImpl (org.drools.core.event.ProcessCompletedEventImpl)8 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)8 SLAViolatedEventImpl (org.drools.core.event.SLAViolatedEventImpl)8 SignalEventImpl (org.drools.core.event.SignalEventImpl)8 Date (java.util.Date)7 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 MessageEvent (org.kie.api.event.process.MessageEvent)5