Guvnor - Unable to fire rules from standalone java
by rganesh84
I am new to drools and even more new to Guvnor.
I have a below code with simple rules (just 2) which doesn't work as
expected, any help would be greatly appreciated.
I attempted to copy the contents of guvnor generated drl file to a local drl
file and tested with drools expert, it works well.
For the below program,
Drools expert (minor changes to java program -
ResourceFactory.newClassPathResource("test.drl")) show the s.o.p (after
firing 1st rule) and prints 90000 (after firing 2nd rule) as expected.
Drools guvnor prints salary as 0.0.
Not sure what is going wrong while integrating with Guvnor, doesn't work as
expected. need help!
[code]
/* Java main method. */
public static void main(String as[]){
KnowledgeBase kbase = readKnowledgeBase1();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Employee employee = new Employee();
employee.setName("David");
employee.setExperience(1);
ksession.insert(employee);
ksession.fireAllRules();
System.out.println(employee.getSalary());
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeAgentConfiguration kaconf = KnowledgeAgentFactory
.newKnowledgeAgentConfiguration();
kaconf.setProperty("drools.agent.scanDirectories", "false");
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("test
agent", kaconf);
kagent.applyChangeSet(ResourceFactory.newClassPathResource("change-set.xml"));
return kbase;
}
/* Change set xml contents: */
<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
http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/...'
>
<add>
<resource
source='http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/org.drools.guvnor.Guv...'
type='DRL'
basicAuthentication="enabled" username="admin" password="admin"/>
</add>
</change-set>
/* Rule file as downloaded from the below link
*
http://localhost:8080/guvnor-5.5.0.Final-tomcat-6.0/rest/packages/Employe...
*/
package EmployeeDetails
import com.sample.Employee
rule "Rule 1"
no-loop true
dialect "mvel"
when
Employee( experience < 3 )
then
System.out.println("User does not have enough experience");
end
rule "Rule 2"
no-loop true
dialect "mvel"
when
emp : Employee( name == "David" )
then
emp.setSalary( 90000 );
update( emp );
end
[/code]
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-Unable-to-fire-rules-from-standa...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
'modify' and 'update' do not work in rules
by mukha
Hi all,
I am using /OptaPlanner/ ver. *6.0.Beta3*.
And I try to call one rule for preparation purposes. I try 3 options:
*1)* By defining additional problem facts /EmployeeAssignment/ for each
employee. Here I am trying to change only its property like this:
/rule "First rule"
salience 1
when
$employeeAssignment : EmployeeAssignment($employee : employee)
accumulate
(
$request : Request(assignedTo == $employee, $points : points),
$assignedPoints : sum($points)
)
then
$employeeAssignment.setAssignedPoints($assignedPoints.intValue());
update($employeeAssignment);
end/
That variant compiles well, but did not even start (e.g. when I try
benchmark it stops on "Warming up started" message and did not do anything).
*2)* Same with /modify($employeeAssignment) {...}/
*3)* The last one is with /insertLogical/. I did not use here
/EmployeeAssignment/ as additional problem fatcs, but just use:
/then
insertLogical(new EmployeeAssignment($employee, $assignedRequests,
$assignedPoints.intValue()));
end/
It works, but with low performance (examples were simplified).
Can you tell me what can be wrong with the 1) and 2) ?
Thank you for your time!
--
View this message in context: http://drools.46999.n3.nabble.com/modify-and-update-do-not-work-in-rules-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
Optaplanner, loading drl from filesystm not off classpath
by meganwoods
Hi,
Is it possible to load drl files from the filesystem without them being on
the classpath.
I can create an XML solver factory using a stream from the constructor but
the loading of any DRL files appears to require those drl files to be on the
class path.
Looking at the private XmlBuildFactory.buildKieBase on line 301 it uses
getClass().getResourceAsStream()
I was wondering if there was another strategy I could use to load DRL's off
the file system as opposed to off the classpath.
Cheers Megan Woods
--
View this message in context: http://drools.46999.n3.nabble.com/Optaplanner-loading-drl-from-filesystm-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
PMML - Exception excuting consequence for rule xxx in yyy: java.lang.NullPointerException : using KnowledgeAgent
by smilk
Hi. I'm trying to test pmml "decision trees"
(https://github.com/droolsjbpm/drools-chance/tree/master/drools-pmml)
on Drools 5.5.0.Final.
The two test environment's outcome are not same.
1) I got a test on Eclipse. The results are fine. Test source is as below.
public class PMMLTestFromLocal {
public static final void main(String[] args) {
try {
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "LocalPmmlTest");
FactType CHK_YN_Type = kbase.getFactType(
"Meritz_ModelRule_01","CHK_YN" );
CHK_YN_Type.newInstance();
ksession.getWorkingMemoryEntryPoint( "in_AC_CSE_TYP_RE"
).insert( "group0" );
ksession.getWorkingMemoryEntryPoint( "in_AC_TYP_RE" ).insert(
"Caution" );
ksession.getWorkingMemoryEntryPoint( "in_COV_CD_RE" ).insert(
"group2" );
ksession.getWorkingMemoryEntryPoint( "in_AC_STAT_CD_RE"
).insert( "group1" );
ksession.getWorkingMemoryEntryPoint( "in_HDCAP_RATE_RE"
).insert( "0" );
ksession.getWorkingMemoryEntryPoint( "in_FDS_AC_YN" ).insert(
"0" );
ksession.getWorkingMemoryEntryPoint( "in_AGE_GRD" ).insert(
"10대" );
ksession.getWorkingMemoryEntryPoint( "in_AC_COT_DAY" ).insert(
0.0 );
ksession.fireAllRules();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("pmml2.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse
knowledge.");
}
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase("Meritz");
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
2) The Second environment which is excuting Exception is Tomcat.
I got a test using same drools engine on Tomcat. But NullpointerException
occured.
Test source is as below.
public class PMMLTestFromServer {
public static void main(String[] args) {
StatefulKnowledgeSession kSession = getSKSession();
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(kSession, "ServerPmmlTest");
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
kSession.getWorkingMemoryEntryPoint( "in_AC_CSE_TYP_RE" ).insert( "group0"
);
kSession.getWorkingMemoryEntryPoint( "in_AC_TYP_RE" ).insert( "Caution" );
kSession.getWorkingMemoryEntryPoint( "in_COV_CD_RE" ).insert( "group2" );
kSession.getWorkingMemoryEntryPoint( "in_AC_STAT_CD_RE" ).insert( "group1"
);
kSession.getWorkingMemoryEntryPoint( "in_HDCAP_RATE_RE" ).insert( "0" );
kSession.getWorkingMemoryEntryPoint( "in_FDS_AC_YN" ).insert( "0" );
kSession.getWorkingMemoryEntryPoint( "in_AGE_GRD" ).insert( "10대" );
kSession.getWorkingMemoryEntryPoint( "in_AC_COT_DAY" ).insert( 0.0 );
kSession.fireAllRules();
logger.close();
}
public static StatefulKnowledgeSession getSKSession() {
KnowledgeAgent agent = KnowledgeAgentFactory.newKnowledgeAgent("Meritz");
agent.applyChangeSet(ResourceFactory.newClassPathResource("change-set_model.xml"));
KnowledgeBase ruleBase = agent.getKnowledgeBase();
System.out.println(ruleBase.getKnowledgePackages());
return ruleBase.newStatefulKnowledgeSession();
}
}
The differences in two test source is using KnowledgeAgent.
Exception stack trace follows -
Exception executing consequence for rule
"outputFeature_CHK_YN_to_Probability_N_probability" in Meritz_ModelRule_01:
java.lang.NullPointerException
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at com.meritzfis.test.PMMLTestFromServer.main(PMMLTestFromServer.java:43)
Caused by: java.lang.NullPointerException
at
org.drools.base.evaluators.BeforeEvaluatorDefinition$BeforeEvaluator.evaluateCachedRight(BeforeEvaluatorDefinition.java:318)
at
org.drools.rule.constraint.EvaluatorConstraint.isAllowedCachedRight(EvaluatorConstraint.java:80)
at
org.drools.common.DoubleBetaConstraints.isAllowedCachedRight(DoubleBetaConstraints.java:97)
at org.drools.reteoo.JoinNode.propagateFromRight(JoinNode.java:156)
at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:148)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:350)
at org.drools.common.SimpleBeliefSystem.insert(SimpleBeliefSystem.java:38)
at
org.drools.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:204)
at
org.drools.common.TruthMaintenanceSystem.addLogicalDependency(TruthMaintenanceSystem.java:176)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:231)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
at
org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:245)
at
org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:210)
at
org.drools.base.DefaultKnowledgeHelper.insertLogical(DefaultKnowledgeHelper.java:205)
at
Meritz_ModelRule_01.Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fc.defaultConsequence(Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fc.java:14)
at
Meritz_ModelRule_01.Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fcDefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
Meritz_ModelRule_01.Rule_outputFeature_CHK_YN_to_Probability_N_probability_a4a43fe942664fe0b31e45a29a6d99fcDefaultConsequenceInvoker.evaluate(Unknown
Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
... 6 more
I'm attaching a drl file.
--
View this message in context: http://drools.46999.n3.nabble.com/PMML-Exception-excuting-consequence-for...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to org.drools.reteoo.AlphaNode$AlphaMemory
by dcrissman
Does this mean anything to anyone?
I found this, but I am using 5.5.0.Final:
http://drools.46999.n3.nabble.com/org-drools-reteoo-AlphaNode-AlphaMemory...
java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to
org.drools.reteoo.AlphaNode$AlphaMemory
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:136)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:141)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:350)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:311)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
at
org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269)
...
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-ClassCastException-org-drools...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
Timer and AgendaFilter
by Kai Ruddies
Hi,
I have a rule with a timer and call fireAllRules(AgendaFilter agendaFilter) with an AgendaFilter. I can see the Activation is fired after the delay but accept(Activation activation) in my AgendaFilter isn't invoked. My AgendaFilter is working well for other rules without timers.
Is this a bug or wanted that ScheduledActivations aren't passed to the AgendaFilter?
I'm using drools expert 5.5.0.Final.
Thanks,
Kai
11 years, 3 months
Dublin : JBoss BRMS event Wed 28th Aug
by Mark Proctor
I'll be giving a "JBoss BRMS 6.0" talk in Dublin this month, it's free, so please help spread the word ;)
http://marketing.interactiveideas.com/acton/fs/blocks/showLandingPage/a/8...
---
JBoss® BRMS Technical Workshop
In this FREE Technical Workshop on Wednesday 28th August at the Westin Dublin Hotel, you will discover how the JBoss Business Rules Management System (BRMS) allows you to automate, manage and improve your critical business processes and policies.
Learn how other organisations are benefiting from maintaining business processes and policies outside of application code; and explore emerging developments and the technology roadmap withMark Proctor, Red Hat's Worldwide Technical Lead for BRMS.
Places are limited, so register early to avoid disappointment.
11 years, 3 months
How to avoid stateless session rule fire on every fact ?
by viraj
Hi all,
In my project I have 20,000 rules to reason with 20,000 facts. The rules are
embedded in facts. Therefore for each rule , there is one fact object which
that rule belongs to. I'm using following condition to find this matching
object.
rule "Book Rule 1 - 187970786749253 "
no-loop true
when
$book : Book( bookId == 187970786749253 , $eligible : eligible == false )
UserProfile( userType == UserType.STUDENT , status == 1 ) //... other
conditions
then
//Do something here...
end
So above rule is belongs to Book object which has id = 187970786749253 (
This is a unique id ). I'm using stateless sequential rule engine.
Following is the my understanding how rules are executed over facts.
For first rule it needs to check all the 20,000 objects in worst case to
find matching Book. For second rule the worst case should be 19,999 object
search since one object is found and processed. But I used
AgendaEventListener to find the time for each rule. It has nearly constant
time for each rule , which means for each rule, engine search all the 20,000
object. I need to avoid this still keeping stateless session. Any ideas how
to do this ?
Thanks !
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-avoid-stateless-session-rule-fir...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
How do you explicitly uses a designated DSL file when parsing dslr?
by Sonata
Hi, I have added more than one DSL files into the KnowledgeBase (with
conflicting definitions).
It seems that even though I have stated expander A.dsl or expander B.dsl in
my dslr
it still uses the first dsl that I added into the KnowledgeBase then the
second dsl to parse my dslr.
Meaning that the definitions in A.dsl persisted when it comes to conflicting
definitions.
Is "expander" there for other purpose or there is simply no way to specific
which dsl to use?
Otherwise how do you specific any dsl for your dslr except to create a new
KnowledgeBuilder each time the dslr is required and add only the dsl it
needs by looking into the dslr file?
I am using 5.5.0.Final, thank you!
--
View this message in context: http://drools.46999.n3.nabble.com/How-do-you-explicitly-uses-a-designated...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 3 months
RightTupleIndexHashTable
by Ming Fang
What is the purpose of RightTupleIndexHashTable?
We are getting the exception below but unable to come up with a self contained unit test to demonstrate the problem.
Caused by: java.lang.NullPointerException: null
at org.drools.core.util.index.RightTupleIndexHashTable.removeAdd(RightTupleIndexHashTable.java:344) ~[drools-core-5.5.0.Final.jar:5.5.0.Final]
at org.drools.reteoo.JoinNode.modifyRightTuple(JoinNode.java:224) ~[drools-core-5.5.0.Final.jar:5.5.0.Final]
at org.drools.reteoo.PropagationQueuingNode$ModifyToSinkAction.execute(PropagationQueuingNode.java:513) ~[drools-core-5.5.0.Final.jar:5.5.0.Final]
at org.drools.reteoo.PropagationQueuingNode.propagateActions(PropagationQueuingNode.java:280) ~[drools-core-5.5.0.Final.jar:5.5.0.Final]
at org.drools.reteoo.PropagationQueuingNode$PropagateAction.execute(PropagationQueuingNode.java:588) ~[drools-core-5.5.0.Final.jar:5.5.0.Final]
at org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:993) [drools-core-5.5.0.Final.jar:5.5.0.Final]
11 years, 3 months