[rules-users] KnowledgeAgent doesn't load dsl files and dslr file from a change-set correctly

Pegram, Macon zmpegram at choosehmc.com
Tue Jan 26 15:38:56 EST 2010


That's actually my ticket, and I've been hoping to get it resolved for
awhile now.  I've posted to this mailing list as well as the actual
ticket but haven't heard responses from anyone.

 

I've recently done more research into the issue, and have some updated
information that needs to be attached to the ticket (I'll try to get it
in shortly) but what it boils down to is a collision of two problems...

 

Problem 1: DSL and DSLR need to be in the same folder, but if you don't
explicitly list the resources for each item in the changeset, you can't
define an independent resource type.    This is kind of silly and in my
mind defeats the benefits of the change-set.  The benefit in my mind of
a change set is being able to point it at a folder and have it scan for
new rule additions as well as changes. 

 

Problem 2: Internally the identified resources in the change set are
held in a hashmap.  Since there's no ordering to a hashmap, when they're
pulled out and added to the knowledgebuilder they could be added in any
order.  In order for a DSL and DSLR to work, they have to be added to
the KnowledgeBuilder in the proper order (DSL first then DSLR).  It does
not matter what order you list them in the change set, the rebuild code
in the KnowledgeAgent framework does not enforce any concept of ordering
or priority to resource types.

 

The documentation (since 5.0.1) has suggested that at some point they
plan to have "autodetection" of file types which would solve for problem
#1, but problem #2 would remain without some priority given to how the
KnowledgeBuilder is being instructed to construct rule sets.  This
problem is present even in the latest 5.1 milestone.

 

Unfortunately this has driven us to choose between having a DSL or
having hot deployment of rules (we've chosen the later)

 

Macon

 

________________________________

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Steve Ronderos
Sent: Tuesday, January 26, 2010 2:58 PM
To: Rules Users List
Subject: Re: [rules-users] KnowledgeAgent doesn't load dsl files and
dslr file from a change-set correctly

 


Pritham, 

I've experienced this issue before as well.  It has to do with the way
that the KnowledgeAgent subscribes to resources.  I believe behind the
scenes the resources are loaded in an arbitrary order.  There is a JIRA
bug report already filed: 

https://jira.jboss.org/jira/browse/JBRULES-2377
<https://jira.jboss.org/jira/browse/JBRULES-2377>  

Hope this helps, 

Steve 

rules-users-bounces at lists.jboss.org wrote on 01/26/2010 01:07:29 PM:

> [image removed] 
> 
> [rules-users] KnowledgeAgent doesn't load dsl files and dslr file 
> from a change-set correctly 
> 
> Pritham 
> 
> to: 
> 
> rules-users 
> 
> 01/26/2010 01:10 PM 
> 
> Sent by: 
> 
> rules-users-bounces at lists.jboss.org 
> 
> Please respond to Rules Users List 
> 
> 
> I have a folder in classpath:
> 
> dsl/global.dsl
> rules/section-A.dslr
> rules/section-A/page-1.dslr
> 
> I create a knowledge base like this:
> 
> public KnowledgeBase createKnowledgeBase() throws
DroolsParserException,
> IOException {
> 
>     KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory
>             .newKnowledgeBuilder();
> 
>         knowledgeBuilder.add(ResourceFactory
>                 .newClassPathResource("dsl/global.dsl"),
>                 ResourceType.DSL);
>         knowledgeBuilder.add(ResourceFactory
>                 .newClassPathResource("rules/section-A.dslr"),
>                 ResourceType.DSLR);
>         knowledgeBuilder.add(ResourceFactory
>                 .newClassPathResource("rules/section-A/page-1.dslr"),
>                 ResourceType.DSLR);   
> 
>     if (knowledgeBuilder.hasErrors()) {
>         throw new
RuntimeException(knowledgeBuilder.getErrors().toString());
>     }
> 
>     KnowledgeBase knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase();
>    
>
knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages
());
> 
>     return knowledgeBase;
> }
> 
> // code
> knowledgeBase = createKnowledgeBase();
> session = knowledgeBase.newStatefulKnowledgeSession();
> // insert facts
> session.fireAllRules();
> session.dispose();   
> 
> The above code works and I can get a unit test to work that processes
rules
> accordingly. I can see my dslr converting to a drl using the "drl
viewer"
> correctly (provided I temporarily place the dsl file in the same
location
> since expander doesn't accept a relative path).
> 
> The problem, however is when I use a change-set.xml and a
KnowledgeAgent,
> things don't work 
> 
> code for loading via knowledgeAgent
> 
> public static KnowledgeBase loadKnowledgeBase() throws
> DroolsParserException, IOException {
>     agent = KnowledgeAgentFactory.newKnowledgeAgent("msll agent");
>    
>
agent.applyChangeSet(ResourceFactory.newClassPathResource("change-set.xm
l"));
> 
>     return agent.getKnowledgeBase();
> }   
> 
> 
> <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.xsd'
> >
>    <add>
>        <resource source='classpath:dsl/' type='DSL' />  
>        <resource source='classpath:rules/' type='DSLR' />    
>        <resource source='classpath:rules/section-A/' type='DSLR' />
>     </add>
> </change-set>
> 
> 
> I get the following generic drools errors:
> ERR 103] Line 4:0 rule 'rule_key' failed predicate:
> {(validateIdentifierKey(DroolsSoftKeywords.RULE))}? in rule[7,0]: [ERR
101]
> Line 7:0 no viable alternative at input 'import' in rule Con in rule
> attribute
> ...
> ...
> 
> The rules are same, folder location is the same. I believe that drools
has a
> problem resolving path (expander global.dsl) from the dslr file when
using a
> KnowlegeAgent since in the earlier strategy, one could build a dsl
into the
> knowledgeBuilder directly from the classpath.
> 
> Pl suggest.
> -- 
> View this message in context: http://n3.nabble.com/KnowledgeAgent-
<http://n3.nabble.com/KnowledgeAgent-> 
> doesn-t-load-dsl-files-and-dslr-file-from-a-change-set-correctly-
> tp139702p139702.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
<https://lists.jboss.org/mailman/listinfo/rules-users> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100126/a92ee59a/attachment.html 


More information about the rules-users mailing list