KnowledgeAgent and Guvnor restart
by Gerret Hansper
Hello,
I have got an issue with the KnowledgeAgent that seems not to survive a Guvnor
restart. The scenario is as follows:
* We use Drools 5.0
* On our application server we create a KnowledgeAgent
applying a ChangeSet that points to a package binary on a separate Guvnor server
like so:
SystemEventListenerFactory.setSystemEventListener(new
SystemEventLogger());
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
KnowledgeAgent agent =
KnowledgeAgentFactory.newKnowledgeAgent(workflowName);
agent.applyChangeSet(changeSet);
* Creating the kbase, registering globals and running sessions works fine.
* We shut down Guvnor (or the connection goes down, this was how we spotted the
problem) and restart it after a minute
* We then try to run sessions from the
same agent as above via
kagent.getKnowledgeBase().newStatefulKnowledgeSession();
which returns a ksession, but then setting a global we get
java.lang.RuntimeException: Unexpected global [log]
at
org.drools.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:5
50)
at
org.drools.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessio
nImpl.java:284)
>From the debugger I can see that indeed the ruleBase's globals map is empty. The
SystemEventLogger indicates that the KnowledgeAgent unsubscribes from its
resource when Guvnor is down and rebuilds its kbase. Also, it stops scanning the
resource and does not find it once Guvnor is up again. (See log snippet below).
Wouldn't it be better in these cases to keep the resource as is in memory and
try to rescan? I figure that as long as the resource is specified in the
changeSet it should be considered part of the kbase and not be removed if it
cannot be found.
For the time being, does anyone have a suggestion how to avoid these problems?
We could catch the RuntimeException and recreate the KnowledgeAgent, but perhaps
there is a better way?
Thanks, Gerret
-- SystemEventLog --
# Guvnor is up here
07:58:01,881 ResourceChangeScanner attempt to scan 1 resources
07:58:02,209 ResourceChangeScanner thread is waiting for 60
07:58:15,067 ResourceChangeScanner attempt to scan 1 resources
# Guvnor goes down here
07:58:16,738 ResourceChangeScanner removed resource=[UrlResource
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST']
07:58:16,738 ResourceChangeNotification received ChangeSet notification
07:58:16,738 ResourceChangeScanner thread is waiting for 60
07:58:16,738 ResourceChangeNotification processing ChangeSet
07:58:16,738 ResourceChangeNotification ChangeSet removed resource=[UrlResource
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] for
listener=org.drools.agent.impl.KnowledgeAgentImpl@1053d6d
07:58:16,738 ResourceChangeNotification ChangeSet removed resource=[UrlResource
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST'] for
listener=org.drools.agent.impl.KnowledgeAgentImpl@b71c17
07:58:16,738 KnowledgeAgent received ChangeSet changed notification
07:58:16,738 KnowledgeAgent received ChangeSet changed notification
07:58:16,738 KnowledgAgent applying ChangeSet
07:58:16,738 ResourceChangeNotification thread is waiting for queue update
07:58:16,738 KnowledgAgent applying ChangeSet
07:58:16,738 KnowledgeAgent unsubscribing from resource=[UrlResource
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST']
07:58:16,738 ResourceChangeNotification unsubscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@1053d6d to
resource=[UrlResource path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST']
07:58:16,738 KnowledgeAgent rebuilding KnowledgeBase using ChangeSet
07:58:16,738 KnowledgeAgent unsubscribing from resource=[UrlResource
path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST']
07:58:16,738 ResourceChangeNotification unsubscribing
listener=org.drools.agent.impl.KnowledgeAgentImpl@b71c17 to
resource=[UrlResource path='http://localhost:7080/drools-
guvnor/org.drools.guvnor.Guvnor/package/com.foo.bar/LATEST']
07:58:16,738
KnowledgeAgent rebuilding KnowledgeBase using ChangeSet
07:58:16,738 KnowledgeAgent new KnowledgeBase now built and in use
07:58:16,738 KnowledgeAgent new KnowledgeBase now built and in use
07:59:02,202 ResourceChangeScanner attempt to scan 0 resources
07:59:02,202 ResourceChangeScanner thread is waiting for 60
# Guvnor back up here
07:59:16,731 ResourceChangeScanner attempt to scan 0 resources
07:59:16,731 ResourceChangeScanner thread is waiting for 60
16 years, 4 months
Rule Templates with empty cells
by jschmied
Hi!
If I write rules in a decision table I can leave cells empty if I don't need
to use all of the conditions in a row.
How can I do this with the ExternalSpreadsheetCompiler?
I would need something like:
rule "rule_(a){row.rowNumber}"
when
$s : MyType1()
@ifDefined{field1} $e : MyType2(val1 == "@{field1}") from $s.SUB;
@ifDefined{field2} $e : MyType2(val2 == "@{field2}") from $s.SUB;
then
retract($s);
end
Thanks
Juergen
--
View this message in context: http://n3.nabble.com/Rule-Templates-with-empty-cells-tp138571p138571.html
Sent from the Drools - User mailing list archive at Nabble.com.
16 years, 4 months
"collection contains" problem
by Mike Dougherty
Hello all,
I've been getting more and more into using Drools Expert, but I certainly still have a lot to learn. I have almost a complete rules file ready to go. But I am having an issue with the LHS checking that a collection contains a certain object value. The rule currently looks like this:
rule "Rule Name"
no-loop true
when
property : StatusProperty( name == "propertyName", value == "valueA" )
t : TrainingStatus( currentSection == "section_a", properties contains property )
then
t.setNextSection( "section_b" );
t.setPreviousSection( "section_overview" );
update( t );
end
The TrainingStatus object has the following fields:
public class TrainingStatus implements Serializable {
private String currentSection;
private String nextSection;
private String previousSection;
private Set<StatusProperty> properties = new TreeSet<StatusProperty>();
}
And the StatusProperty object has the following:
public class StatusProperty implements Serializable {
private String name;
private String value;
}
I'm inserting a TrainingStatus object that should match this rule. But the resulting object does not have the nextSection and previousSection fields set to the values they should.
Can anyone advise on how to get this rule working as expected?
Thanks for your help!
Mike
16 years, 4 months
Human Task Example
by Chuck Irvine
Hello. Is there a complete Human Task example that someone could point me
to? I'm looking for an example that uses the Eclipse task plugin to allow
users to complete tasks. Thanks! -Chuck
16 years, 4 months
confused on when to call fireAllRules
by Charles Binford
Hi, I'm trying to add some functionality to my 4.0.7 based project and
am realizing I don't understand some basics as well as I thought I did.
Until now, I've been using a very simple model: create session, insert
facts, fire rules, destroy session. My new functionality needs to use a
long lived session. I also may find the duration feature useful so I
searched through the examples and found the TroubleTicketExample. Now
what has be confused is that example shows rules firing AFTER control
has been returned from the fireAllRules() call. I tried to create
something similar - call fireAllRules, then call session.update(han,
obj) - but nothing happens. If I call fireAllRules again (after the
update) then my rule fires as expected. My test didn't use any
duration statement. Is that the magic in the TroubleTicketExample? If
so, then how does one have a clue as to whether one needs to call
fireAllRules after an update or not (i.e. no way to tell if a duration
rule is keeping it running)? Obviously I'm missing some basic
understanding here. Please enlighten me.
Thanks,
Charles Binford
16 years, 4 months
Better Performance and Maintainability?
by HonorGod
Hi,
Can someone plz help me understand performance and maintainability in the
following scenario - ?
I load tons of rows of data from database and store them in an object fact
model [POJO based] and apply the rules using decision tables and finally
persist data.
vs
I load tons of rows of data from database and store them in an object fact
model [HashMap - Key - Value] and apply the rules using decision tables and
finally persist data.
The difference in the above two scenarios is that one of them is pojo based
and the other is key-value pairs that are used on LHS of the decision
tables. When I use Key-Value approach I had to do lot of conversion in terms
converting the conditions into eval statements and validations but where as
the pojo approach is very straight forward and less validations.
Which approach gives me better performance and maintainability?
I would consider the following before I make a decision -
1 - size of data
2 - frequency at which the data changes [in terms of adding new conditions /
adding new columns / removal of new columns etc]
3 - re-usability
Thank You!
--
View this message in context: http://n3.nabble.com/Better-Performance-and-Maintainability-tp136941p1369...
Sent from the Drools - User mailing list archive at Nabble.com.
16 years, 4 months
drools-solver recover the score of last step
by dmzpippo-drools@yahoo.it
Hi all,
is possible in a DRL file, useded for droos-solver, recover the score of last step?
I need it because with the rule I calculate a function score f(n); to diverrsificate the research if f(n) is bigger then f(n) of last step then add a penality...
regards
16 years, 4 months
Is this possible in Guvnor?
by HonorGod
Hi,
I have a single fact model with 5 [a1, a2,a3, a4, and a5] different
attributes. I have 3 decision tables in the following fashion
Decision Table 1
---------------------------------------------
condition | condition | condition | Action |
---------------------------------------------
a1 | a2 | a3 | a4 = a1+a3|
----------------------------------------------
Once I have the value of a4, I need to hit different set of rules which are
stored in second decision table
Decision Table 2
---------------------------------------------
condition | condition | condition | Action |
---------------------------------------------
a1 | a2 | a4 | a5 = a4 |
----------------------------------------------
Once I have the value of a5, I need to hit different set of rules which are
store in third decision table
Decision Table 3
------------------------------------------------------------------------
condition | condition | condition | condition | condition | Action
|
-------------------------------------------------------------------------
a1 | a2 | a3 | a4 | a5 |
computeValue() |
------------------------------------------------------------------------
I don't have any problem when I load the rules into individual KnowledgeBase
and fire the rules one after the other as follows -
<code>
// apply rules from decision table 1
StatefulKnowledgeSession kSession =
knowledgeBase1.newStatefulKnowledgeSession() ;
kSession.insert(caEventDO);
kSession.fireAllRules();
// apply rules from decision table 2
kSession = knowledgeBase2.newStatefulKnowledgeSession() ;
kSession.insert(caEventDO);
kSession.fireAllRules();
// apply rules from decision table 3
kSession = knowledgeBase3.newStatefulKnowledgeSession() ;
kSession.insert(caEventDO);
kSession.fireAllRules();
kSession.dispose() ;
</code>
But when I upload the decision tables into Guvnor and use the package / drl
from the package snapshot my second set of rules are not fired at all.
How do I resolve this issue?
Please help.
Thanks
--
View this message in context: http://n3.nabble.com/Is-this-possible-in-Guvnor-tp122132p122132.html
Sent from the Drools - User mailing list archive at Nabble.com.
16 years, 4 months