got blurMetrics forwarding out /metrics.  Ports are one upping like the main 
shards do.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/ca9a17c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/ca9a17c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/ca9a17c4

Branch: refs/heads/master
Commit: ca9a17c4f53082bbf4809b95c8c4fb6f58e3cbfe
Parents: e7f6a94
Author: gbarton <[email protected]>
Authored: Fri Aug 3 22:09:16 2012 -0400
Committer: gbarton <[email protected]>
Committed: Fri Aug 3 22:09:16 2012 -0400

----------------------------------------------------------------------
 .../blur/thrift/ThriftBlurControllerServer.java    |    5 +-
 .../blur/thrift/ThriftBlurShardServer.java         |    8 +-
 .../com/nearinfinity/blur/gui/HttpJettyServer.java |   11 +-
 .../blur/shard/ShardMetricsServlet.java            |   36 +++++
 .../src/main/webapps/controller/WEB-INF/web.xml    |   10 +-
 .../src/main/webapps/controller/functions.jsp      |    2 +-
 .../src/main/webapps/shard/WEB-INF/web.xml         |   10 ++
 src/blur-gui/src/main/webapps/shard/functions.jsp  |   25 ++++
 src/blur-gui/src/main/webapps/shard/index.html     |   13 ++
 src/blur-gui/src/main/webapps/shard/shard.jsp      |  106 +++++++++++++++
 10 files changed, 212 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurControllerServer.java
----------------------------------------------------------------------
diff --git 
a/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurControllerServer.java
 
b/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurControllerServer.java
index 403f31f..79cac7e 100644
--- 
a/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurControllerServer.java
+++ 
b/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurControllerServer.java
@@ -36,7 +36,6 @@ import static 
com.nearinfinity.blur.utils.BlurConstants.BLUR_CONTROLLER_SERVER_T
 import static 
com.nearinfinity.blur.utils.BlurConstants.BLUR_ZOOKEEPER_CONNECTION;
 import static 
com.nearinfinity.blur.utils.BlurConstants.BLUR_ZOOKEEPER_SYSTEM_TIME_TOLERANCE;
 import static 
com.nearinfinity.blur.utils.BlurConstants.BLUR_GUI_CONTROLLER_PORT;
-import static com.nearinfinity.blur.utils.BlurConstants.BLUR_GUI_SHARD_PORT;
 import static com.nearinfinity.blur.utils.BlurUtil.quietClose;
 
 import java.io.IOException;
