Search in sources :

Example 61 with KieModuleModel

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

the class KieHelloWorldTest method createKieProjectWithPackagesAnd2KieBases.

private KieModuleModel createKieProjectWithPackagesAnd2KieBases(KieServices ks) {
    KieModuleModel kproj = ks.newKieModuleModel();
    kproj.newKieBaseModel().setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage("org.pkg1").newKieSessionModel("KSession1");
    kproj.newKieBaseModel().setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage("org.pkg2").newKieSessionModel("KSession2");
    return kproj;
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel)

Example 62 with KieModuleModel

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

the class KieLoggersTest method testDeclarativeKieFileLogger.

@Test
public void testDeclarativeKieFileLogger() throws Exception {
    String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + "    when\n" + "        m : Message( myMessage : message )\n" + "    then\n" + "end";
    String fileName = "target/testKieFileLogger";
    File file = new File(fileName + ".log");
    if (file.exists()) {
        file.delete();
    }
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kproj = ks.newKieModuleModel();
    kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setFileLogger(fileName);
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML());
    kfs.write("src/main/resources/KBase1/rule.drl", drl);
    KieModule kieModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
    KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
    KieSession ksession = kieContainer.newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    int fired = ksession.fireAllRules();
    assertEquals(1, fired);
    // disposing the ksession also flushes and closes the logger
    ksession.dispose();
    file = new File(fileName + ".log");
    assertTrue(file.exists());
    file.delete();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) File(java.io.File) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 63 with KieModuleModel

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

the class KieLoggersTest method testDeclarativeKieConsoleLogger.

@Test
public void testDeclarativeKieConsoleLogger() throws Exception {
    String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + "    when\n" + "        m : Message( myMessage : message )\n" + "    then\n" + "end";
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kproj = ks.newKieModuleModel();
    kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setConsoleLogger("logger");
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML());
    kfs.write("src/main/resources/KBase1/rule.drl", drl);
    KieModule kieModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
    KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
    KieSession ksession = kieContainer.newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    int fired = ksession.fireAllRules();
    assertEquals(1, fired);
    KieRuntimeLogger logger = ksession.getLogger();
    assertNotNull(logger);
    logger.close();
}
Also used : KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 64 with KieModuleModel

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

the class KieLoggersTest method testDeclarativeKieConsoleLoggerStateless.

@Test
public void testDeclarativeKieConsoleLoggerStateless() throws Exception {
    String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + "    when\n" + "        m : Message( myMessage : message )\n" + "    then\n" + "end";
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kproj = ks.newKieModuleModel();
    kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setType(KieSessionModel.KieSessionType.STATELESS).setConsoleLogger("logger");
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML());
    kfs.write("src/main/resources/KBase1/rule.drl", drl);
    KieModule kieModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
    KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
    StatelessKieSession ksession = kieContainer.newStatelessKieSession("KSession1");
    ksession.execute(new Message("Hello World"));
    KieRuntimeLogger logger = ksession.getLogger();
    assertNotNull(logger);
    logger.close();
}
Also used : KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) KieModuleModel(org.kie.api.builder.model.KieModuleModel) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieServices(org.kie.api.KieServices) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 65 with KieModuleModel

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

the class MBeansMonitoringTest method testContainerMBeans.

@Test
public void testContainerMBeans() throws Exception {
    String drl = "package org.drools.compiler.test\n" + "import org.drools.compiler.StockTick\n" + "declare StockTick\n" + "    @role(event)\n" + "    @expires(10s)\n" + "end\n" + "rule X\n" + "when\n" + "    StockTick()\n" + "then\n" + "end";
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kproj = ks.newKieModuleModel();
    KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(KBASE1).setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
    KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel(KSESSION1).setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
    ReleaseId releaseId1 = ks.newReleaseId("org.kie.test", "mbeans", "1.0.0");
    createKJar(ks, kproj, releaseId1, null, drl);
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieBase kiebase = kc.getKieBase(KBASE1);
    kc.newKieSession(KSESSION1);
    kiebase.newKieSession();
    String kc1ID = ((InternalKieContainer) kc).getContainerId();
    MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
    LOG.debug("{}", mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote(kc1ID) + ",*"), null));
    ReleaseId verRelease = ks.newReleaseId("org.kie.test", "mbeans", "RELEASE");
    KieContainer kc2 = ks.newKieContainer("Matteo", verRelease);
    kc2.newKieSession(KSESSION1);
    KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(kc1ID), KieContainerMonitorMXBean.class);
    assertEquals(releaseId1.toExternalForm(), c1Monitor.getConfiguredReleaseIdStr());
    assertEquals(releaseId1.toExternalForm(), c1Monitor.getResolvedReleaseIdStr());
    assertTrue(c1Monitor.getConfiguredReleaseId().sameGAVof(releaseId1));
    assertTrue(c1Monitor.getResolvedReleaseId().sameGAVof(releaseId1));
    assertEquals(releaseId1.getVersion(), c1Monitor.getConfiguredReleaseId().getVersion());
    assertEquals(releaseId1.getVersion(), c1Monitor.getResolvedReleaseId().getVersion());
    KieContainerMonitorMXBean c2Monitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy("Matteo"), KieContainerMonitorMXBean.class);
    assertEquals(verRelease.toExternalForm(), c2Monitor.getConfiguredReleaseIdStr());
    assertEquals(releaseId1.toExternalForm(), c2Monitor.getResolvedReleaseIdStr());
    assertTrue(c2Monitor.getConfiguredReleaseId().sameGAVof(verRelease));
    assertTrue(c2Monitor.getResolvedReleaseId().sameGAVof(releaseId1));
    assertEquals(verRelease.getVersion(), c2Monitor.getConfiguredReleaseId().getVersion());
    assertEquals(releaseId1.getVersion(), c2Monitor.getResolvedReleaseId().getVersion());
    // MBean are supported only via KieContainer public API.
    assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote(kc1ID) + ",*"), null).size());
    kc.dispose();
    assertEquals(0, mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote(kc1ID) + ",*"), null).size());
    assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote("Matteo") + ",*"), null).size());
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) KieContainerMonitorMXBean(org.kie.api.management.KieContainerMonitorMXBean) KieServices(org.kie.api.KieServices) InternalKieContainer(org.drools.core.impl.InternalKieContainer) ReleaseId(org.kie.api.builder.ReleaseId) KieSessionModel(org.kie.api.builder.model.KieSessionModel) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) 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