Search in sources :

Example 96 with TezVertexID

use of org.apache.tez.dag.records.TezVertexID in project tez by apache.

the class TestContainerReuse method testReuseAcrossVertices.

@Test(timeout = 30000l)
public void testReuseAcrossVertices() throws IOException, InterruptedException, ExecutionException {
    LOG.info("Test testReuseAcrossVertices");
    Configuration tezConf = new Configuration(new YarnConfiguration());
    tezConf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
    tezConf.setLong(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 1l);
    tezConf.setLong(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MIN_MILLIS, 20l);
    tezConf.setLong(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MAX_MILLIS, 30l);
    tezConf.setInt(TezConfiguration.TEZ_AM_SESSION_MIN_HELD_CONTAINERS, 1);
    CapturingEventHandler eventHandler = new CapturingEventHandler();
    TezDAGID dagID = TezDAGID.getInstance("0", 0, 0);
    AMRMClient<CookieContainerRequest> rmClientCore = new AMRMClientForTest();
    TezAMRMClientAsync<CookieContainerRequest> rmClient = spy(new AMRMClientAsyncForTest(rmClientCore, 100));
    AppContext appContext = mock(AppContext.class);
    doReturn(new Configuration(false)).when(appContext).getAMConf();
    AMContainerMap amContainerMap = new AMContainerMap(mock(ContainerHeartbeatHandler.class), mock(TaskCommunicatorManagerInterface.class), new ContainerContextMatcher(), appContext);
    AMNodeTracker amNodeTracker = new AMNodeTracker(eventHandler, appContext);
    doReturn(amContainerMap).when(appContext).getAllContainers();
    doReturn(amNodeTracker).when(appContext).getNodeTracker();
    doReturn(DAGAppMasterState.RUNNING).when(appContext).getAMState();
    doReturn(true).when(appContext).isSession();
    doReturn(dagID).when(appContext).getCurrentDAGID();
    doReturn(mock(ClusterInfo.class)).when(appContext).getClusterInfo();
    TaskSchedulerManager taskSchedulerManagerReal = new TaskSchedulerManagerForTest(appContext, eventHandler, rmClient, new AlwaysMatchesContainerMatcher(), TezUtils.createUserPayloadFromConf(tezConf));
    TaskSchedulerManager taskSchedulerManager = spy(taskSchedulerManagerReal);
    taskSchedulerManager.init(tezConf);
    taskSchedulerManager.start();
    TaskSchedulerWithDrainableContext taskScheduler = (TaskSchedulerWithDrainableContext) ((TaskSchedulerManagerForTest) taskSchedulerManager).getSpyTaskScheduler();
    TaskSchedulerContextDrainable drainableAppCallback = taskScheduler.getDrainableAppCallback();
    AtomicBoolean drainNotifier = new AtomicBoolean(false);
    taskScheduler.delayedContainerManager.drainedDelayedContainersForTest = drainNotifier;
    Resource resource1 = Resource.newInstance(1024, 1);
    String[] host1 = { "host1" };
    String[] racks = { "/default-rack" };
    Priority priority1 = Priority.newInstance(3);
    Priority priority2 = Priority.newInstance(4);
    TezVertexID vertexID1 = TezVertexID.getInstance(dagID, 1);
    TezVertexID vertexID2 = TezVertexID.getInstance(dagID, 2);
    // Vertex 1, Task 1, Attempt 1, host1
    TezTaskAttemptID taID11 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID1, 1), 1);
    TaskAttempt ta11 = mock(TaskAttempt.class);
    doReturn(vertexID1).when(ta11).getVertexID();
    AMSchedulerEventTALaunchRequest lrEvent11 = createLaunchRequestEvent(taID11, ta11, resource1, host1, racks, priority1);
    // Vertex2, Task1, Attempt 1, host1
    TezTaskAttemptID taID21 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID2, 1), 1);
    TaskAttempt ta21 = mock(TaskAttempt.class);
    doReturn(vertexID2).when(ta21).getVertexID();
    AMSchedulerEventTALaunchRequest lrEvent21 = createLaunchRequestEvent(taID21, ta21, resource1, host1, racks, priority2);
    // Send launch request for task 1 onle, deterministic assignment to this task.
    taskSchedulerManager.handleEvent(lrEvent11);
    Container container1 = createContainer(1, host1[0], resource1, priority1);
    // One container allocated.
    taskScheduler.onContainersAllocated(Collections.singletonList(container1));
    TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
    drainableAppCallback.drain();
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta11), any(Object.class), eq(container1));
    // Send launch request for task2 (vertex2)
    taskSchedulerManager.handleEvent(lrEvent21);
    // Task assigned to container completed successfully.
    // Container should  be assigned to task21.
    taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta11, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
    drainableAppCallback.drain();
    verifyDeAllocateTask(taskScheduler, ta11, true, null, null);
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta21), any(Object.class), eq(container1));
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    // Task 2 completes.
    taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta21, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    LOG.info("Sleeping to ensure that the container has been idled longer " + "than TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MAX_MILLIS ");
    Thread.sleep(50l);
    // container should not get released due to min held containers
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    taskScheduler.shutdown();
    taskSchedulerManager.close();
}
Also used : CapturingEventHandler(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.CapturingEventHandler) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TaskSchedulerWithDrainableContext(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerWithDrainableContext) AMContainerMap(org.apache.tez.dag.app.rm.container.AMContainerMap) AlwaysMatchesContainerMatcher(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AlwaysMatchesContainerMatcher) Container(org.apache.hadoop.yarn.api.records.Container) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TezDAGID(org.apache.tez.dag.records.TezDAGID) AMRMClientAsyncForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientAsyncForTest) TaskAttempt(org.apache.tez.dag.app.dag.TaskAttempt) ContainerHeartbeatHandler(org.apache.tez.dag.app.ContainerHeartbeatHandler) TaskSchedulerContextDrainable(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerContextDrainable) TezVertexID(org.apache.tez.dag.records.TezVertexID) Priority(org.apache.hadoop.yarn.api.records.Priority) AppContext(org.apache.tez.dag.app.AppContext) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) TaskCommunicatorManagerInterface(org.apache.tez.dag.app.TaskCommunicatorManagerInterface) ContainerContextMatcher(org.apache.tez.dag.app.rm.container.ContainerContextMatcher) AMNodeTracker(org.apache.tez.dag.app.rm.node.AMNodeTracker) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterInfo(org.apache.tez.dag.app.ClusterInfo) TaskSchedulerManagerForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerManagerForTest) CookieContainerRequest(org.apache.tez.dag.app.rm.YarnTaskSchedulerService.CookieContainerRequest) AMRMClientForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientForTest) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID) TaskSchedulerManagerForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerManagerForTest) AMRMClientForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientForTest) AMRMClientAsyncForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientAsyncForTest) Test(org.junit.Test)

Example 97 with TezVertexID

use of org.apache.tez.dag.records.TezVertexID in project tez by apache.

the class TestContainerReuse method testReuseConflictLocalResources.

@Test(timeout = 30000l)
public void testReuseConflictLocalResources() throws IOException, InterruptedException, ExecutionException {
    LOG.info("Test testReuseLocalResourcesChanged");
    Configuration tezConf = new Configuration(new YarnConfiguration());
    tezConf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
    tezConf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, true);
    tezConf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, true);
    tezConf.setLong(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 0);
    tezConf.setLong(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MIN_MILLIS, -1);
    CapturingEventHandler eventHandler = new CapturingEventHandler();
    TezDAGID dagID1 = TezDAGID.getInstance("0", 1, 0);
    AMRMClient<CookieContainerRequest> rmClientCore = new AMRMClientForTest();
    TezAMRMClientAsync<CookieContainerRequest> rmClient = spy(new AMRMClientAsyncForTest(rmClientCore, 100));
    AppContext appContext = mock(AppContext.class);
    doReturn(new Configuration(false)).when(appContext).getAMConf();
    ChangingDAGIDAnswer dagIDAnswer = new ChangingDAGIDAnswer(dagID1);
    AMContainerMap amContainerMap = new AMContainerMap(mock(ContainerHeartbeatHandler.class), mock(TaskCommunicatorManagerInterface.class), new ContainerContextMatcher(), appContext);
    AMNodeTracker amNodeTracker = new AMNodeTracker(eventHandler, appContext);
    doReturn(amContainerMap).when(appContext).getAllContainers();
    doReturn(amNodeTracker).when(appContext).getNodeTracker();
    doReturn(DAGAppMasterState.RUNNING).when(appContext).getAMState();
    doReturn(true).when(appContext).isSession();
    doAnswer(dagIDAnswer).when(appContext).getCurrentDAGID();
    doReturn(mock(ClusterInfo.class)).when(appContext).getClusterInfo();
    TaskSchedulerManager taskSchedulerManagerReal = new TaskSchedulerManagerForTest(appContext, eventHandler, rmClient, new ContainerContextMatcher(), TezUtils.createUserPayloadFromConf(tezConf));
    TaskSchedulerManager taskSchedulerManager = spy(taskSchedulerManagerReal);
    taskSchedulerManager.init(tezConf);
    taskSchedulerManager.start();
    TaskSchedulerWithDrainableContext taskScheduler = (TaskSchedulerWithDrainableContext) ((TaskSchedulerManagerForTest) taskSchedulerManager).getSpyTaskScheduler();
    TaskSchedulerContextDrainable drainableAppCallback = taskScheduler.getDrainableAppCallback();
    AtomicBoolean drainNotifier = new AtomicBoolean(false);
    taskScheduler.delayedContainerManager.drainedDelayedContainersForTest = drainNotifier;
    Resource resource1 = Resource.newInstance(1024, 1);
    String[] host1 = { "host1" };
    String[] racks = { "/default-rack" };
    Priority priority1 = Priority.newInstance(1);
    String rsrc1 = "rsrc1";
    String rsrc2 = "rsrc2";
    LocalResource lr1 = mock(LocalResource.class);
    doReturn(LocalResourceType.FILE).when(lr1).getType();
    LocalResource lr2 = mock(LocalResource.class);
    doReturn(LocalResourceType.FILE).when(lr2).getType();
    LocalResource lr3 = mock(LocalResource.class);
    doReturn(LocalResourceType.FILE).when(lr3).getType();
    AMContainerEventAssignTA assignEvent = null;
    Map<String, LocalResource> v11LR = Maps.newHashMap();
    v11LR.put(rsrc1, lr1);
    TezVertexID vertexID11 = TezVertexID.getInstance(dagID1, 1);
    // Vertex 1, Task 1, Attempt 1, host1, lr1
    TezTaskAttemptID taID111 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID11, 1), 1);
    TaskAttempt ta111 = mock(TaskAttempt.class);
    doReturn(taID111).when(ta111).getID();
    doReturn("Mock for TA " + taID111.toString()).when(ta111).toString();
    AMSchedulerEventTALaunchRequest lrEvent11 = createLaunchRequestEvent(taID111, ta111, resource1, host1, racks, priority1, v11LR);
    Map<String, LocalResource> v12LR = Maps.newHashMap();
    v12LR.put(rsrc1, lr1);
    v12LR.put(rsrc2, lr2);
    // Vertex 1, Task 2, Attempt 1, host1, lr1
    TezTaskAttemptID taID112 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID11, 2), 1);
    TaskAttempt ta112 = mock(TaskAttempt.class);
    doReturn(taID112).when(ta112).getID();
    doReturn("Mock for TA " + taID112.toString()).when(ta112).toString();
    AMSchedulerEventTALaunchRequest lrEvent12 = createLaunchRequestEvent(taID112, ta112, resource1, host1, racks, priority1, v12LR);
    // Vertex 1, Task 3, Attempt 1, host1
    TezTaskAttemptID taID113 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID11, 3), 1);
    TaskAttempt ta113 = mock(TaskAttempt.class);
    doReturn(taID113).when(ta113).getID();
    doReturn("Mock for TA " + taID113.toString()).when(ta113).toString();
    AMSchedulerEventTALaunchRequest lrEvent13 = createLaunchRequestEvent(taID113, ta113, resource1, host1, racks, priority1, new HashMap<String, LocalResource>());
    // Vertex 1, Task 4, Attempt 1, host1
    TezTaskAttemptID taID114 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID11, 4), 1);
    TaskAttempt ta114 = mock(TaskAttempt.class);
    doReturn(taID114).when(ta114).getID();
    doReturn("Mock for TA " + taID114.toString()).when(ta114).toString();
    AMSchedulerEventTALaunchRequest lrEvent14 = createLaunchRequestEvent(taID114, ta114, resource1, host1, racks, priority1, new HashMap<String, LocalResource>());
    taskSchedulerManager.handleEvent(lrEvent11);
    taskSchedulerManager.handleEvent(lrEvent12);
    Container container1 = createContainer(1, "host1", resource1, priority1);
    Container container2 = createContainer(2, "host1", resource1, priority1);
    // One container allocated.
    taskScheduler.onContainersAllocated(Collections.singletonList(container1));
    TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
    drainableAppCallback.drain();
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta111), any(Object.class), eq(container1));
    assignEvent = (AMContainerEventAssignTA) eventHandler.verifyInvocation(AMContainerEventAssignTA.class);
    assertEquals(1, assignEvent.getRemoteTaskLocalResources().size());
    // Task assigned to container completed successfully. Container should be re-used.
    taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta111, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
    drainableAppCallback.drain();
    verifyDeAllocateTask(taskScheduler, ta111, true, null, null);
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta112), any(Object.class), eq(container1));
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
    assignEvent = (AMContainerEventAssignTA) eventHandler.verifyInvocation(AMContainerEventAssignTA.class);
    assertEquals(1, assignEvent.getRemoteTaskLocalResources().size());
    eventHandler.reset();
    // Task assigned to container completed successfully.
    // Verify reuse across hosts.
    taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta112, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
    drainableAppCallback.drain();
    verifyDeAllocateTask(taskScheduler, ta112, true, null, null);
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
    eventHandler.reset();
    // Task 3
    taskSchedulerManager.handleEvent(lrEvent13);
    TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
    drainableAppCallback.drain();
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta113), any(Object.class), eq(container1));
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
    eventHandler.reset();
    taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta113, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
    drainableAppCallback.drain();
    verifyDeAllocateTask(taskScheduler, ta113, true, null, null);
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
    eventHandler.reset();
    // Task 4
    taskSchedulerManager.handleEvent(lrEvent14);
    TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
    drainableAppCallback.drain();
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta114), any(Object.class), eq(container1));
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
    eventHandler.reset();
    taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta114, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
    drainableAppCallback.drain();
    verifyDeAllocateTask(taskScheduler, ta114, true, null, null);
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
    eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
    eventHandler.reset();
    // Setup DAG2 with different resources.
    TezDAGID dagID2 = TezDAGID.getInstance("0", 2, 0);
    dagIDAnswer.setDAGID(dagID2);
    Map<String, LocalResource> v21LR = Maps.newHashMap();
    v21LR.put(rsrc1, lr1);
    v21LR.put(rsrc2, lr3);
    TezVertexID vertexID21 = TezVertexID.getInstance(dagID2, 1);
    // Vertex 2, Task 1, Attempt 1, host1, lr2
    TezTaskAttemptID taID211 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID21, 1), 1);
    TaskAttempt ta211 = mock(TaskAttempt.class);
    doReturn(taID211).when(ta211).getID();
    doReturn("Mock for TA " + taID211.toString()).when(ta211).toString();
    AMSchedulerEventTALaunchRequest lrEvent21 = createLaunchRequestEvent(taID211, ta211, resource1, host1, racks, priority1, v21LR);
    taskSchedulerManager.handleEvent(lrEvent21);
    TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
    drainableAppCallback.drain();
    verify(rmClient, times(1)).releaseAssignedContainer(eq(container1.getId()));
    taskScheduler.onContainersAllocated(Collections.singletonList(container2));
    TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
    drainableAppCallback.drain();
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta211), any(Object.class), eq(container2));
    eventHandler.reset();
    taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta211, container2.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
    drainableAppCallback.drain();
    verifyDeAllocateTask(taskScheduler, ta211, true, null, null);
    verify(rmClient, times(0)).releaseAssignedContainer(eq(container2.getId()));
    eventHandler.reset();
    // Setup DAG3 with a subset of resources from DAG2 (container should be reused).
    TezDAGID dagID3 = TezDAGID.getInstance("0", 3, 0);
    dagIDAnswer.setDAGID(dagID3);
    Map<String, LocalResource> v31LR = Collections.singletonMap(rsrc1, lr1);
    // dag3, vertex1, task1, ta1
    TezTaskAttemptID taID311 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(TezVertexID.getInstance(dagID3, 1), 1), 1);
    TaskAttempt ta311 = mock(TaskAttempt.class);
    doReturn(taID311).when(ta311).getID();
    doReturn("Mock for TA " + taID311).when(ta311).toString();
    AMSchedulerEventTALaunchRequest lrEvent31 = createLaunchRequestEvent(taID311, ta311, resource1, host1, racks, priority1, v31LR);
    taskSchedulerManager.handleEvent(lrEvent31);
    TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
    drainableAppCallback.drain();
    verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta311), any(Object.class), eq(container2));
    eventHandler.reset();
    taskScheduler.shutdown();
    taskSchedulerManager.close();
}
Also used : CapturingEventHandler(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.CapturingEventHandler) AMContainerEventAssignTA(org.apache.tez.dag.app.rm.container.AMContainerEventAssignTA) Configuration(org.apache.hadoop.conf.Configuration) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TaskSchedulerWithDrainableContext(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerWithDrainableContext) AMContainerMap(org.apache.tez.dag.app.rm.container.AMContainerMap) Container(org.apache.hadoop.yarn.api.records.Container) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TezDAGID(org.apache.tez.dag.records.TezDAGID) AMRMClientAsyncForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientAsyncForTest) TaskAttempt(org.apache.tez.dag.app.dag.TaskAttempt) ContainerHeartbeatHandler(org.apache.tez.dag.app.ContainerHeartbeatHandler) TaskSchedulerContextDrainable(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerContextDrainable) TezVertexID(org.apache.tez.dag.records.TezVertexID) Priority(org.apache.hadoop.yarn.api.records.Priority) AppContext(org.apache.tez.dag.app.AppContext) Resource(org.apache.hadoop.yarn.api.records.Resource) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) TaskCommunicatorManagerInterface(org.apache.tez.dag.app.TaskCommunicatorManagerInterface) ContainerContextMatcher(org.apache.tez.dag.app.rm.container.ContainerContextMatcher) AMNodeTracker(org.apache.tez.dag.app.rm.node.AMNodeTracker) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterInfo(org.apache.tez.dag.app.ClusterInfo) TaskSchedulerManagerForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerManagerForTest) CookieContainerRequest(org.apache.tez.dag.app.rm.YarnTaskSchedulerService.CookieContainerRequest) AMRMClientForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientForTest) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID) TaskSchedulerManagerForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.TaskSchedulerManagerForTest) AMRMClientForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientForTest) AMRMClientAsyncForTest(org.apache.tez.dag.app.rm.TestTaskSchedulerHelpers.AMRMClientAsyncForTest) Test(org.junit.Test)

