"Rule-Id" for a Drools Rule
by harishtejwani
All:
We are using Drools to detect specific events/conditions in our system.
In the 'then' condition of Drools rule, we would like to persist the "Rule
Id" of the rule that created the specific event/condition
This is because all our reporting is based on "rules" as filters, where
users can look at exceptions by specific rules.
Is there a suggestion or sample as how can the "Rule Id" be persisted or
indicated in the then condition that is immutable or can be long-lived. The
current approach of using Rule Name itself as the ID is brittle as this can
be changed and suddenly all reports would break.
If we assign ID's to rules, where do we keep the mapping of RULE ID to
Rules. If we store rules in GUVRNOR is there a way we can get Rule Id's for
Rules?
Best regards
Harish Tejwani
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-Id-for-a-Drools-Rule-tp2914385p291...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Fire specific rules deployed in guvnor that reside in the same package
by ciberg2
Hi, I have Guvnor running with a package that has several BPMN processes and
now I'm adding rules to it.
The rules are made in Excel files and built into the package.
I have a web application in JAVA that fires the rules and if I have only one
rule in the package it works fine.
But if I deploy more than one rule to the package the result is a list with
the result of applying the input to all the rules that exist in the package.
I tried using this as URL with no success, drools applies the input to all
the rules in the package:
http://127.0.0.1:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/mera...
How should I organize the rules? One package for each? It doesn't seem a
good solution to me.
Is it possible to fire only a specific rule? If yes, how?
I use this code:
public static KnowledgeBase readKnowledgeBase()
throws Exception {
UrlResource resource = (UrlResource) ResourceFactory
.newUrlResource("http://127.0.0.1:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/myPa...");
resource.setBasicAuthentication("enabled");
resource.setUsername("guest");
resource.setPassword("guest");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(resource, ResourceType.PKG);
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
Thank you
--
View this message in context: http://drools.46999.n3.nabble.com/Fire-specific-rules-deployed-in-guvnor-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
General doubts about Drools capacity and tools
by Alan
Hi guys,
I have to do my final work to graduate at collage and I have some doubts
that I need to make clear about Drools before going on deep on it.
So, the project will have 3 main topics:
-Basic CRUD(maintenance) of rules
-Inference of data to those rules
-Filtering processed data based on statistical rules
I would like to know if Drools and it extensions projects can handle those
topics?
Also I had planned to develop my interface and other middle parts on .NET
based solutions such as C# as MVC.
Would Drools provide enough integration to this?
I would really appreciate any help and guides(topics,books,example projects)
that cover those topics.
Thanks,
Alan Araya
--
View this message in context: http://drools.46999.n3.nabble.com/General-doubts-about-Drools-capacity-an...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Error using 5.5.1 built with 5.5.0 Final jars
by abhinay_agarwal
M getting the following error when i try to connect to guvnor repository, is
this because of the jar conflict or the problem is something else ?
Caused by: java.io.InvalidClassException:
org.drools.rule.constraint.MvelConstraint; local class incompatible: stream
classdesc serialVersionUID = 148857042101396396, local class
serialVersionUID = 8537626313322861096
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.ArrayList.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.drools.rule.Pattern.readExternal(Pattern.java:115)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.ArrayList.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.drools.rule.GroupElement.readExternal(GroupElement.java:63)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.drools.rule.Rule.readExternal(Rule.java:185)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.IdentityHashMap.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at
org.drools.rule.MVELDialectRuntimeData.readExternal(MVELDialectRuntimeData.java:90)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.HashMap.readObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at
org.drools.rule.DialectRuntimeRegistry.readExternal(DialectRuntimeRegistry.java:58)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.drools.rule.Package.readExternal(Package.java:208)
at java.io.ObjectInputStream.readExternalData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205)
at
org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189)
at
org.drools.agent.impl.KnowledgeAgentImpl.createPackageFromResource(KnowledgeAgentImpl.java:769)
... 7 more
--
View this message in context: http://drools.46999.n3.nabble.com/Error-using-5-5-1-built-with-5-5-0-Fina...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Abstracting Rules using extends
by Arul Prashanth
I have a Rule implementation as below which works as expected, here
Vehicles() and RuleConstant are facts.
/rule "Rule|1"
no-loop true
when
$CONSTANT : RuleConstant();
$vehicles : Vehicles();
$vehicle:Vehicle(modelYear > 2000, type = $CONSTANT.SEDAN) from
$vehicles.Vehicle;
then
$vehicle.setValue(100);
update($vehicles);
end /
But am planning to abstract the rules in the below fashion so that we can
reuse the LHS conditions which doesn't work and throws the below said Null
Pointer Exception
*BaseRule.drl*
/package com.xyz.base
rule "Base|1"
no-loop true
enabled false
when
$CONSTANT : RuleConstant();
$vehicles : Vehicles();
then
end /
*CustomRule.drl*
/package com.xyz.custom
rule "Custom|1" extends "Base|1"
no-loop true
enabled true
when
$vehicle:Vehicle(modelYear > 2000, type = $CONSTANT.SEDAN) from
$vehicles.Vehicle;
then
$vehicle.setValue(100);
update($vehicles);
end
rule "Custom|2" extends "Base|1"
no-loop true
enabled true
when
$vehicle:Vehicle(modelYear > 2000, type = $CONSTANT.COUPE) from
$vehicles.Vehicle;
then
$vehicle.setValue(100);
update($vehicles);
end/
*Exception:*
Caused by: [Error: drools.update($vehicles): null]
[Line: 1, Column: 1]
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:416)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:143)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:123)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:116)
at org.mvel2.MVEL.executeExpression(MVEL.java:930)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:101)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1273)
... 33 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1105)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377)
... 42 more
Caused by: java.lang.NullPointerException
at org.drools.common.DefaultAgenda.createActivation(DefaultAgenda.java:569)
at
org.drools.reteoo.RuleTerminalNode.modifyLeftTuple(RuleTerminalNode.java:297)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:246)
at org.drools.reteoo.JoinNode.modifyLeftTuple(JoinNode.java:363)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:272)
at
org.drools.reteoo.EvalConditionNode.modifyLeftTuple(EvalConditionNode.java:213)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:259)
at
org.drools.reteoo.FromNode.checkConstraintsAndPropagate(FromNode.java:337)
at org.drools.reteoo.FromNode.modifyLeftTuple(FromNode.java:281)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.propagateModifyChildLeftTuple(CompositeLeftTupleSinkAdapter.java:316)
at org.drools.reteoo.JoinNode.modifyRightTuple(JoinNode.java:273)
at org.drools.reteoo.BetaNode.modifyObject(BetaNode.java:531)
at org.drools.reteoo.JoinNode.modifyObject(JoinNode.java:446)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:507)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:432)
at org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:314)
at org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:265)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:470)
at org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:370)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:317)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:329)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:325)
... 49 more
-----
- Prashanth
--
View this message in context: http://drools.46999.n3.nabble.com/Abstracting-Rules-using-extends-tp40232...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Rules Firing / Java Objects Not Manipulated
by dfsmith
Hi,
I am new to Drools and Guvnor, so I am likely overlooking something simple.
I am prototyping a proof of concept for integrating Drools into SOLR and
using Guvnor for business rule management.
I have a Guvnor generated rule that looks like this:
rule "t1"
dialect "mvel"
when
SearchState( searchTerms == "monitor" )
then
SearchActions fact0 = new SearchActions();
fact0.setUrlRedirect( "junk" );
insert( fact0 );
System.out.println("Created junk!!!");
end
In a custom SOLR search component, the Drools POC integration code is as
follows:
try {
if (rb.stage == ResponseBuilder.STAGE_START) {
// load package
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newFileResource(new
File("c:\\data\\guvnor\\searchLatest.pkg")), ResourceType.PKG);
// create the knowledge base
kbase = KnowledgeBaseFactory.newKnowledgeBase();
// add the package to the kbase
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
System.out.println("In QueryInterceptorComponent.handleRequestBody(). q =
" + rb.req.getParams().get("q"));
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
SearchState searchState = new SearchState();
searchState.setSearchTerms(rb.req.getParams().get("q"));
//More search state attribute setting here ...
Collection list = new ArrayList();
list.add(searchState);
ksession.execute(list);
System.out.println("EXECUTED RULES");
}
} catch(Exception e) {
System.out.println("Caught exception " + e);
}
Running in Debug mode on Tomcat and searching on "monitor", I can see that I
step through all of the code above without any exceptions. The console
output shows me that the rule successfully fired and that the When condition
was satisfied as it performed the When side of the rule; it wrote the sysout
message I expected.
In QueryInterceptorComponent.handleRequestBody(). q = monitor
/*Created junk!!!*/
EXECUTED RULES
But when I then access the list collection again in the debugger, there is
no SearchActions object added to the list. I've also tried modifying the
rule to just change a value on the SearchState object that is driving the
When condition. That doesn't result in any object changes either.
Can someone point me in the right direction? Again, I'm new at this.
Any assistance most greatly appreciated.
Thanks,
David
--
View this message in context: http://drools.46999.n3.nabble.com/Rules-Firing-Java-Objects-Not-Manipulat...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
NoSuchFieldError: session
by Lance
I am in the midst of converting a set of rules and rule-flows from Drools
5.1.0 to 5.3.0
During the execution of the primary rule-flow, we receive an exception which
traces back to...
*Caused by: java.lang.NoSuchFieldError: session
at
org.jbpm.process.instance.impl.MVELAction.execute(MVELAction.java:89)
at
org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:47)
at
org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:124)
...*
This appears to occur in an action node that contains the following...
* insert(context.getVariable("shipmentDocument"));
insert(context.getVariable("shipmentLifecycle"));*
The action node dialect is set to MVEL, and setting it to Java seems to
cause the rule-flow to never exit the action node.
The rule-flow and associated rules all work without error in our Drools
5.1.0 implementation. Any suggestions on why this might not be working in
5.3.0, and how I might go about fixing it?
--
View this message in context: http://drools.46999.n3.nabble.com/NoSuchFieldError-session-tp4023263.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
Basic question
by goforcrazy
Hello All,
I am having some basic problems with how my rule file is working. Any help
regarding this will be greatly appreciated.
My rule is as follows:
rule "Rating"
when
m : method()
then
System.out.println("Rating inserted as: "+ m.getid() + " and rating: " +
m.getRating());
end
In my main java file, I am calling in the main method:
insertRating(101, 1.0);
insertRating(102, 1.0);
ksession.fireAllRules();
The definition of insertRating is as below:
public void insertRating(int mid, double d)
{
RatingMessage msg = new RatingMessage(mid,d);
ksession.insert(msg);
}
My expectation is that 2 different ksession objects will be created and when
fireAllRules() is executed, the rule will be able to print the ID and rating
for both 101 and 102.
I am surprised that the output is
Rating inserted ID as: 101 and rating: 1.0
It randomly takes either 101 or 102 and never both. Why is it so? Am I
missing something?
Thanks a million for the help:)
--
View this message in context: http://drools.46999.n3.nabble.com/Basic-question-tp4023234.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 11 months
[Planner] How to fix score corruption (answer)
by Geoffrey De Smet
In the past few months, several users have reported on this mailing list
that they ran into score corruption issues,
so I've been working to improve the situation for 6.0.x.
Like in 5.x, by putting the <environmentMode> in ASSERT mode,
it's easy to detect such an issue (and often even the offending score rule),
but it's been generally hard to understand what's the cause on how to
fix it.
There are generally 3 common causes of score corruption:
* Bug in your cloning method.
o In 6.0.0.Beta1 you no longer need to write the cloning method:
+ http://blog.athico.com/2013/02/automatic-solution-cloning-in-planner.html
* Bug in the causes parameter you supply to ConstraintOccurrence or a
planner-incompatible hashcode/equals method of any those objects
o In 6.0.0.Beta1 there is no cause parameter and it no longer
cares about the hashcode/equals method of your objects during
score calculation
+ http://blog.athico.com/2013/04/score-drl-faster-and-easier-in.html
* Bug in our Drools Expert's statefull working memory
o Most of these bugs were fixed for Drools 5.1 and 5.2. I am not
aware of any in Drools 5.3 and 5.4.
+ Mario and I are looking into a very exotic bug in
5.5/6.0.0.Beta1 now, which is unlikely to affect you: it
only affects 1 dataset of 1 example in OptaPlanner.
o As always, we welcome detailed bug reports (especially with
reproducers) if you believe you 've discovered another bug.
Hope that helps :)
wkr,
Geoffrey De Smet
http://www.optaplanner.org
12 years, 11 months