hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r471023 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/DFSShell.java
Date Fri, 03 Nov 2006 22:33:54 GMT
Author: cutting
Date: Fri Nov  3 14:33:53 2006
New Revision: 471023

URL: http://svn.apache.org/viewvc?view=rev&rev=471023
Log:
HADOOP-665.  Extend many DFSShell commands to accept multiple arguments.  Contributed by Dhruba.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=471023&r1=471022&r2=471023
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Fri Nov  3 14:33:53 2006
@@ -137,8 +137,12 @@
 38. HADOOP-647.  Permit map outputs to use a different compression
     type than the job output.  (omalley via cutting)
 
-39. HADOOP-671.  File cache should not create symlinks when they
-    already exist.  (Mahadev Konar via cutting)
+39. HADOOP-671.  Fix file cache to check for pre-existence before
+    creating .  (Mahadev Konar via cutting)
+
+40. HADOOP-665.  Extend many DFSShell commands to accept multiple
+    arguments.  Now commands like "ls", "rm", etc. will operate on
+    multiple files.  (Dhruba Borthakur via cutting)
 
 
 Release 0.7.2 - 2006-10-18

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java?view=diff&rev=471023&r1=471022&r2=471023
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java Fri Nov  3 14:33:53 2006
@@ -608,6 +608,64 @@
     }
 
     /**
+     * Apply operation specified by 'cmd' on all parameters
+     * starting from argv[startindex].
+     */
+    private int doall(String cmd, String argv[], Configuration conf, 
+                      int startindex) {
+      int exitCode = 0;
+      int i = startindex;
+      //
+      // for each source file, issue the command
+      //
+      for (; i < argv.length; i++) {
+        try {
+          //
+          // issue the command to the remote dfs server
+          //
+          if ("-cat".equals(cmd)) {
+              cat(argv[i]);
+          } else if ("-mkdir".equals(cmd)) {
+              mkdir(argv[i]);
+          } else if ("-rm".equals(cmd)) {
+              delete(argv[i], false);
+          } else if ("-rmr".equals(cmd)) {
+              delete(argv[i], true);
+          } else if ("-du".equals(cmd)) {
+              du(argv[i]);
+          } else if ("-ls".equals(cmd)) {
+              ls(argv[i], false);
+          } else if ("-lsr".equals(cmd)) {
+              ls(argv[i], true);
+          }
+        } catch (RemoteException e) {
+          //
+          // This is a error returned by hadoop server. Print
+          // out the first line of the error mesage.
+          //
+          exitCode = -1;
+          try {
+            String[] content;
+            content = e.getLocalizedMessage().split("\n");
+            System.err.println(cmd.substring(1) + ": " +
+                               content[0]);
+          } catch (Exception ex) {
+            System.err.println(cmd.substring(1) + ": " +
+                               ex.getLocalizedMessage());
+          }
+        } catch (IOException e) {
+          //
+          // IO exception encountered locally.
+          //
+          exitCode = -1;
+          System.err.println(cmd.substring(1) + ": " +
+                             e.getLocalizedMessage());
+        }
+      }
+      return exitCode;
+    }
+
+    /**
      * Displays format of commands.
      * 
      */
@@ -703,9 +761,7 @@
                   printUsage(cmd);
                   return exitCode;
                 }
-        } else if ("-rm".equals(cmd) || "-rmr".equals(cmd) ||
-                 "-cat".equals(cmd) || "-mkdir".equals(cmd) ||
-                 "-safemode".equals(cmd)) {
+        } else if ("-safemode".equals(cmd)) {
                 if (argv.length != 2) {
                   printUsage(cmd);
                   return exitCode;
@@ -720,6 +776,12 @@
                   printUsage(cmd);
                   return exitCode;
                 }
+        } else if ("-rm".equals(cmd) || "-rmr".equals(cmd) ||
+                   "-cat".equals(cmd) || "-mkdir".equals(cmd)) {
+                if (argv.length < 2) {
+                  printUsage(cmd);
+                  return exitCode;
+                }
         }
 
         // initialize DFSShell
@@ -748,30 +810,39 @@
                 else
                     copyMergeToLocal(argv[i++], new Path(argv[i++]));
             } else if ("-cat".equals(cmd)) {
-                cat(argv[i++]);
+                doall(cmd, argv, conf, i);
             } else if ("-moveToLocal".equals(cmd)) {
                 moveToLocal(argv[i++], new Path(argv[i++]));
             } else if ("-setrep".equals(cmd)) {
             	setReplication(argv, i);           
             } else if ("-ls".equals(cmd)) {
-                String arg = i < argv.length ? argv[i++] : "";
-                ls(arg, false);
+                if (i < argv.length) {
+                    doall(cmd, argv, conf, i);
+                } else {
+                    ls("", false);
+                } 
             } else if ("-lsr".equals(cmd)) {
-                String arg = i < argv.length ? argv[i++] : "";
-                ls(arg, true);
+                if (i < argv.length) {
+                    doall(cmd, argv, conf, i);
+                } else {
+                    ls("", true);
+                } 
             } else if ("-mv".equals(cmd)) {
                 exitCode = rename(argv, conf);
             } else if ("-cp".equals(cmd)) {
                 exitCode = copy(argv, conf);
             } else if ("-rm".equals(cmd)) {
-                delete(argv[i++], false);
+                doall(cmd, argv, conf, i);
             } else if ("-rmr".equals(cmd)) {
-                delete(argv[i++], true);
+                doall(cmd, argv, conf, i);
             } else if ("-du".equals(cmd)) {
-                String arg = i < argv.length ? argv[i++] : "";
-                du(arg);
+                if (i < argv.length) {
+                    doall(cmd, argv, conf, i);
+                } else {
+                    du("");
+                }
             } else if ("-mkdir".equals(cmd)) {
-                mkdir(argv[i++]);
+                doall(cmd, argv, conf, i);
             } else if ("-report".equals(cmd)) {
                 report();
             } else if ("-safemode".equals(cmd)) {



Mime
View raw message