Example 98 with TezVertexID

use of org.apache.tez.dag.records.TezVertexID in project tez by apache.

the class TestDAGImpl method _testTerminateRunningDAG.

@SuppressWarnings("unchecked")
private void _testTerminateRunningDAG(DAGTerminationCause terminationCause) {
    initDAG(dag);
    startDAG(dag);
    dispatcher.await();
    TezVertexID vId1 = TezVertexID.getInstance(dagId, 1);
    Vertex v1 = dag.getVertex(vId1);
    ((EventHandler<VertexEvent>) v1).handle(new VertexEventTaskCompleted(TezTaskID.getInstance(vId1, 0), TaskState.SUCCEEDED));
    TezVertexID vId0 = TezVertexID.getInstance(dagId, 0);
    Vertex v0 = dag.getVertex(vId0);
    ((EventHandler<VertexEvent>) v0).handle(new VertexEventTaskCompleted(TezTaskID.getInstance(vId0, 0), TaskState.SUCCEEDED));
    dispatcher.await();
    Assert.assertEquals(VertexState.SUCCEEDED, v0.getState());
    Assert.assertEquals(VertexState.RUNNING, v1.getState());
    dispatcher.getEventHandler().handle(new DAGEventTerminateDag(dagId, terminationCause, null));
    dispatcher.await();
    Assert.assertEquals(DAGState.TERMINATING, dag.getState());
    Assert.assertEquals(VertexState.SUCCEEDED, v0.getState());
    Assert.assertEquals(VertexState.TERMINATING, v1.getState());
    for (int i = 2; i < 6; ++i) {
        TezVertexID vId = TezVertexID.getInstance(dagId, i);
        Vertex v = dag.getVertex(vId);
        Assert.assertEquals(VertexState.KILLED, v.getState());
    }
    Assert.assertEquals(1, dag.getSuccessfulVertices());
}
Also used : Vertex(org.apache.tez.dag.app.dag.Vertex) EventHandler(org.apache.hadoop.yarn.event.EventHandler) HistoryEventHandler(org.apache.tez.dag.history.HistoryEventHandler) VertexEventTaskCompleted(org.apache.tez.dag.app.dag.event.VertexEventTaskCompleted) DAGEventTerminateDag(org.apache.tez.dag.app.dag.event.DAGEventTerminateDag) TezVertexID(org.apache.tez.dag.records.TezVertexID) PlanTaskLocationHint(org.apache.tez.dag.api.records.DAGProtos.PlanTaskLocationHint)

