Search in sources :

Example 26 with AppContext

use of org.apache.tez.dag.app.AppContext in project tez by apache.

the class TestRootInputInitializerManager method testCorrectUgiUsage.

@Test(timeout = 5000)
public void testCorrectUgiUsage() throws TezException, InterruptedException {
    Vertex vertex = mock(Vertex.class);
    doReturn(mock(TezVertexID.class)).when(vertex).getVertexId();
    AppContext appContext = mock(AppContext.class);
    doReturn(new DefaultHadoopShim()).when(appContext).getHadoopShim();
    doReturn(mock(EventHandler.class)).when(appContext).getEventHandler();
    UserGroupInformation dagUgi = UserGroupInformation.createRemoteUser("fakeuser");
    StateChangeNotifier stateChangeNotifier = mock(StateChangeNotifier.class);
    RootInputInitializerManager rootInputInitializerManager = new RootInputInitializerManager(vertex, appContext, dagUgi, stateChangeNotifier);
    InputDescriptor id = mock(InputDescriptor.class);
    InputInitializerDescriptor iid = InputInitializerDescriptor.create(InputInitializerForUgiTest.class.getName());
    RootInputLeafOutput<InputDescriptor, InputInitializerDescriptor> rootInput = new RootInputLeafOutput<>("InputName", id, iid);
    rootInputInitializerManager.runInputInitializers(Collections.singletonList(rootInput));
    InputInitializerForUgiTest.awaitInitialize();
    assertEquals(dagUgi, InputInitializerForUgiTest.ctorUgi);
    assertEquals(dagUgi, InputInitializerForUgiTest.initializeUgi);
}
Also used : InputDescriptor(org.apache.tez.dag.api.InputDescriptor) RootInputLeafOutput(org.apache.tez.dag.api.RootInputLeafOutput) AppContext(org.apache.tez.dag.app.AppContext) EventHandler(org.apache.hadoop.yarn.event.EventHandler) DefaultHadoopShim(org.apache.tez.hadoop.shim.DefaultHadoopShim) InputInitializerDescriptor(org.apache.tez.dag.api.InputInitializerDescriptor) TezVertexID(org.apache.tez.dag.records.TezVertexID) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 27 with AppContext

use of org.apache.tez.dag.app.AppContext in project tez by apache.

the class TestRootInputInitializerManager method testEventBeforeSuccess.

