Search in sources :

Example 81 with TabularData

use of javax.management.openmbean.TabularData in project karaf by apache.

the class HttpMBeanImplTest method testRegisterMBean.

@Test
public void testRegisterMBean() throws Exception {
    HttpMBeanImpl httpMBean = new HttpMBeanImpl(new ServletServiceImpl(new ServletEventHandler()));
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    mbeanServer.registerMBean(httpMBean, new ObjectName("org.apache.karaf:type=http,name=root"));
    TabularData data = httpMBean.getServlets();
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 82 with TabularData

use of javax.management.openmbean.TabularData in project karaf by apache.

the class JMXSecurityTest method testOSGiConfigAdminMBean.

private void testOSGiConfigAdminMBean(MBeanServerConnection connection, ObjectName mbean, String pidPrefix, boolean shouldSucceed, boolean isAdmin) throws Exception {
    String infix = "." + System.currentTimeMillis();
    String suffix = infix + "_" + counter.incrementAndGet();
    String pid = pidPrefix + suffix;
    CompositeType ct = new CompositeType("PROPERTY", "X", new String[] { "Key", "Value", "Type" }, new String[] { "X", "X", "X" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
    TabularType tt = new TabularType("PROPERTIES", "X", ct, new String[] { "Key" });
    TabularDataSupport tds = new TabularDataSupport(tt);
    Map<String, Object> data = new HashMap<>();
    data.put("Key", "foo");
    data.put("Value", "bar");
    data.put("Type", "String");
    CompositeDataSupport cds = new CompositeDataSupport(ct, data);
    tds.put(cds);
    assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid, tds }, new String[] { String.class.getName(), TabularData.class.getName() });
    TabularData td = (TabularData) connection.invoke(mbean, "getProperties", new Object[] { pid }, new String[] { String.class.getName() });
    if (shouldSucceed) {
        assertEquals("bar", td.get(new Object[] { "foo" }).get("Value"));
    }
    String[][] configs = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pid + ")" }, new String[] { String.class.getName() });
    if (shouldSucceed) {
        assertEquals(1, configs.length);
        assertEquals(pid, configs[0][0]);
    }
    assertJmxInvoke(shouldSucceed, connection, mbean, "delete", new Object[] { pid }, new String[] { String.class.getName() });
    TabularDataSupport tds2 = new TabularDataSupport(tt);
    Map<String, Object> data2 = new HashMap<>();
    data2.put("Key", "a.b.c");
    data2.put("Value", "d.e.f");
    data2.put("Type", "String");
    CompositeDataSupport cds2 = new CompositeDataSupport(ct, data2);
    tds2.put(cds2);
    String suffix2 = infix + "_" + counter.incrementAndGet();
    String pid2 = pidPrefix + suffix2;
    String location2 = "mylocation" + System.currentTimeMillis();
    assertJmxInvoke(shouldSucceed, connection, mbean, "updateForLocation", new Object[] { pid2, location2, tds2 }, new String[] { String.class.getName(), String.class.getName(), TabularData.class.getName() });
    TabularData td2 = (TabularData) connection.invoke(mbean, "getPropertiesForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
    if (shouldSucceed) {
        assertEquals("d.e.f", td2.get(new Object[] { "a.b.c" }).get("Value"));
    }
    assertJmxInvoke(shouldSucceed, connection, mbean, "deleteForLocation", new Object[] { pid2, location2 }, new String[] { String.class.getName(), String.class.getName() });
    if (isAdmin) {
        String suffix3 = infix + "_" + counter.incrementAndGet();
        String pid3 = pidPrefix + suffix3;
        TabularDataSupport tds3 = new TabularDataSupport(tt);
        assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object[] { pid3, tds3 }, new String[] { String.class.getName(), TabularData.class.getName() });
        String[][] configs2 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
        assertEquals(1, configs2.length);
        assertEquals(pid3, configs2[0][0]);
        String location3 = "my.other.location." + System.currentTimeMillis();
        assertJmxInvoke(shouldSucceed, connection, mbean, "setBundleLocation", new Object[] { pid3, location3 }, new String[] { String.class.getName(), String.class.getName() });
        String[][] configs3 = (String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() });
        assertEquals(1, configs3.length);
        assertEquals(pid3, configs3[0][0]);
        connection.invoke(mbean, "deleteConfigurations", new Object[] { "(service.pid=" + pid3 + ")" }, new String[] { String.class.getName() });
        assertEquals(0, ((String[][]) connection.invoke(mbean, "getConfigurations", new Object[] { "(service.pid=" + pidPrefix + infix + "*)" }, new String[] { String.class.getName() })).length);
    }
}
Also used : HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType) TabularData(javax.management.openmbean.TabularData)

