Search in sources :

Example 1 with TaskCommunicator

use of org.apache.tez.serviceplugins.api.TaskCommunicator in project tez by apache.

the class TaskCommunicatorManager method createCustomTaskCommunicator.

@VisibleForTesting
TaskCommunicator createCustomTaskCommunicator(TaskCommunicatorContext taskCommunicatorContext, NamedEntityDescriptor taskCommDescriptor) throws TezException {
    LOG.info("Creating TaskCommunicator {}:{} " + taskCommDescriptor.getEntityName(), taskCommDescriptor.getClassName());
    Class<? extends TaskCommunicator> taskCommClazz = (Class<? extends TaskCommunicator>) ReflectionUtils.getClazz(taskCommDescriptor.getClassName());
    try {
        Constructor<? extends TaskCommunicator> ctor = taskCommClazz.getConstructor(TaskCommunicatorContext.class);
        return ctor.newInstance(taskCommunicatorContext);
    } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
        throw new TezUncheckedException(e);
    }
}
Also used : TaskCommunicator(org.apache.tez.serviceplugins.api.TaskCommunicator) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with TaskCommunicator

use of org.apache.tez.serviceplugins.api.TaskCommunicator in project tez by apache.

the class TestTaskAttempt method createMockTaskAttemptListener.

private TaskCommunicatorManagerInterface createMockTaskAttemptListener() throws ServicePluginException {
    TaskCommunicatorManagerInterface taListener = mock(TaskCommunicatorManagerInterface.class);
    TaskCommunicator taskComm = mock(TaskCommunicator.class);
    doReturn(new InetSocketAddress("localhost", 0)).when(taskComm).getAddress();
    doReturn(new TaskCommunicatorWrapper(taskComm)).when(taListener).getTaskCommunicator(0);
    return taListener;
}
Also used : TaskCommunicator(org.apache.tez.serviceplugins.api.TaskCommunicator) TaskCommunicatorWrapper(org.apache.tez.dag.app.TaskCommunicatorWrapper) InetSocketAddress(java.net.InetSocketAddress) TaskCommunicatorManagerInterface(org.apache.tez.dag.app.TaskCommunicatorManagerInterface)

Example 3 with TaskCommunicator

use of org.apache.tez.serviceplugins.api.TaskCommunicator in project tez by apache.

the class TestTaskCommunicatorManager method testTaskCommunicatorUserError.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testTaskCommunicatorUserError() {
    TaskCommunicatorContextImpl taskCommContext = mock(TaskCommunicatorContextImpl.class);
    TaskCommunicator taskCommunicator = mock(TaskCommunicator.class, new ExceptionAnswer());
    doReturn(taskCommContext).when(taskCommunicator).getContext();
    EventHandler eventHandler = mock(EventHandler.class);
    AppContext appContext = mock(AppContext.class, RETURNS_DEEP_STUBS);
    when(appContext.getEventHandler()).thenReturn(eventHandler);
    doReturn("testTaskCommunicator").when(appContext).getTaskCommunicatorName(0);
    String expectedId = "[0:testTaskCommunicator]";
    Configuration conf = new Configuration(false);
    TaskCommunicatorManager taskCommunicatorManager = new TaskCommunicatorManager(taskCommunicator, appContext, mock(TaskHeartbeatHandler.class), mock(ContainerHeartbeatHandler.class));
    try {
        taskCommunicatorManager.init(conf);
        taskCommunicatorManager.start();
        // Invoking a couple of random methods.
        DAG mockDag = mock(DAG.class, RETURNS_DEEP_STUBS);
        when(mockDag.getID().getId()).thenReturn(1);
        taskCommunicatorManager.dagComplete(mockDag);
        ArgumentCaptor<Event> argumentCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventHandler, times(1)).handle(argumentCaptor.capture());
        Event rawEvent = argumentCaptor.getValue();
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        DAGAppMasterEventUserServiceFatalError event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertEquals(DAGAppMasterEventType.TASK_COMMUNICATOR_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("TestException_" + "dagComplete"));
        assertTrue(event.getDiagnosticInfo().contains("DAG completion"));
        assertTrue(event.getDiagnosticInfo().contains(expectedId));
        when(appContext.getAllContainers().get(any(ContainerId.class)).getContainer().getNodeId()).thenReturn(mock(NodeId.class));
        taskCommunicatorManager.registerRunningContainer(mock(ContainerId.class), 0);
        argumentCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventHandler, times(2)).handle(argumentCaptor.capture());
        rawEvent = argumentCaptor.getAllValues().get(1);
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertEquals(DAGAppMasterEventType.TASK_COMMUNICATOR_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("TestException_" + "registerRunningContainer"));
        assertTrue(event.getDiagnosticInfo().contains("registering running Container"));
        assertTrue(event.getDiagnosticInfo().contains(expectedId));
    } finally {
        taskCommunicatorManager.stop();
    }
}
Also used : TaskCommunicator(org.apache.tez.serviceplugins.api.TaskCommunicator) DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) Configuration(org.apache.hadoop.conf.Configuration) EventHandler(org.apache.hadoop.yarn.event.EventHandler) DAG(org.apache.tez.dag.app.dag.DAG) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) NodeId(org.apache.hadoop.yarn.api.records.NodeId) Event(org.apache.hadoop.yarn.event.Event) DagInfoImplForTest(org.apache.tez.dag.helpers.DagInfoImplForTest) Test(org.junit.Test)

Aggregations

TaskCommunicator (org.apache.tez.serviceplugins.api.TaskCommunicator)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetSocketAddress (java.net.InetSocketAddress)1 Configuration (org.apache.hadoop.conf.Configuration)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 NodeId (org.apache.hadoop.yarn.api.records.NodeId)1 Event (org.apache.hadoop.yarn.event.Event)1 EventHandler (org.apache.hadoop.yarn.event.EventHandler)1 TezUncheckedException (org.apache.tez.dag.api.TezUncheckedException)1 TaskCommunicatorManagerInterface (org.apache.tez.dag.app.TaskCommunicatorManagerInterface)1 TaskCommunicatorWrapper (org.apache.tez.dag.app.TaskCommunicatorWrapper)1 DAG (org.apache.tez.dag.app.dag.DAG)1 DAGAppMasterEventUserServiceFatalError (org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError)1 DagInfoImplForTest (org.apache.tez.dag.helpers.DagInfoImplForTest)1 Test (org.junit.Test)1