use of org.apache.tez.dag.app.rm.DagAwareYarnTaskScheduler.HeldContainer in project tez by apache.
the class TestDagAwareYarnTaskScheduler method testSessionContainers.
@Test(timeout = 30000)
public void testSessionContainers() throws Exception {
AMRMClientAsyncWrapperForTest mockRMClient = spy(new AMRMClientAsyncWrapperForTest());
String appHost = "host";
int appPort = 0;
String appUrl = "url";
Configuration conf = new Configuration();
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 100);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, true);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, false);
conf.setInt(TezConfiguration.TEZ_AM_RM_HEARTBEAT_INTERVAL_MS_MAX, 100);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MIN_MILLIS, 4000);
conf.setInt(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MAX_MILLIS, 5000);
conf.setInt(TezConfiguration.TEZ_AM_SESSION_MIN_HELD_CONTAINERS, 5);
DagInfo mockDagInfo = mock(DagInfo.class);
when(mockDagInfo.getTotalVertices()).thenReturn(10);
when(mockDagInfo.getVertexDescendants(anyInt())).thenReturn(new BitSet());
TaskSchedulerContext mockApp = setupMockTaskSchedulerContext(appHost, appPort, appUrl, conf);
when(mockApp.getCurrentDagInfo()).thenReturn(mockDagInfo);
when(mockApp.isSession()).thenReturn(true);
TaskSchedulerContextDrainable drainableAppCallback = createDrainableContext(mockApp);
MockClock clock = new MockClock(1000);
NewTaskSchedulerForTest scheduler = new NewTaskSchedulerForTest(drainableAppCallback, mockRMClient, clock);
scheduler.initialize();
drainableAppCallback.drain();
scheduler.start();
drainableAppCallback.drain();
verify(mockRMClient).start();
verify(mockRMClient).registerApplicationMaster(appHost, appPort, appUrl);
RegisterApplicationMasterResponse regResponse = mockRMClient.getRegistrationResponse();
verify(mockApp).setApplicationRegistrationData(regResponse.getMaximumResourceCapability(), regResponse.getApplicationACLs(), regResponse.getClientToAMTokenMasterKey(), regResponse.getQueue());
assertEquals(scheduler.getClusterNodeCount(), mockRMClient.getClusterNodeCount());
final String rack1 = "/r1";
final String rack2 = "/r2";
final String rack3 = "/r3";
final String node1Rack1 = "n1r1";
final String node2Rack1 = "n2r1";
final String node1Rack2 = "n1r2";
final String node2Rack2 = "n2r2";
final String node1Rack3 = "n1r3";
MockDNSToSwitchMapping.addRackMapping(node1Rack1, rack1);
MockDNSToSwitchMapping.addRackMapping(node2Rack1, rack1);
MockDNSToSwitchMapping.addRackMapping(node1Rack2, rack2);
MockDNSToSwitchMapping.addRackMapping(node2Rack2, rack2);
MockDNSToSwitchMapping.addRackMapping(node1Rack3, rack3);
Priority priorityv0 = Priority.newInstance(1);
MockTaskInfo taskv0t0 = new MockTaskInfo("taskv0t0", priorityv0, node1Rack1, rack1);
MockTaskInfo taskv0t1 = new MockTaskInfo("taskv0t1", priorityv0, node2Rack1, rack1);
MockTaskInfo taskv0t2 = new MockTaskInfo("taskv0t2", priorityv0, node1Rack1, rack1);
MockTaskInfo taskv0t3 = new MockTaskInfo("taskv0t3", priorityv0, node2Rack1, rack1);
MockTaskInfo taskv0t4 = new MockTaskInfo("taskv0t4", priorityv0, node1Rack2, rack2);
MockTaskInfo taskv0t5 = new MockTaskInfo("taskv0t5", priorityv0, node2Rack2, rack2);
MockTaskInfo taskv0t6 = new MockTaskInfo("taskv0t6", priorityv0, node1Rack3, rack3);
TaskRequestCaptor taskRequestCaptor = new TaskRequestCaptor(mockRMClient, scheduler, drainableAppCallback);
TaskRequest reqv0t0 = taskRequestCaptor.scheduleTask(taskv0t0);
TaskRequest reqv0t1 = taskRequestCaptor.scheduleTask(taskv0t1);
TaskRequest reqv0t2 = taskRequestCaptor.scheduleTask(taskv0t2);
TaskRequest reqv0t3 = taskRequestCaptor.scheduleTask(taskv0t3);
TaskRequest reqv0t4 = taskRequestCaptor.scheduleTask(taskv0t4);
TaskRequest reqv0t5 = taskRequestCaptor.scheduleTask(taskv0t5);
TaskRequest reqv0t6 = taskRequestCaptor.scheduleTask(taskv0t6);
List<Container> containers = new ArrayList<>();
ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 1), 1);
ContainerId cid1 = ContainerId.newContainerId(attemptId, 1);
NodeId n1r1 = NodeId.newInstance(node1Rack1, 1);
Container container1 = Container.newInstance(cid1, n1r1, null, taskv0t0.capability, priorityv0, null);
containers.add(container1);
ContainerId cid2 = ContainerId.newContainerId(attemptId, 2);
NodeId n2r1 = NodeId.newInstance(node2Rack1, 1);
Container container2 = Container.newInstance(cid2, n2r1, null, taskv0t1.capability, priorityv0, null);
containers.add(container2);
ContainerId cid3 = ContainerId.newContainerId(attemptId, 3);
Container container3 = Container.newInstance(cid3, n1r1, null, taskv0t2.capability, priorityv0, null);
containers.add(container3);
ContainerId cid4 = ContainerId.newContainerId(attemptId, 4);
Container container4 = Container.newInstance(cid4, n2r1, null, taskv0t3.capability, priorityv0, null);
containers.add(container4);
ContainerId cid5 = ContainerId.newContainerId(attemptId, 5);
NodeId n1r2 = NodeId.newInstance(node1Rack2, 1);
Container container5 = Container.newInstance(cid5, n1r2, null, taskv0t4.capability, priorityv0, null);
containers.add(container5);
ContainerId cid6 = ContainerId.newContainerId(attemptId, 6);
NodeId n2r2 = NodeId.newInstance(node2Rack2, 1);
Container container6 = Container.newInstance(cid6, n2r2, null, taskv0t5.capability, priorityv0, null);
containers.add(container6);
ContainerId cid7 = ContainerId.newContainerId(attemptId, 7);
NodeId n1r3 = NodeId.newInstance(node1Rack3, 1);
Container container7 = Container.newInstance(cid7, n1r3, null, taskv0t6.capability, priorityv0, null);
containers.add(container7);
scheduler.onContainersAllocated(containers);
drainableAppCallback.drain();
verify(mockApp).taskAllocated(taskv0t0.task, taskv0t0.cookie, container1);
verify(mockRMClient).removeContainerRequest(reqv0t0);
verify(mockApp).taskAllocated(taskv0t1.task, taskv0t1.cookie, container2);
verify(mockRMClient).removeContainerRequest(reqv0t1);
verify(mockApp).taskAllocated(taskv0t2.task, taskv0t2.cookie, container3);
verify(mockRMClient).removeContainerRequest(reqv0t2);
verify(mockApp).taskAllocated(taskv0t3.task, taskv0t3.cookie, container4);
verify(mockRMClient).removeContainerRequest(reqv0t3);
verify(mockApp).taskAllocated(taskv0t4.task, taskv0t4.cookie, container5);
verify(mockRMClient).removeContainerRequest(reqv0t4);
verify(mockApp).taskAllocated(taskv0t5.task, taskv0t5.cookie, container6);
verify(mockRMClient).removeContainerRequest(reqv0t5);
verify(mockApp).taskAllocated(taskv0t6.task, taskv0t6.cookie, container7);
verify(mockRMClient).removeContainerRequest(reqv0t6);
clock.incrementTime(10000);
drainableAppCallback.drain();
assertTrue(scheduler.deallocateTask(taskv0t0.task, true, null, null));
assertTrue(scheduler.deallocateTask(taskv0t1.task, true, null, null));
assertTrue(scheduler.deallocateTask(taskv0t2.task, true, null, null));
assertTrue(scheduler.deallocateTask(taskv0t3.task, true, null, null));
assertTrue(scheduler.deallocateTask(taskv0t4.task, true, null, null));
assertTrue(scheduler.deallocateTask(taskv0t5.task, true, null, null));
assertTrue(scheduler.deallocateTask(taskv0t6.task, true, null, null));
verify(mockApp, never()).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, never()).releaseAssignedContainer(any(ContainerId.class));
// verify only two of the containers were released after idle expiration
// and the rest were spread across the nodes and racks
clock.incrementTime(5000);
drainableAppCallback.drain();
verify(mockApp, times(2)).containerBeingReleased(any(ContainerId.class));
verify(mockRMClient, times(2)).releaseAssignedContainer(any(ContainerId.class));
Set<String> hosts = new HashSet<>();
Set<String> racks = new HashSet<>();
for (HeldContainer hc : scheduler.getSessionContainers()) {
hosts.add(hc.getHost());
racks.add(hc.getRack());
}
assertEquals(5, hosts.size());
assertEquals(3, racks.size());
assertTrue(hosts.contains(node1Rack1));
assertTrue(hosts.contains(node2Rack1));
assertTrue(hosts.contains(node1Rack2));
assertTrue(hosts.contains(node2Rack2));
assertTrue(hosts.contains(node1Rack3));
assertTrue(racks.contains(rack1));
assertTrue(racks.contains(rack2));
assertTrue(racks.contains(rack3));
String appMsg = "success";
AppFinalStatus finalStatus = new AppFinalStatus(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
when(mockApp.getFinalAppStatus()).thenReturn(finalStatus);
scheduler.shutdown();
drainableAppCallback.drain();
verify(mockRMClient).unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, appMsg, appUrl);
verify(mockRMClient).stop();
}
Aggregations