hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vino...@apache.org
Subject svn commit: r1134652 - in /hadoop/mapreduce/branches/MR-279: ./ mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/ mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/util/
Date Sat, 11 Jun 2011 14:16:58 GMT
Author: vinodkv
Date: Sat Jun 11 14:16:58 2011
New Revision: 1134652

URL: http://svn.apache.org/viewvc?rev=1134652&view=rev
Log:
Display failed/killed attempts of the task on MR AM UI separately. (vinodkv)

Added:
    hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AttemptsPage.java
Modified:
    hadoop/mapreduce/branches/MR-279/CHANGES.txt
    hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMParams.java
    hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebApp.java
    hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AppController.java
    hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/JobBlock.java
    hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/TaskPage.java
    hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/util/MRApps.java

Modified: hadoop/mapreduce/branches/MR-279/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/CHANGES.txt?rev=1134652&r1=1134651&r2=1134652&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/CHANGES.txt (original)
+++ hadoop/mapreduce/branches/MR-279/CHANGES.txt Sat Jun 11 14:16:58 2011
@@ -5,6 +5,9 @@ Trunk (unreleased changes)
 
     MAPREDUCE-279
 
+    Display failed/killed attempts of the task on MR AM UI
+    separately. (vinodkv)
+
     Changes a couple of usages of FileContext to FileSystem in YarnRunner
     to handle distributed cache path resolutions on non-default filesystems.
     (ddas)

Modified: hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMParams.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMParams.java?rev=1134652&r1=1134651&r2=1134652&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMParams.java
(original)
+++ hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMParams.java
Sat Jun 11 14:16:58 2011
@@ -27,4 +27,5 @@ interface AMParams {
   static final String JOB_ID = "job.id";
   static final String TASK_ID = "task.id";
   static final String TASK_TYPE = "task.type";
+  static final String ATTEMPT_STATE = "attempt.state";
 }

Modified: hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebApp.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebApp.java?rev=1134652&r1=1134651&r2=1134652&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebApp.java
(original)
+++ hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AMWebApp.java
Sat Jun 11 14:16:58 2011
@@ -34,6 +34,8 @@ public class AMWebApp extends WebApp imp
     route(pajoin("/job", JOB_ID), AppController.class, "job");
     route(pajoin("/jobcounters", JOB_ID), AppController.class, "jobCounters");
     route(pajoin("/tasks", JOB_ID, TASK_TYPE), AppController.class, "tasks");
+    route(pajoin("/attempts", JOB_ID, TASK_TYPE, ATTEMPT_STATE),
+        AppController.class, "attempts");
     route(pajoin("/task", TASK_ID), AppController.class, "task");
   }
 }

Modified: hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AppController.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AppController.java?rev=1134652&r1=1134651&r2=1134652&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AppController.java
(original)
+++ hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AppController.java
Sat Jun 11 14:16:58 2011
@@ -100,6 +100,27 @@ public class AppController extends Contr
     render(TaskPage.class);
   }
 
