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:

Rule operation Step

An example of rules:

Rules based example:

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:

        $alarm.almPriority = "Low";

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:
    $alarm.Save();
  • if the operation has different data defined as the case above, the operation can be called using the "Registry" object:
    $alarm = Registry.rqServerMonitorAlarm.Trigger($monitor, "MEM_HIGH_0001");

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
package com.requea.rules;

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
Tags:
Created by Pierre Dubois on 2011/10/24 10:44
     
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 9.11.5 - Documentation