use of org.kie.api.management.KieContainerMonitorMXBean in project drools by kiegroup.
the class MonitoringWithJPAKnowledgeServiceTest method testBasic.
@Test
public void testBasic() throws MalformedObjectNameException {
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
KieServices ks = KieServices.Factory.get();
String containerId = "testcontainer-" + System.currentTimeMillis();
KieContainer kc = ks.newKieClasspathContainer(containerId);
KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(containerId), KieContainerMonitorMXBean.class);
KieBase kb = kc.getKieBase("org.kie.monitoring.kbase1");
// Use JPAKnowledgeService to create the KieSession
StatefulKnowledgeSession statefulKieSession = JPAKnowledgeService.newStatefulKnowledgeSession(kb, null, env);
long sessionIdentifier = statefulKieSession.getIdentifier();
statefulKieSession.insert("String1");
statefulKieSession.fireAllRules();
KieSessionMonitoringMXBean statefulKieSessionMonitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(containerId, "org.kie.monitoring.kbase1", KieSessionType.STATEFUL, "persistent"), KieSessionMonitoringMXBean.class);
assertEquals(1, statefulKieSessionMonitor.getTotalMatchesFired());
// There should be 3 mbeans for KieContainer, KieBase and KieSession.
assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote(containerId) + ",*"), null).size());
// needs to be done separately:
statefulKieSession.dispose();
StatefulKnowledgeSession deserialized = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionIdentifier, kb, null, createEnvironment(context));
deserialized.insert("String2");
deserialized.fireAllRules();
// the mbean does not persist state, but in this case consolidate by grouping the fire of the former session and the deserialized one
assertEquals(2, statefulKieSessionMonitor.getTotalMatchesFired());
kc.dispose();
}
use of org.kie.api.management.KieContainerMonitorMXBean in project drools by kiegroup.
the class MBeansMonitoringTest method testLoadKjarFromClasspath.
/**
* Copied from KieRepositoryTest to test JMX monitoring
*/
@Test
public void testLoadKjarFromClasspath() {
// DROOLS-1335
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/kie-project-simple-1.0.0.jar") });
Thread.currentThread().setContextClassLoader(urlClassLoader);
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
try {
KieServices ks = KieServices.Factory.get();
KieRepository kieRepository = ks.getRepository();
ReleaseId releaseId = ks.newReleaseId("org.test", "kie-project-simple", "1.0.0");
KieModule kieModule = kieRepository.getKieModule(releaseId);
assertNotNull(kieModule);
assertEquals(releaseId, kieModule.getReleaseId());
ks.newKieContainer("myID", releaseId);
KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy("myID"), KieContainerMonitorMXBean.class);
assertTrue(c1Monitor.getConfiguredReleaseId().sameGAVof(releaseId));
assertTrue(c1Monitor.getResolvedReleaseId().sameGAVof(releaseId));
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of org.kie.api.management.KieContainerMonitorMXBean in project drools by kiegroup.
the class MBeansMonitoringTest method testKieClasspathMBeans.
@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();
}
use of org.kie.api.management.KieContainerMonitorMXBean 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());
}
Aggregations