Search in sources :

Example 21 with AppContext

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

the class TestAMNodeTracker method testNodeCompletedAndCleanup.

@Test(timeout = 10000L)
public void testNodeCompletedAndCleanup() {
    AppContext appContext = mock(AppContext.class);
    Configuration conf = new Configuration(false);
    conf.setInt(TezConfiguration.TEZ_AM_MAX_TASK_FAILURES_PER_NODE, 2);
    TestEventHandler handler = new TestEventHandler();
    AMNodeTracker amNodeTracker = new AMNodeTracker(handler, appContext);
    doReturn(amNodeTracker).when(appContext).getNodeTracker();
    AMContainerMap amContainerMap = mock(AMContainerMap.class);
    TaskSchedulerManager taskSchedulerManager = mock(TaskSchedulerManager.class);
    dispatcher.register(AMNodeEventType.class, amNodeTracker);
    dispatcher.register(AMContainerEventType.class, amContainerMap);
    dispatcher.register(AMSchedulerEventType.class, taskSchedulerManager);
    amNodeTracker.init(conf);
    amNodeTracker.start();
    try {
        NodeId nodeId = NodeId.newInstance("fakenode", 3333);
        amNodeTracker.nodeSeen(nodeId, 0);
        AMNode amNode = amNodeTracker.get(nodeId, 0);
        ContainerId[] containerIds = new ContainerId[7];
        // Start 5 containers.
        for (int i = 0; i < 5; i++) {
            containerIds[i] = mock(ContainerId.class);
            amNodeTracker.handle(new AMNodeEventContainerAllocated(nodeId, 0, containerIds[i]));
        }
        assertEquals(5, amNode.getContainers().size());
        // Finnish 1st dag
        amNodeTracker.dagComplete(mock(DAG.class));
        assertEquals(5, amNode.getContainers().size());
        // Mark 2 as complete. Finish 2nd dag.
        for (int i = 0; i < 2; i++) {
            amNodeTracker.handle(new AMNodeEventContainerCompleted(nodeId, 0, containerIds[i]));
        }
        amNodeTracker.dagComplete(mock(DAG.class));
        assertEquals(3, amNode.getContainers().size());
        // Add 2 more containers. Mark all as complete. Finish 3rd dag.
        for (int i = 5; i < 7; i++) {
            containerIds[i] = mock(ContainerId.class);
            amNodeTracker.handle(new AMNodeEventContainerAllocated(nodeId, 0, containerIds[i]));
        }
        assertEquals(5, amNode.getContainers().size());
        amNodeTracker.dagComplete(mock(DAG.class));
        assertEquals(5, amNode.getContainers().size());
        amNodeTracker.dagComplete(mock(DAG.class));
        assertEquals(5, amNode.getContainers().size());
        for (int i = 2; i < 7; i++) {
            amNodeTracker.handle(new AMNodeEventContainerCompleted(nodeId, 0, containerIds[i]));
        }
        assertEquals(5, amNode.getContainers().size());
        amNodeTracker.dagComplete(mock(DAG.class));
        assertEquals(0, amNode.getContainers().size());
    } finally {
        amNodeTracker.stop();
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) AppContext(org.apache.tez.dag.app.AppContext) DAG(org.apache.tez.dag.app.dag.DAG) AMContainerMap(org.apache.tez.dag.app.rm.container.AMContainerMap) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) TaskSchedulerManager(org.apache.tez.dag.app.rm.TaskSchedulerManager) NodeId(org.apache.hadoop.yarn.api.records.NodeId) Test(org.junit.Test)

Example 22 with AppContext

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

the class TestHistoryEventHandler method createHandler.

