Well, actually KnowledgeAgent can't modify the rules. It can modify its internal kbase using the change-sets shown by jervis, but the rule sources are never modified by the agent. Basically you can start an agent with some initial change-set and all the rules present in the change-set resources are added to the agent's kbase. Once the agent is running you can add more resources using similar change-sets. You can even modify (remove, update) the rules inside the agent's kbase using change-sets too. Using ResourceScanner and Notifier, the agent is able to automatically detect changes on monitored resources and reflect the changes in its internal kbase. But as I said, the resources are never modified by the agent.
Hope I was clear. Best, On Thu, May 20, 2010 at 3:43 AM, Jervisliu <[email protected]> wrote: > With the new KnowledgeAgent API, you can not only connect to Guvnor > server remotely to store and retrieve rules, but also to add or update > rules. It also has basic authentication supported. Take a look at the > unit test: > > http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/agent/KnowledgeAgentTest.java > > Below is a very simple test case that connects to Guvnor to retrieve a > rule package, build a KnowledgeSession, then fire rules: > > public void testBasicAuthentication() throws Exception { > String xml = ""; > xml += "<change-set > xmlns='http://drools.org/drools-5.0/change-set'"; > xml += " xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'"; > xml += " > xs:schemaLocation='http://drools.org/drools-5.0/change-set > drools-change-set-5.0.xsd' >"; > xml += " <add> "; > xml += " <resource > source=' > http://localhost:8081/drools-guvnor/org.drools.guvnor.Guvnor/package/mortgages/LATEST > ' > type='PKG' basicAuthentication='enabled' username='admin' > password='admin'/>"; > xml += " </add> "; > xml += "</change-set>"; > File fxml = fileManager.newFile("changeset.xml"); > Writer output = new BufferedWriter(new FileWriter(fxml)); > output.write(xml); > output.close(); > > KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); > > ResourceChangeScannerConfiguration sconf = ResourceFactory > .getResourceChangeScannerService() > .newResourceChangeScannerConfiguration(); > sconf.setProperty("drools.resource.scanner.interval", "2"); > ResourceFactory.getResourceChangeScannerService().configure(sconf); > > KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory > .newKnowledgeAgentConfiguration(); > aconf.setProperty("drools.agent.scanDirectories", "true"); > aconf.setProperty("drools.agent.scanResources", "true"); > aconf.setProperty("drools.agent.newInstance", "true"); > KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( > "test agent", kbase, aconf); > > kagent.applyChangeSet(ResourceFactory.newUrlResource(fxml.toURI() > .toURL())); > > StatefulKnowledgeSession ksession = kagent.getKnowledgeBase() > .newStatefulKnowledgeSession(); > List<String> list = new ArrayList<String>(); > ksession.setGlobal("list", list); > ksession.fireAllRules(); > ksession.dispose(); > > assertEquals(2, list.size()); > assertTrue(list.contains("rule1")); > assertTrue(list.contains("rule2")); > } > > Hope this helps, > > Jervis > > Michael Rhoden wrote: > > Yes and no. Guvnor uses a JCR repository (the default is > > http://jackrabbit.apache.org/) which can not be accessed using > > hibernate directly. We ran into this issue, and the only way to use > > guvnor as of 6 months ago was to have a user go into guvnor and create > > a DRL file by clicking a few buttons. Not a big deal, but it isn't > > automated. You can then use that DRL as a resource in your > > application. I know there was some working being done to be able to > > pull out DRLs from Guvnor using xml calls, but don't know if that was > > ever completed. > > > > Michael Rhoden > > > > > > ----- Original Message ----- > > From: "bbarani" <[email protected]> > > To: [email protected] > > Sent: Wednesday, May 19, 2010 5:12:57 PM > > Subject: [rules-users] Drools with Guvnor > > > > > > Hi, > > > > I am very new to Drools and very very new to Guvnor. > > > > I am in the process of creating a rule engine which will fetch the > > data from > > a source (I am using Hibernate framework to fetch the data) and > > evaluate the > > data using Drools rule engine. The rules supplied to the Drools rule > > engine > > are stored in a Rules table in a database. > > > > Now my question is that can I use Guvnor to store the rules (instead of > me > > creating a rule data model) and use Guvnor to supply rules to my Drools > > engine? > > > > I am trying to find out the best possible way to create / manage a rule > > database (which stores all the rules). > > > > Thanks, > > BB > > -- > > View this message in context: > > > http://drools-java-rules-engine.46999.n3.nabble.com/Drools-with-Guvnor-tp830453p830453.html > > Sent from the Drools - User mailing list archive at Nabble.com. > > _______________________________________________ > > rules-users mailing list > > [email protected] > > https://lists.jboss.org/mailman/listinfo/rules-users > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > rules-users mailing list > > [email protected] > > https://lists.jboss.org/mailman/listinfo/rules-users > > > > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users > -- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Esteban Aliverti
_______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
