hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r685334 - in /hadoop/core/trunk: CHANGES.txt src/core/org/apache/hadoop/util/Shell.java src/mapred/org/apache/hadoop/mapred/TaskRunner.java src/test/org/apache/hadoop/util/TestShell.java
Date Tue, 12 Aug 2008 21:57:15 GMT
Author: omalley
Date: Tue Aug 12 14:57:15 2008
New Revision: 685334

URL: http://svn.apache.org/viewvc?rev=685334&view=rev
Log:
HADOOP-3852. Add ShellCommandExecutor.toString method to make nicer
error messages. (Steve Loughran via omalley)

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/core/org/apache/hadoop/util/Shell.java
    hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/TaskRunner.java
    hadoop/core/trunk/src/test/org/apache/hadoop/util/TestShell.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=685334&r1=685333&r2=685334&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Tue Aug 12 14:57:15 2008
@@ -175,6 +175,9 @@
     HADOOP-3780. Remove asynchronous resolution of network topology in the 
     JobTracker (Amar Kamat via omalley)
 
+    HADOOP-3852. Add ShellCommandExecutor.toString method to make nicer
+    error messages. (Steve Loughran via omalley)
+
   OPTIMIZATIONS
 
     HADOOP-3556. Removed lock contention in MD5Hash by changing the 

Modified: hadoop/core/trunk/src/core/org/apache/hadoop/util/Shell.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/util/Shell.java?rev=685334&r1=685333&r2=685334&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/util/Shell.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/util/Shell.java Tue Aug 12 14:57:15 2008
@@ -303,6 +303,27 @@
     public String getOutput() {
       return (output == null) ? "" : output.toString();
     }
+
+    /**
+     * Returns the commands of this instance.
+     * Arguments with spaces in are presented with quotes round; other
+     * arguments are presented raw
+     *
+     * @return a string representation of the object.
+     */
+    public String toString() {
+      StringBuilder builder = new StringBuilder();
+      String[] args = getExecString();
+      for (String s : args) {
+        if (s.indexOf(' ') >= 0) {
+          builder.append('"').append(s).append('"');
+        } else {
+          builder.append(s);
+        }
+        builder.append(' ');
+      }
+      return builder.toString();
+    }
   }
   
   /** 

Modified: hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/TaskRunner.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/TaskRunner.java?rev=685334&r1=685333&r2=685334&view=diff
==============================================================================
--- hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/TaskRunner.java (original)
+++ hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/TaskRunner.java Tue Aug 12 14:57:15
2008
@@ -447,8 +447,8 @@
                         Map<String, String> env,
                         TaskAttemptID taskid) throws IOException {
 
+    shexec = new ShellCommandExecutor(args.toArray(new String[0]), dir, env);
     try {
-      shexec = new ShellCommandExecutor(args.toArray(new String[0]), dir, env);
       shexec.execute();
     } catch (IOException ioe) {
       // do nothing
@@ -461,7 +461,7 @@
           tracker.getTaskTrackerInstrumentation().taskFailedPing(t.getTaskID());
         }
         throw new IOException("Task process exit with nonzero status of " +
-                              exit_code + ".");
+                              exit_code + ": "+ shexec);
       }
     }
   }

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/util/TestShell.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/util/TestShell.java?rev=685334&r1=685333&r2=685334&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/util/TestShell.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/util/TestShell.java Tue Aug 12 14:57:15 2008
@@ -51,6 +51,27 @@
     testInterval(System.currentTimeMillis() / 60000 + 60); // test a very big interval
   }
 
+  /**
+   * Assert that a string has a substring in it
+   * @param string string to search
+   * @param search what to search for it
+   */
+  private void assertInString(String string, String search) {
+    assertNotNull("Empty String", string);
+    if (!string.contains(search)) {
+      fail("Did not find \"" + search + "\" in " + string);
+    }
+  }
+
+  public void testShellCommandExecutorToString() throws Throwable {
+    Shell.ShellCommandExecutor sce=new Shell.ShellCommandExecutor(
+            new String[] { "ls","..","arg 2"});
+    String command = sce.toString();
+    assertInString(command,"ls");
+    assertInString(command, " .. ");
+    assertInString(command, "\"arg 2\"");
+  }
+
   private void testInterval(long interval) throws IOException {
     Command command = new Command(interval);
 



Mime
View raw message