diff --git a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java index 7e3a79df9d3f..a61e61684dac 100644 --- a/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/http/jmx/JMXJsonServlet.java @@ -212,7 +212,11 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro if (qry == null) { qry = "*:*"; } - if (beanWriter.write(this.mBeanServer, new ObjectName(qry), null, description) != 0) { + String excl = request.getParameter("excl"); + ObjectName excluded = excl == null ? null : new ObjectName(excl); + + if (beanWriter.write(this.mBeanServer, new ObjectName(qry), + null, description, excluded) != 0) { beanWriter.flush(); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } diff --git a/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java b/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java index 0dbe0fdf78cd..4afc567e2184 100644 --- a/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java +++ b/hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONBean.java @@ -66,8 +66,13 @@ public interface Writer extends Closeable { void write(String key, String value) throws IOException; - int write(MBeanServer mBeanServer, ObjectName qry, String attribute, boolean description) - throws IOException; + default int write(MBeanServer mBeanServer, ObjectName qry, String attribute, + boolean description) throws IOException { + return write(mBeanServer, qry, attribute, description, null); + } + + int write(MBeanServer mBeanServer, ObjectName qry, String attribute, boolean description, + ObjectName excluded) throws IOException; void flush() throws IOException; } @@ -118,8 +123,8 @@ public void write(String key, String value) throws IOException { @Override public int write(MBeanServer mBeanServer, ObjectName qry, String attribute, - boolean description) throws IOException { - return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description); + boolean description, ObjectName excluded) throws IOException { + return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description, excluded); } }; } @@ -128,7 +133,7 @@ public int write(MBeanServer mBeanServer, ObjectName qry, String attribute, * @return Return non-zero if failed to find bean. 0 */ private static int write(JsonWriter writer, MBeanServer mBeanServer, ObjectName qry, - String attribute, boolean description) throws IOException { + String attribute, boolean description, ObjectName excluded) throws IOException { LOG.debug("Listing beans for {}", qry); Set names = null; names = mBeanServer.queryNames(qry, null); @@ -137,6 +142,9 @@ private static int write(JsonWriter writer, MBeanServer mBeanServer, ObjectName Pattern[] matchingPattern = null; while (it.hasNext()) { ObjectName oname = it.next(); + if (excluded != null && excluded.apply(oname)) { + continue; + } MBeanInfo minfo; String code = ""; String descriptionStr = null; diff --git a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java index e907a3260b0b..02248d6bcd29 100644 --- a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/jmx/TestJMXJsonServlet.java @@ -122,6 +122,12 @@ public static void assertNotFind(String re, String value) { assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result); assertReFind("\"committed\"\\s*:", result); assertReFind("\\}\\);$", result); + + // test exclude the specific mbean + result = readOutput(new URL(baseUrl, + "/jmx?excl=Hadoop:service=HBase,name=RegionServer,sub=Regions")); + LOG.info("/jmx RESULT: " + result); + assertNotFind("\"name\"\\s*:\\s*\"Hadoop:service=HBase,name=RegionServer,sub=Regions\"",result); } @Test