Skip to content
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

[KIE-1492] Allow KieRuntimeBuilder to also create and provide StatelessKieSession #6103

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

mariofusco
Copy link
Contributor

@mariofusco mariofusco commented Sep 25, 2024


import java.util.Map;

public interface RuntimeSession extends CommandExecutor {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced this interface to have a usable common ground between KieSession and StatelessKieSession. Note that they still exists with the same methods as before, so this change is totally backward compatible.

</dependencies>
<profiles>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These and other changes to poms file are actually not related to this fix, but they are meant to fix some tech debt to support old JVM versions that we don't need anymore.

testSimpleDrl(runtimeBuilder.newStatelessKieSession("statelessCanDrinkKSYaml"), "org.drools.yaml", false);
}

private void testSimpleDrl(RuntimeSession session, String assetPackage, boolean stateful) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'm using the new RuntimeSession interface to test both KieSession and StatelessKieSession with the same method.

@@ -115,6 +117,10 @@ Command newQuery(String identifier,
String name,
Object[] arguments);

default BatchExecutionCommand newBatchExecution(Command... commands) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @mariofusco
is this related to the overall task ? If so, could. you please explain why ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly related to this fix, it's just a convenience method that I added to create batch commands in a single line that I used in my test.

* @return a map with all registered channels.
*/
Map<String, Channel> getChannels();
public interface StatelessKieSession extends StatelessRuleSession, StatelessProcessSession, RuntimeSession, KieRuntimeEventManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not notice that before - but at very first sight I have the impression the hierarchies are somehow turned upside:
StatelessRuleSession and StatelessRuleSession should be "specialization" of StatelessKieSession, but as it is, StatelessKieSession is an aggregation of the two, creating an hard-binding: wdyt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately you're right, or at least the name of those interfaces are quite misleading, but we cannot change them if we want to keep backward compatibility.

Copy link
Contributor

@gitgabrio gitgabrio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mariofusco !!!
For the moment being I left some minor comments.
As side-note, and not specifically related to this PR, I have the impression that the whole "KieSession" (statefull/stateless/etc) hierarchy would benefit from a good review, but surely not in this PR
I need slighlty more time to dig in the code itself

@tkobayas
Copy link
Contributor

tkobayas commented Sep 26, 2024

Thanks, Mario.

GHA kogito-runtimes (and other downstreams):

2024-09-25T16:38:02.4742156Z [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project jbpm-flow: Compilation failure
2024-09-25T16:38:02.4744813Z [ERROR] /home/runner/work/incubator-kie-drools/incubator-kie-drools/apache_incubator-kie-kogito-runtimes/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/DummyKnowledgeRuntime.java:[65,1] org.jbpm.process.instance.DummyKnowledgeRuntime is not abstract and does not override abstract method <T>execute(org.kie.api.command.Command<T>) in org.kie.api.runtime.CommandExecutor

DummyKnowledgeRuntime needs to implement execute or CommandExecutor.execute should have a default implementation.

@mariofusco
Copy link
Contributor Author

Thanks, Mario.

GHA kogito-runtimes (and other downstreams):

2024-09-25T16:38:02.4742156Z [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project jbpm-flow: Compilation failure
2024-09-25T16:38:02.4744813Z [ERROR] /home/runner/work/incubator-kie-drools/incubator-kie-drools/apache_incubator-kie-kogito-runtimes/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/DummyKnowledgeRuntime.java:[65,1] org.jbpm.process.instance.DummyKnowledgeRuntime is not abstract and does not override abstract method <T>execute(org.kie.api.command.Command<T>) in org.kie.api.runtime.CommandExecutor

DummyKnowledgeRuntime needs to implement execute or CommandExecutor.execute should have a default implementation.

This is the result of a HUGE technical debt caused by the tight coupling between Drools and Kogito's processes that has no longer reason to exist. I spent a couple of hours trying to refactor Kogito and lower this coupling, but unfortunately this is clearly a multi-days effort, so I gave up for now and fixed the issue in the most straightforward way with this pull request apache/incubator-kie-kogito-runtimes#3681

That said, I'm still willing to solve this debt with more calm when I will have time to dedicate to this, possibly with the help of @elguardian and @fjtirado. I already have a very preliminary question for you 2: is that DummyKnowledgeRuntime still necessary for some reasons (and why) or could it be totally removed? I'm asking because this seems to be a hack that it is also a source of a big part of the issues that I found during this first refactor attempt.

@tkobayas @gitgabrio please review again.

@fjtirado
Copy link
Contributor

fjtirado commented Sep 26, 2024 via email

@gitgabrio
Copy link
Contributor

@mariofusco @fjtirado @elguardian
There is an ongoing task for that: I started make the analysis to remove all the *processes references from drools repository, but I have to finish another ticket before.
@elguardian ?
Anyway, let's avoid duplicate the effort, and stay sync with that

@mariofusco
Copy link
Contributor Author

@mariofusco @fjtirado @elguardian There is an ongoing task for that: I started make the analysis to remove all the *processes references from drools repository, but I have to finish another ticket before. @elguardian ? Anyway, let's avoid duplicate the effort, and stay sync with that

I agree on avoid duplicating the effort, and if possible I would like to work on this on small-ish steps. For now I will try to remove that DummyKnowledgeRuntime class as suggested by @fjtirado or is there anybody else working on this? /cc @elguardian

@gitgabrio If this pull request ok for you? If so can you please approve so I could merge and move forward with that rework?

@mariofusco
Copy link
Contributor Author

I just realized there are a few failing tests, another side effect of that coupling I guess :(
I will fix them immediately.

@gitgabrio
Copy link
Contributor

gitgabrio commented Sep 26, 2024

@mariofusco

If this pull request ok for you?

Fine for me as soon as the build is green 👍

For now I will try to remove that DummyKnowledgeRuntime class as suggested by @fjtirado or is there anybody else working on this? /cc @elguardian

Fine for me

@mariofusco mariofusco merged commit 7d11b92 into apache:main Sep 27, 2024
9 of 10 checks passed
@mariofusco mariofusco deleted the k1492 branch September 27, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow KieRuntimeBuilder to also create and provide StatelessKieSession
4 participants