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