ContainerExecutor implements Configurable { protected String[] getRunCommand(String command, String groupId, String userName, Path pidFile, Configuration conf) { boolean containerSchedPriorityIsSet = false; int containerSchedPriorityAdjustment = YarnConfiguration.DEFAULT_NM_CONTAINER_EXECUTOR_SCHED_PRIORITY; if (conf.get(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY) != null) { containerSchedPriorityIsSet = true; containerSchedPriorityAdjustment = conf .getInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY, YarnConfiguration.DEFAULT_NM_CONTAINER_EXECUTOR_SCHED_PRIORITY); } if (Shell.WINDOWS) { return new String[] { Shell.WINUTILS, "task", "create", groupId, "cmd /c " + command }; } else { List<String> retCommand = new ArrayList<String>(); if (containerSchedPriorityIsSet) { retCommand.addAll(Arrays.asList("nice", "-n", Integer.toString(containerSchedPriorityAdjustment))); } retCommand.addAll(Arrays.asList("bash", command)); return retCommand.toArray(new String[retCommand.size()]); } }  @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]); } }