Drools 6 support for changeset

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Drools 6 support for changeset

wtang

I have a requirement in which when a rule is changed, the change needs to be reflected immediately without retarting the system.

In Drools 5.x we can use the changeset.xml with the knowlegde agent.  Now in Drool 6.0 we have Kie API.

1) does Kie support changeset.xml?

2) Upper management don't want to use kie, they want to use jsr94.  Does jsr94 support changeset.xml?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

Mark Proctor

On 7 Dec 2013, at 00:41, wtang <[hidden email]> wrote:

>
> I have a requirement in which when a rule is changed, the change needs to be
> reflected immediately without retarting the system.
>
> In Drools 5.x we can use the changeset.xml with the knowlegde agent.  Now in
> Drool 6.0 we have Kie API.
>
> 1) does Kie support changeset.xml?
>
In 5.x you had to do this manually. This is now automated in 6.x, there is no need for a change set.
> 2) Upper management don't want to use kie, they want to use jsr94.  Does
> jsr94 support changeset.xml?
no

Mark

>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-6-support-for-changeset-tp4027138.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

wtang
Hi just tried a simple example in which I loop and then I change the rule but I did not see my changes taking place.  Please advice.

while(true) {
        Thread.sleep(100);
                    Message message = new Message();
                    message.setMessage("Hello World");
                    message.setStatus(Message.HELLO);
                    kSession.insert(message);
                    kSession.fireAllRules();
        }

// I change hello world rule while this loop is running but did not see my changes getting pick up.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

Mark Proctor
we have unit tests that say otherwise:
https://github.com/sotty/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/IncrementalCompilationTest.java

You’ll need to provide more information, or better still copy one of those unit tests to try and create a failed assertion that shows any issues.

Mark
On 11 Dec 2013, at 18:20, wtang <[hidden email]> wrote:

> Hi just tried a simple example in which I loop and then I change the rule but
> I did not see my changes taking place.  Please advice.
>
> while(true) {
>         Thread.sleep(100);
>            Message message = new Message();
>            message.setMessage("Hello World");
>            message.setStatus(Message.HELLO);
>            kSession.insert(message);
>            kSession.fireAllRules();
>         }
>
> // I change hello world rule while this loop is running but did not see my
> changes getting pick up.
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-6-support-for-changeset-tp4027138p4027225.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

wtang
Oh, I don't doubt for a moment that it is working.  I know it is working.  
What I am trying to figure out is what step am I missing.

I installed drool 6.0 Eclipse plugin and simply added a loop in the out of the box hello word example.

while the loop is running, I went into the eclipse editor, modify and saved the hello word example in Sample.drl to print out instead of "Hello World" "Hello World!!!!".

The loop just keeps on printing out "Hello World" and not my changes which is "Hello World!!!!".

Here is the hello world program, I just modified it to add the loop:

