Search in sources :

Example 1 with EvaluateDecisionResult

use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateDecisionResult 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 EvaluateDecisionResult

use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateDecisionResult in project kogito-runtimes by kiegroup.

the class DefaultAggregator method buildDmnDecisionTraceExecutionStep.

private static TraceExecutionStep buildDmnDecisionTraceExecutionStep(long duration, EvaluateEvent afterEvent, List<TraceExecutionStep> children) {
    List<Message> messages = afterEvent.getResult().getMessages().stream().filter(m -> afterEvent.getNodeId().equals(m.getSourceId())).collect(Collectors.toList());
    JsonNode result = afterEvent.getResult().getDecisionResults().stream().filter(dr -> dr.getDecisionId().equals(afterEvent.getNodeId())).findFirst().map(EvaluateDecisionResult::getResult).<JsonNode>map(EventUtils::jsonNodeFrom).orElse(null);
    Map<String, String> additionalData = new HashMap<>();
    additionalData.put(NODE_ID_KEY, afterEvent.getNodeId());
    return new TraceExecutionStep(TraceExecutionStepType.DMN_DECISION, duration, afterEvent.getNodeName(), result, messages, additionalData, children);
}
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) EvaluateDecisionResult(org.kie.kogito.tracing.decision.event.evaluate.EvaluateDecisionResult) Message(org.kie.kogito.tracing.event.message.Message) HashMap(java.util.HashMap) TraceExecutionStep(org.kie.kogito.tracing.event.trace.TraceExecutionStep) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 CloudEvent (io.cloudevents.CloudEvent)2 URI (java.net.URI)2 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Deque (java.util.Deque)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 DMNModel (org.kie.dmn.api.core.DMNModel)2 DMNType (org.kie.dmn.api.core.DMNType)2 DMNNode (org.kie.dmn.api.core.ast.DMNNode)2