You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "AthiraHari77 (via GitHub)" <gi...@apache.org> on 2024/12/17 06:25:22 UTC
[PR] [Incubator kie issues#1619]Correctly manage execution of invalid models [incubator-kie-drools]
AthiraHari77 opened a new pull request, #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200
Fixes [https://github.com/apache/incubator-kie-issues/issues/1619]
In this PR, Decision models are validated to ensure correctness, and both valid and invalid decisions are identified and handled accordingly. In the event of an exception, a valid status is returned to reflect the error state accurately.
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
**Thank you for submitting this pull request**
**NOTE!:** Double-check the target branch for this PR.
The default is `main` so it will target Drools 8 / Kogito.
**Ports** If a forward-port or a backport is needed, paste the forward port PR here
* [link](https://www.example.com)
**Issue**: _(please edit the GitHub Issues link if it exists)_
* [link](https://www.example.com)
**referenced Pull Requests**: _(please edit the URLs of referenced pullrequests if they exist)_
* paste the link(s) from GitHub here
* link 2
* link 3 etc.
<details>
<summary>
How to replicate CI configuration locally?
</summary>
Build Chain tool does "simple" maven build(s), the builds are just Maven commands, but because the repositories relates and depends on each other and any change in API or class method could affect several of those repositories there is a need to use [build-chain tool](https://github.com/kiegroup/github-action-build-chain) to handle cross repository builds and be sure that we always use latest version of the code for each repository.
[build-chain tool](https://github.com/kiegroup/github-action-build-chain) is a build tool which can be used on command line locally or in Github Actions workflow(s), in case you need to change multiple repositories and send multiple dependent pull requests related with a change you can easily reproduce the same build by executing it on Github hosted environment or locally in your development environment. See [local execution](https://github.com/kiegroup/github-action-build-chain#local-execution) details to get more information about it.
</details>
<details>
<summary>
How to retest this PR or trigger a specific build:
</summary>
- for <b>pull request and downstream checks</b>
- Push a new commit to the PR. An empty commit would be enough.
- for a <b>full downstream build</b>
- for <b>github actions</b> job: add the label `run_fdb`
- for <b>Jenkins PR check only</b>
- If you are an ASF committer for KIE podling, login to Jenkins (https://ci-builds.apache.org/job/KIE/job/drools/), go to the specific PR job, and click on `Build Now` button.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie]
Posted by "tiagobento (via GitHub)" <gi...@apache.org>.
tiagobento closed pull request #6200: [Incubator-kie-issues#1619] Correctly manage execution of invalid models
URL: https://github.com/apache/incubator-kie/pull/6200
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie]
Posted by "tiagobento (via GitHub)" <gi...@apache.org>.
tiagobento commented on PR #6200:
URL: https://github.com/apache/incubator-kie/pull/6200#issuecomment-5234482691
Closing as stale.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator kie issues#1619]Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#discussion_r1888128925
##########
kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn:
##########
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
Review Comment:
@AthiraHari77 Please add the Apache legal header in all the DMN files you introduced
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "AthiraHari77 (via GitHub)" <gi...@apache.org>.
AthiraHari77 commented on code in PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#discussion_r1888761756
##########
kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn:
##########
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<definitions xmlns="https://www.omg.org/spec/DMN/20230324/MODEL/" expressionLanguage="https://www.omg.org/spec/DMN/20230324/FEEL/" namespace="https://kie.org/dmn/_CADD03FC-4ABD-46D2-B631-E7FDE384D6D7" id="_9C0A9728-3B31-45F3-933F-75763212194B" name="DMN_54AA2CFA-2374-4FCE-8F16-B594DFF87EBE" xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" xmlns:kie="https://kie.org/dmn/extensions/1.0">
Review Comment:
@yesamer I have updated here as well
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "pibizza (via GitHub)" <gi...@apache.org>.
pibizza commented on code in PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#discussion_r1888267530
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java:
##########
@@ -43,4 +53,198 @@ void buildFromConfiguration() {
.fromResources(Collections.emptyList()).getOrElseThrow(RuntimeException::new);
assertThat(retrieved).isNotNull();
}
+
+ @Test
+ void fromDefaultsMultipleDecisionWithoutInputDataReference() {
+ File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn");
+ assertThat(modelFile).isNotNull().exists();
+ Resource modelResource = ResourceFactory.newFileResource(modelFile);
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(
+ nameSpace,
+ "DMN_1A4BD262-7672-4887-9F25-986EE5277D16");
+ assertThat(dmnModel).isNotNull();
+ DMNContext context = DMNFactory.newContext();
+ context.set( "Person Age", 24 );
+ String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) ";
+ assertThatThrownBy(() -> dmnRuntime.evaluateAll(dmnModel, context))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(errorMessage);
+ }
+
+ @Test
+ void evaluateMultipleDecisionModel() {
+ File modelFile = FileUtils.getFile("MultipleDecision.dmn");
+ assertThat(modelFile).isNotNull().exists();
+ Resource modelResource = ResourceFactory.newFileResource(modelFile);
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace = "https://kie.org/dmn/_CADD03FC-4ABD-46D2-B631-E7FDE384D6D7";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(
+ nameSpace,
+ "DMN_54AA2CFA-2374-4FCE-8F16-B594DFF87EBE");
+ assertThat(dmnModel).isNotNull();
+ DMNContext context = DMNFactory.newContext();
+ context.set( "Person Age", 24 );
+ DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, context);
+ assertThat(dmnResult).isNotNull();
+ }
+
+ @Test
+ void evaluateWrongDecisionWithoutInputDataReferencesByName() {
+ File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn");
+ assertThat(modelFile).isNotNull().exists();
+ Resource modelResource = ResourceFactory.newFileResource(modelFile);
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(
+ nameSpace,
+ "DMN_1A4BD262-7672-4887-9F25-986EE5277D16");
+ assertThat(dmnModel).isNotNull();
+ DMNContext context = DMNFactory.newContext();
+ context.set( "Person Age", 24 );
+ String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) ";
+ assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"))
Review Comment:
I would go for the more readable assertThatIllegalStateExceptionIsThrownBy(.... Consider this also in the other tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "AthiraHari77 (via GitHub)" <gi...@apache.org>.
AthiraHari77 commented on code in PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#discussion_r1888763894
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java:
##########
@@ -43,4 +53,198 @@ void buildFromConfiguration() {
.fromResources(Collections.emptyList()).getOrElseThrow(RuntimeException::new);
assertThat(retrieved).isNotNull();
}
+
+ @Test
+ void fromDefaultsMultipleDecisionWithoutInputDataReference() {
+ File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn");
+ assertThat(modelFile).isNotNull().exists();
+ Resource modelResource = ResourceFactory.newFileResource(modelFile);
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(
+ nameSpace,
+ "DMN_1A4BD262-7672-4887-9F25-986EE5277D16");
+ assertThat(dmnModel).isNotNull();
+ DMNContext context = DMNFactory.newContext();
+ context.set( "Person Age", 24 );
+ String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) ";
+ assertThatThrownBy(() -> dmnRuntime.evaluateAll(dmnModel, context))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(errorMessage);
+ }
+
+ @Test
+ void evaluateMultipleDecisionModel() {
+ File modelFile = FileUtils.getFile("MultipleDecision.dmn");
+ assertThat(modelFile).isNotNull().exists();
+ Resource modelResource = ResourceFactory.newFileResource(modelFile);
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace = "https://kie.org/dmn/_CADD03FC-4ABD-46D2-B631-E7FDE384D6D7";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(
+ nameSpace,
+ "DMN_54AA2CFA-2374-4FCE-8F16-B594DFF87EBE");
+ assertThat(dmnModel).isNotNull();
+ DMNContext context = DMNFactory.newContext();
+ context.set( "Person Age", 24 );
+ DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, context);
+ assertThat(dmnResult).isNotNull();
+ }
+
+ @Test
+ void evaluateWrongDecisionWithoutInputDataReferencesByName() {
+ File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn");
+ assertThat(modelFile).isNotNull().exists();
+ Resource modelResource = ResourceFactory.newFileResource(modelFile);
+ DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+ .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(
+ nameSpace,
+ "DMN_1A4BD262-7672-4887-9F25-986EE5277D16");
+ assertThat(dmnModel).isNotNull();
+ DMNContext context = DMNFactory.newContext();
+ context.set( "Person Age", 24 );
+ String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) ";
+ assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"))
Review Comment:
@pibizza Updated the test cases as specified
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on code in PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#discussion_r1888256182
##########
kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn:
##########
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<definitions xmlns="https://www.omg.org/spec/DMN/20230324/MODEL/" expressionLanguage="https://www.omg.org/spec/DMN/20230324/FEEL/" namespace="https://kie.org/dmn/_CADD03FC-4ABD-46D2-B631-E7FDE384D6D7" id="_9C0A9728-3B31-45F3-933F-75763212194B" name="DMN_54AA2CFA-2374-4FCE-8F16-B594DFF87EBE" xmlns:dmndi="https://www.omg.org/spec/DMN/20230324/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:di="http://www.omg.org/spec/DMN/20180521/DI/" xmlns:kie="https://kie.org/dmn/extensions/1.0">
Review Comment:
@AthiraHari77 License header is still missing here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#discussion_r1893552254
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java:
##########
@@ -754,6 +760,15 @@ private static String getDependencyIdentifier(DMNNode callerNode, DMNNode node)
}
+ private static void identifyDecisionErrors(DMNModel model, String... decisions) {
+ List<DMNMessage> errorMessages = model.getMessages(DMNMessage.Severity.ERROR);
+ List<String> identifiedErrors = errorMessages.stream().map(Message::getText)
Review Comment:
HI @AthiraHari77
Many thanks for the PR.
I'm only slightly concerned about this assertion.
The logic here is that
1) `decisions` could be `decisionsId` or `decisionName` (IINW)
2) if an error message _**contains**_ one of them, then the decisions it relates to is "wrong"
I'm afraid there could be some cases where an error message contains the decisionId or decisionName, but that the error is not in the decision itself (e.g. another element that refer that decision)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "AthiraHari77 (via GitHub)" <gi...@apache.org>.
AthiraHari77 commented on code in PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#discussion_r1888145680
##########
kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn:
##########
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
Review Comment:
@yesamer Updated Apache legal header in all the DMN files
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [Incubator-kie-issues#1619] Correctly manage execution of invalid models [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on PR #6200:
URL: https://github.com/apache/incubator-kie-drools/pull/6200#issuecomment-2556501746
@gitgabrio @AthiraHari77 I ran the TCK tests against those changes, and there is only one new test failure:
`1131 - feel -function invocation test: Non existing function evaluates to null (10.3.2.13.2)`
I guess we should return null in case those errors occur.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org