Example 83 with TabularData

use of javax.management.openmbean.TabularData in project karaf by apache.

the class ServiceTest method listViaMBean.

@Test
public void listViaMBean() throws Exception {
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("org.apache.karaf:type=service,name=root");
    TabularData services = (TabularData) mbeanServer.getAttribute(name, "Services");
    assertTrue(services.size() > 0);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 84 with TabularData

use of javax.management.openmbean.TabularData in project karaf by apache.

the class InstanceToTableMapperTest method testJMXInstance2.

public void testJMXInstance2() throws Exception {
    Instance instance = EasyMock.createMock(Instance.class);
    EasyMock.expect(instance.getPid()).andReturn(1712);
    EasyMock.expect(instance.getName()).andReturn("MyInstance");
    EasyMock.expect(instance.isRoot()).andReturn(true);
    EasyMock.expect(instance.getSshPort()).andReturn(0);
    EasyMock.expect(instance.getSshHost()).andReturn("0.0.0.0");
    EasyMock.expect(instance.getRmiRegistryPort()).andReturn(0);
    EasyMock.expect(instance.getRmiRegistryHost()).andReturn("0.0.0.0");
    EasyMock.expect(instance.getRmiServerPort()).andReturn(0);
    EasyMock.expect(instance.getRmiServerHost()).andReturn("0.0.0.0");
    EasyMock.expect(instance.getState()).andReturn("Started");
    EasyMock.expect(instance.getLocation()).andReturn(null);
    EasyMock.expect(instance.getJavaOpts()).andReturn(null);
    EasyMock.replay(instance);
    TabularData td = InstanceToTableMapper.tableFrom(Collections.singletonList(instance));
    Collection<?> keys = (Collection<?>) td.keySet().iterator().next();
    Assert.assertEquals("MyInstance", keys.iterator().next());
    CompositeData cd = td.get(keys.toArray());
    Assert.assertEquals(1712, cd.get("Pid"));
    Assert.assertEquals("MyInstance", cd.get("Name"));
    Assert.assertEquals(true, cd.get("Is Root"));
    Assert.assertEquals(0, cd.get("SSH Port"));
    Assert.assertEquals("0.0.0.0", cd.get("SSH Host"));
    Assert.assertEquals(0, cd.get("RMI Registry Port"));
    Assert.assertEquals("0.0.0.0", cd.get("RMI Registry Host"));
    Assert.assertEquals(0, cd.get("RMI Server Port"));
    Assert.assertEquals("0.0.0.0", cd.get("RMI Server Host"));
    Assert.assertEquals("Started", cd.get("State"));
    Assert.assertNull(cd.get("Location"));
    Assert.assertNull(cd.get("JavaOpts"));
}
Also used : Instance(org.apache.karaf.instance.core.Instance) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 85 with TabularData

use of javax.management.openmbean.TabularData in project karaf by apache.

the class FeatureTest method listViaMBean.

@Test
public void listViaMBean() throws Exception {
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
    TabularData features = (TabularData) mbeanServer.getAttribute(name, "Features");
    assertTrue(features.size() > 0);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8