use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class DecisionsApiV1IT method buildValidDecision.
private Decision buildValidDecision(ListStatus inputsStatus, ListStatus outcomesStatus) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Decision decision = new Decision();
decision.setExecutionId(TEST_EXECUTION_ID);
decision.setSourceUrl(TEST_SOURCE_URL);
decision.setExecutionTimestamp(TEST_EXECUTION_TIMESTAMP);
decision.setSuccess(true);
decision.setExecutedModelName(TEST_MODEL_NAME);
decision.setExecutedModelNamespace(TEST_MODEL_NAMESPACE);
switch(inputsStatus) {
case EMPTY:
decision.setInputs(List.of());
break;
case FULL:
decision.setInputs(List.of(new DecisionInput("1", "first", new UnitValue("string", "string", mapper.readTree("\"Hello\""))), new DecisionInput("2", "second", new UnitValue("number", "number", mapper.readTree("12345")))));
}
switch(outcomesStatus) {
case EMPTY:
decision.setOutcomes(List.of());
break;
case FULL:
decision.setOutcomes(List.of(new DecisionOutcome(TEST_OUTCOME_ID, "ONE", "SUCCEEDED", new UnitValue("string", "string", mapper.readTree("\"The First " + "Outcome\"")), Collections.emptyList(), List.of(getMessage(MessageLevel.WARNING, MessageCategory.INTERNAL, "TEST", "testSrc", "Test message", getMessageExceptionField("TestException", "Test exception message", getMessageExceptionField("TestExceptionCause", "Test exception " + "cause " + "message", null)))))));
}
return decision;
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method storeExecution.
private void storeExecution(String executionId, Long timestamp) {
DecisionInput decisionInput = new DecisionInput();
decisionInput.setId("inputId");
decisionInput.setName("test");
decisionInput.setValue(new UnitValue("number", "number", JsonNodeFactory.instance.numberNode(10)));
Decision decision = new Decision();
decision.setExecutionId(executionId);
decision.setExecutionTimestamp(timestamp);
decision.setServiceUrl("serviceUrl");
decision.setExecutedModelNamespace("executedModelNamespace");
decision.setExecutedModelName("executedModelName");
decision.setInputs(Collections.singletonList(decisionInput));
trustyService.storeDecision(decision.getExecutionId(), decision);
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method givenAnExecutionWhenGetDecisionByIdThenTheComponentsInUnitTypesIsNull.
@Test
public void givenAnExecutionWhenGetDecisionByIdThenTheComponentsInUnitTypesIsNull() {
String executionId = "myExecution";
storeExecution(executionId, 1591692950000L);
Decision result = trustyService.getDecisionById(executionId);
Assertions.assertTrue(result.getInputs().stream().findFirst().get().getValue().isUnit());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method testCounterfactuals_StoreMultipleAndRetrieveAllWithEmptyDefinition.
@Test
public void testCounterfactuals_StoreMultipleAndRetrieveAllWithEmptyDefinition() {
String executionId = "myCFExecution2";
storeExecution(executionId, 0L);
// The Goals structures must be comparable to the original decisions outcomes.
// The Search Domain structures must be identical those of the original decision inputs.
CounterfactualSearchDomain searchDomain = buildSearchDomainUnit("test", "number", new CounterfactualDomainRange(new IntNode(1), new IntNode(2)));
CounterfactualExplainabilityRequest request1 = trustyService.requestCounterfactuals(executionId, Collections.emptyList(), Collections.singletonList(searchDomain));
CounterfactualExplainabilityRequest request2 = trustyService.requestCounterfactuals(executionId, Collections.emptyList(), Collections.singletonList(searchDomain));
List<CounterfactualExplainabilityRequest> result = trustyService.getCounterfactualRequests(executionId);
assertNotNull(result);
assertEquals(2, result.size());
assertTrue(result.stream().anyMatch(c -> c.getCounterfactualId().equals(request1.getCounterfactualId())));
assertTrue(result.stream().anyMatch(c -> c.getCounterfactualId().equals(request2.getCounterfactualId())));
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class TrustyServiceImpl method makeCounterfactualRequest.
protected CounterfactualExplainabilityRequest makeCounterfactualRequest(String executionId, List<NamedTypedValue> goals, List<CounterfactualSearchDomain> searchDomains, Long maxRunningTimeSeconds) {
Decision decision = getDecisionById(executionId);
// This is returned as null under Redis, so play safe
Collection<DecisionInput> decisionInputs = Objects.nonNull(decision.getInputs()) ? decision.getInputs() : Collections.emptyList();
if (!isStructureIdentical(decisionInputs, searchDomains)) {
String error = buildCounterfactualErrorMessage(String.format("The structure of the Search Domains do not match the structure of the original Inputs for decision with ID %s.", executionId), "Decision inputs:-", decisionInputs, "Search domains:-", searchDomains);
LOG.error(error);
throw new IllegalArgumentException(error);
}
// This is returned as null under Redis, so play safe
Collection<DecisionOutcome> decisionOutcomes = Objects.nonNull(decision.getOutcomes()) ? decision.getOutcomes() : Collections.emptyList();
if (!isStructureSubset(decisionOutcomes, goals)) {
String error = buildCounterfactualErrorMessage(String.format("The structure of the Goals is not comparable to the structure of the original Outcomes for decision with ID %s.", executionId), "Decision outcomes:-", decisionOutcomes, "Goals:-", goals);
LOG.error(error);
throw new IllegalArgumentException(error);
}
List<NamedTypedValue> cfInputs = decision.getInputs() != null ? decision.getInputs().stream().map(input -> new NamedTypedValue(input.getName(), input.getValue())).collect(Collectors.toList()) : Collections.emptyList();
List<NamedTypedValue> cfGoals = goals != null ? goals : Collections.emptyList();
List<CounterfactualSearchDomain> cfSearchDomains = searchDomains != null ? searchDomains : Collections.emptyList();
return new CounterfactualExplainabilityRequest(executionId, decision.getServiceUrl(), createDecisionModelIdentifier(decision), UUID.randomUUID().toString(), cfInputs, cfGoals, cfSearchDomains, maxRunningTimeSeconds);
}
Aggregations