Search in sources :

Example 46 with AppContext

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

the class TestAMNodeTracker method testMultipleSourcesNodeCountUpdated.

@Test(timeout = 5000)
public void testMultipleSourcesNodeCountUpdated() {
    AppContext appContext = mock(AppContext.class);
    AMNodeTracker amNodeTracker = new AMNodeTracker(eventHandler, appContext);
    doReturn(amNodeTracker).when(appContext).getNodeTracker();
    amNodeTracker.init(new Configuration(false));
    amNodeTracker.start();
    NodeId nodeId1 = NodeId.newInstance("source01", 3333);
    NodeId nodeId2 = NodeId.newInstance("source02", 3333);
    amNodeTracker.nodeSeen(nodeId1, 0);
    amNodeTracker.nodeSeen(nodeId2, 1);
    amNodeTracker.handle(new AMNodeEventNodeCountUpdated(10, 0));
    amNodeTracker.handle(new AMNodeEventNodeCountUpdated(20, 1));
    // NodeCountUpdate does not reflect in getNumNodes.
    assertEquals(1, amNodeTracker.getNumNodes(0));
    assertEquals(1, amNodeTracker.getNumNodes(1));
    assertNotNull(amNodeTracker.get(nodeId1, 0));
    assertNull(amNodeTracker.get(nodeId2, 0));
    assertNull(amNodeTracker.get(nodeId1, 1));
    assertNotNull(amNodeTracker.get(nodeId2, 1));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) AppContext(org.apache.tez.dag.app.AppContext) NodeId(org.apache.hadoop.yarn.api.records.NodeId) Test(org.junit.Test)

Example 47 with AppContext

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

the class TestAMNodeTracker method _testNodeUnhealthyRescheduleTasks.

private void _testNodeUnhealthyRescheduleTasks(boolean rescheduleTasks) {
    AppContext appContext = mock(AppContext.class);
    Configuration conf = new Configuration(false);
    conf.setBoolean(TezConfiguration.TEZ_AM_NODE_UNHEALTHY_RESCHEDULE_TASKS, rescheduleTasks);
    TestEventHandler handler = new TestEventHandler();
    AMNodeTracker amNodeTracker = new AMNodeTracker(handler, appContext);
    doReturn(amNodeTracker).when(appContext).getNodeTracker();
    amNodeTracker.init(conf);
    amNodeTracker.start();
    // add a node
    amNodeTracker.handle(new AMNodeEventNodeCountUpdated(1, 0));
    NodeId nodeId = NodeId.newInstance("host1", 1234);
    amNodeTracker.nodeSeen(nodeId, 0);
    AMNodeImpl node = (AMNodeImpl) amNodeTracker.get(nodeId, 0);
    // simulate task starting on node
    ContainerId cid = mock(ContainerId.class);
    amNodeTracker.handle(new AMNodeEventContainerAllocated(nodeId, 0, cid));
    // mark node unhealthy
    NodeReport nodeReport = generateNodeReport(nodeId, NodeState.UNHEALTHY);
    amNodeTracker.handle(new AMNodeEventStateChanged(nodeReport, 0));
    assertEquals(AMNodeState.UNHEALTHY, node.getState());
    // check for task rescheduling events
    if (rescheduleTasks) {
        assertEquals(1, handler.events.size());
        assertEquals(AMContainerEventType.C_NODE_FAILED, handler.events.get(0).getType());
    } else {
        assertEquals(0, handler.events.size());
    }
    amNodeTracker.stop();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) AppContext(org.apache.tez.dag.app.AppContext) NodeId(org.apache.hadoop.yarn.api.records.NodeId) NodeReport(org.apache.hadoop.yarn.api.records.NodeReport)

Example 48 with AppContext

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

the class TestRecoveryService method setup.

