use of org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent in project tez by apache.
the class TestContainerLauncherManager method testReportFailureFromContainerLauncher.
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testReportFailureFromContainerLauncher() throws ServicePluginException, TezException {
final String dagName = DAG_NAME;
final int dagIndex = DAG_INDEX;
TezDAGID dagId = TezDAGID.getInstance(ApplicationId.newInstance(0, 0), dagIndex);
DAG dag = mock(DAG.class);
doReturn(dagName).when(dag).getName();
doReturn(dagId).when(dag).getID();
EventHandler eventHandler = mock(EventHandler.class);
AppContext appContext = mock(AppContext.class);
doReturn(eventHandler).when(appContext).getEventHandler();
doReturn(dag).when(appContext).getCurrentDAG();
doReturn("testlauncher").when(appContext).getContainerLauncherName(0);
NamedEntityDescriptor<TaskCommunicatorDescriptor> taskCommDescriptor = new NamedEntityDescriptor<>("testlauncher", ContainerLauncherForTest.class.getName());
List<NamedEntityDescriptor> list = new LinkedList<>();
list.add(taskCommDescriptor);
ContainerLauncherManager containerLauncherManager = new ContainerLauncherManager(appContext, mock(TaskCommunicatorManagerInterface.class), "", list, false);
try {
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.getDiagnosticInfo().contains("ReportedFatalError"));
assertTrue(event.getDiagnosticInfo().contains(ServicePluginErrorDefaults.INCONSISTENT_STATE.name()));
assertTrue(event.getDiagnosticInfo().contains("[0:testlauncher]"));
reset(eventHandler);
// stop container
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 DAGEventTerminateDag);
DAGEventTerminateDag killEvent = (DAGEventTerminateDag) rawEvent;
assertTrue(killEvent.getDiagnosticInfo().contains("ReportError"));
assertTrue(killEvent.getDiagnosticInfo().contains(ServicePluginErrorDefaults.SERVICE_UNAVAILABLE.name()));
assertTrue(killEvent.getDiagnosticInfo().contains("[0:testlauncher]"));
} finally {
containerLauncherManager.stop();
}
}
use of org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent in project tez by apache.
the class TestContainerLauncherManager method testEventRouting.
@Test(timeout = 5000)
public void testEventRouting() throws Exception {
Configuration conf = new Configuration(false);
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(TezConstants.getTezYarnServicePluginName(), clr.getContainerLauncherName(1));
verify(clr.getTestContainerLauncher(0)).initialize();
verify(clr.getTestContainerLauncher(0)).start();
verify(clr.getTestContainerLauncher(1)).initialize();
verify(clr.getTestContainerLauncher(1)).start();
ContainerLaunchContext clc1 = mock(ContainerLaunchContext.class);
Container container1 = mock(Container.class);
ContainerLaunchContext clc2 = mock(ContainerLaunchContext.class);
Container container2 = mock(Container.class);
ContainerLauncherLaunchRequestEvent launchRequestEvent1 = new ContainerLauncherLaunchRequestEvent(clc1, container1, 0, 0, 0);
ContainerLauncherLaunchRequestEvent launchRequestEvent2 = new ContainerLauncherLaunchRequestEvent(clc2, container2, 1, 0, 0);
clr.handle(launchRequestEvent1);
ArgumentCaptor<ContainerLaunchRequest> captor = ArgumentCaptor.forClass(ContainerLaunchRequest.class);
verify(clr.getTestContainerLauncher(0)).launchContainer(captor.capture());
assertEquals(1, captor.getAllValues().size());
ContainerLaunchRequest launchRequest1 = captor.getValue();
assertEquals(clc1, launchRequest1.getContainerLaunchContext());
clr.handle(launchRequestEvent2);
captor = ArgumentCaptor.forClass(ContainerLaunchRequest.class);
verify(clr.getTestContainerLauncher(1)).launchContainer(captor.capture());
assertEquals(1, captor.getAllValues().size());
ContainerLaunchRequest launchRequest2 = captor.getValue();
assertEquals(clc2, launchRequest2.getContainerLaunchContext());
} finally {
clr.stop();
verify(clr.getTestContainerLauncher(0)).shutdown();
verify(clr.getTestContainerLauncher(1)).shutdown();
}
}
use of org.apache.tez.dag.app.rm.ContainerLauncherLaunchRequestEvent 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.rm.ContainerLauncherLaunchRequestEvent in project tez by apache.
the class ContainerLauncherManager method handle.
@Override
public void handle(ContainerLauncherEvent event) {
int launcherId = event.getLauncherId();
String schedulerName = appContext.getTaskSchedulerName(event.getSchedulerId());
String taskCommName = appContext.getTaskCommunicatorName(event.getTaskCommId());
switch(event.getType()) {
case CONTAINER_LAUNCH_REQUEST:
ContainerLauncherLaunchRequestEvent launchEvent = (ContainerLauncherLaunchRequestEvent) event;
ContainerLaunchRequest launchRequest = new ContainerLaunchRequest(launchEvent.getNodeId(), launchEvent.getContainerId(), launchEvent.getContainerToken(), launchEvent.getContainerLaunchContext(), launchEvent.getContainer(), schedulerName, taskCommName);
try {
containerLaunchers[launcherId].launchContainer(launchRequest);
} catch (Exception e) {
String msg = "Error when launching container" + ", containerLauncher=" + Utils.getContainerLauncherIdentifierString(launcherId, appContext) + ", scheduler=" + Utils.getTaskSchedulerIdentifierString(event.getSchedulerId(), appContext) + ", taskCommunicator=" + Utils.getTaskCommIdentifierString(event.getTaskCommId(), appContext);
LOG.error(msg, e);
sendEvent(new DAGAppMasterEventUserServiceFatalError(DAGAppMasterEventType.CONTAINER_LAUNCHER_SERVICE_FATAL_ERROR, msg, e));
}
break;
case CONTAINER_STOP_REQUEST:
ContainerStopRequest stopRequest = new ContainerStopRequest(event.getNodeId(), event.getContainerId(), event.getContainerToken(), schedulerName, taskCommName);
try {
containerLaunchers[launcherId].stopContainer(stopRequest);
} catch (Exception e) {
String msg = "Error when stopping container" + ", containerLauncher=" + Utils.getContainerLauncherIdentifierString(launcherId, appContext) + ", scheduler=" + Utils.getTaskSchedulerIdentifierString(event.getSchedulerId(), appContext) + ", taskCommunicator=" + Utils.getTaskCommIdentifierString(event.getTaskCommId(), appContext);
LOG.error(msg, e);
sendEvent(new DAGAppMasterEventUserServiceFatalError(DAGAppMasterEventType.CONTAINER_LAUNCHER_SERVICE_FATAL_ERROR, msg, e));
}
break;
}
}
Aggregations