// Simple testing. No events if task doesn't succeed.
// Also exercises path where two attempts are reported as successful via the stateChangeNotifier.
// Primarily a failure scenario, when a Task moves back to running from success
// Order event1, success1, event2, success2
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testEventBeforeSuccess() throws Exception {
    InputDescriptor id = mock(InputDescriptor.class);
    InputInitializerDescriptor iid = mock(InputInitializerDescriptor.class);
    RootInputLeafOutput<InputDescriptor, InputInitializerDescriptor> rootInput = new RootInputLeafOutput<InputDescriptor, InputInitializerDescriptor>("InputName", id, iid);
    InputInitializer initializer = mock(InputInitializer.class);
    InputInitializerContext initializerContext = mock(InputInitializerContext.class);
    Vertex vertex = mock(Vertex.class);
    StateChangeNotifier stateChangeNotifier = mock(StateChangeNotifier.class);
    AppContext appContext = mock(AppContext.class, RETURNS_DEEP_STUBS);
    RootInputInitializerManager.InitializerWrapper initializerWrapper = new RootInputInitializerManager.InitializerWrapper(rootInput, initializer, initializerContext, vertex, stateChangeNotifier, appContext);
    ApplicationId appId = ApplicationId.newInstance(1000, 1);
    TezDAGID dagId = TezDAGID.getInstance(appId, 1);
    TezVertexID srcVertexId = TezVertexID.getInstance(dagId, 2);
    TezTaskID srcTaskId1 = TezTaskID.getInstance(srcVertexId, 3);
    Vertex srcVertex = mock(Vertex.class);
    Task srcTask1 = mock(Task.class);
    doReturn(TaskState.RUNNING).when(srcTask1).getState();
    doReturn(srcTask1).when(srcVertex).getTask(srcTaskId1.getId());
    when(appContext.getCurrentDAG().getVertex(any(String.class))).thenReturn(srcVertex);
    String srcVertexName = "srcVertexName";
    List<TezEvent> eventList = Lists.newLinkedList();
    // First Attempt send event
    TezTaskAttemptID srcTaskAttemptId11 = TezTaskAttemptID.getInstance(srcTaskId1, 1);
    EventMetaData sourceInfo11 = new EventMetaData(EventMetaData.EventProducerConsumerType.PROCESSOR, srcVertexName, null, srcTaskAttemptId11);
    InputInitializerEvent e1 = InputInitializerEvent.create("fakeVertex", "fakeInput", null);
    TezEvent te1 = new TezEvent(e1, sourceInfo11);
    eventList.add(te1);
    initializerWrapper.handleInputInitializerEvents(eventList);
    verify(initializer, never()).handleInputInitializerEvent(any(List.class));
    eventList.clear();
    // First attempt, Task success notification
    initializerWrapper.onTaskSucceeded(srcVertexName, srcTaskId1, srcTaskAttemptId11.getId());
    ArgumentCaptor<List> argumentCaptor = ArgumentCaptor.forClass(List.class);
    verify(initializer, times(1)).handleInputInitializerEvent(argumentCaptor.capture());
    List<InputInitializerEvent> invokedEvents = argumentCaptor.getValue();
    assertEquals(1, invokedEvents.size());
    reset(initializer);
    // 2nd attempt send event
    TezTaskAttemptID srcTaskAttemptId12 = TezTaskAttemptID.getInstance(srcTaskId1, 2);
    EventMetaData sourceInfo12 = new EventMetaData(EventMetaData.EventProducerConsumerType.PROCESSOR, srcVertexName, null, srcTaskAttemptId12);
    InputInitializerEvent e2 = InputInitializerEvent.create("fakeVertex", "fakeInput", null);
    TezEvent te2 = new TezEvent(e2, sourceInfo12);
    eventList.add(te2);
    initializerWrapper.handleInputInitializerEvents(eventList);
    verify(initializer, never()).handleInputInitializerEvent(any(List.class));
    eventList.clear();
    reset(initializer);
    // 2nd attempt succeeded
    initializerWrapper.onTaskSucceeded(srcVertexName, srcTaskId1, srcTaskAttemptId12.getId());
    verify(initializer, never()).handleInputInitializerEvent(argumentCaptor.capture());
}
Also used : InputDescriptor(org.apache.tez.dag.api.InputDescriptor) InputInitializer(org.apache.tez.runtime.api.InputInitializer) TezDAGID(org.apache.tez.dag.records.TezDAGID) List(java.util.List) TezVertexID(org.apache.tez.dag.records.TezVertexID) EventMetaData(org.apache.tez.runtime.api.impl.EventMetaData) RootInputLeafOutput(org.apache.tez.dag.api.RootInputLeafOutput) AppContext(org.apache.tez.dag.app.AppContext) InputInitializerContext(org.apache.tez.runtime.api.InputInitializerContext) TezTaskID(org.apache.tez.dag.records.TezTaskID) InputInitializerEvent(org.apache.tez.runtime.api.events.InputInitializerEvent) InputInitializerDescriptor(org.apache.tez.dag.api.InputInitializerDescriptor) TezEvent(org.apache.tez.runtime.api.impl.TezEvent) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID) Test(org.junit.Test)

Example 28 with AppContext

use of org.apache.tez.dag.app.AppContext in project tez by apache.

