Java Code Examples for org.apache.hadoop.mapreduce.v2.app.job.Task#getState()

The following examples show how to use org.apache.hadoop.mapreduce.v2.app.job.Task#getState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobInfo.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Go through a job and update the member variables with counts for
 * information to output in the page.
 *
 * @param job
 *          the job to get counts for.
 */
private void countTasksAndAttempts(Job job) {
  final Map<TaskId, Task> tasks = job.getTasks();
  if (tasks == null) {
    return;
  }
  for (Task task : tasks.values()) {
    switch (task.getType()) {
    case MAP:
      // Task counts
      switch (task.getState()) {
      case RUNNING:
        ++this.mapsRunning;
        break;
      case SCHEDULED:
        ++this.mapsPending;
        break;
      default:
        break;
      }
      break;
    case REDUCE:
      // Task counts
      switch (task.getState()) {
      case RUNNING:
        ++this.reducesRunning;
        break;
      case SCHEDULED:
        ++this.reducesPending;
        break;
      default:
        break;
      }
      break;
    default:
      throw new IllegalStateException(
          "Task type is neither map nor reduce: " + task.getType());
    }
    // Attempts counts
    Map<TaskAttemptId, TaskAttempt> attempts = task.getAttempts();
    int newAttempts, running, successful, failed, killed;
    for (TaskAttempt attempt : attempts.values()) {

      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:
        this.newMapAttempts += newAttempts;
        this.runningMapAttempts += running;
        this.successfulMapAttempts += successful;
        this.failedMapAttempts += failed;
        this.killedMapAttempts += killed;
        break;
      case REDUCE:
        this.newReduceAttempts += newAttempts;
        this.runningReduceAttempts += running;
        this.successfulReduceAttempts += successful;
        this.failedReduceAttempts += failed;
        this.killedReduceAttempts += killed;
        break;
      default:
        throw new IllegalStateException("Task type neither map nor reduce: " + 
            task.getType());
      }
    }
  }
}
 
Example 2
Source File: JobInfo.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Go through a job and update the member variables with counts for
 * information to output in the page.
 *
 * @param job
 *          the job to get counts for.
 */
private void countTasksAndAttempts(Job job) {
  final Map<TaskId, Task> tasks = job.getTasks();
  if (tasks == null) {
    return;
  }
  for (Task task : tasks.values()) {
    switch (task.getType()) {
    case MAP:
      // Task counts
      switch (task.getState()) {
      case RUNNING:
        ++this.mapsRunning;
        break;
      case SCHEDULED:
        ++this.mapsPending;
        break;
      default:
        break;
      }
      break;
    case REDUCE:
      // Task counts
      switch (task.getState()) {
      case RUNNING:
        ++this.reducesRunning;
        break;
      case SCHEDULED:
        ++this.reducesPending;
        break;
      default:
        break;
      }
      break;
    default:
      throw new IllegalStateException(
          "Task type is neither map nor reduce: " + task.getType());
    }
    // Attempts counts
    Map<TaskAttemptId, TaskAttempt> attempts = task.getAttempts();
    int newAttempts, running, successful, failed, killed;
    for (TaskAttempt attempt : attempts.values()) {

      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:
        this.newMapAttempts += newAttempts;
        this.runningMapAttempts += running;
        this.successfulMapAttempts += successful;
        this.failedMapAttempts += failed;
        this.killedMapAttempts += killed;
        break;
      case REDUCE:
        this.newReduceAttempts += newAttempts;
        this.runningReduceAttempts += running;
        this.successfulReduceAttempts += successful;
        this.failedReduceAttempts += failed;
        this.killedReduceAttempts += killed;
        break;
      default:
        throw new IllegalStateException("Task type neither map nor reduce: " + 
            task.getType());
      }
    }
  }
}