HDDS-707. Allow registering MBeans without additional jmx properties.

Contributed by Arpit Agarwal.
This commit is contained in:
Anu Engineer 2018-10-21 22:50:28 -07:00
parent 977c6f6470
commit c9077a9f5a
5 changed files with 57 additions and 13 deletions

View File

@ -21,22 +21,29 @@ package org.apache.hadoop.hdds;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.net.HostAndPort; 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.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
import org.apache.hadoop.hdds.scm.ScmConfigKeys; 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.DNS;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import static org.apache.hadoop.hdfs.DFSConfigKeys import static org.apache.hadoop.hdfs.DFSConfigKeys
.DFS_DATANODE_DNS_INTERFACE_KEY; .DFS_DATANODE_DNS_INTERFACE_KEY;
@ -49,6 +56,8 @@ import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ENABLED_DEFAULT;
/** /**
* HDDS specific stateless utility functions. * HDDS specific stateless utility functions.
*/ */
@InterfaceAudience.Private
@InterfaceStability.Stable
public final class HddsUtils { 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);
}
}
} }

View File

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

View File

@ -20,6 +20,7 @@
package org.apache.hadoop.utils.db; package org.apache.hadoop.utils.db;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.metrics2.util.MBeans; import org.apache.hadoop.metrics2.util.MBeans;
import org.apache.hadoop.utils.RocksDBStoreMBean; import org.apache.hadoop.utils.RocksDBStoreMBean;
@ -92,7 +93,8 @@ public class RDBStore implements DBStore {
if (dbOptions.statistics() != null) { if (dbOptions.statistics() != null) {
Map<String, String> jmxProperties = new HashMap<>(); Map<String, String> jmxProperties = new HashMap<>();
jmxProperties.put("dbName", dbFile.getName()); jmxProperties.put("dbName", dbFile.getName());
statMBeanName = MBeans.register("Ozone", "RocksDbStore", jmxProperties, statMBeanName = HddsUtils.registerWithJmxProperties(
"Ozone", "RocksDbStore", jmxProperties,
new RocksDBStoreMBean(dbOptions.statistics())); new RocksDBStoreMBean(dbOptions.statistics()));
if (statMBeanName == null) { if (statMBeanName == null) {
LOG.warn("jmx registration failed during RocksDB init, db path :{}", LOG.warn("jmx registration failed during RocksDB init, db path :{}",

View File

@ -611,10 +611,9 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
} }
private void registerMXBean() { private void registerMXBean() {
Map<String, String> jmxProperties = new HashMap<>(); final Map<String, String> jmxProperties = new HashMap<>();
jmxProperties.put("component", "ServerRuntime"); jmxProperties.put("component", "ServerRuntime");
this.scmInfoBeanName = this.scmInfoBeanName = HddsUtils.registerWithJmxProperties(
MBeans.register(
"StorageContainerManager", "StorageContainerManagerInfo", "StorageContainerManager", "StorageContainerManagerInfo",
jmxProperties, this); jmxProperties, this);
} }

View File

@ -21,6 +21,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.protobuf.BlockingService; import com.google.protobuf.BlockingService;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails; import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos; import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
@ -1041,13 +1042,10 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
} }
private void registerMXBean() { private void registerMXBean() {
Map<String, String> jmxProperties = new HashMap<String, String>(); Map<String, String> jmxProperties = new HashMap<>();
jmxProperties.put("component", "ServerRuntime"); jmxProperties.put("component", "ServerRuntime");
this.omInfoBeanName = this.omInfoBeanName = HddsUtils.registerWithJmxProperties(
MBeans.register("OzoneManager", "OzoneManager", "OzoneManagerInfo", jmxProperties, this);
"OzoneManagerInfo",
jmxProperties,
this);
} }
private void unregisterMXBean() { private void unregisterMXBean() {