[Drools Fusion] Can't detect 2 occurrences with sliding window
by Xavier Coulon
Hello,
I'm new to Drools (5.0.1) and i've tryied the following (basic) fusion rule
for a few days now without success.
The rule is to determine if a user performs 2 operations in the sliding
window of 60s. In such a condition, a log message should be triggered.
Here is my DRL code :
# declare events
declare Operation
@role(event)
@timestamp(date)
end
rule "overActivity"
dialect "mvel"
when
#condition : 2 operation in less than 1 minute
$operation1 : Operation()
over window:time(60s) from entry-point "OperationStream"
$operation2 : Operation(this != $operation1, ipAddress ==
$operation1.ipAddress)
over window:time(60s) from entry-point "OperationStream"
then
#actions
System.out.println("over-active user " + $operation1.ipAddress );
end
And my JUnit test, using a PSEUDO Clock :
public class DroolsRulesTestCase {
static KnowledgeBase knowledgeBase;
StatefulKnowledgeSession session;
// FactHandle handle;
SessionPseudoClock clock;
WorkingMemoryEntryPoint entryPoint;
private TrackingAgendaEventListener listener;
private static final Logger LOGGER = Logger
.getLogger(DroolsRulesTestCase.class);
@BeforeClass
public static void globalSetup() throws IOException {
KnowledgeBuilder builder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
ClassPathResource classPathResource = new ClassPathResource(
"rules/activity-fusion.drl");
Assert.assertTrue("Rules resource not found", classPathResource
.exists());
builder.add(ResourceFactory.newInputStreamResource(classPathResource
.getInputStream()), ResourceType.DRL);
Assert.assertFalse("Errors in builder:"
+ builder.getErrors().toString(), builder.hasErrors());
KnowledgeBaseConfiguration configuration = KnowledgeBaseFactory
.newKnowledgeBaseConfiguration();
configuration.setOption(EventProcessingOption.STREAM);
knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(configuration);
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
}
@Before
public void setup() {
KnowledgeSessionConfiguration configuration = KnowledgeBaseFactory
.newKnowledgeSessionConfiguration();
configuration.setOption(ClockTypeOption.get("pseudo"));
session = knowledgeBase
.newStatefulKnowledgeSession(configuration, null);
clock = (SessionPseudoClock) session.getSessionClock();
listener = new TrackingAgendaEventListener();
session.addEventListener(listener);
session.addEventListener(new TrackingWorkingMemoryEventListener());
entryPoint = session.getWorkingMemoryEntryPoint("OperationStream");
}
@SuppressWarnings("unchecked")
@Test
public void testActivity() throws IOException, ParseException,
InterruptedException {
// parse the log file
Resource logFile = new ClassPathResource(
"activity/extract.log");
// converter and inject tracks in the session,
List<String> logLines = FileUtils.readLines(logFile.getFile(), "UTF-8");
// fire all rules
session.fireAllRules();
LOGGER.info("loading events");
// load events from stream
for (String logLine : logLines) {
Operation operation = LineConverterUtil.getOperation(logLine);
LOGGER.debug("Inserting " + operation);
LOGGER.debug("Moving clock from "
+ (new Date(clock.getCurrentTime())).toString() + " to "
+ operation.getDate());
clock.advanceTime(operation.getDate().getTime()
- clock.getCurrentTime(), TimeUnit.MILLISECONDS);
// clock.advanceTime(10, TimeUnit.SECONDS);
FactHandle operationHandle = entryPoint.insert(operation);
LOGGER.debug("Insertion done: " + operationHandle.toExternalForm());
}
LOGGER.info("done with events");
// check...
Assert.assertTrue("Rule not fired...", listener
.isRuleFired("overActivity"));
}
}
I also use a TrackingWorkingMemoryEventListener to track events.
The test because since the rule is not fired, and the log contains the
following lines :
Console> 2010-05-17 11:15:15|INFO ||DroolsRulesTestCase.testActivity|loading
events
Console> 2010-05-17
11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
[date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1, hostname=server1,
ipAddress=1.2.3.4, operation=null, requestSize=0, responseSize=0]
Console> 2010-05-17 11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Moving
clock from Thu Jan 01 01:00:00 CET 1970 to Fri Apr 30 18:26:47 CEST 2010
Console> 2010-05-17 11:15:15|WARN
||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [event
fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1,
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
Console> 2010-05-17
11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010, executionTime=1,
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
Console> 2010-05-17
11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
[date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164, hostname=server1,
ipAddress=1.2.3.4, operation=CONSULTATION, requestSize=1299,
responseSize=895]
Console> 2010-05-17 11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Moving
clock from Fri Apr 30 18:26:47 CEST 2010 to Fri Apr 30 18:27:11 CEST 2010
Console> 2010-05-17 11:15:15|WARN
||TrackingWorkingMemoryEventListener.objectRetracted|Object retracted:
[event fid:1:1:Operation [date=Fri Apr 30 18:26:47 CEST 2010,
executionTime=1, hostname=server1, ipAddress=1.2.3.4, operation=null,
requestSize=0, responseSize=0]]
Console> 2010-05-17 11:15:15|WARN
||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [event
fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164,
hostname=server1, ipAddress=1.2.3.4, operation=CONSULTATION,
requestSize=1299, responseSize=895]]
Console> 2010-05-17
11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010, executionTime=164,
hostname=server1, ipAddress=1.2.3.4, operation=CONSULTATION,
requestSize=1299, responseSize=895]]
Console> 2010-05-17
11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Inserting Operation
[date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1, hostname=server1,
ipAddress=1.2.3.4, operation=null, requestSize=0, responseSize=0]
Console> 2010-05-17 11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Moving
clock from Fri Apr 30 18:27:11 CEST 2010 to Fri Apr 30 18:28:47 CEST 2010
Console> 2010-05-17 11:15:15|WARN
||TrackingWorkingMemoryEventListener.objectRetracted|Object retracted:
[event fid:2:2:Operation [date=Fri Apr 30 18:27:11 CEST 2010,
executionTime=164, hostname=server1, ipAddress=1.2.3.4,
operation=CONSULTATION, requestSize=1299, responseSize=895]]
Console> 2010-05-17 11:15:15|WARN
||TrackingWorkingMemoryEventListener.objectInserted|Object inserted: [event
fid:3:3:Operation [date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1,
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
Console> 2010-05-17
11:15:15|DEBUG||DroolsRulesTestCase.testActivity|Insertion done: [event
fid:3:3:Operation [date=Fri Apr 30 18:28:47 CEST 2010, executionTime=1,
hostname=server1, ipAddress=1.2.3.4, operation=null, requestSize=0,
responseSize=0]]
Console> 2010-05-17 11:15:15|INFO ||DroolsRulesTestCase.testActivity|done
with events
I guess there is something wrong with my use of the PseudoClock, since
previous operations are retracted before a new one is inserted, which I
believe prevents the rule to be fired.
Can you help me ?
Thank you in advance
Regards,
Xavier
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Fusion-Can-t-d...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 9 months
Drools Roadmap - Planned Release 5.1 release date
by McDonald, Daniel
Hi,
I was wondering if there is a planned release date for Release 5.1?
Thank you,
Daniel McDonald
Fidelity National Information Services - Research & Development
Office phone: (972) 691-6593
Mobile phone (214) 697-8163
_____________
The information contained in this message is proprietary and/or confidential. If you are not the
intended recipient, please: (i) delete the message and all copies; (ii) do not disclose,
distribute or use the message in any manner; and (iii) notify the sender immediately. In addition,
please be aware that any message addressed to our domain is subject to archiving and review by
persons other than the intended recipient. Thank you.
_____________
15 years, 9 months
5.1M2 Issue: LeftTupleSinkUpdateAdapter onlys supports assertLeftTuple
by malkhafaji
Hello,
Did anyone have an issue with the latest M2 files? I just decided to try
them out and upon trying to fire my first set of rules (which worked
perfectly with M1 from 02/10/10), I get the following exceptions on this
line:
ksession.update(factHandle, myObject);
Any ideas?
java.lang.UnsupportedOperationException: LeftTupleSinkUpdateAdapter onlys
supports assertLeftTuple method calls
INFO|12572/0|10-05-12 15:20:50| at
org.drools.reteoo.EvalConditionNode$LeftTupleSinkUpdateAdapter.retractLeftTuple(EvalConditionNode.java:460)
INFO|12572/0|10-05-12 15:20:50| at
org.drools.reteoo.ModifyPreviousTuples.retractTuples(ModifyPreviousTuples.java:101)
INFO|12572/0|10-05-12 15:20:50| at
org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:177)
INFO|12572/0|10-05-12 15:20:50| at
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1389)
INFO|12572/0|10-05-12 15:20:50| at
org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1285)
INFO|12572/0|10-05-12 15:20:50| at
org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:248)
INFO|12572/0|10-05-12 15:20:50| at
com.medcpu.mpu.pp.engine.Drools.updateWorkingMemory(Drools.java:524)
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/5-1M2-Issue-LeftTuple...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 9 months
org.drools.reteoo.AlphaNode$AlphaMemory cannot be cast to org.drools.reteoo.BetaMemory
by Axelrod, Nelson
Can anyone explain what this ConsequenceException means?
Exception in thread "main" org.drools.runtime.rule.ConsequenceException:
java.lang.ClassCastException: org.drools.reteoo.AlphaNode$AlphaMemory
cannot be cast to org.drools.reteoo.BetaMemory
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleEx
ception(DefaultConsequenceExceptionHandler.java:23)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
at
org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemo
ry.java:660)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemo
ry.java:627)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowle
dgeSessionImpl.java:183)
at
org.jcvi.annotation.rulesengine.RulesEngine.fireAllRules(RulesEngine.jav
a:210)
at org.jcvi.annotation.Aruba.run(Aruba.java:311)
at org.jcvi.annotation.RunTest.main(RunTest.java:55)
Nelson
15 years, 9 months
Drools memory usage issue
by Shah, Malay
Hi,
We have an drools 5.0.1 application that uses StatelessSession and high volume of objects (facts) that we need to apply static rules on, and having out of memory issues doing so. We added the following three properties as given in the drools documentation for decreasing the memory usage:
drools.shadowproxy=false
drools.maintainTms=false
drools.sequential=true
As per the following blog, there is an algorithm to minimize the engine work, and memory usage.
http://blog.athico.com/2007/07/sequential-rete.html
Are the properties above sufficient to trigger this algorithm, or do we need to do write extra code for this?
Also, does the "drools.sequential" property make sure that rules are applied sequentially on facts? If so, is there a hook into the drools engine to figure out which particular rule is consuming more memory or having more execution time?
Thanks in advance.
Malay Shah
--------------------------------------------------------------------------
NOTICE: If received in error, please destroy, and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. We may monitor and store emails to the extent permitted by applicable law.
15 years, 9 months
Discriminator mode of the join node
by HONG DENG
Hi,i am a newbie about drools and my english is not good enough ,so i hope
someone can understand my question:)
Who can tell me the Discriminator mode of join node that can support what
kind of business scenarios?
15 years, 9 months
Simple decision service, zero coding (was: Drools5 in tomcat 5)
by Rubén Marrero
Hi again:
We've been learning, installing and in general getting ourselves acquainted with drools.
The last iteration left us with a correctly installed drools-server service, which can be used with curl on the command line. We post data and get data back, we basically ended up installing verbatim an example from somewhere on the internets.
Now we've hit what appears to be a brick wall. We don't want / can't code in Java, and we still want to have a decision service.
Here's what we need. Please feel free to comment on the requirement itself or the possible solution (if any)
1. Creation of rules on a simple text file, residing on our PHP application tree.
2. Any amount of rules say in /var/www/my_web_app/lib/drooles :-)
3. Creation and removal of said files without any kind of restarting, reloadin' or resettin'
4. Invocation of any given rule, using libcurl inside PHP and connecting to a REST URL. POSTing a lump of JSON data, and expecting JSON data as result.
5. No Java coding or syntax in the rules file.
6. Simple syntax for the rules; something like YAML would be great.
7. No external requirements (Jars or whatnot)
We see all the time that the rules have import statements in them, meaning that they are in some way Java themselves. We want to use some neutral syntax so that our PHP coders can express business rules in a pinch, and just execute it.
Is this a realistic set of expectations? can it be done?
Thanks for your time,
Rubén
15 years, 9 months