Java Code Examples for org.kie.api.runtime.KieContainer#getKieBase()
The following examples show how to use
org.kie.api.runtime.KieContainer#getKieBase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RulesConfiguration.java From cia with Apache License 2.0 | 6 votes |
/** * Kie container. * * @return the kie container */ @Bean public KieContainer kieContainer() { final KieServices kieServices = KieServices.Factory.get(); final KieContainer kContainer = kieServices.getKieClasspathContainer(); LOGGER.info("Using classloader {}, parent {}",kContainer.getClassLoader(),kContainer.getClassLoader().getParent()); final Results verifyResults = kContainer.verify(); for (final Message m : verifyResults.getMessages()) { LOGGER.warn("Kie container message: {}", m); } final KieBase kieBase = kContainer.getKieBase(); for (final KiePackage kp : kieBase.getKiePackages()) { for (final Rule rule : kp.getRules()) { LOGGER.info("Loadded Rule: {} {}", kp, rule.getName()); } } return kContainer; }
Example 2
Source File: BaseTest.java From iot-ocp with Apache License 2.0 | 6 votes |
@Before public void setup() { KieServices kieServices = KieServices.Factory.get(); KieContainer kContainer = kieServices.getKieClasspathContainer(); Results verifyResults = kContainer.verify(); for (Message m : verifyResults.getMessages()) { LOG.debug("Kie container message: {}", m); } KieBase kieBase = kContainer.getKieBase(); LOG.debug("Created kieBase"); for ( KiePackage kp : kieBase.getKiePackages() ) { for (Rule rule : kp.getRules()) { LOG.debug("kp " + kp + " rule " + rule.getName()); } } session = kieBase.newKieSession(); LOG.info(session.getGlobals().toString()); Logger kieLogger = LoggerFactory.getLogger(this.getClass()); // session.setGlobal("logger",kieLogger); }
Example 3
Source File: SecurityPolicyTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testSerializationUntrustedMvelConsequence() throws Exception { String drl = "package org.foo.bar\n" + "rule R1 dialect \"mvel\" when\n" + "then\n" + " System.exit(0);" + "end\n"; try { KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()) .setSourcePath("org/foo/bar/r1.drl")); ks.newKieBuilder(kfs).buildAll(); ReleaseId releaseId = ks.getRepository().getDefaultReleaseId(); KieContainer kc = ks.newKieContainer(releaseId); KieBase kbase = kc.getKieBase(); kbase = SerializationHelper.serializeObject( kbase ); } catch (Exception e) { e.printStackTrace(); fail(e.toString()); // test succeeded. the policy in place prevented the rule from executing the System.exit(). } }
Example 4
Source File: JbpmBpmn2TestCase.java From kogito-runtimes with Apache License 2.0 | 6 votes |
protected KieBase createKnowledgeBaseFromResources(Resource... process) throws Exception { KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); if (process.length > 0) { KieFileSystem kfs = ks.newKieFileSystem(); for (Resource p : process) { kfs.write(p); } KieBuilder kb = ks.newKieBuilder(kfs); kb.buildAll(); // kieModule is automatically deployed to KieRepository // if successfully built. if (kb.getResults().hasMessages(Level.ERROR)) { throw new RuntimeException("Build Errors:\n" + kb.getResults().toString()); } } KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId()); return kContainer.getKieBase(); }
Example 5
Source File: KieBuilderTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public void createAndTestKieContainer(ReleaseId releaseId, KieBuilder kb, String kBaseName) throws IOException, ClassNotFoundException, InterruptedException { KieServices ks = KieServices.Factory.get(); kb.buildAll(); if ( kb.getResults().hasMessages(Level.ERROR) ) { fail("Unable to build KieModule\n" + kb.getResults( ).toString() ); } KieRepository kr = ks.getRepository(); KieModule kJar = kr.getKieModule(releaseId); assertNotNull( kJar ); KieContainer kContainer = ks.newKieContainer(releaseId); KieBase kBase = kBaseName != null ? kContainer.getKieBase( kBaseName ) : kContainer.getKieBase(); KieSession kSession = kBase.newKieSession(); List list = new ArrayList(); kSession.setGlobal( "list", list ); kSession.fireAllRules(); assertEquals( 1, list.size() ); assertEquals( "org.kie.test.Message", list.get(0).getClass().getName() ); }
Example 6
Source File: KieCompilationCacheTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testCompilationCache() throws Exception { String drl = "package org.drools.compiler\n" + "declare type X\n" + " foo : String\n" + "end\n"+ "rule R1 when\n" + " $m : X( foo == \"Hello World\" )\n" + "then\n" + "end\n"; KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", drl ); ks.newKieBuilder( kfs ).buildAll(); ReleaseId releaseId = ks.getRepository().getDefaultReleaseId(); InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule( releaseId ); byte[] jar = kieModule.getBytes(); MemoryFileSystem mfs = MemoryFileSystem.readFromJar( jar ); File file = mfs.getFile( KieBuilderImpl.getCompilationCachePath( releaseId, "KBase1") ); assertNotNull( file ); Resource jarRes = ks.getResources().newByteArrayResource( jar ); KieModule km = ks.getRepository().addKieModule( jarRes ); KieContainer kc = ks.newKieContainer( km.getReleaseId() ); KieBase kbase = kc.getKieBase(); FactType type = kbase.getFactType( "org.drools.compiler", "X" ); FactField foo = type.getField( "foo" ); Object x = type.newInstance(); foo.set( x, "Hello World" ); KieSession ksession = kc.newKieSession(); ksession.insert(x); int count = ksession.fireAllRules(); assertEquals( 1, count ); }
Example 7
Source File: SimpleTest.java From servicemix with Apache License 2.0 | 5 votes |
/** * beforeClass. */ @BeforeClass public static void beforeClass() { KieServices ks = KieServices.Factory.get(); KieContainer kcont = ks.newKieClasspathContainer(); KieBase kbase = kcont.getKieBase("SimpleRuleKBase"); ksession = kbase.newKieSession(); ksession.addEventListener(new DebugAgendaEventListener()); ksession.addEventListener(new DebugRuleRuntimeEventListener()); }
Example 8
Source File: SimpleRuleActivator.java From servicemix with Apache License 2.0 | 5 votes |
@Override public void start(BundleContext context) throws Exception { KieServices ks = KieServices.Factory.get(); KieContainer kcont = ks.newKieClasspathContainer(getClass() .getClassLoader()); KieBase kbase = kcont.getKieBase("SimpleRuleKBase"); logger.info("KieSession newKieSession."); ksession = kbase.newKieSession(); ksession.addEventListener(new DebugAgendaEventListener()); ksession.addEventListener(new DebugRuleRuntimeEventListener()); Customer customer = customerPoor(); logger.info("KieSession fireAllRules. {}", customer); FactHandle fh = ksession.insert(customer); ksession.fireAllRules(); ksession.delete(fh); logger.info("After rule {}", customer); customer = customerNormal(); logger.info("KieSession fireAllRules. {}", customer); fh = ksession.insert(customer); ksession.fireAllRules(); ksession.delete(fh); logger.info("After rule {}", customer); customer = customerVip(); logger.info("KieSession fireAllRules. {}", customer); fh = ksession.insert(customer); ksession.fireAllRules(); ksession.delete(fh); logger.info("After rule {}", customer); }
Example 9
Source File: RulesManager.java From hacep with Apache License 2.0 | 5 votes |
public KieBase getKieBase(KieContainer kieContainer) { checkStatus(); if (!StringUtils.isEmpty(rulesConfiguration.getKieBaseName())) { return kieContainer.getKieBase(rulesConfiguration.getKieBaseName()); } return kieContainer.getKieBase(); }
Example 10
Source File: KieAPITestUtils.java From hacep with Apache License 2.0 | 5 votes |
public static KieBase setupKieBase(String... resources) throws Exception { ReleaseId releaseId = ks.newReleaseId("it.redhat.jdg", "rules", "1.0.0"); KieContainer kieContainer = setupKieContainerFromTemplates(releaseId, resources); KieBaseConfiguration config = KieServices.Factory.get().newKieBaseConfiguration(); config.setOption(EventProcessingOption.STREAM); return kieContainer.getKieBase(); }
Example 11
Source File: StartEventTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testSignalStartDynamic() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-SignalStart.bpmn2"); ksession = createKnowledgeSession(kbase); // create KieContainer after session was created to make sure no runtime data // will be used during serialization (deep clone) KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId()); kContainer.getKieBase(); final List<String> list = new ArrayList<>(); ksession.addEventListener(new DefaultProcessEventListener() { public void beforeProcessStarted(ProcessStartedEvent event) { logger.info("{}", event.getProcessInstance().getId()); list.add(event.getProcessInstance().getId()); } }); ksession.signalEvent("MySignal", "NewValue"); assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1); // now remove the process from kbase to make sure runtime based listeners are removed from signal manager kbase.removeProcess("Minimal"); assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { ksession.signalEvent("MySignal", "NewValue"); }) .withMessageContaining("Unknown process ID: Minimal"); // must be still one as the process was removed assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(1); }
Example 12
Source File: XSDResourceTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testXSDResourceNotBreakingCompilation() { final KieContainer kcontainer = KieServices.Factory.get().getKieClasspathContainer(); final KieBase kieBase = kcontainer.getKieBase("xsdKieBase"); assertThat(kieBase).as("Created KieBase with XSD should not be null").isNotNull(); }
Example 13
Source File: MBeansMonitoringTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Test public void testEventOffset() 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 ksession1 = 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 ); MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer(); ObjectName kbOn = DroolsManagementAgent.createObjectNameFor((InternalKnowledgeBase) kiebase); mbserver.invoke( kbOn, "startInternalMBeans", new Object[0], new String[0] ); Object expOffset = mbserver.getAttribute( new ObjectName( kbOn + ",group=EntryPoints,EntryPoint=DEFAULT,ObjectType=org.drools.compiler.StockTick" ), "ExpirationOffset" ); assertEquals( 10001, ((Number) expOffset).longValue() ); }
Example 14
Source File: KieHelper.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public KieBase build(KieBaseOption... options) { KieContainer kieContainer = getKieContainer(); if (options == null || options.length == 0) { return kieContainer.getKieBase(); } KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration(); for (KieBaseOption option : options) { kieBaseConf.setOption(option); } return kieContainer.newKieBase(kieBaseConf); }
Example 15
Source File: KieBuilderTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testKieModuleDependencies() throws ClassNotFoundException, InterruptedException, IOException { KieServices ks = KieServices.Factory.get(); String namespace1 = "org.kie.test1"; ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId(namespace1, "memory", "1.0"); KieModuleModel kProj1 = createKieProject(namespace1); KieFileSystem kfs1 = KieServices.Factory.get().newKieFileSystem(); generateAll(kfs1, namespace1, releaseId1, kProj1); KieBuilder kb1 = createKieBuilder(kfs1); kb1.buildAll(); if ( kb1.getResults().hasMessages(Level.ERROR) ) { fail("Unable to build KieJar\n" + kb1.getResults( ).toString() ); } KieRepository kr = ks.getRepository(); KieModule kModule1 = kr.getKieModule(releaseId1); assertNotNull( kModule1 ); String namespace2 = "org.kie.test2"; ReleaseId releaseId2 = KieServices.Factory.get().newReleaseId(namespace2, "memory", "1.0"); KieModuleModel kProj2 = createKieProject(namespace2); KieBaseModelImpl kieBase2 = ( KieBaseModelImpl ) kProj2.getKieBaseModels().get( namespace2 ); kieBase2.addInclude( namespace1 ); KieFileSystem kfs2 = KieServices.Factory.get().newKieFileSystem(); generateAll(kfs2, namespace2, releaseId2, kProj2); KieBuilder kb2 = createKieBuilder(kfs2); kb2.setDependencies( kModule1 ); kb2.buildAll(); if ( kb2.getResults().hasMessages(Level.ERROR) ) { fail("Unable to build KieJar\n" + kb2.getResults( ).toString() ); } KieModule kModule2= kr.getKieModule(releaseId2); assertNotNull( kModule2); KieContainer kContainer = ks.newKieContainer(releaseId2); KieBase kBase = kContainer.getKieBase( namespace2 ); KieSession kSession = kBase.newKieSession(); List list = new ArrayList(); kSession.setGlobal( "list", list ); kSession.fireAllRules(); assertEquals( 2, list.size() ); if ("org.kie.test1.Message".equals(list.get(0).getClass().getName())) { assertEquals( "org.kie.test2.Message", list.get(1).getClass().getName() ); } else { assertEquals( "org.kie.test2.Message", list.get(0).getClass().getName() ); assertEquals( "org.kie.test1.Message", list.get(1).getClass().getName() ); } }
Example 16
Source File: KieBaseIncludesTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
/** * Test the inclusion of a KieBase defined in one KJAR into the KieBase of another KJAR. * <p/> * The 2 KieBases use the same package names for the rules (i.e. "rules"). */ @Test public void testKieBaseIncludesCrossKJarSamePackageNames() { // @formatter:off String pomContent1 = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "<modelVersion>4.0.0</modelVersion>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-1</artifactId>\n" + "<version>1.0.0</version>\n" + "<packaging>jar</packaging>\n" + "<dependencies>\n" + "<dependency>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-2</artifactId>\n" + "<version>1.0.0</version>\n" + "</dependency>\n" + "</dependencies>\n" + "</project>\n"; String kmoduleContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + "<kbase name=\"kbase1\" equalsBehavior=\"equality\" default=\"true\" packages=\"rules\" includes=\"kbase2\">\n" + "<ksession name=\"ksession1\" default=\"true\" type=\"stateful\"/>\n" + "</kbase>\n"+ "</kmodule>"; String drl1 = "package rules\n" + "\n" + "rule \"Rule in KieBase 1\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase1\");\n" + "end"; String kmoduleContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + "<kbase name=\"kbase2\" equalsBehavior=\"equality\" default=\"false\" packages=\"rules\">\n" + "<ksession name=\"ksession2\" default=\"false\" type=\"stateful\"/>\n" + "</kbase>\n"+ "</kmodule>"; String drl2 = "package rules\n" + "\n" + "rule \"Rule in KieBase 2\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase2\");\n" + "end"; // @formatter:on KieServices ks = KieServices.Factory.get(); ReleaseId releaseId1 = ks.newReleaseId("org.kie", "rules-1", "1.0.0"); ReleaseId releaseId2 = ks.newReleaseId("org.kie", "rules-2", "1.0.0"); //First deploy the second KJAR on which the first one depends. KieFileSystem kfs2 = ks.newKieFileSystem() .generateAndWritePomXML(releaseId2) .write("src/main/resources/rules/rules.drl", drl2) .writeKModuleXML(kmoduleContent2); ks.newKieBuilder(kfs2).buildAll(); KieFileSystem kfs1 = ks.newKieFileSystem() //.generateAndWritePomXML(releaseId1) .writePomXML(pomContent1) .write("src/main/resources/rules/rules.drl", drl1) .writeKModuleXML(kmoduleContent1); ks.newKieBuilder(kfs1).buildAll(); KieContainer kc = ks.newKieContainer(releaseId1); KieBase kieBase = kc.getKieBase(); // Assert the number of rules in the KieBase. long nrOfRules = getNumberOfRules(kieBase); // We should have 2 rules in our KieBase. One from our own DRL and one from the DRL in the KieBase we've included. assertEquals(2, nrOfRules); }
Example 17
Source File: KieBaseIncludesTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
/** * Test the inclusion of a KieBase defined in one KJAR into the KieBase of another KJAR. * <p/> * The 2 KieBases use different package names for the rules (i.e. "rules" and "rules2"). */ @Test public void testKieBaseIncludesCrossKJarDifferentPackageNames() { // @formatter:off String pomContent1 = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "<modelVersion>4.0.0</modelVersion>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-1</artifactId>\n" + "<version>1.0.0</version>\n" + "<packaging>jar</packaging>\n" + "<dependencies>\n" + "<dependency>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-2</artifactId>\n" + "<version>1.0.0</version>\n" + "</dependency>\n" + "</dependencies>\n" + "</project>\n"; String kmoduleContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + "<kbase name=\"kbase1\" equalsBehavior=\"equality\" default=\"true\" packages=\"rules\" includes=\"kbase2\">\n" + "<ksession name=\"ksession1\" default=\"true\" type=\"stateful\"/>\n" + "</kbase>\n"+ "</kmodule>"; String drl1 = "package rules\n" + "\n" + "rule \"Rule in KieBase 1\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase1\");\n" + "end"; String kmoduleContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + "<kbase name=\"kbase2\" equalsBehavior=\"equality\" default=\"false\" packages=\"rules2\">\n" + "<ksession name=\"ksession2\" default=\"false\" type=\"stateful\"/>\n" + "</kbase>\n"+ "</kmodule>"; String drl2 = "package rules2\n" + "\n" + "rule \"Rule in KieBase 2\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase2\");\n" + "end"; // @formatter:on KieServices ks = KieServices.Factory.get(); ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "rules-1", "1.0.0" ); ReleaseId releaseId2 = ks.newReleaseId("org.kie", "rules-2", "1.0.0"); //First deploy the second KJAR on which the first one depends. KieFileSystem kfs2 = ks.newKieFileSystem() .generateAndWritePomXML(releaseId2) .write("src/main/resources/rules2/rules.drl", drl2) .writeKModuleXML(kmoduleContent2); ks.newKieBuilder(kfs2).buildAll(); KieFileSystem kfs1 = ks.newKieFileSystem() //.generateAndWritePomXML(releaseId1) .writePomXML(pomContent1) .write("src/main/resources/rules/rules.drl", drl1) .writeKModuleXML(kmoduleContent1); ks.newKieBuilder(kfs1).buildAll(); KieContainer kc = ks.newKieContainer( releaseId1 ); KieBase kieBase = kc.getKieBase(); // Assert the number of rules in the KieBase. long nrOfRules = getNumberOfRules(kieBase); // We should have 2 rules in our KieBase. One from our own DRL and one from the DRL in the KieBase we've included. assertEquals(2, nrOfRules); }
Example 18
Source File: MBeansMonitoringTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@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()); }
Example 19
Source File: MBeansMonitoringTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testKieClasspathMBeans() throws Exception { MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer(); KieServices ks = KieServices.Factory.get(); KieContainer kc = ks.getKieClasspathContainer("myID"); KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy("myID"), KieContainerMonitorMXBean.class); KieBase kb = kc.getKieBase("org.kie.monitoring.kbase1"); KieSession statefulKieSession = kc.newKieSession("org.kie.monitoring.kbase1.ksession1"); StatelessKieSession statelessKieSession = kc.newStatelessKieSession("org.kie.monitoring.kbase1.ksession2"); KieSessionMonitoringMXBean statefulKieSessionMonitor = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy("myID", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"), KieSessionMonitoringMXBean.class); StatelessKieSessionMonitoringMXBean statelessKieSessionMonitor = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy("myID", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"), StatelessKieSessionMonitoringMXBean.class); assertEquals("myID", c1Monitor.getContainerId() ); assertTrue(c1Monitor.getConfiguredReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID)); assertTrue(c1Monitor.getResolvedReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID)); assertEquals("org.kie.monitoring.kbase1.ksession1", statefulKieSessionMonitor.getKieSessionName()); assertEquals("org.kie.monitoring.kbase1", statefulKieSessionMonitor.getKieBaseId()); assertEquals("org.kie.monitoring.kbase1.ksession1", statelessKieSessionMonitor.getKieSessionName()); assertEquals("org.kie.monitoring.kbase1", statelessKieSessionMonitor.getKieBaseId()); KieContainer kc2 = ks.newKieClasspathContainer("myID2"); KieContainerMonitorMXBean c2Monitor = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy("myID2"), KieContainerMonitorMXBean.class); KieBase kb2 = kc2.getKieBase("org.kie.monitoring.kbase1"); KieSession statefulKieSession2 = kc2.newKieSession("org.kie.monitoring.kbase1.ksession1"); StatelessKieSession statelessKieSession2 = kc2.newStatelessKieSession("org.kie.monitoring.kbase1.ksession2"); KieSessionMonitoringMXBean statefulKieSessionMonitor2 = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy("myID2", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"), KieSessionMonitoringMXBean.class); StatelessKieSessionMonitoringMXBean statelessKieSessionMonitor2 = JMX.newMXBeanProxy( mbserver, DroolsManagementAgent.createObjectNameBy("myID2", "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "org.kie.monitoring.kbase1.ksession1"), StatelessKieSessionMonitoringMXBean.class); assertEquals("myID2", c2Monitor.getContainerId() ); assertTrue(c2Monitor.getConfiguredReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID)); assertTrue(c2Monitor.getResolvedReleaseId().sameGAVof(KieContainerMonitorMXBean.CLASSPATH_KIECONTAINER_RELEASEID)); assertEquals("org.kie.monitoring.kbase1.ksession1", statefulKieSessionMonitor2.getKieSessionName()); assertEquals("org.kie.monitoring.kbase1", statefulKieSessionMonitor2.getKieBaseId()); assertEquals("org.kie.monitoring.kbase1.ksession1", statelessKieSessionMonitor2.getKieSessionName()); assertEquals("org.kie.monitoring.kbase1", statelessKieSessionMonitor2.getKieBaseId()); kc.dispose(); kc2.dispose(); }
Example 20
Source File: WorkflowEngineImpl.java From tutorials with MIT License | 4 votes |
private KieBase getKieBase(String kbaseId) { KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.getKieClasspathContainer(); KieBase kbase = kContainer.getKieBase(kbaseId); return kbase; }