private HistoryEventHandler createHandler(HistoryLogLevel logLevel) {
    Configuration conf = new Configuration(baseConfig);
    conf.setBoolean(TezConfiguration.DAG_RECOVERY_ENABLED, false);
    conf.set(TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS, InMemoryHistoryLoggingService.class.getName());
    if (logLevel != null) {
        conf.setEnum(TezConfiguration.TEZ_HISTORY_LOGGING_LOGLEVEL, logLevel);
    }
    DAG dag = mock(DAG.class);
    when(dag.getConf()).thenReturn(conf);
    AppContext appContext = mock(AppContext.class);
    when(appContext.getApplicationID()).thenReturn(appId);
    when(appContext.getHadoopShim()).thenReturn(new HadoopShim() {
    });
    when(appContext.getAMConf()).thenReturn(conf);
    when(appContext.getCurrentDAG()).thenReturn(dag);
    HistoryEventHandler handler = new HistoryEventHandler(appContext);
    handler.init(conf);
    return handler;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) HadoopShim(org.apache.tez.hadoop.shim.HadoopShim) AppContext(org.apache.tez.dag.app.AppContext) DAG(org.apache.tez.dag.app.dag.DAG)

Example 23 with AppContext

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

the class TestATSHistoryLoggingService method setup.

@Before
public void setup() throws Exception {
    appContext = mock(AppContext.class);
    historyACLPolicyManager = mock(HistoryACLPolicyManager.class);
    atsHistoryLoggingService = new ATSHistoryLoggingService();
    atsHistoryLoggingService.setAppContext(appContext);
    conf = new Configuration(false);
    conf.setLong(TezConfiguration.YARN_ATS_EVENT_FLUSH_TIMEOUT_MILLIS, 1000l);
    conf.setInt(TezConfiguration.YARN_ATS_MAX_EVENTS_PER_BATCH, 2);
    conf.setBoolean(TezConfiguration.TEZ_AM_ALLOW_DISABLED_TIMELINE_DOMAINS, true);
    conf.set(TezConfiguration.YARN_ATS_ACL_SESSION_DOMAIN_ID, "test-domain");
    atsInvokeCounter = 0;
    atsEntitiesCounter = 0;
    atsHistoryLoggingService.init(conf);
    atsHistoryLoggingService.historyACLPolicyManager = historyACLPolicyManager;
    atsHistoryLoggingService.timelineClient = mock(TimelineClient.class);
    when(appContext.getClock()).thenReturn(clock);
    when(appContext.getCurrentDAGID()).thenReturn(null);
    when(appContext.getApplicationID()).thenReturn(appId);
    when(atsHistoryLoggingService.timelineClient.putEntities(Matchers.<TimelineEntity[]>anyVararg())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ++atsInvokeCounter;
            atsEntitiesCounter += invocation.getArguments().length;
            try {
                Thread.sleep(500l);
            } catch (InterruptedException e) {
            // do nothing
            }
            return null;
        }
    });
}
Also used : TimelineClient(org.apache.hadoop.yarn.client.api.TimelineClient) HistoryACLPolicyManager(org.apache.tez.common.security.HistoryACLPolicyManager) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AppContext(org.apache.tez.dag.app.AppContext) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) Before(org.junit.Before)

Example 24 with AppContext

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

the class TestATSHistoryWithACLs method testDagLoggingDisabled.

/**
 * use mini cluster to verify data do not push to ats when the daglogging flag
 * in dagsubmittedevent is set off
 * @throws Exception
 */
@Test(timeout = 50000)
public void testDagLoggingDisabled() throws Exception {
    ATSHistoryLoggingService historyLoggingService;
    historyLoggingService = ReflectionUtils.createClazzInstance(ATSHistoryLoggingService.class.getName());
    AppContext appContext = mock(AppContext.class);
    when(appContext.getApplicationID()).thenReturn(ApplicationId.newInstance(0, 1));
    historyLoggingService.setAppContext(appContext);
    TezConfiguration tezConf = new TezConfiguration(mrrTezCluster.getConfig());
    String viewAcls = "nobody nobody_group";
    tezConf.set(TezConfiguration.TEZ_AM_VIEW_ACLS, viewAcls);
    tezConf.set(TezConfiguration.TEZ_HISTORY_LOGGING_SERVICE_CLASS, ATSHistoryLoggingService.class.getName());
    Path remoteStagingDir = remoteFs.makeQualified(new Path("/tmp", String.valueOf(random.nextInt(100000))));
    remoteFs.mkdirs(remoteStagingDir);
    tezConf.set(TezConfiguration.TEZ_AM_STAGING_DIR, remoteStagingDir.toString());
    historyLoggingService.init(tezConf);
    historyLoggingService.start();
    ApplicationId appId = ApplicationId.newInstance(100l, 1);
    TezDAGID tezDAGID = TezDAGID.getInstance(appId, 100);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    DAGPlan dagPlan = DAGPlan.newBuilder().setName("DAGPlanMock").build();
    DAGSubmittedEvent submittedEvent = new DAGSubmittedEvent(tezDAGID, 1, dagPlan, appAttemptId, null, "usr", tezConf, null, null);
    submittedEvent.setHistoryLoggingEnabled(false);
    DAGHistoryEvent event = new DAGHistoryEvent(tezDAGID, submittedEvent);
    historyLoggingService.handle(new DAGHistoryEvent(tezDAGID, submittedEvent));
    Thread.sleep(1000l);
    String url = "http://" + timelineAddress + "/ws/v1/timeline/TEZ_DAG_ID/" + event.getDagID();
    Client client = new Client();
    WebResource resource = client.resource(url);
    ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(404, response.getStatus());
}
Also used : Path(org.apache.hadoop.fs.Path) ClientResponse(com.sun.jersey.api.client.ClientResponse) AppContext(org.apache.tez.dag.app.AppContext) DAGHistoryEvent(org.apache.tez.dag.history.DAGHistoryEvent) WebResource(com.sun.jersey.api.client.WebResource) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ATSHistoryLoggingService(org.apache.tez.dag.history.logging.ats.ATSHistoryLoggingService) DAGPlan(org.apache.tez.dag.api.records.DAGProtos.DAGPlan) TezDAGID(org.apache.tez.dag.records.TezDAGID) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) DAGClient(org.apache.tez.dag.api.client.DAGClient) TezClient(org.apache.tez.client.TezClient) Client(com.sun.jersey.api.client.Client) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) DAGSubmittedEvent(org.apache.tez.dag.history.events.DAGSubmittedEvent) Test(org.junit.Test)

Example 25 with AppContext

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

the class TestDAGClientHandler method testDAGClientHandler.

