use of org.apache.tez.runtime.api.events.TaskAttemptCompletedEvent 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.TaskAttemptCompletedEvent in project tez by apache.
the class TestTaskCommunicatorManager1 method testTaskEventRoutingTaskAttemptOnly.
@Test(timeout = 5000)
public void testTaskEventRoutingTaskAttemptOnly() throws Exception {
List<TezEvent> events = Arrays.asList(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(1)).handle(arg.capture());
final List<Event> argAllValues = arg.getAllValues();
final Event event = argAllValues.get(0);
// Route to TaskAttempt directly rather than through Vertex
assertEquals("only event should be route event", TaskAttemptEventType.TA_DONE, event.getType());
}
use of org.apache.tez.runtime.api.events.TaskAttemptCompletedEvent 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.TaskAttemptCompletedEvent 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.TaskAttemptCompletedEvent 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