hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject svn commit: r1496209 - in /hbase/branches/0.94/src: main/jamon/org/apache/hadoop/hbase/tmpl/master/ main/java/org/apache/hadoop/hbase/master/ test/java/org/apache/hadoop/hbase/master/
Date Mon, 24 Jun 2013 20:42:11 GMT
Author: larsh
Date: Mon Jun 24 20:42:11 2013
New Revision: 1496209

URL: http://svn.apache.org/r1496209
Log:
HBASE-5083 Backup HMaster should have http infoport open with link to the active master (Cody
Marcel)

Added:
    hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
Modified:
    hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/MasterStatusServlet.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java

Added: hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon?rev=1496209&view=auto
==============================================================================
--- hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
(added)
+++ hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/BackupMasterStatusTmpl.jamon
Mon Jun 24 20:42:11 2013
@@ -0,0 +1,77 @@
+<%doc>
+
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+</%doc>
+<%args>
+HMaster master;
+</%args>
+<%import>
+java.util.*;
+org.apache.hadoop.hbase.util.Bytes;
+org.apache.hadoop.hbase.ServerName;
+org.apache.hadoop.hbase.ClusterStatus;
+org.apache.hadoop.hbase.master.HMaster;
+org.apache.hadoop.hbase.master.ServerManager;
+org.apache.hadoop.hbase.master.AssignmentManager;
+org.apache.hadoop.hbase.master.ActiveMasterManager;
+</%import>
+<%java>
+Collection<ServerName> masters;
+
+if (master.isActiveMaster()) {
+    ClusterStatus status = master.getClusterStatus();
+    masters = status.getBackupMasters();
+} else{
+    ServerName sn = master.getActiveMasterManager().getActiveMaster() ;
+    assert sn != null : "Failed to retreive master's ServerName!";
+
+    List<ServerName> serverNames = new ArrayList<ServerName>(1);
+    serverNames.add(sn);
+    masters = Collections.unmodifiableCollection(serverNames);
+}
+</%java>
+
+<%java>
+ServerName [] serverNames = masters.toArray(new ServerName[masters.size()]);
+</%java>
+<%if (!master.isActiveMaster()) %>
+    <h2>Master</h2>
+    <a href="<% serverNames[0].getHostname() %>:<% master.getConfiguration().getInt("hbase.master.info.port",
60010) %>/master-status" target="_blank"><% serverNames[0].getHostname() %></a>
+<%else>
+    <h2>Backup Masters</h2>
+
+    <table class="table table-striped">
+    <tr>
+        <th>ServerName</th>
+        <th>Port</th>
+        <th>Start Time</th>
+    </tr>
+    <%java>
+    Arrays.sort(serverNames);
+    for (ServerName serverName: serverNames) {
+    </%java>
+    <tr>
+        <td><a href="<% serverName.getHostname() %>:<% master.getConfiguration().getInt("hbase.master.info.port",
60010) %>/master-status" target="_blank"><% serverName.getHostname() %></a></td>
+        <td><% serverName.getPort() %></td>
+        <td><% new Date(serverName.getStartcode()) %></td>
+    </tr>
+    <%java>
+    }
+    </%java>
+    <tr><td>Total:<% (masters != null) ? masters.size() : 0 %></td>
+    </table>
+</%if>

Modified: hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon?rev=1496209&r1=1496208&r2=1496209&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
(original)
+++ hbase/branches/0.94/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
Mon Jun 24 20:42:11 2013
@@ -28,6 +28,8 @@ Set<ServerName> deadServers = null;
 boolean showAppendWarning = false;
 String filter = "general";
 String format = "html";
+ServerManager serverManager = null;
+AssignmentManager assignmentManager = null;
 </%args>
 <%import>
 java.util.*;
@@ -36,6 +38,8 @@ org.apache.hadoop.hbase.util.Bytes;
 org.apache.hadoop.hbase.util.JvmVersion;
 org.apache.hadoop.hbase.util.FSUtils;
 org.apache.hadoop.hbase.master.HMaster;
+org.apache.hadoop.hbase.master.AssignmentManager;
+org.apache.hadoop.hbase.master.ServerManager;
 org.apache.hadoop.hbase.HConstants;
 org.apache.hadoop.hbase.HServerLoad;
 org.apache.hadoop.hbase.ServerName;
@@ -49,6 +53,11 @@ org.apache.hadoop.hbase.protobuf.generat
   <& ../common/TaskMonitorTmpl; filter = filter; format = "json" &>
   <%java return; %>
 </%if>
