Search in sources :

Example 1 with JMXConnector

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

the class JMXReporterTest method testJMXAvailability.

/**
	 * Verifies that we can connect to multiple JMXReporters running on the same machine.
	 *
	 * @throws Exception
	 */
@Test
public void testJMXAvailability() throws Exception {
    Configuration cfg = new Configuration();
    cfg.setString(ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter.class.getName());
    cfg.setString(ConfigConstants.METRICS_REPORTERS_LIST, "test1,test2");
    cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
    cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1.port", "9040-9055");
    cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
    cfg.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2.port", "9040-9055");
    MetricRegistry reg = new MetricRegistry(MetricRegistryConfiguration.fromConfiguration(cfg));
    TaskManagerMetricGroup mg = new TaskManagerMetricGroup(reg, "host", "tm");
    List<MetricReporter> reporters = reg.getReporters();
    assertTrue(reporters.size() == 2);
    MetricReporter rep1 = reporters.get(0);
    MetricReporter rep2 = reporters.get(1);
    Gauge<Integer> g1 = new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return 1;
        }
    };
    Gauge<Integer> g2 = new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return 2;
        }
    };
    rep1.notifyOfAddedMetric(g1, "rep1", new FrontMetricGroup<>(0, new TaskManagerMetricGroup(reg, "host", "tm")));
    rep2.notifyOfAddedMetric(g2, "rep2", new FrontMetricGroup<>(1, new TaskManagerMetricGroup(reg, "host", "tm")));
    ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(mg.getAllVariables()));
    ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(mg.getAllVariables()));
    JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep1).getPort() + "/jndi/rmi://localhost:" + ((JMXReporter) rep1).getPort() + "/jmxrmi");
    JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
    MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();
    assertEquals(1, mCon1.getAttribute(objectName1, "Value"));
    assertEquals(2, mCon1.getAttribute(objectName2, "Value"));
    jmxCon1.close();
    JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + ((JMXReporter) rep2).getPort() + "/jndi/rmi://localhost:" + ((JMXReporter) rep2).getPort() + "/jmxrmi");
    JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
    MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();
    assertEquals(1, mCon2.getAttribute(objectName1, "Value"));
    assertEquals(2, mCon2.getAttribute(objectName2, "Value"));
    rep1.notifyOfRemovedMetric(g1, "rep1", null);
    rep1.notifyOfRemovedMetric(g2, "rep2", null);
    jmxCon2.close();
    rep1.close();
    rep2.close();
    mg.close();
    reg.shutdown();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) MetricReporter(org.apache.flink.metrics.reporter.MetricReporter) Gauge(org.apache.flink.metrics.Gauge) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) TestReporter(org.apache.flink.runtime.metrics.util.TestReporter) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 2 with JMXConnector

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

the class JMXGet method init.

/**
   * @throws Exception
   *           initializes MBeanServer
   */
