Search in sources :

Example 11 with KogitoNodeInstance

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;
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance(org.kie.kogito.serialization.process.protobuf.ProtobufTypeRegistryFactory.protobufTypeRegistryFactoryInstance) Date(java.util.Date) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) MarshallerWriterContext(org.kie.kogito.serialization.process.MarshallerWriterContext) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) HumanTaskWorkItemData(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) ContextInstance(org.jbpm.process.instance.ContextInstance) Map(java.util.Map) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) MilestoneNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.MilestoneNodeInstanceContent) EventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventNodeInstanceContent) WorkflowContext(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf.WorkflowContext) Attachment(org.kie.kogito.process.workitem.Attachment) JoinTrigger(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.JoinNodeInstanceContent.JoinTrigger) ForEachNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.ForEachNodeInstanceContent) Collection(java.util.Collection) DynamicNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.DynamicNodeInstanceContent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoTypesProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoTypesProtobuf) VariableScope(org.jbpm.process.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) List(java.util.List) EventSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.EventSubProcessNodeInstanceContent) JsonFormat(com.google.protobuf.util.JsonFormat) ExclusiveGroup(org.jbpm.process.core.context.exclusive.ExclusiveGroup) Entry(java.util.Map.Entry) Any(com.google.protobuf.Any) StateNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.StateNodeInstanceContent) SwimlaneContext(org.jbpm.process.core.context.swimlane.SwimlaneContext) CompositeContextNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.CompositeContextNodeInstanceContent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) NodeInstance(org.kie.api.runtime.process.NodeInstance) KogitoWorkItemsProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf) HashMap(java.util.HashMap) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) JoinNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.JoinNodeInstanceContent) ArrayList(java.util.ArrayList) AsyncEventNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.AsyncEventNodeInstanceContent) WorkItemNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.WorkItemNodeInstanceContent) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) LambdaSubProcessNodeInstance(org.jbpm.workflow.instance.node.LambdaSubProcessNodeInstance) LambdaSubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.LambdaSubProcessNodeInstanceContent) MARSHALLER_FORMAT(org.kie.kogito.serialization.process.MarshallerContextName.MARSHALLER_FORMAT) KogitoProcessInstanceProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoProcessInstanceProtobuf) OutputStream(java.io.OutputStream) SubProcessNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.SubProcessNodeInstanceContent) MARSHALLER_FORMAT_JSON(org.kie.kogito.serialization.process.MarshallerContextName.MARSHALLER_FORMAT_JSON) TimerNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.TimerNodeInstanceContent) IOException(java.io.IOException) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) RuleSetNodeInstanceContent(org.kie.kogito.serialization.process.protobuf.KogitoNodeInstanceContentsProtobuf.RuleSetNodeInstanceContent) AsyncEventNodeInstance(org.jbpm.workflow.core.node.AsyncEventNodeInstance) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) Comparator(java.util.Comparator) JoinInstance(org.jbpm.workflow.instance.node.JoinInstance) Collections(java.util.Collections) Reassignment(org.jbpm.process.instance.impl.humantask.Reassignment) ArrayList(java.util.ArrayList) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance) LambdaSubProcessNodeInstance(org.jbpm.workflow.instance.node.LambdaSubProcessNodeInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) AsyncEventNodeInstance(org.jbpm.workflow.core.node.AsyncEventNodeInstance) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) Date(java.util.Date)

Example 12 with KogitoNodeInstance

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);
        }
    }
}
Also used : KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) KogitoWorkItemNodeInstance(org.kie.kogito.internal.process.runtime.KogitoWorkItemNodeInstance)

Example 13 with KogitoNodeInstance

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);
}
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 14 with KogitoNodeInstance

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");
}
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 15 with KogitoNodeInstance

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);
    }
}
Also used : KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) HashMap(java.util.HashMap) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) InternalKogitoWorkItemManager(org.kie.kogito.process.workitems.InternalKogitoWorkItemManager) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)

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