Dynamic loading of rules

1,089 views
Skip to first unread message

Priyanka

unread,
Apr 11, 2017, 5:21:58 AM4/11/17
to Drools Usage
Hi,

My rules are on hdfs I did write a program to load rules files (drl files) from hdfs and create kieSession. Now I want a mechanism to dynamically reload the rules when updated.

As I read through documents, "KnowledgeAgent" is replaced by "KieScanner".
My questions are as follows
1. KieScanner works only with kjars. Does this mean I will have to package my rules in a jar?
2. When a rule is changed the jar needs to be re-built with new version? I can't have this jar in local/maven repository so I should have it in classpath?
3. If I use kjar can I still grammatically load rules? I didn't find any example doing so.
4. Is there any other way to scan for changes? Provided your rules could be hosted on some server so you use URL or they are on HDFS?

-Priyanka

Abhijit Humbe

unread,
Apr 11, 2017, 8:51:55 AM4/11/17
to drools...@googlegroups.com


Abhijit Humbe

On Tue, Apr 11, 2017 at 2:51 PM, Priyanka <priyank...@gmail.com> wrote:
Hi,

My rules are on hdfs I did write a program to load rules files (drl files) from hdfs and create kieSession. Now I want a mechanism to dynamically reload the rules when updated.

As I read through documents, "KnowledgeAgent" is replaced by "KieScanner".
My questions are as follows
1. KieScanner works only with kjars. Does this mean I will have to package my rules in a jar?
>> Yes, for rules you have to create kjar if you want to use kieScanner API's. KieScanner is maven based so we have to use kjar.
2. When a rule is changed the jar needs to be re-built with new version? I can't have this jar in local/maven repository so I should have it in classpath?
>>Its not necessary to build kjar with new version, you can keep the version same then you have to use LATEST keyword in kieScanner API. To use kieScanner API's kjar should be available in local/remote maven repository,
3. If I use kjar can I still grammatically load rules? I didn't find any example doing so.
>> Even if you use kjar you can load it from classpath, add kjar in project classpath and use below code:
KieServices kieService = KieServices.Factory.get();
KieContainer kieContainer = kieService.getKieClasspathContainer();
 KieSession ksession= kieContainer.newKieSession("statefulSession");
 
4. Is there any other way to scan for changes? Provided your rules could be hosted on some server so you use URL or they are on HDFS?
Without kjar ? I guess its not possible. If kjar is available in maven repository then we can give its direct URL to get latest version.

-Priyanka

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/e7d96908-10eb-4375-b618-7ec3c7275da1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Priyanka

unread,
Apr 12, 2017, 1:21:25 AM4/12/17
to Drools Usage
Thanks for your response Abhijit.

So can I summarize it as, if I am not using kjar, I need to implement my own mechanism to detect rule changes and create ChangeSet and write it to KieFileSystem?

-Priyanka


On Tuesday, April 11, 2017 at 6:21:55 PM UTC+5:30, Abhijit Humbe wrote:


Abhijit Humbe

On Tue, Apr 11, 2017 at 2:51 PM, Priyanka <priyank...@gmail.com> wrote:
Hi,

My rules are on hdfs I did write a program to load rules files (drl files) from hdfs and create kieSession. Now I want a mechanism to dynamically reload the rules when updated.

As I read through documents, "KnowledgeAgent" is replaced by "KieScanner".
My questions are as follows
1. KieScanner works only with kjars. Does this mean I will have to package my rules in a jar?
>> Yes, for rules you have to create kjar if you want to use kieScanner API's. KieScanner is maven based so we have to use kjar.
2. When a rule is changed the jar needs to be re-built with new version? I can't have this jar in local/maven repository so I should have it in classpath?
>>Its not necessary to build kjar with new version, you can keep the version same then you have to use LATEST keyword in kieScanner API. To use kieScanner API's kjar should be available in local/remote maven repository,
3. If I use kjar can I still grammatically load rules? I didn't find any example doing so.
>> Even if you use kjar you can load it from classpath, add kjar in project classpath and use below code:
KieServices kieService = KieServices.Factory.get();
KieContainer kieContainer = kieService.getKieClasspathContainer();
 KieSession ksession= kieContainer.newKieSession("statefulSession");
 
4. Is there any other way to scan for changes? Provided your rules could be hosted on some server so you use URL or they are on HDFS?
Without kjar ? I guess its not possible. If kjar is available in maven repository then we can give its direct URL to get latest version.

-Priyanka

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.

Abhijit Humbe

unread,
Apr 12, 2017, 5:21:57 AM4/12/17
to drools...@googlegroups.com
Yes.

Abhijit Humbe

To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage+unsubscribe@googlegroups.com.

To post to this group, send email to drools...@googlegroups.com.

srinivas akella

unread,
May 24, 2017, 11:24:25 PM5/24/17
to Drools Usage

srinivas akella

unread,
May 24, 2017, 11:26:30 PM5/24/17
to Drools Usage
I am looking for similar solution. I can create kjar but I am thinking of storing the rules in database so that I can load the rules dynamically. Wanted to find out which is more efficient? KieScanner or DB approach?


On Tuesday, 11 April 2017 04:21:58 UTC-5, Priyanka wrote:

Priyanka

unread,
May 25, 2017, 3:00:30 AM5/25/17
to Drools Usage

The advantage of using kjar is uses can use drools workbench to define rules. I assume you will add rules to DB and not the rule files / kjar.
If you are okay to go away with advantage of using kjar DB should be fine ( I haven't tried it though). But if you really want to use kjar, you can write some logic to detect changes to kjar on hdfs.

-Priyanka

srinivas akella

unread,
May 25, 2017, 2:18:13 PM5/25/17
to Drools Usage
ok. 

How are you loading the new rules? using KieScanner or some other mechanism?

Priyanka

unread,
May 26, 2017, 1:34:53 AM5/26/17
to Drools Usage
I tried using kiescanner with HDFS unfortunately it fails while parsing URI.

I am thinking of this way:
1. When a container is launched copy the kjar from HDFS to local machine temp dir.
2. Initialize kieScanner to read the temp dir on local machine

It will be good change to drools code to be able to work with different file systems.

-Priyanka

srinivas akella

unread,
May 28, 2017, 1:42:34 AM5/28/17
to Drools Usage
OK. Are you using JBPM also?

for now, I am building the kjar to nexus repo and getting the latest by calling UpdatoVersion API.

I am not using KieScanner since I know when to update the rules so I am exposing an API to call UpdateToVersion API and it working fine.

Now I need to figure out how to autmatically deplyoy the kjar to nexus. Do you know?

Priyanka

unread,
May 29, 2017, 4:36:59 AM5/29/17
to Drools Usage
I haven't tried it, but there is some maven plugin to do this. You will need to config your maven repository and credentials properly.

-Priyanka
Reply all
Reply to author
Forward
0 new messages