+<%java>
+ServerManager serverManager = master.getServerManager();
+AssignmentManager assignmentManager = master.getAssignmentManager();
+</%java>
+
 <?xml version="1.0" encoding="UTF-8" ?>
 <!-- Commenting out DOCTYPE so our blue outline shows on hadoop 0.20.205.0, etc.
      See tail of HBASE-2110 for explaination.
@@ -100,20 +109,23 @@ org.apache.hadoop.hbase.protobuf.generat
 <tr><td>Hadoop Version</td><td><% org.apache.hadoop.util.VersionInfo.getVersion()
%>, r<% org.apache.hadoop.util.VersionInfo.getRevision() %></td><td>Hadoop
version and revision</td></tr>
 <tr><td>Hadoop Compiled</td><td><% org.apache.hadoop.util.VersionInfo.getDate()
%>, <% org.apache.hadoop.util.VersionInfo.getUser() %></td><td>When Hadoop
version was compiled and by whom</td></tr>
 <tr><td>HBase Root Directory</td><td><% FSUtils.getRootDir(master.getConfiguration()).toString()
%></td><td>Location of HBase home directory</td></tr>
-<tr><td>HBase Cluster ID</td><td><% master.getClusterId() != null
? master.getClusterId() : "Not set" %><td>Unique identifier generated for each HBase
cluster</td></tr>
-<tr><td>Load average</td><td><% StringUtils.limitDecimalTo2(master.getServerManager().getAverageLoad())
%></td><td>Average number of regions per regionserver. Naive computation.</td></tr>
-<%if frags != null %>
-        <tr><td>Fragmentation</td><td><% frags.get("-TOTAL-")
!= null ? frags.get("-TOTAL-").intValue() + "%" : "n/a" %></td><td>Overall
fragmentation of all tables, including .META. and -ROOT-.</td></tr>
-</%if>
 <tr><td>Zookeeper Quorum</td><td><% master.getZooKeeperWatcher().getQuorum()
%></td><td>Addresses of all registered ZK servers. For more, see <a href="/zk.jsp">zk
dump</a>.</td></tr>
-<tr>
-  <td>
-   Coprocessors</td><td><% java.util.Arrays.toString(master.getCoprocessors())
%>
-  </td>
-  <td>Coprocessors currently loaded loaded by the master</td>
-</tr>
 <tr><td>HMaster Start Time</td><td><% new Date(master.getMasterStartTime())
%></td><td>Date stamp of when this HMaster was started</td></tr>
-<tr><td>HMaster Active Time</td><td><% new Date(master.getMasterActiveTime())
%></td><td>Date stamp of when this HMaster became active</td></tr>
+
+<%if master.isActiveMaster() %>
+  <tr><td>HMaster Active Time</td><td><% new Date(master.getMasterActiveTime())
%></td><td>Date stamp of when this HMaster became active</td></tr>
+  <tr><td>Load average</td><td><% StringUtils.limitDecimalTo2((serverManager
!= null) ? serverManager.getAverageLoad() : 0) %></td><td>Average number of
regions per regionserver. Naive computation.</td></tr>
+  <tr><td>HBase Cluster ID</td><td><% master.getClusterId() !=
null ? master.getClusterId() : "Not set" %><td>Unique identifier generated for each
HBase cluster</td></tr>
+  <%if frags != null %>
+          <tr><td>Fragmentation</td><td><% frags.get("-TOTAL-")
!= null ? frags.get("-TOTAL-").intValue() + "%" : "n/a" %></td><td>Overall
fragmentation of all tables, including .META. and -ROOT-.</td></tr>
+  </%if>
+  <tr>
+    <td>
+     Coprocessors</td><td><% java.util.Arrays.toString(master.getCoprocessors())
%>
+    </td>
+    <td>Coprocessors currently loaded loaded by the master</td>
+  </tr>
+</%if>
 </table>
 
 <& ../common/TaskMonitorTmpl; filter = filter &>
@@ -131,13 +143,16 @@ org.apache.hadoop.hbase.protobuf.generat
 <%if (deadServers != null) %>
 <& deadRegionServers &>
 </%if>
-
-<& AssignmentManagerStatusTmpl; assignmentManager=master.getAssignmentManager()&>
+<%if (assignmentManager != null) %>
+<& AssignmentManagerStatusTmpl; assignmentManager=assignmentManager&>
+</%if>
+<%if (master != null) %>
+    <& BackupMasterStatusTmpl; master = master &>
+</%if>
 
 </body>
 </html>
 
