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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations