incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject [56/58] git commit: Got the first graph working
Date Tue, 08 Oct 2013 18:00:04 GMT
Got the first graph working


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

Branch: refs/heads/blur-console-v2
Commit: de5eb337b3e67059ad75158c4f38e7836745af20
Parents: 7b116c1
Author: Chris Rohr <crohr@nearinfinity.com>
Authored: Fri Oct 4 08:18:21 2013 -0400
Committer: Chris Rohr <crohr@nearinfinity.com>
Committed: Fri Oct 4 08:18:21 2013 -0400

----------------------------------------------------------------------
 .../org/apache/blur/console/JettyServer.java    |   15 +-
 .../main/java/org/apache/blur/console/Main.java |    5 +-
 .../blur/console/servlets/DashboardServlet.java |   66 +
 .../org/apache/blur/console/util/Config.java    |  109 +
 .../org/apache/blur/console/webapp/index.html   |    4 +-
 .../org/apache/blur/console/webapp/js/app.js    |   32 +-
 .../apache/blur/console/webapp/js/dashboard.js  |   10 +-
 .../console/webapp/js/ui-bootstrap-0.6.0.js     | 3308 ------------------
 8 files changed, 229 insertions(+), 3320 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de5eb337/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java b/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
index 3b71436..e864639 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
@@ -2,15 +2,15 @@ package org.apache.blur.console;
 
 import java.net.URL;
 
