[rules-users] Knowledge Base and Guvnor

Michael Anstis michael.anstis at gmail.com
Tue Jan 4 03:30:33 EST 2011


Hi,

You should be able to use the URL syntax with KnowledgeBuilder as follows:-

final String STANDARD_URL = "
http://your-guvnor-instance-host/org.drools.guvnor.Guvnor/package/standard/LATEST.drl
";
final String CUSTOMER_URL="
http://your-guvnor-instance-host/org.drools.guvnor.Guvnor/package/customer/LATEST.drl
";

KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

UrlResource standardUrlResource =
(UrlResource)ResourceFactory.newUrlResource(STANDARD_URL);
standardUrlResource.setBasicAuthentication("enabled");
standardUrlResource.setUsername("xyz");
standardUrlResource.setPassword("abc");

UrlResource customerUrlResource =
(UrlResource)ResourceFactory.newUrlResource(CUSTOMER_URL);
customerUrlResource.setBasicAuthentication("enabled");
customerUrlResource.setUsername("xyz");
customerUrlResource.setPassword("abc");

kbuilder.add( standardUrlResource, ResourceType.DRL);
kbuilder.add( customerUrlResource, ResourceType.DRL);

assertFalse( kbuilder.hasErrors() );
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

I don't think you'd need to (or want to) create two KnowledgeBases: You
could ensure "standard" rules are applied first by any of Drools' agenda
controls; i.e. salience, agenda-group or ruleflow; plus sharing a single
KnowledgeBase ensures rules in both packages that share patterns are
optimissed in the RETE network.

Use of ChangeSet could make things a little simpler too (rather than the
individual UrlResources).

Cheers,

Mike

On 3 January 2011 20:03, Dean Whisnant <dean at basys.com> wrote:

> Hi all, thank you for all the help in the past.
>
> I'm to a point in my project of implementing Guvnor built packages into my
> java code that calls drools.
>
> In the past I used the simple solution of building the knowledge agent on a
> .drl file as follows:
>
>        //Setup the knowledge session for drools
>        private static KnowledgeBase readKnowledgeBase() throws Exception {
>                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
>                                .newKnowledgeBuilder();
>
>  kbuilder.add(ResourceFactory.newClassPathResource("Standard837P.drl"),
>                                ResourceType.DRL);
>                KnowledgeBuilderErrors errors = kbuilder.getErrors();
>                if (errors.size() > 0) {
>                        for (KnowledgeBuilderError error : errors) {
>                                System.err.println(error);
>                        }
>                        throw new IllegalArgumentException("Could not parse
> knowledge.");
>                }
>                KnowledgeBase kbase =
> KnowledgeBaseFactory.newKnowledgeBase();
>                kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
>                return kbase;
>        }
>
> A little background before the question.  My project includes one set of
> rules that are standard business logic, we'll call that STANDARD for now and
> one set of rules that any one of my 45 customers could have created, we'll
> call CUSTOMER, on our common guvnor server.  My java code knows which
> customer is running the app, so determining which two packages I want to
> fire is simple.  The part that is not as straight forward for me is how I
> then I migrate using the guvnor urls in my above code.
>
> I thought it would be as easy as to replace "Standard837P.drl" above with
> the STANDARD url and create a second add that would use the CUSTOMER url.
>
> I also want all of my STANDARD rules applied before my CUSTOMER rules are
> applied.  This got me thinking that I need to have two independent knowledge
> bases running so that I fire all in the first and then fire all in the
> second.
>
> Backing up a bit again, my application looks through an incoming file
> inserting facts into the knowledge base for one medical claim line item,
> fires rules, writes out results to a database, and then moves on to the next
> claim line item in the file.
>
> 1) What would the syntax need to be to implement the STANDARD and CUSTOMER
> urls?
> 2) Would I need to create two independent knowledge bases?
> 3) DO you see any performance issues in this arrangement?
>
> Thank you!
>
> Dean
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110104/4130672e/attachment.html 


More information about the rules-users mailing list