Search in sources :

Example 46 with KieBaseModel

use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.

the class KieSessionUtil method getKieSessionFromKieBaseModel.

public static Session getKieSessionFromKieBaseModel(final String moduleGroupId, final KieBaseTestConfiguration kieBaseTestConfiguration, final KieSessionTestConfiguration kieSessionTestConfiguration, final Resource... resources) {
    final KieModuleModel module = KieUtil.createKieModuleModel();
    final KieBaseModel kieBaseModel = kieBaseTestConfiguration.getKieBaseModel(module);
    kieSessionTestConfiguration.getKieSessionModel(kieBaseModel);
    final KieModule kieModule = KieUtil.buildAndInstallKieModuleIntoRepo(kieBaseTestConfiguration, moduleGroupId, module, resources);
    return getDefaultKieSessionFromReleaseId(kieModule.getReleaseId(), kieSessionTestConfiguration.isStateful(), false);
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieModule(org.kie.api.builder.KieModule)

Example 47 with KieBaseModel

use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.

the class BuildtimeUtil method getDefaultKieModuleModel.

public static KieModuleModel getDefaultKieModuleModel(final KieServices ks) {
    final KieModuleModel kproj = ks.newKieModuleModel();
    final KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("kbase").setDefault(true);
    kieBaseModel1.newKieSessionModel("ksession").setDefault(true);
    return kproj;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel)

Example 48 with KieBaseModel

use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.

the class DroolsGcCausesNPETest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    final KieModuleModel module = SERVICES.newKieModuleModel();
    final KieBaseModel base = module.newKieBaseModel(KIE_BASE_NAME);
    base.setEventProcessingMode(EventProcessingOption.STREAM);
    final KieFileSystem fs = SERVICES.newKieFileSystem();
    fs.generateAndWritePomXML(RELEASE_ID);
    fs.write(SERVICES.getResources().newClassPathResource(DRL_FILE_NAME, DroolsGcCausesNPETest.class));
    fs.writeKModuleXML(module.toXML());
    final KieBuilder builder = SERVICES.newKieBuilder(fs);
    final List<Message> errors = builder.buildAll().getResults().getMessages(Message.Level.ERROR);
    Assertions.assertThat(errors).as("Unexpected errors building drl: " + errors).isEmpty();
    SERVICES.getRepository().addKieModule(builder.getKieModule());
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBuilder(org.kie.api.builder.KieBuilder) BeforeClass(org.junit.BeforeClass)

Example 49 with KieBaseModel

use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.

the class IncrementalCompilationTest method createAndDeployJarInStreamMode.

public static KieModule createAndDeployJarInStreamMode(KieServices ks, ReleaseId releaseId, String... drls) {
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.generateAndWritePomXML(releaseId);
    KieModuleModel module = ks.newKieModuleModel();
    KieBaseModel defaultBase = module.newKieBaseModel("kBase1");
    defaultBase.setEventProcessingMode(EventProcessingOption.STREAM).setDefault(true);
    defaultBase.newKieSessionModel("defaultKSession").setDefault(true);
    kfs.writeKModuleXML(module.toXML());
    for (int i = 0; i < drls.length; i++) {
        kfs.write("src/main/resources/rules" + i + ".drl", drls[i]);
    }
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    if (kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
        System.out.println(kb.getResults().toString());
    }
    return kb.getKieModule();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder)

Example 50 with KieBaseModel

use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.

the class IncrementalCompilationTest method testChangeWindowTime.

@Test
public void testChangeWindowTime() {
    // DROOLS-853
    String drl1 = "import " + MyEvent.class.getCanonicalName() + "\n" + "global java.util.concurrent.atomic.AtomicInteger result\n" + "declare MyEvent @expires(5m) @role( event ) end\n" + "rule A when\n" + "    accumulate( $e : MyEvent() over window:time(10s), $result : count($e) )\n" + "then" + "    System.out.println(\"Result-1: \" + $result);\n" + "    result.set( $result.intValue() );\n" + "end";
    String drl2 = "import " + MyEvent.class.getCanonicalName() + "\n" + "global java.util.concurrent.atomic.AtomicInteger result\n" + "declare MyEvent @expires(5m) @role( event ) end\n" + "rule A when\n" + "    accumulate( $e : MyEvent() over window:time(5s), $result : count($e) )\n" + "then" + "    System.out.println(\"Result-2: \" + $result);\n" + "    result.set( $result.intValue() );\n" + "end";
    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()));
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    deployJar(ks, createKJar(ks, kproj, releaseId1, null, drl1));
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieSession ksession = kc.newKieSession();
    PseudoClockScheduler clock = ksession.getSessionClock();
    AtomicInteger result = new AtomicInteger(0);
    ksession.setGlobal("result", result);
    ksession.insert(new MyEvent(1));
    clock.advanceTime(4, TimeUnit.SECONDS);
    ksession.insert(new MyEvent(2));
    clock.advanceTime(4, TimeUnit.SECONDS);
    ksession.insert(new MyEvent(3));
    ksession.fireAllRules();
    assertEquals(3, result.get());
    // expires 1
    clock.advanceTime(3, TimeUnit.SECONDS);
    ksession.fireAllRules();
    assertEquals(2, result.get());
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    deployJar(ks, createKJar(ks, kproj, releaseId2, null, drl2));
    kc.updateToVersion(releaseId2);
    // shorter window: 2 is out
    ksession.fireAllRules();
    assertEquals(1, result.get());
    ksession.insert(new MyEvent(4));
    ksession.insert(new MyEvent(5));
    ksession.fireAllRules();
    assertEquals(3, result.get());
    // expires 3
    clock.advanceTime(3, TimeUnit.SECONDS);
    ksession.fireAllRules();
    assertEquals(2, result.get());
    // expires 4 & 5
    clock.advanceTime(3, TimeUnit.SECONDS);
    ksession.fireAllRules();
    assertEquals(0, result.get());
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler) KieSessionModel(org.kie.api.builder.model.KieSessionModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieBaseModel (org.kie.api.builder.model.KieBaseModel)74 KieModuleModel (org.kie.api.builder.model.KieModuleModel)55 KieServices (org.kie.api.KieServices)45 KieFileSystem (org.kie.api.builder.KieFileSystem)31 Test (org.junit.Test)26 KieSessionModel (org.kie.api.builder.model.KieSessionModel)24 KieBuilder (org.kie.api.builder.KieBuilder)22 KieContainer (org.kie.api.runtime.KieContainer)22 ReleaseId (org.kie.api.builder.ReleaseId)20 KieSession (org.kie.api.runtime.KieSession)13 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)10 ArrayList (java.util.ArrayList)7 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 KieBase (org.kie.api.KieBase)7 KieModule (org.kie.api.builder.KieModule)7 KieRepository (org.kie.api.builder.KieRepository)6 Before (org.junit.Before)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4