-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DROOLS-5964] Implement PMML-Trusty/Scesim backend integration #3344
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
059e505
[DROOLS-5964] Begin implementation. Moved exceptions to specific package
gitgabrio f859690
Merge remote-tracking branch 'origin/master' into DROOLS-5964
gitgabrio c501ab7
[DROOLS-5964] Implemented PMMLScenarioRunnerHelper with tests. Update…
gitgabrio e9d1507
[DROOLS-5964] Implemented pmml-scesim backend integration. Implemente…
gitgabrio c909beb
Merge remote-tracking branch 'origin/master' into DROOLS-5964
gitgabrio 507f71f
[DROOLS-5964] Fixed AbstractScenarioRunner.getSpecificRunnerProvider …
gitgabrio c77b757
Merge remote-tracking branch 'origin/master' into DROOLS-5964
gitgabrio 87d66fd
Merge remote-tracking branch 'origin/main' into DROOLS-5964
gitgabrio f1b5dda
[DROOLS-5964] Working status. TODO: add tests, cleanup
gitgabrio 81b419a
Merge remote-tracking branch 'origin/main' into DROOLS-5964
gitgabrio fb2676f
Merge remote-tracking branch 'origin/main' into DROOLS-5964
gitgabrio ef1ece5
[DROOLS-5964] Working status.
gitgabrio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../java/org/drools/scenariosimulation/backend/exceptions/ImpossibleToFindPMMLException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2021 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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. | ||
*/ | ||
package org.drools.scenariosimulation.backend.exceptions; | ||
|
||
public class ImpossibleToFindPMMLException extends IllegalArgumentException { | ||
|
||
public ImpossibleToFindPMMLException(String message) { | ||
super(message); | ||
} | ||
|
||
public ImpossibleToFindPMMLException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ImpossibleToFindPMMLException(Throwable cause) { | ||
super(cause.getMessage(), cause); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...main/java/org/drools/scenariosimulation/backend/fluent/PMMLScenarioExecutableBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2021 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package org.drools.scenariosimulation.backend.fluent; | ||
|
||
import java.nio.file.FileSystems; | ||
import java.util.Objects; | ||
|
||
import org.drools.core.command.RequestContextImpl; | ||
import org.drools.scenariosimulation.backend.exceptions.ImpossibleToFindPMMLException; | ||
import org.kie.api.KieBase; | ||
import org.kie.api.pmml.PMML4Result; | ||
import org.kie.api.pmml.PMMLRequestData; | ||
import org.kie.api.runtime.KieContainer; | ||
import org.kie.api.runtime.KieRuntimeFactory; | ||
import org.kie.api.runtime.RequestContext; | ||
import org.kie.pmml.api.models.PMMLModel; | ||
import org.kie.pmml.api.runtime.PMMLRuntime; | ||
import org.kie.pmml.evaluator.core.PMMLContextImpl; | ||
import org.kie.pmml.evaluator.core.utils.PMMLRequestDataBuilder; | ||
|
||
public class PMMLScenarioExecutableBuilder { | ||
|
||
public static final String DEFAULT_APPLICATION = "defaultApplication"; | ||
public static final String PMML_RESULT = "pmmlResult"; | ||
public static final String PMML_MODEL = "pmmlModel"; | ||
|
||
private static final String SEPARATOR = FileSystems.getDefault().getSeparator(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to normalise the path to use |
||
|
||
private final KieContainer kieContainer; | ||
private final PMMLRequestDataBuilder pmmlRequestDataBuilder; | ||
private final String pmmlFilePath; | ||
|
||
private PMMLScenarioExecutableBuilder(KieContainer kieContainer, String pmmlFilePath, String pmmlModelName) { | ||
this.kieContainer = kieContainer; | ||
this.pmmlFilePath = pmmlFilePath; | ||
|
||
|
||
String fileName = pmmlFilePath.contains(SEPARATOR) ? pmmlFilePath.substring(pmmlFilePath.lastIndexOf(SEPARATOR) +1) : pmmlFilePath; | ||
pmmlRequestDataBuilder = new PMMLRequestDataBuilder("correlationid", pmmlModelName, fileName); | ||
} | ||
|
||
public static PMMLScenarioExecutableBuilder createBuilder(KieContainer kieContainer, String pmmlFilePath, | ||
String pmmlModelName) { | ||
return new PMMLScenarioExecutableBuilder(kieContainer, pmmlFilePath, pmmlModelName); | ||
} | ||
|
||
public void setValue(String key, Object value) { | ||
Class class1 = value.getClass(); | ||
pmmlRequestDataBuilder.addParameter(key, value, class1); | ||
} | ||
|
||
public RequestContext run() { | ||
Objects.requireNonNull(kieContainer, "KieContainer is null"); | ||
final PMMLRequestData pmmlRequestData = pmmlRequestDataBuilder.build(); | ||
final KieBase kieBase = kieContainer.getKieBase(); | ||
final KieRuntimeFactory kieRuntimeFactory = KieRuntimeFactory.of(kieBase); | ||
final PMMLRuntime pmmlRuntime = kieRuntimeFactory.get(PMMLRuntime.class); | ||
final PMMLModel pmmlModel = pmmlRuntime.getPMMLModel(pmmlRequestData.getModelName()) | ||
.orElseThrow(() -> new ImpossibleToFindPMMLException("Failed to retrieve model with name " + pmmlRequestData.getModelName())); | ||
final PMML4Result pmml4Result = pmmlRuntime.evaluate(pmmlRequestData.getModelName(), new PMMLContextImpl(pmmlRequestData)); | ||
final RequestContext toReturn = new RequestContextImpl(); | ||
toReturn.setOutput(PMML_RESULT, pmml4Result); | ||
toReturn.setOutput(PMML_MODEL, pmmlModel); | ||
return toReturn; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ackend/src/main/java/org/drools/scenariosimulation/backend/runner/PMMLScenarioRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2021 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
package org.drools.scenariosimulation.backend.runner; | ||
|
||
import org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorFactory; | ||
import org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO; | ||
import org.kie.api.runtime.KieContainer; | ||
|
||
public class PMMLScenarioRunner extends AbstractScenarioRunner { | ||
|
||
public PMMLScenarioRunner(KieContainer kieContainer, ScenarioRunnerDTO scenarioRunnerDTO) { | ||
super(kieContainer, | ||
scenarioRunnerDTO, | ||
ExpressionEvaluatorFactory.create( | ||
kieContainer.getClassLoader(), | ||
scenarioRunnerDTO.getSettings().getType())); | ||
} | ||
|
||
@Override | ||
protected AbstractRunnerHelper newRunnerHelper() { | ||
return new PMMLScenarioRunnerHelper(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yesamer
Do you think this is a problem for client side marshaller or in general do you expect any impact on Kogito/BC side?