diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMInfoMXBean.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMInfoMXBean.java new file mode 100644 index 0000000..138ff90 --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMInfoMXBean.java @@ -0,0 +1,43 @@ +/** + * 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.yarn.server.resourcemanager; + +public interface RMInfoMXBean { + + /** + * Gets the ResourceManager state. + * + * @return the ResourceManager state. + */ + public String getState(); + + /** + * Gets the host and port colon separated. + * + * @return host and port colon separated. + */ + public String getHostAndPort(); + + /** + * Gets if security is enabled. + * + * @return true, if security is enabled. + */ + public boolean isSecurityEnabled(); + +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java index 130cfd4..077ccb9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java @@ -28,6 +28,8 @@ import org.apache.hadoop.http.lib.StaticUserWebFilter; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.metrics2.source.JvmMetrics; +import org.apache.hadoop.metrics2.util.MBeans; +import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.AuthenticationFilterInitializer; import org.apache.hadoop.security.Groups; import org.apache.hadoop.security.SecurityUtil; @@ -109,13 +111,16 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import javax.management.ObjectName; + /** * The ResourceManager is the main class that is a set of components. * "I am the ResourceManager. All your resources belong to us..." * */ @SuppressWarnings("unchecked") -public class ResourceManager extends CompositeService implements Recoverable { +public class ResourceManager extends CompositeService implements Recoverable, + RMInfoMXBean { /** * Priority of the ResourceManager shutdown hook. @@ -135,6 +140,8 @@ @VisibleForTesting protected AdminService adminService; + private ObjectName rmStatusBeanName; + /** * "Active" services. Services that need to run only on the Active RM. * These services are managed (initialized, started, stopped) by the @@ -189,6 +196,7 @@ protected static void setClusterTimeStamp(long timestamp) { protected void serviceInit(Configuration conf) throws Exception { this.conf = conf; this.rmContext = new RMContextImpl(); + registerRMSMXBean(); this.configurationProvider = ConfigurationProviderFactory.getConfigurationProvider(conf); @@ -1107,6 +1115,10 @@ protected void serviceStop() throws Exception { super.serviceStop(); transitionToStandby(false); rmContext.setHAServiceState(HAServiceState.STOPPING); + if (rmStatusBeanName != null) { + MBeans.unregister(rmStatusBeanName); + rmStatusBeanName = null; + } } protected ResourceTrackerService createResourceTrackerService() { @@ -1305,4 +1317,31 @@ private static void printUsage(PrintStream out) { out.println(" " + "[-remove-application-from-state-store ]" + "\n"); } + + @Override + public String getState() { + String servStateStr = ""; + HAServiceState servState = rmContext.getHAServiceState(); + if (null != servState) { + servStateStr = servState.toString(); + } + return servStateStr; + } + + @Override + public String getHostAndPort() { + return NetUtils.getHostPortString(getBindAddress(conf)); + } + + @Override + public boolean isSecurityEnabled() { + return UserGroupInformation.isSecurityEnabled(); + } + + /** + * Register ResourceManagerStatusMXBean + */ + private void registerRMSMXBean() { + rmStatusBeanName = MBeans.register("ResourceManager", "RMInfo", this); + } } -- 1.9.2.msysgit.0