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.
11 years, 7 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.
11 years, 7 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.
11 years, 7 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
11 years, 7 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
11 years, 7 months
planner: documentation about subChain-MoveSelectors
by roman.stumm
The only example that uses a SubChainChangeMoveSelector and a
SubChainSwapMoveSelector is the vehicleRoutingProblem. The
travelling-salesman-problem (which is another example for a problem with a
chained PlanningVariable) does not use them.
Is there a reason for this, e.g. what are the subChain*MoveSelectors for?
The documentation of drools-planner 5.5.0.Final does not say anything about
them,
see chapter 7.3.4. subChainChangeMoveSelector and 7.3.5.
subChainSwapMoveSelector
Regards,
Roman
--
View this message in context: http://drools.46999.n3.nabble.com/planner-documentation-about-subChain-Mo...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 7 months
Fact insertion & retraction in working memory
by jigna
I need to add rule for filtering an event for 30 seconds.
i.e. The action would be taken once event has occurred for the first time &
then all the events of the same type would be ignored 30 seconds
& action should again take place if event has occurred anytime after 30
seconds.
I have tried creating a Throote class for holding thrittle value & timestamp
of firts occurance of events.
Following are the three rules which I am creating for the same.
It works correctly with first two rules, however for triggering third rule,
I need to insert an event which is not '000000A1'
& then this would give result retarcting ThrottleInfo Object which is
holding timestamp of this event for which throttle period has passed.
How can I make third rule trigger when there is not event of type '000000A1'
after throttle period?
Also is it possible to simplify this & write in single rule using timestamp
or any other features of fusion?
import com.igate.iheal.model.ErrorInfo
import com.igate.iheal.model.ThrottleInfo
import com.igate.iheal.model.process.IHEALProcessModel
declare ErrorInfo
@role(event)
@timestamp(errorTimeStamp)
end
rule "Error Rule 1"
no-loop true
when
$Error1:ErrorInfo(errorCode=="000000A1")from entry-point ErrorEntryPoint
not(exists(ThrottleInfo(errorCode=="000000A1")))
then
#Passing throttle duration as 30 seconds
insert(new
ThrottleInfo("000000A1",30,System.currentTimeMillis()));
retract($Error1);
System.out.println("New throttle info instance created");
end
rule "Error Rule 2"
no-loop true
when
$Error2:ErrorInfo(errorCode=="000000A1") from entry-point
ErrorEntryPoint
exists(ThrottleInfo(errorCode=="000000A1"))
$ThrottleError:ThrottleInfo(errorCode=="000000A1")
eval($ThrottleError.isThrottleCompleted()==true)
then
modify($ThrottleError)
{setErrorTimeStamp(System.currentTimeMillis())};
retract($Error2);
System.out.println("Modified throttle info instance");
end
rule "Error Rule 3"
#no-loop true
when
$Error3:ErrorInfo(errorCode!="000000A1") from entry-point ErrorEntryPoint
not(ErrorInfo(errorCode=="000000A1"))
exists(ThrottleInfo(errorCode=="000000A1"))
$ThrottleError:ThrottleInfo(errorCode=="000000A1")
eval($ThrottleError.isThrottleCompleted()==true)
then
retract($ThrottleError);
System.out.println("Delete unused throttle info instance");
end
--
View this message in context: http://drools.46999.n3.nabble.com/Fact-insertion-retraction-in-working-me...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 8 months