Search in sources :

Example 1 with DefaultLinuxContainerRuntime

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime in project hadoop by apache.

the class TestLinuxContainerExecutorWithMocks method testContainerLaunchError.

@Test
public void testContainerLaunchError() throws IOException, ContainerExecutionException {
    // reinitialize executer
    Configuration conf = new Configuration();
    setupMockExecutor(MOCK_EXECUTOR_WITH_ERROR, conf);
    conf.set(YarnConfiguration.NM_LOCAL_DIRS, "file:///bin/echo");
    conf.set(YarnConfiguration.NM_LOG_DIRS, "file:///dev/null");
    LinuxContainerExecutor exec;
    LinuxContainerRuntime linuxContainerRuntime = new DefaultLinuxContainerRuntime(PrivilegedOperationExecutor.getInstance(conf));
    linuxContainerRuntime.initialize(conf);
    exec = new LinuxContainerExecutor(linuxContainerRuntime);
    mockExec = spy(exec);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            String diagnostics = (String) invocationOnMock.getArguments()[0];
            assertTrue("Invalid Diagnostics message: " + diagnostics, diagnostics.contains("badcommand"));
            return null;
        }
    }).when(mockExec).logOutput(any(String.class));
    dirsHandler = new LocalDirsHandlerService();
    dirsHandler.init(conf);
    mockExec.setConf(conf);
    String appSubmitter = "nobody";
    String cmd = String.valueOf(PrivilegedOperation.RunAsUserCommand.LAUNCH_CONTAINER.getValue());
    String appId = "APP_ID";
    String containerId = "CONTAINER_ID";
    Container container = mock(Container.class);
    ContainerId cId = mock(ContainerId.class);
    ContainerLaunchContext context = mock(ContainerLaunchContext.class);
    HashMap<String, String> env = new HashMap<String, String>();
    when(container.getContainerId()).thenReturn(cId);
    when(container.getLaunchContext()).thenReturn(context);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            ContainerDiagnosticsUpdateEvent event = (ContainerDiagnosticsUpdateEvent) invocationOnMock.getArguments()[0];
            assertTrue("Invalid Diagnostics message: " + event.getDiagnosticsUpdate(), event.getDiagnosticsUpdate().contains("badcommand"));
            return null;
        }
    }).when(container).handle(any(ContainerDiagnosticsUpdateEvent.class));
    when(cId.toString()).thenReturn(containerId);
    when(context.getEnvironment()).thenReturn(env);
    Path scriptPath = new Path("file:///bin/echo");
    Path tokensPath = new Path("file:///dev/null");
    Path workDir = new Path("/tmp");
    Path pidFile = new Path(workDir, "pid.txt");
    mockExec.activateContainer(cId, pidFile);
    int ret = mockExec.launchContainer(new ContainerStartContext.Builder().setContainer(container).setNmPrivateContainerScriptPath(scriptPath).setNmPrivateTokensPath(tokensPath).setUser(appSubmitter).setAppId(appId).setContainerWorkDir(workDir).setLocalDirs(dirsHandler.getLocalDirs()).setLogDirs(dirsHandler.getLogDirs()).setFilecacheDirs(new ArrayList<>()).setUserLocalDirs(new ArrayList<>()).setContainerLocalDirs(new ArrayList<>()).setContainerLogDirs(new ArrayList<>()).build());
    Assert.assertNotSame(0, ret);
    assertEquals(Arrays.asList(YarnConfiguration.DEFAULT_NM_NONSECURE_MODE_LOCAL_USER, appSubmitter, cmd, appId, containerId, workDir.toString(), "/bin/echo", "/dev/null", pidFile.toString(), StringUtils.join(PrivilegedOperation.LINUX_FILE_PATH_SEPARATOR, dirsHandler.getLocalDirs()), StringUtils.join(PrivilegedOperation.LINUX_FILE_PATH_SEPARATOR, dirsHandler.getLogDirs()), "cgroups=none"), readMockParams());
}
Also used : Path(org.apache.hadoop.fs.Path) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HashMap(java.util.HashMap) LinuxContainerRuntime(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntime) DefaultLinuxContainerRuntime(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime) ArrayList(java.util.ArrayList) ContainerDiagnosticsUpdateEvent(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerDiagnosticsUpdateEvent) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) DefaultLinuxContainerRuntime(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 2 with DefaultLinuxContainerRuntime

use of org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime in project hadoop by apache.

the class TestLinuxContainerExecutorWithMocks method setup.

@Before
public void setup() throws IOException, ContainerExecutionException {
    assumeNotWindows();
    tmpMockExecutor = System.getProperty("test.build.data") + "/tmp-mock-container-executor";
    Configuration conf = new YarnConfiguration();
    LinuxContainerRuntime linuxContainerRuntime;
    setupMockExecutor(MOCK_EXECUTOR, conf);
    linuxContainerRuntime = new DefaultLinuxContainerRuntime(PrivilegedOperationExecutor.getInstance(conf));
    dirsHandler = new LocalDirsHandlerService();
    dirsHandler.init(conf);
    linuxContainerRuntime.initialize(conf);
    mockExec = new LinuxContainerExecutor(linuxContainerRuntime);
    mockExec.setConf(conf);
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) LinuxContainerRuntime(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntime) DefaultLinuxContainerRuntime(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime) DefaultLinuxContainerRuntime(org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime) Before(org.junit.Before)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2 DefaultLinuxContainerRuntime (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DefaultLinuxContainerRuntime)2 LinuxContainerRuntime (org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntime)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Path (org.apache.hadoop.fs.Path)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)1 Container (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container)1 ContainerDiagnosticsUpdateEvent (org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerDiagnosticsUpdateEvent)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1