Example 99 with TezVertexID

use of org.apache.tez.dag.records.TezVertexID in project tez by apache.

the class TestAMContainer method testCredentialsTransfer.

@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testCredentialsTransfer() {
    WrappedContainerMultipleDAGs wc = new WrappedContainerMultipleDAGs();
    TezDAGID dagID2 = TezDAGID.getInstance("800", 500, 2);
    TezDAGID dagID3 = TezDAGID.getInstance("800", 500, 3);
    TezVertexID vertexID2 = TezVertexID.getInstance(dagID2, 1);
    TezVertexID vertexID3 = TezVertexID.getInstance(dagID3, 1);
    TezTaskID taskID2 = TezTaskID.getInstance(vertexID2, 1);
    TezTaskID taskID3 = TezTaskID.getInstance(vertexID3, 1);
    TezTaskAttemptID attempt11 = TezTaskAttemptID.getInstance(wc.taskID, 200);
    TezTaskAttemptID attempt12 = TezTaskAttemptID.getInstance(wc.taskID, 300);
    TezTaskAttemptID attempt21 = TezTaskAttemptID.getInstance(taskID2, 200);
    TezTaskAttemptID attempt22 = TezTaskAttemptID.getInstance(taskID2, 300);
    TezTaskAttemptID attempt31 = TezTaskAttemptID.getInstance(taskID3, 200);
    TezTaskAttemptID attempt32 = TezTaskAttemptID.getInstance(taskID3, 300);
    Map<String, LocalResource> LRs = new HashMap<String, LocalResource>();
    AMContainerTask fetchedTask = null;
    ArgumentCaptor<AMContainerTask> argumentCaptor = null;
    Token<TokenIdentifier> amGenToken = mock(Token.class);
    Token<TokenIdentifier> token1 = mock(Token.class);
    Token<TokenIdentifier> token3 = mock(Token.class);
    Credentials containerCredentials = new Credentials();
    TokenCache.setSessionToken(amGenToken, containerCredentials);
    Text token1Name = new Text("tokenDag1");
    Text token3Name = new Text("tokenDag3");
    Credentials dag1Credentials = new Credentials();
    dag1Credentials.addToken(new Text(token1Name), token1);
    Credentials dag3Credentials = new Credentials();
    dag3Credentials.addToken(new Text(token3Name), token3);
    wc.launchContainer(new HashMap<String, LocalResource>(), containerCredentials);
    wc.containerLaunched();
    wc.assignTaskAttempt(attempt11, LRs, dag1Credentials);
    argumentCaptor = ArgumentCaptor.forClass(AMContainerTask.class);
    verify(wc.tal, times(1)).registerTaskAttempt(argumentCaptor.capture(), eq(wc.containerID), eq(0));
    fetchedTask = argumentCaptor.getAllValues().get(0);
    assertTrue(fetchedTask.haveCredentialsChanged());
    assertNotNull(fetchedTask.getCredentials());
    assertNotNull(fetchedTask.getCredentials().getToken(token1Name));
    wc.taskAttemptSucceeded(attempt11);
    wc.assignTaskAttempt(attempt12, LRs, dag1Credentials);
    argumentCaptor = ArgumentCaptor.forClass(AMContainerTask.class);
    verify(wc.tal, times(2)).registerTaskAttempt(argumentCaptor.capture(), eq(wc.containerID), eq(0));
    fetchedTask = argumentCaptor.getAllValues().get(1);
    assertFalse(fetchedTask.haveCredentialsChanged());
    assertNull(fetchedTask.getCredentials());
    wc.taskAttemptSucceeded(attempt12);
    // Move to running a second DAG, with no credentials.
    wc.setNewDAGID(dagID2);
    wc.assignTaskAttempt(attempt21, LRs, null);
    argumentCaptor = ArgumentCaptor.forClass(AMContainerTask.class);
    verify(wc.tal, times(3)).registerTaskAttempt(argumentCaptor.capture(), eq(wc.containerID), eq(0));
    fetchedTask = argumentCaptor.getAllValues().get(2);
    assertTrue(fetchedTask.haveCredentialsChanged());
    assertNull(fetchedTask.getCredentials());
    wc.taskAttemptSucceeded(attempt21);
    wc.assignTaskAttempt(attempt22, LRs, null);
    argumentCaptor = ArgumentCaptor.forClass(AMContainerTask.class);
    verify(wc.tal, times(4)).registerTaskAttempt(argumentCaptor.capture(), eq(wc.containerID), eq(0));
    fetchedTask = argumentCaptor.getAllValues().get(3);
    assertFalse(fetchedTask.haveCredentialsChanged());
    assertNull(fetchedTask.getCredentials());
    wc.taskAttemptSucceeded(attempt22);
    // Move to running a third DAG, with Credentials this time
    wc.setNewDAGID(dagID3);
    wc.assignTaskAttempt(attempt31, LRs, dag3Credentials);
    argumentCaptor = ArgumentCaptor.forClass(AMContainerTask.class);
    verify(wc.tal, times(5)).registerTaskAttempt(argumentCaptor.capture(), eq(wc.containerID), eq(0));
    fetchedTask = argumentCaptor.getAllValues().get(4);
    assertTrue(fetchedTask.haveCredentialsChanged());
    assertNotNull(fetchedTask.getCredentials());
    assertNotNull(fetchedTask.getCredentials().getToken(token3Name));
    assertNull(fetchedTask.getCredentials().getToken(token1Name));
    wc.taskAttemptSucceeded(attempt31);
    wc.assignTaskAttempt(attempt32, LRs, dag1Credentials);
    argumentCaptor = ArgumentCaptor.forClass(AMContainerTask.class);
    verify(wc.tal, times(6)).registerTaskAttempt(argumentCaptor.capture(), eq(wc.containerID), eq(0));
    fetchedTask = argumentCaptor.getAllValues().get(5);
    assertFalse(fetchedTask.haveCredentialsChanged());
    assertNull(fetchedTask.getCredentials());
    wc.taskAttemptSucceeded(attempt32);
}
Also used : JobTokenIdentifier(org.apache.tez.common.security.JobTokenIdentifier) TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) TezTaskID(org.apache.tez.dag.records.TezTaskID) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) TezDAGID(org.apache.tez.dag.records.TezDAGID) TezVertexID(org.apache.tez.dag.records.TezVertexID) Credentials(org.apache.hadoop.security.Credentials) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID) Test(org.junit.Test)