+  public void attempts() {
+    requireJob();
+    if (app.job != null) {
+      try {
+        String taskType = $(TASK_TYPE);
+        if (taskType.isEmpty()) {
+          throw new RuntimeException("missing task-type.");
+        }
+        String attemptState = $(ATTEMPT_STATE);
+        if (attemptState.isEmpty()) {
+          throw new RuntimeException("missing attempt-state.");
+        }
+        setTitle(join(attemptState, " ",
+            MRApps.taskType(taskType).toString(), " attempts in ", $(JOB_ID)));
+      } catch (Exception e) {
+        badRequest(e.getMessage());
+      }
+    }
+    render(AttemptsPage.class);
+  }
+
   void badRequest(String s) {
     setStatus(response().SC_BAD_REQUEST);
     setTitle(join("Bad request: ", s));

Added: hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AttemptsPage.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AttemptsPage.java?rev=1134652&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AttemptsPage.java
(added)
+++ hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/AttemptsPage.java
Sat Jun 11 14:16:58 2011
@@ -0,0 +1,76 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.mapreduce.v2.app.webapp;
+
+import static org.apache.hadoop.mapreduce.v2.app.webapp.AMParams.TASK_TYPE;
+import static org.apache.hadoop.mapreduce.v2.app.webapp.AMParams.ATTEMPT_STATE;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
+import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptState;
+import org.apache.hadoop.mapreduce.v2.api.records.TaskType;
+import org.apache.hadoop.mapreduce.v2.app.job.Task;
+import org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt;
+import org.apache.hadoop.mapreduce.v2.util.MRApps;
+import org.apache.hadoop.mapreduce.v2.util.MRApps.TaskAttemptStateUI;
+import org.apache.hadoop.yarn.webapp.SubView;
+
+import com.google.inject.Inject;
+
+public class AttemptsPage extends TaskPage {
+  static class FewAttemptsBlock extends TaskPage.AttemptsBlock {
+    @Inject
+    FewAttemptsBlock(App ctx) {
+      super(ctx);
+    }
+
+    @Override
+    protected boolean isValidRequest() {
+      return true;
+    }
+
+    @Override
+    protected Collection<TaskAttempt> getTaskAttempts() {
+      List<TaskAttempt> fewTaskAttemps = new ArrayList<TaskAttempt>();
+      String taskTypeStr = $(TASK_TYPE);
+      TaskType taskType = MRApps.taskType(taskTypeStr);
+      String attemptStateStr = $(ATTEMPT_STATE);
+      TaskAttemptStateUI neededState = MRApps
+          .taskAttemptState(attemptStateStr);
+      for (Task task : super.app.job.getTasks(taskType).values()) {
+        Map<TaskAttemptId, TaskAttempt> attempts = task.getAttempts();
+        for (TaskAttempt attempt : attempts.values()) {
+          if (neededState.correspondsTo(attempt.getState())) {
+            fewTaskAttemps.add(attempt);
+          }
+        }
+      }
+      return fewTaskAttemps;
+    }
+  }
+
+  @Override
+  protected Class<? extends SubView> content() {
+    return FewAttemptsBlock.class;
+  }
+}

Modified: hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/JobBlock.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/JobBlock.java?rev=1134652&r1=1134651&r2=1134652&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/JobBlock.java
(original)
+++ hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/JobBlock.java
Sat Jun 11 14:16:58 2011
@@ -24,11 +24,14 @@ import java.util.Map;
 
 import org.apache.hadoop.mapreduce.v2.api.records.JobId;
 import org.apache.hadoop.mapreduce.v2.api.records.JobReport;
+import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
 import org.apache.hadoop.mapreduce.v2.api.records.TaskId;
 import org.apache.hadoop.mapreduce.v2.app.AppContext;
 import org.apache.hadoop.mapreduce.v2.app.job.Job;
 import org.apache.hadoop.mapreduce.v2.app.job.Task;
+import org.apache.hadoop.mapreduce.v2.app.job.TaskAttempt;
 import org.apache.hadoop.mapreduce.v2.util.MRApps;
+import org.apache.hadoop.mapreduce.v2.util.MRApps.TaskAttemptStateUI;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.yarn.util.Times;
 import org.apache.hadoop.yarn.webapp.view.HtmlBlock;
@@ -39,10 +42,22 @@ import static org.apache.hadoop.yarn.web
 
 public class JobBlock extends HtmlBlock {
   final AppContext appContext;
-  int runningMaps = 0;
-  int pendingMaps = 0;
-  int runningReds = 0;
-  int pendingReds = 0;
+
+  int runningMapTasks = 0;
+  int pendingMapTasks = 0;
+  int runningReduceTasks = 0;
+  int pendingReduceTasks = 0;
+
+  int newMapAttempts = 0;
+  int runningMapAttempts = 0;
+  int killedMapAttempts = 0;
+  int failedMapAttempts = 0;
+  int successfulMapAttempts = 0;
+  int newReduceAttempts = 0;
+  int runningReduceAttempts = 0;
+  int killedReduceAttempts = 0;
+  int failedReduceAttempts = 0;
+  int successfulReduceAttempts = 0;
 
   @Inject JobBlock(AppContext appctx) {
     appContext = appctx;
@@ -65,13 +80,13 @@ public class JobBlock extends HtmlBlock 
     JobReport jobReport = job.getReport();
     String mapPct = percent(jobReport.getMapProgress());
     String reducePct = percent(jobReport.getReduceProgress());
-    int maps = job.getTotalMaps();
-    int mapsComplete = job.getCompletedMaps();
-    int reduces = job.getTotalReduces();
-    int reducesComplete = job.getCompletedReduces();
+    int mapTasks = job.getTotalMaps();
+    int mapTasksComplete = job.getCompletedMaps();
+    int reduceTasks = job.getTotalReduces();
+    int reducesTasksComplete = job.getCompletedReduces();
     long startTime = jobReport.getStartTime();
     long finishTime = jobReport.getFinishTime();
-    countTasks(job);
+    countTasksAndAttempts(job);
     info("Job Overview").
         _("Job Name:", job.getName()).
         _("State:", job.getState()).
@@ -82,6 +97,8 @@ public class JobBlock extends HtmlBlock 
     html.
       _(InfoBlock.class).
       div(_INFO_WRAP).
+
+      // Tasks table
         table("#job").
           tr().
             th(_TH, "Task Type").
@@ -98,10 +115,10 @@ public class JobBlock extends HtmlBlock 
                 $title(join(mapPct, '%')). // tooltip
                 div(_PROGRESSBAR_VALUE).
                   $style(join("width:", mapPct, '%'))._()._()._().
-            td(String.valueOf(maps)).
-            td(String.valueOf(pendingMaps)).
-            td(String.valueOf(runningMaps)).
-            td(String.valueOf(mapsComplete))._().
+            td(String.valueOf(mapTasks)).
+            td(String.valueOf(pendingMapTasks)).
+            td(String.valueOf(runningMapTasks)).
+            td(String.valueOf(mapTasksComplete))._().
           tr(_EVEN).
             th().
               a(url("tasks", jid, "r"), "Reduce")._().
@@ -110,24 +127,127 @@ public class JobBlock extends HtmlBlock 
                 $title(join(reducePct, '%')). // tooltip
                 div(_PROGRESSBAR_VALUE).
                   $style(join("width:", reducePct, '%'))._()._()._().
-            td(String.valueOf(reduces)).
-            td(String.valueOf(pendingReds)).
-            td(String.valueOf(runningReds)).
-            td(String.valueOf(reducesComplete))._()._()._();
+            td(String.valueOf(reduceTasks)).
+            td(String.valueOf(pendingReduceTasks)).
+            td(String.valueOf(runningReduceTasks)).
+            td(String.valueOf(reducesTasksComplete))._()
+          ._().
+
+        // Attempts table
+        table("#job").
+        tr().
+          th(_TH, "Attempt Type").
+          th(_TH, "New").
+          th(_TH, "Running").
+          th(_TH, "Failed").
+          th(_TH, "Killed").
+          th(_TH, "Successful")._().
+        tr(_ODD).
+          th("Maps").
+          td().a(url("attempts", jid, "m",
+              TaskAttemptStateUI.NEW.toString()), 
+              String.valueOf(newMapAttempts))._().
+          td().a(url("attempts", jid, "m",
+              TaskAttemptStateUI.RUNNING.toString()), 
+              String.valueOf(runningMapAttempts))._().
+          td().a(url("attempts", jid, "m",
+              TaskAttemptStateUI.FAILED.toString()), 
+              String.valueOf(failedMapAttempts))._().
+          td().a(url("attempts", jid, "m",
+              TaskAttemptStateUI.KILLED.toString()), 
+              String.valueOf(killedMapAttempts))._().
+          td().a(url("attempts", jid, "m",
+              TaskAttemptStateUI.SUCCESSFUL.toString()), 
+              String.valueOf(successfulMapAttempts))._().
+        _().
+        tr(_EVEN).
+          th("Reduces").
+          td().a(url("attempts", jid, "r",
+              TaskAttemptStateUI.NEW.toString()), 
+              String.valueOf(newReduceAttempts))._().
+          td().a(url("attempts", jid, "r",
+              TaskAttemptStateUI.RUNNING.toString()), 
+              String.valueOf(runningReduceAttempts))._().
+          td().a(url("attempts", jid, "r",
+              TaskAttemptStateUI.FAILED.toString()), 
+              String.valueOf(failedReduceAttempts))._().
+          td().a(url("attempts", jid, "r",
+              TaskAttemptStateUI.KILLED.toString()), 
+              String.valueOf(killedReduceAttempts))._().
+          td().a(url("attempts", jid, "r",
+              TaskAttemptStateUI.SUCCESSFUL.toString()), 
+              String.valueOf(successfulReduceAttempts))._().
+         _().
+       _().
+     _();
   }
 
-  private void countTasks(Job job) {
+  private void countTasksAndAttempts(Job job) {
     Map<TaskId, Task> tasks = job.getTasks();
     for (Task task : tasks.values()) {
       switch (task.getType()) {
-        case MAP: switch (task.getState()) {
-          case RUNNING:   ++runningMaps;  break;
-          case SCHEDULED: ++pendingMaps;  break;
-        } break;
-        case REDUCE: switch(task.getState()) {
-          case RUNNING:   ++runningReds;  break;
-          case SCHEDULED: ++pendingReds;  break;
-        } break;
+      case MAP:
+        // Task counts
+        switch (task.getState()) {
+        case RUNNING:
+          ++runningMapTasks;
+          break;
+        case SCHEDULED:
+          ++pendingMapTasks;
+          break;
+        }
+        break;
+      case REDUCE:
+        // Task counts
+        switch (task.getState()) {
+        case RUNNING:
+          ++runningReduceTasks;
+          break;
+        case SCHEDULED:
+          ++pendingReduceTasks;
+          break;
+        }
+        break;
+      }
+
+      // Attempts counts
+      Map<TaskAttemptId, TaskAttempt> attempts = task.getAttempts();
+      for (TaskAttempt attempt : attempts.values()) {
+
+        int newAttempts = 0, running = 0, successful = 0, failed = 0, killed =0;
+
+        if (TaskAttemptStateUI.NEW.correspondsTo(attempt.getState())) {
+          ++newAttempts;
+        } else if (TaskAttemptStateUI.RUNNING.correspondsTo(attempt
+            .getState())) {
+          ++running;
+        } else if (TaskAttemptStateUI.SUCCESSFUL.correspondsTo(attempt
+            .getState())) {
+          ++successful;
+        } else if (TaskAttemptStateUI.FAILED
+            .correspondsTo(attempt.getState())) {
+          ++failed;
+        } else if (TaskAttemptStateUI.KILLED
+            .correspondsTo(attempt.getState())) {
+          ++killed;
+        }
+
+        switch (task.getType()) {
+        case MAP:
+          newMapAttempts += newAttempts;
+          runningMapAttempts += running;
+          successfulMapAttempts += successful;
+          failedMapAttempts += failed;
+          killedMapAttempts += killed;
+          break;
+        case REDUCE:
+          newReduceAttempts += newAttempts;
+          runningReduceAttempts += running;
+          successfulReduceAttempts += successful;
+          failedReduceAttempts += failed;
+          killedReduceAttempts += killed;
+          break;
+        }
       }
     }
   }

Modified: hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/TaskPage.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/TaskPage.java?rev=1134652&r1=1134651&r2=1134652&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/TaskPage.java
(original)
+++ hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/webapp/TaskPage.java
Sat Jun 11 14:16:58 2011
@@ -18,6 +18,8 @@
 
 package org.apache.hadoop.mapreduce.v2.app.webapp;
 
+import java.util.Collection;
+
 import com.google.common.base.Joiner;
 import com.google.inject.Inject;
 
@@ -46,7 +48,7 @@ public class TaskPage extends AppView {
 
     @Override
     protected void render(Block html) {
-      if (app.task == null) {
+      if (!isValidRequest()) {
         html.
           h2($(TITLE));
         return;
@@ -64,7 +66,7 @@ public class TaskPage extends AppView {
             th(".tsh", "Elapsed").
             th(".note", "Note")._()._().
         tbody();
-      for (TaskAttempt ta : app.task.getAttempts().values()) {
+      for (TaskAttempt ta : getTaskAttempts()) {
         String taid = MRApps.toString(ta.getID());
         String progress = percent(ta.getProgress());
         ContainerId containerId = ta.getAssignedContainerID();
@@ -94,6 +96,14 @@ public class TaskPage extends AppView {
       }
       tbody._()._();
     }
+
+    protected boolean isValidRequest() {
+      return app.task != null;
+    }
+
+    protected Collection<TaskAttempt> getTaskAttempts() {
+      return app.task.getAttempts().values();
+    }
   }
 
   @Override protected void preHead(Page.HTML<_> html) {

Modified: hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/util/MRApps.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/util/MRApps.java?rev=1134652&r1=1134651&r2=1134652&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/util/MRApps.java
(original)
+++ hadoop/mapreduce/branches/MR-279/mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/util/MRApps.java
Sat Jun 11 14:16:58 2011
@@ -25,7 +25,9 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.hadoop.conf.Configuration;
@@ -33,6 +35,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapreduce.v2.MRConstants;
 import org.apache.hadoop.mapreduce.v2.api.records.JobId;
 import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
+import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptState;
 import org.apache.hadoop.mapreduce.v2.api.records.TaskId;
 import org.apache.hadoop.mapreduce.v2.api.records.TaskType;
 import org.apache.hadoop.util.Shell.ShellCommandExecutor;
@@ -113,6 +116,33 @@ public class MRApps extends Apps {
     throw new YarnException("Unknown task type: "+ type.toString());
   }
 
+  public static enum TaskAttemptStateUI {
+    NEW(
+        new TaskAttemptState[] { TaskAttemptState.NEW,
+        TaskAttemptState.UNASSIGNED, TaskAttemptState.ASSIGNED }),
+    RUNNING(
+        new TaskAttemptState[] { TaskAttemptState.RUNNING,
+            TaskAttemptState.COMMIT_PENDING,
+            TaskAttemptState.SUCCESS_CONTAINER_CLEANUP,
+            TaskAttemptState.FAIL_CONTAINER_CLEANUP,
+            TaskAttemptState.FAIL_TASK_CLEANUP,
+            TaskAttemptState.KILL_CONTAINER_CLEANUP,
+            TaskAttemptState.KILL_TASK_CLEANUP }),
+    SUCCESSFUL(new TaskAttemptState[] { TaskAttemptState.SUCCEEDED}),
+    FAILED(new TaskAttemptState[] { TaskAttemptState.FAILED}),
+    KILLED(new TaskAttemptState[] { TaskAttemptState.KILLED});
+
+    private final List<TaskAttemptState> correspondingStates;
+
+    private TaskAttemptStateUI(TaskAttemptState[] correspondingStates) {
+      this.correspondingStates = Arrays.asList(correspondingStates);
+    }
+
+    public boolean correspondsTo(TaskAttemptState state) {
+      return this.correspondingStates.contains(state);
+    }
+  }
+
   public static TaskType taskType(String symbol) {
     // JDK 7 supports switch on strings
     if (symbol.equals("m")) return TaskType.MAP;
@@ -120,6 +150,10 @@ public class MRApps extends Apps {
     throw new YarnException("Unknown task symbol: "+ symbol);
   }
 
+  public static TaskAttemptStateUI taskAttemptState(String attemptStateStr) {
+    return TaskAttemptStateUI.valueOf(attemptStateStr);
+  }
+
   public static void setInitialClasspath(
       Map<String, String> environment) throws IOException {
 



Mime
View raw message