hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1077674 - in /hadoop/common/branches/branch-0.20-security-patches/src: hdfs/org/apache/hadoop/hdfs/server/datanode/ hdfs/org/apache/hadoop/hdfs/server/namenode/ test/org/apache/hadoop/hdfs/server/datanode/ test/org/apache/hadoop/hdfs/serve...
Date Fri, 04 Mar 2011 04:42:53 GMT
Author: omalley
Date: Fri Mar  4 04:42:53 2011
New Revision: 1077674

URL: http://svn.apache.org/viewvc?rev=1077674&view=rev
Log:
commit 2e2e5f72b9b2348f3dce87a39f586522fe12e5a4
Author: Tanping Wang <tanping@yahoo-inc.com>
Date:   Mon Sep 13 18:30:08 2010 -0700

    [] using the unified way to register/unregister namenode datanode info MXBean

Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
    hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
    hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java
    hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java

Modified: hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java?rev=1077674&r1=1077673&r2=1077674&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/datanode/DataNode.java
Fri Mar  4 04:42:53 2011
@@ -97,6 +97,7 @@ import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.ipc.RemoteException;
 import org.apache.hadoop.ipc.Server;
 import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.util.MBeans;
 import org.apache.hadoop.net.DNS;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.security.SecurityUtil;
@@ -113,12 +114,8 @@ import org.apache.hadoop.util.DiskChecke
 import org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException;
 import org.mortbay.util.ajax.JSON;
 
-import java.lang.management.ManagementFactory;  
-
 import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
 import javax.management.MBeanRegistrationException;
-import javax.management.MBeanServer; 
 import javax.management.ObjectName;
 
 /**********************************************************
@@ -237,8 +234,6 @@ public class DataNode extends Configured
 
   private SecureResources secureResources = null;
   
-  private ObjectName mxBeanName = null;
-  
   /**
    * Current system time.
    * @return current time in msec.
@@ -364,7 +359,7 @@ public class DataNode extends Configured
     }
       
     // register datanode MXBean
-    registerMXBean();
+    this.registerMXBean(conf); // register the MXBean for DataNode
     
     // find free port or use privileged port provide
     ServerSocket ss;
@@ -466,34 +461,22 @@ public class DataNode extends Configured
 
     LOG.info("dnRegistration = " + dnRegistration);
   }
-
-  private void registerMXBean() {
-    // register MXBean
-    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
-    if (mxBeanName == null) {
-      try {
-        mxBeanName = new ObjectName("HadoopInfo:type=DataNodeInfo");
-        mbs.registerMBean(this, mxBeanName);
-      } catch ( javax.management.JMException e ) {
-        LOG.warn("Failed to register DataNodeMXBean", e);
-      }
-    }
+  
+  private ObjectName mxBean = null;
+  /**
+   * Register the DataNode MXBean using the name
+   *        "hadoop:service=DataNode,name=DataNodeInfo"
+   */
+  void registerMXBean(Configuration conf) {
+    // We wrap to bypass standard mbean naming convention.
+    // This wraping can be removed in java 6 as it is more flexible in 
+    // package naming for mbeans and their impl.
+    mxBean = MBeans.register("DataNode", "DataNodeInfo", this);
   }
   
-  private void unRegisterMXBean() {
-    if (mxBeanName == null)
-      return;
-    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
-    if (mbs.isRegistered(mxBeanName)){
-      try {
-        mbs.unregisterMBean(mxBeanName);
-      } catch (InstanceNotFoundException e ) {
-        LOG.warn(mxBeanName, e);
-      } catch (javax.management.JMException e) {
-        LOG.warn("Error unregistering "+ mxBeanName, e);
-      }
-      mxBeanName = null;
-    }
+  public void unRegisterMXBean() {
+    if (mxBean != null)
+      MBeans.unregister(mxBean);
   }
   
   /**

Modified: hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java?rev=1077674&r1=1077673&r2=1077674&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java
Fri Mar  4 04:42:53 2011
@@ -49,8 +49,6 @@ import java.util.TreeSet;
 import java.util.Map.Entry;
 import java.util.concurrent.TimeUnit;
 
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanServer;
 import javax.management.NotCompliantMBeanException;
 import javax.management.ObjectName;
 import javax.management.StandardMBean;
@@ -344,8 +342,6 @@ public class FSNamesystem implements FSC
   // precision of access times.
   private long accessTimePrecision = 0;
   
-  private ObjectName mxBeanName = null;
-  
   /**
    * FSNamesystem constructor.
    */
@@ -418,7 +414,6 @@ public class FSNamesystem implements FSC
       dnsToSwitchMapping.resolve(new ArrayList<String>(hostsReader.getHosts()));
     }
     
