Search in sources :

Example 46 with JMXConnector

use of javax.management.remote.JMXConnector in project karaf by apache.

the class DeployMojo method deployWithJmx.

protected void deployWithJmx(List<String> locations) throws MojoExecutionException {
    try {
        JMXServiceURL jmxServiceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/" + instance);
        ArrayList<String> list = new ArrayList<>();
        if (user != null)
            list.add(user);
        if (password != null)
            list.add(password);
        HashMap env = new HashMap();
        String[] credentials = list.toArray(new String[list.size()]);
        env.put(JMXConnector.CREDENTIALS, credentials);
        JMXConnector jmxConnector = null;
        if (credentials.length > 0)
            jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, env);
        else
            jmxConnector = JMXConnectorFactory.connect(jmxServiceURL);
        MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
        for (String location : locations) {
            mBeanServerConnection.invoke(new ObjectName("org.apache.karaf:type=bundle,name=*"), "install", new Object[] { location, true }, new String[] { "java.lang.String", "boolean" });
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Can't deploy using JMX", e);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) JMXConnector(javax.management.remote.JMXConnector) ArrayList(java.util.ArrayList) MBeanServerConnection(javax.management.MBeanServerConnection) RuntimeSshException(org.apache.sshd.common.RuntimeSshException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ObjectName(javax.management.ObjectName)

Example 47 with JMXConnector

use of javax.management.remote.JMXConnector in project wildfly by wildfly.

the class ServiceMBeanSupportTestCase method testSarWithServiceMBeanSupport.

/**
     * Tests that invocation on a service deployed within a .sar, inside a .ear without an application.xml, is successful.
     *
     * @throws Exception
     */
@Test
public void testSarWithServiceMBeanSupport() throws Exception {
    // get mbean server
    final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
    final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
    try {
        // deploy the unmanaged sar
        deployer.deploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME);
        // check the unmanaged mbean state
        int state = (Integer) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test"), "State");
        Assert.assertEquals("Unexpected return state from Test MBean: " + state, ServiceMBean.STARTED, state);
    } finally {
        // undeploy it
        deployer.undeploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME);
    }
    // check the result of life-cycle methods invocation, using result mbean
    // also check that the result mbean received lifecycle notifications
    String[] expectedAttributes = new String[] { "CreateServiceInvoked", "StartServiceInvoked", "StopServiceInvoked", "DestroyServiceInvoked", "StartingNotificationReceived", "StartedNotificationReceived", "StoppingNotificationReceived", "StoppedNotificationReceived" };
    // each of these attributes should be 'true'
    for (String attribute : expectedAttributes) {
        Boolean result = (Boolean) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), attribute);
        Assert.assertTrue("Unexpected result for " + attribute + ": " + result, result);
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 48 with JMXConnector

use of javax.management.remote.JMXConnector in project wildfly by wildfly.

the class JNDIBindingMBeanTestCase method testMBeanStartup.

/**
     * Makes sure that the MBeans that are expected to be up and running are accessible.
     *
     * @throws Exception
     * @see https://developer.jboss.org/thread/251092
     */
@Test
public void testMBeanStartup() throws Exception {
    // get mbean server
    final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
    try {
        final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
        // check the deployed MBeans
        for (int i = 1; i <= 9; i++) {
            final String mbeanName = "jboss:name=mbean-startup-jndi-bind-" + i;
            final Object instance = mBeanServerConnection.getObjectInstance(new ObjectName(mbeanName));
            Assert.assertNotNull("No instance returned for MBean: " + mbeanName, instance);
        }
    } finally {
        connector.close();
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 49 with JMXConnector

use of javax.management.remote.JMXConnector in project wildfly by wildfly.

the class SarInjectionTestCase method testMBean.

@Test
public void testMBean() throws Exception {
    final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL());
    try {
        final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
        final ObjectName objectName = new ObjectName("jboss:name=POJOService");
        Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "Count"));
        Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "InjectedCount"));
        Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "CreateCalled"));
        Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "StartCalled"));
        Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "StopCalled"));
        Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "DestroyCalled"));
    } finally {
        IoUtils.safeClose(connector);
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 50 with JMXConnector

use of javax.management.remote.JMXConnector in project voldemort by voldemort.

the class AbstractFailureDetectorTest method assertJmxEquals.

protected void assertJmxEquals(String attributeName, Object attributeValue) throws Exception {
    JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("service:jmx:rmi://"), null, ManagementFactory.getPlatformMBeanServer());
    cs.start();
    JMXConnector cc = null;
    try {
        cc = JMXConnectorFactory.connect(cs.getAddress());
        MBeanServerConnection mbsc = cc.getMBeanServerConnection();
        ObjectName objectName = JmxUtils.createObjectName(JmxUtils.getPackageName(failureDetector.getClass()), failureDetector.getClass().getSimpleName());
        Object availableNodes = mbsc.getAttribute(objectName, attributeName);
        assertEquals(attributeValue, availableNodes);
    } finally {
        if (cc != null)
            cc.close();
        cs.stop();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) JMXConnectorServer(javax.management.remote.JMXConnectorServer) ObjectName(javax.management.ObjectName)

Aggregations

JMXConnector (javax.management.remote.JMXConnector)118 MBeanServerConnection (javax.management.MBeanServerConnection)85 JMXServiceURL (javax.management.remote.JMXServiceURL)78 ObjectName (javax.management.ObjectName)54 JMXConnectorServer (javax.management.remote.JMXConnectorServer)47 MBeanServer (javax.management.MBeanServer)37 IOException (java.io.IOException)35 HashMap (java.util.HashMap)27 Test (org.junit.Test)22 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 Attribute (javax.management.Attribute)13 MalformedURLException (java.net.MalformedURLException)12 RemoteException (java.rmi.RemoteException)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 LocateRegistry (java.rmi.registry.LocateRegistry)8 Registry (java.rmi.registry.Registry)8 Properties (java.util.Properties)7