You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2017/03/24 06:05:49 UTC

mesos git commit: Fixed environment duplication in command executor.

Repository: mesos
Updated Branches:
  refs/heads/master df05e921a -> 71a9feffd


Fixed environment duplication in command executor.

Review: https://reviews.apache.org/r/57762/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/71a9feff
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/71a9feff
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/71a9feff

Branch: refs/heads/master
Commit: 71a9feffd768d8857da34e2d6d06cd765403ccbc
Parents: df05e92
Author: Till Toenshoff <to...@me.com>
Authored: Fri Mar 24 06:57:42 2017 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Fri Mar 24 07:05:25 2017 +0100

----------------------------------------------------------------------
 src/launcher/executor.cpp | 44 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/71a9feff/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index 4e5841c..a4bac9d 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -465,20 +465,52 @@ protected:
     // TODO(josephw): Windows tasks will inherit the environment
     // from the executor for now. Change this if a Windows isolator
     // ever uses the `--task_environment` flag.
-    Environment launchEnvironment;
+    //
+    // TODO(tillt): Consider logging in detail the original environment
+    // variable source and overwriting source.
+    //
+    // TODO(tillt): Consider implementing a generic, reusable solution
+    // for merging these environments. See MESOS-7299.
+    //
+    // Note that we can not use protobuf message merging as that could
+    // cause duplicate keys in the resulting environment.
+    hashmap<string, Environment::Variable> environment;
 
     foreachpair (const string& name, const string& value, os::environment()) {
-      Environment::Variable* variable = launchEnvironment.add_variables();
-      variable->set_name(name);
-      variable->set_value(value);
+      Environment::Variable variable;
+      variable.set_name(name);
+      variable.set_type(Environment::Variable::VALUE);
+      variable.set_value(value);
+      environment[name] = variable;
     }
 
     if (taskEnvironment.isSome()) {
-      launchEnvironment.MergeFrom(taskEnvironment.get());
+      foreach (const Environment::Variable& variable,
+               taskEnvironment->variables()) {
+        const string& name = variable.name();
+        if (environment.contains(name) &&
+            environment[name].value() != variable.value()) {
+          cout << "Overwriting environment variable '" << name << "'" << endl;
+        }
+        environment[name] = variable;
+      }
     }
 
     if (command.has_environment()) {
-      launchEnvironment.MergeFrom(command.environment());
+      foreach (const Environment::Variable& variable,
+               command.environment().variables()) {
+        const string& name = variable.name();
+        if (environment.contains(name) &&
+            environment[name].value() != variable.value()) {
+          cout << "Overwriting environment variable '" << name << "'" << endl;
+        }
+        environment[name] = variable;
+      }
+    }
+
+    Environment launchEnvironment;
+    foreachvalue (const Environment::Variable& variable, environment) {
+      launchEnvironment.add_variables()->CopyFrom(variable);
     }
 
     cout << "Starting task " << taskId.get() << endl;