incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Changes to make the jetty web server easier to reuse.
Date Wed, 28 May 2014 01:11:58 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 2e62b7fff -> 93f4b3cf6


Changes to make the jetty web server easier to reuse.


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

Branch: refs/heads/apache-blur-0.2
Commit: 93f4b3cf672f606044efca3496881d2b34897baf
Parents: 2e62b7f
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue May 27 21:12:13 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue May 27 21:12:13 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/thrift/BlurShardServer.java |  5 --
 .../blur/thrift/ThriftBlurControllerServer.java | 14 ++--
 .../blur/thrift/ThriftBlurShardServer.java      | 14 ++--
 .../org/apache/blur/gui/HttpJettyServer.java    | 69 ++++++++++----------
 blur-gui/src/main/webapp/WEB-INF/web.xml        |  2 +-
 .../org/apache/blur/utils/BlurConstants.java    |  1 +
 6 files changed, 44 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/93f4b3cf/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
index d7ab206..3ccd577 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
@@ -30,7 +30,6 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLongArray;
 
-import org.apache.blur.BlurConfiguration;
 import org.apache.blur.concurrent.Executors;
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
@@ -566,10 +565,6 @@ public class BlurShardServer extends TableAdmin implements Iface {
     _dataFetchThreadCount = dataFetchThreadCount;
   }
 
