You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/04/14 02:09:07 UTC

[3/3] mesos git commit: Added a slave post fetch hook.

Added a slave post fetch hook.

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


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

Branch: refs/heads/master
Commit: 80550c7d6105cf997def5930688485b70a66829f
Parents: 124a05b
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Apr 13 15:28:19 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Apr 13 17:08:59 2016 -0700

----------------------------------------------------------------------
 include/mesos/hook.hpp                          | 11 ++++++++++
 src/hook/manager.cpp                            | 15 ++++++++++++++
 src/hook/manager.hpp                            |  4 ++++
 src/slave/containerizer/docker.cpp              | 21 ++++++++++++++++----
 src/slave/containerizer/mesos/containerizer.cpp | 10 +++++++++-
 5 files changed, 56 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/80550c7d/include/mesos/hook.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/hook.hpp b/include/mesos/hook.hpp
index 87e01a9..210ffba 100644
--- a/include/mesos/hook.hpp
+++ b/include/mesos/hook.hpp
@@ -101,6 +101,17 @@ public:
     return Nothing();
   }
 
+  // This hook is called from within slave after URIs and container
+  // image are fetched. A typical module implementing this hook will
+  // perform some operations on the fetched artifacts.
+  virtual Try<Nothing> slavePostFetchHook(
+      const ContainerID& containerId,
+      const std::string& directory)
+  {
+    return Nothing();
+  }
+
+
   // This hook is called from within slave when an executor is being
   // removed. A typical module implementing the hook will perform some
   // cleanup as required.

http://git-wip-us.apache.org/repos/asf/mesos/blob/80550c7d/src/hook/manager.cpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.cpp b/src/hook/manager.cpp
index 17a42f8..692b9ea 100644
--- a/src/hook/manager.cpp
+++ b/src/hook/manager.cpp
@@ -232,6 +232,21 @@ void HookManager::slavePreLaunchDockerHook(
 }
 
 
+void HookManager::slavePostFetchHook(
+    const ContainerID& containerId,
+    const string& directory)
+{
+  foreach (const string& name, availableHooks.keys()) {
+    Hook* hook = availableHooks[name];
+    Try<Nothing> result = hook->slavePostFetchHook(containerId, directory);
+    if (result.isError()) {
+      LOG(WARNING) << "Slave post fetch hook failed for module "
+                   << "'" << name << "': " << result.error();
+    }
+  }
+}
+
+
 void HookManager::slaveRemoveExecutorHook(
     const FrameworkInfo& frameworkInfo,
     const ExecutorInfo& executorInfo)

http://git-wip-us.apache.org/repos/asf/mesos/blob/80550c7d/src/hook/manager.hpp
----------------------------------------------------------------------
diff --git a/src/hook/manager.hpp b/src/hook/manager.hpp
index 3af28a7..528674e 100644
--- a/src/hook/manager.hpp
+++ b/src/hook/manager.hpp
@@ -65,6 +65,10 @@ public:
       const Option<Resources>& resources,
       const Option<std::map<std::string, std::string>>& env);
 
+  static void slavePostFetchHook(
+      const ContainerID& containerId,
+      const std::string& directory);
+
   static void slaveRemoveExecutorHook(
       const FrameworkInfo& frameworkInfo,
       const ExecutorInfo& executorInfo);

http://git-wip-us.apache.org/repos/asf/mesos/blob/80550c7d/src/slave/containerizer/docker.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp
index 9c24227..30f85a1 100644
--- a/src/slave/containerizer/docker.cpp
+++ b/src/slave/containerizer/docker.cpp
@@ -1039,11 +1039,19 @@ Future<bool> DockerContainerizerProcess::launch(
     // creates the Docker container for the task. See more details in
     // the comments of r33174.
     return container.get()->launch = fetch(containerId, slaveId)
-      .then(defer(self(), [=]() { return pull(containerId); }))
       .then(defer(self(), [=]() {
+        return pull(containerId);
+      }))
+      .then(defer(self(), [=]() {
+        if (HookManager::hooksAvailable()) {
+          HookManager::slavePostFetchHook(containerId, directory);
+        }
+
         return mountPersistentVolumes(containerId);
       }))
-      .then(defer(self(), [=]() { return launchExecutorProcess(containerId); }))
+      .then(defer(self(), [=]() {
+        return launchExecutorProcess(containerId);
+      }))
       .then(defer(self(), [=](pid_t pid) {
         return reapExecutor(containerId, pid);
       }));
@@ -1063,8 +1071,14 @@ Future<bool> DockerContainerizerProcess::launch(
   // running in a container (via docker_mesos_image flag) we want the
   // executor to keep running when the slave container dies.
   return container.get()->launch = fetch(containerId, slaveId)
-    .then(defer(self(), [=]() { return pull(containerId); }))
     .then(defer(self(), [=]() {
+      return pull(containerId);
+    }))
+    .then(defer(self(), [=]() {
+      if (HookManager::hooksAvailable()) {
+        HookManager::slavePostFetchHook(containerId, directory);
+      }
+
       return mountPersistentVolumes(containerId);
     }))
     .then(defer(self(), [=]() {
@@ -2011,7 +2025,6 @@ void DockerContainerizerProcess::remove(
   }
 }
 
-
 } // namespace slave {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/80550c7d/src/slave/containerizer/mesos/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index c25fa92..dfaffd7 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -38,6 +38,8 @@
 
 #include "common/protobuf_utils.hpp"
 
+#include "hook/manager.hpp"
+
 #include "module/manager.hpp"
 
 #include "slave/paths.hpp"
@@ -948,7 +950,13 @@ Future<Nothing> MesosContainerizerProcess::fetch(
       directory,
       user,
       slaveId,
-      flags);
+      flags)
+    .then([=]() -> Future<Nothing> {
+      if (HookManager::hooksAvailable()) {
+        HookManager::slavePostFetchHook(containerId, directory);
+      }
+      return Nothing();
+    });
 }