You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2015/04/21 00:32:03 UTC

[3/6] mesos git commit: Added slave run task decorator.

Added slave run task decorator.

Added decorator which gets invoked on start of runTask() sequence in the
slave.

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


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

Branch: refs/heads/master
Commit: 8dd1bb1213ac3f69fdcd5cbc35599fea49272b14
Parents: a454fc5
Author: Niklas Nielsen <ni...@qni.dk>
Authored: Mon Apr 20 14:36:40 2015 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Mon Apr 20 14:36:40 2015 -0700

----------------------------------------------------------------------
 include/mesos/hook.hpp | 12 ++++++++++++
 src/hook/manager.cpp   | 27 +++++++++++++++++++++++++++
 src/hook/manager.hpp   |  5 +++++
 src/slave/slave.cpp    |  6 +++++-
 src/slave/slave.hpp    |  2 +-
 src/tests/mesos.cpp    |  2 +-
 src/tests/mesos.hpp    |  4 ++--
 7 files changed, 53 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8dd1bb12/include/mesos/hook.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/hook.hpp b/include/mesos/hook.hpp
index f2b8259..a9dbc10 100644
--- a/include/mesos/hook.hpp
+++ b/include/mesos/hook.hpp
@@ -45,6 +45,18 @@ public:
     return None();
   }
 
+  // This label decorator hook is called from within the slave when
+  // receiving a run task request from the master. A module
+  // implementing the hook creates and returns a set of labels. These
+  // labels overwrite the existing labels on the task info.
+  virtual Result<Labels> slaveRunTaskLabelDecorator(
+      const TaskInfo& taskInfo,
+      const FrameworkInfo& frameworkInfo,
+      const SlaveInfo& slaveInfo)
+  {
+    return None();
+  }
+
   // This environment decorator hook is called from within slave when
   // launching a new executor. A module implementing the hook creates
   // and returns a set of environment variables. These environment

http://git-wip-us.apache.org/repos/asf/mesos/blob/8dd1bb12/src/hook/manager.cpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.cpp b/src/hook/manager.cpp
index 28d5c58..54b0d34 100644
--- a/src/hook/manager.cpp
+++ b/src/hook/manager.cpp
@@ -120,6 +120,33 @@ Labels HookManager::masterLaunchTaskLabelDecorator(
 }
 
 
+Labels HookManager::slaveRunTaskLabelDecorator(
+    const TaskInfo& taskInfo,
+    const FrameworkInfo& frameworkInfo,
+    const SlaveInfo& slaveInfo)
+{
+  Lock lock(&mutex);
+
+  TaskInfo taskInfo_ = taskInfo;
+
+  foreachpair (const string& name, Hook* hook, availableHooks) {
+    const Result<Labels>& result =
+      hook->slaveRunTaskLabelDecorator(taskInfo_, frameworkInfo, slaveInfo);
+
+    // NOTE: If the hook returns None(), the task labels won't be
+    // changed.
+    if (result.isSome()) {
+      taskInfo_.mutable_labels()->CopyFrom(result.get());
+    } else if (result.isError()) {
+      LOG(WARNING) << "Slave label decorator hook failed for module '"
+                   << name << "': " << result.error();
+    }
+  }
+
+  return taskInfo_.labels();
+}
+
+
 Environment HookManager::slaveExecutorEnvironmentDecorator(
     ExecutorInfo executorInfo)
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/8dd1bb12/src/hook/manager.hpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.hpp b/src/hook/manager.hpp
index da81349..638e19f 100644
--- a/src/hook/manager.hpp
+++ b/src/hook/manager.hpp
@@ -44,6 +44,11 @@ public:
       const FrameworkInfo& frameworkInfo,
       const SlaveInfo& slaveInfo);
 
+  static Labels slaveRunTaskLabelDecorator(
+      const TaskInfo& taskInfo,
+      const FrameworkInfo& frameworkInfo,
+      const SlaveInfo& slaveInfo);
+
   static Environment slaveExecutorEnvironmentDecorator(
       ExecutorInfo executorInfo);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/8dd1bb12/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 8ec80ed..60345ec 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -1107,7 +1107,7 @@ void Slave::runTask(
     const FrameworkInfo& frameworkInfo_,
     const FrameworkID& frameworkId_,
     const string& pid,
-    const TaskInfo& task)
+    TaskInfo task)
 {
   if (master != from) {
     LOG(WARNING) << "Ignoring run task message from " << from
@@ -1149,6 +1149,10 @@ void Slave::runTask(
     return;
   }
 
+  // Set task labels from run task label decorator.
+  task.mutable_labels()->CopyFrom(
+      HookManager::slaveRunTaskLabelDecorator(task, frameworkInfo, info));
+
   Future<bool> unschedule = true;
 
   // If we are about to create a new framework, unschedule the work

http://git-wip-us.apache.org/repos/asf/mesos/blob/8dd1bb12/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 9495c70..d214ddb 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -108,7 +108,7 @@ public:
       const FrameworkInfo& frameworkInfo,
       const FrameworkID& frameworkId,
       const std::string& pid,
-      const TaskInfo& task);
+      TaskInfo task);
 
   // Made 'virtual' for Slave mocking.
   virtual void _runTask(

http://git-wip-us.apache.org/repos/asf/mesos/blob/8dd1bb12/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index fc534e9..42a4015 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -394,7 +394,7 @@ void MockSlave::unmocked_runTask(
     const FrameworkInfo& frameworkInfo,
     const FrameworkID& frameworkId,
     const std::string& pid,
-    const TaskInfo& task)
+    TaskInfo task)
 {
   slave::Slave::runTask(from, frameworkInfo, frameworkId, pid, task);
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/8dd1bb12/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 7744df5..4edb33b 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -679,14 +679,14 @@ public:
       const FrameworkInfo& frameworkInfo,
       const FrameworkID& frameworkId,
       const std::string& pid,
-      const TaskInfo& task));
+      TaskInfo task));
 
   void unmocked_runTask(
       const process::UPID& from,
       const FrameworkInfo& frameworkInfo,
       const FrameworkID& frameworkId,
       const std::string& pid,
-      const TaskInfo& task);
+      TaskInfo task);
 
   MOCK_METHOD4(_runTask, void(
       const process::Future<bool>& future,