use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class ProtobufProcessInstanceWriter method buildNodeInstances.
private List<org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.NodeInstance> buildNodeInstances(List<NodeInstance> nodeInstances) {
Comparator<NodeInstance> comparator = (o1, o2) -> ((KogitoNodeInstance) o1).getStringId().compareTo(((KogitoNodeInstance) o2).getStringId());
Collections.sort(nodeInstances, comparator);
List<KogitoTypesProtobuf.NodeInstance> nodeInstancesProtobuf = new ArrayList<>();
for (NodeInstance nodeInstance : nodeInstances) {
KogitoTypesProtobuf.NodeInstance.Builder node = KogitoTypesProtobuf.NodeInstance.newBuilder().setId(((KogitoNodeInstance) nodeInstance).getStringId()).setNodeId(nodeInstance.getNodeId()).setLevel(((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getLevel());
Date triggerDate = ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getTriggerTime();
if (triggerDate != null) {
node.setTriggerDate(triggerDate.getTime());
}
node.setSla(buildSLAContext(((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getSlaCompliance(), ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getSlaDueDate(), ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getSlaTimerId()));
node.setContent(buildNodeInstanceContent(nodeInstance));
nodeInstancesProtobuf.add(node.build());
}
return nodeInstancesProtobuf;
}
use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class MetricsProcessEventListener method beforeNodeLeft.
@Override
public void beforeNodeLeft(ProcessNodeLeftEvent event) {
LOGGER.debug("Before Node left event: {}", event);
final KogitoNodeInstance nodeInstance = (KogitoNodeInstance) event.getNodeInstance();
if (nodeInstance instanceof KogitoWorkItemNodeInstance) {
KogitoWorkItemNodeInstance wi = (KogitoWorkItemNodeInstance) nodeInstance;
if (wi.getTriggerTime() != null) {
final String name = (String) wi.getWorkItem().getParameters().getOrDefault("TaskName", wi.getWorkItem().getName());
final double duration = millisToSeconds(wi.getLeaveTime().getTime() - wi.getTriggerTime().getTime());
getWorkItemsDurationSummary(name).record(duration);
LOGGER.debug("Work Item {}, duration: {}s", name, duration);
}
}
}
use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class SLAComplianceTest method testSLAonUserTaskViolatedExternalTracking.
@Test
public void testSLAonUserTaskViolatedExternalTracking() 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);
kruntime.getKieRuntime().getEnvironment().set("SLATimerMode", "false");
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(5, TimeUnit.SECONDS);
assertFalse(slaViolated, "SLA should not 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 userTaskNode = active.iterator().next();
// simulate external tracking of sla
kruntime.signalEvent("slaViolation:" + userTaskNode.getStringId(), null, processInstance.getStringId());
slaViolated = latch.await(10, TimeUnit.SECONDS);
assertTrue(slaViolated, "SLA was not violated while it is expected");
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);
assertEquals(KogitoProcessInstance.SLA_VIOLATED, 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 testSLAonCatchEventNotViolated.
@Test
public void testSLAonCatchEventNotViolated() 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());
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, 1);
assertEquals(KogitoProcessInstance.SLA_MET, slaCompliance);
boolean slaViolated = latch.await(3, TimeUnit.SECONDS);
assertFalse(slaViolated, "SLA should not violated by timer");
}
use of org.kie.kogito.internal.process.runtime.KogitoNodeInstance in project kogito-runtimes by kiegroup.
the class SignalProcessInstanceAction method execute.
@Override
public void execute(KogitoProcessContext context) throws Exception {
String variableName = VariableUtil.resolveVariable(this.variableNameExpression, context.getNodeInstance());
KogitoProcessInstance processInstance = context.getProcessInstance();
KogitoNodeInstance nodeInstance = context.getNodeInstance();
Object signal = null;
if (inputVariable != null) {
signal = context.getContextData().get(inputVariable);
} else {
if (variableName != null) {
signal = context.getVariable(variableName);
} else {
signal = eventDataSupplier.apply(context);
}
}
signal = signal != null ? signal : variableName;
// compute inputs for throwing
Map<String, Object> inputSet = new HashMap<>();
inputSet.put("Data", signal);
String signalName = VariableUtil.resolveVariable(this.signalNameTemplate, context.getNodeInstance());
context.getKogitoProcessRuntime().getProcessEventSupport().fireOnSignal(processInstance, nodeInstance, context.getKieRuntime(), signalName, signal);
if (DEFAULT_SCOPE.equals(scope)) {
context.getKogitoProcessRuntime().signalEvent(signalName, signal);
} else if (PROCESS_INSTANCE_SCOPE.equals(scope)) {
context.getProcessInstance().signalEvent(signalName, signal);
} else if (EXTERNAL_SCOPE.equals(scope)) {
KogitoWorkItemImpl workItem = new KogitoWorkItemImpl();
workItem.setName("External Send Task");
workItem.setNodeInstanceId(context.getNodeInstance().getStringId());
workItem.setProcessInstanceId(context.getProcessInstance().getStringId());
workItem.setNodeId(context.getNodeInstance().getNodeId());
workItem.getParameters().putAll(inputSet);
workItem.setParameter("Signal", signalName);
workItem.setParameter("SignalProcessInstanceId", context.getVariable("SignalProcessInstanceId"));
workItem.setParameter("SignalWorkItemId", context.getVariable("SignalWorkItemId"));
workItem.setParameter("SignalDeploymentId", context.getVariable("SignalDeploymentId"));
((InternalKogitoWorkItemManager) context.getKogitoProcessRuntime().getKogitoWorkItemManager()).internalExecuteWorkItem(workItem);
}
}
Aggregations