|
@@ -41,7 +41,6 @@ import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedHashMap;
|
|
|
-import java.util.LinkedHashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.StringTokenizer;
|
|
@@ -186,10 +185,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
DefaultContainerExecutor defaultContainerExecutor =
|
|
|
new DefaultContainerExecutor();
|
|
|
defaultContainerExecutor.setConf(new YarnConfiguration());
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
defaultContainerExecutor.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), "user", tempFile.getName(),
|
|
|
- nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), "user", tempFile.getName());
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
FileUtil.setExecutable(tempFile, true);
|
|
@@ -263,9 +260,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
DefaultContainerExecutor defaultContainerExecutor =
|
|
|
new DefaultContainerExecutor();
|
|
|
defaultContainerExecutor.setConf(new YarnConfiguration());
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
defaultContainerExecutor.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), "user", nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), "user");
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
FileUtil.setExecutable(tempFile, true);
|
|
@@ -327,9 +323,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
conf.set(YarnConfiguration.NM_ENV_WHITELIST,
|
|
|
"HADOOP_MAPRED_HOME,HADOOP_YARN_HOME");
|
|
|
defaultContainerExecutor.setConf(conf);
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
defaultContainerExecutor.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), "user", nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), "user");
|
|
|
String shellContent =
|
|
|
new String(Files.readAllBytes(Paths.get(shellFile.getAbsolutePath())),
|
|
|
StandardCharsets.UTF_8);
|
|
@@ -342,8 +337,7 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
Assert.assertFalse(shellContent.contains("HADOOP_HDFS_HOME"));
|
|
|
// Available in env and in whitelist
|
|
|
Assert.assertTrue(shellContent.contains(
|
|
|
- "export HADOOP_YARN_HOME=${HADOOP_YARN_HOME:-\"nodemanager_yarn_home\"}"
|
|
|
- ));
|
|
|
+ "export HADOOP_YARN_HOME=\"nodemanager_yarn_home\""));
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
}
|
|
@@ -378,9 +372,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
conf.set(YarnConfiguration.NM_ENV_WHITELIST,
|
|
|
"HADOOP_MAPRED_HOME,HADOOP_YARN_HOME");
|
|
|
lce.setConf(conf);
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
lce.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), "user", nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), "user");
|
|
|
String shellContent =
|
|
|
new String(Files.readAllBytes(Paths.get(shellFile.getAbsolutePath())),
|
|
|
StandardCharsets.UTF_8);
|
|
@@ -389,106 +382,13 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
// Whitelisted variable overridden by container
|
|
|
Assert.assertTrue(shellContent.contains(
|
|
|
"export HADOOP_MAPRED_HOME=\"/opt/hadoopbuild\""));
|
|
|
- // Available in env but not in whitelist
|
|
|
+ // Verify no whitelisted variables inherited from NM env
|
|
|
Assert.assertFalse(shellContent.contains("HADOOP_HDFS_HOME"));
|
|
|
- // Available in env and in whitelist
|
|
|
- Assert.assertTrue(shellContent.contains(
|
|
|
- "export HADOOP_YARN_HOME=${HADOOP_YARN_HOME:-\"nodemanager_yarn_home\"}"
|
|
|
- ));
|
|
|
- fos.flush();
|
|
|
- fos.close();
|
|
|
- }
|
|
|
-
|
|
|
- @Test(timeout = 20000)
|
|
|
- public void testWriteEnvOrder() throws Exception {
|
|
|
- // Valid only for unix
|
|
|
- assumeNotWindows();
|
|
|
- List<String> commands = new ArrayList<String>();
|
|
|
-
|
|
|
- // Setup user-defined environment
|
|
|
- Map<String, String> env = new HashMap<String, String>();
|
|
|
- env.put("USER_VAR_1", "1");
|
|
|
- env.put("USER_VAR_2", "2");
|
|
|
- env.put("NM_MODIFIED_VAR_1", "nm 1");
|
|
|
- env.put("NM_MODIFIED_VAR_2", "nm 2");
|
|
|
-
|
|
|
- // These represent vars explicitly set by NM
|
|
|
- LinkedHashSet<String> trackedNmVars = new LinkedHashSet<>();
|
|
|
- trackedNmVars.add("NM_MODIFIED_VAR_1");
|
|
|
- trackedNmVars.add("NM_MODIFIED_VAR_2");
|
|
|
-
|
|
|
- // Setup Nodemanager environment
|
|
|
- final Map<String, String> nmEnv = new HashMap<>();
|
|
|
- nmEnv.put("WHITELIST_VAR_1", "wl 1");
|
|
|
- nmEnv.put("WHITELIST_VAR_2", "wl 2");
|
|
|
- nmEnv.put("NON_WHITELIST_VAR_1", "nwl 1");
|
|
|
- nmEnv.put("NON_WHITELIST_VAR_2", "nwl 2");
|
|
|
- DefaultContainerExecutor defaultContainerExecutor =
|
|
|
- new DefaultContainerExecutor() {
|
|
|
- @Override
|
|
|
- protected String getNMEnvVar(String varname) {
|
|
|
- return nmEnv.get(varname);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // Setup conf with whitelisted variables
|
|
|
- ArrayList<String> whitelistVars = new ArrayList<>();
|
|
|
- whitelistVars.add("WHITELIST_VAR_1");
|
|
|
- whitelistVars.add("WHITELIST_VAR_2");
|
|
|
- YarnConfiguration conf = new YarnConfiguration();
|
|
|
- conf.set(YarnConfiguration.NM_ENV_WHITELIST,
|
|
|
- whitelistVars.get(0) + "," + whitelistVars.get(1));
|
|
|
-
|
|
|
- // These are in the NM env, but not in the whitelist.
|
|
|
- ArrayList<String> nonWhiteListEnv = new ArrayList<>();
|
|
|
- nonWhiteListEnv.add("NON_WHITELIST_VAR_1");
|
|
|
- nonWhiteListEnv.add("NON_WHITELIST_VAR_2");
|
|
|
-
|
|
|
- // Write the launch script
|
|
|
- File shellFile = Shell.appendScriptExtension(tmpDir, "hello");
|
|
|
- Map<Path, List<String>> resources = new HashMap<Path, List<String>>();
|
|
|
- FileOutputStream fos = new FileOutputStream(shellFile);
|
|
|
- defaultContainerExecutor.setConf(conf);
|
|
|
- defaultContainerExecutor.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), "user", trackedNmVars);
|
|
|
+ Assert.assertFalse(shellContent.contains("HADOOP_YARN_HOME"));
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
-
|
|
|
- // Examine the script
|
|
|
- String shellContent =
|
|
|
- new String(Files.readAllBytes(Paths.get(shellFile.getAbsolutePath())),
|
|
|
- StandardCharsets.UTF_8);
|
|
|
- // First make sure everything is there that's supposed to be
|
|
|
- for (String envVar : env.keySet()) {
|
|
|
- Assert.assertTrue(shellContent.contains(envVar + "="));
|
|
|
- }
|
|
|
- for (String wlVar : whitelistVars) {
|
|
|
- Assert.assertTrue(shellContent.contains(wlVar + "="));
|
|
|
- }
|
|
|
- for (String nwlVar : nonWhiteListEnv) {
|
|
|
- Assert.assertFalse(shellContent.contains(nwlVar + "="));
|
|
|
- }
|
|
|
- // Explicitly Set NM vars should be before user vars
|
|
|
- for (String nmVar : trackedNmVars) {
|
|
|
- for (String userVar : env.keySet()) {
|
|
|
- // Need to skip nm vars and whitelist vars
|
|
|
- if (!trackedNmVars.contains(userVar) &&
|
|
|
- !whitelistVars.contains(userVar)) {
|
|
|
- Assert.assertTrue(shellContent.indexOf(nmVar + "=") <
|
|
|
- shellContent.indexOf(userVar + "="));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // Whitelisted vars should be before explicitly set NM vars
|
|
|
- for (String wlVar : whitelistVars) {
|
|
|
- for (String nmVar : trackedNmVars) {
|
|
|
- Assert.assertTrue(shellContent.indexOf(wlVar + "=") <
|
|
|
- shellContent.indexOf(nmVar + "="));
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Test (timeout = 20000)
|
|
|
public void testInvalidEnvSyntaxDiagnostics() throws IOException {
|
|
|
|
|
@@ -510,9 +410,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
DefaultContainerExecutor defaultContainerExecutor =
|
|
|
new DefaultContainerExecutor();
|
|
|
defaultContainerExecutor.setConf(new YarnConfiguration());
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
defaultContainerExecutor.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), "user", nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), "user");
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
|
|
@@ -594,9 +493,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
commands.add(command);
|
|
|
ContainerExecutor exec = new DefaultContainerExecutor();
|
|
|
exec.setConf(new YarnConfiguration());
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
exec.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), "user", nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), "user");
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
|
|
@@ -687,7 +585,7 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
Path nmp = new Path(testDir);
|
|
|
|
|
|
launch.sanitizeEnv(userSetEnv, pwd, appDirs, userLocalDirs, containerLogs,
|
|
|
- resources, nmp, Collections.emptySet());
|
|
|
+ resources, nmp);
|
|
|
|
|
|
List<String> result =
|
|
|
getJarManifestClasspath(userSetEnv.get(Environment.CLASSPATH.name()));
|
|
@@ -706,7 +604,7 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
dispatcher, exec, null, container, dirsHandler, containerManager);
|
|
|
|
|
|
launch.sanitizeEnv(userSetEnv, pwd, appDirs, userLocalDirs, containerLogs,
|
|
|
- resources, nmp, Collections.emptySet());
|
|
|
+ resources, nmp);
|
|
|
|
|
|
result =
|
|
|
getJarManifestClasspath(userSetEnv.get(Environment.CLASSPATH.name()));
|
|
@@ -1630,10 +1528,9 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
FileOutputStream fos = new FileOutputStream(tempFile);
|
|
|
ContainerExecutor exec = new DefaultContainerExecutor();
|
|
|
exec.setConf(conf);
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
exec.writeLaunchEnv(fos, env, resources, commands,
|
|
|
new Path(localLogDir.getAbsolutePath()), "user",
|
|
|
- tempFile.getName(), nmVars);
|
|
|
+ tempFile.getName());
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
FileUtil.setExecutable(tempFile, true);
|
|
@@ -1856,9 +1753,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
List<String> commands = new ArrayList<String>();
|
|
|
DefaultContainerExecutor executor = new DefaultContainerExecutor();
|
|
|
executor.setConf(new Configuration());
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
executor.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), user, nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), user);
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
|
|
@@ -1902,9 +1798,8 @@ public class TestContainerLaunch extends BaseContainerManagerTest {
|
|
|
Configuration execConf = new Configuration();
|
|
|
execConf.setBoolean(YarnConfiguration.NM_LOG_CONTAINER_DEBUG_INFO, false);
|
|
|
executor.setConf(execConf);
|
|
|
- LinkedHashSet<String> nmVars = new LinkedHashSet<>();
|
|
|
executor.writeLaunchEnv(fos, env, resources, commands,
|
|
|
- new Path(localLogDir.getAbsolutePath()), user, nmVars);
|
|
|
+ new Path(localLogDir.getAbsolutePath()), user);
|
|
|
fos.flush();
|
|
|
fos.close();
|
|
|
|