Example 100 with TezVertexID

use of org.apache.tez.dag.records.TezVertexID in project tez by apache.

the class TestHistoryEventsProtoConversion method testVertexGroupCommitStartedEvent.

private void testVertexGroupCommitStartedEvent() throws Exception {
    TezVertexID vertexId1 = TezVertexID.getInstance(TezDAGID.getInstance(ApplicationId.newInstance(0, 1), 0), 1);
    TezVertexID vertexId2 = TezVertexID.getInstance(TezDAGID.getInstance(ApplicationId.newInstance(0, 1), 0), 2);
    Collection<TezVertexID> vertexIds = Lists.newArrayList(vertexId1, vertexId2);
    VertexGroupCommitStartedEvent event = new VertexGroupCommitStartedEvent(TezDAGID.getInstance(ApplicationId.newInstance(0, 1), 1), "fooGroup", vertexIds, 1000344l);
    {
        VertexGroupCommitStartedEvent deserializedEvent = (VertexGroupCommitStartedEvent) testProtoConversion(event);
        Assert.assertEquals(event.getDagID(), deserializedEvent.getDagID());
        Assert.assertEquals(event.getVertexGroupName(), deserializedEvent.getVertexGroupName());
        Assert.assertEquals(event.getVertexIds(), vertexIds);
        logEvents(event, deserializedEvent);
    }
    {
        VertexGroupCommitStartedEvent deserializedEvent = (VertexGroupCommitStartedEvent) testSummaryProtoConversion(event);
        Assert.assertEquals(event.getVertexGroupName(), deserializedEvent.getVertexGroupName());
        logEvents(event, deserializedEvent);
    }
}
Also used : TezVertexID(org.apache.tez.dag.records.TezVertexID)

