|
@@ -334,6 +334,7 @@ public abstract class ContainerExecutor implements Configurable {
|
|
public void writeLaunchEnv(OutputStream out, Map<String, String> environment,
|
|
public void writeLaunchEnv(OutputStream out, Map<String, String> environment,
|
|
Map<Path, List<String>> resources, List<String> command, Path logDir,
|
|
Map<Path, List<String>> resources, List<String> command, Path logDir,
|
|
String user, String outFilename) throws IOException {
|
|
String user, String outFilename) throws IOException {
|
|
|
|
+ updateEnvForWhitelistVars(environment);
|
|
|
|
|
|
ContainerLaunch.ShellScriptBuilder sb =
|
|
ContainerLaunch.ShellScriptBuilder sb =
|
|
ContainerLaunch.ShellScriptBuilder.create();
|
|
ContainerLaunch.ShellScriptBuilder.create();
|
|
@@ -351,19 +352,6 @@ public abstract class ContainerExecutor implements Configurable {
|
|
for (Map.Entry<String, String> env : environment.entrySet()) {
|
|
for (Map.Entry<String, String> env : environment.entrySet()) {
|
|
sb.env(env.getKey(), env.getValue());
|
|
sb.env(env.getKey(), env.getValue());
|
|
}
|
|
}
|
|
- // Whitelist environment variables are treated specially.
|
|
|
|
- // Only add them if they are not already defined in the environment.
|
|
|
|
- // Add them using special syntax to prevent them from eclipsing
|
|
|
|
- // variables that may be set explicitly in the container image (e.g,
|
|
|
|
- // in a docker image)
|
|
|
|
- for(String var : whitelistVars) {
|
|
|
|
- if (!environment.containsKey(var)) {
|
|
|
|
- String val = getNMEnvVar(var);
|
|
|
|
- if (val != null) {
|
|
|
|
- sb.whitelistedEnv(var, val);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (resources != null) {
|
|
if (resources != null) {
|
|
@@ -663,6 +651,23 @@ public abstract class ContainerExecutor implements Configurable {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Propagate variables from the nodemanager's environment into the
|
|
|
|
+ * container's environment if unspecified by the container.
|
|
|
|
+ * @param env the environment to update
|
|
|
|
+ * @see org.apache.hadoop.yarn.conf.YarnConfiguration#NM_ENV_WHITELIST
|
|
|
|
+ */
|
|
|
|
+ protected void updateEnvForWhitelistVars(Map<String, String> env) {
|
|
|
|
+ for(String var : whitelistVars) {
|
|
|
|
+ if (!env.containsKey(var)) {
|
|
|
|
+ String val = getNMEnvVar(var);
|
|
|
|
+ if (val != null) {
|
|
|
|
+ env.put(var, val);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
protected String getNMEnvVar(String varname) {
|
|
protected String getNMEnvVar(String varname) {
|
|
return System.getenv(varname);
|
|
return System.getenv(varname);
|