-
 <%def catalogTables>
 <h2>Tables</h2>
 <table>

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java?rev=1496209&r1=1496208&r2=1496209&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/ActiveMasterManager.java
Mon Jun 24 20:42:11 2013
@@ -23,16 +23,14 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.Server;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.monitoring.MonitoredTask;
-import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.zookeeper.ClusterStatusTracker;
 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperListener;
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.zookeeper.KeeperException;
-import org.apache.hadoop.hbase.zookeeper.ClusterStatusTracker;
 
 /**
  * Handles everything on master-side related to master election.
@@ -47,7 +45,7 @@ import org.apache.hadoop.hbase.zookeeper
  * #blockUntilBecomingActiveMaster() is called to wait until becoming
  * the active master of the cluster.
  */
-class ActiveMasterManager extends ZooKeeperListener {
+public class ActiveMasterManager extends ZooKeeperListener {
   private static final Log LOG = LogFactory.getLog(ActiveMasterManager.class);
 
   final AtomicBoolean clusterHasActiveMaster = new AtomicBoolean(false);
@@ -242,4 +240,25 @@ class ActiveMasterManager extends ZooKee
       LOG.error(this.watcher.prefix("Error deleting our own master address node"), e);
     }
   }
+
+  /**
+   * @return the ServerName for the current active master
+   */
+  public ServerName getActiveMaster() {
+    ServerName sn = null;
+    String msg;
+    try {
+      byte[] bytes = ZKUtil.getDataAndWatch(this.watcher, this.watcher.masterAddressZNode);
+      if (bytes == null) {
+        msg = "A master was detected, but went down before its address.";
+        LOG.info(msg);
+      } else {
+        sn = ServerName.parseVersionedServerName(bytes);
+      }
+    } catch (KeeperException e) {
+      msg = "Could not find active master";
+      LOG.info(msg);
+    }
+    return sn;
+  }
 }

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1496209&r1=1496208&r2=1496209&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Mon Jun
24 20:42:11 2013
@@ -100,9 +100,9 @@ import org.apache.hadoop.hbase.monitorin
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;
 import org.apache.hadoop.hbase.replication.regionserver.Replication;
+import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.snapshot.HSnapshotDescription;
 import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
-import org.apache.hadoop.hbase.security.User;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.FSTableDescriptors;
 import org.apache.hadoop.hbase.util.HFileArchiveUtil;
@@ -130,6 +130,7 @@ import org.apache.zookeeper.Watcher;
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.Maps;
 import com.google.common.collect.MutableClassToInstanceMap;
+import com.google.protobuf.ServiceException;
 
 /**
  * HMaster is the "master server" for HBase. An HBase cluster has one active
@@ -389,6 +390,18 @@ Server {
     masterStartTime = System.currentTimeMillis();
     try {
       this.registeredZKListenersBeforeRecovery = this.zooKeeper.getListeners();
+
+      // Put up info server.
+      int port = this.conf.getInt("hbase.master.info.port", 60010);
+      if (port >= 0) {
+        String a = this.conf.get("hbase.master.info.bindAddress", "0.0.0.0");
+        this.infoServer = new InfoServer(MASTER, a, port, false, this.conf);
+        this.infoServer.addServlet("status", "/master-status", MasterStatusServlet.class);
+        this.infoServer.addServlet("dump", "/dump", MasterDumpServlet.class);
+        this.infoServer.setAttribute(MASTER, this);
+        this.infoServer.start();
+      }
+
       /*
        * Block on becoming the active master.
        *
@@ -943,6 +956,10 @@ Server {
     return this.zooKeeper;
   }
 
+  public ActiveMasterManager getActiveMasterManager() {
+    return this.activeMasterManager;
+  }
+
   /*
    * Start up all services. If any of these threads gets an unhandled exception
    * then they just die with a logged message.  This should be fine because
@@ -982,17 +999,6 @@ Server {
         .getFileSystem(), archiveDir);
     Threads.setDaemonThreadRunning(hfileCleaner.getThread(), n + ".archivedHFileCleaner");
 
-   // Put up info server.
-   int port = this.conf.getInt("hbase.master.info.port", 60010);
-   if (port >= 0) {
-     String a = this.conf.get("hbase.master.info.bindAddress", "0.0.0.0");
-     this.infoServer = new InfoServer(MASTER, a, port, false, this.conf);
-     this.infoServer.addServlet("status", "/master-status", MasterStatusServlet.class);
-     this.infoServer.addServlet("dump", "/dump", MasterDumpServlet.class);
-     this.infoServer.setAttribute(MASTER, this);
-     this.infoServer.start();
-    }
-
    // Start the health checker
    if (this.healthCheckChore != null) {
      Threads.setDaemonThreadRunning(this.healthCheckChore.getThread(), n + ".healthChecker");
@@ -1551,7 +1557,7 @@ Server {
   }
 
   public String getClusterId() {
-    return fileSystemManager.getClusterId();
+    return (fileSystemManager == null) ? null : fileSystemManager.getClusterId();
   }
 
   /**
@@ -1583,9 +1589,12 @@ Server {
    * @return array of coprocessor SimpleNames.
    */
   public String[] getCoprocessors() {
-    Set<String> masterCoprocessors =
-        getCoprocessorHost().getCoprocessors();
-    return masterCoprocessors.toArray(new String[0]);
+    MasterCoprocessorHost cp = getCoprocessorHost();
+    String[] cpList = new String[0];
+    if (cp == null) return cpList;
+
+    Set<String> masterCoprocessors = cp.getCoprocessors();
+    return masterCoprocessors.toArray(cpList);
   }
 
   @Override

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/MasterStatusServlet.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/MasterStatusServlet.java?rev=1496209&r1=1496208&r2=1496209&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/MasterStatusServlet.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/master/MasterStatusServlet.java
Mon Jun 24 20:42:11 2013
@@ -20,7 +20,6 @@
 package org.apache.hadoop.hbase.master;
 
 import java.io.IOException;
