Drools Integration
Introduction
In 3.0, there is the possibility to activate rules in Operations.
Rules is a new way to express some business coding that sometimes is more appropriate than procedural javascript.
Note that rules do not replace JavaScript, but in some cases is more efficient and more maintainable.
By default, the rules management system uses JBoss Drools: http://www.jboss.org/drools
Using Rules in Operations
A Rule based step can be added in operations:
An example of rules:
:
Rules definitions
Rules can be
- inline: the rule (or rules) are defined directly in the step.
- knowledge base: the rules are defined in external files
Objects added to the rule set
In an operation step, records (data) are added to the rule session.
- if the current record (data) is an entity, the entity is added
- if the data is a list of entities, all the entities are added in the rule session
Setting values in Rules
In the "then" clause of rules, you can set properties:
Calling Operations in Rules
You can call operations on objects that are defined in the Rules:
- if the operation has the "data" parameter defined as of type "Entity" of the same type, the operation is considered as an "instance" operation, and can be called directly on the object. Example:
- if the operation has different data defined as the case above, the operation can be called using the "Registry" object:
Rules Examples
Here are some examples of rules. In those examples, you can see:
- accessing properties (with the mvel dialect)
- joining entities by reference
- inserting related entities in the rule session for further processing
- setting properties
- calling operation on entities
- using salience
import com.requea.entity.Registry;
import com.requea.entity.*;
rule"New monitor"
dialect"mvel"
when
$monitor : rqServerMonitor()
then
// eval server info
insert($monitor.rqServer);
// eval memory info
insert($monitor.rqHeapMemoryInfo);
end
rule"MEM_HIGH_0001 - When memory is too high"
dialect"mvel"
when
$mem : rqMemoryInfo(rqUsed > 0.9 * rqMax)
$monitor : rqServerMonitor(rqHeapMemoryInfo == $mem)
then
// trigger an alarm
$alarm = Registry.rqServerMonitorAlarm.Trigger($monitor, "MEM_HIGH_0001");
// this is a low priority alarm
$alarm.almPriority = "Low";
insert($alarm);
end
rule"MEM_HIGH_0001 - Memory Alarm on a production server"
dialect"mvel"
when
$server : rqRepoServerConfiguration(rqProduction == true)
$monitor : rqServerMonitor(rqServer == $server)
$alarm : rqServerMonitorAlarm(almPriority != "High", rqServerMonitor == $monitor)
then
// trigger an alarm
modify($alarm) {
// priority should be high
almPriority = "High";
}
end
rule"Save Alarms"
dialect"mvel"
salience -50
when
$alarm : rqServerMonitorAlarm()
then
// save the alarm
$alarm.Save();
end