@Test(timeout = 5000)
public void testDAGClientHandler() throws TezException {
    TezDAGID mockTezDAGId = mock(TezDAGID.class);
    when(mockTezDAGId.getId()).thenReturn(1);
    when(mockTezDAGId.toString()).thenReturn("dag_9999_0001_1");
    DAG mockDAG = mock(DAG.class);
    when(mockDAG.getID()).thenReturn(mockTezDAGId);
    DAGStatusBuilder mockDagStatusBuilder = mock(DAGStatusBuilder.class);
    when(mockDAG.getDAGStatus(anySetOf(StatusGetOpts.class))).thenReturn(mockDagStatusBuilder);
    VertexStatusBuilder mockVertexStatusBuilder = mock(VertexStatusBuilder.class);
    when(mockDAG.getVertexStatus(anyString(), anySetOf(StatusGetOpts.class))).thenReturn(mockVertexStatusBuilder);
    DAGAppMaster mockDagAM = mock(DAGAppMaster.class);
    when(mockDagAM.getState()).thenReturn(DAGAppMasterState.RUNNING);
    AppContext mockAppContext = mock(AppContext.class);
    when(mockDagAM.getContext()).thenReturn(mockAppContext);
    when(mockDagAM.getContext().getCurrentDAG()).thenReturn(mockDAG);
    when(mockAppContext.getClock()).thenReturn(new SystemClock());
    DAGClientHandler dagClientHandler = new DAGClientHandler(mockDagAM);
    // getAllDAGs()
    assertEquals(1, dagClientHandler.getAllDAGs().size());
    assertEquals("dag_9999_0001_1", dagClientHandler.getAllDAGs().get(0));
    // getDAGStatus
    try {
        dagClientHandler.getDAGStatus("dag_9999_0001_2", Sets.newSet(StatusGetOpts.GET_COUNTERS));
        fail("should not come here");
    } catch (TezException e) {
        assertTrue(e.getMessage().contains("Unknown dagId"));
    }
    DAGStatus dagStatus = dagClientHandler.getDAGStatus("dag_9999_0001_1", Sets.newSet(StatusGetOpts.GET_COUNTERS));
    assertEquals(mockDagStatusBuilder, dagStatus);
    // getVertexStatus
    try {
        dagClientHandler.getVertexStatus("dag_9999_0001_2", "v1", Sets.newSet(StatusGetOpts.GET_COUNTERS));
        fail("should not come here");
    } catch (TezException e) {
        assertTrue(e.getMessage().contains("Unknown dagId"));
    }
    VertexStatus vertexStatus = dagClientHandler.getVertexStatus("dag_9999_0001_1", "v1", Sets.newSet(StatusGetOpts.GET_COUNTERS));
    assertEquals(mockVertexStatusBuilder, vertexStatus);
    // getTezAppMasterStatus
    when(mockDagAM.isSession()).thenReturn(false);
    assertEquals(TezAppMasterStatus.RUNNING, dagClientHandler.getTezAppMasterStatus());
    when(mockDagAM.isSession()).thenReturn(true);
    when(mockDagAM.getState()).thenReturn(DAGAppMasterState.INITED);
    assertEquals(TezAppMasterStatus.INITIALIZING, dagClientHandler.getTezAppMasterStatus());
    when(mockDagAM.getState()).thenReturn(DAGAppMasterState.ERROR);
    assertEquals(TezAppMasterStatus.SHUTDOWN, dagClientHandler.getTezAppMasterStatus());
    // tryKillDAG
    try {
        dagClientHandler.tryKillDAG("dag_9999_0001_2");
        fail("should not come here");
    } catch (TezException e) {
        assertTrue(e.getMessage().contains("Unknown dagId"));
    }
    dagClientHandler.tryKillDAG("dag_9999_0001_1");
    ArgumentCaptor<DAG> eventCaptor = ArgumentCaptor.forClass(DAG.class);
    verify(mockDagAM, times(1)).tryKillDAG(eventCaptor.capture(), contains("Sending client kill from"));
    assertEquals(1, eventCaptor.getAllValues().size());
    assertTrue(eventCaptor.getAllValues().get(0) instanceof DAG);
    assertEquals("dag_9999_0001_1", ((DAG) eventCaptor.getAllValues().get(0)).getID().toString());
    // submitDAG
    DAGPlan dagPlan = DAGPlan.getDefaultInstance();
    Map<String, LocalResource> localResources = new HashMap<String, LocalResource>();
    dagClientHandler.submitDAG(dagPlan, localResources);
    verify(mockDagAM).submitDAGToAppMaster(dagPlan, localResources);
    // shutdown
    dagClientHandler.shutdownAM();
    verify(mockDagAM).shutdownTezAM(contains("Received message to shutdown AM from"));
}
Also used : TezException(org.apache.tez.dag.api.TezException) SystemClock(org.apache.hadoop.yarn.util.SystemClock) HashMap(java.util.HashMap) AppContext(org.apache.tez.dag.app.AppContext) DAG(org.apache.tez.dag.app.dag.DAG) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) DAGPlan(org.apache.tez.dag.api.records.DAGProtos.DAGPlan) DAGAppMaster(org.apache.tez.dag.app.DAGAppMaster) TezDAGID(org.apache.tez.dag.records.TezDAGID) Test(org.junit.Test)

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