Aggregations

TezVertexID (org.apache.tez.dag.records.TezVertexID)117 Test (org.junit.Test)64 TezDAGID (org.apache.tez.dag.records.TezDAGID)61 TezTaskAttemptID (org.apache.tez.dag.records.TezTaskAttemptID)54 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)46 Configuration (org.apache.hadoop.conf.Configuration)43 TezTaskID (org.apache.tez.dag.records.TezTaskID)43 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)40 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)31 Resource (org.apache.hadoop.yarn.api.records.Resource)29 Container (org.apache.hadoop.yarn.api.records.Container)28 ClusterInfo (org.apache.tez.dag.app.ClusterInfo)28 TaskCommunicatorManagerInterface (org.apache.tez.dag.app.TaskCommunicatorManagerInterface)28 ContainerHeartbeatHandler (org.apache.tez.dag.app.ContainerHeartbeatHandler)27 AMContainerMap (org.apache.tez.dag.app.rm.container.AMContainerMap)27 ContainerContextMatcher (org.apache.tez.dag.app.rm.container.ContainerContextMatcher)27 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)24 TezEvent (org.apache.tez.runtime.api.impl.TezEvent)24 SystemClock (org.apache.hadoop.yarn.util.SystemClock)22 Vertex (org.apache.tez.dag.app.dag.Vertex)22