-    registerMXBean();
     registerWith(DefaultMetricsSystem.INSTANCE);
   }
 
@@ -4783,9 +4778,13 @@ public class FSNamesystem implements FSC
   }
   
   private ObjectName mbeanName;
+  
+  private ObjectName mxBean = null;
   /**
    * Register the FSNamesystem MBean using the name
    *        "hadoop:service=NameNode,name=FSNamesystemState"
+   * Register the FSNamesystem MXBean using the name
+   *        "hadoop:service=NameNode,name=NameNodeInfo"
    */
   void registerMBean(Configuration conf) {
     // We wrap to bypass standard mbean naming convention.
@@ -4798,8 +4797,9 @@ public class FSNamesystem implements FSC
     } catch (NotCompliantMBeanException e) {
       e.printStackTrace();
     }
+    mxBean = MBeans.register("NameNode", "NameNodeInfo", this);
 
-    LOG.info("Registered FSNamesystemStateMBean");
+    LOG.info("Registered FSNamesystemStateMBean and NameNodeMXBean");
   }
 
   /**
@@ -4808,8 +4808,8 @@ public class FSNamesystem implements FSC
   public void shutdown() {
     if (mbeanName != null)
       MBeans.unregister(mbeanName);
-    if (mxBeanName != null)
-      unRegisterMXBean();
+    if (mxBean != null)
+      MBeans.unregister(mxBean);
   }
   
 
@@ -5158,38 +5158,7 @@ public class FSNamesystem implements FSC
     }
     return authMethod;
   }
-
-  /**
-   * Register NameNodeMXBean
-   */
-  private void registerMXBean() {
-    // register MXBean
-    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-    if (mxBeanName == null) {
-      try {
-        mxBeanName = new ObjectName("HadoopInfo:type=NameNodeInfo");
-        mbs.registerMBean(this, mxBeanName);
-      } catch ( javax.management.JMException e ) {
-        LOG.warn("Failed to register NameNodeMXBean", e);
-      }
-    }
-  }
-
-  private void unRegisterMXBean() {
-    if (mxBeanName == null)
-      return;
-    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-    if (mbs.isRegistered(mxBeanName)){
-      try {
-        mbs.unregisterMBean(mxBeanName);
-      } catch (InstanceNotFoundException e ) {
-        LOG.warn(mxBeanName, e);
-      } catch (javax.management.JMException e) {
-        LOG.warn("Error unregistering "+ mxBeanName, e);
-      }
-      mxBeanName = null;
-    }
-  }
+  
   /**
    * Class representing Namenode information for JMX interfaces
    */

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java?rev=1077674&r1=1077673&r2=1077674&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/datanode/TestDataNodeMXBean.java
Fri Mar  4 04:42:53 2011
@@ -43,8 +43,9 @@ public class TestDataNodeMXBean {
       DataNode datanode = datanodes.get(0);
 
       MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
-      ObjectName mxbeanName = new ObjectName("HadoopInfo:type=DataNodeInfo");
-      // get attribute "Version"
+      ObjectName mxbeanName = new ObjectName(
+          "Hadoop:service=DataNode,name=DataNodeInfo");
+          // get attribute "Version"
       String version = (String)mbs.getAttribute(mxbeanName, "Version");
       Assert.assertEquals(datanode.getVersion(),version);
       // get attribute "RpcPort"

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java?rev=1077674&r1=1077673&r2=1077674&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
(original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java
Fri Mar  4 04:42:53 2011
@@ -45,7 +45,8 @@ public class TestNameNodeMXBean {
       FSNamesystem fsn = cluster.getNameNode().namesystem;
 
       MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-      ObjectName mxbeanName = new ObjectName("HadoopInfo:type=NameNodeInfo");
+      ObjectName mxbeanName = new ObjectName(
+        "Hadoop:service=NameNode,name=NameNodeInfo");
       // get attribute "Version"
       String version = (String) mbs.getAttribute(mxbeanName, "Version");
       Assert.assertEquals(fsn.getVersion(), version);



Mime
View raw message