public static final void main(String[] args) {
        try {
       
            // load up the knowledge base
                KieServices ks = KieServices.Factory.get();
       KieContainer kContainer = ks.getKieClasspathContainer();
        KieSession kSession = kContainer.newKieSession("ksession-rules");

            // go !
        while(true) {
        Thread.sleep(100);
                    Message message = new Message();
                    message.setMessage("Hello World");
                    message.setStatus(Message.HELLO);
                    kSession.insert(message);
                    kSession.fireAllRules();
        }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

Mark Proctor
it’s not quite that automatic.

You can only do updates vis the dynamic modules system. you have to build jars and update to the latest jar.

Go through the KIE examples docs, and the unit tests I showed you.

Mark
On 11 Dec 2013, at 22:31, wtang <[hidden email]> wrote:

> Oh, I don't doubt for a moment that it is working.  I know it is working.  
> What I am trying to figure out is what step am I missing.
>
> I installed drool 6.0 Eclipse plugin and simply added a loop in the out of
> the box hello word example.
>
> while the loop is running, I went into the eclipse editor, modify and saved
> the hello word example in Sample.drl to print out instead of "Hello World"
> "Hello World!!!!".
>
> The loop just keeps on printing out "Hello World" and not my changes which
> is "Hello World!!!!".
>
> Here is the hello world program, I just modified it to add the loop:
>
> public static final void main(String[] args) {
>        try {
>        
>            // load up the knowledge base
>        KieServices ks = KieServices.Factory.get();
>        KieContainer kContainer = ks.getKieClasspathContainer();
>         KieSession kSession = kContainer.newKieSession("ksession-rules");
>
>            // go !
>         while(true) {
>         Thread.sleep(100);
>            Message message = new Message();
>            message.setMessage("Hello World");
>            message.setStatus(Message.HELLO);
>            kSession.insert(message);
>            kSession.fireAllRules();
>         }
>        } catch (Throwable t) {
>            t.printStackTrace();
>        }
>    }
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-6-support-for-changeset-tp4027138p4027231.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

wtang
you mentioned that I have to:

"build jars and update to the latest jar".

My question is do I have to write code to detect the changes in the rule first or Drool 6.0 can detect this for me?  It seems that nothing is automatic.

Again my goal is change a rule and be able to have the rule change take effect almost immediately.  In 5.x, I can use change-set and start the scanner service to accomplish this goal.  But in Drools 6.0, it seems I need to:

1) write code to detect that a rule has changed
2) write code using the KIE API to build the jar and update to this lastest jar

Please confirm.  Please give link to Drools documentation.



 
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

Mark Proctor
We do not have any file change listeners. You, or the workbench, needs to build the jar.

What is automatic is the role of change sets before. You no longer need to compute them, build the jar, have the client consume the jar  (with different ReleaseID) - that’s it. Drools diffs the current and target jar, and upgrades accordingly.

Mark
On 13 Dec 2013, at 05:11, wtang <[hidden email]> wrote:

> you mentioned that I have to:
>
> "build jars and update to the latest jar".
>
> My question is do I have to write code to detect the changes in the rule
> first or Drool 6.0 can detect this for me?  It seems that nothing is
> automatic.
>
> Again my goal is change a rule and be able to have the rule change take
> effect almost immediately.  In 5.x, I can use change-set and start the
> scanner service to accomplish this goal.  But in Drools 6.0, it seems I need
> to:
>
> 1) write code to detect that a rule has changed
> 2) write code using the KIE API to build the jar and update to this lastest
> jar
>
> Please confirm.  Please give link to Drools documentation.
>
>
>
>
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-6-support-for-changeset-tp4027138p4027271.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

lbilger
I thought that was what the KieScanner did? I spent some time trying to get it to work as I would expect it to, but ran into several problems that made me go back to 5.5 for now.

Here's what I did:
I created two maven projects, one to contain the rules ("drools6:rules") and one to use them ("drools6:drools6").
In "drools6:drools6" I created a Main class and method in which I initialize the KieContainer and KieScanner as follows:

        KieServices kieServices = KieServices.Factory.get();
        ReleaseId releaseId = kieServices.newReleaseId("drools6", "rules", "1.0.0-SNAPSHOT");
        final KieContainer kieContainer = kieServices.newKieContainer(releaseId);
        KieScanner kieScanner = kieServices.newKieScanner(kieContainer);
        kieScanner.start(1000);
        // Some code to see when rules were changed
        System.in.read(); // Keep the VM running while waiting for rule changes

Now I would expect the rules to be automatically picked up if I change them in "drools6:rules" and "mvn install" it. But no changes are detected. I debugged the KieScanner and it seems that it compares the version number of the releaseId to the one from the repository, which is "1.0.0-SNAPSHOT" in both cases, so the new jar is not considered newer.

So I thought, "OK, so I need to change the version number". I changed the version of the "drools6:rules" project to 1.0.1-SNAPSHOT. This didn't help either, because the releaseId explicitly requests 1.0.0-SNAPSHOT, so the newer version is never loaded.

