HDFS-2835. Fix findbugs and javadoc issue with GetConf.java. Contributed by Suresh Srinivas.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1238779 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2012-01-31 20:03:49 +00:00
parent 319021d6fb
commit 536b30ec91
2 changed files with 31 additions and 19 deletions

View File

@ -384,6 +384,9 @@ Release 0.23.1 - UNRELEASED
directory results in leases updated incorrectly. (Uma Maheswara Rao G directory results in leases updated incorrectly. (Uma Maheswara Rao G
via szetszwo) via szetszwo)
HDFS-2835. Fix findbugs and javadoc issue with GetConf.java.
(suresh)
Release 0.23.0 - 2011-11-01 Release 0.23.0 - 2011-11-01
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -21,7 +21,9 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured; import org.apache.hadoop.conf.Configured;
@ -47,6 +49,9 @@ import org.apache.hadoop.util.ToolRunner;
* {@link GetConf.Command}. * {@link GetConf.Command}.
* *
* See {@link GetConf.Command#NAMENODE} for example. * See {@link GetConf.Command#NAMENODE} for example.
*
* Add for the new option added, a map entry with the corresponding
* {@link GetConf.CommandHandler}.
* </ul> * </ul>
*/ */
public class GetConf extends Configured implements Tool { public class GetConf extends Configured implements Tool {
@ -54,31 +59,40 @@ public class GetConf extends Configured implements Tool {
+ "getting configuration information from the config file.\n"; + "getting configuration information from the config file.\n";
enum Command { enum Command {
NAMENODE("-namenodes", new NameNodesCommandHandler(), NAMENODE("-namenodes", "gets list of namenodes in the cluster."),
"gets list of namenodes in the cluster."), SECONDARY("-secondaryNameNodes",
SECONDARY("-secondaryNameNodes", new SecondaryNameNodesCommandHandler(),
"gets list of secondary namenodes in the cluster."), "gets list of secondary namenodes in the cluster."),
BACKUP("-backupNodes", new BackupNodesCommandHandler(), BACKUP("-backupNodes", "gets list of backup nodes in the cluster."),
"gets list of backup nodes in the cluster."),
INCLUDE_FILE("-includeFile", INCLUDE_FILE("-includeFile",
new CommandHandler("DFSConfigKeys.DFS_HOSTS"),
"gets the include file path that defines the datanodes " + "gets the include file path that defines the datanodes " +
"that can join the cluster."), "that can join the cluster."),
EXCLUDE_FILE("-excludeFile", EXCLUDE_FILE("-excludeFile",
new CommandHandler("DFSConfigKeys.DFS_HOSTS_EXCLUDE"),
"gets the exclude file path that defines the datanodes " + "gets the exclude file path that defines the datanodes " +
"that need to decommissioned."), "that need to decommissioned."),
NNRPCADDRESSES("-nnRpcAddresses", NNRPCADDRESSES("-nnRpcAddresses", "gets the namenode rpc addresses");
new NNRpcAddressesCommandHandler(),
"gets the namenode rpc addresses"); private static Map<String, CommandHandler> map;
static {
map = new HashMap<String, CommandHandler>();
map.put(NAMENODE.getName().toLowerCase(),
new NameNodesCommandHandler());
map.put(SECONDARY.getName().toLowerCase(),
new SecondaryNameNodesCommandHandler());
map.put(BACKUP.getName().toLowerCase(),
new BackupNodesCommandHandler());
map.put(INCLUDE_FILE.getName().toLowerCase(),
new CommandHandler("DFSConfigKeys.DFS_HOSTS"));
map.put(EXCLUDE_FILE.getName().toLowerCase(),
new CommandHandler("DFSConfigKeys.DFS_HOSTS_EXCLUDE"));
map.put(NNRPCADDRESSES.getName().toLowerCase(),
new NNRpcAddressesCommandHandler());
}
private final String cmd; private final String cmd;
private final CommandHandler handler;
private final String description; private final String description;
Command(String cmd, CommandHandler handler, String description) { Command(String cmd, String description) {
this.cmd = cmd; this.cmd = cmd;
this.handler = handler;
this.description = description; this.description = description;
} }
@ -91,12 +105,7 @@ public class GetConf extends Configured implements Tool {
} }
public static CommandHandler getHandler(String name) { public static CommandHandler getHandler(String name) {
for (Command cmd : values()) { return map.get(name.toLowerCase());
if (cmd.getName().equalsIgnoreCase(name)) {
return cmd.handler;
}
}
return null;
} }
} }