HBASE-14423 TestStochasticBalancerJmxMetrics.testJmxMetrics_PerTableMode:183 NullPointer
This commit is contained in:
parent
a9157379a3
commit
439ca071ec
|
@ -20,8 +20,10 @@ package org.apache.hadoop.hbase;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -30,6 +32,7 @@ import java.util.Set;
|
||||||
import javax.management.MBeanAttributeInfo;
|
import javax.management.MBeanAttributeInfo;
|
||||||
import javax.management.MBeanInfo;
|
import javax.management.MBeanInfo;
|
||||||
import javax.management.MBeanServerConnection;
|
import javax.management.MBeanServerConnection;
|
||||||
|
import javax.management.ObjectInstance;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.remote.JMXConnector;
|
import javax.management.remote.JMXConnector;
|
||||||
import javax.management.remote.JMXConnectorFactory;
|
import javax.management.remote.JMXConnectorFactory;
|
||||||
|
@ -42,6 +45,7 @@ import org.apache.hadoop.hbase.master.balancer.BalancerTestBase;
|
||||||
import org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer;
|
import org.apache.hadoop.hbase.master.balancer.StochasticLoadBalancer;
|
||||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||||
|
import org.apache.hadoop.hbase.util.Threads;
|
||||||
import org.apache.hadoop.net.DNSToSwitchMapping;
|
import org.apache.hadoop.net.DNSToSwitchMapping;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -114,7 +118,7 @@ public class TestStochasticBalancerJmxMetrics extends BalancerTestBase {
|
||||||
/**
|
/**
|
||||||
* In Ensemble mode, there should be only one ensemble table
|
* In Ensemble mode, there should be only one ensemble table
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test (timeout=60000)
|
||||||
public void testJmxMetrics_EnsembleMode() throws Exception {
|
public void testJmxMetrics_EnsembleMode() throws Exception {
|
||||||
loadBalancer = new StochasticLoadBalancer();
|
loadBalancer = new StochasticLoadBalancer();
|
||||||
|
|
||||||
|
@ -127,7 +131,7 @@ public class TestStochasticBalancerJmxMetrics extends BalancerTestBase {
|
||||||
|
|
||||||
String[] tableNames = new String[] { tableName.getNameAsString() };
|
String[] tableNames = new String[] { tableName.getNameAsString() };
|
||||||
String[] functionNames = loadBalancer.getCostFunctionNames();
|
String[] functionNames = loadBalancer.getCostFunctionNames();
|
||||||
Set<String> jmxMetrics = readJmxMetrics();
|
Set<String> jmxMetrics = readJmxMetricsWithRetry();
|
||||||
Set<String> expectedMetrics = getExpectedJmxMetrics(tableNames, functionNames);
|
Set<String> expectedMetrics = getExpectedJmxMetrics(tableNames, functionNames);
|
||||||
|
|
||||||
// printMetrics(jmxMetrics, "existing metrics in ensemble mode");
|
// printMetrics(jmxMetrics, "existing metrics in ensemble mode");
|
||||||
|
@ -143,7 +147,7 @@ public class TestStochasticBalancerJmxMetrics extends BalancerTestBase {
|
||||||
/**
|
/**
|
||||||
* In per-table mode, each table has a set of metrics
|
* In per-table mode, each table has a set of metrics
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test (timeout=60000)
|
||||||
public void testJmxMetrics_PerTableMode() throws Exception {
|
public void testJmxMetrics_PerTableMode() throws Exception {
|
||||||
loadBalancer = new StochasticLoadBalancer();
|
loadBalancer = new StochasticLoadBalancer();
|
||||||
|
|
||||||
|
@ -172,7 +176,7 @@ public class TestStochasticBalancerJmxMetrics extends BalancerTestBase {
|
||||||
loadBalancer.balanceCluster(tableName, clusterState);
|
loadBalancer.balanceCluster(tableName, clusterState);
|
||||||
|
|
||||||
String[] tableNames = new String[] { TABLE_NAME_1, TABLE_NAME_2, TABLE_NAME_NAMESPACE };
|
String[] tableNames = new String[] { TABLE_NAME_1, TABLE_NAME_2, TABLE_NAME_NAMESPACE };
|
||||||
Set<String> jmxMetrics = readJmxMetrics();
|
Set<String> jmxMetrics = readJmxMetricsWithRetry();
|
||||||
Set<String> expectedMetrics = getExpectedJmxMetrics(tableNames, functionNames);
|
Set<String> expectedMetrics = getExpectedJmxMetrics(tableNames, functionNames);
|
||||||
|
|
||||||
// printMetrics(jmxMetrics, "existing metrics in per-table mode");
|
// printMetrics(jmxMetrics, "existing metrics in per-table mode");
|
||||||
|
@ -185,21 +189,35 @@ public class TestStochasticBalancerJmxMetrics extends BalancerTestBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> readJmxMetricsWithRetry() throws IOException {
|
||||||
|
final int count = 0;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
Set<String> metrics = readJmxMetrics();
|
||||||
|
if (metrics != null) return metrics;
|
||||||
|
LOG.warn("Failed to get jmxmetrics... sleeping, retrying; " + i + " of " + count + " times");
|
||||||
|
Threads.sleep(1000);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the attributes from Hadoop->HBase->Master->Balancer in JMX
|
* Read the attributes from Hadoop->HBase->Master->Balancer in JMX
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private Set<String> readJmxMetrics() {
|
private Set<String> readJmxMetrics() throws IOException {
|
||||||
JMXConnector connector = null;
|
JMXConnector connector = null;
|
||||||
|
ObjectName target = null;
|
||||||
|
MBeanServerConnection mb = null;
|
||||||
try {
|
try {
|
||||||
connector =
|
connector =
|
||||||
JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));
|
JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort));
|
||||||
MBeanServerConnection mb = connector.getMBeanServerConnection();
|
mb = connector.getMBeanServerConnection();
|
||||||
|
|
||||||
Hashtable<String, String> pairs = new Hashtable<>();
|
Hashtable<String, String> pairs = new Hashtable<>();
|
||||||
pairs.put("service", "HBase");
|
pairs.put("service", "HBase");
|
||||||
pairs.put("name", "Master");
|
pairs.put("name", "Master");
|
||||||
pairs.put("sub", "Balancer");
|
pairs.put("sub", "Balancer");
|
||||||
ObjectName target = new ObjectName("Hadoop", pairs);
|
target = new ObjectName("Hadoop", pairs);
|
||||||
MBeanInfo beanInfo = mb.getMBeanInfo(target);
|
MBeanInfo beanInfo = mb.getMBeanInfo(target);
|
||||||
|
|
||||||
Set<String> existingAttrs = new HashSet<String>();
|
Set<String> existingAttrs = new HashSet<String>();
|
||||||
|
@ -208,7 +226,17 @@ public class TestStochasticBalancerJmxMetrics extends BalancerTestBase {
|
||||||
}
|
}
|
||||||
return existingAttrs;
|
return existingAttrs;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LOG.warn("Failed to get bean!!! " + target, e);
|
||||||
|
if (mb != null) {
|
||||||
|
Set<ObjectInstance> instances = mb.queryMBeans(null, null);
|
||||||
|
Iterator<ObjectInstance> iterator = instances.iterator();
|
||||||
|
System.out.println("MBean Found:");
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
ObjectInstance instance = iterator.next();
|
||||||
|
System.out.println("Class Name: " + instance.getClassName());
|
||||||
|
System.out.println("Object Name: " + instance.getObjectName());
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (connector != null) {
|
if (connector != null) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue