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

Allow to retrieve the KieBase and KieSession models from the KieContainer

    Details

    • Type: Enhancement
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 6.3.0.Final
    • Fix Version/s: 6.4.0.Beta1
    • Component/s: core engine
    • Labels:
      None
    • Docs QE Status:
      NEW
    • QE Status:
      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.");
              }
          }
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mfusco Mario Fusco
                Reporter:
                ge0ffrey Geoffrey De Smet
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: