You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2021/05/21 08:58:18 UTC

[GitHub] [phoenix-queryserver] anmolnar commented on a change in pull request #65: PHOENIX-6473 Add Hadoop JMXServlet as /jmx endpoint

anmolnar commented on a change in pull request #65:
URL: https://github.com/apache/phoenix-queryserver/pull/65#discussion_r636755496



##########
File path: phoenix-queryserver/src/main/java/org/apache/phoenix/queryserver/server/customizers/JMXJsonEndpointServerCustomizer.java
##########
@@ -0,0 +1,46 @@
+package org.apache.phoenix.queryserver.server.customizers;
+
+import static org.apache.hadoop.http.HttpServer2.CONF_CONTEXT_ATTRIBUTE;
+
+import org.apache.calcite.avatica.server.ServerCustomizer;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.jmx.JMXJsonServlet;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.HandlerList;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+
+import javax.servlet.Servlet;
+
+public class JMXJsonEndpointServerCustomizer implements ServerCustomizer<Server> {
+  private static final Logger LOG = LoggerFactory.getLogger(JMXJsonEndpointServerCustomizer.class);
+
+  @Override
+  public void customize(Server server) {
+    Handler[] handlers = server.getHandlers();
+    if (handlers.length != 1) {
+      LOG.warn("Observed handlers on server {}", Arrays.toString(handlers));
+      throw new IllegalStateException("Expected to find one handler");
+    }
+    HandlerList list = (HandlerList) handlers[0];
+
+    ServletContextHandler ctx = new ServletContextHandler();
+    ctx.setContextPath("/jmx");
+    ctx.getServletContext().setAttribute(CONF_CONTEXT_ATTRIBUTE, HBaseConfiguration.create());
+
+    Servlet servlet = new JMXJsonServlet();
+    ServletHolder holder = new ServletHolder(servlet);
+    ctx.addServlet(holder, "/");
+
+    Handler[] realHandlers = list.getChildHandlers();
+    Handler[] newHandlers = new Handler[realHandlers.length + 1];
+    newHandlers[0] = ctx;
+    System.arraycopy(realHandlers, 0, newHandlers, 1, realHandlers.length);
+    server.setHandler(new HandlerList(newHandlers));

Review comment:
       No, it doesn't need authentication (currently).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org