hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1293417 - in /hbase/branches/0.92: ./ src/main/java/org/apache/hadoop/hbase/master/ src/main/java/org/apache/hadoop/hbase/regionserver/ src/test/java/org/apache/hadoop/hbase/master/ src/test/java/org/apache/hadoop/hbase/regionserver/
Date Fri, 24 Feb 2012 21:08:41 GMT
Author: stack
Date: Fri Feb 24 21:08:40 2012
New Revision: 1293417

URL: http://svn.apache.org/viewvc?rev=1293417&view=rev
Log:
HBASE-5325 Expose basic information about the master-status through jmx beans

Added:
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBean.java
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBean.java
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBeanImpl.java
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestMXBean.java
    hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/regionserver/TestMXBean.java
Modified:
    hbase/branches/0.92/CHANGES.txt
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Modified: hbase/branches/0.92/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/CHANGES.txt?rev=1293417&r1=1293416&r2=1293417&view=diff
==============================================================================
--- hbase/branches/0.92/CHANGES.txt (original)
+++ hbase/branches/0.92/CHANGES.txt Fri Feb 24 21:08:40 2012
@@ -56,6 +56,8 @@ Release 0.92.1 - Unreleased
    HBASE-5209  HConnection/HMasterInterface should allow for way to get
                hostname of currently active master in multi-master HBase
                setup (David S. Wang)
+   HBASE-5325  Expose basic information about the master-status through
+               jmx beans (Hitesh Shah)
 
   TESTS
    HBASE-5223  TestMetaReaderEditor is missing call to CatalogTracker.stop()

Modified: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java?rev=1293417&r1=1293416&r2=1293417&view=diff
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
(original)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
Fri Feb 24 21:08:40 2012
@@ -3048,6 +3048,10 @@ public class AssignmentManager extends Z
       return region;
     }
 
+    public ServerName getServerName() {
+      return serverName;
+    }
+
     public boolean isClosing() {
       return state == State.CLOSING;
     }

Modified: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1293417&r1=1293416&r2=1293417&view=diff
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Fri Feb
24 21:08:40 2012
@@ -37,6 +37,8 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 
+import javax.management.ObjectName;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -69,7 +71,6 @@ import org.apache.hadoop.hbase.ipc.HMast
 import org.apache.hadoop.hbase.ipc.HMasterRegionInterface;
 import org.apache.hadoop.hbase.ipc.ProtocolSignature;
 import org.apache.hadoop.hbase.ipc.RpcServer;
-import org.apache.hadoop.hbase.master.CatalogJanitor.SplitParentFirstComparator;
 import org.apache.hadoop.hbase.master.handler.CreateTableHandler;
 import org.apache.hadoop.hbase.master.handler.DeleteTableHandler;
 import org.apache.hadoop.hbase.master.handler.DisableTableHandler;
@@ -101,6 +102,7 @@ import org.apache.hadoop.hbase.zookeeper
 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.hadoop.io.MapWritable;
 import org.apache.hadoop.io.Text;
+import org.apache.hadoop.metrics.util.MBeanUtil;
 import org.apache.hadoop.net.DNS;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.Watcher;
@@ -123,7 +125,8 @@ import org.apache.zookeeper.Watcher;
  * @see Watcher
  */
 public class HMaster extends HasThread
