Search in sources :

Example 1 with Pair

use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.

the class DefaultAggregator method traceOutputFrom.

private static TraceOutputValue traceOutputFrom(EvaluateDecisionResult decisionResult, DMNModel model, Map<String, Object> context) {
    DMNType type = Optional.ofNullable(model).map(m -> m.getDecisionById(decisionResult.getDecisionId())).map(DecisionNode::getResultType).orElse(null);
    // cast to DMNBaseNode here is required to have access to getDependencies method
    Map<String, DMNType> decisionInputTypes = Optional.ofNullable(model).map(m -> m.getDecisionById(decisionResult.getDecisionId())).filter(DMNBaseNode.class::isInstance).map(DMNBaseNode.class::cast).map(DMNBaseNode::getDependencies).map(deps -> deps.values().stream().map(DMNNode::getId).collect(Collectors.toList())).map(ids -> ids.stream().map(id -> typeAndNameOf(id, model)).filter(Objects::nonNull).collect(Collectors.toMap(Pair::getRight, Pair::getLeft))).orElseGet(HashMap::new);
    Map<String, TypedValue> decisionInputs = decisionInputTypes.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> EventUtils.typedValueFrom(e.getValue(), context.get(e.getKey()))));
    return new TraceOutputValue(decisionResult.getDecisionId(), decisionResult.getDecisionName(), decisionResult.getEvaluationStatus().name(), EventUtils.typedValueFrom(type, decisionResult.getResult()), decisionInputs, decisionResult.getMessages());
}
Also used : TraceEventType(org.kie.kogito.tracing.event.trace.TraceEventType) TraceExecutionStepType(org.kie.kogito.tracing.event.trace.TraceExecutionStepType) Arrays(java.util.Arrays) DMNType(org.kie.dmn.api.core.DMNType) CloudEvent(io.cloudevents.CloudEvent) AFTER_EVALUATE_DECISION_SERVICE(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType.AFTER_EVALUATE_DECISION_SERVICE) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Deque(java.util.Deque) Function(java.util.function.Function) TraceExecutionStep(org.kie.kogito.tracing.event.trace.TraceExecutionStep) ArrayList(java.util.ArrayList) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl) DMNModel(org.kie.dmn.api.core.DMNModel) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) Map(java.util.Map) EvaluateDecisionResult(org.kie.kogito.tracing.decision.event.evaluate.EvaluateDecisionResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) InternalMessageType(org.kie.kogito.tracing.decision.message.InternalMessageType) Message(org.kie.kogito.tracing.event.message.Message) EvaluateEventType(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType) TraceEvent(org.kie.kogito.tracing.event.trace.TraceEvent) ConfigBean(org.kie.kogito.conf.ConfigBean) Logger(org.slf4j.Logger) DMNNode(org.kie.dmn.api.core.ast.DMNNode) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) TraceInputValue(org.kie.kogito.tracing.event.trace.TraceInputValue) TraceOutputValue(org.kie.kogito.tracing.event.trace.TraceOutputValue) Collection(java.util.Collection) EventUtils(org.kie.kogito.tracing.decision.event.EventUtils) Collectors(java.util.stream.Collectors) Pair(org.kie.dmn.feel.util.Pair) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) Objects(java.util.Objects) List(java.util.List) TraceHeader(org.kie.kogito.tracing.event.trace.TraceHeader) Stream(java.util.stream.Stream) CloudEventUtils(org.kie.kogito.event.cloudevents.utils.CloudEventUtils) BEFORE_EVALUATE_DECISION_SERVICE(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType.BEFORE_EVALUATE_DECISION_SERVICE) Optional(java.util.Optional) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) TraceOutputValue(org.kie.kogito.tracing.event.trace.TraceOutputValue) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) HashMap(java.util.HashMap) DMNNode(org.kie.dmn.api.core.ast.DMNNode) HashMap(java.util.HashMap) Map(java.util.Map) DMNType(org.kie.dmn.api.core.DMNType) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue)

Example 2 with Pair

use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.

the class DecisionTracingCollectorTest method testInterleavedEvaluations.

