HBASE-26554 Introduce a new parameter in jmx servlet to exclude the specific mbean (#3930)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
a3ff8e4c81
commit
136b1ea7ab
|
@ -212,7 +212,11 @@ public class JMXJsonServlet extends HttpServlet {
|
||||||
if (qry == null) {
|
if (qry == null) {
|
||||||
qry = "*:*";
|
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();
|
beanWriter.flush();
|
||||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,13 @@ public class JSONBean {
|
||||||
|
|
||||||
void write(String key, String value) throws IOException;
|
void write(String key, String value) throws IOException;
|
||||||
|
|
||||||
int write(MBeanServer mBeanServer, ObjectName qry, String attribute, boolean description)
|
default int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
|
||||||
throws IOException;
|
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;
|
void flush() throws IOException;
|
||||||
}
|
}
|
||||||
|
@ -118,8 +123,8 @@ public class JSONBean {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
|
public int write(MBeanServer mBeanServer, ObjectName qry, String attribute,
|
||||||
boolean description) throws IOException {
|
boolean description, ObjectName excluded) throws IOException {
|
||||||
return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description);
|
return JSONBean.write(jsonWriter, mBeanServer, qry, attribute, description, excluded);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -128,7 +133,7 @@ public class JSONBean {
|
||||||
* @return Return non-zero if failed to find bean. 0
|
* @return Return non-zero if failed to find bean. 0
|
||||||
*/
|
*/
|
||||||
private static int write(JsonWriter writer, MBeanServer mBeanServer, ObjectName qry,
|
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);
|
LOG.debug("Listing beans for {}", qry);
|
||||||
Set<ObjectName> names = null;
|
Set<ObjectName> names = null;
|
||||||
names = mBeanServer.queryNames(qry, null);
|
names = mBeanServer.queryNames(qry, null);
|
||||||
|
@ -137,6 +142,9 @@ public class JSONBean {
|
||||||
Pattern[] matchingPattern = null;
|
Pattern[] matchingPattern = null;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
ObjectName oname = it.next();
|
ObjectName oname = it.next();
|
||||||
|
if (excluded != null && excluded.apply(oname)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
MBeanInfo minfo;
|
MBeanInfo minfo;
|
||||||
String code = "";
|
String code = "";
|
||||||
String descriptionStr = null;
|
String descriptionStr = null;
|
||||||
|
|
|
@ -122,6 +122,12 @@ public class TestJMXJsonServlet extends HttpServerFunctionalTest {
|
||||||
assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result);
|
assertReFind("\"name\"\\s*:\\s*\"java.lang:type=Memory\"", result);
|
||||||
assertReFind("\"committed\"\\s*:", result);
|
assertReFind("\"committed\"\\s*:", result);
|
||||||
assertReFind("\\}\\);$", 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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue