|
@@ -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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|