use of org.apache.tez.dag.app.rm.container.AMContainerMap in project tez by apache.
the class TestContainerReuse method testReuseNonLocalRequest.
@Test(timeout = 30000l)
public void testReuseNonLocalRequest() throws IOException, InterruptedException, ExecutionException {
LOG.info("Test testReuseNonLocalRequest");
Configuration tezConf = new Configuration();
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, 100l);
tezConf.setLong(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MIN_MILLIS, 1000l);
tezConf.setLong(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MAX_MILLIS, 1000l);
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(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[] emptyHosts = new String[0];
String[] racks = { "default-rack" };
Priority priority = Priority.newInstance(3);
TezVertexID vertexID = TezVertexID.getInstance(dagID, 1);
// Vertex 1, Task 1, Attempt 1, no locality information.
TezTaskAttemptID taID11 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID, 1), 1);
TaskAttempt ta11 = mock(TaskAttempt.class);
doReturn(vertexID).when(ta11).getVertexID();
AMSchedulerEventTALaunchRequest lrEvent11 = createLaunchRequestEvent(taID11, ta11, resource1, emptyHosts, racks, priority);
// Vertex1, Task2, Attempt 1, no locality information.
TezTaskAttemptID taID12 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID, 2), 1);
TaskAttempt ta12 = mock(TaskAttempt.class);
doReturn(vertexID).when(ta12).getVertexID();
AMSchedulerEventTALaunchRequest lrEvent12 = createLaunchRequestEvent(taID12, ta12, resource1, emptyHosts, racks, priority);
// Send launch request for task 1 only, deterministic assignment to this task.
taskSchedulerManager.handleEvent(lrEvent11);
Container container1 = createContainer(1, "randomHost", resource1, priority);
// 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(lrEvent12);
// Task assigned to container completed successfully.
// Container should not be immediately assigned to task 2
// until delay expires.
taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta11, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
drainableAppCallback.drain();
verifyDeAllocateTask(taskScheduler, ta11, true, null, null);
verify(taskSchedulerManager, times(0)).taskAllocated(eq(0), eq(ta12), any(Object.class), eq(container1));
verify(rmClient, times(0)).releaseAssignedContainer(eq(container1.getId()));
eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
eventHandler.reset();
TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
drainableAppCallback.drain();
verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta12), any(Object.class), eq(container1));
// TA12 completed.
taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta12, container1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
drainableAppCallback.drain();
verify(rmClient).releaseAssignedContainer(eq(container1.getId()));
eventHandler.verifyInvocation(AMContainerEventStopRequest.class);
taskScheduler.shutdown();
taskSchedulerManager.close();
}
use of org.apache.tez.dag.app.rm.container.AMContainerMap in project tez by apache.
the class TestTaskCommunicatorManager1 method setUp.
@Before
public void setUp() throws TezException {
appId = ApplicationId.newInstance(1000, 1);
appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
dag = mock(DAG.class);
TezDAGID dagID = TezDAGID.getInstance(appId, 1);
vertexID = TezVertexID.getInstance(dagID, 1);
taskID = TezTaskID.getInstance(vertexID, 1);
taskAttemptID = TezTaskAttemptID.getInstance(taskID, 1);
credentials = new Credentials();
amContainerMap = mock(AMContainerMap.class);
Map<ApplicationAccessType, String> appAcls = new HashMap<ApplicationAccessType, String>();
eventHandler = mock(EventHandler.class);
MockClock clock = new MockClock();
appContext = mock(AppContext.class);
doReturn(eventHandler).when(appContext).getEventHandler();
doReturn(dag).when(appContext).getCurrentDAG();
doReturn(appAcls).when(appContext).getApplicationACLs();
doReturn(amContainerMap).when(appContext).getAllContainers();
doReturn(clock).when(appContext).getClock();
doReturn(appAttemptId).when(appContext).getApplicationAttemptId();
doReturn(credentials).when(appContext).getAppCredentials();
NodeId nodeId = NodeId.newInstance("localhost", 0);
AMContainer amContainer = mock(AMContainer.class);
Container container = mock(Container.class);
doReturn(nodeId).when(container).getNodeId();
doReturn(amContainer).when(amContainerMap).get(any(ContainerId.class));
doReturn(container).when(amContainer).getContainer();
Configuration conf = new TezConfiguration();
UserPayload defaultPayload;
try {
defaultPayload = TezUtils.createUserPayloadFromConf(conf);
} catch (IOException e) {
throw new TezUncheckedException(e);
}
taskAttemptListener = new TaskCommunicatorManagerInterfaceImplForTest(appContext, mock(TaskHeartbeatHandler.class), mock(ContainerHeartbeatHandler.class), Lists.newArrayList(new NamedEntityDescriptor(TezConstants.getTezYarnServicePluginName(), null).setUserPayload(defaultPayload)));
taskSpec = mock(TaskSpec.class);
doReturn(taskAttemptID).when(taskSpec).getTaskAttemptID();
amContainerTask = new AMContainerTask(taskSpec, null, null, false, 0);
containerTask = null;
}
use of org.apache.tez.dag.app.rm.container.AMContainerMap in project tez by apache.
the class TestAMNodeTracker method testNodeSelfBlacklist.
@Test(timeout = 10000)
public void testNodeSelfBlacklist() {
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 {
_testNodeSelfBlacklist(amNodeTracker, handler, 0);
} finally {
amNodeTracker.stop();
}
}
use of org.apache.tez.dag.app.rm.container.AMContainerMap in project tez by apache.
the class TestAMNodeTracker method testNodeSelfBlacklistAlternateScheduler1.
@Test(timeout = 10000)
public void testNodeSelfBlacklistAlternateScheduler1() {
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 {
_testNodeSelfBlacklist(amNodeTracker, handler, 1);
} finally {
amNodeTracker.stop();
}
}
use of org.apache.tez.dag.app.rm.container.AMContainerMap in project tez by apache.
the class TestAMNodeTracker method testSingleNodeNotBlacklistedAlternateScheduler2.
@Test(timeout = 5000)
public void testSingleNodeNotBlacklistedAlternateScheduler2() {
AppContext appContext = mock(AppContext.class);
Configuration conf = new Configuration(false);
conf.setInt(TezConfiguration.TEZ_AM_MAX_TASK_FAILURES_PER_NODE, 2);
conf.setBoolean(TezConfiguration.TEZ_AM_NODE_BLACKLISTING_ENABLED, true);
conf.setInt(TezConfiguration.TEZ_AM_NODE_BLACKLISTING_IGNORE_THRESHOLD, 33);
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();
// This should not affect the blacklisting behaviour
for (int i = 0; i < 10; i++) {
amNodeTracker.nodeSeen(NodeId.newInstance("fakenode" + i, 3333), 0);
}
_testSingleNodeNotBlacklisted(amNodeTracker, handler, 1);
// No impact on blacklisting for the alternate source
assertFalse(amNodeTracker.isBlacklistingIgnored(0));
}
Aggregations