GUI for controller working and starting/stopping with Blur
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/5ae2318d Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/5ae2318d Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/5ae2318d Branch: refs/heads/master Commit: 5ae2318d6266c9615e7e2dd95f572bc0cb504618 Parents: 5c9f4b2 Author: gbarton <[email protected]> Authored: Mon Jul 30 16:47:29 2012 -0400 Committer: gbarton <[email protected]> Committed: Mon Jul 30 16:47:58 2012 -0400 ---------------------------------------------------------------------- src/blur-core/pom.xml | 5 + .../blur/thrift/ThriftBlurControllerServer.java | 5 + .../com/nearinfinity/blur/utils/BlurConstants.java | 3 + src/blur-gui/pom.xml | 148 + .../com/nearinfinity/blur/gui/HttpJettyServer.java | 70 + .../src/main/webapps/controller/WEB-INF/web.xml | 10 + .../src/main/webapps/controller/controller.jsp | 115 + src/blur-gui/src/main/webapps/controller/d3.v2.js | 9406 +++++++++++++++ .../src/main/webapps/controller/d3.v2.min.js | 4 + .../src/main/webapps/controller/functions.jsp | 25 + .../src/main/webapps/controller/index.html | 13 + .../src/main/webapps/controller/shardList.jsp | 55 + src/blur-gui/src/main/webapps/controller/style.css | 53 + src/blur-gui/src/main/webapps/controller/table.jsp | 147 + src/blur-testsuite/pom.xml | 74 +- .../blur/testsuite/CreateInsertQueryRepeating.java | 246 + .../src/main/resources/blur-default.properties | 3 + 17 files changed, 10349 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/5ae2318d/src/blur-core/pom.xml ---------------------------------------------------------------------- diff --git a/src/blur-core/pom.xml b/src/blur-core/pom.xml index 3586781..6da14c3 100644 --- a/src/blur-core/pom.xml +++ b/src/blur-core/pom.xml @@ -32,6 +32,11 @@ <version>0.1.3</version> </dependency> <dependency> + <groupId>com.nearinfinity.blur</groupId> + <artifactId>blur-gui</artifactId> + <version>0.1.3</version> + </dependency> + <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.3.4</version> http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/5ae2318d/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 8065fca..782204c 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 @@ -35,6 +35,8 @@ import static com.nearinfinity.blur.utils.BlurConstants.BLUR_CONTROLLER_SERVER_R import static com.nearinfinity.blur.utils.BlurConstants.BLUR_CONTROLLER_SERVER_THRIFT_THREAD_COUNT; 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; @@ -48,6 +50,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.manager.BlurQueryChecker; @@ -126,6 +129,8 @@ public class ThriftBlurControllerServer extends ThriftServer { server.setBindPort(bindPort); server.setThreadCount(threadCount); server.setIface(iface); + + HttpJettyServer httpServer = new HttpJettyServer(configuration.get(BLUR_GUI_CONTROLLER_PORT), "controller"); // 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/5ae2318d/src/blur-core/src/main/java/com/nearinfinity/blur/utils/BlurConstants.java ---------------------------------------------------------------------- diff --git a/src/blur-core/src/main/java/com/nearinfinity/blur/utils/BlurConstants.java b/src/blur-core/src/main/java/com/nearinfinity/blur/utils/BlurConstants.java index 4ff0fae..ec2c72a 100644 --- a/src/blur-core/src/main/java/com/nearinfinity/blur/utils/BlurConstants.java +++ b/src/blur-core/src/main/java/com/nearinfinity/blur/utils/BlurConstants.java @@ -86,6 +86,9 @@ public class BlurConstants { public static final String BLUR_CONTROLLER_RETRY_MAX_MUTATE_DELAY = "blur.controller.retry.max.mutate.delay"; public static final String BLUR_CONTROLLER_RETRY_MAX_DEFAULT_DELAY = "blur.controller.retry.max.default.delay"; public static final String BLUR_CONTROLLER_RETRY_MAX_FETCH_RETRIES = "blur.controller.retry.max.fetch.retries"; + + public static final String BLUR_GUI_CONTROLLER_PORT = "blur.gui.controller.port"; + public static final String BLUR_GUI_SHARD_PORT = "blur.gui.shard.port"; public static final String DEFAULT = "default"; public static final String BLUR_CLUSTER_NAME = "blur.cluster.name"; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/5ae2318d/src/blur-gui/pom.xml ---------------------------------------------------------------------- diff --git a/src/blur-gui/pom.xml b/src/blur-gui/pom.xml new file mode 100644 index 0000000..1fca209 --- /dev/null +++ b/src/blur-gui/pom.xml @@ -0,0 +1,148 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>com.nearinfinity.blur</groupId> + <artifactId>blur</artifactId> + <version>0.1.3</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>com.nearinfinity.blur</groupId> + <artifactId>blur-gui</artifactId> + <packaging>jar</packaging> + <name>Blur GUI</name> + + <properties> + <enableAssertions>false</enableAssertions> + </properties> + + <dependencies> + <dependency> + <groupId>javax.servlet.jsp</groupId> + <artifactId>jsp-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jsp-api-2.1-glassfish</artifactId> + <version>9.1.02.B04.p0</version> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jsp-2.1-glassfish</artifactId> + <version>9.1.02.B04.p0</version> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-webapp</artifactId> + <version>7.0.0.pre5</version> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty</artifactId> + <version>7.0.0.pre5</version> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-util</artifactId> + <version>7.0.0.pre5</version> + </dependency> + <dependency> + <groupId>com.nearinfinity.blur</groupId> + <artifactId>blur-thrift</artifactId> + <version>0.1.3</version> + </dependency> + <dependency> + <groupId>com.nearinfinity.blur</groupId> + <artifactId>blur-store</artifactId> + <version>0.1.2</version> + </dependency> + <dependency> + <groupId>com.nearinfinity.blur</groupId> + <artifactId>blur-util</artifactId> + <version>0.1.2</version> + </dependency> + <dependency> + <groupId>org.apache.zookeeper</groupId> + <artifactId>zookeeper</artifactId> + <version>3.3.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.15</version> + <scope>provided</scope> + <exclusions> + <exclusion> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + </exclusion> + <exclusion> + <groupId>javax.jms</groupId> + <artifactId>jms</artifactId> + </exclusion> + <exclusion> + <groupId>com.sun.jdmk</groupId> + <artifactId>jmxtools</artifactId> + </exclusion> + <exclusion> + <groupId>com.sun.jmx</groupId> + <artifactId>jmxri</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>libdir</id> + <url>file://${basedir}/../lib</url> + </repository> + </repositories> + + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0.2</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>2.2</version> + <executions> + <execution> + <id>copy-dependencies</id> + <phase>package</phase> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <outputDirectory>${project.build.directory}/../../../lib + </outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>false</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <excludeTransitive>true</excludeTransitive> + <excludeArtifactIds>junit,commons-cli,commons-logging,hadoop-core,slf4j-api + </excludeArtifactIds> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/5ae2318d/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 new file mode 100644 index 0000000..43b8181 --- /dev/null +++ b/src/blur-gui/src/main/java/com/nearinfinity/blur/gui/HttpJettyServer.java @@ -0,0 +1,70 @@ +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.webapp.WebAppContext; + +import com.nearinfinity.blur.BlurConfiguration; +import com.nearinfinity.blur.log.Log; +import com.nearinfinity.blur.log.LogFactory; + +/** + * Starts up a Jetty server to run the utility gui + * @author gman + * + */ +public class HttpJettyServer { + + private static final Log LOG = LogFactory.getLog(HttpJettyServer.class); + + private Server server = null; + + public HttpJettyServer(String port, String base) throws IOException { + server = new Server(Integer.parseInt(port)); + + WebAppContext context = new WebAppContext(); + context.setWar(getJarFolder() + "../src/blur-gui/src/main/webapps/" + base); + context.setContextPath("/"); + context.setParentLoaderPriority(true); + + LOG.info("WEB GUI coming up for resource: " + base); + LOG.info("WEB GUI thinks its at: " + getJarFolder()); + + server.setHandler(context); + + try { + server.start(); + } catch (Exception e) { + throw new IOException("cannot start Http server for " + base, e); + } + LOG.info("WEB GUI up on port: " + port); + } + + 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); + } + + public void close() { + if(server != null) + try { + LOG.info("stopping web server"); + server.stop(); + LOG.info("stopped web server"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/5ae2318d/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 new file mode 100644 index 0000000..311e084 --- /dev/null +++ b/src/blur-gui/src/main/webapps/controller/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/5ae2318d/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 new file mode 100644 index 0000000..55a0dc3 --- /dev/null +++ b/src/blur-gui/src/main/webapps/controller/controller.jsp @@ -0,0 +1,115 @@ +<%@ 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 Controller '<%=hostName%>' +</title> +<link href="style.css" rel="stylesheet" type="text/css" /> +</head> +<body> + <h1> + Blur Controller '<%=hostName%>' + </h1> + <br /> + <h2>Controllers</h2> + <%=table(getControllers(client),"Name","Online") %> + <hr /> + <br /> + <h2>Clusters</h2> + <%=table(getClusters(client),"Cluster Name","Shard Servers","Enabled") %> + <hr /> + <br /> + <h2>Tables</h2> + <%=table(getTables(client),"Cluster Name","Table Name","Enabled")%> + <hr /> + <br /> + <h2>Configs</h2> + <table class="statTable" class="statTableTitle"> + <tr> + <td class="statTableTitle">Param</td> + <td class="statTableTitle">Value</td> + </tr> + <%=getConf(client)%> + </table> + +</body> + +</html>