-
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -34,8 +33,8 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.hbase.tmpl.master.MasterStatusTmpl;
+import org.apache.hadoop.hbase.util.FSUtils;
 
 /**
  * The servlet responsible for rendering the index page of the
@@ -54,13 +53,19 @@ public class MasterStatusServlet extends
     
     Configuration conf = master.getConfiguration();
     HBaseAdmin admin = new HBaseAdmin(conf);    
-        
+    ServerName metaLocation = null;
+    List<ServerName> servers = null;
+    Set<ServerName> deadServers = null;
+
     Map<String, Integer> frags = getFragmentationInfo(master, conf);
     
     ServerName rootLocation = getRootLocationOrNull(master);
-    ServerName metaLocation = master.getCatalogTracker().getMetaLocation();
-    List<ServerName> servers = master.getServerManager().getOnlineServersList();
-    Set<ServerName> deadServers = master.getServerManager().getDeadServers();
+
+    if (master.isActiveMaster()) {
+      metaLocation = master.getCatalogTracker().getMetaLocation();
+      servers = master.getServerManager().getOnlineServersList();
+      deadServers = master.getServerManager().getDeadServers();
+    }
 
     response.setContentType("text/html");
     MasterStatusTmpl tmpl = new MasterStatusTmpl()
@@ -80,7 +85,8 @@ public class MasterStatusServlet extends
 
   private ServerName getRootLocationOrNull(HMaster master) {
     try {
-      return master.getCatalogTracker().getRootLocation();
+      return (master.getCatalogTracker() == null) ? null : master.getCatalogTracker()
+          .getRootLocation();
     } catch (InterruptedException e) {
       LOG.warn("Unable to get root location", e);
       return null;

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java?rev=1496209&r1=1496208&r2=1496209&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/master/TestMasterStatusServlet.java
Mon Jun 24 20:42:11 2013
@@ -19,7 +19,8 @@
  */
 package org.apache.hadoop.hbase.master;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.io.StringWriter;
@@ -31,15 +32,17 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.MediumTests;
+import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
-import org.apache.hadoop.hbase.master.HMaster;
-import org.apache.hadoop.hbase.master.ServerManager;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.hadoop.hbase.tmpl.master.AssignmentManagerStatusTmpl;
 import org.apache.hadoop.hbase.tmpl.master.MasterStatusTmpl;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -73,6 +76,11 @@ public class TestMasterStatusServlet {
     Mockito.doReturn(FAKE_HOST).when(master).getServerName();
     Mockito.doReturn(conf).when(master).getConfiguration();
     
+    // Fake ActiveMasterManager
+    ActiveMasterManager amm = Mockito.mock(ActiveMasterManager.class);
+    Mockito.doReturn(amm).when(master).getActiveMasterManager();
+    Mockito.doReturn(FAKE_HOST).when(amm).getActiveMaster();
+
     // Fake serverManager
     ServerManager serverManager = Mockito.mock(ServerManager.class);
     Mockito.doReturn(1.0).when(serverManager).getAverageLoad();



Mime
View raw message