You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ti...@apache.org on 2016/11/28 16:13:56 UTC
[1/2] mesos git commit: Added new hook for covering executor and task
environment.
Repository: mesos
Updated Branches:
refs/heads/master 83863c7d5 -> dadb22bd6
Added new hook for covering executor and task environment.
For being able to supply environment additions for both, a task and
its executor separately we need to introduce a new hook as the
existing ones slavePreLaunchDockerHook (deprecated) as well as
slavePreLaunchDockerEnvironmentDecorator do not allow for this.
This new hook will likely allow for further additions like e.g.
adding volumes without having to adapt the signature but only the
returned proto message TaskExecutorDecoratorInfo.
Review: https://reviews.apache.org/r/54038/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8509a6db
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8509a6db
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8509a6db
Branch: refs/heads/master
Commit: 8509a6db4dbc0a30fb0c5175905f0c9a00126d6c
Parents: 83863c7
Author: Till Toenshoff <to...@me.com>
Authored: Mon Nov 28 16:57:02 2016 +0100
Committer: Till Toenshoff <to...@me.com>
Committed: Mon Nov 28 16:57:02 2016 +0100
----------------------------------------------------------------------
include/mesos/hook.hpp | 36 +++++++++++++++++
include/mesos/module/hook.proto | 34 ++++++++++++++++
src/Makefile.am | 5 +++
src/hook/manager.cpp | 44 +++++++++++++++++++++
src/hook/manager.hpp | 9 +++++
src/slave/containerizer/docker.cpp | 69 +++++++++++++++++++++++++++++++++
6 files changed, 197 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/8509a6db/include/mesos/hook.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/hook.hpp b/include/mesos/hook.hpp
index f0606e3..3ad5933 100644
--- a/include/mesos/hook.hpp
+++ b/include/mesos/hook.hpp
@@ -31,6 +31,9 @@
#include <stout/result.hpp>
#include <stout/try.hpp>
+// ONLY USEFUL AFTER RUNNING PROTOC.
+#include <mesos/module/hook.pb.h>
+
namespace mesos {
class Hook
@@ -105,6 +108,8 @@ public:
//
// NOTE: This hook is designed to be an asynchronous replacement for
// `slavePreLaunchDockerHook`. This hook is called first.
+ //
+ // NOTE: Superseded by `slavePreLaunchDockerTaskExecutorDecorator`.
virtual process::Future<Option<Environment>>
slavePreLaunchDockerEnvironmentDecorator(
const Option<TaskInfo>& taskInfo,
@@ -117,6 +122,37 @@ public:
return None();
}
+ // This task and executor decorator is called from within the slave after
+ // receiving a run task request from the master but before the docker
+ // containerizer launches the task. A module implementing the hook can
+ // inspect the arguments and return a `Failure` if the task should be
+ // rejected with a `TASK_FAILED`.
+ // The hook can return a set of environment variables individually for
+ // both, the executor and the task. Note that for custom executors,
+ // the task environment variables, in case of conflicts, *will*
+ // overwrite the executor variables.
+ //
+ // NOTE: The order of hooks matters for environment variables.
+ // If there is a conflict, the hook loaded last will take priority.
+ //
+ // NOTE: Unlike `slaveExecutorEnvironmentDecorator`, environment variables
+ // returned from this hook, in case of conflicts, *will* overwrite
+ // environment variables inside the `ExecutorInfo`.
+ //
+ // NOTE: This hook is designed to be a replacement for
+ // `slavePreLaunchDockerEnvironmentDecorator`.
+ virtual process::Future<Option<DockerTaskExecutorPrepareInfo>>
+ slavePreLaunchDockerTaskExecutorDecorator(
+ const Option<TaskInfo>& taskInfo,
+ const ExecutorInfo& executorInfo,
+ const std::string& containerName,
+ const std::string& containerWorkDirectory,
+ const std::string& mappedSandboxDirectory,
+ const Option<std::map<std::string, std::string>>& env)
+ {
+ return None();
+ }
+
// This hook is called from within slave before docker is launched.
// A typical module implementing the hook will perform some settings
// as required.
http://git-wip-us.apache.org/repos/asf/mesos/blob/8509a6db/include/mesos/module/hook.proto
----------------------------------------------------------------------
diff --git a/include/mesos/module/hook.proto b/include/mesos/module/hook.proto
new file mode 100644
index 0000000..f7b91f8
--- /dev/null
+++ b/include/mesos/module/hook.proto
@@ -0,0 +1,34 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import "mesos/mesos.proto";
+
+package mesos;
+
+option java_package = "org.apache.mesos";
+option java_outer_classname = "Protos";
+
+/**
+ * Docker task and executor decoration information.
+ *
+ * Note that custom executors will receive the `executorEnvironment`
+ * and the `taskEnvironment` merged. In case of key collisions, values
+ * from `taskEnvironment` *will* overwrite those from `executorEnvironment`.
+ */
+message DockerTaskExecutorPrepareInfo {
+ optional Environment executorEnvironment = 1;
+ optional Environment taskEnvironment = 2;
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/8509a6db/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index dd1626d..85eda53 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -222,6 +222,7 @@ DOCKER_V1_PROTO = $(top_srcdir)/include/mesos/docker/v1.proto
DOCKER_V2_PROTO = $(top_srcdir)/include/mesos/docker/v2.proto
EXECUTOR_PROTO = $(top_srcdir)/include/mesos/executor/executor.proto
FETCHER_PROTO = $(top_srcdir)/include/mesos/fetcher/fetcher.proto
+HOOK_PROTO = $(top_srcdir)/include/mesos/module/hook.proto
MAINTENANCE_PROTO = $(top_srcdir)/include/mesos/maintenance/maintenance.proto
MASTER_PROTO = $(top_srcdir)/include/mesos/master/master.proto
MESOS_PROTO = $(top_srcdir)/include/mesos/mesos.proto
@@ -270,6 +271,8 @@ CXX_PROTOS = \
../include/mesos/maintenance/maintenance.pb.h \
../include/mesos/master/master.pb.cc \
../include/mesos/master/master.pb.h \
+ ../include/mesos/module/hook.pb.cc \
+ ../include/mesos/module/hook.pb.h \
../include/mesos/module/module.pb.cc \
../include/mesos/module/module.pb.h \
../include/mesos/quota/quota.pb.cc \
@@ -566,6 +569,7 @@ module_HEADERS = \
$(top_srcdir)/include/mesos/module/authorizer.hpp \
$(top_srcdir)/include/mesos/module/container_logger.hpp \
$(top_srcdir)/include/mesos/module/hook.hpp \
+ $(top_srcdir)/include/mesos/module/hook.proto \
$(top_srcdir)/include/mesos/module/http_authenticator.hpp \
$(top_srcdir)/include/mesos/module/isolator.hpp \
$(top_srcdir)/include/mesos/module/module.hpp \
@@ -1285,6 +1289,7 @@ libmesos_la_SOURCES = \
$(DOCKER_V1_PROTO) \
$(DOCKER_V2_PROTO) \
$(FETCHER_PROTO) \
+ $(HOOK_PROTO) \
$(MAINTENANCE_PROTO) \
$(MASTER_PROTO) \
$(MESOS_PROTO) \
http://git-wip-us.apache.org/repos/asf/mesos/blob/8509a6db/src/hook/manager.cpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.cpp b/src/hook/manager.cpp
index 2488522..1923d0b 100644
--- a/src/hook/manager.cpp
+++ b/src/hook/manager.cpp
@@ -208,6 +208,50 @@ Environment HookManager::slaveExecutorEnvironmentDecorator(
}
+Future<DockerTaskExecutorPrepareInfo>
+ HookManager::slavePreLaunchDockerTaskExecutorDecorator(
+ const Option<TaskInfo>& taskInfo,
+ const ExecutorInfo& executorInfo,
+ const string& containerName,
+ const string& containerWorkDirectory,
+ const string& mappedSandboxDirectory,
+ const Option<map<string, string>>& env)
+{
+ // We execute these hooks according to their ordering so any conflicting
+ // `DockerTaskExecutorPrepareInfo` can be deterministically resolved
+ // (the last hook takes priority).
+ list<Future<Option<DockerTaskExecutorPrepareInfo>>> futures;
+
+ foreach (const string& name, availableHooks.keys()) {
+ Hook* hook = availableHooks[name];
+
+ // Chain together each hook.
+ futures.push_back(
+ hook->slavePreLaunchDockerTaskExecutorDecorator(
+ taskInfo,
+ executorInfo,
+ containerName,
+ containerWorkDirectory,
+ mappedSandboxDirectory,
+ env));
+ }
+
+ return collect(futures)
+ .then([](const list<Option<DockerTaskExecutorPrepareInfo>>& results)
+ -> Future<DockerTaskExecutorPrepareInfo> {
+ DockerTaskExecutorPrepareInfo taskExecutorDecoratorInfo;
+
+ foreach (const Option<DockerTaskExecutorPrepareInfo>& result, results) {
+ if (result.isSome()) {
+ taskExecutorDecoratorInfo.MergeFrom(result.get());
+ }
+ }
+
+ return taskExecutorDecoratorInfo;
+ });
+}
+
+
Future<map<string, string>>
HookManager::slavePreLaunchDockerEnvironmentDecorator(
const Option<TaskInfo>& taskInfo,
http://git-wip-us.apache.org/repos/asf/mesos/blob/8509a6db/src/hook/manager.hpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.hpp b/src/hook/manager.hpp
index 5ecfcab..d67d938 100644
--- a/src/hook/manager.hpp
+++ b/src/hook/manager.hpp
@@ -65,6 +65,15 @@ public:
const std::string& mappedDirectory,
const Option<std::map<std::string, std::string>>& env);
+ static process::Future<DockerTaskExecutorPrepareInfo>
+ slavePreLaunchDockerTaskExecutorDecorator(
+ const Option<TaskInfo>& taskInfo,
+ const ExecutorInfo& executorInfo,
+ const std::string& containerName,
+ const std::string& containerWorkDirectory,
+ const std::string& mappedSandboxDirectory,
+ const Option<std::map<std::string, std::string>>& env);
+
static void slavePreLaunchDockerHook(
const ContainerInfo& containerInfo,
const CommandInfo& commandInfo,
http://git-wip-us.apache.org/repos/asf/mesos/blob/8509a6db/src/slave/containerizer/docker.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp
index a8e522f..5ce4667 100644
--- a/src/slave/containerizer/docker.cpp
+++ b/src/slave/containerizer/docker.cpp
@@ -1128,6 +1128,9 @@ Future<bool> DockerContainerizerProcess::launch(
Future<Nothing> f = Nothing();
if (HookManager::hooksAvailable()) {
+ // TODO(tillt): `slavePreLaunchDockerEnvironmentDecorator` is
+ // deprecated, remove this entire block after Mesos 1.2's
+ // deprecation cycle ends.
f = HookManager::slavePreLaunchDockerEnvironmentDecorator(
taskInfo,
executorInfo,
@@ -1166,6 +1169,72 @@ Future<bool> DockerContainerizerProcess::launch(
return Nothing();
}));
+
+ f = HookManager::slavePreLaunchDockerTaskExecutorDecorator(
+ taskInfo,
+ executorInfo,
+ container.get()->name(),
+ container.get()->directory,
+ flags.sandbox_directory,
+ container.get()->environment)
+ .then(defer(self(), [this, taskInfo, containerId](
+ const DockerTaskExecutorPrepareInfo& decoratorInfo)
+ -> Future<Nothing> {
+ if (!containers_.contains(containerId)) {
+ return Failure("Container is already destroyed");
+ }
+
+ Container* container = containers_.at(containerId);
+
+ if (decoratorInfo.has_executorenvironment()) {
+ foreach (
+ const Environment::Variable& variable,
+ decoratorInfo.executorenvironment().variables()) {
+ // TODO(tillt): Tell the user about overrides possibly
+ // happening here while making sure we state the source
+ // hook causing this conflict.
+ container->environment[variable.name()] =
+ variable.value();
+ }
+ }
+
+ map<string, string> taskEnvironment;
+
+ if (decoratorInfo.has_taskenvironment()) {
+ foreach (
+ const Environment::Variable& variable,
+ decoratorInfo.taskenvironment().variables()) {
+ taskEnvironment[variable.name()] = variable.value();
+ }
+ }
+
+ if (taskInfo.isSome()) {
+ container->taskEnvironment = taskEnvironment;
+
+ // For dockerized command executors, the flags have already
+ // been serialized into the command, albeit without these
+ // environment variables. Append the last flag to the
+ // overridden command.
+ if (container->launchesExecutorContainer) {
+ container->command.add_arguments(
+ "--task_environment=" +
+ string(jsonify(taskEnvironment)));
+ }
+ } else {
+ // For custom executors, the environment variables from a
+ // hook are passed directly into the executor. It is up to
+ // the custom executor whether individual tasks should
+ // inherit these variables.
+ foreachpair (
+ const string& key,
+ const string& value,
+ taskEnvironment) {
+ container->environment[key] = value;
+ }
+ }
+
+ return Nothing();
+ }));
}
return f.then(defer(
[2/2] mesos git commit: Fixed some nits in hooks interfaces.
Posted by ti...@apache.org.
Fixed some nits in hooks interfaces.
Review: https://reviews.apache.org/r/54068/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/dadb22bd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/dadb22bd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/dadb22bd
Branch: refs/heads/master
Commit: dadb22bd68da10433bcda4d9d0e9c54d4e75ed7a
Parents: 8509a6d
Author: Till Toenshoff <to...@me.com>
Authored: Mon Nov 28 16:57:08 2016 +0100
Committer: Till Toenshoff <to...@me.com>
Committed: Mon Nov 28 16:57:08 2016 +0100
----------------------------------------------------------------------
include/mesos/hook.hpp | 18 +++++++++---------
src/examples/test_hook_module.cpp | 14 +++++++-------
src/hook/manager.cpp | 16 ++++++++--------
src/hook/manager.hpp | 8 ++++----
4 files changed, 28 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/dadb22bd/include/mesos/hook.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/hook.hpp b/include/mesos/hook.hpp
index 3ad5933..134951c 100644
--- a/include/mesos/hook.hpp
+++ b/include/mesos/hook.hpp
@@ -103,8 +103,8 @@ public:
// If there is a conflict, the hook loaded last will take priority.
//
// NOTE: Unlike `slaveExecutorEnvironmentDecorator`, environment variables
- // returned from this hook *will* overwrite environment variables inside
- // the `ExecutorInfo`.
+ // returned from this hook, in case of conflicts, *will* overwrite
+ // environment variables inside the `ExecutorInfo`.
//
// NOTE: This hook is designed to be an asynchronous replacement for
// `slavePreLaunchDockerHook`. This hook is called first.
@@ -114,9 +114,9 @@ public:
slavePreLaunchDockerEnvironmentDecorator(
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
- const std::string& name,
- const std::string& sandboxDirectory,
- const std::string& mappedDirectory,
+ const std::string& containerName,
+ const std::string& containerWorkDirectory,
+ const std::string& mappedSandboxDirectory,
const Option<std::map<std::string, std::string>>& env)
{
return None();
@@ -157,15 +157,15 @@ public:
// A typical module implementing the hook will perform some settings
// as required.
//
- // NOTE: Superceded by `slavePreLaunchDockerEnvironmentDecorator`.
+ // NOTE: Superseded by `slavePreLaunchDockerEnvironmentDecorator`.
virtual Try<Nothing> slavePreLaunchDockerHook(
const ContainerInfo& containerInfo,
const CommandInfo& commandInfo,
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
- const std::string& name,
- const std::string& sandboxDirectory,
- const std::string& mappedDirectory,
+ const std::string& containerName,
+ const std::string& containerWorkDirectory,
+ const std::string& mappedSandboxDirectory,
const Option<Resources>& resources,
const Option<std::map<std::string, std::string>>& env)
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/dadb22bd/src/examples/test_hook_module.cpp
----------------------------------------------------------------------
diff --git a/src/examples/test_hook_module.cpp b/src/examples/test_hook_module.cpp
index 5e91a71..094a92b 100644
--- a/src/examples/test_hook_module.cpp
+++ b/src/examples/test_hook_module.cpp
@@ -193,9 +193,9 @@ public:
virtual Future<Option<Environment>> slavePreLaunchDockerEnvironmentDecorator(
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
- const string& name,
- const string& sandboxDirectory,
- const string& mappedDirectory,
+ const string& containerName,
+ const string& containerWorkDirectory,
+ const string& mappedSandboxDirectory,
const Option<map<string, string>>& env)
{
LOG(INFO) << "Executing 'slavePreLaunchDockerEnvironmentDecorator' hook";
@@ -222,14 +222,14 @@ public:
const CommandInfo& commandInfo,
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
- const string& name,
- const string& sandboxDirectory,
- const string& mappedDirectory,
+ const string& containerName,
+ const string& containerWorkDirectory,
+ const string& mappedSandboxDirectory,
const Option<Resources>& resources,
const Option<map<string, string>>& env)
{
LOG(INFO) << "Executing 'slavePreLaunchDockerHook'";
- return os::touch(path::join(sandboxDirectory, "foo"));
+ return os::touch(path::join(containerWorkDirectory, "foo"));
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/dadb22bd/src/hook/manager.cpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.cpp b/src/hook/manager.cpp
index 1923d0b..59f402b 100644
--- a/src/hook/manager.cpp
+++ b/src/hook/manager.cpp
@@ -257,8 +257,8 @@ Future<map<string, string>>
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
const string& containerName,
- const string& sandboxDirectory,
- const string& mappedDirectory,
+ const string& containerWorkDirectory,
+ const string& mappedSandboxDirectory,
const Option<map<string, string>>& env)
{
// We execute these hooks according to their ordering so any conflicting
@@ -275,8 +275,8 @@ Future<map<string, string>>
taskInfo,
executorInfo,
containerName,
- sandboxDirectory,
- mappedDirectory,
+ containerWorkDirectory,
+ mappedSandboxDirectory,
env));
}
@@ -307,8 +307,8 @@ void HookManager::slavePreLaunchDockerHook(
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
const string& containerName,
- const string& sandboxDirectory,
- const string& mappedDirectory,
+ const string& containerWorkDirectory,
+ const string& mappedSandboxDirectory,
const Option<Resources>& resources,
const Option<map<string, string>>& env)
{
@@ -321,8 +321,8 @@ void HookManager::slavePreLaunchDockerHook(
taskInfo,
executorInfo,
containerName,
- sandboxDirectory,
- mappedDirectory,
+ containerWorkDirectory,
+ mappedSandboxDirectory,
resources,
env);
if (result.isError()) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/dadb22bd/src/hook/manager.hpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.hpp b/src/hook/manager.hpp
index d67d938..ad52717 100644
--- a/src/hook/manager.hpp
+++ b/src/hook/manager.hpp
@@ -61,8 +61,8 @@ public:
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
const std::string& containerName,
- const std::string& sandboxDirectory,
- const std::string& mappedDirectory,
+ const std::string& containerWorkDirectory,
+ const std::string& mappedSandboxDirectory,
const Option<std::map<std::string, std::string>>& env);
static process::Future<DockerTaskExecutorPrepareInfo>
@@ -80,8 +80,8 @@ public:
const Option<TaskInfo>& taskInfo,
const ExecutorInfo& executorInfo,
const std::string& containerName,
- const std::string& sandboxDirectory,
- const std::string& mappedDirectory,
+ const std::string& containerWorkDirectory,
+ const std::string& mappedSandboxDirectory,
const Option<Resources>& resources,
const Option<std::map<std::string, std::string>>& env);