the class TestTaskSchedulerManager method testTaskSchedulerUserError.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testTaskSchedulerUserError() {
    TaskScheduler taskScheduler = mock(TaskScheduler.class, new ExceptionAnswer());
    EventHandler eventHandler = mock(EventHandler.class);
    AppContext appContext = mock(AppContext.class, RETURNS_DEEP_STUBS);
    when(appContext.getEventHandler()).thenReturn(eventHandler);
    doReturn("testTaskScheduler").when(appContext).getTaskSchedulerName(0);
    String expectedId = "[0:testTaskScheduler]";
    Configuration conf = new Configuration(false);
    InetSocketAddress address = new InetSocketAddress(15222);
    DAGClientServer mockClientService = mock(DAGClientServer.class);
    doReturn(address).when(mockClientService).getBindAddress();
    TaskSchedulerManager taskSchedulerManager = new TaskSchedulerManager(taskScheduler, appContext, mock(ContainerSignatureMatcher.class), mockClientService, Executors.newFixedThreadPool(1)) {

        @Override
        protected void instantiateSchedulers(String host, int port, String trackingUrl, AppContext appContext) throws TezException {
        // Stubbed out since these are setup up front in the constructor used for testing
        }
    };
    try {
        taskSchedulerManager.init(conf);
        taskSchedulerManager.start();
        // Invoking a couple of random methods
        AMSchedulerEventTALaunchRequest launchRequest = new AMSchedulerEventTALaunchRequest(mock(TezTaskAttemptID.class), mock(Resource.class), mock(TaskSpec.class), mock(TaskAttempt.class), mock(TaskLocationHint.class), 0, mock(ContainerContext.class), 0, 0, 0);
        taskSchedulerManager.handleEvent(launchRequest);
        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_SCHEDULER_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("TestException_" + "allocateTask"));
        assertTrue(event.getDiagnosticInfo().contains("Task Allocation"));
        assertTrue(event.getDiagnosticInfo().contains(expectedId));
        taskSchedulerManager.dagCompleted();
        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_SCHEDULER_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getError().getMessage().contains("TestException_" + "dagComplete"));
        assertTrue(event.getDiagnosticInfo().contains("Dag Completion"));
        assertTrue(event.getDiagnosticInfo().contains(expectedId));
    } finally {
        taskSchedulerManager.stop();
    }
}
Also used : DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) InetSocketAddress(java.net.InetSocketAddress) AppContext(org.apache.tez.dag.app.AppContext) TaskSpec(org.apache.tez.runtime.api.impl.TaskSpec) ContainerSignatureMatcher(org.apache.tez.common.ContainerSignatureMatcher) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) EventHandler(org.apache.hadoop.yarn.event.EventHandler) TaskScheduler(org.apache.tez.serviceplugins.api.TaskScheduler) TaskLocationHint(org.apache.tez.dag.api.TaskLocationHint) ContainerContext(org.apache.tez.dag.app.ContainerContext) Event(org.apache.hadoop.yarn.event.Event) DAGClientServer(org.apache.tez.dag.api.client.DAGClientServer) TaskAttempt(org.apache.tez.dag.app.dag.TaskAttempt) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID) DagInfoImplForTest(org.apache.tez.dag.helpers.DagInfoImplForTest) Test(org.junit.Test)

Example 29 with AppContext

use of org.apache.tez.dag.app.AppContext in project tez by apache.

