1 2 Previous Next 16 Replies Latest reply on Jan 21, 2014 9:56 AM by David Ward

    How to update knowledge container dynamically

    Thang Do Newbie

      Hi everyone,

       

      I am trying to build a rules service which allow to add/remove rules dynamically at runtime. The idea is that: my service is running and wait for input data. When input data arrives, the service will load a set of rules, do reasoning and return result. The requirement is the rule set can be update (add/remove) dynamically when the service is still running.

      My understand is that I need to bind Rule component in Switchyard to a knowledge container and set interval for scanning for updates. Knowledge Services - SwitchYard - Project Documentation Editor


      My question is how to update the knowledge container dynamically without rebuild or deploy my service.


      I am using Switchyard 1.0.0 Final, Jboss eap 6.1, Jboss studio 7 with Switchyard plugin 4.1.3, Oracle jdk 1.7.0_45.

       

      Any help is appreciated.

      Thanks everyone.

        • 1. Re: How to update knowledge container dynamically
          synclpz Novice

          I think it might be done using knowledge repository (drools guvnor), but I've never tried.

           

          If you achieve any success with this scenario please let me know, it's very interesting, indeed!

          • 2. Re: How to update knowledge container dynamically
            Keith Babo Master

            Yes, you would basically:

             

            - Define a resource pointing to a change-set in switchyard.xml

            - Create the change-set file and point it at a repository

            - Put your rules and stuff in the repository (Guvnor)

             

            The first two are deployed with your application,  The third one is stored in the repository and can change independent of the application.

            • 3. Re: How to update knowledge container dynamically
              synclpz Novice

              Keith, could you please provide a link to a proper Guvnor to be used with switchyard? I'm not well into it, but I'd like much to try it. Especially with jBPM workflows and expert rules...

              • 4. Re: How to update knowledge container dynamically
                Thang Do Newbie

                Hi Viktor and Keith,

                 

                Thank you for your reply.

                I just gave a quick try as bellow but wasn't success, it may need some tweaks.

                 

                1. the change-set file: "demochangeset.xml":

                <change-set xmlns='http://drools.org/drools-5.0/change-set' xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'

                xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >

                     <add>

                          <resource source='http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/designerdemo/LATEST' type='PKG' basicAuthentication="enabled" username="admin" password="admin"/>

                     </add>

                </change-set>

                 

                2. I can use the change-set.xml file to trigger workflow and fire rules in java

                public static final void main(String[] args){

                     try {

                          KnowledgeBase kbase = readKnowledgeBase();

                          StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                                   // the simplest process

                          ksession.startProcess("designerdemo.sample");

                          ksession.fireAllRules();

                 

                     } catch (Throwable t) {

                           t.printStackTrace();

                     }

                 

                }

                private static KnowledgeBase readKnowledgeBase() throws Exception {

                 

                     KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                     kbuilder.add(ResourceFactory.newClassPathResource("demochangeset.xml"), ResourceType.CHANGE_SET);

                     KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();

                     knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());

                     return knowledgeBase;

                }


                3. I set the resource of the rule component in Switchyard to the change file, run testing and get this errors.

                error1.png

                 

                Kind regards,

                Thang

                • 5. Re: How to update knowledge container dynamically
                  David Ward Master

                  Thang,

                   

                  A couple ideas:

                   

                  1. SwitchYard 1.0.0.Final uses KIE/Drools/jBPM 6.0.0.Beta4.  What version of Guvnor did you compile your package with?  I ask because drools packages are just serialized classes, and the runtime is very sensitive that the versions line up.  so basically, you'd have to be running Guvnor with the same version as drools as is running in SwitchYard.
                  2. It's possible there could be a bug in SwitchYard 1.0.0.Final's release packaging with AS7, where a library in a module for classloading is not visible.  But we should verify #1 first.

                   

                  Thanks,

                  David

                  • 6. Re: How to update knowledge container dynamically
                    David Ward Master

                    Addendum: Sorry; your error trace is an eclipse one, not an AS7 one.  You need to make sure you have the right libraries available to eclipse, which for what you're doing is 6.0.0.Beta4.  Also, it appears to me that you are running an older Guvnor, as I believe the Package class is now in the org.drools.core.rule package, not org.drools.rule...

                    • 7. Re: How to update knowledge container dynamically
                      David Ward Master

                      Viktor,

                       

                      As I mentioned to Thang, the version of Drools SwitchYard 1.0.0.Final uses is 6.0.0.Beta4.  So, you should grab that version of Guvnor ("drools-wb-distribution"): http://goo.gl/lj75Cm

                       

                      SwitchYard 1.1 uses Drools 6.0.0.CR3, and SwitchYard 1.1.1 - which is being built into the upcoming JBoss Fuse Service Works 6 (formally known as the JBoss SOA Platform) - uses Drools 6.0.0.Final.

                       

                      David

                      • 8. Re: How to update knowledge container dynamically
                        David Ward Master

                        OOPS!

                         

                        Okay, all, as it turns out, I gave kcbabo some outdated information.  My bad - not his.  After speaking with someone on the Drools team, even though the CHANGE_SET resource type exist in the KIE public api, it is no longer the way you interact with Guvnor in 6.0.0.  Instead, Guvnor acts as it's own Maven2 repository, and you have to use SwitchYard's KIE container methodology to access it.  This is a multi-step process, however:

                        1. In your app, switchard.xml rules implementation has to use the <manifest><container releaseId="groupId:artifactId:version"/></manifest> form.
                        2. In your app, your pom.xml has to point to your Guvnor M2 repo, like this: http://pastebin.com/v3710WcX
                        3. In Guvnor, you have uploaded or created your kjar (the new way to "package" your knowledge), build and deploy it.
                        4. In your SwitchYard installation, you have to have installed all the extra maven/plexus/wagon jars to do the remote communication.  I did this myself by building the modules and adding them to JBoss EAP: http://goo.gl/2HkEdl
                        5. If you are not running Guvnor and SwitchYard in the same EAP instance (which you wouldn't likely), you need to start one of them up with a -Djboss.socket.binding.port-offset=10 (or some number) so the ports don't conflict.

                         

                        In all honestly, I have not yet reached success in this endeavor, as the published maven2 URL from Guvnor is giving me a 404.  This is probably a newbie error.  I am going to be talking to a different Drools team member to get past this, and will update this thread - and the SwitchYard documentation with exact steps - once I get everything working.

                         

                        David

                        • 9. Re: How to update knowledge container dynamically
                          synclpz Novice

                          Thanks, I see this is much intriguing %)

                          • 10. Re: Re: How to update knowledge container dynamically
                            David Ward Master

                            Follow-up on this...

                             

                            I was able to get this to successfully work, however I need to modify the instructions I started above.  Also, note that when I refer to "Guvnor" (the old name), I really mean the new "kie-drools-wb" web console application.

                             

                            So, the changes to my instructions:

                             

                            2. It is unnecessary to make any additions or changes to your project's pom.xml.  Instead, you add the kie-drools-wb console to your ~/.m2/settings.xml like so:

                                <profiles>
                                    <profile>
                                        <id>guvnor-m2-profile</id>
                                        <activation>
                                            <activeByDefault>true</activeByDefault>
                                        </activation>
                                        <repositories>
                                            <repository>
                                                <id>guvnor-m2-repo</id>
                                                <name>Guvnor M2 Repo</name>
                                                <url>http://localhost:8080/kie-drools-wb-distribution-wars-6.0.0.Final-eap-6_1/maven2/</url>
                                            </repository>
                                        </repositories>
                                    </profile>
                                </profiles>
                            
                            

                            You can also use a custom settings.xml via a system property: -Dkie.maven.settings.custom=/path/to/custom/settings.xml

                             

                            6. The kie-ci-6.0.0.Final jar module has to be replaced with one that is fixed for 6.0.1.Final, per jira DROOLS-367.

                             

                            7. Security has to be disabled for the maven2 repo URL in the kie-drools-wb war application.  Edit WEB-INF/classes/url_filter.yaml and move the /maven2/** entry to the exclude section of that file. This is also being addressed by the Drools team for 6.0.1.Final, but I don't have a jira id handy right now.

                             

                            After the above, simply referring to my kjar using the container element and releaseId caused KIE to pull down the kjar using maven libraries, and make it available to the drools runtime inside switchyard.

                             

                            David

                            • 11. Re: Re: How to update knowledge container dynamically
                              David Ward Master

                              Viktor, check out my Follow-up please.

                              • 12. Re: Re: Re: How to update knowledge container dynamically
                                David Ward Master

                                7. I'm checking to see if a code fix was needed to keep the security of the /maven2/** URI intact (I thought there was), but it appears one should just be able to add add another section to your settings.xml to do the client authentication bit:

                                        <server>
                                            <id>guvnor-m2-repo</id>
                                            <username>admin</username>
                                            <password>admin-123</password>
                                            <configuration>
                                                <wagonProvider>httpclient</wagonProvider>
                                                <httpConfiguration>
                                                    <all>
                                                        <usePreemptive>true</usePreemptive>
                                                    </all>
                                                </httpConfiguration>
                                            </configuration>
                                        </server>
                                
                                • 14. Re: How to update knowledge container dynamically
                                  Thang Do Newbie

                                  Thanks guys,

                                   

                                  I will check it out.

                                  1 2 Previous Next