1

Right now, in my drools project I have two groups of rules in separate DRL files which are split by agenda groups. For the agenda group "preCheck" I am setting auto focus to true for each rule in that agenda group. Example:

rule "preCheckDuplicate"
    agenda-group "preCheck"
    auto-focus true
    no-loop true
    salience 50
    when
        $f : IngestFileMetadata(isDuplicate.equalsIgnoreCase("True"))
    then
        $f.setIsDuplicate("True");
end

For the other agenda group - "defaultRules" - the rules do NOT have the auto focus attribute set. Example:

rule "duplicate file default"
    agenda-group "defaultRules"
    activation-group "isDuplicate"
    no-loop true
    salience 0
    when
        $f : IngestFileMetadata(isDuplicate.equals("True"))
    then
        insert(createResponse($f));
end

When invoking the rules via the rest API, I am also trying to set focus to the "preCheck" agenda group through the JSON payload. Example:

{
  "lookup": "defaultStatelessKieSession",
  "set-focus": "preCheck",
  "commands": [
    {
      "insert": {
        "out-identifier": "IngestFileMetadata",
        "return-object": "true",
        "entry-point": "DEFAULT",
        "object": {
          "com.hms.ingestion.rules.IngestFileMetadata": {
              * * * * * data attributes here * * * * *
          }
        }
      }
    },
    {
      "fire-all-rules": {"out-identifier": "fired"}
    },
    {
      "query": {"name": "rulesResponses", "out-identifier": "rulesResponses"}
    }
  ]
}

However, when the rules are executed, it seems like the rules in the "defaultRules" agenda group are being evaluated first. I have no idea why. I'm relatively new to drools so it's entirely possible I'm not correctly understanding the concept of agenda groups, but I was sure this design would ensure the "preCheck" rules would evaluate first.

Can anyone provide any insight on why this is not happening? If I need to provide more details I can.

Thanks in advance.

Mike
  • 269
  • 3
  • 8
  • 20

2 Answers2

3

Agenda groups allow you to place rules into groups, and to place those groups onto a stack. The stack has push/pop behavior. Before going into how to use agenda group firstly, I want to say that configuring agenda group is depends on what type of KieSession you are using in your rule engine. For stateful Session, you can directly configure it by calling ksession.getAgenda().getAgendaGroup( "preCheck" ).setFocus();. For Stateless Session, you have to declare an explicit rule to set the focus of the session to the particular Agenda. You can use the below rule to set agenda in Stateless Session:

 rule "global"
 salience 100
    when
        $f : IngestFileMetadata()
    then
        drools.setFocus($f.getAgenda());
end

Note : You have to find some way to get the agenda variable in your rule file. In the above example, getAgenda() is a method in your IngestFileMetadata class and it returns agenda value of String type

Prog_G
  • 1,539
  • 1
  • 8
  • 22
0

Turns out my issue was having to issue an explicit update to my fact once I updated the attributes during my pre-check rule. That solved the problem.

Mike
  • 269
  • 3
  • 8
  • 20