[rules-users] DSL, DSLR and Changesets...

Pegram, Macon zmpegram at choosehmc.com
Tue Oct 27 00:35:28 EDT 2009


I should've mentioned this was in Drools 5.0.1.

 

I've created a small test app which demonstrates the issue.   I've
attached it to this message:

 

Macon

________________________________

From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Pegram, Macon
Sent: Monday, October 26, 2009 4:36 PM
To: Rules Users List
Subject: [rules-users] DSL, DSLR and Changesets...

 

All,

 

Are DSL and DSLR files supported by the KnowledgeAgent / Changeset code.
Here's the details of my test case:

 

I have a Changeset file I'm trying to load which looks like the
following:

 

<?xml version="1.0" encoding="UTF-8"?>

<change-set xmlns='http://drools.org/drools-5.0/change-set'

             xmlns:xs='http://www.w3.org/2001/XMLSchema-instance' >

   <add>

        <resource source="classpath:com/test/general/" type="DSL" />

        <resource source="classpath:com/test/general/" type="DSLR" />

   </add>

</change-set>

 

There's a single DSL and a single DSLR file in this folder.   I'm
loading the change set as follows:

 

KnowledgeAgent ka = KnowledgeAgentFactory.newKnowledgeAgent(agentName);

      ka.applyChangeSet(ResourceFactory.newClassPathResource(agentName +
"-changeset.xml", getClass()));

 

When I run this code, the logger suggests the DSL and DSLR are being
loaded and compiled:

 

[2009:10:299 16:10:52:info] KnowledgAgent created, with configuration:

monitorChangeSetEvents=true scanResources=true scanDirectories=true

++ Constructing and applying changeSet: dsl-test

[2009:10:299 16:10:52:info] KnowledegAgent has started listening for
ChangeSet notifications

(null: 3, 68): cvc-elt.1: Cannot find the declaration of element
'change-set'.

[2009:10:299 16:10:317:info] KnowledgAgent applying ChangeSet

[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to
directory=[ClassPathResource path='com/test/general/']

[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl at b9b618 to
resource=[ClassPathResource path='com/test/general/']

[2009:10:299 16:10:317:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl at 61ec49 to
resource=[ClassPathResource path='com/test/general/']

[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to directory
content resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']

[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl at b9b618 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']

[2009:10:299 16:10:317:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl at 61ec49 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']

[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to directory
content resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']

[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl at b9b618 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']

[2009:10:299 16:10:317:debug] ResourceChangeScanner subcribing
notifier=org.drools.io.impl.ResourceChangeNotifierImpl at 61ec49 to
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']

[2009:10:299 16:10:317:debug] KnowledgeAgent subscribing to
directory=[ClassPathResource path='com/hmc/test/general/']

[2009:10:299 16:10:317:debug] ResourceChangeNotification subscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl at b9b618 to
resource=[ClassPathResource path='com/hmc/test/general/']

[2009:10:299 16:10:317:debug] KnowledgeAgent ChangeSet requires
KnowledgeBuilder

[2009:10:299 16:10:317:debug] KnowledgeAgent rebuilding KnowledgeBase
using ChangeSet

[2009:10:299 16:10:317:debug] KnowledgeAgent building
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test.dsl']

[2009:10:299 16:10:333:debug] KnowledgeAgent building
resource=[FileResource
file='C:\bea\user_projects\workspaces\alerts\rules-kb\test-kb\target\tes
t-classes\com\test\general\test-dsl.dslr']

[2009:10:299 16:10:333:info] KnowledgeAgent new KnowledgeBase now built
and in use

 

However after load is completed I try to run the following code:

      

      System.out.println("KB Info");

      Collection<KnowledgePackage> pkgs =
ka.getKnowledgeBase().getKnowledgePackages();

      for (KnowledgePackage kp : pkgs) {

            for (Rule rule : kp.getRules()) {

                  System.out.println("Rule: " + rule.getName() + ", " +
ule.getPackageName());

                        for (String attribs : rule.listMetaAttributes())

                              System.out.println("---- " + attribs);

                  }

            }

            }

 

I get NO output (except of course "KB Info").

 

If I initialize the knowledgebase like this:

 

            KnowledgeBuilder kbuilder = KnowledgeBuilderFactory

                        .newKnowledgeBuilder();

            kbuilder.add(ResourceFactory

 
.newClassPathResource("com/test/general/test.dsl"),

                        ResourceType.DSL);

 

            kbuilder.add(ResourceFactory

 
.newClassPathResource("com/test/general/test-dsl.dslr"),

                        ResourceType.DSLR);

 

            if (kbuilder.hasErrors()) {

                  throw new Exception(kbuilder.getErrors().toString());

            }

 

            KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();

            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

      }

 

... and run the same output code I get a list of the rules that were
loaded.

 

Any clues why the different behavior?

 

Macon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091027/5f98f80c/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dsl-demo.zip
Type: application/x-zip-compressed
Size: 4575 bytes
Desc: dsl-demo.zip
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20091027/5f98f80c/attachment.bin 


More information about the rules-users mailing list