private void finishRunningTask(TaskStatus finalStatus, long now) {
    TaskAttemptID taskId = finalStatus.getTaskID();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Finishing running task id=" + taskId + ", now=" + now);
    }

    SimulatorTaskInProgress tip = tasks.get(taskId);
    if (tip == null) {
      throw new IllegalArgumentException("Unknown task attempt " + taskId
          + " completed");
    }
    TaskStatus currentStatus = tip.getTaskStatus();
    if (currentStatus.getRunState() != State.RUNNING) {
      throw new IllegalArgumentException(
          "Task attempt to finish is not running: " + tip);
    }

    // Check that finalStatus describes a task attempt that has just been
    // completed
    State finalRunState = finalStatus.getRunState();
    if (finalRunState != State.SUCCEEDED && finalRunState != State.FAILED
        && finalRunState != State.KILLED) {
      throw new IllegalArgumentException(
          "Final run state for completed task can't be : " + finalRunState
              + " " + tip);
    }

    if (now != finalStatus.getFinishTime()) {
      throw new IllegalArgumentException(
          "Current time does not match task finish time: now=" + now
              + ", finish=" + finalStatus.getFinishTime());
    }

    if (currentStatus.getIsMap() != finalStatus.getIsMap()
        || currentStatus.getNumSlots() != finalStatus.getNumSlots()
        || currentStatus.getPhase() != finalStatus.getPhase()
        || currentStatus.getStartTime() != finalStatus.getStartTime()) {
      throw new IllegalArgumentException(
          "Current status does not match final status");
    }

    // We can't assert getShuffleFinishTime() and getSortFinishTime() for
    // reduces as those were unknown when the task attempt completion event
    // was created. We have not called setMapFinishTime() for maps either.
    // If we were really thorough we could update the progress of the task
    // and check if it is consistent with finalStatus.

    // If we've got this far it is safe to update the task status
    currentStatus.setRunState(finalStatus.getRunState());
    currentStatus.setFinishTime(finalStatus.getFinishTime());
    currentStatus.setProgress(finalStatus.getProgress());

    // and update the free slots
    int numSlots = currentStatus.getNumSlots();
    if (tip.isMapTask()) {
      usedMapSlots -= numSlots;
      if (usedMapSlots < 0) {
        throw new IllegalStateException(
            "TaskTracker reaches negative map slots: " + usedMapSlots);
      }
    } else {
      usedReduceSlots -= numSlots;
      if (usedReduceSlots < 0) {
        throw new IllegalStateException(
            "TaskTracker reaches negative reduce slots: " + usedReduceSlots);
      }
    }
  }
private void finishRunningTask ( TaskStatus finalStatus , long now ) { TaskAttemptID taskId = finalStatus . getTaskID ( ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Finishing running task id=" + taskId + ", now=" + now ) ; } SimulatorTaskInProgress tip = tasks . get ( taskId ) ; if ( tip == null ) { throw new IllegalArgumentException ( "Unknown task attempt " + taskId + " completed" ) ; } TaskStatus currentStatus = tip . getTaskStatus ( ) ; if ( currentStatus . getRunState ( ) != State . RUNNING ) { throw new IllegalArgumentException ( "Task attempt to finish is not running: " + tip ) ; } State finalRunState = finalStatus . getRunState ( ) ; if ( finalRunState != State . SUCCEEDED && finalRunState != State . FAILED && finalRunState != State . KILLED ) { throw new IllegalArgumentException ( "Final run state for completed task can't be : " + finalRunState + " " + tip ) ; } if ( now != finalStatus . getFinishTime ( ) ) { throw new IllegalArgumentException ( "Current time does not match task finish time: now=" + now + ", finish=" + finalStatus . getFinishTime ( ) ) ; } if ( currentStatus . getIsMap ( ) != finalStatus . getIsMap ( ) || currentStatus . getNumSlots ( ) != finalStatus . getNumSlots ( ) || currentStatus . getPhase ( ) != finalStatus . getPhase ( ) || currentStatus . getStartTime ( ) != finalStatus . getStartTime ( ) ) { throw new IllegalArgumentException ( "Current status does not match final status" ) ; } currentStatus . setRunState ( finalStatus . getRunState ( ) ) ; currentStatus . setFinishTime ( finalStatus . getFinishTime ( ) ) ; currentStatus . setProgress ( finalStatus . getProgress ( ) ) ; int numSlots = currentStatus . getNumSlots ( ) ; if ( tip . isMapTask ( ) ) { usedMapSlots -= numSlots ; if ( usedMapSlots < 0 ) { throw new IllegalStateException ( "TaskTracker reaches negative map slots: " + usedMapSlots ) ; } } else { usedReduceSlots -= numSlots ; if ( usedReduceSlots < 0 ) { throw new IllegalStateException ( "TaskTracker reaches negative reduce slots: " + usedReduceSlots ) ; } } }
Stops running a task attempt on the task tracker. It also updates the
number of available slots accordingly.

@param finalStatus the TaskStatus containing the task id and final
status of the task attempt. This rountine asserts a lot of the
finalStatus params, in case it is coming from a task attempt
completion event sent to ourselves. Only the run state, finish time,
and progress fields of the task attempt are updated.
@param now Current simulation time, used for assert only