use of org.apache.tez.runtime.api.events.TaskStatusUpdateEvent in project tez by apache.
the class TestTaskAttempt method testCompletedAtSubmitted.
@Test(timeout = 5000)
public void testCompletedAtSubmitted() throws ServicePluginException {
ApplicationId appId = ApplicationId.newInstance(1, 2);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 0);
TezDAGID dagID = TezDAGID.getInstance(appId, 1);
TezVertexID vertexID = TezVertexID.getInstance(dagID, 1);
TezTaskID taskID = TezTaskID.getInstance(vertexID, 1);
MockEventHandler eventHandler = spy(new MockEventHandler());
TaskCommunicatorManagerInterface taListener = createMockTaskAttemptListener();
Configuration taskConf = new Configuration();
taskConf.setClass("fs.file.impl", StubbedFS.class, FileSystem.class);
taskConf.setBoolean("fs.file.impl.disable.cache", true);
locationHint = TaskLocationHint.createTaskLocationHint(new HashSet<String>(Arrays.asList(new String[] { "127.0.0.1" })), null);
Resource resource = Resource.newInstance(1024, 1);
NodeId nid = NodeId.newInstance("127.0.0.1", 0);
@SuppressWarnings("deprecation") ContainerId contId = ContainerId.newInstance(appAttemptId, 3);
Container container = mock(Container.class);
when(container.getId()).thenReturn(contId);
when(container.getNodeId()).thenReturn(nid);
when(container.getNodeHttpAddress()).thenReturn("localhost:0");
AMContainerMap containers = new AMContainerMap(mock(ContainerHeartbeatHandler.class), mock(TaskCommunicatorManagerInterface.class), new ContainerContextMatcher(), appCtx);
containers.addContainerIfNew(container, 0, 0, 0);
doReturn(new ClusterInfo()).when(appCtx).getClusterInfo();
doReturn(containers).when(appCtx).getAllContainers();
TaskHeartbeatHandler mockHeartbeatHandler = mock(TaskHeartbeatHandler.class);
TaskAttemptImpl taImpl = new MockTaskAttemptImpl(taskID, 1, eventHandler, taListener, taskConf, new SystemClock(), mockHeartbeatHandler, appCtx, false, resource, createFakeContainerContext(), false);
TezTaskAttemptID taskAttemptID = taImpl.getID();
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
taImpl.handle(new TaskAttemptEventSchedule(taskAttemptID, 0, 0));
taImpl.handle(new TaskAttemptEventSubmitted(taskAttemptID, contId));
assertEquals("Task attempt is not in the RUNNING state", taImpl.getState(), TaskAttemptState.STARTING);
verify(mockHeartbeatHandler).register(taskAttemptID);
int expectedEventsAtStarting = 4;
verify(eventHandler, times(expectedEventsAtStarting)).handle(arg.capture());
// Ensure status_updates are handled in the submitted state.
taImpl.handle(new TaskAttemptEventStatusUpdate(taskAttemptID, new TaskStatusUpdateEvent(null, 0.1f, null, false)));
taImpl.handle(new TaskAttemptEvent(taskAttemptID, TaskAttemptEventType.TA_DONE));
assertEquals("Task attempt is not in the SUCCEEDED state", taImpl.getState(), TaskAttemptState.SUCCEEDED);
verify(mockHeartbeatHandler).unregister(taskAttemptID);
assertEquals(0, taImpl.getDiagnostics().size());
int expectedEvenstAfterTerminating = expectedEventsAtStarting + 3;
arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(expectedEvenstAfterTerminating)).handle(arg.capture());
Event e = verifyEventType(arg.getAllValues().subList(expectedEventsAtStarting, expectedEvenstAfterTerminating), TaskEventTASucceeded.class, 1);
assertEquals(TaskEventType.T_ATTEMPT_SUCCEEDED, e.getType());
verifyEventType(arg.getAllValues().subList(expectedEventsAtStarting, expectedEvenstAfterTerminating), AMSchedulerEventTAEnded.class, 1);
verifyEventType(arg.getAllValues().subList(expectedEventsAtStarting, expectedEvenstAfterTerminating), DAGEventCounterUpdate.class, 1);
}
use of org.apache.tez.runtime.api.events.TaskStatusUpdateEvent in project tez by apache.
the class TestTaskCommunicatorManager1 method testTaskEventRouting.
@Test(timeout = 5000)
public void testTaskEventRouting() throws Exception {
List<TezEvent> events = Arrays.asList(new TezEvent(new TaskStatusUpdateEvent(null, 0.0f, null, false), new EventMetaData(EventProducerConsumerType.PROCESSOR, "v1", "v2", taskAttemptID)), new TezEvent(DataMovementEvent.create(0, ByteBuffer.wrap(new byte[0])), new EventMetaData(EventProducerConsumerType.OUTPUT, "v1", "v2", taskAttemptID)), new TezEvent(new TaskAttemptCompletedEvent(), new EventMetaData(EventProducerConsumerType.SYSTEM, "v1", "v2", taskAttemptID)));
generateHeartbeat(events, 0, 1, 0, new ArrayList<TezEvent>());
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(4)).handle(arg.capture());
final List<Event> argAllValues = arg.getAllValues();
final Event statusUpdateEvent = argAllValues.get(0);
assertEquals("First event should be status update", TaskAttemptEventType.TA_STATUS_UPDATE, statusUpdateEvent.getType());
assertEquals(false, ((TaskAttemptEventStatusUpdate) statusUpdateEvent).getReadErrorReported());
final TaskAttemptEventTezEventUpdate taEvent = (TaskAttemptEventTezEventUpdate) argAllValues.get(1);
assertEquals(1, taEvent.getTezEvents().size());
assertEquals(EventType.DATA_MOVEMENT_EVENT, taEvent.getTezEvents().get(0).getEventType());
final TaskAttemptEvent taCompleteEvent = (TaskAttemptEvent) argAllValues.get(2);
assertEquals(TaskAttemptEventType.TA_DONE, taCompleteEvent.getType());
final VertexEventRouteEvent vertexRouteEvent = (VertexEventRouteEvent) argAllValues.get(3);
assertEquals(1, vertexRouteEvent.getEvents().size());
assertEquals(EventType.DATA_MOVEMENT_EVENT, vertexRouteEvent.getEvents().get(0).getEventType());
}
use of org.apache.tez.runtime.api.events.TaskStatusUpdateEvent in project tez by apache.
the class TestTaskCommunicatorManager1 method testTaskEventRoutingWithReadError.
@Test(timeout = 5000)
public void testTaskEventRoutingWithReadError() throws Exception {
List<TezEvent> events = Arrays.asList(new TezEvent(new TaskStatusUpdateEvent(null, 0.0f, null, false), null), new TezEvent(InputReadErrorEvent.create("", 0, 0), new EventMetaData(EventProducerConsumerType.INPUT, "v2", "v1", taskAttemptID)), new TezEvent(new TaskAttemptCompletedEvent(), new EventMetaData(EventProducerConsumerType.SYSTEM, "v1", "v2", taskAttemptID)));
generateHeartbeat(events, 0, 1, 0, new ArrayList<TezEvent>());
ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(3)).handle(arg.capture());
final List<Event> argAllValues = arg.getAllValues();
final Event statusUpdateEvent = argAllValues.get(0);
assertEquals("First event should be status update", TaskAttemptEventType.TA_STATUS_UPDATE, statusUpdateEvent.getType());
assertEquals(true, ((TaskAttemptEventStatusUpdate) statusUpdateEvent).getReadErrorReported());
final Event taFinishedEvent = argAllValues.get(1);
assertEquals("Second event should be TA_DONE", TaskAttemptEventType.TA_DONE, taFinishedEvent.getType());
final Event vertexEvent = argAllValues.get(2);
final VertexEventRouteEvent vertexRouteEvent = (VertexEventRouteEvent) vertexEvent;
assertEquals("Third event should be routed to vertex", VertexEventType.V_ROUTE_EVENT, vertexEvent.getType());
assertEquals(EventType.INPUT_READ_ERROR_EVENT, vertexRouteEvent.getEvents().get(0).getEventType());
}
use of org.apache.tez.runtime.api.events.TaskStatusUpdateEvent in project tez by apache.
the class TezEvent method deserializeEvent.
private void deserializeEvent(DataInput in) throws IOException {
if (!in.readBoolean()) {
event = null;
return;
}
eventType = EventType.values()[in.readInt()];
eventReceivedTime = in.readLong();
if (eventType.equals(EventType.TASK_STATUS_UPDATE_EVENT)) {
// TODO NEWTEZ convert to PB
event = new TaskStatusUpdateEvent();
((TaskStatusUpdateEvent) event).readFields(in);
} else {
int eventBytesLen = in.readInt();
byte[] eventBytes;
CodedInputStream input;
int startOffset = 0;
if (in instanceof DataInputBuffer) {
eventBytes = ((DataInputBuffer) in).getData();
startOffset = ((DataInputBuffer) in).getPosition();
} else {
eventBytes = new byte[eventBytesLen];
in.readFully(eventBytes);
}
input = CodedInputStream.newInstance(eventBytes, startOffset, eventBytesLen);
switch(eventType) {
case CUSTOM_PROCESSOR_EVENT:
CustomProcessorEventProto cpProto = CustomProcessorEventProto.parseFrom(input);
event = ProtoConverters.convertCustomProcessorEventFromProto(cpProto);
break;
case DATA_MOVEMENT_EVENT:
DataMovementEventProto dmProto = DataMovementEventProto.parseFrom(input);
event = ProtoConverters.convertDataMovementEventFromProto(dmProto);
break;
case COMPOSITE_ROUTED_DATA_MOVEMENT_EVENT:
CompositeRoutedDataMovementEventProto edmProto = CompositeRoutedDataMovementEventProto.parseFrom(eventBytes);
event = ProtoConverters.convertCompositeRoutedDataMovementEventFromProto(edmProto);
break;
case COMPOSITE_DATA_MOVEMENT_EVENT:
CompositeEventProto cProto = CompositeEventProto.parseFrom(input);
event = ProtoConverters.convertCompositeDataMovementEventFromProto(cProto);
break;
case VERTEX_MANAGER_EVENT:
VertexManagerEventProto vmProto = VertexManagerEventProto.parseFrom(input);
event = ProtoConverters.convertVertexManagerEventFromProto(vmProto);
break;
case INPUT_READ_ERROR_EVENT:
InputReadErrorEventProto ideProto = InputReadErrorEventProto.parseFrom(input);
event = InputReadErrorEvent.create(ideProto.getDiagnostics(), ideProto.getIndex(), ideProto.getVersion());
break;
case TASK_ATTEMPT_FAILED_EVENT:
TaskAttemptFailedEventProto tfProto = TaskAttemptFailedEventProto.parseFrom(input);
event = new TaskAttemptFailedEvent(tfProto.getDiagnostics(), TezConverterUtils.failureTypeFromProto(tfProto.getTaskFailureType()));
break;
case TASK_ATTEMPT_KILLED_EVENT:
TaskAttemptKilledEventProto tkProto = TaskAttemptKilledEventProto.parseFrom(input);
event = new TaskAttemptKilledEvent(tkProto.getDiagnostics());
break;
case TASK_ATTEMPT_COMPLETED_EVENT:
event = new TaskAttemptCompletedEvent();
break;
case INPUT_FAILED_EVENT:
InputFailedEventProto ifProto = InputFailedEventProto.parseFrom(input);
event = InputFailedEvent.create(ifProto.getTargetIndex(), ifProto.getVersion());
break;
case ROOT_INPUT_DATA_INFORMATION_EVENT:
RootInputDataInformationEventProto difProto = RootInputDataInformationEventProto.parseFrom(input);
event = ProtoConverters.convertRootInputDataInformationEventFromProto(difProto);
break;
case ROOT_INPUT_INITIALIZER_EVENT:
EventProtos.RootInputInitializerEventProto riiProto = EventProtos.RootInputInitializerEventProto.parseFrom(input);
event = ProtoConverters.convertRootInputInitializerEventFromProto(riiProto);
break;
default:
// RootInputUpdatePayload event not wrapped in a TezEvent.
throw new TezUncheckedException("Unexpected TezEvent" + ", type=" + eventType);
}
if (in instanceof DataInputBuffer) {
// Skip so that position is updated
int skipped = in.skipBytes(eventBytesLen);
if (skipped != eventBytesLen) {
throw new TezUncheckedException("Expected to skip " + eventBytesLen + " bytes. Actually skipped = " + skipped);
}
}
}
}
use of org.apache.tez.runtime.api.events.TaskStatusUpdateEvent in project tez by apache.
the class TestTezEvent method testSerialization.
@Test
public void testSerialization() throws IOException {
ArrayList<TezEvent> events = new ArrayList<TezEvent>();
Configuration conf = new Configuration(true);
String confVal = RandomStringUtils.random(10000, true, true);
conf.set("testKey", confVal);
UserPayload payload = TezUtils.createUserPayloadFromConf(conf);
TezTaskAttemptID srcTAID = TezTaskAttemptID.getInstance(TezTaskID.fromString("task_1454468251169_866787_1_02_000000"), 1000);
TezTaskAttemptID destTAID = TezTaskAttemptID.getInstance(TezTaskID.fromString("task_1454468251169_866787_1_02_000000"), 2000);
EventMetaData srcInfo = new EventMetaData(EventProducerConsumerType.OUTPUT, "v1", "v2", srcTAID);
EventMetaData destInfo = new EventMetaData(EventProducerConsumerType.OUTPUT, "v3", "v4", destTAID);
// Case of size less than 4K and parsing skipped during deserialization
events.add(new TezEvent(new TaskAttemptCompletedEvent(), new EventMetaData(EventProducerConsumerType.PROCESSOR, "v1", "v2", srcTAID)));
TezEvent dmeEvent = new TezEvent(DataMovementEvent.create(1000, 3, 1, payload.getPayload()), srcInfo, System.currentTimeMillis());
dmeEvent.setDestinationInfo(destInfo);
events.add(dmeEvent);
// Different code path
events.add(new TezEvent(new TaskStatusUpdateEvent(null, 0.1f, null, false), new EventMetaData(EventProducerConsumerType.PROCESSOR, "v5", "v6", srcTAID)));
// Serialize to different types of DataOutput
// One that implements OutputStream and one that does not
DataOutputBuffer dataout = new DataOutputBuffer();
ByteArrayDataOutput bout = ByteStreams.newDataOutput();
serializeEvents(events, dataout);
serializeEvents(events, bout);
// Deserialize from different types of DataInput
// One with DataInputBuffer and another different implementation
DataInputBuffer datain = new DataInputBuffer();
datain.reset(dataout.getData(), dataout.getLength());
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dataout.getData(), 0, dataout.getLength()));
ArrayList<TezEvent> actual1 = deserializeEvents(datain);
ArrayList<TezEvent> actual2 = deserializeEvents(dis);
assertEventEquals(events, actual1);
assertEventEquals(events, actual2);
byte[] serializedBytes = bout.toByteArray();
datain.reset(serializedBytes, serializedBytes.length);
dis = new DataInputStream(new ByteArrayInputStream(serializedBytes));
actual1 = deserializeEvents(datain);
actual2 = deserializeEvents(dis);
assertEventEquals(events, actual1);
assertEventEquals(events, actual2);
}
Aggregations