[jboss-jira] [JBoss JIRA] (DROOLS-1729) Unable to load rule with global variables via kiescanner.

Mario Fusco (JIRA) issues at jboss.org
Wed Sep 20 06:33:00 EDT 2017


    [ https://issues.jboss.org/browse/DROOLS-1729?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13466145#comment-13466145 ] 

Mario Fusco commented on DROOLS-1729:
-------------------------------------

I tried what you described with the test case that I'm pasting below, but everything works for me. Possibly try with a newer version of drools and if you can reproduce the problem also there, please provide a complete reproducer of your issue (possibly similar to my test case). I'll close this issue as "cannot reproduce" for now, but in case you'll be able to provide a reproducer feel free to reopen it.

{code}
    @Test
    public void testUpdateWithGlobalAndEventInSeparatedDRL() throws Exception {
        String drl1 = "import " + FooEvent.class.getCanonicalName() + ";\n" +
                      "global Boolean isTest;\n" +
                      "declare FooEvent\n" +
                      " @timestamp( mytime )\n" +
                      " @role( event )\n" +
                      "end\n";

        String drl2 = "global Boolean isTest;\n" +
                      "\n" +
                      "rule \"Red Car\"\n" +
                      "when\n" +
                      "  FooEvent () over window:time(2h);\n" +
                      "then\n" +
                      "  System.out.println(\"*** FooEvent\");\n" +
                      "  System.out.println(\"*** \" + isTest);\n" +
                      "end\n";

        String drl3 = "global Boolean isTest;\n" +
                      "\n" +
                      "rule \"Red Car\"\n" +
                      "when\n" +
                      "  FooEvent () over window:time(3h);\n" +
                      "then\n" +
                      "  System.out.println(\"$$$ FooEvent\");\n" +
                      "  System.out.println(\"$$$ \" + isTest);\n" +
                      "end\n";

        KieServices ks = KieServices.Factory.get();

        KieModuleModel kproj = ks.newKieModuleModel();
        KieBaseModel kieBaseModel1 = kproj.newKieBaseModel( "KBase1" ).setDefault( true )
                                          .setEventProcessingMode( EventProcessingOption.STREAM );
        KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel( "KSession1" ).setDefault( true )
                                                 .setType( KieSessionModel.KieSessionType.STATEFUL )
                                                 .setClockType( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) );

        // Create an in-memory jar for version 1.0.0
        ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.0.0" );
        KieModule km = deployJar( ks, createKJar( ks, kproj, releaseId1, null, drl1, drl2 ) );

        // Create a session and fire rules
        KieContainer kc = ks.newKieContainer( km.getReleaseId() );
        KieSession ksession = kc.newKieSession();
        ksession.setGlobal( "isTest", true );
        ksession.insert( new FooEvent( 0 ) );
        assertEquals( 1, ksession.fireAllRules() );

        // Create a new jar for version 1.1.0
        ReleaseId releaseId2 = ks.newReleaseId( "org.kie", "test-upgrade", "1.1.0" );
        km = deployJar( ks, createKJar( ks, kproj, releaseId2, null, drl1, drl3 ) );

        // try to update the container to version 1.1.0
        Results results = kc.updateToVersion( releaseId2 );

        assertFalse("Errors detected on updateToVersion: " + results.getMessages(org.kie.api.builder.Message.Level.ERROR), results.hasMessages(org.kie.api.builder.Message.Level.ERROR));

        // continue working with the session
        ksession.insert( new FooEvent( 1 ) );
        assertEquals( 2, ksession.fireAllRules() );
    }
{code}

> Unable to load rule with global variables via kiescanner.
> ---------------------------------------------------------
>
>                 Key: DROOLS-1729
>                 URL: https://issues.jboss.org/browse/DROOLS-1729
>             Project: Drools
>          Issue Type: Bug
>    Affects Versions: 6.5.0.Final
>            Reporter: Pedro Almeida
>            Assignee: Mario Fusco
>            Priority: Blocker
>
> I have a master drl that has global *variables declaration* as well as *class role declarations*. Other drl files depend on those declarations. 
> Build is successful and I'm able to use the engine as intended. The thing is when I use kiescanner to unload a rule and load it back, I get compilation errors that make it look like the master drl is not being accounted for.
> *Errors:*
> 1) "A Sliding Window can only be assigned to types declared with @role( event )
> [Actually my object type is declared with role event on the master drl]
> 2) "isTest cannot be resolved"
> [isTest being my global variable]
> *Rule:*
> package rules;
> import model.Car;
> global Boolean isTest;
> rule "Red Car"
>     when
>         Car (color=="Red") over window:time(2h);
>     then
>         System.out.println("*** Red car");
>         System.out.println("*** " + isTest);
> end
> *Master Drl*
> package rules;
> import model.Car;
> global Boolean isTest;
> declare Car
>     @role( event )
> end



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the jboss-jira mailing list