Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
};
}
Expand All @@ -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<ObjectName> names = null;
names = mBeanServer.queryNames(qry, null);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down