My next idea was to use "LATEST" in the releaseId instead of an explicit version. At first this did not work for my local repository, but after manually editing the maven metadata file and adding a <latest> tag, it found the new version. But now, the KieScanner found a change every time it looked because it compared the version string "LATEST" to "1.0.1-SNAPSHOT" and always considered the "real" version newer. With a certain amount of rules and a short polling interval this caused the KieContainer to be busy rebuilding all the time and a very high CPU load.

I also tried deploying to a real maven repository instead of just installing to local, but with no success.


What am I missing here? Or isn't this how the KieScanner is supposed to work?

Thanks
Lars

Mark Proctor wrote
We do not have any file change listeners. You, or the workbench, needs to build the jar.

What is automatic is the role of change sets before. You no longer need to compute them, build the jar, have the client consume the jar  (with different ReleaseID) - that’s it. Drools diffs the current and target jar, and upgrades accordingly.

Mark
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

Mark Proctor

On 13 Dec 2013, at 13:51, lbilger <[hidden email]> wrote:

I thought that was what the KieScanner did?
KieScanner re-resolves the pom and it’s dependencies, and checks against what is currently deployed. If any of the versions have changed, it updates the current KieContainer.


I spent some time trying to get
it to work as I would expect it to, but ran into several problems that made
me go back to 5.5 for now.

Here's what I did:
I created two maven projects, one to contain the rules ("drools6:rules") and
one to use them ("drools6:drools6").
In "drools6:drools6" I created a Main class and method in which I initialize
the KieContainer and KieScanner as follows:

       KieServices kieServices = KieServices.Factory.get();
       ReleaseId releaseId = kieServices.newReleaseId("drools6", "rules",
"1.0.0-SNAPSHOT");
       final KieContainer kieContainer =
kieServices.newKieContainer(releaseId);
       KieScanner kieScanner = kieServices.newKieScanner(kieContainer);
       kieScanner.start(1000);
       // Some code to see when rules were changed
       System.in.read(); // Keep the VM running while waiting for rule
changes

Now I would expect the rules to be automatically picked up if I change them
in "drools6:rules" and "mvn install" it. But no changes are detected.
There is a limitation in 6.0.0 - fixed in master. Once you pass in the initial root releaseId - it resolves it to real version, and uses that for all scanNows. So only dependencies in the pom.xml will have their -SNAPSHOT re-resolved. The work around was to create a wrapper project.

A previous email "Re: [rules-users] Drools 6 and dynamic update”:
"On a side note, on master, there is a change to ensure that the Maven syntax for scanNow (with using the KieScanner) is obeyed. see
https://issues.jboss.org/browse/DROOLS-356"


I
debugged the KieScanner and it seems that it compares the version number of
the releaseId to the one from the repository, which is "1.0.0-SNAPSHOT" in
both cases, so the new jar is not considered newer.

So I thought, "OK, so I need to change the version number". I changed the
version of the "drools6:rules" project to 1.0.1-SNAPSHOT. This didn't help
either, because the releaseId explicitly requests 1.0.0-SNAPSHOT, so the
newer version is never loaded.

My next idea was to use "LATEST" in the releaseId instead of an explicit
version. At first this did not work for my local repository, but after
manually editing the maven metadata file and adding a <latest> tag, it found
the new version. But now, the KieScanner found a change every time it looked
because it compared the version string "LATEST" to "1.0.1-SNAPSHOT" and
always considered the "real" version newer. With a certain amount of rules
and a short polling interval this caused the KieContainer to be busy
rebuilding all the time and a very high CPU load.

I also tried deploying to a real maven repository instead of just installing
to local, but with no success.


What am I missing here? Or isn't this how the KieScanner is supposed to
work?
Try the latest snapshot, that has the above issue, in 356,  fixed.
http://downloads.jboss.org/drools/release/snapshot/6.0.x/

Thanks
Lars


Mark Proctor wrote
We do not have any file change listeners. You, or the workbench, needs to
build the jar.

What is automatic is the role of change sets before. You no longer need to
compute them, build the jar, have the client consume the jar  (with
different ReleaseID) - that’s it. Drools diffs the current and target jar,
and upgrades accordingly.

