@Test public void testErrorMessage() throws Exception { JobContext jobContext = Mockito.mock(JobContext.class); JobState jobState = new JobState("jobName", "1234"); TaskState taskState1 = new TaskState(); TaskState taskState2 = new TaskState(); taskState1.setTaskId("1"); taskState1.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, "exception1"); taskState2.setTaskId("2"); taskState2.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, "exception2"); taskState2.setProp(EventMetadataUtils.TASK_FAILURE_MESSAGE_KEY, "failureMessage2"); jobState.addTaskState(taskState1); jobState.addTaskState(taskState2); Mockito.when(jobContext.getJobState()).thenReturn(jobState); ClusterEventMetadataGenerator metadataGenerator = new ClusterEventMetadataGenerator(); Map<String, String> metadata; metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_COMMIT); Assert.assertEquals(metadata.get("message"), null); metadata = metadataGenerator.getMetadata(jobContext, EventName.JOB_FAILED); Assert.assertTrue(metadata.get("message").startsWith("failureMessage")); Assert.assertTrue(metadata.get("message").contains("exception1")); Assert.assertTrue(metadata.get("message").contains("exception2")); }
public Map<String, String> getMetadata(JobContext jobContext, EventName eventName) { List<TaskState> taskStates = jobContext.getJobState().getTaskStates(); String taskException = EventMetadataUtils.getTaskFailureExceptions(taskStates); String jobException = EventMetadataUtils.getJobFailureExceptions(jobContext.getJobState()); switch (eventName) { case JOB_COMPLETE: return ImmutableMap.of(PROCESSED_COUNT_KEY, Long.toString(EventMetadataUtils.getProcessedCount(taskStates))); case JOB_FAILED: return ImmutableMap.of(MESSAGE_KEY, taskException.length() != 0 ? taskException : jobException); default: break; } return ImmutableMap.of(); }
ClusterEventMetadataGenerator implements EventMetadataGenerator { public Map<String, String> getMetadata(JobContext jobContext, EventName eventName) { List<TaskState> taskStates = jobContext.getJobState().getTaskStates(); String taskException = EventMetadataUtils.getTaskFailureExceptions(taskStates); String jobException = EventMetadataUtils.getJobFailureExceptions(jobContext.getJobState()); switch (eventName) { case JOB_COMPLETE: return ImmutableMap.of(PROCESSED_COUNT_KEY, Long.toString(EventMetadataUtils.getProcessedCount(taskStates))); case JOB_FAILED: return ImmutableMap.of(MESSAGE_KEY, taskException.length() != 0 ? taskException : jobException); default: break; } return ImmutableMap.of(); } }
ClusterEventMetadataGenerator implements EventMetadataGenerator { public Map<String, String> getMetadata(JobContext jobContext, EventName eventName) { List<TaskState> taskStates = jobContext.getJobState().getTaskStates(); String taskException = EventMetadataUtils.getTaskFailureExceptions(taskStates); String jobException = EventMetadataUtils.getJobFailureExceptions(jobContext.getJobState()); switch (eventName) { case JOB_COMPLETE: return ImmutableMap.of(PROCESSED_COUNT_KEY, Long.toString(EventMetadataUtils.getProcessedCount(taskStates))); case JOB_FAILED: return ImmutableMap.of(MESSAGE_KEY, taskException.length() != 0 ? taskException : jobException); default: break; } return ImmutableMap.of(); }  }
ClusterEventMetadataGenerator implements EventMetadataGenerator { public Map<String, String> getMetadata(JobContext jobContext, EventName eventName) { List<TaskState> taskStates = jobContext.getJobState().getTaskStates(); String taskException = EventMetadataUtils.getTaskFailureExceptions(taskStates); String jobException = EventMetadataUtils.getJobFailureExceptions(jobContext.getJobState()); switch (eventName) { case JOB_COMPLETE: return ImmutableMap.of(PROCESSED_COUNT_KEY, Long.toString(EventMetadataUtils.getProcessedCount(taskStates))); case JOB_FAILED: return ImmutableMap.of(MESSAGE_KEY, taskException.length() != 0 ? taskException : jobException); default: break; } return ImmutableMap.of(); }  Map<String, String> getMetadata(JobContext jobContext, EventName eventName); }
ClusterEventMetadataGenerator implements EventMetadataGenerator { public Map<String, String> getMetadata(JobContext jobContext, EventName eventName) { List<TaskState> taskStates = jobContext.getJobState().getTaskStates(); String taskException = EventMetadataUtils.getTaskFailureExceptions(taskStates); String jobException = EventMetadataUtils.getJobFailureExceptions(jobContext.getJobState()); switch (eventName) { case JOB_COMPLETE: return ImmutableMap.of(PROCESSED_COUNT_KEY, Long.toString(EventMetadataUtils.getProcessedCount(taskStates))); case JOB_FAILED: return ImmutableMap.of(MESSAGE_KEY, taskException.length() != 0 ? taskException : jobException); default: break; } return ImmutableMap.of(); }  Map<String, String> getMetadata(JobContext jobContext, EventName eventName); static final String PROCESSED_COUNT_KEY; static final String MESSAGE_KEY; }