Jelajahi Sumber

HADOOP-488: return exit code in ToolBase.doMain, and use
System.exit(code) in classes that use this in their main() method.


git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@439069 13f79535-47bb-0310-9956-ffa450edef68

Andrzej Bialecki 18 tahun lalu
induk
melakukan
a043e66798

+ 2 - 1
src/java/org/apache/hadoop/dfs/DFSShell.java

@@ -391,6 +391,7 @@ public class DFSShell extends ToolBase {
      * main() has some simple utility methods
      */
     public static void main(String argv[]) throws Exception {
-        new DFSShell().doMain(new Configuration(), argv);
+        int res = new DFSShell().doMain(new Configuration(), argv);
+        System.exit(res);
     }
 }

+ 2 - 1
src/java/org/apache/hadoop/dfs/DFSck.java

@@ -450,7 +450,8 @@ public class DFSck extends ToolBase {
   }
 
   public static void main(String[] args) throws Exception {
-      new DFSck().doMain(new Configuration(), args);
+      int res = new DFSck().doMain(new Configuration(), args);
+      System.exit(res);
   }
 
   /**

+ 2 - 1
src/java/org/apache/hadoop/mapred/JobClient.java

@@ -457,7 +457,8 @@ public class JobClient extends ToolBase implements MRConstants  {
     /**
      */
     public static void main(String argv[]) throws Exception {
-        new JobClient().doMain(new Configuration(), argv);
+        int res = new JobClient().doMain(new Configuration(), argv);
+        System.exit(res);
     }
 }
 

+ 2 - 1
src/java/org/apache/hadoop/util/CopyFiles.java

@@ -810,9 +810,10 @@ public class CopyFiles extends ToolBase {
   }
   
   public static void main(String[] args) throws Exception {
-    new CopyFiles().doMain(
+    int res = new CopyFiles().doMain(
         new JobConf(new Configuration(), CopyFiles.class), 
         args);
+    System.exit(res);
   }
   
 }

+ 5 - 2
src/java/org/apache/hadoop/util/ToolBase.java

@@ -177,11 +177,14 @@ public abstract class ToolBase implements Tool {
      * @param conf Application default configuration
      * @param args User-specified arguments
      * @throws Exception
+     * @return exit code to be passed to a caller. General contract is that code
+     * equal zero signifies a normal return, negative values signify errors, and
+     * positive non-zero values can be used to return application-specific codes.
      */
-    public final void doMain(Configuration conf, String[] args) throws Exception {
+    public final int doMain(Configuration conf, String[] args) throws Exception {
         String [] commandOptions = parseGeneralOptions(conf, args);
         setConf(conf);
-        this.run(commandOptions);
+        return this.run(commandOptions);
     }
 
 }