public void init() throws Exception {
    err("init: server=" + server + ";port=" + port + ";service=" + service + ";localVMUrl=" + localVMUrl);
    String url_string = null;
    // build connection url
    if (localVMUrl != null) {
        // use
        // jstat -snap <vmpid> | grep sun.management.JMXConnectorServer.address
        // to get url
        url_string = localVMUrl;
        err("url string for local pid = " + localVMUrl + " = " + url_string);
    } else if (!port.isEmpty() && !server.isEmpty()) {
        // using server and port
        url_string = "service:jmx:rmi:///jndi/rmi://" + server + ":" + port + "/jmxrmi";
    }
    if (url_string == null) {
        // assume local vm (for example for Testing)
        mbsc = ManagementFactory.getPlatformMBeanServer();
    } else {
        JMXServiceURL url = new JMXServiceURL(url_string);
        err("Create RMI connector and connect to the RMI connector server" + url);
        JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
        // Get an MBeanServerConnection
        //
        err("\nGet an MBeanServerConnection");
        mbsc = jmxc.getMBeanServerConnection();
    }
    // Get domains from MBeanServer
    //
    err("\nDomains:");
    String[] domains = mbsc.getDomains();
    Arrays.sort(domains);
    for (String domain : domains) {
        err("\tDomain = " + domain);
    }
    // Get MBeanServer's default domain
    //
    err("\nMBeanServer default domain = " + mbsc.getDefaultDomain());
    // Get MBean count
    //
    err("\nMBean count = " + mbsc.getMBeanCount());
    // Query MBean names for specific domain "hadoop" and service
    ObjectName query = new ObjectName("Hadoop:service=" + service + ",*");
    hadoopObjectNames = new ArrayList<ObjectName>(5);
    err("\nQuery MBeanServer MBeans:");
    Set<ObjectName> names = new TreeSet<ObjectName>(mbsc.queryNames(query, null));
    for (ObjectName name : names) {
        hadoopObjectNames.add(name);
        err("Hadoop service: " + name);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) TreeSet(java.util.TreeSet) ObjectName(javax.management.ObjectName)

Example 3 with JMXConnector

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

the class TestJMXConnectorServer method testRSConnectorServerWhenStopRegionServer.

/**
   * This tests to validate the RegionServer's ConnectorServer after unauthorised stopRegionServer
   * call.
   */
@Test(timeout = 180000)
public void testRSConnectorServerWhenStopRegionServer() throws Exception {
    conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, JMXListener.class.getName() + "," + MyAccessController.class.getName());
    conf.setInt("regionserver.rmi.registry.port", rmiRegistryPort);
    UTIL.startMiniCluster();
    admin = UTIL.getConnection().getAdmin();
    hasAccess = false;
    ServerName serverName = UTIL.getHBaseCluster().getRegionServer(0).getServerName();
    LOG.info("Stopping Region Server...");
    admin.stopRegionServer(serverName.getHostname() + ":" + serverName.getPort());
    // Check whether Region Sever JMX Connector server can be connected
    JMXConnector connector = null;
    try {
        connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
    } catch (IOException e) {
        if (e.getCause() instanceof ServiceUnavailableException) {
            Assert.fail("Can't connect to Region Server ConnectorServer.");
        }
    }
    Assert.assertNotNull("JMXConnector should not be null.", connector);
    connector.close();
}
Also used : JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Test(org.junit.Test)

Example 4 with JMXConnector

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

the class TestJMXConnectorServer method testHMConnectorServerWhenShutdownCluster.

/**
   * This tests to validate the HMaster's ConnectorServer after unauthorised shutdown call.
   */
@Test(timeout = 180000)
public void testHMConnectorServerWhenShutdownCluster() throws Exception {
    conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, JMXListener.class.getName() + "," + MyAccessController.class.getName());
    conf.setInt("master.rmi.registry.port", rmiRegistryPort);
    UTIL.startMiniCluster();
    admin = UTIL.getConnection().getAdmin();
    boolean accessDenied = false;
    try {
        hasAccess = false;
        LOG.info("Stopping HMaster...");
        admin.shutdown();
    } catch (AccessDeniedException e) {
        LOG.error("Exception occured while stopping HMaster. ", e);
        accessDenied = true;
    }
    Assert.assertTrue(accessDenied);
    // Check whether HMaster JMX Connector server can be connected
    JMXConnector connector = null;
    try {
        connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
    } catch (IOException e) {
        if (e.getCause() instanceof ServiceUnavailableException) {
            Assert.fail("Can't connect to HMaster ConnectorServer.");
        }
    }
    Assert.assertNotNull("JMXConnector should not be null.", connector);
    connector.close();
}
Also used : AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Test(org.junit.Test)

Example 5 with JMXConnector

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

the class TestJMXListener method testStop.

@Test
public void testStop() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    LOG.info("shutdown hbase cluster...");
    cluster.shutdown();
    LOG.info("wait for the hbase cluster shutdown...");
    cluster.waitUntilShutDown();
    JMXConnector connector = JMXConnectorFactory.newJMXConnector(JMXListener.buildJMXServiceURL(connectorPort, connectorPort), null);
    expectedEx.expect(IOException.class);
    connector.connect();
}
Also used : JMXConnector(javax.management.remote.JMXConnector) Test(org.junit.Test)

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