You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2019/07/03 00:03:37 UTC
[mesos] branch master updated: Set the `MESOS_ALLOCATION_ROLE`
environment variable for task.
This is an automated email from the ASF dual-hosted git repository.
gilbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new 1e42b01 Set the `MESOS_ALLOCATION_ROLE` environment variable for task.
1e42b01 is described below
commit 1e42b01ff73f539f111bb8635f59bf1378271cdf
Author: Qian Zhang <zh...@gmail.com>
AuthorDate: Tue Jul 2 16:53:48 2019 -0700
Set the `MESOS_ALLOCATION_ROLE` environment variable for task.
Review: https://reviews.apache.org/r/70989/
---
src/docker/docker.cpp | 8 ++++++++
src/launcher/default_executor.cpp | 14 +++++++++++++-
src/launcher/executor.cpp | 9 +++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index 9ebb5f2..d13869d 100644
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -681,6 +681,14 @@ Try<Docker::RunOptions> Docker::RunOptions::create(
options.env["MESOS_SANDBOX"] = mappedDirectory;
options.env["MESOS_CONTAINER_NAME"] = name;
+ if (resources.isSome()) {
+ // Set the `MESOS_ALLOCATION_ROLE` environment variable. Please note
+ // that tasks and executors are not allowed to mix resources allocated
+ // to different roles, see MESOS-6636.
+ const Resource resource = *resources->begin();
+ options.env["MESOS_ALLOCATION_ROLE"] = resource.allocation_info().role();
+ }
+
Option<string> volumeDriver;
foreach (const Volume& volume, containerInfo.volumes()) {
// The 'container_path' can be either an absolute path or a
diff --git a/src/launcher/default_executor.cpp b/src/launcher/default_executor.cpp
index 5837cfa..521494a 100644
--- a/src/launcher/default_executor.cpp
+++ b/src/launcher/default_executor.cpp
@@ -88,6 +88,7 @@ namespace mesos {
namespace internal {
constexpr char MESOS_CONTAINER_IP[] = "MESOS_CONTAINER_IP";
+constexpr char MESOS_ALLOCATION_ROLE[] = "MESOS_ALLOCATION_ROLE";
class DefaultExecutor : public ProtobufProcess<DefaultExecutor>
@@ -431,6 +432,9 @@ protected:
LOG(INFO) << "Setting 'MESOS_CONTAINER_IP' to: " << containerIP.value();
+ Environment::Variable allocationRole;
+ allocationRole.set_name(MESOS_ALLOCATION_ROLE);
+
vector<ContainerID> containerIds;
vector<Future<Response>> responses;
@@ -510,13 +514,21 @@ protected:
sandboxPath->set_path(executorVolume.container_path());
}
- // Set the `MESOS_CONTAINER_IP` for the task.
+ // Set the `MESOS_CONTAINER_IP` environment variable for the task.
//
// TODO(asridharan): Document this API for consumption by tasks
// in the Mesos CNI and default-executor documentation.
CommandInfo *command = launch->mutable_command();
command->mutable_environment()->add_variables()->CopyFrom(containerIP);
+ // Set the `MESOS_ALLOCATION_ROLE` environment variable for the task.
+ // Please note that tasks are not allowed to mix resources allocated
+ // to different roles, see MESOS-6636.
+ allocationRole.set_value(
+ task.resources().begin()->allocation_info().role());
+
+ command->mutable_environment()->add_variables()->CopyFrom(allocationRole);
+
responses.push_back(post(connection.get(), call));
}
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index 38d8261..d9b39e5 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -690,6 +690,15 @@ protected:
}
}
+ // Set the `MESOS_ALLOCATION_ROLE` environment variable for the task.
+ // Please note that tasks are not allowed to mix resources allocated
+ // to different roles, see MESOS-6636.
+ Environment::Variable variable;
+ variable.set_name("MESOS_ALLOCATION_ROLE");
+ variable.set_type(Environment::Variable::VALUE);
+ variable.set_value(task.resources().begin()->allocation_info().role());
+ environment["MESOS_ALLOCATION_ROLE"] = variable;
+
Environment launchEnvironment;
foreachvalue (const Environment::Variable& variable, environment) {
launchEnvironment.add_variables()->CopyFrom(variable);