Drools server and knowledge agent functionality
by Manuel Ortiz
Hello everybody:
I am taking a look at Drools Integration documentation to understand how
Drools server works and how can be used, and have a doubt concerning, let's
say... 'KnowledgeAgent capabilities'. Does Drools server support on the fly
rule updating as when using KnowledgeAgent to create KnowledgeBase objects?
If it does, where can be configured 'KnowledgeAgent related' properties such
as newInstance or resource scanner interval?
Thank you in advance for your time.
Kind regards,
Manuel Ortiz.
12 years, 1 month
Problem with chained planning variables
by Juan Ignacio Barisich
Hi everybody.
I have a problem with chained planning variables.
I'm using optaplanner 5.5.0.Final.
I have a planning entity like:
@PlanningEntity()
public class Case implements Chained {
private Chained previous;
@PlanningVariable(chained = true)
@ValueRanges({
@ValueRange(type = ValueRangeType.FROM_SOLUTION_PROPERTY,
solutionProperty = "doctors"),
@ValueRange(type = ValueRangeType.FROM_SOLUTION_PROPERTY,
solutionProperty = "cases", excludeUninitializedPlanningEntity = true) })
public Chained getPrevious() {
return previous;
}
}
A fact class:
public class Doctor implements Chained {
...
}
An a solution class:
public class Plan extends implements Solution<HardAndSoftScore> {
private List<Doctor> doctors;
private List<Case> cases;
private HardAndSoftScore score;
@PlanningEntityCollectionProperty
public List<Case> getCases() {
return cases;
}
public Collection<? extends Object> getProblemFacts() {
return new ArrayList<Doctor>(doctors);
}
}
The equals / hashCode / clone methods are inspired on the
TravelingSalesmanTour example.
I want that Optaplanner generates chains like:
DoctorA <- Case1 <- Case2
DoctorB <- Case3
This model tries to represent a list of Cases assigned to each Doctor.
Suppose I build a solution like:
Plan plan = new Plan();
plan.setDoctors(DoctorA, DoctorB); //pseudo-code
plan.setCases(Case1, Case2); //pseudo-code
Then I build a solver:
Solver solver = getSolverFactory().buildSolver();
solver.setPlanningProblem(plan);
solver.solve();
Plan bestPlan = (Plan) solver.getBestSolution();
The problem is that, Optaplanner is not testing all the posible
combinations of chains. I mean, suppose that we know that the better
solution (based on the scoring rules) is:
DoctorA
DoctorB <- Case1 <- Case2
But Optaplanner seems to test only chains with DoctorA, so the result of
calling getBestSolution() is:
DoctorA <- Case1 <- Case2
I guess that Optaplanner only test chains whit DoctorA, becouse it logs
lines like:
...
DEBUG: org.drools.planner.core.localsearch.DefaultLocalSearchSolverPhase
- Step index (1), time spend (20002), score (1hard/2soft), best
score (1hard/2soft), accepted/selected move count (0/58187) for picked step
(Case [id=2, previous=Doctor [id=1]] => Case [id=1, previous=Case [id=2,
previous=Doctor [id=1]]]).
...
That is, no lines whith "DoctorB" are logged.
If the doctor list is inverted, the same problem happen (the DoctorA is no
processed). That is:
Plan plan = new Plan();
plan.setDoctors(DoctorB, DoctorA); //pseudo-code
plan.setCases(Case1, Case2); //pseudo-code
Solver solver = getSolverFactory().buildSolver();
solver.setPlanningProblem(plan);
solver.solve(); // DoctorA is not part of chains
I guess the problem is on the solver configuration, specifically on the
localSearch configuration:
<localSearch>
<unionMoveSelector>
<changeMoveSelector>
<valueSelector/>
</changeMoveSelector>
<swapMoveSelector />
<subChainChangeMoveSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
</subChainChangeMoveSelector>
<subChainSwapMoveSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
</subChainSwapMoveSelector>
</unionMoveSelector>
<acceptor>
<planningEntityTabuSize>9</planningEntityTabuSize>
</acceptor>
<forager>
<minimalAcceptedSelection>2000</minimalAcceptedSelection>
</forager>
</localSearch>
I tried some alternatives to this configuration, but with no success.
Do you know what I am doing wrong?
Thanks a lot.
Regards
12 years, 1 month
Question about custom accumulation functions
by Bruno Freudensprung
Hi,
While testing my custom accumulation function I noticed an unexpected
behavior (th'ats of course a personal point of view).
It seems that Drools 5.1 calls accumulate(...) and getResult(...) as
many times as the number of accumulated facts (accumulate, getResult,
accumulate, getResult, etc...).
Is it supposed to work like this?
Best regards,
Bruno.
12 years, 1 month
gives error while retracting an object
by Ganesh
Hi Team,
I am using drools-guvnor 5.4 version and designer 2.1 version,
I am calling an drools object from web service
While retracting an object I am getting
classCastException,"*java.lang.boolean cannot be cast to
org.drools.spi.activation* "
I am using session.retract(droolsobject);-Every time I got the error in this
line
This issue rise very often,
I think this issue is due to increase on load on object ,As I found this is
the reason while I search in INTERNET
Can you please tell me how to solve this
Regards
Ganesh N Neelekani
--
View this message in context: http://drools.46999.n3.nabble.com/gives-error-while-retracting-an-object-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 1 month
Please help me on hibernate-meet-drools
by Hong Ju
Hi,
I would like Drools to save my POJO objects as Hibernate Entities so that I can see my POJO objects as db tables in my database.
I tried to make this work by searching on the net, but there is very limited example on this topic, my code does not have any error, but it does not save any tables in my db. I attached my project in this email, if someone can help me on this, this will be so great and make me move forward.
Thank you so much in advance,
Hong Lily Ju
Software Engineer
hong.ju(a)steward.org<mailto:derrick.smith@steward.org>
Steward Heath Care
[Description: cid:image001.png@01CD0DC1.C0D81BD0]
Office: 781-375-3034
Cell: 781-801-9313
12 years, 2 months
Implementation of my use case - what am I doing wrong?
by Elran Dvir
Hi all,
A few weeks ago I posted a question about my use case to the mailing list. The correspondence is attached.
This is the example of the use case I implemented:
Port scan event - the basic event is connection log. For each combination
of source_ip and destination_ip, detect a port scan event,
if over 5 seconds there were more than 2 connection logs with
different ports .
The event will stay open for 10 seconds and an update will be
sent for any new port detected. Every update will contain the count of
connection logs combining it and their id ("marker").
the drl fie:
package test;
import correlation.impl.drools.Log
import correlation.impl.drools.CorrelatedEvent
global correlation.server.EventsHandler externalEventsHandler;
declare Log
@role( event)
end
declare CorrelatedEvent
@role( event)
@timestamp( getTimestamp().getTime() )
@expires( 10s )
@duration( getDuration() )
end
// this rule will create a "Port Scan" event if none exist for this group-by values
rule "Create Port Scan Event"
dialect "java"
no-loop
when
$log : Log() from entry-point "Log stream" //get all the logs in the last 5 seconds
accumulate( Log( this after[0s,5s] $log, fieldsMap.get("src") == $log.fieldsMap.get("src") , fieldsMap.get("dst") == $log.fieldsMap.get("dst"), $port : fieldsMap.get("port")) from entry-point "Log stream";
$portSet : collectSet($port);
$portSet.size > 2 )
accumulate( Log( this after[0s,5s] $log, fieldsMap.get("src") == $log.fieldsMap.get("src") , fieldsMap.get("dst") == $log.fieldsMap.get("dst"), $marker : fieldsMap.get("marker")) from entry-point "Log stream";
$markerSet : collectSet($marker))
not CorrelatedEvent(getName() == "portScan" , fieldsMap.get("src") == $log.fieldsMap.get("src") , fieldsMap.get("dst") == $log.fieldsMap.get("dst"))
then
System.out.println(drools.getRule().getName());
CorrelatedEvent $ce = new CorrelatedEvent();
$ce.setName("portScan");
$ce.setEventsHandler(externalEventsHandler);
$ce.setDurationInSec(10);
$ce.fieldsMap.put("src", $log.fieldsMap.get("src"));
$ce.fieldsMap.put("dst", $log.fieldsMap.get("dst"));
$ce.endUpdate($markerSet);
insert($ce);
end
rule "Create Port Scan Event - update"
dialect "java"
no-loop
when
$ce: CorrelatedEvent(getName() == "portScan")
accumulate( Log(fieldsMap.get("src") == $ce.fieldsMap.get("src") , fieldsMap.get("dst") == $ce.fieldsMap.get("dst") , $port : fieldsMap.get("port") , (this meets $ce || this during $ce || this metby $ce)) from entry-point "Log stream";
$portSet : collectSet($port);
$portSet.size > 0 )
accumulate( Log(fieldsMap.get("src") == $ce.fieldsMap.get("src") , fieldsMap.get("dst") == $ce.fieldsMap.get("dst") , $marker : fieldsMap.get("marker") , (this meets $ce || this during $ce || this metby $ce)) from entry-point "Log stream";
$markerSet : collectSet($marker))
then
System.out.println(drools.getRule().getName());
modify( $ce ) {endUpdate($markerSet)}
end
my questions:
1) If I have only one stream of data , can I omit the use of entry point and insert logs to the session ? Or the use of entry points is mandatory in Drools Fusion?
2) When I tested it with matching data, rule "Create Port Scan Event - update" was never fired. When I replaced "(this meets $ce || this during $ce || this metby $ce)" with "this after $ce.getStartTime() , this before $ce.getEndTime()" everything worked fine.
Why?
3) I tried to use sliding windows in rule "Create Port Scan Event" and an exception was thrown at runtime. I decided to use "this after[0s,5s] $log" instead. Is it correct?
4) Is my basic Implementation correct?
Thank you all very much.
Log class:
public class Log {
public HashMap<String, Object> fieldsMap = new HashMap<>();
}
CorrelatedEvent class:
public class CorrelatedEvent
{
public Map<String, Object> fieldsMap;
private String name;
private Set<String> markersSet;
private long logsCount;
private Calendar startTime;
private Calendar endTime;
private int duration;
private EventsHandler eventsHandler;
public CorrelatedEvent()
{
startTime = Calendar.getInstance();
endTime = Calendar.getInstance();
endTime.setTime(startTime.getTime());
fieldsMap = new HashMap<>();
markersSet = new HashSet<>();
logsCount = 0;
}
public Date getTimestamp()
{
return startTime.getTime();
}
public Date getStartTime()
{
return startTime.getTime();
}
public Date getEndTime()
{
return endTime.getTime();
}
public void setDurationInSec(int duration)
{
this.duration = duration;
endTime.setTime(startTime.getTime());
endTime.add(Calendar.SECOND, duration);
}
public int getDuration()
{
return duration;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
fieldsMap.put("name", name);
}
public void setEventsHandler(EventsHandler eventsHandler)
{
this.eventsHandler = eventsHandler;
}
public void endUpdate(Set<String> markersSet)
{
this.markersSet.addAll(markersSet);
if (this.markersSet.size() > logsCount) {
logsCount = this.markersSet.size();
if (eventsHandler == null)
return;
Map<String, Object> clonedFieldsMap = getClonedFieldsMap();
clonedFieldsMap.put("markers", this.markersSet.toString()); //need a function that converts a set of markers to a "\n" separated list
clonedFieldsMap.put("count", logsCount);
eventsHandler.handleEvent(clonedFieldsMap);
}
}
private Map<String, Object> getClonedFieldsMap()
{
Map<String, Object> clonedFieldsMap = new HashMap<>();
clonedFieldsMap.putAll(fieldsMap);
return clonedFieldsMap;
}
}
12 years, 2 months
Guvnor 5.5 bug - when the advanced enum feature is used, the selected value is not saved in special condition
by Sean Su
When there are 3 drop downs, one determines the values of the other, the
selection in the last drop down is not saved when changing the rules twice
in the row.
For example: I have the following statement:
in fact [field1] [field2][field3]
each of the field is presented as a drop down by using the advanced ENUM
feature - 1 determines the values in 2 and the selection of 2 determines
the value of 3.
After the value in field3 is selected, I can move on and make the changes
in the rule. When the first change occurred, Guvnor remembers the values
being selected in all 3 fields. But when another change is make, the
selected value in the last field (field3) will be forgotten. Please note
this is only happening to the last field. I did not go further and make the
statement contain more than 3 drop downs.
I have tested this several times and am confident this is a bug in the 5.5
final version.
Thanks
Sean
12 years, 2 months