use of org.apache.tez.dag.app.AppContext in project tez by apache.
the class TestDAGRecovery method setup.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setup() {
conf = new Configuration();
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, false);
appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(100, 1), 1);
dagId = TezDAGID.getInstance(appAttemptId.getApplicationId(), 1);
Assert.assertNotNull(dagId);
dagPlan = createDAGPlan();
dispatcher = new DrainDispatcher();
fsTokens = new Credentials();
appContext = mock(AppContext.class);
execService = mock(ListeningExecutorService.class);
thh = mock(TaskHeartbeatHandler.class);
final ListenableFuture<Void> mockFuture = mock(ListenableFuture.class);
when(appContext.getHadoopShim()).thenReturn(new DefaultHadoopShim());
when(appContext.getApplicationID()).thenReturn(appAttemptId.getApplicationId());
when(appContext.getClock()).thenReturn(new SystemClock());
Mockito.doAnswer(new Answer() {
public ListenableFuture<Void> answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
CallableEvent e = (CallableEvent) args[0];
dispatcher.getEventHandler().handle(e);
return mockFuture;
}
}).when(execService).submit((Callable<Void>) any());
doReturn(execService).when(appContext).getExecService();
historyEventHandler = new MockHistoryEventHandler(appContext);
aclManager = new ACLManager("amUser");
doReturn(conf).when(appContext).getAMConf();
doReturn(appAttemptId).when(appContext).getApplicationAttemptId();
doReturn(appAttemptId.getApplicationId()).when(appContext).getApplicationID();
doReturn(dagId).when(appContext).getCurrentDAGID();
doReturn(historyEventHandler).when(appContext).getHistoryHandler();
doReturn(aclManager).when(appContext).getAMACLManager();
doReturn(dagRecoveryData).when(appContext).getDAGRecoveryData();
dag = new DAGImpl(dagId, conf, dagPlan, dispatcher.getEventHandler(), taskCommunicatorManagerInterface, fsTokens, clock, "user", thh, appContext);
dag.entityUpdateTracker = new StateChangeNotifierForTest(dag);
doReturn(dag).when(appContext).getCurrentDAG();
ugi = mock(UserGroupInformation.class);
UserGroupInformation ugi = dag.getDagUGI();
doReturn(clusterInfo).when(appContext).getClusterInfo();
TaskSchedulerManager mockTaskScheduler = mock(TaskSchedulerManager.class);
doReturn(mockTaskScheduler).when(appContext).getTaskScheduler();
v1Id = TezVertexID.getInstance(dagId, 0);
t1v1Id = TezTaskID.getInstance(v1Id, 0);
ta1t1v1Id = TezTaskAttemptID.getInstance(t1v1Id, 0);
v2Id = TezVertexID.getInstance(dagId, 1);
t1v2Id = TezTaskID.getInstance(v2Id, 0);
ta1t1v2Id = TezTaskAttemptID.getInstance(t1v2Id, 0);
dispatcher.register(CallableEventType.class, new CallableEventDispatcher());
taskEventDispatcher = new TaskEventDispatcher();
dispatcher.register(TaskEventType.class, taskEventDispatcher);
taskAttemptEventDispatcher = new TaskAttemptEventDispatcher();
dispatcher.register(TaskAttemptEventType.class, taskAttemptEventDispatcher);
vertexEventDispatcher = new VertexEventDispatcher();
dispatcher.register(VertexEventType.class, vertexEventDispatcher);
dagEventDispatcher = new DagEventDispatcher();
dispatcher.register(DAGEventType.class, dagEventDispatcher);
dagFinishEventHandler = new DAGFinishEventHandler();
dispatcher.register(DAGAppMasterEventType.class, dagFinishEventHandler);
dispatcher.register(AMSchedulerEventType.class, new AMSchedulerEventDispatcher());
dispatcher.init(conf);
dispatcher.start();
doReturn(dispatcher.getEventHandler()).when(appContext).getEventHandler();
LogManager.getRootLogger().setLevel(Level.DEBUG);
}
use of org.apache.tez.dag.app.AppContext in project tez by apache.
the class TestContainerLauncherManager method testCustomLauncherSpecified.
@Test(timeout = 5000)
public void testCustomLauncherSpecified() throws IOException, TezException {
Configuration conf = new Configuration(false);
AppContext appContext = mock(AppContext.class);
TaskCommunicatorManagerInterface tal = mock(TaskCommunicatorManagerInterface.class);
String customLauncherName = "customLauncher";
List<NamedEntityDescriptor> launcherDescriptors = new LinkedList<>();
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(0, 3);
UserPayload customPayload = UserPayload.create(bb);
launcherDescriptors.add(new NamedEntityDescriptor(customLauncherName, FakeContainerLauncher.class.getName()).setUserPayload(customPayload));
ContainerLaucherRouterForMultipleLauncherTest clr = new ContainerLaucherRouterForMultipleLauncherTest(appContext, tal, null, launcherDescriptors, true);
try {
clr.init(conf);
clr.start();
assertEquals(1, clr.getNumContainerLaunchers());
assertFalse(clr.getYarnContainerLauncherCreated());
assertFalse(clr.getUberContainerLauncherCreated());
assertEquals(customLauncherName, clr.getContainerLauncherName(0));
assertEquals(bb, clr.getContainerLauncherContext(0).getInitialUserPayload().getPayload());
} finally {
clr.stop();
}
}
use of org.apache.tez.dag.app.AppContext in project tez by apache.
the class TestContainerLauncherManager method testMultipleContainerLaunchers.
@Test(timeout = 5000)
public void testMultipleContainerLaunchers() throws IOException, TezException {
Configuration conf = new Configuration(false);
conf.set("testkey", "testvalue");
UserPayload userPayload = TezUtils.createUserPayloadFromConf(conf);
AppContext appContext = mock(AppContext.class);
TaskCommunicatorManagerInterface tal = mock(TaskCommunicatorManagerInterface.class);
String customLauncherName = "customLauncher";
List<NamedEntityDescriptor> launcherDescriptors = new LinkedList<>();
ByteBuffer bb = ByteBuffer.allocate(4);
bb.putInt(0, 3);
UserPayload customPayload = UserPayload.create(bb);
launcherDescriptors.add(new NamedEntityDescriptor(customLauncherName, FakeContainerLauncher.class.getName()).setUserPayload(customPayload));
launcherDescriptors.add(new NamedEntityDescriptor(TezConstants.getTezYarnServicePluginName(), null).setUserPayload(userPayload));
ContainerLaucherRouterForMultipleLauncherTest clr = new ContainerLaucherRouterForMultipleLauncherTest(appContext, tal, null, launcherDescriptors, true);
try {
clr.init(conf);
clr.start();
assertEquals(2, clr.getNumContainerLaunchers());
assertTrue(clr.getYarnContainerLauncherCreated());
assertFalse(clr.getUberContainerLauncherCreated());
assertEquals(customLauncherName, clr.getContainerLauncherName(0));
assertEquals(bb, clr.getContainerLauncherContext(0).getInitialUserPayload().getPayload());
assertEquals(TezConstants.getTezYarnServicePluginName(), clr.getContainerLauncherName(1));
Configuration confParsed = TezUtils.createConfFromUserPayload(clr.getContainerLauncherContext(1).getInitialUserPayload());
assertEquals("testvalue", confParsed.get("testkey"));
} finally {
clr.stop();
}
}
use of org.apache.tez.dag.app.AppContext in project tez by apache.
the class TestContainerLauncherManager method testContainerLauncherUserError.
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testContainerLauncherUserError() throws ServicePluginException {
ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
EventHandler eventHandler = mock(EventHandler.class);
AppContext appContext = mock(AppContext.class);
doReturn(eventHandler).when(appContext).getEventHandler();
doReturn("testlauncher").when(appContext).getContainerLauncherName(0);
Configuration conf = new Configuration(false);
ContainerLauncherManager containerLauncherManager = new ContainerLauncherManager(appContext);
containerLauncherManager.setContainerLauncher(containerLauncher);
try {
containerLauncherManager.init(conf);
containerLauncherManager.start();
// launch container
doThrow(new RuntimeException("testexception")).when(containerLauncher).launchContainer(any(ContainerLaunchRequest.class));
ContainerLaunchContext clc1 = mock(ContainerLaunchContext.class);
Container container1 = mock(Container.class);
ContainerLauncherLaunchRequestEvent launchRequestEvent = new ContainerLauncherLaunchRequestEvent(clc1, container1, 0, 0, 0);
containerLauncherManager.handle(launchRequestEvent);
ArgumentCaptor<Event> argumentCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventHandler, times(1)).handle(argumentCaptor.capture());
Event rawEvent = argumentCaptor.getValue();
assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
DAGAppMasterEventUserServiceFatalError event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
assertEquals(DAGAppMasterEventType.CONTAINER_LAUNCHER_SERVICE_FATAL_ERROR, event.getType());
assertTrue(event.getError().getMessage().contains("testexception"));
assertTrue(event.getDiagnosticInfo().contains("launching container"));
assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
reset(eventHandler);
// stop container
doThrow(new RuntimeException("teststopexception")).when(containerLauncher).stopContainer(any(ContainerStopRequest.class));
ContainerId containerId2 = mock(ContainerId.class);
NodeId nodeId2 = mock(NodeId.class);
ContainerLauncherStopRequestEvent stopRequestEvent = new ContainerLauncherStopRequestEvent(containerId2, nodeId2, null, 0, 0, 0);
argumentCaptor = ArgumentCaptor.forClass(Event.class);
containerLauncherManager.handle(stopRequestEvent);
verify(eventHandler, times(1)).handle(argumentCaptor.capture());
rawEvent = argumentCaptor.getValue();
assertTrue(rawEvent instanceof DAGAppMasterEventUserServiceFatalError);
event = (DAGAppMasterEventUserServiceFatalError) rawEvent;
assertTrue(event.getError().getMessage().contains("teststopexception"));
assertTrue(event.getDiagnosticInfo().contains("stopping container"));
assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
} finally {
containerLauncherManager.stop();
}
}
use of org.apache.tez.dag.app.AppContext in project tez by apache.
the class TestContainerReuse method testDelayedReuseContainerBecomesAvailable.
@Test(timeout = 15000l)
public void testDelayedReuseContainerBecomesAvailable() throws IOException, InterruptedException, ExecutionException {
LOG.info("Test testDelayedReuseContainerBecomesAvailable");
Configuration conf = new Configuration(new YarnConfiguration());
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, true);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_RACK_FALLBACK_ENABLED, false);
conf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_NON_LOCAL_FALLBACK_ENABLED, false);
conf.setLong(TezConfiguration.TEZ_AM_CONTAINER_REUSE_LOCALITY_DELAY_ALLOCATION_MILLIS, 3000l);
conf.setLong(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MIN_MILLIS, 0);
conf.setLong(TezConfiguration.TEZ_AM_CONTAINER_IDLE_RELEASE_TIMEOUT_MAX_MILLIS, 0);
CapturingEventHandler eventHandler = new CapturingEventHandler();
TezDAGID dagID = TezDAGID.getInstance("0", 0, 0);
TezVertexID vertexID = TezVertexID.getInstance(dagID, 1);
AMRMClient<CookieContainerRequest> rmClientCore = new AMRMClientForTest();
TezAMRMClientAsync<CookieContainerRequest> rmClient = spy(new AMRMClientAsyncForTest(rmClientCore, 100));
AppContext appContext = mock(AppContext.class);
doReturn(conf).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(DAGAppMasterState.RUNNING).when(appContext).getAMState();
doReturn(amNodeTracker).when(appContext).getNodeTracker();
doReturn(dagID).when(appContext).getCurrentDAGID();
doReturn(mock(ClusterInfo.class)).when(appContext).getClusterInfo();
TaskSchedulerManager taskSchedulerManagerReal = new TaskSchedulerManagerForTest(appContext, eventHandler, rmClient, new AlwaysMatchesContainerMatcher(), TezUtils.createUserPayloadFromConf(conf));
TaskSchedulerManager taskSchedulerManager = spy(taskSchedulerManagerReal);
taskSchedulerManager.init(conf);
taskSchedulerManager.start();
TaskSchedulerWithDrainableContext taskScheduler = (TaskSchedulerWithDrainableContext) ((TaskSchedulerManagerForTest) taskSchedulerManager).getSpyTaskScheduler();
TaskSchedulerContextDrainable drainableAppCallback = taskScheduler.getDrainableAppCallback();
AtomicBoolean drainNotifier = new AtomicBoolean(false);
taskScheduler.delayedContainerManager.drainedDelayedContainersForTest = drainNotifier;
Resource resource = Resource.newInstance(1024, 1);
Priority priority = Priority.newInstance(5);
String[] host1 = { "host1" };
String[] host2 = { "host2" };
String[] defaultRack = { "/default-rack" };
TezTaskAttemptID taID11 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID, 1), 1);
TezTaskAttemptID taID21 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID, 2), 1);
TezTaskAttemptID taID31 = TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexID, 3), 1);
TaskAttempt ta11 = mock(TaskAttempt.class);
TaskAttempt ta21 = mock(TaskAttempt.class);
TaskAttempt ta31 = mock(TaskAttempt.class);
AMSchedulerEventTALaunchRequest lrTa11 = createLaunchRequestEvent(taID11, ta11, resource, host1, defaultRack, priority);
AMSchedulerEventTALaunchRequest lrTa21 = createLaunchRequestEvent(taID21, ta21, resource, host2, defaultRack, priority);
AMSchedulerEventTALaunchRequest lrTa31 = createLaunchRequestEvent(taID31, ta31, resource, host1, defaultRack, priority);
taskSchedulerManager.handleEvent(lrTa11);
taskSchedulerManager.handleEvent(lrTa21);
Container containerHost1 = createContainer(1, host1[0], resource, priority);
Container containerHost2 = createContainer(2, host2[0], resource, priority);
taskScheduler.onContainersAllocated(Lists.newArrayList(containerHost1, containerHost2));
TestTaskSchedulerHelpers.waitForDelayedDrainNotify(drainNotifier);
drainableAppCallback.drain();
verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta11), any(Object.class), eq(containerHost1));
verify(taskSchedulerManager).taskAllocated(eq(0), eq(ta21), any(Object.class), eq(containerHost2));
// Adding the event later so that task1 assigned to containerHost1
// is deterministic.
taskSchedulerManager.handleEvent(lrTa31);
taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta11, containerHost1.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
drainableAppCallback.drain();
verifyDeAllocateTask(taskScheduler, ta11, true, null, null);
verify(taskSchedulerManager, times(1)).taskAllocated(eq(0), eq(ta31), any(Object.class), eq(containerHost1));
verify(rmClient, times(0)).releaseAssignedContainer(eq(containerHost1.getId()));
eventHandler.verifyNoInvocations(AMContainerEventStopRequest.class);
eventHandler.reset();
taskSchedulerManager.handleEvent(new AMSchedulerEventTAEnded(ta21, containerHost2.getId(), TaskAttemptState.SUCCEEDED, null, null, 0));
long currentTs = System.currentTimeMillis();
Throwable exception = null;
while (System.currentTimeMillis() < currentTs + 5000l) {
try {
verify(taskSchedulerManager, times(1)).containerBeingReleased(eq(0), eq(containerHost2.getId()));
exception = null;
break;
} catch (Throwable e) {
exception = e;
}
}
assertTrue("containerHost2 was not released", exception == null);
taskScheduler.shutdown();
taskSchedulerManager.close();
}
Aggregations