incubator-accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1188621 - in /incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor: Monitor.java servlets/BasicServlet.java
Date Tue, 25 Oct 2011 12:00:25 GMT
Author: ecn
Date: Tue Oct 25 12:00:25 2011
New Revision: 1188621

URL: http://svn.apache.org/viewvc?rev=1188621&view=rev
Log:
ACCUMULO-54: provide service even if zookeeper is down

Modified:
    incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
    incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java

Modified: incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java?rev=1188621&r1=1188620&r2=1188621&view=diff
==============================================================================
--- incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
(original)
+++ incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/Monitor.java
Tue Oct 25 12:00:25 2011
@@ -417,12 +417,6 @@ public class Monitor {
   private static long START_TIME;
   
   public void run(String[] args) {
-    try {
-      Accumulo.init("monitor");
-      Accumulo.enableTracing(Accumulo.getLocalAddress(args).toString(), "monitor");
-    } catch (UnknownHostException e) {
-      throw new RuntimeException(e);
-    }
     Monitor.START_TIME = System.currentTimeMillis();
     int port = ServerConfiguration.getSystemConfiguration().getPort(Property.MONITOR_PORT);
     EmbeddedWebServer server;
@@ -469,6 +463,14 @@ public class Monitor {
         
       }
     }), "Data fetcher").start();
+    
+    try {
+      Accumulo.init("monitor");
+      Accumulo.enableTracing(Accumulo.getLocalAddress(args).toString(), "monitor");
+    } catch (UnknownHostException e) {
+      throw new RuntimeException(e);
+    }
+    
   }
   
   public static MasterMonitorInfo getMmi() {

Modified: incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java?rev=1188621&r1=1188620&r2=1188621&view=diff
==============================================================================
--- incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java
(original)
+++ incubator/accumulo/trunk/src/server/src/main/java/org/apache/accumulo/server/monitor/servlets/BasicServlet.java
Tue Oct 25 12:00:25 2011
@@ -23,6 +23,7 @@ import java.io.UnsupportedEncodingExcept
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.util.Date;
+import java.util.TimerTask;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
@@ -34,12 +35,14 @@ import org.apache.accumulo.core.Constant
 import org.apache.accumulo.server.client.HdfsZooInstance;
 import org.apache.accumulo.server.monitor.LogService;
 import org.apache.accumulo.server.monitor.Monitor;
+import org.apache.accumulo.server.util.time.SimpleTimer;
 import org.apache.log4j.Logger;
 
 abstract public class BasicServlet extends HttpServlet {
   
   private static final long serialVersionUID = 1L;
   protected static final Logger log = Logger.getLogger(BasicServlet.class);
+  static String cachedInstanceName = null;
   
   abstract protected String getTitle(HttpServletRequest req);
   
@@ -86,6 +89,21 @@ abstract public class BasicServlet exten
         // ignore improperly formatted user cookie
       }
     }
+    synchronized(BasicServlet.class) {
+      // Learn our instance name asynchronously so we don't hang up if zookeeper is down
+      if (cachedInstanceName == null) {
+        SimpleTimer.getInstance().schedule(new TimerTask() {
+          @Override
+          public void run() {
+            synchronized (BasicServlet.class) {
+              if (cachedInstanceName == null) {
+                cachedInstanceName = HdfsZooInstance.getInstance().getInstanceName();
+              }
+            }
+          }
+        }, 1000);
+      }
+    }
     
     // BEGIN PAGE
     sb.append("<html>\n");
@@ -112,7 +130,7 @@ abstract public class BasicServlet exten
     sb.append("<div id='content-wrapper'>\n");
     sb.append("<div id='content'>\n");
     sb.append("<div id='header'><h1>").append(getTitle(req)).append("</h1></div>\n");
-    sb.append("<div id='subheader'>Instance&nbsp;Name:&nbsp;").append(HdfsZooInstance.getInstance().getInstanceName())
+    sb.append("<div id='subheader'>Instance&nbsp;Name:&nbsp;").append(cachedInstanceName)
         .append("&nbsp;&nbsp;&nbsp;Version:&nbsp;").append(Constants.VERSION).append("\n");
     sb.append("<br><span class='smalltext'>Instance&nbsp;ID:&nbsp;").append(HdfsZooInstance.getInstance().getInstanceID()).append("</span>\n");
     sb.append("<br><span class='smalltext'>").append(new Date().toString().replace("
", "&nbsp;")).append("</span></div>\n");



Mime
View raw message