Repository: mesos Updated Branches: refs/heads/master 1fe548562 -> 78567c553
Call hookmanager only if some hooks are installed. Call hook manager only if hooks were specified on the commandline. Review: https://reviews.apache.org/r/30339 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/78567c55 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/78567c55 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/78567c55 Branch: refs/heads/master Commit: 78567c5533b30b70dde9f55459237698b97acb4c Parents: 1fe5485 Author: Kapil Arya <[email protected]> Authored: Wed Jun 17 13:59:42 2015 -0700 Committer: Niklas Q. Nielsen <[email protected]> Committed: Wed Jun 17 13:59:44 2015 -0700 ---------------------------------------------------------------------- src/hook/manager.cpp | 8 +++++++ src/hook/manager.hpp | 1 + src/master/master.cpp | 14 ++++++----- src/slave/containerizer/containerizer.cpp | 32 ++++++++++++++------------ src/slave/slave.cpp | 12 ++++++---- 5 files changed, 42 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/78567c55/src/hook/manager.cpp ---------------------------------------------------------------------- diff --git a/src/hook/manager.cpp b/src/hook/manager.cpp index b43b918..0108534 100644 --- a/src/hook/manager.cpp +++ b/src/hook/manager.cpp @@ -91,6 +91,14 @@ Try<Nothing> HookManager::unload(const std::string& hookName) } +bool HookManager::hooksAvailable() +{ + synchronized (mutex) { + return !availableHooks.empty(); + } +} + + Labels HookManager::masterLaunchTaskLabelDecorator( const TaskInfo& taskInfo, const FrameworkInfo& frameworkInfo, http://git-wip-us.apache.org/repos/asf/mesos/blob/78567c55/src/hook/manager.hpp ---------------------------------------------------------------------- diff --git a/src/hook/manager.hpp b/src/hook/manager.hpp index 638e19f..47e8eb7 100644 --- a/src/hook/manager.hpp +++ b/src/hook/manager.hpp @@ -38,6 +38,7 @@ public: // hook and remove it from the list of available hooks. static Try<Nothing> unload(const std::string& hookName); + static bool hooksAvailable(); static Labels masterLaunchTaskLabelDecorator( const TaskInfo& taskInfo, http://git-wip-us.apache.org/repos/asf/mesos/blob/78567c55/src/master/master.cpp ---------------------------------------------------------------------- diff --git a/src/master/master.cpp b/src/master/master.cpp index 0137c37..0135c15 100644 --- a/src/master/master.cpp +++ b/src/master/master.cpp @@ -2757,12 +2757,14 @@ void Master::_accept( message.set_pid(framework->pid); message.mutable_task()->MergeFrom(task_); - // Set labels retrieved from label-decorator hooks. - message.mutable_task()->mutable_labels()->CopyFrom( - HookManager::masterLaunchTaskLabelDecorator( - task_, - framework->info, - slave->info)); + if (HookManager::hooksAvailable()) { + // Set labels retrieved from label-decorator hooks. + message.mutable_task()->mutable_labels()->CopyFrom( + HookManager::masterLaunchTaskLabelDecorator( + task_, + framework->info, + slave->info)); + } send(slave->pid, message); } http://git-wip-us.apache.org/repos/asf/mesos/blob/78567c55/src/slave/containerizer/containerizer.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/containerizer.cpp b/src/slave/containerizer/containerizer.cpp index e995ce6..c5ffc49 100644 --- a/src/slave/containerizer/containerizer.cpp +++ b/src/slave/containerizer/containerizer.cpp @@ -291,21 +291,23 @@ map<string, string> executorEnvironment( env["MESOS_RECOVERY_TIMEOUT"] = stringify(recoveryTimeout); } - // Include any environment variables from Hooks. - // TODO(karya): Call environment decorator hook _after_ putting all - // variables from executorInfo into 'env'. This would prevent the - // ones provided by hooks from being overwritten by the ones in - // executorInfo in case of a conflict. The overwriting takes places - // at the callsites of executorEnvironment (e.g., ___launch function - // in src/slave/containerizer/docker.cpp) - // TODO(karya): Provide a mechanism to pass the new environment - // variables created above (MESOS_*) on to the hook modules. - const Environment& hooksEnvironment = - HookManager::slaveExecutorEnvironmentDecorator(executorInfo); - - foreach (const Environment::Variable& variable, - hooksEnvironment.variables()) { - env[variable.name()] = variable.value(); + if (HookManager::hooksAvailable()) { + // Include any environment variables from Hooks. + // TODO(karya): Call environment decorator hook _after_ putting all + // variables from executorInfo into 'env'. This would prevent the + // ones provided by hooks from being overwritten by the ones in + // executorInfo in case of a conflict. The overwriting takes places + // at the callsites of executorEnvironment (e.g., ___launch function + // in src/slave/containerizer/docker.cpp) + // TODO(karya): Provide a mechanism to pass the new environment + // variables created above (MESOS_*) on to the hook modules. + const Environment& hooksEnvironment = + HookManager::slaveExecutorEnvironmentDecorator(executorInfo); + + foreach (const Environment::Variable& variable, + hooksEnvironment.variables()) { + env[variable.name()] = variable.value(); + } } return env; http://git-wip-us.apache.org/repos/asf/mesos/blob/78567c55/src/slave/slave.cpp ---------------------------------------------------------------------- diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp index 098b58a..a5ad29f 100644 --- a/src/slave/slave.cpp +++ b/src/slave/slave.cpp @@ -1233,9 +1233,11 @@ void Slave::runTask( return; } - // Set task labels from run task label decorator. - task.mutable_labels()->CopyFrom( - HookManager::slaveRunTaskLabelDecorator(task, frameworkInfo, info)); + if (HookManager::hooksAvailable()) { + // Set task labels from run task label decorator. + task.mutable_labels()->CopyFrom( + HookManager::slaveRunTaskLabelDecorator(task, frameworkInfo, info)); + } Future<bool> unschedule = true; @@ -3429,7 +3431,9 @@ void Slave::removeExecutor(Framework* framework, Executor* executor) } } - HookManager::slaveRemoveExecutorHook(framework->info, executor->info); + if (HookManager::hooksAvailable()) { + HookManager::slaveRemoveExecutorHook(framework->info, executor->info); + } framework->destroyExecutor(executor->id); }
