use of org.apache.tez.dag.history.events.TaskAttemptStartedEvent in project tez by apache.
the class TestDAGRecovery method testTARecoverFromSucceeded.
/**
* RecoveryEvents: TaskAttemptStartedEvent -> TaskAttemptFinishedEvent (SUCCEEDED)
* Recover it to SUCCEEDED
*/
@Test(timeout = 5000)
public void testTARecoverFromSucceeded() {
initMockDAGRecoveryDataForTaskAttempt();
TaskAttemptStartedEvent taStartedEvent = new TaskAttemptStartedEvent(ta1t1v1Id, "v1", ta1LaunchTime, mock(ContainerId.class), mock(NodeId.class), "", "", "");
List<TezEvent> taGeneratedEvents = new ArrayList<TezEvent>();
EventMetaData sourceInfo = new EventMetaData(EventProducerConsumerType.INPUT, "vertex1", "vertex3", ta1t1v1Id);
taGeneratedEvents.add(new TezEvent(DataMovementEvent.create(ByteBuffer.wrap(new byte[0])), sourceInfo));
TaskAttemptFinishedEvent taFinishedEvent = new TaskAttemptFinishedEvent(ta1t1v1Id, "v1", ta1LaunchTime, ta1FinishedTime, TaskAttemptState.SUCCEEDED, null, null, "", null, null, taGeneratedEvents, 0L, null, 0L, null, null, null, null, null);
TaskAttemptRecoveryData taRecoveryData = new TaskAttemptRecoveryData(taStartedEvent, taFinishedEvent);
doReturn(taRecoveryData).when(dagRecoveryData).getTaskAttemptRecoveryData(ta1t1v1Id);
dag.handle(new DAGEventRecoverEvent(dagId, dagRecoveryData));
dispatcher.await();
TaskImpl task = (TaskImpl) dag.getVertex(v1Id).getTask(t1v1Id);
TaskAttemptImpl taskAttempt = (TaskAttemptImpl) task.getAttempt(ta1t1v1Id);
assertEquals(TaskAttemptStateInternal.SUCCEEDED, taskAttempt.getInternalState());
historyEventHandler.verifyHistoryEvent(0, HistoryEventType.TASK_ATTEMPT_FINISHED);
assertEquals(TaskStateInternal.SUCCEEDED, task.getInternalState());
assertEquals(ta1LaunchTime, taskAttempt.getLaunchTime());
assertEquals(ta1FinishedTime, taskAttempt.getFinishTime());
}
use of org.apache.tez.dag.history.events.TaskAttemptStartedEvent in project tez by apache.
the class TestDAGRecovery method testTARecoverFromRunning.
/**
* RecoveryEvents: TaskAttemptStartedEvent
* Recover it to KILLED
*/
@Test(timeout = 5000)
public void testTARecoverFromRunning() {
initMockDAGRecoveryDataForTaskAttempt();
TaskAttemptStartedEvent taStartedEvent = new TaskAttemptStartedEvent(ta1t1v1Id, "v1", ta1LaunchTime, mock(ContainerId.class), mock(NodeId.class), "", "", "");
TaskAttemptRecoveryData taRecoveryData = new TaskAttemptRecoveryData(taStartedEvent, null);
doReturn(taRecoveryData).when(dagRecoveryData).getTaskAttemptRecoveryData(ta1t1v1Id);
dag.handle(new DAGEventRecoverEvent(dagId, dagRecoveryData));
dispatcher.await();
TaskImpl task = (TaskImpl) dag.getVertex(v1Id).getTask(t1v1Id);
TaskAttemptImpl taskAttempt = (TaskAttemptImpl) task.getAttempt(ta1t1v1Id);
assertEquals(TaskAttemptStateInternal.KILLED, taskAttempt.getInternalState());
assertEquals(TaskAttemptTerminationCause.TERMINATED_AT_RECOVERY, taskAttempt.getTerminationCause());
historyEventHandler.verifyHistoryEvent(0, HistoryEventType.TASK_ATTEMPT_STARTED);
historyEventHandler.verifyHistoryEvent(1, HistoryEventType.TASK_ATTEMPT_FINISHED);
assertEquals(ta1LaunchTime, taskAttempt.getLaunchTime());
}
use of org.apache.tez.dag.history.events.TaskAttemptStartedEvent in project tez by apache.
the class TestRecoveryParser method testRecoveryData.
@Test(timeout = 5000)
public void testRecoveryData() throws IOException {
ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
TezDAGID dagID = TezDAGID.getInstance(appId, 1);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
AppContext appContext = mock(AppContext.class);
when(appContext.getCurrentRecoveryDir()).thenReturn(new Path(recoveryPath + "/1"));
when(appContext.getClock()).thenReturn(new SystemClock());
when(mockDAGImpl.getID()).thenReturn(dagID);
when(appContext.getHadoopShim()).thenReturn(new DefaultHadoopShim());
when(appContext.getApplicationID()).thenReturn(appId);
RecoveryService rService = new RecoveryService(appContext);
Configuration conf = new Configuration();
conf.setBoolean(RecoveryService.TEZ_TEST_RECOVERY_DRAIN_EVENTS_WHEN_STOPPED, true);
rService.init(conf);
rService.start();
DAGPlan dagPlan = TestDAGImpl.createTestDAGPlan();
// DAG DAGSubmittedEvent -> DAGInitializedEvent -> DAGStartedEvent
rService.handle(new DAGHistoryEvent(dagID, new DAGSubmittedEvent(dagID, 1L, dagPlan, ApplicationAttemptId.newInstance(appId, 1), null, "user", new Configuration(), null, null)));
DAGInitializedEvent dagInitedEvent = new DAGInitializedEvent(dagID, 100L, "user", "dagName", null);
DAGStartedEvent dagStartedEvent = new DAGStartedEvent(dagID, 0L, "user", "dagName");
rService.handle(new DAGHistoryEvent(dagID, dagInitedEvent));
rService.handle(new DAGHistoryEvent(dagID, dagStartedEvent));
// 3 vertices of this dag: v0, v1, v2
TezVertexID v0Id = TezVertexID.getInstance(dagID, 0);
TezVertexID v1Id = TezVertexID.getInstance(dagID, 1);
TezVertexID v2Id = TezVertexID.getInstance(dagID, 2);
// v0 VertexInitializedEvent
VertexInitializedEvent v0InitedEvent = new VertexInitializedEvent(v0Id, "v0", 200L, 400L, 2, null, null, null, null);
rService.handle(new DAGHistoryEvent(dagID, v0InitedEvent));
// v1 VertexFinishedEvent(KILLED)
VertexFinishedEvent v1FinishedEvent = new VertexFinishedEvent(v1Id, "v1", 2, 300L, 400L, 500L, 600L, 700L, VertexState.KILLED, "", null, null, null, null);
rService.handle(new DAGHistoryEvent(dagID, v1FinishedEvent));
// v2 VertexInitializedEvent -> VertexStartedEvent
List<TezEvent> initGeneratedEvents = Lists.newArrayList(new TezEvent(DataMovementEvent.create(ByteBuffer.wrap(new byte[0])), null));
VertexInitializedEvent v2InitedEvent = new VertexInitializedEvent(v2Id, "v2", 200L, 300L, 2, null, null, initGeneratedEvents, null);
VertexStartedEvent v2StartedEvent = new VertexStartedEvent(v2Id, 0L, 0L);
rService.handle(new DAGHistoryEvent(dagID, v2InitedEvent));
rService.handle(new DAGHistoryEvent(dagID, v2StartedEvent));
// 3 tasks of v2
TezTaskID t0v2Id = TezTaskID.getInstance(v2Id, 0);
TezTaskID t1v2Id = TezTaskID.getInstance(v2Id, 1);
TezTaskID t2v2Id = TezTaskID.getInstance(v2Id, 2);
// t0v2 TaskStartedEvent
TaskStartedEvent t0v2StartedEvent = new TaskStartedEvent(t0v2Id, "v2", 400L, 5000L);
rService.handle(new DAGHistoryEvent(dagID, t0v2StartedEvent));
// t1v2 TaskFinishedEvent
TaskFinishedEvent t1v2FinishedEvent = new TaskFinishedEvent(t1v2Id, "v1", 0L, 0L, null, TaskState.KILLED, "", null, 4);
rService.handle(new DAGHistoryEvent(dagID, t1v2FinishedEvent));
// t2v2 TaskStartedEvent -> TaskFinishedEvent
TaskStartedEvent t2v2StartedEvent = new TaskStartedEvent(t2v2Id, "v2", 400L, 500L);
rService.handle(new DAGHistoryEvent(dagID, t2v2StartedEvent));
TaskFinishedEvent t2v2FinishedEvent = new TaskFinishedEvent(t2v2Id, "v1", 0L, 0L, null, TaskState.SUCCEEDED, "", null, 4);
rService.handle(new DAGHistoryEvent(dagID, t2v2FinishedEvent));
// attempts under t0v2
ContainerId containerId = ContainerId.newInstance(appAttemptId, 1);
NodeId nodeId = NodeId.newInstance("localhost", 9999);
TezTaskAttemptID ta0t0v2Id = TezTaskAttemptID.getInstance(t0v2Id, 0);
TaskAttemptStartedEvent ta0t0v2StartedEvent = new TaskAttemptStartedEvent(ta0t0v2Id, "v1", 0L, containerId, nodeId, "", "", "");
rService.handle(new DAGHistoryEvent(dagID, ta0t0v2StartedEvent));
// attempts under t2v2
TezTaskAttemptID ta0t2v2Id = TezTaskAttemptID.getInstance(t2v2Id, 0);
TaskAttemptStartedEvent ta0t2v2StartedEvent = new TaskAttemptStartedEvent(ta0t2v2Id, "v1", 500L, containerId, nodeId, "", "", "");
rService.handle(new DAGHistoryEvent(dagID, ta0t2v2StartedEvent));
TaskAttemptFinishedEvent ta0t2v2FinishedEvent = new TaskAttemptFinishedEvent(ta0t2v2Id, "v1", 500L, 600L, TaskAttemptState.SUCCEEDED, null, null, "", null, null, null, 0L, null, 0L, null, null, null, null, null);
rService.handle(new DAGHistoryEvent(dagID, ta0t2v2FinishedEvent));
rService.stop();
DAGRecoveryData dagData = parser.parseRecoveryData();
assertFalse(dagData.nonRecoverable);
// There's no equals method for the history event, so here only verify the init/start/finish time of each event for simplicity
assertEquals(dagInitedEvent.getInitTime(), dagData.getDAGInitializedEvent().getInitTime());
assertEquals(dagStartedEvent.getStartTime(), dagData.getDAGStartedEvent().getStartTime());
assertNull(dagData.getDAGFinishedEvent());
VertexRecoveryData v0Data = dagData.getVertexRecoveryData(v0Id);
VertexRecoveryData v1Data = dagData.getVertexRecoveryData(v1Id);
VertexRecoveryData v2Data = dagData.getVertexRecoveryData(v2Id);
assertNotNull(v0Data);
assertNotNull(v1Data);
assertNotNull(v2Data);
assertEquals(v0InitedEvent.getInitedTime(), v0Data.getVertexInitedEvent().getInitedTime());
assertNull(v0Data.getVertexStartedEvent());
assertNull(v1Data.getVertexInitedEvent());
assertEquals(v1FinishedEvent.getFinishTime(), v1Data.getVertexFinishedEvent().getFinishTime());
assertEquals(v2InitedEvent.getInitedTime(), v2Data.getVertexInitedEvent().getInitedTime());
assertEquals(v2StartedEvent.getStartTime(), v2Data.getVertexStartedEvent().getStartTime());
TaskRecoveryData t0v2Data = dagData.getTaskRecoveryData(t0v2Id);
TaskRecoveryData t1v2Data = dagData.getTaskRecoveryData(t1v2Id);
TaskRecoveryData t2v2Data = dagData.getTaskRecoveryData(t2v2Id);
assertNotNull(t0v2Data);
assertNotNull(t1v2Data);
assertNotNull(t2v2Data);
assertEquals(t0v2StartedEvent.getStartTime(), t0v2Data.getTaskStartedEvent().getStartTime());
assertNull(t0v2Data.getTaskFinishedEvent());
assertEquals(t1v2FinishedEvent.getFinishTime(), t1v2Data.getTaskFinishedEvent().getFinishTime());
assertNull(t1v2Data.getTaskStartedEvent());
assertEquals(t2v2StartedEvent.getStartTime(), t2v2Data.getTaskStartedEvent().getStartTime());
assertEquals(t2v2FinishedEvent.getFinishTime(), t2v2Data.getTaskFinishedEvent().getFinishTime());
TaskAttemptRecoveryData ta0t0v2Data = dagData.getTaskAttemptRecoveryData(ta0t0v2Id);
TaskAttemptRecoveryData ta0t2v2Data = dagData.getTaskAttemptRecoveryData(ta0t2v2Id);
assertNotNull(ta0t0v2Data);
assertNotNull(ta0t2v2Data);
assertEquals(ta0t0v2StartedEvent.getStartTime(), ta0t0v2Data.getTaskAttemptStartedEvent().getStartTime());
assertNull(ta0t0v2Data.getTaskAttemptFinishedEvent());
assertEquals(ta0t2v2StartedEvent.getStartTime(), ta0t2v2Data.getTaskAttemptStartedEvent().getStartTime());
assertEquals(ta0t2v2FinishedEvent.getFinishTime(), ta0t2v2Data.getTaskAttemptFinishedEvent().getFinishTime());
}
use of org.apache.tez.dag.history.events.TaskAttemptStartedEvent in project tez by apache.
the class TestATSHistoryLoggingService method makeHistoryEvents.
private List<DAGHistoryEvent> makeHistoryEvents(TezDAGID dagId, ATSHistoryLoggingService service) {
List<DAGHistoryEvent> historyEvents = new ArrayList<>();
long time = System.currentTimeMillis();
Configuration conf = new Configuration(service.getConfig());
historyEvents.add(new DAGHistoryEvent(null, new AMStartedEvent(attemptId, time, "user")));
historyEvents.add(new DAGHistoryEvent(dagId, new DAGSubmittedEvent(dagId, time, DAGPlan.getDefaultInstance(), attemptId, null, "user", conf, null, "default")));
TezVertexID vertexID = TezVertexID.getInstance(dagId, 1);
historyEvents.add(new DAGHistoryEvent(dagId, new VertexStartedEvent(vertexID, time, time)));
TezTaskID tezTaskID = TezTaskID.getInstance(vertexID, 1);
historyEvents.add(new DAGHistoryEvent(dagId, new TaskStartedEvent(tezTaskID, "test", time, time)));
historyEvents.add(new DAGHistoryEvent(dagId, new TaskAttemptStartedEvent(TezTaskAttemptID.getInstance(tezTaskID, 1), "test", time, ContainerId.newContainerId(attemptId, 1), NodeId.newInstance("localhost", 8765), null, null, null)));
return historyEvents;
}
use of org.apache.tez.dag.history.events.TaskAttemptStartedEvent in project tez by apache.
the class TestHistoryEventTimelineConversion method testConvertTaskAttemptStartedEvent.
@Test(timeout = 5000)
public void testConvertTaskAttemptStartedEvent() {
long startTime = random.nextLong();
TaskAttemptStartedEvent event = new TaskAttemptStartedEvent(tezTaskAttemptID, "v1", startTime, containerId, nodeId, "inProgressURL", "logsURL", "nodeHttpAddress");
List<TimelineEntity> entities = HistoryEventTimelineConversion.convertToTimelineEntities(event);
Assert.assertEquals(1, entities.size());
TimelineEntity timelineEntity = entities.get(0);
Assert.assertEquals(EntityTypes.TEZ_TASK_ATTEMPT_ID.name(), timelineEntity.getEntityType());
Assert.assertEquals(tezTaskAttemptID.toString(), timelineEntity.getEntityId());
Assert.assertEquals(startTime, timelineEntity.getStartTime().longValue());
Assert.assertEquals(1, timelineEntity.getRelatedEntities().size());
Assert.assertTrue(timelineEntity.getRelatedEntities().get(EntityTypes.TEZ_TASK_ID.name()).contains(tezTaskID.toString()));
Assert.assertEquals(1, timelineEntity.getEvents().size());
TimelineEvent timelineEvent = timelineEntity.getEvents().get(0);
Assert.assertEquals(HistoryEventType.TASK_ATTEMPT_STARTED.name(), timelineEvent.getEventType());
Assert.assertEquals(startTime, timelineEvent.getTimestamp());
Assert.assertEquals(4, timelineEntity.getPrimaryFilters().size());
Assert.assertTrue(timelineEntity.getPrimaryFilters().get(ATSConstants.APPLICATION_ID).contains(applicationId.toString()));
Assert.assertTrue(timelineEntity.getPrimaryFilters().get(EntityTypes.TEZ_DAG_ID.name()).contains(tezDAGID.toString()));
Assert.assertTrue(timelineEntity.getPrimaryFilters().get(EntityTypes.TEZ_VERTEX_ID.name()).contains(tezVertexID.toString()));
Assert.assertTrue(timelineEntity.getPrimaryFilters().get(EntityTypes.TEZ_TASK_ID.name()).contains(tezTaskID.toString()));
Assert.assertTrue(timelineEntity.getOtherInfo().containsKey(ATSConstants.START_TIME));
Assert.assertEquals("inProgressURL", timelineEntity.getOtherInfo().get(ATSConstants.IN_PROGRESS_LOGS_URL));
Assert.assertEquals("logsURL", timelineEntity.getOtherInfo().get(ATSConstants.COMPLETED_LOGS_URL));
Assert.assertEquals(nodeId.toString(), timelineEntity.getOtherInfo().get(ATSConstants.NODE_ID));
Assert.assertEquals(containerId.toString(), timelineEntity.getOtherInfo().get(ATSConstants.CONTAINER_ID));
Assert.assertEquals("nodeHttpAddress", timelineEntity.getOtherInfo().get(ATSConstants.NODE_HTTP_ADDRESS));
Assert.assertTrue(TaskAttemptState.RUNNING.name().equals(timelineEntity.getOtherInfo().get(ATSConstants.STATUS)));
}
Aggregations