the class TestTaskSchedulerManager method testReportFailureFromTaskScheduler.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testReportFailureFromTaskScheduler() {
    String dagName = DAG_NAME;
    Configuration conf = new TezConfiguration();
    String taskSchedulerName = "testTaskScheduler";
    String expIdentifier = "[0:" + taskSchedulerName + "]";
    EventHandler eventHandler = mock(EventHandler.class);
    AppContext appContext = mock(AppContext.class, RETURNS_DEEP_STUBS);
    doReturn(taskSchedulerName).when(appContext).getTaskSchedulerName(0);
    doReturn(eventHandler).when(appContext).getEventHandler();
    doReturn(conf).when(appContext).getAMConf();
    InetSocketAddress address = new InetSocketAddress("host", 55000);
    DAGClientServer dagClientServer = mock(DAGClientServer.class);
    doReturn(address).when(dagClientServer).getBindAddress();
    DAG dag = mock(DAG.class);
    TezDAGID dagId = TezDAGID.getInstance(ApplicationId.newInstance(1, 0), DAG_INDEX);
    doReturn(dagName).when(dag).getName();
    doReturn(dagId).when(dag).getID();
    doReturn(dag).when(appContext).getCurrentDAG();
    NamedEntityDescriptor<TaskSchedulerDescriptor> namedEntityDescriptor = new NamedEntityDescriptor<>(taskSchedulerName, TaskSchedulerForFailureTest.class.getName());
    List<NamedEntityDescriptor> list = new LinkedList<>();
    list.add(namedEntityDescriptor);
    TaskSchedulerManager taskSchedulerManager = new TaskSchedulerManager(appContext, dagClientServer, eventHandler, mock(ContainerSignatureMatcher.class), mock(WebUIService.class), list, false, new HadoopShimsLoader(appContext.getAMConf()).getHadoopShim()) {

        @Override
        TaskSchedulerContext wrapTaskSchedulerContext(TaskSchedulerContext rawContext) {
            // Avoid wrapping in threads
            return rawContext;
        }
    };
    try {
        taskSchedulerManager.init(new TezConfiguration());
        taskSchedulerManager.start();
        taskSchedulerManager.getTotalResources(0);
        ArgumentCaptor<Event> argumentCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventHandler, times(1)).handle(argumentCaptor.capture());
        Event rawEvent = argumentCaptor.getValue();
        assertTrue(rawEvent instanceof DAGEventTerminateDag);
        DAGEventTerminateDag killEvent = (DAGEventTerminateDag) rawEvent;
        assertTrue(killEvent.getDiagnosticInfo().contains("ReportError"));
        assertTrue(killEvent.getDiagnosticInfo().contains(ServicePluginErrorDefaults.SERVICE_UNAVAILABLE.name()));
        assertTrue(killEvent.getDiagnosticInfo().contains(expIdentifier));
        reset(eventHandler);
        taskSchedulerManager.getAvailableResources(0);
        argumentCaptor = ArgumentCaptor.forClass(Event.class);
        verify(eventHandler, times(1)).handle(argumentCaptor.capture());
        rawEvent = argumentCaptor.getValue();
        assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
        DAGAppMasterEventUserServiceFatalError event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
        assertEquals(DAGAppMasterEventType.TASK_SCHEDULER_SERVICE_FATAL_ERROR, event.getType());
        assertTrue(event.getDiagnosticInfo().contains("ReportedFatalError"));
        assertTrue(event.getDiagnosticInfo().contains(ServicePluginErrorDefaults.INCONSISTENT_STATE.name()));
        assertTrue(event.getDiagnosticInfo().contains(expIdentifier));
    } finally {
        taskSchedulerManager.stop();
    }
}
Also used : DAGAppMasterEventUserServiceFatalError(org.apache.tez.dag.app.dag.event.DAGAppMasterEventUserServiceFatalError) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) TaskSchedulerDescriptor(org.apache.tez.serviceplugins.api.TaskSchedulerDescriptor) TaskSchedulerContext(org.apache.tez.serviceplugins.api.TaskSchedulerContext) InetSocketAddress(java.net.InetSocketAddress) AppContext(org.apache.tez.dag.app.AppContext) ContainerSignatureMatcher(org.apache.tez.common.ContainerSignatureMatcher) EventHandler(org.apache.hadoop.yarn.event.EventHandler) DAG(org.apache.tez.dag.app.dag.DAG) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) NamedEntityDescriptor(org.apache.tez.dag.api.NamedEntityDescriptor) LinkedList(java.util.LinkedList) WebUIService(org.apache.tez.dag.app.web.WebUIService) HadoopShimsLoader(org.apache.tez.hadoop.shim.HadoopShimsLoader) TezDAGID(org.apache.tez.dag.records.TezDAGID) Event(org.apache.hadoop.yarn.event.Event) DAGClientServer(org.apache.tez.dag.api.client.DAGClientServer) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) DagInfoImplForTest(org.apache.tez.dag.helpers.DagInfoImplForTest) Test(org.junit.Test)

Example 30 with AppContext

use of org.apache.tez.dag.app.AppContext in project tez by apache.

the class TestCommit method setupDAG.

