ContainerExecutor implements Configurable { protected String[] getRunCommand(String command, String groupId, String userName, Path pidFile, Configuration conf) { return getRunCommand(command, groupId, userName, pidFile, conf, null); }  @Override void setConf(Configuration conf); @Override Configuration getConf(); abstract void init(); Path localizeClasspathJar(Path classPathJar, Path pwd, String owner); abstract void startLocalizer(Path nmPrivateContainerTokens,
      InetSocketAddress nmAddr, String user, String appId, String locId,
      LocalDirsHandlerService dirsHandler); abstract int launchContainer(Container container,
      Path nmPrivateContainerScriptPath, Path nmPrivateTokensPath,
      String user, String appId, Path containerWorkDir, 
      List<String> localDirs, List<String> logDirs); abstract boolean signalContainer(String user, String pid,
      Signal signal); abstract void deleteAsUser(String user, Path subDir, Path... basedirs); abstract boolean isContainerProcessAlive(String user, String pid); int reacquireContainer(String user, ContainerId containerId); void writeLaunchEnv(OutputStream out, Map<String, String> environment, Map<Path, List<String>> resources, List<String> command); void activateContainer(ContainerId containerId, Path pidFilePath); void deactivateContainer(ContainerId containerId); String getProcessId(ContainerId containerID); final static FsPermission TASK_LAUNCH_SCRIPT_PERMISSION; }
@Test (timeout = 5000) public void testRunCommandNoPriority() throws Exception { Configuration conf = new Configuration(); String[] command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf); assertTrue("first command should be the run command for the platform", command[0].equals(Shell.WINUTILS) || command[0].equals("bash")); }
@Test (timeout = 5000) public void testRunCommandwithPriority() throws Exception { Configuration conf = new Configuration(); conf.setInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY, 2); String[] command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf); if (Shell.WINDOWS) { assertEquals("first command should be the run command for the platform", Shell.WINUTILS, command[0]); } else { assertEquals("first command should be nice", "nice", command[0]); assertEquals("second command should be -n", "-n", command[1]); assertEquals("third command should be the priority", Integer.toString(2), command[2]); } conf.setInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY, -5); command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf); if (Shell.WINDOWS) { assertEquals("first command should be the run command for the platform", Shell.WINUTILS, command[0]); } else { assertEquals("first command should be nice", "nice", command[0]); assertEquals("second command should be -n", "-n", command[1]); assertEquals("third command should be the priority", Integer.toString(-5), command[2]); } }
@Test (timeout = 5000) public void testRunCommandWithNoResources() { assumeTrue(Shell.WINDOWS); Configuration conf = new Configuration(); String[] command = containerExecutor.getRunCommand("echo", "group1", null, null, conf, Resource.newInstance(1024, 1)); String[] expected = { Shell.WINUTILS, "task", "create", "-m", "-1", "-c", "-1", "group1", "cmd /c " + "echo" }; Assert.assertTrue(Arrays.equals(expected, command)); }
@Test (timeout = 5000) public void testRunCommandWithMemoryOnlyResources() { assumeTrue(Shell.WINDOWS); Configuration conf = new Configuration(); conf.set(YarnConfiguration.NM_WINDOWS_CONTAINER_MEMORY_LIMIT_ENABLED, "true"); String[] command = containerExecutor.getRunCommand("echo", "group1", null, null, conf, Resource.newInstance(1024, 1)); String[] expected = { Shell.WINUTILS, "task", "create", "-m", "1024", "-c", "-1", "group1", "cmd /c " + "echo" }; Assert.assertTrue(Arrays.equals(expected, command)); }
@Test (timeout = 5000) public void testRunCommandWithCpuAndMemoryResources() { assumeTrue(Shell.WINDOWS); Configuration conf = new Configuration(); conf.set(YarnConfiguration.NM_WINDOWS_CONTAINER_CPU_LIMIT_ENABLED, "true"); conf.set(YarnConfiguration.NM_WINDOWS_CONTAINER_MEMORY_LIMIT_ENABLED, "true"); String[] command = containerExecutor.getRunCommand("echo", "group1", null, null, conf, Resource.newInstance(1024, 1)); float yarnProcessors = NodeManagerHardwareUtils.getContainersCores( ResourceCalculatorPlugin.getResourceCalculatorPlugin(null, conf), conf); int cpuRate = Math.min(10000, (int) ((1 * 10000) / yarnProcessors)); String[] expected = { Shell.WINUTILS, "task", "create", "-m", "1024", "-c", String.valueOf(cpuRate), "group1", "cmd /c " + "echo" }; Assert.assertTrue(Arrays.equals(expected, command)); }