From 536b30ec910296d2f5efdbb35050c3c88f27719f Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Tue, 31 Jan 2012 20:03:49 +0000 Subject: [PATCH] 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 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../org/apache/hadoop/hdfs/tools/GetConf.java | 47 +++++++++++-------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 6bf330bac13..4ca203b6dfc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -384,6 +384,9 @@ Release 0.23.1 - UNRELEASED directory results in leases updated incorrectly. (Uma Maheswara Rao G via szetszwo) + HDFS-2835. Fix findbugs and javadoc issue with GetConf.java. + (suresh) + Release 0.23.0 - 2011-11-01 INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java index b9631430d74..0c7517739a7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/GetConf.java @@ -21,7 +21,9 @@ import java.io.IOException; import java.io.PrintStream; import java.net.InetSocketAddress; import java.security.PrivilegedExceptionAction; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; @@ -47,6 +49,9 @@ import org.apache.hadoop.util.ToolRunner; * {@link GetConf.Command}. * * See {@link GetConf.Command#NAMENODE} for example. + * + * Add for the new option added, a map entry with the corresponding + * {@link GetConf.CommandHandler}. * */ 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"; enum Command { - NAMENODE("-namenodes", new NameNodesCommandHandler(), - "gets list of namenodes in the cluster."), - SECONDARY("-secondaryNameNodes", new SecondaryNameNodesCommandHandler(), + NAMENODE("-namenodes", "gets list of namenodes in the cluster."), + SECONDARY("-secondaryNameNodes", "gets list of secondary namenodes in the cluster."), - BACKUP("-backupNodes", new BackupNodesCommandHandler(), - "gets list of backup nodes in the cluster."), + BACKUP("-backupNodes", "gets list of backup nodes in the cluster."), INCLUDE_FILE("-includeFile", - new CommandHandler("DFSConfigKeys.DFS_HOSTS"), "gets the include file path that defines the datanodes " + "that can join the cluster."), EXCLUDE_FILE("-excludeFile", - new CommandHandler("DFSConfigKeys.DFS_HOSTS_EXCLUDE"), "gets the exclude file path that defines the datanodes " + "that need to decommissioned."), - NNRPCADDRESSES("-nnRpcAddresses", - new NNRpcAddressesCommandHandler(), - "gets the namenode rpc addresses"); + NNRPCADDRESSES("-nnRpcAddresses", "gets the namenode rpc addresses"); + private static Map map; + static { + map = new HashMap(); + 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 CommandHandler handler; private final String description; - Command(String cmd, CommandHandler handler, String description) { + Command(String cmd, String description) { this.cmd = cmd; - this.handler = handler; this.description = description; } @@ -91,12 +105,7 @@ public class GetConf extends Configured implements Tool { } public static CommandHandler getHandler(String name) { - for (Command cmd : values()) { - if (cmd.getName().equalsIgnoreCase(name)) { - return cmd.handler; - } - } - return null; + return map.get(name.toLowerCase()); } }