Java Code Examples for org.apache.hadoop.mapreduce.JobCounter#NUM_FAILED_MAPS

The following examples show how to use org.apache.hadoop.mapreduce.JobCounter#NUM_FAILED_MAPS . 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: TestRecovery.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void recoveryChecker(MapTaskImpl checkTask, TaskState finalState,
    Map<TaskAttemptID, TaskAttemptState> finalAttemptStates,
    ArgumentCaptor<Event> arg, List<EventType> expectedJobHistoryEvents,
    long expectedMapLaunches, long expectedFailedMaps) {

  assertEquals("Final State of Task", finalState, checkTask.getState());

  Map<TaskAttemptId, TaskAttempt> recoveredAttempts =
      checkTask.getAttempts();
  assertEquals("Expected Number of Task Attempts",
      finalAttemptStates.size(), recoveredAttempts.size());
  for (TaskAttemptID taID : finalAttemptStates.keySet()) {
    assertEquals("Expected Task Attempt State",
        finalAttemptStates.get(taID),
        recoveredAttempts.get(TypeConverter.toYarn(taID)).getState());
  }

  Iterator<Event> ie = arg.getAllValues().iterator();
  int eventNum = 0;
  long totalLaunchedMaps = 0;
  long totalFailedMaps = 0;
  boolean jobTaskEventReceived = false;

  while (ie.hasNext()) {
    Object current = ie.next();
    ++eventNum;
    LOG.info(eventNum + " " + current.getClass().getName());
    if (current instanceof JobHistoryEvent) {
      JobHistoryEvent jhe = (JobHistoryEvent) current;
      LOG.info(expectedJobHistoryEvents.get(0).toString() + " " +
          jhe.getHistoryEvent().getEventType().toString() + " " +
          jhe.getJobID());
      assertEquals(expectedJobHistoryEvents.get(0),
          jhe.getHistoryEvent().getEventType());
      expectedJobHistoryEvents.remove(0);
    }  else if (current instanceof JobCounterUpdateEvent) {
      JobCounterUpdateEvent jcue = (JobCounterUpdateEvent) current;

      LOG.info("JobCounterUpdateEvent "
          + jcue.getCounterUpdates().get(0).getCounterKey()
          + " " + jcue.getCounterUpdates().get(0).getIncrementValue());
      if (jcue.getCounterUpdates().get(0).getCounterKey() ==
          JobCounter.NUM_FAILED_MAPS) {
        totalFailedMaps += jcue.getCounterUpdates().get(0)
            .getIncrementValue();
      } else if (jcue.getCounterUpdates().get(0).getCounterKey() ==
          JobCounter.TOTAL_LAUNCHED_MAPS) {
        totalLaunchedMaps += jcue.getCounterUpdates().get(0)
            .getIncrementValue();
      }
    } else if (current instanceof JobTaskEvent) {
      JobTaskEvent jte = (JobTaskEvent) current;
      assertEquals(jte.getState(), finalState);
      jobTaskEventReceived = true;
    }
  }
  assertTrue(jobTaskEventReceived || (finalState == TaskState.RUNNING));
  assertEquals("Did not process all expected JobHistoryEvents",
      0, expectedJobHistoryEvents.size());
  assertEquals("Expected Map Launches",
      expectedMapLaunches, totalLaunchedMaps);
  assertEquals("Expected Failed Maps",
      expectedFailedMaps, totalFailedMaps);
}
 
Example 2
Source File: TestRecovery.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void recoveryChecker(MapTaskImpl checkTask, TaskState finalState,
    Map<TaskAttemptID, TaskAttemptState> finalAttemptStates,
    ArgumentCaptor<Event> arg, List<EventType> expectedJobHistoryEvents,
    long expectedMapLaunches, long expectedFailedMaps) {

  assertEquals("Final State of Task", finalState, checkTask.getState());

  Map<TaskAttemptId, TaskAttempt> recoveredAttempts =
      checkTask.getAttempts();
  assertEquals("Expected Number of Task Attempts",
      finalAttemptStates.size(), recoveredAttempts.size());
  for (TaskAttemptID taID : finalAttemptStates.keySet()) {
    assertEquals("Expected Task Attempt State",
        finalAttemptStates.get(taID),
        recoveredAttempts.get(TypeConverter.toYarn(taID)).getState());
  }

  Iterator<Event> ie = arg.getAllValues().iterator();
  int eventNum = 0;
  long totalLaunchedMaps = 0;
  long totalFailedMaps = 0;
  boolean jobTaskEventReceived = false;

  while (ie.hasNext()) {
    Object current = ie.next();
    ++eventNum;
    LOG.info(eventNum + " " + current.getClass().getName());
    if (current instanceof JobHistoryEvent) {
      JobHistoryEvent jhe = (JobHistoryEvent) current;
      LOG.info(expectedJobHistoryEvents.get(0).toString() + " " +
          jhe.getHistoryEvent().getEventType().toString() + " " +
          jhe.getJobID());
      assertEquals(expectedJobHistoryEvents.get(0),
          jhe.getHistoryEvent().getEventType());
      expectedJobHistoryEvents.remove(0);
    }  else if (current instanceof JobCounterUpdateEvent) {
      JobCounterUpdateEvent jcue = (JobCounterUpdateEvent) current;

      LOG.info("JobCounterUpdateEvent "
          + jcue.getCounterUpdates().get(0).getCounterKey()
          + " " + jcue.getCounterUpdates().get(0).getIncrementValue());
      if (jcue.getCounterUpdates().get(0).getCounterKey() ==
          JobCounter.NUM_FAILED_MAPS) {
        totalFailedMaps += jcue.getCounterUpdates().get(0)
            .getIncrementValue();
      } else if (jcue.getCounterUpdates().get(0).getCounterKey() ==
          JobCounter.TOTAL_LAUNCHED_MAPS) {
        totalLaunchedMaps += jcue.getCounterUpdates().get(0)
            .getIncrementValue();
      }
    } else if (current instanceof JobTaskEvent) {
      JobTaskEvent jte = (JobTaskEvent) current;
      assertEquals(jte.getState(), finalState);
      jobTaskEventReceived = true;
    }
  }
  assertTrue(jobTaskEventReceived || (finalState == TaskState.RUNNING));
  assertEquals("Did not process all expected JobHistoryEvents",
      0, expectedJobHistoryEvents.size());
  assertEquals("Expected Map Launches",
      expectedMapLaunches, totalLaunchedMaps);
  assertEquals("Expected Failed Maps",
      expectedFailedMaps, totalFailedMaps);
}