Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-1021

Allow to retrieve the KieBase and KieSession models from the KieContainer

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Done
    • Major
    • 6.4.0.Beta1
    • 6.3.0.Final
    • core engine
    • None
    • NEW
    • NEW

    Description

      OptaPlanner is switching from using KieBase (with a drl classpath resource to retrieve the rules) to KContainer (with ksessionName to retrieve the rules), so it can function as part of a kjar.

      During bootstrap, it needs to check the rules if a specific Global is defined.
      Currently it needs to instantiate a throwaway KieSession to do that which is bad:

              KieSession kieSession = kieContainer.newKieSession(ksessionName); // BAD
              KieBase kieBase = kieSession.getKieBase();
              checkIfGlobalScoreHolderExists(kieBase);
      

      It would be much nicer if we could do this instead:

              KieBase kieBase = kieContainer.getKieBaseForKsessionName(ksessionName);
              checkIfGlobalScoreHolderExists(kieBase);
      

      So the proposal is to add that new method kieContainer.getKieBaseForKsessionName(String ksessionName)

      For the record, here's that check method that's being called at bootstrap:

          protected void checkIfGlobalScoreHolderExists(KieBase kieBase) {
              boolean hasGlobalScoreHolder = false;
              for (KiePackage kiePackage : kieBase.getKiePackages()) {
                  for (Global global : kiePackage.getGlobalVariables()) {
                      if (DroolsScoreDirector.GLOBAL_SCORE_HOLDER_KEY.equals(global.getName())) {
                          hasGlobalScoreHolder = true;
                          break;
                      }
                  }
              }
              if (!hasGlobalScoreHolder) {
                  throw new IllegalArgumentException("The kieBase with kiePackages (" + kieBase.getKiePackages()
                          + ") has no global field called " + DroolsScoreDirector.GLOBAL_SCORE_HOLDER_KEY + ".\n"
                          + "Check if the rule files are found and if the global field is spelled correctly.");
              }
          }
      

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            gdesmet@redhat.com Geoffrey De Smet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: