[jboss-jira] [JBoss JIRA] (DROOLS-782) NullPointerException Updating KieContainer KieModule Version

Mark Kretschmann (JIRA) issues at jboss.org
Mon May 11 15:38:19 EDT 2015


Mark Kretschmann created DROOLS-782:
---------------------------------------

             Summary: NullPointerException Updating KieContainer KieModule Version
                 Key: DROOLS-782
                 URL: https://issues.jboss.org/browse/DROOLS-782
             Project: Drools
          Issue Type: Bug
            Reporter: Mark Kretschmann
            Assignee: Mark Proctor


I'm trying to dynamically update the rule definitions inside a KieContainer while a KieSession is running, invoked with KieSession.fireUntilHalt().  We need to leverage KieSession.fireUntilHalt() as all of our rules in this service are timer rules, as we're leveraging drools as a scheduling service here.

The code below shows how I'm testing this.  First I setup two rules to print every 3 and 6 seconds, then execute KieSession.fireUntilHalt().

Then later on I update the KieContainer version with three rules which print out @ 5, 8 and 10 seconds.  I immediately receive a NullPointerException after calling the KieContainer.updateToVersion.

   public void run()
    {

        String testRuleAdd = "rule \"test-rule-add\" timer (cron: */3 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every three seconds'); end ";
        String testRuleAdd2 = "rule \"test-rule-add-two\" timer (cron: */6 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every six seconds'); end ";
        String testRuleAdd3 = "rule \"test-rule-add-three\" timer (cron: */10 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every ten seconds'); end ";
        String testRuleAdd4 = "rule \"test-rule-add-four\" timer (cron: */5 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every five seconds'); end ";
        String testRuleAdd5= "rule \"test-rule-add-five\" timer (cron: */8 * * * * ?; start=\"4-MAY-2015\", end=\"30-JUN-2015\") when eval(true) then System.out.println('Hey there, I print every eight seconds'); end ";

        try {

            KieServices ks = KieServices.Factory.get();
            KieFileSystem kfs = ks.newKieFileSystem();

            EntityManager em = modelService.createEntityManager();
            List<Schedule> schedules = em
                    .createQuery("select s from Schedule s where s.enabled = true", Schedule.class)
                    .getResultList();
            schedules.forEach(s -> System.out.println(s.getPath() + " : " + s.getDefinition()));
            schedules.forEach(s -> kfs.write(s.getPath(), s.getDefinition()));

            ArrayList<String> testRules = new ArrayList<String>();
            testRules.add(testRuleAdd);

            kfs.write("src/main/resources/r1.drl", testRuleAdd);
            kfs.write("src/main/resources/r2.drl", testRuleAdd2);

            KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
            if (kb.getResults().hasMessages(Message.Level.ERROR)) {
                throw new RuntimeException(kb.getResults().toString());
            }

            logger.trace("repository version: " + ks.getRepository().getDefaultReleaseId());

            ReleaseId initialReleaseId = ks.getRepository().getDefaultReleaseId();
            KieContainer kc = ks.newKieContainer(initialReleaseId);
            KieSession ksession = kc.newKieSession();
            ksession.setGlobal("queueService", queueService);

            new Thread(new Runnable() {
                public void run() {
                    ksession.fireUntilHalt();
                }
            }).start();

            Thread.sleep((10000));

            // Update release version with same KieSession

            ReleaseId relId2 = ks.newReleaseId("os-rules", "test-release-upgrade", "1.0.1");

            KieFileSystem kfs_2 = ks.newKieFileSystem();
            kfs_2.generateAndWritePomXML(relId2);

            // kfs_2.write("src/main/resources/r1.drl", testRuleAdd);
            // kfs_2.write("src/main/resources/r2.drl", testRuleAdd2);
            kfs_2.write("src/main/resources/r3.drl", testRuleAdd3);
            kfs_2.write("src/main/resources/r4.drl", testRuleAdd4);
            kfs_2.write("src/main/resources/r5.drl", testRuleAdd5);

            KieBuilder kb2 = ks.newKieBuilder(kfs_2).buildAll();
            if (kb2.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
                for (org.kie.api.builder.Message result : kb2.getResults().getMessages() ) {
                    System.out.println(result.getText());
                }
                throw new RuntimeException((kb2.getResults().toString()));
            }

            KieModule km = ks.getRepository().getKieModule((relId2));
            kc.updateToVersion(relId2);
            
        } catch (Exception ex) {
            logger.error("Failed to start the schedule runner: " + ex.getMessage());
        }
    }



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the jboss-jira mailing list