HDFS-5004. Add additional JMX bean for NameNode status data. Contributed by Trevor Lorimer.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1507534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Konstantin Boudnik 2013-07-27 00:17:23 +00:00
parent c0cb57e307
commit 709aa9b9b0
6 changed files with 129 additions and 1 deletions

View File

@ -30,6 +30,9 @@ Release 2.3.0 - UNRELEASED
HDFS-4817. Make HDFS advisory caching configurable on a per-file basis.
(Colin Patrick McCabe)
HDFS-5004. Add additional JMX bean for NameNode status data. Contributed
by Trevor Lorimer.
OPTIMIZATIONS
BUG FIXES

View File

@ -6320,6 +6320,24 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
return dir;
}
@Override // NameNodeMXBean
public String getCorruptFiles() {
List<String> list = new ArrayList<String>();
Collection<FSNamesystem.CorruptFileBlockInfo> corruptFileBlocks;
try {
corruptFileBlocks = listCorruptFileBlocks("/", null);
int corruptFileCount = corruptFileBlocks.size();
if (corruptFileCount != 0) {
for (FSNamesystem.CorruptFileBlockInfo c : corruptFileBlocks) {
list.add(c.toString());
}
}
} catch (IOException e) {
LOG.warn("Get corrupt file blocks returned error: " + e.getMessage());
}
return JSON.toString(list);
}
/**
* Verifies that the given identifier and password are valid and match.
* @param identifier Token identifier.

View File

@ -70,6 +70,7 @@ import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
import org.apache.hadoop.ipc.Server;
import org.apache.hadoop.ipc.StandbyException;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.metrics2.util.MBeans;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.RefreshUserMappingsProtocol;
@ -125,7 +126,7 @@ import com.google.common.collect.Lists;
* NameNode state, for example partial blocksMap etc.
**********************************************************/
@InterfaceAudience.Private
public class NameNode {
public class NameNode implements NameNodeStatusMXBean {
static{
HdfsConfiguration.init();
}
@ -533,6 +534,7 @@ public class NameNode {
/** Start the services common to active and standby states */
private void startCommonServices(Configuration conf) throws IOException {
namesystem.startCommonServices(conf, haContext);
registerNNSMXBean();
if (NamenodeRole.NAMENODE != role) {
startHttpServer(conf);
httpServer.setNameNodeAddress(getNameNodeAddress());
@ -1366,6 +1368,43 @@ public class NameNode {
return state.getServiceState();
}
/**
* Register NameNodeStatusMXBean
*/
private void registerNNSMXBean() {
MBeans.register("NameNode", "NameNodeStatus", this);
}
@Override // NameNodeStatusMXBean
public String getNNRole() {
String roleStr = "";
NamenodeRole role = getRole();
if (null != role) {
roleStr = role.toString();
}
return roleStr;
}
@Override // NameNodeStatusMXBean
public String getState() {
String servStateStr = "";
HAServiceState servState = getServiceState();
if (null != servState) {
servStateStr = servState.toString();
}
return servStateStr;
}
@Override // NameNodeStatusMXBean
public String getHostAndPort() {
return getNameNodeAddressHostPortString();
}
@Override // NameNodeStatusMXBean
public boolean isSecurityEnabled() {
return UserGroupInformation.isSecurityEnabled();
}
/**
* Shutdown the NN immediately in an ungraceful way. Used when it would be
* unsafe for the NN to continue operating, e.g. during a failed HA state

View File

@ -202,4 +202,11 @@ public interface NameNodeMXBean {
* @return the compilation information, as a JSON string.
*/
public String getCompileInfo();
/**
* Get the list of corrupt files
*
* @return the list of corrupt files, as a JSON string.
*/
public String getCorruptFiles();
}

View File

@ -0,0 +1,57 @@
/**
* 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.hdfs.server.namenode;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
/**
* This is the JMX management interface for NameNode status information
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public interface NameNodeStatusMXBean {
/**
* Gets the NameNode role.
*
* @return the NameNode role.
*/
public String getNNRole();
/**
* Gets the NameNode state.
*
* @return the NameNode 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();
}

View File

@ -126,6 +126,10 @@ public class TestNameNodeMXBean {
// get attribute "CompileInfo"
String compileInfo = (String) mbs.getAttribute(mxbeanName, "CompileInfo");
assertEquals("Bad value for CompileInfo", fsn.getCompileInfo(), compileInfo);
// get attribute CorruptFiles
String corruptFiles = (String) (mbs.getAttribute(mxbeanName,
"CorruptFiles"));
assertEquals("Bad value for CorruptFiles", fsn.getCorruptFiles(), corruptFiles);
// get attribute NameDirStatuses
String nameDirStatuses = (String) (mbs.getAttribute(mxbeanName,
"NameDirStatuses"));