YARN-602. Fixed NodeManager to not let users override some mandatory environmental variables. Contributed by Kenji Kikushima.

svn merge --ignore-ancestry -c 1518077 ../../trunk/


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1518078 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vinod Kumar Vavilapalli 2013-08-28 05:14:15 +00:00
parent 13ac033578
commit 0fb55f1aec
3 changed files with 65 additions and 9 deletions

View File

@ -96,6 +96,9 @@ Release 2.1.1-beta - UNRELEASED
YARN-981. Fixed YARN webapp so that /logs servlet works like before. (Jian He YARN-981. Fixed YARN webapp so that /logs servlet works like before. (Jian He
via vinodkv) via vinodkv)
YARN-602. Fixed NodeManager to not let users override some mandatory
environmental variables. (Kenji Kikushima via vinodkv)
Release 2.1.0-beta - 2013-08-22 Release 2.1.0-beta - 2013-08-22
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -588,20 +588,18 @@ public class ContainerLaunch implements Callable<Integer> {
environment.put(Environment.LOG_DIRS.name(), environment.put(Environment.LOG_DIRS.name(),
StringUtils.join(",", containerLogDirs)); StringUtils.join(",", containerLogDirs));
putEnvIfNotNull(environment, Environment.USER.name(), container.getUser()); environment.put(Environment.USER.name(), container.getUser());
putEnvIfNotNull(environment, environment.put(Environment.LOGNAME.name(), container.getUser());
Environment.LOGNAME.name(),container.getUser());
environment.put(Environment.HOME.name(),
putEnvIfNotNull(environment,
Environment.HOME.name(),
conf.get( conf.get(
YarnConfiguration.NM_USER_HOME_DIR, YarnConfiguration.NM_USER_HOME_DIR,
YarnConfiguration.DEFAULT_NM_USER_HOME_DIR YarnConfiguration.DEFAULT_NM_USER_HOME_DIR
) )
); );
putEnvIfNotNull(environment, Environment.PWD.name(), pwd.toString()); environment.put(Environment.PWD.name(), pwd.toString());
putEnvIfNotNull(environment, putEnvIfNotNull(environment,
Environment.HADOOP_CONF_DIR.name(), Environment.HADOOP_CONF_DIR.name(),

View File

@ -346,7 +346,6 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
ApplicationAttemptId appAttemptId = ApplicationAttemptId appAttemptId =
ApplicationAttemptId.newInstance(appId, 1); ApplicationAttemptId.newInstance(appId, 1);
int port = 12345;
ContainerId cId = ContainerId.newInstance(appAttemptId, 0); ContainerId cId = ContainerId.newInstance(appAttemptId, 0);
Map<String, String> userSetEnv = new HashMap<String, String>(); Map<String, String> userSetEnv = new HashMap<String, String>();
userSetEnv.put(Environment.CONTAINER_ID.name(), "user_set_container_id"); userSetEnv.put(Environment.CONTAINER_ID.name(), "user_set_container_id");
@ -354,6 +353,11 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
userSetEnv.put(Environment.NM_PORT.name(), "user_set_NM_PORT"); userSetEnv.put(Environment.NM_PORT.name(), "user_set_NM_PORT");
userSetEnv.put(Environment.NM_HTTP_PORT.name(), "user_set_NM_HTTP_PORT"); userSetEnv.put(Environment.NM_HTTP_PORT.name(), "user_set_NM_HTTP_PORT");
userSetEnv.put(Environment.LOCAL_DIRS.name(), "user_set_LOCAL_DIR"); userSetEnv.put(Environment.LOCAL_DIRS.name(), "user_set_LOCAL_DIR");
userSetEnv.put(Environment.USER.key(), "user_set_" +
Environment.USER.key());
userSetEnv.put(Environment.LOGNAME.name(), "user_set_LOGNAME");
userSetEnv.put(Environment.PWD.name(), "user_set_PWD");
userSetEnv.put(Environment.HOME.name(), "user_set_HOME");
containerLaunchContext.setEnvironment(userSetEnv); containerLaunchContext.setEnvironment(userSetEnv);
File scriptFile = Shell.appendScriptExtension(tmpDir, "scriptFile"); File scriptFile = Shell.appendScriptExtension(tmpDir, "scriptFile");
@ -371,6 +375,14 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
+ processStartFile); + processStartFile);
fileWriter.println("@echo " + Environment.LOCAL_DIRS.$() + ">> " fileWriter.println("@echo " + Environment.LOCAL_DIRS.$() + ">> "
+ processStartFile); + processStartFile);
fileWriter.println("@echo " + Environment.USER.$() + ">> "
+ processStartFile);
fileWriter.println("@echo " + Environment.LOGNAME.$() + ">> "
+ processStartFile);
fileWriter.println("@echo " + Environment.PWD.$() + ">> "
+ processStartFile);
fileWriter.println("@echo " + Environment.HOME.$() + ">> "
+ processStartFile);
fileWriter.println("@echo " + cId + ">> " + processStartFile); fileWriter.println("@echo " + cId + ">> " + processStartFile);
fileWriter.println("@ping -n 100 127.0.0.1 >nul"); fileWriter.println("@ping -n 100 127.0.0.1 >nul");
} else { } else {
@ -385,6 +397,14 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
+ processStartFile); + processStartFile);
fileWriter.write("\necho $" + Environment.LOCAL_DIRS.name() + " >> " fileWriter.write("\necho $" + Environment.LOCAL_DIRS.name() + " >> "
+ processStartFile); + processStartFile);
fileWriter.write("\necho $" + Environment.USER.name() + " >> "
+ processStartFile);
fileWriter.write("\necho $" + Environment.LOGNAME.name() + " >> "
+ processStartFile);
fileWriter.write("\necho $" + Environment.PWD.name() + " >> "
+ processStartFile);
fileWriter.write("\necho $" + Environment.HOME.name() + " >> "
+ processStartFile);
fileWriter.write("\necho $$ >> " + processStartFile); fileWriter.write("\necho $$ >> " + processStartFile);
fileWriter.write("\nexec sleep 100"); fileWriter.write("\nexec sleep 100");
} }
@ -452,6 +472,22 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
reader.readLine()); reader.readLine());
Assert.assertEquals(String.valueOf(HTTP_PORT), reader.readLine()); Assert.assertEquals(String.valueOf(HTTP_PORT), reader.readLine());
Assert.assertEquals(StringUtils.join(",", appDirs), reader.readLine()); Assert.assertEquals(StringUtils.join(",", appDirs), reader.readLine());
Assert.assertEquals(user, reader.readLine());
Assert.assertEquals(user, reader.readLine());
String obtainedPWD = reader.readLine();
boolean found = false;
for (Path localDir : appDirs) {
if (new Path(localDir, cId.toString()).toString().equals(obtainedPWD)) {
found = true;
break;
}
}
Assert.assertTrue("Wrong local-dir found : " + obtainedPWD, found);
Assert.assertEquals(
conf.get(
YarnConfiguration.NM_USER_HOME_DIR,
YarnConfiguration.DEFAULT_NM_USER_HOME_DIR),
reader.readLine());
Assert.assertEquals(cId.toString(), containerLaunchContext Assert.assertEquals(cId.toString(), containerLaunchContext
.getEnvironment().get(Environment.CONTAINER_ID.name())); .getEnvironment().get(Environment.CONTAINER_ID.name()));
@ -465,6 +501,26 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
.getEnvironment().get(Environment.LOCAL_DIRS.name())); .getEnvironment().get(Environment.LOCAL_DIRS.name()));
Assert.assertEquals(StringUtils.join(",", containerLogDirs), Assert.assertEquals(StringUtils.join(",", containerLogDirs),
containerLaunchContext.getEnvironment().get(Environment.LOG_DIRS.name())); containerLaunchContext.getEnvironment().get(Environment.LOG_DIRS.name()));
Assert.assertEquals(user, containerLaunchContext.getEnvironment()
.get(Environment.USER.name()));
Assert.assertEquals(user, containerLaunchContext.getEnvironment()
.get(Environment.LOGNAME.name()));
found = false;
obtainedPWD =
containerLaunchContext.getEnvironment().get(Environment.PWD.name());
for (Path localDir : appDirs) {
if (new Path(localDir, cId.toString()).toString().equals(obtainedPWD)) {
found = true;
break;
}
}
Assert.assertTrue("Wrong local-dir found : " + obtainedPWD, found);
Assert.assertEquals(
conf.get(
YarnConfiguration.NM_USER_HOME_DIR,
YarnConfiguration.DEFAULT_NM_USER_HOME_DIR),
containerLaunchContext.getEnvironment()
.get(Environment.HOME.name()));
// Get the pid of the process // Get the pid of the process
String pid = reader.readLine().trim(); String pid = reader.readLine().trim();
@ -538,7 +594,6 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
ContainerLaunchContext containerLaunchContext = ContainerLaunchContext containerLaunchContext =
recordFactory.newRecordInstance(ContainerLaunchContext.class); recordFactory.newRecordInstance(ContainerLaunchContext.class);
int port = 12345;
// upload the script file so that the container can run it // upload the script file so that the container can run it
URL resource_alpha = URL resource_alpha =