incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [36/47] git commit: simple log viewer and metrics servlet
Date Mon, 03 Sep 2012 00:32:20 GMT
simple log viewer and metrics servlet


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

Branch: refs/heads/master
Commit: ab40a9a3c42611343961b8e57ba079a00b22525f
Parents: ca9a17c
Author: gbarton <garrett.barton@gmail.com>
Authored: Thu Aug 16 22:21:15 2012 -0400
Committer: gbarton <garrett.barton@gmail.com>
Committed: Thu Aug 16 22:21:15 2012 -0400

----------------------------------------------------------------------
 .../blur/thrift/ThriftBlurControllerServer.java    |    9 ++-
 .../blur/thrift/ThriftBlurShardServer.java         |   11 ++-
 .../com/nearinfinity/blur/gui/HttpJettyServer.java |   36 +++++--
 .../java/com/nearinfinity/blur/gui/LogServlet.java |   80 +++++++++++++
 .../com/nearinfinity/blur/gui/MetricsServlet.java  |   36 ++++++
 .../blur/shard/ShardMetricsServlet.java            |   36 ------
 .../src/main/webapps/controller/controller.jsp     |    6 +-
 .../src/main/webapps/controller/d3.v2.min.js       |    8 +-
 .../src/main/webapps/controller/shardList.jsp      |   10 ++-
 src/blur-gui/src/main/webapps/controller/table.jsp |    2 +-
 src/blur-gui/src/main/webapps/controller/test.html |   91 +++++++++++++++
 src/blur-gui/src/main/webapps/shard/shard.jsp      |   17 +++-
 src/blur-gui/src/main/webapps/shard/style.css      |   53 +++++++++
 13 files changed, 336 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab40a9a3/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 79cac7e..4009c43 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,6 +36,8 @@ 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.BlurConstants.BLUR_SHARD_BIND_PORT;
 import static com.nearinfinity.blur.utils.BlurUtil.quietClose;
 
 import java.io.IOException;