public void setupDAG(DAGPlan dagPlan) {
    conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, false);
    appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(100, 1), 1);
    dagId = TezDAGID.getInstance(appAttemptId.getApplicationId(), 1);
    Assert.assertNotNull(dagId);
    dispatcher = new DrainDispatcher();
    fsTokens = new Credentials();
    appContext = mock(AppContext.class);
    when(appContext.getHadoopShim()).thenReturn(new DefaultHadoopShim());
    rawExecutor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("App Shared Pool - " + "#%d").build());
    execService = MoreExecutors.listeningDecorator(rawExecutor);
    doReturn(execService).when(appContext).getExecService();
    historyEventHandler = new MockHistoryEventHandler(appContext);
    aclManager = new ACLManager("amUser");
    doReturn(conf).when(appContext).getAMConf();
    doReturn(appAttemptId).when(appContext).getApplicationAttemptId();
    doReturn(appAttemptId.getApplicationId()).when(appContext).getApplicationID();
    doReturn(dagId).when(appContext).getCurrentDAGID();
    doReturn(historyEventHandler).when(appContext).getHistoryHandler();
    doReturn(aclManager).when(appContext).getAMACLManager();
    dag = new DAGImpl(dagId, conf, dagPlan, dispatcher.getEventHandler(), taskCommunicatorManagerInterface, fsTokens, clock, "user", thh, appContext);
    doReturn(dag).when(appContext).getCurrentDAG();
    doReturn(dispatcher.getEventHandler()).when(appContext).getEventHandler();
    ClusterInfo clusterInfo = new ClusterInfo(Resource.newInstance(8192, 10));
    doReturn(clusterInfo).when(appContext).getClusterInfo();
    dispatcher.register(CallableEventType.class, new CallableEventDispatcher());
    taskEventDispatcher = new TaskEventDispatcher();
    dispatcher.register(TaskEventType.class, taskEventDispatcher);
    taskAttemptEventDispatcher = new TaskAttemptEventDispatcher();
    dispatcher.register(TaskAttemptEventType.class, taskAttemptEventDispatcher);
    vertexEventDispatcher = new VertexEventDispatcher();
    dispatcher.register(VertexEventType.class, vertexEventDispatcher);
    dagEventDispatcher = new DagEventDispatcher();
    dispatcher.register(DAGEventType.class, dagEventDispatcher);
    dagFinishEventHandler = new DAGFinishEventHandler();
    dispatcher.register(DAGAppMasterEventType.class, dagFinishEventHandler);
    dispatcher.init(conf);
    dispatcher.start();
}
Also used : DrainDispatcher(org.apache.tez.common.DrainDispatcher) AppContext(org.apache.tez.dag.app.AppContext) ACLManager(org.apache.tez.common.security.ACLManager) DefaultHadoopShim(org.apache.tez.hadoop.shim.DefaultHadoopShim) ClusterInfo(org.apache.tez.dag.app.ClusterInfo) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Credentials(org.apache.hadoop.security.Credentials)

Aggregations

AppContext (org.apache.tez.dag.app.AppContext)52 Test (org.junit.Test)40 Configuration (org.apache.hadoop.conf.Configuration)39 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)36 TezDAGID (org.apache.tez.dag.records.TezDAGID)20 TaskCommunicatorManagerInterface (org.apache.tez.dag.app.TaskCommunicatorManagerInterface)19 AMContainerMap (org.apache.tez.dag.app.rm.container.AMContainerMap)18 Container (org.apache.hadoop.yarn.api.records.Container)16 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)16 TezVertexID (org.apache.tez.dag.records.TezVertexID)16 TezTaskAttemptID (org.apache.tez.dag.records.TezTaskAttemptID)15 Resource (org.apache.hadoop.yarn.api.records.Resource)13 ClusterInfo (org.apache.tez.dag.app.ClusterInfo)13 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)12 ContainerHeartbeatHandler (org.apache.tez.dag.app.ContainerHeartbeatHandler)12 TaskAttempt (org.apache.tez.dag.app.dag.TaskAttempt)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Priority (org.apache.hadoop.yarn.api.records.Priority)11 AMRMClientAsyncForTest (org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientAsyncForTest)11 AMRMClientForTest (org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientForTest)11