Updating rules in Business Central affects execution of those rules which are extended from one another

Solution Verified - Updated -

Issue

  • The following rules are defined in Business Central of BRMS 6 where they extend one another. e.g. Rule A extends Rule B and Rule B extends Rule C. Users build and deploy the rules to BRMS maven repository so that the resultant kjar can be used to execute it;s consituent rules from a client application. Now the application which is executing the rules from the kjar inside BRMS maven repository is also running KieScanner with some predefined interval for scanning the updated version of the kjar to ensure the latest version of the kjar is loaded by the application. This KieScanner now picks up the latest deployed rules kjar version which has Rule A , extending Rule B , Rule Bextending Rule C.
  • The rules are updated in the Business Central application and the kjar is also built as and when the latest rules are required to be run by the client application. For the first time when the application first executes the rules from kjar everything works fine and in order. Now when the application is executing the rules after the rules and the kjar is updated the execution results show some weird behavior.

    • Sometimes Rule B and Rule C fire but Rule A doesn't even though all conditions are met.
    • Sometimes Rule A and Rule C fire but Rule B doesn't.
      It is confirmed that the input facts inserted into ksession based on which the rules should fire are correct and it should ideally fire all three rules, because once the application and it's JVM is restarted it starts working fine again.
  • Some observations for the pattern of this issue are given below.

    • This happens only if the client application is running with the KieScanner API to pick up the latest deployed rules version. If user restarts JVM then all the rules fire fine.
    • Issue occurs only if the rules have more than one level of inheritance. If rules are modified so that they have only one level of inheritance like Rule A extends Rule B (i.e. Rule B won't extend Rule C further) then also rule execution is fine with KieScanner as well.
  • Suppose there are two rules where the second one extends the first one.

test rule 2

package org.drools.test;

import org.drools.Cheese;

rule "test rule 2" extends "test rule 1"
     when
         Cheese( price <= 6) from c
     then
         System.out.println(" ****** Printing from rule 'test rule 2' ****** ");
end

test rule 1

package org.drools.test;

import org.drools.Cheese;

rule "test rule 1"
     when
         c: Cheese( type == "hilton" )
     then
         System.out.println(" ****** Printing from rule 'test rule 1' ****** ");

end

These rules are drafted in Business Central and build&deploy the project there to create the kjars. Now an application code is used to test these rules using KieScanner API to look for changes made to the rules from time to time, and the application keeps on running the rules at a scheduled interval. If the application fires the rules for the first time with a fact which matches both the above rules, the results
are favorable.

****** Printing from rule 'test rule 2' ******
****** Printing from rule 'test rule 1' ******

Now if user makes a change to test rule 2 in such a way that it should not be executed. User saves the rules and build&deploy the project in Business Central. Now, KieScanner picks up the updated kjar containing the updated rule but it is observed that the application no longer longer runs the test rule 2 rule. But surprisingly the test rule 1 still gets executed.

****** Printing from rule 'test rule 1' ******

Now user updates the RHS of the test rule 1 rule in such a way that it does not put any effect on LHS.

test rule 1

package org.drools.test;

import org.drools.Cheese;

rule "test rule 1"
     when
         c: Cheese( type == "hilton" )
     then
         System.out.println(" &&&&&&& Printing from rule 'test rule 1' &&&&&&& ");

end

This time user no longer sees the test rule 1 even getting fired in the application code.

  • Are the rules' inheritance designed and authored in correct way, when Rule A extends Rule B and Rule Bextends Rule C?
  • Are there any specific guidelines around Rule Inheritance which users should take care of in such a case to avoid this kind of issue?
  • Are there any workarounds for this issue?
  • What could the root cause behind this issue?

Environment

  • Red Hat JBoss BRMS (BRMS)
    • 6.1

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.