private void setup(boolean useMockFs, String[][] configs) throws Exception {
    conf = new Configuration();
    if (configs != null) {
        for (String[] config : configs) {
            conf.set(config[0], config[1]);
        }
    }
    appContext = mock(AppContext.class);
    when(appContext.getClock()).thenReturn(new SystemClock());
    when(appContext.getHadoopShim()).thenReturn(new DefaultHadoopShim());
    when(appContext.getApplicationID()).thenReturn(appId);
    if (useMockFs) {
        fs = mock(FileSystem.class);
        when(appContext.getCurrentRecoveryDir()).thenReturn(new Path("mockfs:///"));
        conf.set("fs.mockfs.impl", MockFileSystem.class.getName());
        MockFileSystem.delegate = fs;
        dagFos = spy(new FSDataOutputStream(new OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }
        }, null));
        summaryFos = spy(new FSDataOutputStream(new OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }
        }, null));
    } else {
        when(appContext.getCurrentRecoveryDir()).thenReturn(new Path(TEST_ROOT_DIR));
        fs = FileSystem.getLocal(conf);
        fs.delete(new Path(TEST_ROOT_DIR), true);
    }
    recoveryService = new MockRecoveryService(appContext);
    conf.setBoolean(RecoveryService.TEZ_TEST_RECOVERY_DRAIN_EVENTS_WHEN_STOPPED, true);
    recoveryService.init(conf);
    summaryPath = TezCommonUtils.getSummaryRecoveryPath(recoveryService.recoveryPath);
    dagRecoveryPath = TezCommonUtils.getDAGRecoveryPath(recoveryService.recoveryPath, dagId.toString());
    if (useMockFs) {
        when(fs.create(eq(dagRecoveryPath), eq(false), anyInt())).thenReturn(dagFos);
        when(fs.create(eq(summaryPath), eq(false), anyInt())).thenReturn(summaryFos);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) SystemClock(org.apache.hadoop.yarn.util.SystemClock) AppContext(org.apache.tez.dag.app.AppContext) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) DefaultHadoopShim(org.apache.tez.hadoop.shim.DefaultHadoopShim) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream)

Example 49 with AppContext

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

the class TestATSV15HistoryLoggingService method createService.

private ATSV15HistoryLoggingService createService(int numDagsPerGroup) throws IOException, YarnException {
    ATSV15HistoryLoggingService service = new ATSV15HistoryLoggingService();
    appContext = mock(AppContext.class);
    when(appContext.getApplicationID()).thenReturn(appId);
    when(appContext.getHadoopShim()).thenReturn(new HadoopShim() {
    });
    service.setAppContext(appContext);
    Configuration conf = new Configuration(false);
    if (numDagsPerGroup != -1) {
        conf.setInt(TezConfiguration.TEZ_HISTORY_LOGGING_TIMELINE_NUM_DAGS_PER_GROUP, numDagsPerGroup);
    }
    service.init(conf);
    // Set timeline service.
    timelineClient = mock(TimelineClient.class);
    entityLog = new HashMap<>();
    // timelineClient.init(conf);
    when(timelineClient.getDelegationToken(anyString())).thenReturn(null);
    when(timelineClient.renewDelegationToken(Matchers.<Token<TimelineDelegationTokenIdentifier>>any())).thenReturn(0L);
    when(timelineClient.putEntities(Matchers.<TimelineEntity>anyVararg())).thenAnswer(new Answer() {

        @Override
        public TimelinePutResponse answer(InvocationOnMock invocation) throws Throwable {
            return putEntityHelper(DEFAULT_GROUP_ID, invocation.getArguments(), 0);
        }
    });
    when(timelineClient.putEntities(any(ApplicationAttemptId.class), any(TimelineEntityGroupId.class), Matchers.<TimelineEntity>anyVararg())).thenAnswer(new Answer() {

        @Override
        public TimelinePutResponse answer(InvocationOnMock invocation) throws Throwable {
            return putEntityHelper(invocation.getArgumentAt(1, TimelineEntityGroupId.class), invocation.getArguments(), 2);
        }
    });
    service.timelineClient = timelineClient;
    return service;
}
Also used : HadoopShim(org.apache.tez.hadoop.shim.HadoopShim) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) AppContext(org.apache.tez.dag.app.AppContext) TimelineDelegationTokenIdentifier(org.apache.hadoop.yarn.security.client.TimelineDelegationTokenIdentifier) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) TimelineEntityGroupId(org.apache.hadoop.yarn.api.records.timeline.TimelineEntityGroupId) TimelineClient(org.apache.hadoop.yarn.client.api.TimelineClient) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 50 with AppContext

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

the class TestATSHistoryWithACLs method testDagLoggingEnabled.

/**
 * use mini cluster to verify data do push to ats when
 * the dag logging flag in dagsubmitted event is set on
 * @throws Exception
 */
@Test(timeout = 50000)
public void testDagLoggingEnabled() 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, 11);
    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(true);
    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(200, response.getStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    TimelineEntity entity = response.getEntity(TimelineEntity.class);
    assertEquals(entity.getEntityType(), "TEZ_DAG_ID");
    assertEquals(entity.getEvents().get(0).getEventType(), HistoryEventType.DAG_SUBMITTED.toString());
}
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) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) 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)

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