hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject svn commit: r615345 - in /hadoop/core/trunk: CHANGES.txt src/test/org/apache/hadoop/mapred/SortValidator.java
Date Fri, 25 Jan 2008 21:23:24 GMT
Author: nigel
Date: Fri Jan 25 13:23:23 2008
New Revision: 615345

URL: http://svn.apache.org/viewvc?rev=615345&view=rev
Log:
HADOOP-2646. Fix SortValidator to work with fully-qualified working directories. Contributed
by Arun C Murthy.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/test/org/apache/hadoop/mapred/SortValidator.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=615345&r1=615344&r2=615345&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Jan 25 13:23:23 2008
@@ -570,6 +570,8 @@
     HADOOP-2626. Fix paths with special characters to work correctly
     with the local filesystem.  (Thomas Friol via cutting)
 
+    HADOOP-2646. Fix SortValidator to work with fully-qualified 
+    working directories.  (Arun C Murthy via nigel)
 
 Release 0.15.3 - 2008-01-18
 

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/mapred/SortValidator.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/mapred/SortValidator.java?rev=615345&r1=615344&r2=615345&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/mapred/SortValidator.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/mapred/SortValidator.java Fri Jan 25 13:23:23
2008
@@ -20,10 +20,10 @@
 
 import java.io.*;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.*;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.conf.Configured;
 import org.apache.hadoop.io.BytesWritable;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.SequenceFile;
@@ -33,6 +33,8 @@
 import org.apache.hadoop.io.WritableComparator;
 import org.apache.hadoop.io.WritableUtils;
 import org.apache.hadoop.mapred.lib.HashPartitioner;
+import org.apache.hadoop.util.Tool;
+import org.apache.hadoop.util.ToolRunner;
 import org.apache.hadoop.fs.*;
 
 /**
@@ -49,7 +51,7 @@
  *            [-m <i>maps</i>] [-r <i>reduces</i>] [-deep] 
  *            -sortInput <i>sort-in-dir</i> -sortOutput <i>sort-out-dir</i>

  */
-public class SortValidator {
+public class SortValidator extends Configured implements Tool {
 
   static private final IntWritable sortInput = new IntWritable(1); 
   static private final IntWritable sortOutput = new IntWritable(2); 
@@ -62,17 +64,11 @@
 
   static private IntWritable deduceInputFile(JobConf job) {
     Path[] inputPaths = job.getInputPaths();
-    String inputFile = null; 
-    try {
-      inputFile = new URI(job.get("map.input.file")).getPath();
-    } catch (URISyntaxException urise) {
-      System.err.println("Caught: " + urise);
-      System.exit(-1);
-    }
-    
+    Path inputFile = new Path(job.get("map.input.file"));
+
     // value == one for sort-input; value == two for sort-output
-    return (inputFile.startsWith(inputPaths[0].toString()+"/")) ? 
-      sortInput : sortOutput;
+    return (inputFile.getParent().equals(inputPaths[0])) ? 
+        sortInput : sortOutput;
   }
   
   static private byte[] pair(BytesWritable a, BytesWritable b) {
@@ -149,7 +145,6 @@
     }
     
     private static Raw createRaw(Class rawClass) {
-      System.err.println("rawClass: " + rawClass);
       if (rawClass == Text.class) {
         return new RawText();
       } else if (rawClass == BytesWritable.class) {
@@ -511,13 +506,13 @@
 
   
   /**
-   * The main driver for sort program.
+   * The main driver for sort-validator program.
    * Invoke this method to submit the map/reduce job.
    * @throws IOException When there is communication problems with the 
    *                     job tracker.
    */
-  public static void main(String[] args) throws IOException {
-    Configuration defaults = new Configuration();
+  public int run(String[] args) throws Exception {
+    Configuration defaults = getConf();
     
     int noMaps = -1, noReduces = -1;
     Path sortInput = null, sortOutput = null;
@@ -536,20 +531,24 @@
           deepTest = true;
         } else {
           printUsage();
+          return -1;
         }
       } catch (NumberFormatException except) {
         System.err.println("ERROR: Integer expected instead of " + args[i]);
         printUsage();
+        return -1;
       } catch (ArrayIndexOutOfBoundsException except) {
         System.err.println("ERROR: Required parameter missing from " +
                            args[i-1]);
-        printUsage(); // exits
+        printUsage();
+        return -1;
       }
     }
     
     // Sanity check
     if (sortInput == null || sortOutput == null) {
       printUsage();
+      return -2;
     }
 
     // Check if the records are consistent and sorted correctly
@@ -563,6 +562,12 @@
     
     System.out.println("\nSUCCESS! Validated the MapReduce framework's 'sort'" +
                        " successfully.");
+    
+    return 0;
+  }
+
+  public static void main(String[] args) throws Exception {
+    int res = ToolRunner.run(new Configuration(), new SortValidator(), args);
+    System.exit(res);
   }
-  
 }



Mime
View raw message