-
Feature Request
-
Resolution: Done
-
Critical
-
None
-
None
-
NEW
-
NEW
Goal: Make a solver configuration XML file, a real member of a kjar. So it can be loaded ad hoc with kie-ci through maven.
For example: in workbench we create a cloudBalancing.solver file and deploy it to a maven repo. Our client app can now run this solver easily without having that file cloudBalancing.solver in it's original classpath - instead it loads it based on a maven GAV.
Presume we have these files:
org/cb/cloudBalancing.solver (the solver configuration)
<solver> <scoreDirectorFactory> <ksessionName>cloudBalancingKsession</ksessionName><!-- Value matches in kmodule.xml --> </scoreDirectorFactory> ... </solver>
META-INF/kmodule.xml
<kmodule> <kbase ...> <ksession name="cloudBalancingKsession"/><!-- the Drools rules --> </kbase> </kmodule>
The code above already works. But how would an API usage look like?
Proposal A) SolverFactory.createFromXmlResource(KieContainer, String)
org/cb/App.java
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();
SolverFactory<CloudBalance> solverFactory = SolverFactory.createFromXmlResource(
kieContainer, "org/cb/cloudBalancing.solver");
Proposal B) KieContainer.getSolverFactory(String) which returns Object
org/cb/App.java
KieServices kieServices = KieServices.Factory.get(); KieContainer kieContainer = kieServices.getKieClasspathContainer(); SolverFactory<CloudBalance> solverFactory = (SolverFactory) kieContainer.getSolverFactory( "org/cb/cloudBalancing.solver"); // Note: the ugly cast to SolverFactory is unavoidable because we can't move SolverFactory out of optaplanner-core [1]
Proposal C) A SolverFactory is a KieBase somehow and a Solver is a KieSession somehow.
META-INF/kmodule.xml
<kmodule> <kbase packages="org.cb.rules"> <ksession name="cloudBalancingKsession"/><!-- the Drools rules --> </kbase> <kbase packages="org.cb" file="cloudBalancing.solver"> <ksession name="cloudBalancingSolverFactory"/><!-- the Solver Configuration rules --> </kbase> </kmodule>
org/cb/App.java
KieServices kieServices = KieServices.Factory.get(); KieContainer kieContainer = kieServices.getKieClasspathContainer(); KieSession kSession = kieContainer.newKieSession("cloudBalancingSolverFactory"); Solver solver = (Solver) ksession.convertToSolver(); // Note: the ugly cast to SolverFactory is unavoidable because we can't move SolverFactory out of optaplanner-core [1]
[1] Why can't we move SolverFactory from optaplanner-core to kie-api? Why can't the reflection trick fix that?
- Because that interface has method signatures that expose Solution, Solver, ...
which in turn expose Score, ProblemFactChange, ScoreDirectorFactory, ...
which in turn expose SolverEventListener, ScoreDirector, ...
which in turn expose ConstraintMatchTotal, ConstraintMatch, ... - Because SolverFactory and Solver are part of the public api, so they can't move to another java package.
- duplicates
-
PLANNER-344 KContainer support: kie-api wrapper for SolverFactory and Solver so Workbench and Execution Server can treat it like a kjar
- Resolved
- relates to
-
PLANNER-253 Solver configuration must be able to use KieSession defined in kmodule.xml
- Resolved