hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aengin...@apache.org
Subject [2/2] hadoop git commit: HDDS-707. Allow registering MBeans without additional jmx properties. Contributed by Arpit Agarwal.
Date Mon, 22 Oct 2018 05:55:58 GMT
HDDS-707. Allow registering MBeans without additional jmx properties.
Contributed by Arpit Agarwal.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c9077a9f
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c9077a9f
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c9077a9f

Branch: refs/heads/trunk
Commit: c9077a9f5a693df63c2ff797415605233e38a9a8
Parents: 977c6f6
Author: Anu Engineer <aengineer@apache.org>
Authored: Sun Oct 21 22:50:28 2018 -0700
Committer: Anu Engineer <aengineer@apache.org>
Committed: Sun Oct 21 22:50:28 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hdds/HddsUtils.java  | 43 ++++++++++++++++++++
 .../org/apache/hadoop/utils/RocksDBStore.java   |  4 +-
 .../org/apache/hadoop/utils/db/RDBStore.java    |  4 +-
 .../scm/server/StorageContainerManager.java     |  9 ++--
 .../apache/hadoop/ozone/om/OzoneManager.java    | 10 ++---
 5 files changed, 57 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/c9077a9f/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
index db9d374..bd75f2d 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
@@ -21,22 +21,29 @@ package org.apache.hadoop.hdds;
 import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import com.google.common.net.HostAndPort;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
 import org.apache.hadoop.hdds.scm.ScmConfigKeys;
+import org.apache.hadoop.metrics2.util.MBeans;
 import org.apache.hadoop.net.DNS;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.ozone.OzoneConfigKeys;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.management.ObjectName;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 import java.nio.file.Paths;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Map;
 
 import static org.apache.hadoop.hdfs.DFSConfigKeys
     .DFS_DATANODE_DNS_INTERFACE_KEY;
@@ -49,6 +56,8 @@ import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ENABLED_DEFAULT;
 /**
  * HDDS specific stateless utility functions.
  */
+@InterfaceAudience.Private
+@InterfaceStability.Stable
 public final class HddsUtils {
 
 
@@ -348,4 +357,38 @@ public final class HddsUtils {
     }
   }
 
+  /**
+   * Register the provided MBean with additional JMX ObjectName properties.
+   * If additional properties are not supported then fallback to registering
+   * without properties.
+   *
+   * @param serviceName - see {@link MBeans#register}
+   * @param mBeanName - see {@link MBeans#register}
+   * @param jmxProperties - additional JMX ObjectName properties.
+   * @param mBean - the MBean to register.
+   * @return the named used to register the MBean.
+   */
+  public static ObjectName registerWithJmxProperties(
+      String serviceName, String mBeanName, Map<String, String> jmxProperties,
+      Object mBean) {
+    try {
+
+      // Check support for registering with additional properties.
+      final Method registerMethod = MBeans.class.getMethod(
+          "register", String.class, String.class,
+          Map.class, Object.class);
+
+      return (ObjectName) registerMethod.invoke(
+          null, serviceName, mBeanName, jmxProperties, mBean);
+
+    } catch (NoSuchMethodException | IllegalAccessException |
+        InvocationTargetException e) {
+
+      // Fallback
+      LOG.trace("Registering MBean {} without additional properties {}",
+          mBeanName, jmxProperties);
+      return MBeans.register(serviceName, mBeanName, mBean);
+    }
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c9077a9f/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/RocksDBStore.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/RocksDBStore.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/RocksDBStore.java
index 377153a..0ca99b6 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/RocksDBStore.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/RocksDBStore.java
@@ -21,6 +21,7 @@ package org.apache.hadoop.utils;
 import com.google.common.base.Preconditions;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.hadoop.hdds.HddsUtils;
 import org.apache.hadoop.metrics2.util.MBeans;
 import org.apache.ratis.thirdparty.com.google.common.annotations.
     VisibleForTesting;
@@ -72,7 +73,8 @@ public class RocksDBStore implements MetadataStore {
 
         Map<String, String> jmxProperties = new HashMap<String, String>();
         jmxProperties.put("dbName", dbFile.getName());
-        statMBeanName = MBeans.register("Ozone", "RocksDbStore", jmxProperties,
+        statMBeanName = HddsUtils.registerWithJmxProperties(
+            "Ozone", "RocksDbStore", jmxProperties,
             new RocksDBStoreMBean(dbOptions.statistics()));
         if (statMBeanName == null) {
           LOG.warn("jmx registration failed during RocksDB init, db path :{}",

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c9077a9f/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/db/RDBStore.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/db/RDBStore.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/db/RDBStore.java
index cdee10b..d0644b6 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/db/RDBStore.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/utils/db/RDBStore.java
@@ -20,6 +20,7 @@
 package org.apache.hadoop.utils.db;
 
 import com.google.common.base.Preconditions;
+import org.apache.hadoop.hdds.HddsUtils;
 import org.apache.hadoop.hdfs.DFSUtil;
 import org.apache.hadoop.metrics2.util.MBeans;
 import org.apache.hadoop.utils.RocksDBStoreMBean;
@@ -92,7 +93,8 @@ public class RDBStore implements DBStore {
       if (dbOptions.statistics() != null) {
         Map<String, String> jmxProperties = new HashMap<>();
         jmxProperties.put("dbName", dbFile.getName());
-        statMBeanName = MBeans.register("Ozone", "RocksDbStore", jmxProperties,
+        statMBeanName = HddsUtils.registerWithJmxProperties(
+            "Ozone", "RocksDbStore", jmxProperties,
             new RocksDBStoreMBean(dbOptions.statistics()));
         if (statMBeanName == null) {
           LOG.warn("jmx registration failed during RocksDB init, db path :{}",

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c9077a9f/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
index 242310f..fc9afd6 100644
--- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
+++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
@@ -611,12 +611,11 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
   }
 
   private void registerMXBean() {
-    Map<String, String> jmxProperties = new HashMap<>();
+    final Map<String, String> jmxProperties = new HashMap<>();
     jmxProperties.put("component", "ServerRuntime");
-    this.scmInfoBeanName =
-        MBeans.register(
-            "StorageContainerManager", "StorageContainerManagerInfo",
-            jmxProperties, this);
+    this.scmInfoBeanName = HddsUtils.registerWithJmxProperties(
+        "StorageContainerManager", "StorageContainerManagerInfo",
+        jmxProperties, this);
   }
 
   private void unregisterMXBean() {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c9077a9f/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
index 5c82fc3..63f0d52 100644
--- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
+++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
@@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.protobuf.BlockingService;
 import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.hdds.HddsUtils;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.protocol.DatanodeDetails;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
@@ -1041,13 +1042,10 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
   }
 
   private void registerMXBean() {
-    Map<String, String> jmxProperties = new HashMap<String, String>();
+    Map<String, String> jmxProperties = new HashMap<>();
     jmxProperties.put("component", "ServerRuntime");
-    this.omInfoBeanName =
-        MBeans.register("OzoneManager",
-            "OzoneManagerInfo",
-            jmxProperties,
-            this);
+    this.omInfoBeanName = HddsUtils.registerWithJmxProperties(
+        "OzoneManager", "OzoneManagerInfo", jmxProperties, this);
   }
 
   private void unregisterMXBean() {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message