Rule For Counting Planning Variables/Entities
by newbie
I am new user of drools and I'm trying to recreate an application similar to
nurse rostering. This time assigning an employee to a department for a
specific period of time. My hard constraint was an employee must be assigned
to a department at least 3 months. My planning entity is
DepartmentAssignment and planning variable Employee. The planning entity
class looks like this:
@PlanningEntity(difficultyComparatorClass =
DepartmentAssignmentDifficultyComparator.class)
@XStreamAlias("DepartmentAssignment ")
public class DepartmentAssignment extends AbstractPersistable{
private Duration duration; // per month
private Department department;
//Planning variable : changes during planning, between score calculations.
private Employee employee;
How can I make such rule? I tried using this but it seems not working. Am i
missing something?
rule "minimumNumberofMonths"
when
$employee : Employee()
$department : Department()
$assignedNumberOfMonths : Number(intValue > 0 && < 3) from accumulate(
$assignment: DepartmentAssignment(
employee!= null,
department== $department,
employee== $employee
), count($assignment)
)
then
insertLogical(new IntConstraintOccurrence("minimumNumberofMonths",
ConstraintType.NEGATIVE_HARD,
1,
$employee, $department));
end
--
View this message in context: http://drools.46999.n3.nabble.com/Rule-For-Counting-Planning-Variables-En...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
Session missing rules
by sandeep_nambiar
I have integrated Drools 5.3 in my Web application(running in Jboss 7.1). We
were creating rules before starting the application. Now we are trying to
create rules dynamically.
Have added the folder path where I am creating rules dynamically in
change-set.xml .
After creating rules during runtime I am doing all required things mentioned
in the documents.
There itself after adding the new rule if i do a check in the available
KnowledgePackages , I can see the new rule present in Package...
But once I restart the Jboss ,and I see in the session some rules which I
have created before are missing..its not always the same rule..it varies on
each restart.
We are using StatefulSessions and I have made the "drools.agent.newInstance"
as false..
Please provide a solution for the same...
--
View this message in context: http://drools.46999.n3.nabble.com/Session-missing-rules-tp4026709.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
Govner - drools:resource-change-scanner
by san_hegde
Hi All,
Our application is developed using Spring framework. We have our Rules in
Guvnor. In our application we use resource scanner to poll Guvnor to check
and download the latest package if modified like below.
<drools:resource-change-scanner id="s1" interval="3600" />
The issue is in case if Guvnor goes down and during that time if scanner
checks Guvnor and finds Guvnor is down, THEN
1) In the application the local copy of the Rules package which Spring bean
have is lost. Hence Rules will not be fired.
2) Even if we restart the Guvnor, the scanner not scanning the resource.
I have one package in Guvnor. Before the Guvnor went down the log message
from scanner was
"ResourceChangeScanner attempt to scan 1 resources"
After the Guvnor went down the log message is
"ResourceChangeScanner attempt to scan 0 resources"
That means it is not even scanning the Guvnor resource as the log message
says its 0 resource scanning.
Any idea on how to handle this kind of scenario where even if Guvnor goes
down Spring should still should continue using its spring local copy which
it downloaded while starting the application.
My complete spring bean configuration is as below.
<bean id="EnvConfiguration"
class="com.hp.rebates.grs.model.rules.conf.EnvConfiguration">
</bean>
<drools:resource id="resource"
source="#{EnvConfiguration.ruleEngineURL}"
type="CHANGE_SET" />
<drools:resource-change-scanner id="s1"
interval="3600" />
<drools:kagent kbase="knowledgeBase" id="kagent"
new-instance="false">
<drools:resources>
<drools:resource ref="resource" />
</drools:resources>
</drools:kagent>
<drools:kbase id="knowledgeBase">
<drools:resources>
<drools:resource ref="resource" />
</drools:resources>
</drools:kbase>
<drools:ksession id="knowledgeSession" type="stateless"
kbase="knowledgeBase" />
<bean id="StartChangeScanner"
class="com.hp.rebates.grs.model.rules.conf.StartChangeScanner">
</bean>
--
View this message in context: http://drools.46999.n3.nabble.com/Govner-drools-resource-change-scanner-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
how can I modify a batch of objects
by Elran Dvir
Hi all,
I am trying to identify a port scan event.
The basic fact is connection log. For each combination of src (source IP) and dst (destination IP) , detect a port scan event, if over 60 seconds there were at least 20 connection logs with different service and protocol.
The event will stay closed for 10 minute - no event will be sent during this time for this combination of src and dst. The event will contain the connection logs' ids (markers).
I tried to implement it using "accumulate" and "over window:time" but it consumes too much memory.
So I am trying to imitate this functionality using several rules and facts.
My drl contains the following lines (among others):
declare CorrelatedEvent
@role( event)
@expires( 600s )
end
declare CandidatesWindow
@role( event)
@expires( 60s )
end
rule "Create Port Scan Event - 1"
enabled true
dialect "java"
no-loop
when
$log : Log()
not CorrelatedEvent(getId() == "portScan" , groupByFieldsMap.get("src") == $log.fieldsMap.get("src") ,groupByFieldsMap.get("dst") == $log.fieldsMap.get("dst"))
$windows : ArrayList()
from collect( CandidatesWindow(getRuleId() == "portScan" , groupByFieldsMap.get("src") == $log.fieldsMap.get("src") , groupByFieldsMap.get("dst") == $log.fieldsMap.get("dst")))
then
String id = $log.fieldsMap.get("port").toString();
System.out.println(new Date().toString()+" windowSize: " + $windows.size());
for (Object windowObj : $windows) {
CandidatesWindow window = (CandidatesWindow) windowObj;
modify ( window ) { addLog($log, id) }
}
CandidatesWindow newWindow = new CandidatesWindow("portScan", true);
newWindow.groupByFieldsMap.put("src", $log.fieldsMap.get("src"));
newWindow.groupByFieldsMap.put("dst", $log.fieldsMap.get("dst"));
newWindow.addLog($log, id);
insert(newWindow);
end
This imitates sliding time windows.
when I tested it, I got the following exception:
Exception executing consequence for rule "Create Port Scan Event - 1" in com.checkpoint.correlation.impl.drools.package1: java.util.ConcurrentModificationException
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.checkpoint.correlation.impl.drools.DroolsCEPEngineV1.insertEvents(DroolsCEPEngineV1.java:173)
at com.checkpoint.correlation.impl.feeder.JsonFileFeeder.init(JsonFileFeeder.java:68)
at com.checkpoint.correlation.server.CorrelationServer.initFeeder(CorrelationServer.java:63)
at com.checkpoint.correlation.server.CorrelationServer.run(CorrelationServer.java:28)
at com.checkpoint.correlation.server.CorrelationServer.runServer(CorrelationServer.java:101)
at com.checkpoint.correlation.server.CorrelationServer.main(CorrelationServer.java:85)
Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at com.checkpoint.correlation.impl.drools.package1.Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859.defaultConsequence(Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859.java:11)
at com.checkpoint.correlation.impl.drools.package1.Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
at com.checkpoint.correlation.impl.drools.package1.Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859DefaultConsequenceInvoker.evaluate(Unknown Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
... 11 more
It is caused by modify ( window ) in the for loop.
How can I make it work?
Thanks.
12 years, 5 months
Drools get value from stateful session
by forsakendoll
How can I get the value from a stateful session. As they say I can use this:
protected Collection findFacts( final StatefulKnowledgeSession session,
final String factClass )
{
ObjectFilter filter = new ObjectFilter()
{
@Override
public boolean accept( Object object )
{
return object.getClass().getSimpleName().equals( factClass
);
}
};
Collection results = session.getObjects( filter );
return results;
}
to get the value from the rules. Given the fact the code already red the
rules when I tried this:
StatefulKnowledgeSession ksession =
aKnowledgeBase.newStatefulKnowledgeSession();
ksession.insert( aBean );
ksession.fireAllRules();
Collection result = findFacts( ksession,
"com.neu.als.thesis.db.beans.StudentBean" );
ksession.dispose();
for( Object test : result )
{
System.out.println( test == null );
System.out.println( test );
}
Nothing is printed. What is the proper way to get bean that I inserted in
the rules?
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-get-value-from-stateful-session-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
Two Guvnor instances sharing repository
by Demian Calcaprina
Hi Guys,
I have two guvnor instances. They are using a mysql db repository. I would
like both to point to the same database.
I configured them both to use the same database in the repository.xml, but
it starting throwing errors and they were not in sync.
Errors are like this
11:43:29,597 WARN [com.arjuna.ats.arjuna] (Transaction Reaper)
ARJUNA012117: TransactionReaper::check timeout for TX
0:ffff7f000101:55ee0fc5:527e486a:3f in state RUN
11:43:29,599 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0)
ARJUNA012095: Abort of action id 0:ffff7f000101:55ee0fc5:527e486a:3f
invoked while multiple threads active within it.
11:43:29,601 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0)
ARJUNA012108: CheckedAction::check - atomic action
0:ffff7f000101:55ee0fc5:527e486a:3f aborting with 1 threads active!
11:43:29,602 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0)
ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction
Reaper Worker 0,5,main] successfully canceled TX
0:ffff7f000101:55ee0fc5:527e486a:3f
11:44:37,245 INFO [org.apache.jackrabbit.core.query.lucene.IndexMerger]
(jackrabbit-pool-5) merged 791 documents in 568 ms into _p.
11:44:37,377 INFO [org.apache.jackrabbit.core.query.lucene.IndexMerger]
(jackrabbit-pool-2) merged 1370 documents in 709 ms into _o.
11:48:07,300 WARN [org.jboss.seam.transaction.TransactionServletListener]
(http--127.0.0.1-8080-5) Error starting the transaction:
javax.transaction.NotSupportedException:
BaseTransaction.checkTransactionState - ARJUNA016051: thread is already
associated with a transaction!
at
com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.begin(BaseTransaction.java:63)
at
com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.begin(BaseTransactionManagerDelegate.java:65)
at
org.jboss.tm.usertx.client.ServerVMClientUserTransaction.begin(ServerVMClientUserTransaction.java:142)
at org.jboss.seam.transaction.UTTransaction.begin(UTTransaction.java:51)
[seam-transaction-3.1.0.Final.jar:3.1.0.Final]
at
org.jboss.seam.transaction.DefaultSeamTransaction.begin(DefaultSeamTransaction.java:88)
[seam-transaction-3.1.0.Final.jar:3.1.0.Final]
at
org.jboss.seam.transaction.TransactionServletListener.requestInitialized(TransactionServletListener.java:110)
[seam-transaction-3.1.0.Final.jar:3.1.0.Final]
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
[jbossweb-7.0.13.Final.jar:]
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
[jbossweb-7.0.13.Final.jar:]
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[jbossweb-7.0.13.Final.jar:]
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
[jbossweb-7.0.13.Final.jar:]
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
[jbossweb-7.0.13.Final.jar:]
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
[jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
[jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]
Caused by: java.lang.IllegalStateException:
BaseTransaction.checkTransactionState - ARJUNA016051: thread is already
associated with a transaction!
at
com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.checkTransactionState(BaseTransaction.java:257)
at
com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.begin(BaseTransaction.java:59)
... 13 more
I also tried both instances to also share the repository folder, both this
is failing because it lockes the file
Caused by: javax.jcr.RepositoryException: The repository home
/home/calcacuervo/development appears to be in use since the file named
.lock is locked by another process.
at
org.apache.jackrabbit.core.util.RepositoryLock.tryLock(RepositoryLock.java:166)
Any idea on how could I do it?
Thanks!
Demian
12 years, 5 months
Drools in a web application
by forsakendoll
I'm very new to drools. I know this question is really a noob question but
please bear with me. I'm using Spring MVC and I want to integrate drools
expert to my project. What I've done so far is to integrate the hello world
sample of drools expert. But now what I want to do is:
1. Send a bean to the rules for it to evaluate.
2. Modify the bean depending on the rules
3. Send it back to the controller to make a response to the user.
I was able to do the number 1. But for number 2 and 3. I don't know how to
do it. I want to have a nested rule. But now I'm only capable of doing this
rule:
global String $test;
rule "Excellent"
when
$m: FLTBean ( listeningScore > 85 )
$p: FLTBean ( listeningScore < 101 )
then
$test = "Excellent";
System.out.println( $test );
end
I don't know yet how can I make a nested rule. Please give me a simple
example that a newbie like me can understand.
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-in-a-web-application-tp4026704.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
Where to cache KnowledgeAgent
by darrell.pittman
Hello,
I am new to Drools a starting a new Java EE 6 application that will use
drools. We are not using Guvnor. I am wondering what is the suggested way
of creating the knowledge agent and where to cache it. EJB's shouldn't read
from the file system so I guess a Singleton EJB is out as far as loading the
knowledgebase goes. Should I load knowledgebase in a ServletContextListener
and store it in the ServletContext and pass it into my EJB's? What is the
recommend practice?
--
View this message in context: http://drools.46999.n3.nabble.com/Where-to-cache-KnowledgeAgent-tp4026696...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months