-implements HMasterInterface, HMasterRegionInterface, MasterServices, Server {
+implements HMasterInterface, HMasterRegionInterface, MasterServices,
+Server {
   private static final Log LOG = LogFactory.getLog(HMaster.class.getName());
 
   // MASTER is name of the webapp and the attribute name used stuffing this
@@ -203,6 +206,11 @@ implements HMasterInterface, HMasterRegi
   private long masterActiveTime;
   
   /**
+   * MX Bean for MasterInfo
+   */
+  private ObjectName mxBean = null;
+
+  /**
    * Initializes the HMaster. The steps are as follows:
    * <p>
    * <ol>
@@ -516,6 +524,8 @@ implements HMasterInterface, HMasterRegi
     this.catalogJanitorChore = new CatalogJanitor(this, this);
     Threads.setDaemonThreadRunning(catalogJanitorChore.getThread());
 
+    registerMBean();
+
     status.markComplete("Initialization successful");
     LOG.info("Master has completed initialization");
     initialized = true;
@@ -1213,6 +1223,7 @@ implements HMasterInterface, HMasterRegi
       this.assignmentManager.clearRegionFromTransition(hri);
     }
   }
+
   /**
    * @return cluster status
    */
@@ -1270,7 +1281,7 @@ implements HMasterInterface, HMasterRegi
   public long getMasterActiveTime() {
     return masterActiveTime;
   }
-  
+
   /**
    * @return array of coprocessor SimpleNames.
    */
@@ -1413,6 +1424,7 @@ implements HMasterInterface, HMasterRegi
     return rsFatals;
   }
 
+  @SuppressWarnings("deprecation")
   @Override
   public void shutdown() {
     if (cpHost != null) {
@@ -1422,6 +1434,10 @@ implements HMasterInterface, HMasterRegi
         LOG.error("Error call master coprocessor preShutdown()", ioe);
       }
     }
+    if (mxBean != null) {
+      MBeanUtil.unregisterMBean(mxBean);
+      mxBean = null;
+    }
     this.assignmentManager.shutdown();
     this.serverManager.shutdownCluster();
     try {
@@ -1620,4 +1636,14 @@ implements HMasterInterface, HMasterRegi
 	VersionInfo.logVersion();
     new HMasterCommandLine(HMaster.class).doMain(args);
   }
+
+  /**
+   * Register bean with platform management server
+   */
+  @SuppressWarnings("deprecation")
+  void registerMBean() {
+    MXBeanImpl mxBeanInfo = MXBeanImpl.init(this);
+    MBeanUtil.registerMBean("org.apache.hbase", "Master", mxBeanInfo);
+    LOG.info("Registered HMaster MXBean");
+  }
 }

Added: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBean.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBean.java?rev=1293417&view=auto
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBean.java (added)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBean.java Fri Feb 24
21:08:40 2012
@@ -0,0 +1,118 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.hbase.master;
+
+import java.util.Map;
+
+import org.apache.hadoop.classification.InterfaceStability.Evolving;
+import org.apache.hadoop.hbase.HServerLoad;
+
+/**
+ * This is the JMX management interface for Hbase master information
+ */
+@Evolving
+public interface MXBean {
+
+  /**
+   * Required for MXBean implementation
+   */
+  public static interface RegionsInTransitionInfo {
+    /**
+     * Name of region in transition
+     */
+    public String getRegionName();
+    /**
+     * Current transition state
+     */
+    public String getRegionState();
+    /**
+     * Get Region Server name
+     */
+    public String getRegionServerName();
+    /**
+     * Get last update time
+     */
+    public long getLastUpdateTime();
+  }
+
+  /**
+   * Get ServerName
+   */
+  public String getServerName();
+
+  /**
+   * Get Average Load
+   * @return Average Load
+   */
+  public double getAverageLoad();
+
+  /**
+   * Get the Cluster ID
+   * @return Cluster ID
+   */
+  public String getClusterId();
+
+  /**
+   * Get the Zookeeper Quorum Info
+   * @return Zookeeper Quorum Info
+   */
+  public String getZookeeperQuorum();
+
+  /**
+   * Get the co-processors
+   * @return Co-processors
+   */
+  public String[] getCoprocessors();
+
+  /**
+   * Get hbase master start time
+   * @return Start time of master in milliseconds
+   */
+  public long getMasterStartTime();
+
+  /**
+   * Get the hbase master active time
+   * @return Time in milliseconds when master became active
+   */
+  public long getMasterActiveTime();
+
+  /**
+   * Whether this master is the active master
+   * @return True if this is the active master
+   */
+  public boolean getIsActiveMaster();
+
+  /**
+   * Get the live region servers
+   * @return Live region servers
+   */
+  public Map<String, HServerLoad> getRegionServers();
+
+  /**
+   * Get the dead region servers
+   * @return Dead region Servers
+   */
+  public String[] getDeadRegionServers();
+
+  /**
+   * Get information on regions in transition
+   * @return Regions in transition
+   */
+  public RegionsInTransitionInfo[] getRegionsInTransition();
+
+}