private void testInterleavedEvaluations(Supplier<TerminationDetector> terminationDetectorSupplier) throws IOException {
    MockDefaultAggregator aggregator = new MockDefaultAggregator();
    Consumer<String> payloadConsumer = mock(Consumer.class);
    DecisionTracingCollector collector = new DecisionTracingCollector(aggregator, payloadConsumer, (namespace, name) -> model, terminationDetectorSupplier, configBean);
    List<EvaluateEvent> evaluateAllEvents = readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE);
    List<EvaluateEvent> evaluateDecisionServiceEvents = readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE);
    for (int i = 0; i < Math.max(evaluateAllEvents.size(), evaluateDecisionServiceEvents.size()); i++) {
        if (i < evaluateAllEvents.size()) {
            collector.addEvent(evaluateAllEvents.get(i));
        }
        if (i < evaluateDecisionServiceEvents.size()) {
            collector.addEvent(evaluateDecisionServiceEvents.get(i));
        }
    }
    Map<String, Pair<List<EvaluateEvent>, CloudEvent>> aggregatorCalls = aggregator.getCalls();
    assertEquals(2, aggregatorCalls.size());
    assertTrue(aggregatorCalls.containsKey(EVALUATE_ALL_EXECUTION_ID));
    assertEquals(evaluateAllEvents.size(), aggregatorCalls.get(EVALUATE_ALL_EXECUTION_ID).getLeft().size());
    assertTrue(aggregatorCalls.containsKey(EVALUATE_DECISION_SERVICE_EXECUTION_ID));
    assertEquals(evaluateDecisionServiceEvents.size(), aggregatorCalls.get(EVALUATE_DECISION_SERVICE_EXECUTION_ID).getLeft().size());
    ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
    verify(payloadConsumer, times(2)).accept(payloadCaptor.capture());
    int evaluateAllIndex = evaluateAllEvents.size() > evaluateDecisionServiceEvents.size() ? 1 : 0;
    int evaluateDecisionServiceIndex = evaluateAllIndex == 1 ? 0 : 1;
    List<String> payloads = payloadCaptor.getAllValues();
    String expectedEvaluateAll = encodeFromCall(aggregatorCalls, EVALUATE_ALL_EXECUTION_ID);
    assertEquals(expectedEvaluateAll, payloads.get(evaluateAllIndex));
    String expectedEvaluateDecisionService = encodeFromCall(aggregatorCalls, EVALUATE_DECISION_SERVICE_EXECUTION_ID);
    assertEquals(expectedEvaluateDecisionService, payloads.get(evaluateDecisionServiceIndex));
}
Also used : MockDefaultAggregator(org.kie.kogito.tracing.decision.mock.MockDefaultAggregator) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Pair(org.kie.dmn.feel.util.Pair)

Example 3 with Pair

use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.

the class EvaluateEventTypeTest method testNotManagedEvents.

@Test
void testNotManagedEvents() {
    for (Method listenerMethod : LISTENER_CLASS.getMethods()) {
        Optional<Map.Entry<EvaluateEventType, Pair<String, Class<?>>>> optEntry = CHECK_MAP.entrySet().stream().filter(e -> e.getValue().getLeft().equals(listenerMethod.getName())).findAny();
        assertTrue(optEntry.isPresent(), () -> String.format("No EvaluateEventType for listener method \"%s\"", listenerMethod.getName()));
    }
}
Also used : AfterEvaluateDecisionServiceEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionServiceEvent) AfterEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent) BeforeEvaluateDecisionEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionEvent) BeforeEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionTableEvent) DMNRuntimeEventListener(org.kie.dmn.api.core.event.DMNRuntimeEventListener) DMNEvent(org.kie.dmn.api.core.event.DMNEvent) AfterEvaluateAllEvent(org.kie.dmn.api.core.event.AfterEvaluateAllEvent) AfterInvokeBKMEvent(org.kie.dmn.api.core.event.AfterInvokeBKMEvent) BeforeEvaluateDecisionServiceEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionServiceEvent) BeforeEvaluateBKMEvent(org.kie.dmn.api.core.event.BeforeEvaluateBKMEvent) HashMap(java.util.HashMap) Pair(org.kie.dmn.feel.util.Pair) BeforeEvaluateContextEntryEvent(org.kie.dmn.api.core.event.BeforeEvaluateContextEntryEvent) Test(org.junit.jupiter.api.Test) BeforeEvaluateAllEvent(org.kie.dmn.api.core.event.BeforeEvaluateAllEvent) AfterEvaluateContextEntryEvent(org.kie.dmn.api.core.event.AfterEvaluateContextEntryEvent) BeforeInvokeBKMEvent(org.kie.dmn.api.core.event.BeforeInvokeBKMEvent) Map(java.util.Map) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Method(java.lang.reflect.Method) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) AfterEvaluateBKMEvent(org.kie.dmn.api.core.event.AfterEvaluateBKMEvent) AfterEvaluateDecisionEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionEvent) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 4 with Pair

use of org.kie.dmn.feel.util.Pair in project kogito-runtimes by kiegroup.

the class DefaultAggregator method typeAndNameOf.

private static Pair<DMNType, String> typeAndNameOf(String nodeId, DMNModel model) {
    InputDataNode input = model.getInputById(nodeId);
    if (input != null) {
        return new Pair<>(input.getType(), input.getName());
    }
    DecisionNode decision = model.getDecisionById(nodeId);
    if (decision != null) {
        return new Pair<>(decision.getResultType(), decision.getName());
    }
    return null;
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Pair(org.kie.dmn.feel.util.Pair)

Aggregations

Pair (org.kie.dmn.feel.util.Pair)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)2 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)2 EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CloudEvent (io.cloudevents.CloudEvent)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 List (java.util.List)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1