@@ -130,7 +129,9 @@ public class ThriftBlurControllerServer extends 
ThriftServer {
     server.setThreadCount(threadCount);
     server.setIface(iface);
     
-    final HttpJettyServer httpServer = new 
HttpJettyServer(configuration.get(BLUR_GUI_CONTROLLER_PORT), "controller");
+    int webServerPort = 
Integer.parseInt(configuration.get(BLUR_GUI_CONTROLLER_PORT)) + serverIndex;
+    
+    final HttpJettyServer httpServer = new HttpJettyServer(webServerPort, 
"controller", blurMetrics);
 
     // This will shutdown the server when the correct path is set in zk
     new BlurServerShutDown().register(new BlurShutdown() {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurShardServer.java
----------------------------------------------------------------------
diff --git 
a/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurShardServer.java
 
b/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurShardServer.java
index 1c1e8c8..eaf831e 100644
--- 
a/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurShardServer.java
+++ 
b/src/blur-core/src/main/java/com/nearinfinity/blur/thrift/ThriftBlurShardServer.java
@@ -16,6 +16,7 @@
 
 package com.nearinfinity.blur.thrift;
 
+import static com.nearinfinity.blur.utils.BlurConstants.BLUR_GUI_SHARD_PORT;
 import static 
com.nearinfinity.blur.utils.BlurConstants.BLUR_INDEXMANAGER_SEARCH_THREAD_COUNT;
 import static com.nearinfinity.blur.utils.BlurConstants.BLUR_MAX_CLAUSE_COUNT;
 import static 
com.nearinfinity.blur.utils.BlurConstants.BLUR_SHARD_BIND_ADDRESS;
@@ -51,6 +52,7 @@ import org.apache.zookeeper.ZooKeeper;
 import com.nearinfinity.blur.BlurConfiguration;
 import com.nearinfinity.blur.concurrent.SimpleUncaughtExceptionHandler;
 import com.nearinfinity.blur.concurrent.ThreadWatcher;
+import com.nearinfinity.blur.gui.HttpJettyServer;
 import com.nearinfinity.blur.log.Log;
 import com.nearinfinity.blur.log.LogFactory;
 import com.nearinfinity.blur.lucene.index.TimeBasedIndexDeletionPolicy;
@@ -192,13 +194,17 @@ public class ThriftBlurShardServer extends ThriftServer {
     server.setThreadCount(threadCount);
     server.setIface(iface);
     server.setConfiguration(configuration);
+    
+    int webServerPort = 
Integer.parseInt(configuration.get(BLUR_GUI_SHARD_PORT)) + serverIndex;
+    
+    final HttpJettyServer httpServer = new HttpJettyServer(webServerPort, 
"shard", blurMetrics);
 
     // This will shutdown the server when the correct path is set in zk
     new BlurServerShutDown().register(new BlurShutdown() {
       @Override
       public void shutdown() {
         ThreadWatcher threadWatcher = ThreadWatcher.instance();
-        quietClose(refresher, server, shardServer, indexManager, indexServer, 
threadWatcher);
+        quietClose(refresher, server, shardServer, indexManager, indexServer, 
threadWatcher, httpServer);
         System.exit(0);
       }
     }, zooKeeper);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java
----------------------------------------------------------------------
diff --git 
a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java 
b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java
index 43b8181..06339f9 100644
--- a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java
+++ b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java
@@ -2,14 +2,15 @@ package com.nearinfinity.blur.gui;
 
 import java.io.File;
 import java.io.IOException;
-import java.net.URL;
 
 import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.webapp.WebAppContext;
 
-import com.nearinfinity.blur.BlurConfiguration;
 import com.nearinfinity.blur.log.Log;
 import com.nearinfinity.blur.log.LogFactory;
+import com.nearinfinity.blur.metrics.BlurMetrics;
+import com.nearinfinity.blur.shard.ShardMetricsServlet;
 
 /**
  * Starts up a Jetty server to run the utility gui
@@ -22,13 +23,15 @@ public class HttpJettyServer {
 
        private Server server = null;
        
-       public HttpJettyServer(String port, String base) throws IOException  {
-        server = new Server(Integer.parseInt(port));
+       public HttpJettyServer(int port, String base, BlurMetrics bm) throws 
IOException  {
+        server = new Server(port);
         
         WebAppContext context = new WebAppContext();
         context.setWar(getJarFolder() + "../src/blur-gui/src/main/webapps/" + 
base);
         context.setContextPath("/");
         context.setParentLoaderPriority(true);
+        context.setAttribute("bm", bm);
+        context.addServlet(new ServletHolder(new ShardMetricsServlet(bm)), 
"/metrics");
         
         LOG.info("WEB GUI coming up for resource: " + base);
         LOG.info("WEB GUI thinks its at: " + getJarFolder());

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/java/com/nearinfinity/blur/shard/ShardMetricsServlet.java
----------------------------------------------------------------------
diff --git 
a/src/blur-gui/src/main/java/com/nearinfinity/blur/shard/ShardMetricsServlet.java
 
b/src/blur-gui/src/main/java/com/nearinfinity/blur/shard/ShardMetricsServlet.java
new file mode 100644
index 0000000..f9e234a
--- /dev/null
+++ 
b/src/blur-gui/src/main/java/com/nearinfinity/blur/shard/ShardMetricsServlet.java
@@ -0,0 +1,36 @@
+package com.nearinfinity.blur.shard;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+import com.nearinfinity.blur.metrics.BlurMetrics;
+
+public class ShardMetricsServlet extends HttpServlet {
+       
+       private static final long serialVersionUID = 1L;
+
+       private BlurMetrics bm = null;
+
+       public ShardMetricsServlet() {
+       }
+
+       
+       public ShardMetricsServlet(BlurMetrics bm) {
+               this.bm = bm;
+       }
+
+       protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+               response.setContentType("application/json");
+               PrintWriter out = response.getWriter();
+               ObjectMapper mapper = new ObjectMapper();
+               mapper.writeValue(out, bm);
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/webapps/controller/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/webapps/controller/WEB-INF/web.xml 
b/src/blur-gui/src/main/webapps/controller/WEB-INF/web.xml
index 311e084..a35ac56 100644
--- a/src/blur-gui/src/main/webapps/controller/WEB-INF/web.xml
+++ b/src/blur-gui/src/main/webapps/controller/WEB-INF/web.xml
@@ -1,10 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<web-app xmlns="http://java.sun.com/xml/ns/javaee";
-   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
-   version="2.5">
-
- <display-name>Blur GUI</display-name>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
+       version="2.5">
 
+       <display-name>Blur GUI</display-name>
 </web-app>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/webapps/controller/functions.jsp
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/webapps/controller/functions.jsp 
b/src/blur-gui/src/main/webapps/controller/functions.jsp
index bbc6e4c..9e5d82b 100644
--- a/src/blur-gui/src/main/webapps/controller/functions.jsp
+++ b/src/blur-gui/src/main/webapps/controller/functions.jsp
@@ -22,4 +22,4 @@
                return ret + "</tr>" + content + "</table>\n";
        }
        
-       %>
\ No newline at end of file
+%>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/webapps/shard/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/webapps/shard/WEB-INF/web.xml 
b/src/blur-gui/src/main/webapps/shard/WEB-INF/web.xml
new file mode 100644
index 0000000..311e084
--- /dev/null
+++ b/src/blur-gui/src/main/webapps/shard/WEB-INF/web.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee";
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
+   version="2.5">
+
+ <display-name>Blur GUI</display-name>
+
+</web-app>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/webapps/shard/functions.jsp
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/webapps/shard/functions.jsp 
b/src/blur-gui/src/main/webapps/shard/functions.jsp
new file mode 100644
index 0000000..9e5d82b
--- /dev/null
+++ b/src/blur-gui/src/main/webapps/shard/functions.jsp
@@ -0,0 +1,25 @@
+
+<%!public String row(String... col) {
+               String ret = "<tr>";
+               for (String c : col)
+                       ret += "<td>" + c + "</td>";
+               return ret + "</tr>\n";
+       }
+
+       public String row(int colspan, String col) {
+               return "<tr><td colspan=" + colspan + ">" + col + "</td></tr>";
+       }
+
+       public String shardListLink(String cluster, String display) {
+               return "<a href='shardList.jsp?clusterName=" + cluster
+                               + "' title='view shard servers'>" + display + 
"</a>";
+       }
+       
+       public String table(String content, String... headers) {
+               String ret = "<table class='statTable'><tr>\n";
+               for(String h : headers)
+                       ret += "<td class='statTableTitle'>" + h + "</td>\n";
+               return ret + "</tr>" + content + "</table>\n";
+       }
+       
+%>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/webapps/shard/index.html
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/webapps/shard/index.html 
b/src/blur-gui/src/main/webapps/shard/index.html
new file mode 100644
index 0000000..1a67009
--- /dev/null
+++ b/src/blur-gui/src/main/webapps/shard/index.html
@@ -0,0 +1,13 @@
+<meta HTTP-EQUIV="REFRESH" content="0;url=shard.jsp"/>
+<html>
+<head>
+<title>Blur</title>
+</head>
+<body>
+<h1>Blur</h1>
+
+<ul>
+<li><a href="shard.jsp">Blur Shard Health/Status</a></li>
+</ul>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ca9a17c4/src/blur-gui/src/main/webapps/shard/shard.jsp
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/webapps/shard/shard.jsp 
b/src/blur-gui/src/main/webapps/shard/shard.jsp
new file mode 100644
index 0000000..8e36706
--- /dev/null
+++ b/src/blur-gui/src/main/webapps/shard/shard.jsp
@@ -0,0 +1,106 @@
+<%@ page contentType="text/html; charset=UTF-8" isThreadSafe="false"
+       import="javax.servlet.*" import="javax.servlet.http.*"
+       import="java.io.*" import="java.util.*" import="java.text.DateFormat"
+       import="java.lang.Math" import="java.net.URLEncoder"
+       import="com.nearinfinity.blur.thrift.*"
+       import="com.nearinfinity.blur.thrift.generated.*"
+       import="com.nearinfinity.blur.thrift.generated.Blur.*"%>
+<%@ include file="functions.jsp" %>
+<%!
+
+       public String tableLink(String tableName, String clusterName) {
+               return "<a 
href='table.jsp?tableName="+tableName+"&clusterName="+clusterName+"' 
title='view details for " + tableName + "'>" + tableName + "</a>";
+       }
+       
+       public String getTables(Iface client) throws Exception {
+               String ret = "";
+               List<String> clusters = client.shardClusterList();
+               for (String cluster : clusters) {
+                       //tables: _ tableName : enabled
+                       List<String> tables = 
client.tableListByCluster(cluster);
+                       for (String table : tables) {
+                               try {
+                                       ret += row(cluster, 
tableLink(table,cluster), client.describe(table).isEnabled?"yes":"no");
+                               } catch (BlurException e) {
+                                       ret += row(3, "<font color=FF0000>Error 
describing table: "
+                                                       + table + "</font>");
+                               }
+                       }
+               }
+               return ret;
+       }
+
+       public String getClusters(Iface client) throws Exception {
+               String ret = "";
+               List<String> clusters = client.shardClusterList();
+               for (String cluster : clusters) {
+                       ret += row(cluster, 
shardListLink(cluster,client.shardServerList(cluster).size()+""), 
getClusterEnabled(client, cluster));
+               }
+               return ret;
+       }
+
+       
+       public String getConf(Iface client) throws Exception {
+               return row(2,"disabled as its broken");
+/*             try {
+                       Map<String, String> config = client.configuration();
+                       String ret = "";
+                       for (String key : config.keySet()) {
+                               ret += row(key, config.get(key));
+                       }
+                       return ret;
+               } catch (Exception e) {
+                       return row(2, "Cannot retrieve anything from 
client.configuration.");
+               }*/
+       }
+
+       public String getClusterEnabled(Iface client, String cluster)
+                       throws Exception {
+               return client.isInSafeMode(cluster) ? "Safe Mode On"
+                               : "Yes";
+       }
+
+       public String getControllers(Iface client) throws Exception {
+               String ret = "";
+               List<String> con = client.controllerServerList();
+
+               for (String c : con) {
+                       ret += row(c, "Yes");
+               }
+               
+               return ret;
+       }%>
+<%
+       //TODO: prop file the port
+       String hostName = request.getServerName() + ":40010";
+
+       Iface client = BlurClient.getClient(hostName);
+%>
+
+
+<html>
+<head>
+<title>Blur Shard '<%=hostName%>'
+</title>
+<link href="style.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+       <h1>
+               Blur Shard '<%=hostName%>'
+       </h1>
+       <br />
+       <h2>Controllers</h2>
+
+       <hr />
+       <br />
+       <h2>Clusters</h2>
+       <hr />
+       <br />
+       <h2>Tables</h2>
+       <hr />
+       <br />
+       <h2>Configs</h2>
+
+</body>
+
+</html>

Reply via email to