Drools KnowledgeAgent not picking up drl resource updates
by js203
Hi,
I am looking for a way to update drools rules files in our production
environment without having to go through a full application rebuild and
redeploy to pick up .drl modifications.
To make this seamless, I'm investigating using change sets but I can't get a
KnowledgeBase to update when a .drl is updated.
Here is the code I have, all files are in the /root/com/me/drools package:
*1. DroolsConfig.java - Helper class to configure and start a
KnowledgeAgent. It references a local change-set.xml to manage the Drools
resources and scan for resource changes every 2 seconds*
package com.me.drools;
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.builder.KnowledgeBuilderConfiguration;
import org.drools.io.ResourceChangeScannerConfiguration;
import org.drools.io.ResourceFactory;
public class DroolsConfig {
public KnowledgeBase getAgentKnowledgeBase() {
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
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 knowledgeAgent =
KnowledgeAgentFactory.newKnowledgeAgent("CS", aconf);
knowledgeAgent.applyChangeSet(ResourceFactory.newFileResource("/root/com/me/drools/change-set.xml"));
return knowledgeAgent.getKnowledgeBase();
}
}
*2. change-set.xml - Referenced from DroolsConfig and manages a local rules
file*
<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
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...'>
<add>
<resource source='file:/root/com/me/drools/personrules.drl'
type='DRL' />
</add>
</change-set>
To test this out I have the following JUnit. The aim is to run the test and
during the loop execution, change the condition in the drl so that the
KnowledgeBase updates and rule results differ.
*3. DroolsConfigTest.java - Tests DroolsConfig. Rule results should change
during loop execution if drl is updated*
package com.me.drools;
import org.drools.KnowledgeBase;
import org.drools.runtime.StatelessKnowledgeSession;
import org.junit.Test;
public class DroolsConfigTest {
@Test
public void testGetAgentKnowledgeBase() throws Exception {
Person person = new Person();
DroolsConfig droolsConfig = new DroolsConfig();
KnowledgeBase kb = droolsConfig.getAgentKnowledgeBase();
for (int i = 0; i < 10; i++) {
StatelessKnowledgeSession session =
kb.newStatelessKnowledgeSession();
session.execute(person);
Thread.currentThread().sleep(3000);
System.out.println(person.getErrors().size());
}
System.out.println("Errors: " + person.getErrors());
}
}
Just for reference here is PersonTO and the person.drl rules file.
*4. Person.java - Simple object to fire rules against*
package com.me.drools;
import java.util.ArrayList;
import java.util.List;
public class Person {
private String name;
private List<String> errors = new ArrayList<String>();
public void addError(final String error) {
errors.add(error);
}
public List<String> getErrors() {
return errors;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
*5. personrules.drl*
package com.me.drools
import com.me.drools.Person
dialect "java"
rule "name_is_null"
when
$p : Person( name == null )
then
$p.addError("Name is null");
end
So, as mentioned when the for loop in DroolsConfigTest is running, I'm
changing the condition in the personrules.drl file from name == null to name
!= null which should mean that errors are no longer added to the errors List
in Person.class but the error count keeps on going up.
Can anybody see why the KnowledgeAgent isn't updating and how I can make
this configuration work so that I can change the drl on the fly and have the
rules behave accordingly?
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-KnowledgeAgent-not-picking-up-dr...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Difficulty determining why I have score corruption
by megwoods
Hi,
I have been at this a couple of days now but I am getting score corruption
from a rule that does the following:
rule "to bigger gap"
when
$res: ResourceInstance()
$resList : ArrayList(size > 1)
from collect( TripAtTimeWithResource(resource == $res) )
then
-- Sort the list using custom comparator.
-- Measure a series of deltas between elements in the list.
-- If the delta is larger than a threshold add a soft constraint.
insertLogical(new IntConstraintOccurrence("to bigger gap",
ConstraintType.NEGATIVE_SOFT,delta * 10, ttrL));
end
The TripAtTimeWithResource is the planning entity.
I have checked the cloning and been through and checked that all equals and
hashcode methods and they are correct.
If I take this rule out the implementation functions as correctly.
Interestingly though I first prototyped this using a simple score and with
the same 'when' and 'then' clause (inserting a different fact) and no score
corruption was observed.
If anyone has any suggestions I would really like to hear from you.
Cheers Megan Woods
Extract from exception:
The workingMemory has 3 ConstraintOccurrence(s) in excess:
to bigger gap/NEGATIVE_SOFT:[TripAtTimeWithResource
[trip=a.c.t.p.p.m.TripInstance@43b, resource=All(17), startTime=TimeUnit
[minute=285]]]=750
to bigger gap/NEGATIVE_SOFT:[TripAtTimeWithResource
[trip=a.c.t.p.p.m.TripInstance@46c, resource=All(17), startTime=TimeUnit
[minute=75]]]=1700
to bigger gap/NEGATIVE_SOFT:[TripAtTimeWithResource
[trip=a.c.t.p.p.m.TripInstance@421, resource=All(17), startTime=TimeUnit
[minute=75]]]=960
The workingMemory has 4 ConstraintOccurrence(s) lacking:
overlapping trips with same
resource/NEGATIVE_HARD:[TripAtTimeWithResource
[trip=a.c.t.p.p.m.TripInstance@43b, resource=All(17), startTime=TimeUnit
[minute=285]]]=100
to bigger gap/NEGATIVE_SOFT:[TripAtTimeWithResource
[trip=a.c.t.p.p.m.TripInstance@421, resource=All(17), startTime=TimeUnit
[minute=75]]]=1710
to bigger gap/NEGATIVE_SOFT:[TripAtTimeWithResource
[trip=a.c.t.p.p.m.TripInstance@43b, resource=All(17), startTime=TimeUnit
[minute=285]]]=1650
to bigger gap/NEGATIVE_SOFT:[TripAtTimeWithResource
[trip=a.c.t.p.p.m.TripInstance@46c, resource=All(17), startTime=TimeUnit
[minute=75]]]=950
--
View this message in context: http://drools.46999.n3.nabble.com/Difficulty-determining-why-I-have-score...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
[Switchyard RuleService] Rule doesnt fire when in FireAllRules mode
by kurrent93
Im confused about why my rule isnt firing.
Im using Jboss SwitchYard.
This is the only difference from the switchyard perspective:
<rules:action name="sendData" type="FIRE_ALL_RULES"
entryPoint="AccountData"/>
And when I use EXECUTE the rule fires.
When I use FIRE_ALL_RULES, it never gets activated.
This is my rule:
| rule "OpenTrade-Open"
2. | agenda-group "OpenTrade"
3. | no-loop true
4. | dialect "mvel"
5. | when
6. | Tick( ) over window:time (1m) from entry-point "AccountData"
7. | then
8. | TradeOrder newTrade = new TradeOrder();
9. | newTrade.setSymbol( "EURUSD" );
10. | newTrade.setVolume( 1 );
11. | newTrade.setMt4username( "4002642" );
12. | newTrade.setStatus( OrderStatus.OPENING );
13. | newTrade.setOperation( "OP_BUY" );
14. | newTrade.setComment( "From Magick.Rhythm" );
15. | insert( newTrade );
16. | modifiedOrderList.add(newTrade);
17. | end
--
View this message in context: http://drools.46999.n3.nabble.com/Switchyard-RuleService-Rule-doesnt-fire...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Web services and Drools
by riri
Hello everyone,
I need to develop a web application that includes Drools as its rule engine
and would like to expose its functionality as web services. I would
appreciate some expert opinion on which framework would be easiest to learn
and to work with. Some of the posts I have seen regarding Drools and OSGi
refer to it as a "nightmare". Is that still true with the current version?
If anyone has had any experience with Spring, EJB or other and would like to
share I would be very interested since I am new to this domain. If there is
a case to be made about not using a framework at all then I would also like
to hear you out.
Best regards,
--
View this message in context: http://drools.46999.n3.nabble.com/Web-services-and-Drools-tp4021509.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Stuck on simple testcase
by Michiel Vermandel
Hi,
I wrote a quite simple unit test which I expected to succeed.
But it does not, it ends with a negative score.
Though, it is easy to see on sight that there is a zero-score solution possible.
So... something must be wrong in some of my rules.
I was wondering if it is possible to manually set all planning variables to what I expected them to be and then see which rule(s) break(s)?
So planning variables should not be changed anymore while solving.
I'm using drools planner 5.5.0.Final.
Thanks,
Michiel
-----------------
http://www.codessentials.com - Your essential software, for free!
Follow us at http://twitter.com/#!/Codessentials
13 years
Hello and my first question
by Bojan Janisch
Hello everybody,
this is my first post and also my first question to you.
I've searched the net for quite some hours now, but don't get any information regarding optionally conditions.
I'm using drools to annotate some textobjects and I'm stucking with the following rule:
When there are two named entities, one body side and one anatomy in a text (they're defined earlier by a textannotating system, so I'm working on annotated objects) and there is a optionally anatomic side (it contains generally something like "lateral" oder "medial" and so on), then generate me a new annotation.
So up to now I'm on this state:
Rule "Anatomic Side"
when
$NE1 : NE(Type.contains("body"))
$NE2 : NE(Type.contains("anatomy"))
//So here starts the problem
[$NE3 : NE(Type.contains("anatomic"))]
then
...
How can I set a condition as optionally or is there no such way?
Thanks everyone to who reads this.
Janisch
13 years
Re: [rules-users] Solution
by Wolfgang Laun
On 14/01/2013, Bojan Janisch <bojan.janisch(a)scai.fraunhofer.de> wrote:
>
> so if someone has the same problem, to get some options how to solve this
> problem.
Posting code that's grossly syntactically invalid isn't going to help.
-W
13 years