Mark





--
View this message in context: http://drools.46999.n3.nabble.com/Drools-6-support-for-changeset-tp4027138p4027279.html
Sent from the Drools: User forum mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

wtang
Can I forget all this and just use KieFileSystem?

Again my requirement is when a rule changed, I need to run with the lastest changes WITHOUT bringing down the server and rebuild jar and redeploy.

I have the following code and getRule() is just reading the .drl rule as a string stored as a CLOB in the database:

KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();

kfs.write("src/main/resources/org/kie/example5/HAL5.drl", getRule());

if (ruleHasChanged()) {
     KieBuilder kb = ks.newKieBuilder(kfs);
     kb.buildAll(); // kieModule is automatically deployed to KieRepository if successfully built.
}

KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
KieSession kSession = kContainer.newKieSession();
kSession.inserFact();
KSession.fireAllRules();

So I will do:

1) write my own logic to detect any rule changes in ruleHasChanged()
2) if any rules have changed, I will do buildAll() to build a new KieBase; otherwise, I don't call buildAll() and use the old KieBase.

Would this approach work per my requirement?
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

Mark Proctor
update the releaseID in the meta model, build it (it’ll be added to KieRepository). Then on the KieContainer do updatetoVersion(String releaseId) giving it the release ID you wish to update to, and it will update at runtime.

Mark
On 13 Dec 2013, at 23:39, wtang <[hidden email]> wrote:

> Can I forget all this and just use KieFileSystem?
>
> Again my requirement is when a rule changed, I need to run with the lastest
> changes WITHOUT bringing down the server and rebuild jar and redeploy.
>
> I have the following code and getRule() is just reading the .drl rule as a
> string stored as a CLOB in the database:
>
> KieServices ks = KieServices.Factory.get();
> KieRepository kr = ks.getRepository();
> KieFileSystem kfs = ks.newKieFileSystem();
>
> kfs.write("src/main/resources/org/kie/example5/HAL5.drl", getRule());
>
> if (ruleHasChanged()) {
>     KieBuilder kb = ks.newKieBuilder(kfs);
>     kb.buildAll(); // kieModule is automatically deployed to KieRepository
> if successfully built.
> }
>
> KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
> KieSession kSession = kContainer.newKieSession();
> kSession.inserFact();
> KSession.fireAllRules();
>
> So I will do:
>
> 1) write my own logic to detect any rule changes in ruleHasChanged()
> 2) if any rules have changed, I will do buildAll() to build a new KieBase;
> otherwise, I don't call buildAll() and use the old KieBase.
>
> Would this approach work per my requirement?
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-6-support-for-changeset-tp4027138p4027289.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

wtang
please cut and paste code example
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

ganeshneelekani
Hi All,

I am using drools version 5.4 and I used url of changeset.xml to call the the drools-guvnor from my java code.

Now  I am upgrading to drools 6.0 workbench version(Let me know if camel version is used), How can I call the drools workbench from my java code.



Thanks
Ganesh Neelekani
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

Mark Proctor

On 13 May 2014, at 11:57, ganeshneelekani <[hidden email]> wrote:

> Hi All,
>
> I am using drools version 5.4 and I used url of changeset.xml to call the
> the drools-guvnor from my java code.
>
> Now  I am upgrading to drools 6.0 workbench version(Let me know if camel
> version is used), How can I call the drools workbench from my java code.
read the docs for kie-ci jar, kiescanner class, and settings.xml. It also has some architecture diagrams and a cheat sheet diagram.
http://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html_single/#d0e791

Mark

>
>
>
> Thanks
> Ganesh Neelekani
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Drools-6-support-for-changeset-tp4027138p4029549.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools 6 support for changeset

skay
This post has NOT been accepted by the mailing list yet.
Hi,

Is it planned to get some equivalent to the KnowledgeAgent ?
reading this thread it seems that I'm not the only one needing that feature...
Drools 6.0 completely removes it from documentation. This is really annoying / It is not trvivial to build a scanner that implements KnowledgeAgent behaviour.