Added: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java?rev=1293417&view=auto
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java (added)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/master/MXBeanImpl.java Fri Feb
24 21:08:40 2012
@@ -0,0 +1,150 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.hbase.master;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.hadoop.hbase.HServerLoad;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.master.AssignmentManager.RegionState;
+
+/**
+ * Impl for exposing HMaster Information through JMX
+ */
+public class MXBeanImpl implements MXBean {
+
+  private final HMaster master;
+
+  private static MXBeanImpl instance = null;
+  public synchronized static MXBeanImpl init(final HMaster master) {
+    if (instance == null) {
+      instance = new MXBeanImpl(master);
+    }
+    return instance;
+  }
+
+  protected MXBeanImpl(final HMaster master) {
+    this.master = master;
+  }
+
+  @Override
+  public double getAverageLoad() {
+    return master.getAverageLoad();
+  }
+
+  @Override
+  public String getClusterId() {
+    return master.getClusterId();
+  }
+
+  @Override
+  public String getZookeeperQuorum() {
+    return master.getZooKeeperWatcher().getQuorum();
+  }
+
+  @Override
+  public String[] getCoprocessors() {
+    return master.getCoprocessors();
+  }
+
+  @Override
+  public long getMasterStartTime() {
+    return master.getMasterStartTime();
+  }
+
+  @Override
+  public long getMasterActiveTime() {
+    return master.getMasterActiveTime();
+  }
+
+  @Override
+  public Map<String, HServerLoad> getRegionServers() {
+    Map<String, HServerLoad> data = new HashMap<String, HServerLoad>();
+    for (final Entry<ServerName, HServerLoad> entry :
+      master.getServerManager().getOnlineServers().entrySet()) {
+      data.put(entry.getKey().getServerName(),
+          entry.getValue());
+    }
+    return data;
+  }
+
+  @Override
+  public String[] getDeadRegionServers() {
+    List<String> deadServers = new ArrayList<String>();
+    for (ServerName name : master.getServerManager().getDeadServers()) {
+      deadServers.add(name.getHostAndPort());
+    }
+    return deadServers.toArray(new String[0]);
+  }
+
+  @Override
+  public RegionsInTransitionInfo[] getRegionsInTransition() {
+    List<RegionsInTransitionInfo> info =
+        new ArrayList<RegionsInTransitionInfo>();
+    for (final Entry<String, RegionState> entry :
+      master.getAssignmentManager().getRegionsInTransition().entrySet()) {
+      RegionsInTransitionInfo innerinfo = new RegionsInTransitionInfo() {
+
+        @Override
+        public String getRegionState() {
+          return entry.getValue().getState().toString();
+        }
+
+        @Override
+        public String getRegionName() {
+          return entry.getKey();
+        }
+
+        @Override
+        public long getLastUpdateTime() {
+          return entry.getValue().getStamp();
+        }
+
+        @Override
+        public String getRegionServerName() {
+          ServerName serverName = entry.getValue().getServerName();
+          if (serverName != null) {
+            return serverName.getServerName();
+          }
+          else {
+            return "";
+          }
+        }
+      };
+      info.add(innerinfo);
+    }
+    RegionsInTransitionInfo[] data =
+        new RegionsInTransitionInfo[info.size()];
+    info.toArray(data);
+    return data;
+  }
+
+  @Override
+  public String getServerName() {
+    return master.getServerName().getServerName();
+  }
+
+  @Override
+  public boolean getIsActiveMaster() {
+    return master.isActiveMaster();
+  }
+}

Modified: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1293417&r1=1293416&r2=1293417&view=diff
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Fri Feb 24 21:08:40 2012
@@ -49,6 +49,8 @@ import java.util.concurrent.atomic.Atomi
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import javax.management.ObjectName;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -144,6 +146,7 @@ import org.apache.hadoop.hbase.zookeeper
 import org.apache.hadoop.io.MapWritable;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.ipc.RemoteException;