@@ -131,7 +133,12 @@ public class ThriftBlurControllerServer extends ThriftServer {
     
     int webServerPort = Integer.parseInt(configuration.get(BLUR_GUI_CONTROLLER_PORT)) + serverIndex;
     
-    final HttpJettyServer httpServer = new HttpJettyServer(webServerPort, "controller", blurMetrics);
+    final HttpJettyServer httpServer = new HttpJettyServer(bindPort, webServerPort,
+    		configuration.getInt(BLUR_CONTROLLER_BIND_PORT, -1),
+    		configuration.getInt(BLUR_SHARD_BIND_PORT, -1),
+    		Integer.parseInt(configuration.get(BLUR_GUI_CONTROLLER_PORT)),
+    		Integer.parseInt(configuration.get(BLUR_GUI_SHARD_PORT)),
+    		"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/ab40a9a3/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 eaf831e..08b542f 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,8 @@
 
 package com.nearinfinity.blur.thrift;
 
+import static com.nearinfinity.blur.utils.BlurConstants.BLUR_CONTROLLER_BIND_PORT;
+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.BlurConstants.BLUR_INDEXMANAGER_SEARCH_THREAD_COUNT;
 import static com.nearinfinity.blur.utils.BlurConstants.BLUR_MAX_CLAUSE_COUNT;
@@ -196,8 +198,13 @@ public class ThriftBlurShardServer extends ThriftServer {
     server.setConfiguration(configuration);
     
     int webServerPort = Integer.parseInt(configuration.get(BLUR_GUI_SHARD_PORT)) + serverIndex;
-    
-    final HttpJettyServer httpServer = new HttpJettyServer(webServerPort, "shard", blurMetrics);
+
+    final HttpJettyServer httpServer = new HttpJettyServer(bindPort, webServerPort,
+    		Integer.parseInt(configuration.get(BLUR_GUI_CONTROLLER_PORT)),
+    		Integer.parseInt(configuration.get(BLUR_GUI_SHARD_PORT)),
+    		configuration.getInt(BLUR_CONTROLLER_BIND_PORT, -1),
+    		configuration.getInt(BLUR_SHARD_BIND_PORT, -1),
+    		"shard", 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/ab40a9a3/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 06339f9..f2fd971 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
@@ -7,10 +7,10 @@ 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
@@ -23,18 +23,42 @@ public class HttpJettyServer {
 
 	private Server server = null;
 	
-	public HttpJettyServer(int port, String base, BlurMetrics bm) throws IOException  {
+	/**
+	 * @param bindPort port of the process that the gui is wrapping
+	 * @param port port to run gui on
+	 * @param baseControllerPort ports that service runs on
+	 * @param baseShardPort
+	 * @param baseGuiShardPort port to run gui on
+	 * @param baseGuiControllerPort port to run gui on
+	 * @param base location of webapp to serve
+	 * @param bm metrics object for using.
+	 * @throws IOException
+	 */
+	//TODO: this got ugly, move to a set/start pattern
+	public HttpJettyServer(int bindPort, int port, int baseControllerPort,
+			int baseShardPort, int baseGuiControllerPort, int baseGuiShardPort,
+			String base, BlurMetrics bm) throws IOException {
         server = new Server(port);
         
+        String blurLogFile = System.getProperty("blur.logs.dir") + "/" + System.getProperty("blur.log.file");
+        System.setProperty("blur.gui.servicing.port", bindPort+"");
+        System.setProperty("blur.base.shard.port",baseShardPort+"");
+        System.setProperty("blur.base.controller.port",baseControllerPort+"");
+        System.setProperty("baseGuiShardPort",baseGuiShardPort+"");
+        System.setProperty("baseGuiControllerPort",baseGuiControllerPort+"");
+        LOG.info("System props:" + System.getProperties().toString());
+
         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");
+        //servlets
+        context.addServlet(new ServletHolder(new MetricsServlet(bm)), "/metrics");
+        context.addServlet(new ServletHolder(new LogServlet(blurLogFile)), "/logs");
         
         LOG.info("WEB GUI coming up for resource: " + base);
         LOG.info("WEB GUI thinks its at: " + getJarFolder());
+        LOG.info("WEB GUI log file being exposed: " + blurLogFile);
         
         server.setHandler(context);
  
@@ -49,13 +73,9 @@ public class HttpJettyServer {
 	  private String getJarFolder() {
 		    String name = this.getClass().getName().replace('.', '/');
 		    String s = this.getClass().getResource("/" + name + ".class").toString();
-		    LOG.info("s: " + s);
 		    s = s.replace('/', File.separatorChar);
-		    LOG.info("s: " + s);
 		    s = s.substring(0, s.indexOf(".jar")+4);
-		    LOG.info("s: " + s);
 		    s = s.substring(s.lastIndexOf(':')+1);
-		    LOG.info("s: " + s);
 		    return s.substring(0, s.lastIndexOf(File.separatorChar)+1);
 		  } 
 	

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab40a9a3/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java
new file mode 100644
index 0000000..c1fc283
--- /dev/null
+++ b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/LogServlet.java
@@ -0,0 +1,80 @@
+package com.nearinfinity.blur.gui;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.RandomAccessFile;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+public class LogServlet extends HttpServlet {
+
+	private static final long serialVersionUID = 1L;
+	private String filePath = null;
+	private int buffLen = 8192;
+	
+	public LogServlet(String filePath) {
+		this.filePath = filePath;
+	}
+
+	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
+		
+		response.setContentType("text/html");
+		PrintWriter out = response.getWriter();
+		
+		File f = new File(filePath);
+		RandomAccessFile ram = new RandomAccessFile(f, "r");
+
+		String offsetStr = request.getParameter("offset");
+		long offset = -1;
+		if(offsetStr != null)
+			offset = Long.parseLong(offsetStr);
+
+		long start = 0;
+		long length = ram.length();
+		//figure out buffer
+		if(length < buffLen)
+			buffLen = new Long(length).intValue();
+		
+		//use offset if passed in
+		if(offset >= 0)
+			start = offset;
+		else
+			start = length - buffLen;
+
+		//calc new offset
+		offset = start - buffLen;
+		if(offset < 0)
+			offset = 0;
+		
+		//buffer
+		byte[] buff = new byte[buffLen];
+		
+		ram.seek(start);
+		ram.read(buff);
+		
+		String returnStr = new String(buff,"UTF-8").replaceAll("\n", "\n<br>");
+
+		out.write("<html><link href='style.css' rel='stylesheet' type='text/css' /><body>");
+		out.write("<a href='index.html'>home</a><br/>");
+		out.write("<p>File:<b> "+ f.toString() + "</b> (" + start + "/" + length
+ ")</p>");
+		if(start != 0) {
+			out.write("<a href='logs?offset=" + 0 + "'>start</a>");
+			out.write(" <a href='logs?offset=" + offset + "'>prev</a>");
+		}
+		if(start + buffLen < length) {
+			out.write(" <a href='logs?offset=" + (start+buffLen) + "'>next</a>");
+			out.write(" <a href='logs?offset=" + ((length-buffLen>0)?(length-buffLen):0) + "'>end</a>");
+		}
+		out.write("<br/>");
+		out.write(returnStr);
+		out.write("</body></html>");
+		
+		ram.close();
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/ab40a9a3/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java
new file mode 100644
index 0000000..b901128
--- /dev/null
+++ b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/MetricsServlet.java
@@ -0,0 +1,36 @@
+package com.nearinfinity.blur.gui;
+
+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 MetricsServlet extends HttpServlet {
+	
+	private static final long serialVersionUID = 1L;
+
+	private BlurMetrics bm = null;
+
+	public MetricsServlet() {
+	}
+
+	
+	public MetricsServlet(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/ab40a9a3/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
deleted file mode 100644
index f9e234a..0000000
--- a/src/blur-gui/src/main/java/com/nearinfinity/blur/shard/ShardMetricsServlet.java
+++ /dev/null
@@ -1,36 +0,0 @@
-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/ab40a9a3/src/blur-gui/src/main/webapps/controller/controller.jsp
----------------------------------------------------------------------
diff --git a/src/blur-gui/src/main/webapps/controller/controller.jsp b/src/blur-gui/src/main/webapps/controller/controller.jsp
index 55a0dc3..3800429 100644
--- a/src/blur-gui/src/main/webapps/controller/controller.jsp
+++ b/src/blur-gui/src/main/webapps/controller/controller.jsp
@@ -72,7 +72,7 @@
 	}%>
 <%
 	//TODO: prop file the port
-	String hostName = request.getServerName() + ":40010";
+	String hostName = request.getServerName() + ":" + System.getProperty("blur.gui.servicing.port");
 
 	Iface client = BlurClient.getClient(hostName);
 %>
@@ -109,7 +109,9 @@
 		</tr>
 		<%=getConf(client)%>
 	</table>
-
+	<hr />
+	<br />
+	<a href="logs">logs</a>
 </body>
 
 </html>


Mime
View raw message