I am looking into ways to deploy multiple KieModule
s represented by multiple Maven artifacts into a single KieContainer
. Here are my requirements:
KieModule
and add it to the KieContainer
.Basically what would have been great is:
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
kContainer.addKieModule(someKieModule); // This doesn't exist
kContainer.addKieModule(someOtherKieModule); // This doesn't exist
So far, all I could see is that there's a one-to-one relationship in between KieContainer
and KieModule
. Is this true? I am also aware that I can group my artifacts under a parent artifact and deploy it every time it is updated, but I don't wan't to enforce my business users to group their artifacts (as that would also make them dependent on each other).
I am also open to alternative suggestions on how to achieve this (Maybe having multiple KieModule
's files, loop through them, and add them one by one into a KieContainer
)?
Thanks in advance.
Update
I am also experimenting with DeploymentService
, specifically KModuleDeploymentService
, but I am not sure if it achieves what I would like to achieve. I would also appreciate if you could enlighten me on this.
Update#2
It seems like KieBuilder
may help according to this. So do you think that:
KieFactory kf = KieFactory.Factory.get();
KieFileSystem kfs = kf.newKieFileSystem();
KieBuilder kb = ks.newKieBuilder(kfs);
kb.setDependencies(someKieModule, someOtherKieModule);
kb.build();
KieContainer kContainer = ks.getKieContainer(kr.getDefaultGAV());
would work?
This is the elementary sequence of actions for building a KieBase from a number of resources.
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
FileInputStream fis = new FileInputStream( "simple/simple2.drl" );
kfs.write( "src/main/resources/simple.drl",
kieServices.getResources().newInputStreamResource( fis ) );
FileInputStream fis1 = new FileInputStream( "simple/simple.dsl" );
kfs.write( "src/main/resources/simple.dsl",
kieServices.getResources().newInputStreamResource( fis1 ) );
FileInputStream fis2 = new FileInputStream( "simple/simple.dslr" );
kfs.write( "src/main/resources/simple.dslr",
kieServices.getResources().newInputStreamResource( fis2 ) );
KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
System.out.println( results.getMessages() );
throw new IllegalStateException( "### errors ###" );
}
KieContainer kieContainer =
kieServices.newKieContainer( kieServices.getRepository().getDefaultReleaseId() );
KieBase kieBase = kieContainer.getKieBase();