+import org.apache.hadoop.metrics.util.MBeanUtil;
 import org.apache.hadoop.net.DNS;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.zookeeper.KeeperException;
@@ -326,6 +329,11 @@ public class HRegionServer implements HR
   private static final String CLOSE = "CLOSE";
 
   /**
+   * MX Bean for RegionServerInfo
+   */
+  private ObjectName mxBean = null;
+
+  /**
    * Starts a HRegionServer at the default location
    *
    * @param conf
@@ -619,6 +627,7 @@ public class HRegionServer implements HR
   /**
    * The HRegionServer sticks in this loop until closed.
    */
+  @SuppressWarnings("deprecation")
   public void run() {
     try {
       // Do pre-registration initializations; zookeeper, lease threads, etc.
@@ -640,6 +649,7 @@ public class HRegionServer implements HR
           break;
         }
       }
+      registerMBean();
 
       // We registered with the Master.  Go into run mode.
       long lastMsg = 0;
@@ -686,6 +696,10 @@ public class HRegionServer implements HR
       }
     }
     // Run shutdown.
+    if (mxBean != null) {
+      MBeanUtil.unregisterMBean(mxBean);
+      mxBean = null;
+    }
     this.leases.closeAfterLeasesExpire();
     this.rpcServer.stop();
     if (this.splitLogWorker != null) {
@@ -3254,4 +3268,16 @@ public class HRegionServer implements HR
     HServerLoad hsl = buildServerLoad();
     return hsl == null? null: hsl.getCoprocessors();
   }
+
+  /**
+   * Register bean with platform management server
+   */
+  @SuppressWarnings("deprecation")
+  void registerMBean() {
+    MXBeanImpl mxBeanInfo = MXBeanImpl.init(this);
+    mxBean = MBeanUtil.registerMBean("org.apache.hbase", "RegionServer",
+        mxBeanInfo);
+    LOG.info("Registered RegionServer MXBean");
+  }
+
 }

Added: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBean.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBean.java?rev=1293417&view=auto
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBean.java (added)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBean.java Fri
Feb 24 21:08:40 2012
@@ -0,0 +1,46 @@
+/**
+ * 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.
+ */
+
+package org.apache.hadoop.hbase.regionserver;
+
+import org.apache.hadoop.classification.InterfaceStability.Evolving;
+
+/**
+ * This is the JMX management interface for HBase Region Server information
+ */
+@Evolving
+public interface MXBean {
+
+  /**
+   * Return RegionServer's ServerName
+   * @return ServerName
+   */
+  public String getServerName();
+
+  /**
+   * Get loaded co-processors
+   * @return Loaded Co-processors
+   */
+  public String[] getCoprocessors();
+
+  /**
+   * Get Zookeeper Quorum
+   * @return Comma-separated list of Zookeeper Quorum servers
+   */
+  public String getZookeeperQuorum();
+}

Added: hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBeanImpl.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBeanImpl.java?rev=1293417&view=auto
==============================================================================
--- hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBeanImpl.java
(added)
+++ hbase/branches/0.92/src/main/java/org/apache/hadoop/hbase/regionserver/MXBeanImpl.java
Fri Feb 24 21:08:40 2012
@@ -0,0 +1,54 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.hbase.regionserver;
+
+/**
+ * Impl for exposing Region Server Information through JMX
+ */
+public class MXBeanImpl implements MXBean {
+
+  private final HRegionServer regionServer;
+
+  private static MXBeanImpl instance = null;
+  public synchronized static MXBeanImpl init(final HRegionServer rs){
+    if (instance == null) {
+      instance = new MXBeanImpl(rs);
+    }
+    return instance;
+  }
+
+  protected MXBeanImpl(final HRegionServer rs) {
+    this.regionServer = rs;
+  }
+
+  @Override
+  public String[] getCoprocessors() {
+    return regionServer.getCoprocessors();
+  }
+
+  @Override
+  public String getZookeeperQuorum() {
+    return regionServer.getZooKeeper().getQuorum();
+  }
+
+  @Override
+  public String getServerName() {
+    return regionServer.getServerName().getServerName();
+  }
+
+}

