Sfoglia il codice sorgente

HDFS-2835. Merging change 1238779 from trunk to 0.23

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1238781 13f79535-47bb-0310-9956-ffa450edef68
Suresh Srinivas 13 anni fa
parent
commit
b8fbf25ace

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -197,6 +197,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

+ 28 - 19
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}.
  * </ul>
  */
 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<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 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());
     }
   }