-  public void setConfiguration(BlurConfiguration conf) {
-    _configuration = conf;
-  }
-
   @Override
   public void setUser(User user) throws TException {
     ShardServerContext context = ShardServerContext.getShardServerContext();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/93f4b3cf/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurControllerServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurControllerServer.java
b/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurControllerServer.java
index cd06b6b..76897f6 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurControllerServer.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurControllerServer.java
@@ -36,9 +36,8 @@ import static org.apache.blur.utils.BlurConstants.BLUR_CONTROLLER_THRIFT_ACCEPT_
 import static org.apache.blur.utils.BlurConstants.BLUR_CONTROLLER_THRIFT_MAX_READ_BUFFER_BYTES;
 import static org.apache.blur.utils.BlurConstants.BLUR_CONTROLLER_THRIFT_SELECTOR_THREADS;
 import static org.apache.blur.utils.BlurConstants.BLUR_GUI_CONTROLLER_PORT;
-import static org.apache.blur.utils.BlurConstants.BLUR_GUI_SHARD_PORT;
+import static org.apache.blur.utils.BlurConstants.BLUR_HTTP_STATUS_RUNNING_PORT;
 import static org.apache.blur.utils.BlurConstants.BLUR_MAX_RECORDS_PER_ROW_FETCH_REQUEST;
-import static org.apache.blur.utils.BlurConstants.BLUR_SHARD_BIND_PORT;
 import static org.apache.blur.utils.BlurConstants.BLUR_THRIFT_MAX_FRAME_SIZE;
 import static org.apache.blur.utils.BlurConstants.BLUR_ZOOKEEPER_CONNECTION;
 import static org.apache.blur.utils.BlurConstants.BLUR_ZOOKEEPER_TIMEOUT;
@@ -176,14 +175,11 @@ public class ThriftBlurControllerServer extends ThriftServer {
 
     int baseGuiPort = Integer.parseInt(configuration.get(BLUR_GUI_CONTROLLER_PORT));
     final HttpJettyServer httpServer;
-    if (baseGuiPort > 0) {
+    if (baseGuiPort >= 0) {
       int webServerPort = baseGuiPort + serverIndex;
-      // TODO: this got ugly, there has to be a better way to handle all these
-      // params
-      // without reversing the mvn dependancy and making blur-gui on top.
-      httpServer = new HttpJettyServer(bindPort, webServerPort, configuration.getInt(BLUR_CONTROLLER_BIND_PORT,
-1),
-          configuration.getInt(BLUR_SHARD_BIND_PORT, -1), configuration.getInt(BLUR_GUI_CONTROLLER_PORT,
-1),
-          configuration.getInt(BLUR_GUI_SHARD_PORT, -1), "controller");
+      httpServer = new HttpJettyServer(HttpJettyServer.class, webServerPort);
+      int port = httpServer.getLocalPort();
+      configuration.setInt(BLUR_HTTP_STATUS_RUNNING_PORT, port);
     } else {
       httpServer = null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/93f4b3cf/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurShardServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurShardServer.java b/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurShardServer.java
index a46c1b5..cd39485 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurShardServer.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/ThriftBlurShardServer.java
@@ -18,10 +18,9 @@ package org.apache.blur.thrift;
  */
 import static org.apache.blur.utils.BlurConstants.BLUR_CLUSTER;
 import static org.apache.blur.utils.BlurConstants.BLUR_CLUSTER_NAME;
-import static org.apache.blur.utils.BlurConstants.BLUR_CONTROLLER_BIND_PORT;
 import static org.apache.blur.utils.BlurConstants.BLUR_CONTROLLER_REMOTE_FETCH_COUNT;
-import static org.apache.blur.utils.BlurConstants.BLUR_GUI_CONTROLLER_PORT;
 import static org.apache.blur.utils.BlurConstants.BLUR_GUI_SHARD_PORT;
+import static org.apache.blur.utils.BlurConstants.BLUR_HTTP_STATUS_RUNNING_PORT;
 import static org.apache.blur.utils.BlurConstants.BLUR_INDEXMANAGER_FACET_THREAD_COUNT;
 import static org.apache.blur.utils.BlurConstants.BLUR_INDEXMANAGER_MUTATE_THREAD_COUNT;
 import static org.apache.blur.utils.BlurConstants.BLUR_INDEXMANAGER_SEARCH_THREAD_COUNT;
@@ -106,7 +105,6 @@ import sun.misc.VM;
 
 public class ThriftBlurShardServer extends ThriftServer {
 
-  
   private static final Log LOG = LogFactory.getLog(ThriftBlurShardServer.class);
   private static final boolean enableJsonReporter = false;
   private static final long _64MB = 64 * 1024 * 1024;
@@ -152,12 +150,9 @@ public class ThriftBlurShardServer extends ThriftServer {
     final HttpJettyServer httpServer;
     if (baseGuiPort > 0) {
       int webServerPort = baseGuiPort + serverIndex;
-
-      // TODO: this got ugly, there has to be a better way to handle all these
-      // params without reversing the mvn dependancy and making blur-gui on top.
-      httpServer = new HttpJettyServer(bindPort, webServerPort, configuration.getInt(BLUR_CONTROLLER_BIND_PORT,
-1),
-          configuration.getInt(BLUR_SHARD_BIND_PORT, -1), configuration.getInt(BLUR_GUI_CONTROLLER_PORT,
-1),
-          configuration.getInt(BLUR_GUI_SHARD_PORT, -1), "shard");
+      httpServer = new HttpJettyServer(HttpJettyServer.class, webServerPort);
+      int port = httpServer.getLocalPort();
+      configuration.setInt(BLUR_HTTP_STATUS_RUNNING_PORT, port);
     } else {
       httpServer = null;
     }
@@ -250,7 +245,6 @@ public class ThriftBlurShardServer extends ThriftServer {
     shardServer.setZookeeper(zooKeeper);
     shardServer.setClusterStatus(clusterStatus);
     shardServer.setQueryChecker(queryChecker);
-    shardServer.setConfiguration(configuration);
     shardServer.setMaxRecordsPerRowFetchRequest(configuration.getInt(BLUR_MAX_RECORDS_PER_ROW_FETCH_REQUEST,
1000));
     shardServer.setConfiguration(configuration);
     shardServer.init();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/93f4b3cf/blur-gui/src/main/java/org/apache/blur/gui/HttpJettyServer.java
----------------------------------------------------------------------
diff --git a/blur-gui/src/main/java/org/apache/blur/gui/HttpJettyServer.java b/blur-gui/src/main/java/org/apache/blur/gui/HttpJettyServer.java
index cb8b16f..bb91868 100644
--- a/blur-gui/src/main/java/org/apache/blur/gui/HttpJettyServer.java
+++ b/blur-gui/src/main/java/org/apache/blur/gui/HttpJettyServer.java
@@ -22,6 +22,7 @@ import java.util.Properties;
 
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
+import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.mortbay.jetty.webapp.WebAppContext;
@@ -30,7 +31,6 @@ import com.yammer.metrics.reporting.MetricsServlet;
 
 /**
  * Starts up a Jetty server to run the utility gui.
- * 
  */
 public class HttpJettyServer {
 
@@ -40,52 +40,30 @@ public class HttpJettyServer {
 
   private WebAppContext context;
 
+  private int _localPort;
+
   /**
-   * @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
    */
-  public HttpJettyServer(int bindPort, int port, int baseControllerPort, int baseShardPort,
int baseGuiControllerPort,
-      int baseGuiShardPort, String base) throws IOException {
+  public HttpJettyServer(Class<?> c, int port) throws IOException {
     server = new Server(port);
-
     String logDir = System.getProperty("blur.logs.dir");
     String logFile = System.getProperty("blur.log.file");
     String blurLogFile = logDir + "/" + logFile;
-    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 + "");
-    System.setProperty("blur.gui.mode", base);
     LOG.info("System props:" + System.getProperties().toString());
 
     context = new WebAppContext();
-    String warPath = getWarFolder();
+    String warPath = getWarFolder(c);
     context.setWar(warPath);
     context.setContextPath("/");
     context.setParentLoaderPriority(true);
-    // context.addServlet(new ServletHolder(new LiveMetricsServlet()),
-    // "/livemetrics");
     context.addServlet(new ServletHolder(new MetricsServlet()), "/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: " + warPath);
-    LOG.info("WEB GUI log file being exposed: " + logDir == null ? "STDOUT" : blurLogFile);
+    LOG.info("Http server thinks its at: " + warPath);
+    LOG.info("Http server log file being exposed: " + logDir == null ? "STDOUT" : blurLogFile);
 
     server.setHandler(context);
 
@@ -97,9 +75,23 @@ public class HttpJettyServer {
       } catch (Exception ex) {
         LOG.error("Unknown error while trying to stop server during error on startup.", ex);
       }
-      throw new IOException("cannot start Http server for " + base, e);
+      throw new IOException("Cannot start Http server.", e);
     }
-    LOG.info("WEB GUI up on port: " + port);
+    for (int i = 0; i < 100; i++) {
+      if (server.isRunning()) {
+        break;
+      }
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
+        return;
+      }
+    }
+    Connector[] connectors = server.getConnectors();
+    for (Connector connector : connectors) {
+      _localPort = connector.getLocalPort();
+    }
+    LOG.info("Http server up on port: " + _localPort);
   }
 
   public WebAppContext getContext() {
@@ -118,21 +110,22 @@ public class HttpJettyServer {
     return null;
   }
 
-  private String getWarFolder() {
+  private String getWarFolder(Class<?> c) {
     String findBlurGuiInClassPath = findBlurGuiInClassPath();
     if (findBlurGuiInClassPath != null) {
       return findBlurGuiInClassPath;
     }
-    String name = getClass().getName().replace('.', '/');
+    String name = c.getName().replace('.', '/');
     String classResource = "/" + name + ".class";
-    String pathToClassResource = getClass().getResource(classResource).toString();
+    String pathToClassResource = c.getResource(classResource).toString();
     pathToClassResource = pathToClassResource.replace('/', File.separatorChar);
     int indexOfJar = pathToClassResource.indexOf(".jar");
     if (indexOfJar < 0) {
       int index = pathToClassResource.indexOf(name);
       String pathToClasses = pathToClassResource.substring(0, index);
-      int indexOfProjectName = pathToClasses.indexOf("/blur-gui/");
-      return pathToClasses.substring(0, indexOfProjectName) + "/blur-gui/src/main/webapp";
+      int indexOfProjectName = pathToClasses.indexOf("/target/");
+      String str = pathToClasses.substring(0, indexOfProjectName) + "/src/main/webapp";
+      return str;
     }
     return null;
   }
@@ -149,4 +142,8 @@ public class HttpJettyServer {
     }
   }
 
+  public int getLocalPort() {
+    return _localPort;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/93f4b3cf/blur-gui/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/blur-gui/src/main/webapp/WEB-INF/web.xml b/blur-gui/src/main/webapp/WEB-INF/web.xml
index 3d3f3b0..0740e28 100644
--- a/blur-gui/src/main/webapp/WEB-INF/web.xml
+++ b/blur-gui/src/main/webapp/WEB-INF/web.xml
@@ -21,5 +21,5 @@ under the License.
 	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>
+	<display-name>Blur YARN</display-name>
 </web-app>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/93f4b3cf/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
----------------------------------------------------------------------
diff --git a/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java b/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
index 197b89f..e8d406e 100644
--- a/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
+++ b/blur-util/src/main/java/org/apache/blur/utils/BlurConstants.java
@@ -155,6 +155,7 @@ public class BlurConstants {
   public static final String DEFAULT = "default";
   public static final String BLUR_CLUSTER_NAME = "blur.cluster.name";
   public static final String BLUR_CLUSTER;
+  public static final String BLUR_HTTP_STATUS_RUNNING_PORT = "blur.http.status.running.port";
 
   public static final long ZK_WAIT_TIME = TimeUnit.SECONDS.toMillis(5);
   public static final String DELETE_MARKER_VALUE = "delete";


Mime
View raw message