Search in sources :

Example 81 with KieModuleModel

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

the class KieRepositoryTest method createKieModule.

/**
 * Helper method creating simple KieModule with given ReleaseId.
 */
private void createKieModule(final ReleaseId releaseId) {
    final KieModuleModel kmodule = kieServices.newKieModuleModel();
    kmodule.newKieBaseModel("defaultKBase").setDefault(true);
    final KieFileSystem kfs = kieServices.newKieFileSystem();
    kfs.generateAndWritePomXML(releaseId);
    kfs.writeKModuleXML(kmodule.toXML());
    kfs.write("src/main/resources/defaultKBase/test.drl", kieServices.getResources().newByteArrayResource(DRL.getBytes()));
    final KieBuilder kbuilder = kieServices.newKieBuilder(kfs);
    kbuilder.buildAll();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBuilder(org.kie.api.builder.KieBuilder)

Example 82 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel 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 83 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel 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 84 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel 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 85 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel 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

KieModuleModel (org.kie.api.builder.model.KieModuleModel)126 KieFileSystem (org.kie.api.builder.KieFileSystem)78 KieServices (org.kie.api.KieServices)76 Test (org.junit.Test)67 KieBuilder (org.kie.api.builder.KieBuilder)56 KieBaseModel (org.kie.api.builder.model.KieBaseModel)55 KieContainer (org.kie.api.runtime.KieContainer)50 ReleaseId (org.kie.api.builder.ReleaseId)38 KieSession (org.kie.api.runtime.KieSession)27 KieSessionModel (org.kie.api.builder.model.KieSessionModel)25 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)18 InternalKieContainer (org.drools.core.impl.InternalKieContainer)14 KieModule (org.kie.api.builder.KieModule)14 KieBase (org.kie.api.KieBase)11 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)10 Results (org.kie.api.builder.Results)10 Resource (org.kie.api.io.Resource)9 ArrayList (java.util.ArrayList)8 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)8 Before (org.junit.Before)7