diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/ApplicationConstants.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/ApplicationConstants.java index 8a824ec..9600142 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/ApplicationConstants.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/ApplicationConstants.java @@ -177,7 +177,15 @@ * $LOCAL_DIRS * Final, exported by NodeManager and non-modifiable by users. */ - LOCAL_DIRS("LOCAL_DIRS"); + LOCAL_DIRS("LOCAL_DIRS"), + + /** + * $LOG_DIRS + * Final, exported by NodeManager and non-modifiable by users. + * Comma separate list of directories that the container should use for + * logging. + */ + LOG_DIRS("LOG_DIRS"); private final String variable; private Environment(String variable) { diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java index ec63d35..0ce3b0d 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/ContainerLaunch.java @@ -132,9 +132,10 @@ public Integer call() { // Before the container script gets written out. List newCmds = new ArrayList(command.size()); String appIdStr = app.getAppId().toString(); + String relativeContainerLogDir = ContainerLaunch + .getRelativeContainerLogDir(appIdStr, containerIdStr); Path containerLogDir = - dirsHandler.getLogPathForWrite(ContainerLaunch - .getRelativeContainerLogDir(appIdStr, containerIdStr), false); + dirsHandler.getLogPathForWrite(relativeContainerLogDir, false); for (String str : command) { // TODO: Should we instead work via symlinks without this grammar? newCmds.add(str.replace(ApplicationConstants.LOG_DIR_EXPANSION_VAR, @@ -189,6 +190,11 @@ public Integer call() { List localDirs = dirsHandler.getLocalDirs(); List logDirs = dirsHandler.getLogDirs(); + List containerLogDirs = new ArrayList(); + for( String logDir : logDirs) { + containerLogDirs.add(logDir + Path.SEPARATOR + relativeContainerLogDir); + } + if (!dirsHandler.areDisksHealthy()) { ret = ContainerExitStatus.DISKS_FAILED; throw new IOException("Most of the disks failed. " @@ -215,7 +221,8 @@ public Integer call() { FINAL_CONTAINER_TOKENS_FILE).toUri().getPath()); // Sanitize the container's environment - sanitizeEnv(environment, containerWorkDir, appDirs, localResources); + sanitizeEnv(environment, containerWorkDir, appDirs, containerLogDirs, + localResources); // Write out the environment writeLaunchEnv(containerScriptOutStream, environment, localResources, @@ -543,9 +550,9 @@ private static void putEnvIfAbsent( } } - public void sanitizeEnv(Map environment, - Path pwd, List appDirs, Map> resources) - throws IOException { + public void sanitizeEnv(Map environment, Path pwd, + List appDirs, List containerLogDirs, + Map> resources) throws IOException { /** * Non-modifiable environment variables */ @@ -565,6 +572,9 @@ public void sanitizeEnv(Map environment, environment.put(Environment.LOCAL_DIRS.name(), StringUtils.join(",", appDirs)); + environment.put(Environment.LOG_DIRS.name(), + StringUtils.join(",", containerLogDirs)); + putEnvIfNotNull(environment, Environment.USER.name(), container.getUser()); putEnvIfNotNull(environment, diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java index 35630e6..a79d165 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/launcher/TestContainerLaunch.java @@ -248,6 +248,8 @@ public void testContainerEnvVariables() throws Exception { // Now verify the contents of the file List localDirs = dirsHandler.getLocalDirs(); + List logDirs = dirsHandler.getLogDirs(); + List appDirs = new ArrayList(localDirs.size()); for (String localDir : localDirs) { Path usersdir = new Path(localDir, ContainerLocalizer.USERCACHE); @@ -255,6 +257,12 @@ public void testContainerEnvVariables() throws Exception { Path appsdir = new Path(userdir, ContainerLocalizer.APPCACHE); appDirs.add(new Path(appsdir, appId.toString())); } + List containerLogDirs = new ArrayList(); + String relativeContainerLogDir = ContainerLaunch + .getRelativeContainerLogDir(appId.toString(), cId.toString()); + for(String logDir : logDirs){ + containerLogDirs.add(logDir + Path.SEPARATOR + relativeContainerLogDir); + } BufferedReader reader = new BufferedReader(new FileReader(processStartFile)); Assert.assertEquals(cId.toString(), reader.readLine()); @@ -274,6 +282,9 @@ public void testContainerEnvVariables() throws Exception { .getEnvironment().get(Environment.NM_HTTP_PORT.name())); Assert.assertEquals(StringUtils.join(",", appDirs), containerLaunchContext .getEnvironment().get(Environment.LOCAL_DIRS.name())); + Assert.assertEquals(StringUtils.join(",", containerLogDirs), + containerLaunchContext.getEnvironment().get(Environment.LOG_DIRS.name())); + // Get the pid of the process String pid = reader.readLine().trim(); // No more lines