+import org.apache.blur.console.servlets.DashboardServlet;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.webapp.WebAppContext;
 
 public class JettyServer {
-	// assumes that this directory contains .html and .jsp files
-	// This is just a directory within your source tree, and can be exported as
-	// part of your normal .jar
 	private final static String WEBAPPDIR = "org/apache/blur/console/webapp";
 	private final static String CONTEXTPATH = "/console";
 	private final Log log = LogFactory.getLog(JettyServer.class);
@@ -38,15 +38,14 @@ public class JettyServer {
 	private void createServer() {
 		server = new Server(port);
 		
-		// for localhost:port/admin/index.html and whatever else is in the webapp directory
+		// for localhost:port/console/index.html and whatever else is in the webapp directory
 	    final URL warUrl = this.getClass().getClassLoader().getResource(WEBAPPDIR);
 	    final String warUrlString = warUrl.toExternalForm();
 	    server.setHandler(new WebAppContext(warUrlString, CONTEXTPATH));
 	      
-	    // for localhost:port/servlets/cust, etc.
-//	    final Context context = new Context(server, "/servlets", Context.SESSIONS);
-//	    context.addServlet(new ServletHolder(), "/cust");
-//	    context.addServlet(new ServletHolder(new UserServlet(whatever)), "/user");
+	    // for localhost:port/service/dashboard, etc.
+	    final Context context = new Context(server, "/service", Context.SESSIONS);
+	    context.addServlet(new ServletHolder(new DashboardServlet()), "/dashboard/*");
 	      
 	    try {
 			server.start();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de5eb337/contrib/blur-console/src/main/java/org/apache/blur/console/Main.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/Main.java b/contrib/blur-console/src/main/java/org/apache/blur/console/Main.java
index 7600344..192f980 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/Main.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/Main.java
@@ -1,8 +1,11 @@
 package org.apache.blur.console;
 
+import org.apache.blur.console.util.Config;
+
 public class Main {
 	public static void main(String[] args) throws Exception {
-		JettyServer server = new JettyServer(8080).start();
+		Config.setupConfig();
+		JettyServer server = new JettyServer(Config.getConsolePort()).start();
 		server.join();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de5eb337/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java
b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java
new file mode 100644
index 0000000..dc24194
--- /dev/null
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/servlets/DashboardServlet.java
@@ -0,0 +1,66 @@
+package org.apache.blur.console.servlets;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.blur.console.util.Config;
+import org.apache.blur.thrift.BlurClient;
+import org.apache.blur.thrift.generated.Blur.Iface;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+public class DashboardServlet extends HttpServlet {
+	private static final long serialVersionUID = 6522056391102413432L;
+
+	@Override
+	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
+		String path = request.getPathInfo();
+		if ("/controllers/status".equalsIgnoreCase(path)) {
+			sendControllerStatus(response);
+		} else {
+			response.setStatus(404);
+			IOUtils.write("Route [" + path + "] doesn't exist", response.getOutputStream());
+		}
+	}
+
+	private void sendControllerStatus(HttpServletResponse response) throws IOException {
+		Iface client = BlurClient.getClient(StringUtils.join(Config.getControllers(), ","));
+		List<String> controllersFromBlur = new ArrayList<String>();
+		try {
+			controllersFromBlur = client.controllerServerList();
+		} catch (Exception e) {}
+		
+		int onlineControllers = CollectionUtils.intersection(Config.getControllers(), controllersFromBlur).size();
+		int offlineControllers = CollectionUtils.subtract(Config.getControllers(), controllersFromBlur).size();
+		
+		JSONArray data = new JSONArray();
+		
+		try {
+			JSONObject online = new JSONObject();
+			online.put("value", onlineControllers);
+			online.put("color", "#7DC77D");
+			
+			JSONObject offline = new JSONObject();
+			offline.put("value", offlineControllers);
+			offline.put("color", "#FF1919");
+			
+			data.put(online);
+			data.put(offline);
+		} catch (Exception e) {}
+		
+		String body = data.toString();
+		response.setContentType("application/json");
+		response.setContentLength(body.getBytes().length);
+		response.setStatus(200);
+		IOUtils.write(body, response.getOutputStream());
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de5eb337/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
new file mode 100644
index 0000000..5b797f0
--- /dev/null
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
@@ -0,0 +1,109 @@
+package org.apache.blur.console.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.Transformer;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+
+import com.google.common.collect.ImmutableList;
+
+public class Config {
+	private static List<String> controllers = new ArrayList<String>();
+	private static List<String> shards = new ArrayList<String>();
+	private static List<String> zookeepers = new ArrayList<String>();
+	
+	private static boolean foundSite = false;
+	private static int port = 8080;
+	
+	public static Collection<String> getControllers() {
+		return ImmutableList.copyOf(controllers);
+	}
+	public static Collection<String> getShards() {
+		return ImmutableList.copyOf(shards);
+	}
+	public static Collection<String> getZookeepers() {
+		return ImmutableList.copyOf(zookeepers);
+	}
+	public static boolean isBlurConfigured() {
+		return foundSite;
+	}
+	public static int getConsolePort() {
+		return port;
+	}
+	
+	public static void setupConfig() {
+		String blurHome = System.getenv("BLUR_HOME");
+		
+		if (StringUtils.isNotBlank(blurHome)) {
+			File blurHomeDir = new File(blurHome + "/conf/blur-site.properties");
+			if (blurHomeDir.exists()) {
+				foundSite = true;
+			}
+			
+			startTimer(blurHome);
+		}
+	}
+	
+	private static void startTimer(final String blurHome) {
+		Timer timer = new Timer("BlurSiteReader", true);
+		timer.scheduleAtFixedRate(new TimerTask() {
+			@Override
+			public void run() {
+				try {
+					List<String> tmpControllers = IOUtils.readLines(new FileInputStream(blurHome +
"/conf/controllers"));
+					List<String> tmpShards = IOUtils.readLines(new FileInputStream(blurHome + "/conf/shards"));
+					List<String> tmpZookeepers = IOUtils.readLines(new FileInputStream(blurHome +
"/conf/zookeepers"));
+					
+					removeComments(tmpControllers);
+					removeComments(tmpShards);
+					removeComments(tmpZookeepers);
+					
+					tmpControllers = new ArrayList<String>(fixPorts(tmpControllers, 40010));
+					
+					controllers = tmpControllers;
+					shards = tmpShards;
+					zookeepers = tmpZookeepers;
+					
+					Properties props = new Properties();
+					props.load(new FileInputStream(blurHome + "/conf/blur-site.properties"));
+					
+					port = Integer.parseInt(props.getProperty("blur.console.port", "8080"));
+				} catch (Exception e) {}
+				
+			}
+			
+			private void removeComments(List<String> list) {
+				CollectionUtils.filter(list, new Predicate() {
+					@Override
+					public boolean evaluate(Object line) {
+						return !StringUtils.startsWith((String) line, "#");
+					}
+				});
+			}
+			
+			@SuppressWarnings("unchecked")
+			private Collection<String> fixPorts(List<String> list, final int port) {
+				return CollectionUtils.collect(list, new Transformer() {
+					@Override
+					public Object transform(Object input) {
+						if (((String) input).indexOf(":") > 0) {
+							return input;
+						}
+						return input + ":" + port;
+					}
+				});
+			}
+		}, 0, TimeUnit.MINUTES.toMillis(2));
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de5eb337/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/index.html
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/index.html
b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/index.html
index dd1c55c..603806d 100644
--- a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/index.html
+++ b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/index.html
@@ -21,7 +21,8 @@
                         <div id="slow-query-warnings" class="alert alert-danger hidden">Warning</div>
                         <div class="row">
                             <div class="col-md-4">
-                                <h3>Controllers</h3>
+                                <h4>Controllers</h4>
+                                <canvas doughnutchart data="controllerData" width="200"
height="200"></canvas>
                             </div>
                             <div class="col-md-4">
                                 <h3>Shards</h3>
@@ -59,6 +60,7 @@
 		<script type="text/javascript" src="js/angular.js"></script>
 		<script type="text/javascript" src="js/ui-bootstrap-tpls-0.6.0.js"></script>
         <script type="text/javascript" src="js/Chart.js"></script>
+
         <script type="text/javascript" src="js/app.js"></script>
         <script type="text/javascript" src="js/dashboard.js"></script>
 	</body>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de5eb337/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/app.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/app.js
b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/app.js
index d155bdb..3cea194 100644
--- a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/app.js
+++ b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/app.js
@@ -1 +1,31 @@
-var blurApp = angular.module('blurApp', ['ui.bootstrap'])
\ No newline at end of file
+var blurApp = angular.module('blurApp', ['ui.bootstrap'])
+
+blurApp.chart = function (type) {
+    return {
+        restrict: "A",
+        scope: {
+            data: "=",
+            options: "=",
+            id: "@"
+        },
+        link: function ($scope, $elem) {
+            var ctx = $elem[0].getContext("2d");
+            var chart = new Chart(ctx);
+
+            $scope.$watch("data", function (newVal, oldVal) {
+                // if data not defined, exit
+                if (!newVal) return;
+
+                chart[type]($scope.data, $scope.options);
+            }, true);
+        }
+    }
+}
+
+/* Aliases for various chart types */
+blurApp.directive("linechart", function () { return blurApp.chart("Line"); });
+blurApp.directive("barchart", function () { return blurApp.chart("Bar"); });
+blurApp.directive("radarchart", function () { return blurApp.chart("Radar"); });
+blurApp.directive("polarchart", function () { return blurApp.chart("PolarArea"); });
+blurApp.directive("piechart", function () { return blurApp.chart("Pie"); });
+blurApp.directive("doughnutchart", function () { return blurApp.chart("Doughnut"); });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/de5eb337/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/dashboard.js
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/dashboard.js
b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/dashboard.js
index eb9d578..b651ee7 100644
--- a/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/dashboard.js
+++ b/contrib/blur-console/src/main/resources/org/apache/blur/console/webapp/js/dashboard.js
@@ -1,3 +1,11 @@
-blurApp.controller('DashboardCtrl', function($scope) {
+blurApp.controller('DashboardCtrl', function($scope, $http, $timeout) {
+    $scope.controllerData = [];
+    //$scope.shard
 
+    (function tick() {
+        $http.get('/service/dashboard/controllers/status').success(function (data) {
+            $scope.controllerData = data;
+            $timeout(tick, 10000);
+        });
+    })();
 })
\ No newline at end of file


Mime
View raw message