瀏覽代碼

HADOOP-977. Send task's stdout and stderr to JobClient's stdout and stderr, respectively. Contributed by Arun.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@505507 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 年之前
父節點
當前提交
7f5cd4855c
共有 4 個文件被更改,包括 40 次插入26 次删除
  1. 4 0
      CHANGES.txt
  2. 9 0
      conf/hadoop-default.xml
  3. 27 23
      src/java/org/apache/hadoop/mapred/JobClient.java
  4. 0 3
      src/webapps/task/tasklog.jsp

+ 4 - 0
CHANGES.txt

@@ -26,6 +26,10 @@ Trunk (unreleased changes)
  7. HADOOP-882.  Upgrade to jets3t version 0.5, used by the S3
  7. HADOOP-882.  Upgrade to jets3t version 0.5, used by the S3
     FileSystem.  This version supports retries.  (Michael Stack via cutting)
     FileSystem.  This version supports retries.  (Michael Stack via cutting)
 
 
+ 8. HADOOP-977.  Send task's stdout and stderr to JobClient's stdout
+    and stderr respectively, with each line tagged by the task's name.
+    (Arun C Murthy via cutting)
+
 
 
 Branch 0.11 - unreleased
 Branch 0.11 - unreleased
 
 

+ 9 - 0
conf/hadoop-default.xml

@@ -699,6 +699,15 @@ creations/deletions), or "all".</description>
   </description>
   </description>
 </property>
 </property>
 
 
+<property>
+  <name>jobclient.output.filter</name>
+  <value>FAILED</value>
+  <description>The filter for controlling the output of the task's userlogs sent
+               to the console of the JobClient. 
+               The permissible options are: NONE, FAILED, SUCCEEDED and ALL.
+  </description>
+</property>
+
 <!-- ipc properties -->
 <!-- ipc properties -->
 
 
 <property>
 <property>

+ 27 - 23
src/java/org/apache/hadoop/mapred/JobClient.java

@@ -384,7 +384,7 @@ public class JobClient extends ToolBase implements MRConstants  {
       String lastReport = null;
       String lastReport = null;
       final int MAX_RETRIES = 5;
       final int MAX_RETRIES = 5;
       int retries = MAX_RETRIES;
       int retries = MAX_RETRIES;
-      String outputFilterName = job.get("jobclient.output.filter");
+      String outputFilterName = job.get("jobclient.output.filter", "FAILED");
 
 
       if (null != outputFilterName) {
       if (null != outputFilterName) {
         try {
         try {
@@ -428,19 +428,19 @@ public class JobClient extends ToolBase implements MRConstants  {
                   if( event.getTaskStatus() == 
                   if( event.getTaskStatus() == 
                     TaskCompletionEvent.Status.SUCCEEDED){
                     TaskCompletionEvent.Status.SUCCEEDED){
                     LOG.info(event.toString());
                     LOG.info(event.toString());
-                    printHttpFile(event.getTaskTrackerHttp());
+                    displayTaskLogs(event.getTaskId(), event.getTaskTrackerHttp());
                   }
                   }
                   break; 
                   break; 
                 case FAILED:
                 case FAILED:
                   if( event.getTaskStatus() == 
                   if( event.getTaskStatus() == 
                     TaskCompletionEvent.Status.FAILED){
                     TaskCompletionEvent.Status.FAILED){
                     LOG.info(event.toString());
                     LOG.info(event.toString());
-                    printHttpFile(event.getTaskTrackerHttp());
+                    displayTaskLogs(event.getTaskId(), event.getTaskTrackerHttp());
                   }
                   }
                   break ; 
                   break ; 
                 case ALL:
                 case ALL:
                   LOG.info(event.toString());
                   LOG.info(event.toString());
-                  printHttpFile(event.getTaskTrackerHttp());
+                  displayTaskLogs(event.getTaskId(), event.getTaskTrackerHttp());
                   break;
                   break;
                 }
                 }
               }
               }
@@ -467,29 +467,33 @@ public class JobClient extends ToolBase implements MRConstants  {
         jc.close();
         jc.close();
       }
       }
     }
     }
+
+    private static void displayTaskLogs(String taskId, String baseUrl)
+    throws IOException {
+      // Copy tasks's stdout of the JobClient
+      getTaskLogs(taskId, new URL(baseUrl+"&filter=stdout"), System.out);
+      
+      // Copy task's stderr to stderr of the JobClient 
+      getTaskLogs(taskId, new URL(baseUrl+"&filter=stderr"), System.err);
+    }
     
     
-    static void printHttpFile(String httpURL ) throws IOException {
-      boolean good = false;
-      long totalBytes = 0;
-      URL path = new URL(httpURL); 
+    private static void getTaskLogs(String taskId, URL taskLogUrl, 
+            OutputStream out) {
       try {
       try {
-        URLConnection connection = path.openConnection();
-        InputStream input = connection.getInputStream();
+        URLConnection connection = taskLogUrl.openConnection();
+        BufferedReader input = 
+          new BufferedReader(new InputStreamReader(connection.getInputStream()));
+        BufferedWriter output = 
+          new BufferedWriter(new OutputStreamWriter(out));
         try {
         try {
-          byte[] buffer = new byte[64 * 1024];
-          int len = input.read(buffer);
-          while (len > 0) {
-            totalBytes += len;
-            LOG.info(new String(buffer).trim());
-            len = input.read(buffer);
-          }
-          good = ((int) totalBytes) == connection.getContentLength();
-          if (!good) {
-          LOG.warn("Incomplete task output received for " + path +
-                          " (" + totalBytes + " instead of " + 
-                          connection.getContentLength() + ")");
+          String logData = null;
+          while ((logData = input.readLine()) != null) {
+            if (logData.length() > 0) {
+              output.write(taskId + ": " + logData + "\n");
+              output.flush();
+            }
           }
           }
-        }finally {
+        } finally {
             input.close();
             input.close();
         }
         }
       }catch(IOException ioe){
       }catch(IOException ioe){

+ 0 - 3
src/webapps/task/tasklog.jsp

@@ -121,9 +121,6 @@
   	  }
   	  }
   	  gotRequiredData = false;
   	  gotRequiredData = false;
   	}
   	}
-  	if( plainText ) {
-  	  response.setContentLength(bytesRead); 
-  	}
 	String logData = new String(b, 0, bytesRead);
 	String logData = new String(b, 0, bytesRead);
 	out.println(logData);
 	out.println(logData);
   } catch (IOException ioe) {
   } catch (IOException ioe) {