This is an automated email from the ASF dual-hosted git repository.
gitgabrio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-apps.git
The following commit(s) were added to refs/heads/main by this push:
new 551b5381f [incubator-kie-issues#1015] Implement configurable log on
DMN rest endpoints (#2017)
551b5381f is described below
commit 551b5381facf20913c4183edaaae8fe0b54df4fe
Author: Gabriele Cardosi <[email protected]>
AuthorDate: Tue Mar 19 16:59:50 2024 +0100
[incubator-kie-issues#1015] Implement configurable log on DMN rest
endpoints (#2017)
* [incubator-kie-issues#1015] Implement configurable log on DMN rest
endpoints
* [incubator-kie-issues#1015] Fix typo
* [incubator-kie-issues#1015] Fix as per PR suggestion
---------
Co-authored-by: Gabriele-Cardosi <[email protected]>
---
jitexecutor/README.md | 5 +++++
.../common/requests/MultipleResourcesPayload.java | 8 +++++++
.../common/requests/ResourceWithURI.java | 8 +++++++
jitexecutor/jitexecutor-dmn/README.md | 11 +++++++++
jitexecutor/jitexecutor-dmn/pom.xml | 26 ++++++++++++++++++++++
.../application.properties | 2 ++
.../jitexecutor/dmn/api/DMNValidationResource.java | 17 ++++++++++++--
.../kogito/jitexecutor/dmn/api/JITDMNResource.java | 19 ++++++++++++++++
.../jitexecutor/dmn/requests/JITDMNPayload.java | 8 +++++++
.../org/kie/kogito/jitexecutor/dmn/DMN15Test.java | 4 ++--
.../dmn/api/DMNValidatorResourceTest.java | 7 +++---
11 files changed, 108 insertions(+), 7 deletions(-)
diff --git a/jitexecutor/README.md b/jitexecutor/README.md
index b80ac3ffc..3fa5d7e94 100644
--- a/jitexecutor/README.md
+++ b/jitexecutor/README.md
@@ -168,6 +168,11 @@ The native mode is supported by this application. You can
create the native Quar
mvn clean package -DskipTests -Pnative
```
+end execute with
+```bash
+jitexecutor-runner/target/jitexecutor-runner-999-SNAPSHOT-runner
+```
+
## Multiple models
Each endpoint does support a multiple DMN models variant of the payload; this
is helpful for the use-case where the main model to be evaluated has some
DMN-import references to other DMNs.
diff --git
a/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/MultipleResourcesPayload.java
b/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/MultipleResourcesPayload.java
index ef9f39443..0c16e267d 100644
---
a/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/MultipleResourcesPayload.java
+++
b/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/MultipleResourcesPayload.java
@@ -48,4 +48,12 @@ public class MultipleResourcesPayload {
public void setResources(List<ResourceWithURI> resources) {
this.resources = resources;
}
+
+ @Override
+ public String toString() {
+ return "MultipleResourcesPayload{" +
+ "mainURI='" + mainURI + '\'' +
+ ", resources=" + resources +
+ '}';
+ }
}
diff --git
a/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/ResourceWithURI.java
b/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/ResourceWithURI.java
index 7d74778b9..7c3f7d2f6 100644
---
a/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/ResourceWithURI.java
+++
b/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/requests/ResourceWithURI.java
@@ -49,4 +49,12 @@ public class ResourceWithURI {
public void setContent(String content) {
this.content = content;
}
+
+ @Override
+ public String toString() {
+ return "ResourceWithURI{" +
+ "URI='" + URI + '\'' +
+ ", content='" + content + '\'' +
+ '}';
+ }
}
diff --git a/jitexecutor/jitexecutor-dmn/README.md
b/jitexecutor/jitexecutor-dmn/README.md
new file mode 100644
index 000000000..c23837a65
--- /dev/null
+++ b/jitexecutor/jitexecutor-dmn/README.md
@@ -0,0 +1,11 @@
+# Kogito JIT DMN Executor
+
+## Log configuration
+
+Rest endpoints have log configuration to eventually print out received
payload, if log is set to DEBUG level (default is INFO).
+This is managed in the application.properties, that is under
filtered-resources.
+The `quarkus.log.category."org.kie.kogito".level` is set from
`${jitexecutor.dmn.log.level}`, that by default is "INFO" in the pom.xml.
+
+It can be overridden with commandline parameter, e.g.
+
+`mvn clean package -Djitexecutor.dmn.log.level=DEBUG`
diff --git a/jitexecutor/jitexecutor-dmn/pom.xml
b/jitexecutor/jitexecutor-dmn/pom.xml
index b0972e9a2..daffe13eb 100644
--- a/jitexecutor/jitexecutor-dmn/pom.xml
+++ b/jitexecutor/jitexecutor-dmn/pom.xml
@@ -32,6 +32,7 @@
<properties>
<java.module.name>org.kie.kogito.jitexecutor.dmn</java.module.name>
+ <jitexecutor.dmn.log.level>INFO</jitexecutor.dmn.log.level>
</properties>
<dependencyManagement>
@@ -121,4 +122,29 @@
<scope>test</scope>
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-filtered-resources</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+
<outputDirectory>${project.build.directory}/classes</outputDirectory>
+ <resources>
+ <resource>
+
<directory>${project.basedir}/src/main/filtered-resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git
a/jitexecutor/jitexecutor-dmn/src/main/resources/application.properties
b/jitexecutor/jitexecutor-dmn/src/main/filtered-resources/application.properties
similarity index 93%
rename from
jitexecutor/jitexecutor-dmn/src/main/resources/application.properties
rename to
jitexecutor/jitexecutor-dmn/src/main/filtered-resources/application.properties
index 0f5873075..ea6443155 100644
--- a/jitexecutor/jitexecutor-dmn/src/main/resources/application.properties
+++
b/jitexecutor/jitexecutor-dmn/src/main/filtered-resources/application.properties
@@ -24,6 +24,8 @@
# quarkus.log.category."org".level=INFO
+quarkus.log.category."org.kie.kogito".level=${jitexecutor.dmn.log.level}
+
# To avoid errors such as:
# Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException:
Discovered unresolved type during parsing:
org.kie.pmml.pmml_4_2.PMMLRequestDataBuilder. To diagnose the issue you can use
the --allow-incomplete-classpath option. The missing type is then reported at
run time when it is accessed the first time.
quarkus.native.additional-build-args=\
diff --git
a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java
b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java
index edfb1f9cd..fd2a31e0b 100644
---
a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java
+++
b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java
@@ -19,7 +19,6 @@
package org.kie.kogito.jitexecutor.dmn.api;
import java.io.StringReader;
-import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -36,6 +35,8 @@ import
org.kie.kogito.jitexecutor.common.requests.MultipleResourcesPayload;
import org.kie.kogito.jitexecutor.common.requests.ResourceWithURI;
import org.kie.kogito.jitexecutor.dmn.responses.JITDMNMessage;
import org.kie.kogito.jitexecutor.dmn.utils.ResolveByKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
@@ -47,13 +48,21 @@ import jakarta.ws.rs.core.Response;
@Path("jitdmn/validate")
public class DMNValidationResource {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(DMNValidationResource.class);
+
+ static final String LINEBREAK = "******\n";
+
// trick for resolver/implementation for NI
- static final DMNValidator validator =
DMNValidatorFactory.newValidator(Arrays.asList(new ExtendedDMNProfile()));
+ static final DMNValidator validator =
DMNValidatorFactory.newValidator(List.of(new ExtendedDMNProfile()));
@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_JSON)
public Response schema(String payload) {
+ LOGGER.debug(LINEBREAK);
+ LOGGER.debug("jitdmn/validate");
+ LOGGER.debug(payload);
+ LOGGER.debug(LINEBREAK);
List<DMNMessage> validate =
validator.validate(new StringReader(payload),
Validation.VALIDATE_SCHEMA, Validation.VALIDATE_MODEL,
Validation.VALIDATE_COMPILATION, Validation.ANALYZE_DECISION_TABLE);
List<JITDMNMessage> result =
validate.stream().map(JITDMNMessage::of).collect(Collectors.toList());
@@ -64,6 +73,10 @@ public class DMNValidationResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response schema(MultipleResourcesPayload payload) {
+ LOGGER.debug(LINEBREAK);
+ LOGGER.debug("jitdmn/validate");
+ LOGGER.debug(payload.toString());
+ LOGGER.debug(LINEBREAK);
Map<String, Resource> resources = new LinkedHashMap<>();
for (ResourceWithURI r : payload.getResources()) {
Resource readerResource = ResourceFactory.newReaderResource(new
StringReader(r.getContent()), "UTF-8");
diff --git
a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java
b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java
index dd926ffc9..b99739c54 100644
---
a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java
+++
b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java
@@ -27,6 +27,8 @@ import org.kie.kogito.jitexecutor.dmn.JITDMNService;
import org.kie.kogito.jitexecutor.dmn.requests.JITDMNPayload;
import org.kie.kogito.jitexecutor.dmn.responses.DMNResultWithExplanation;
import org.kie.kogito.jitexecutor.dmn.responses.JITDMNResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
@@ -36,9 +38,13 @@ import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
+import static
org.kie.kogito.jitexecutor.dmn.api.DMNValidationResource.LINEBREAK;
+
@Path("/jitdmn")
public class JITDMNResource {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(JITDMNResource.class);
+
@Inject
JITDMNService jitdmnService;
@@ -46,6 +52,10 @@ public class JITDMNResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response jitdmn(JITDMNPayload payload) {
+ LOGGER.debug(LINEBREAK);
+ LOGGER.debug("jitdmn/");
+ LOGGER.debug(payload.toString());
+ LOGGER.debug(LINEBREAK);
JITDMNResult evaluateAll = payload.getModel() != null ?
jitdmnService.evaluateModel(payload.getModel(), payload.getContext()) :
jitdmnService.evaluateModel(payload, payload.getContext());
Map<String, Object> restResulk = new HashMap<>();
for (Entry<String, Object> kv :
evaluateAll.getContext().getAll().entrySet()) {
@@ -59,6 +69,10 @@ public class JITDMNResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response jitdmnResult(JITDMNPayload payload) {
+ LOGGER.debug(LINEBREAK);
+ LOGGER.debug("jitdmn/dmnresult");
+ LOGGER.debug(payload.toString());
+ LOGGER.debug(LINEBREAK);
JITDMNResult dmnResult = payload.getModel() != null ?
jitdmnService.evaluateModel(payload.getModel(), payload.getContext()) :
jitdmnService.evaluateModel(payload, payload.getContext());
return Response.ok(dmnResult).build();
}
@@ -68,8 +82,13 @@ public class JITDMNResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response jitEvaluateAndExplain(JITDMNPayload payload) {
+ LOGGER.debug(LINEBREAK);
+ LOGGER.debug("jitdmn/evaluateAndExplain");
+ LOGGER.debug(payload.toString());
+ LOGGER.debug(LINEBREAK);
DMNResultWithExplanation response =
payload.getModel() != null ?
jitdmnService.evaluateModelAndExplain(payload.getModel(), payload.getContext())
: jitdmnService.evaluateModelAndExplain(payload, payload.getContext());
return Response.ok(response).build();
}
+
}
diff --git
a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/requests/JITDMNPayload.java
b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/requests/JITDMNPayload.java
index 178dfd578..b2a15cf2d 100644
---
a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/requests/JITDMNPayload.java
+++
b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/requests/JITDMNPayload.java
@@ -68,6 +68,14 @@ public class JITDMNPayload extends MultipleResourcesPayload {
this.context = context;
}
+ @Override
+ public String toString() {
+ return "JITDMNPayload{" +
+ "model='" + model + '\'' +
+ ", context=" + context +
+ '}';
+ }
+
private void consistencyChecks() {
if (model != null && getMainURI() != null && getResources() != null &&
!getResources().isEmpty()) {
throw new IllegalStateException("JITDMNPayload should not contain
both (main) model and resources collection");
diff --git
a/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java
b/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java
index c700d02e0..8412136a6 100644
---
a/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java
+++
b/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java
@@ -109,7 +109,7 @@ class DMN15Test {
.statusCode(200)
.extract()
.asString();
- LOG.info("Validate response: {}", response);
+ LOG.debug("Validate response: {}", response);
List<JITDMNMessage> messages = MAPPER.readValue(response,
LIST_OF_MSGS);
assertEquals(0, messages.size());
@@ -217,7 +217,7 @@ class DMN15Test {
.statusCode(200)
.extract()
.asString();
- LOG.info("Validate response: {}", response);
+ LOG.debug("Validate response: {}", response);
List<JITDMNMessage> messages = MAPPER.readValue(response,
LIST_OF_MSGS);
assertEquals(0, messages.size());
}
diff --git
a/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidatorResourceTest.java
b/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidatorResourceTest.java
index 68607cff1..9bbee47dd 100644
---
a/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidatorResourceTest.java
+++
b/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidatorResourceTest.java
@@ -38,6 +38,7 @@ import io.restassured.http.ContentType;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@QuarkusTest
@@ -66,7 +67,7 @@ public class DMNValidatorResourceTest {
.extract()
.asString();
- LOG.info("Validate response: {}", response);
+ LOG.debug("Validate response: {}", response);
List<JITDMNMessage> messages = MAPPER.readValue(response,
LIST_OF_MSGS);
assertEquals(1, messages.size());
assertTrue(messages.stream().anyMatch(m ->
m.getSourceId().equals("_E7994A2B-1189-4BE5-9382-891D48E87D47") &&
@@ -87,9 +88,9 @@ public class DMNValidatorResourceTest {
.extract()
.asString();
- LOG.info("Validate response: {}", response);
+ LOG.debug("Validate response: {}", response);
List<JITDMNMessage> messages = MAPPER.readValue(response,
LIST_OF_MSGS);
- assertTrue(messages.size() > 0);
+ assertFalse(messages.isEmpty());
assertTrue(messages.stream().anyMatch(m ->
m.getSourceId().equals("_E7994A2B-1189-4BE5-9382-891D48E87D47") &&
m.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_UNIQUE)));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]