Added: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestMXBean.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestMXBean.java?rev=1293417&view=auto
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestMXBean.java (added)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/master/TestMXBean.java Fri Feb
24 21:08:40 2012
@@ -0,0 +1,95 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.hbase.master;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HServerLoad;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestMXBean {
+
+  private static final HBaseTestingUtility TEST_UTIL =
+      new HBaseTestingUtility();
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    TEST_UTIL.startMiniCluster(1, 4);
+  }
+
+  @AfterClass
+  public static void teardown() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  private void verifyRegionServers(Map<String, HServerLoad> regions) {
+    Set<String> expected = new HashSet<String>();
+    for (int i = 0; i < 4; ++i) {
+      HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(i);
+      expected.add(rs.getServerName().getServerName());
+    }
+
+    int found = 0;
+    for (java.util.Map.Entry<String, HServerLoad> entry : regions.entrySet()) {
+      if (expected.contains(entry.getKey())) {
+        ++found;
+      }
+    }
+    Assert.assertEquals(4, found);
+  }
+
+  @Test
+  public void testInfo() {
+    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
+    MXBeanImpl info = MXBeanImpl.init(master);
+    Assert.assertEquals(master.getAverageLoad(), info.getAverageLoad());
+    Assert.assertEquals(master.getClusterId(), info.getClusterId());
+    Assert.assertEquals(master.getMasterActiveTime(),
+        info.getMasterActiveTime());
+    Assert.assertEquals(master.getMasterStartTime(),
+        info.getMasterStartTime());
+    Assert.assertEquals(master.getCoprocessors().length,
+        info.getCoprocessors().length);
+    Assert.assertEquals(master.getServerManager().getOnlineServersList().size(),
+        info.getRegionServers().size());
+    Assert.assertEquals(master.getAssignmentManager().isRegionsInTransition(),
+        info.getRegionsInTransition().length > 0);
+    Assert.assertTrue(info.getRegionServers().size() == 4);
+
+    String zkServers = info.getZookeeperQuorum();
+    Assert.assertEquals(zkServers.split(",").length,
+        TEST_UTIL.getZkCluster().getZooKeeperServerNum());
+
+    verifyRegionServers(info.getRegionServers());
+
+    TEST_UTIL.getMiniHBaseCluster().stopRegionServer(3, false);
+    TEST_UTIL.getMiniHBaseCluster().waitOnRegionServer(3);
+    Assert.assertTrue(info.getRegionServers().size() == 3);
+    Assert.assertTrue(info.getDeadRegionServers().length == 1);
+
+  }
+
+}

Added: hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/regionserver/TestMXBean.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/regionserver/TestMXBean.java?rev=1293417&view=auto
==============================================================================
--- hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/regionserver/TestMXBean.java
(added)
+++ hbase/branches/0.92/src/test/java/org/apache/hadoop/hbase/regionserver/TestMXBean.java
Fri Feb 24 21:08:40 2012
@@ -0,0 +1,58 @@
+/**
+ * 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.
+ */
+package org.apache.hadoop.hbase.regionserver;
+
+import junit.framework.Assert;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.master.HMaster;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestMXBean {
+
+  private static final HBaseTestingUtility TEST_UTIL =
+      new HBaseTestingUtility();
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    TEST_UTIL.startMiniCluster(1, 1);
+  }
+
+  @AfterClass
+  public static void teardown() throws Exception {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  @Test
+  public void testInfo() {
+    HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
+    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
+    MXBeanImpl info = MXBeanImpl.init(rs);
+
+    Assert.assertEquals(rs.getServerName().getServerName(),
+        info.getServerName());
+    Assert.assertEquals(rs.getCoprocessors().length,
+        info.getCoprocessors().length);
+    rs.getConfiguration().setInt("hbase.master.info.port",
+      master.getServerName().getPort());
+    Assert.assertEquals(rs.getZooKeeperWatcher().getQuorum(),
+        info.getZookeeperQuorum());
+  }
+}



Mime
View raw message