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/08/21 00:53:03 UTC

[2/2] mesos git commit: Added extra functions to the 'Launcher' abstraction.

Added extra functions to the 'Launcher' abstraction.

The functions added in this commit are not currently used anywhere in
the code base. However, they are required for some changes we are
making in order to persist container state in cases where an agent
crashes. The changes to use these function will come in subsequent
commits.

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


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

Branch: refs/heads/master
Commit: bb047cd72936aa1836b6e959127a572c72fb824b
Parents: c59f5b1
Author: Kevin Klues <kl...@gmail.com>
Authored: Sat Aug 20 17:52:56 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Sat Aug 20 17:52:56 2016 -0700

----------------------------------------------------------------------
 src/slave/containerizer/mesos/launcher.cpp      | 43 +++++++++++++++++++-
 src/slave/containerizer/mesos/launcher.hpp      | 26 +++++++++++-
 .../containerizer/mesos/linux_launcher.cpp      | 15 +++++++
 .../containerizer/mesos/linux_launcher.hpp      |  3 ++
 src/tests/containerizer/launcher.hpp            |  4 ++
 5 files changed, 87 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bb047cd7/src/slave/containerizer/mesos/launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launcher.cpp b/src/slave/containerizer/mesos/launcher.cpp
index 9efe847..413a8af 100644
--- a/src/slave/containerizer/mesos/launcher.cpp
+++ b/src/slave/containerizer/mesos/launcher.cpp
@@ -21,6 +21,7 @@
 #include <process/process.hpp>
 #include <process/reap.hpp>
 
+#include <stout/path.hpp>
 #include <stout/unreachable.hpp>
 
 #include <stout/os/killtree.hpp>
@@ -46,9 +47,35 @@ namespace mesos {
 namespace internal {
 namespace slave {
 
+constexpr char POSIX_LAUNCHER_NAME[] = "posix";
+
+
+string Launcher::buildPathFromHierarchy(
+    const ContainerID& _containerId,
+    const string& prefix)
+{
+  // Build the path in reverse order
+  // by following the parent hierarchy.
+  ContainerID containerId = _containerId;
+
+  string path = path::join(prefix, containerId.value());
+
+  while (containerId.has_parent()) {
+    containerId = containerId.parent();
+
+    path = path::join(
+        prefix,
+        containerId.value(),
+        path);
+  }
+
+  return path;
+}
+
+
 Try<Launcher*> PosixLauncher::create(const Flags& flags)
 {
-  return new PosixLauncher();
+  return new PosixLauncher(flags);
 }
 
 
@@ -181,9 +208,21 @@ Future<ContainerStatus> PosixLauncher::status(const ContainerID& containerId)
 }
 
 
+string PosixLauncher::getExitStatusCheckpointPath(
+    const ContainerID& containerId)
+{
+  return path::join(
+      flags.runtime_dir,
+      "launcher",
+      POSIX_LAUNCHER_NAME,
+      buildPathFromHierarchy(containerId, "containers"),
+      "exit_status");
+}
+
+
 Try<Launcher*> WindowsLauncher::create(const Flags& flags)
 {
-  return new WindowsLauncher();
+  return new WindowsLauncher(flags);
 }
 
 } // namespace slave {

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb047cd7/src/slave/containerizer/mesos/launcher.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launcher.hpp b/src/slave/containerizer/mesos/launcher.hpp
index bf435e3..0eae095 100644
--- a/src/slave/containerizer/mesos/launcher.hpp
+++ b/src/slave/containerizer/mesos/launcher.hpp
@@ -80,6 +80,21 @@ public:
   // Currently only returns Executor PID info.
   virtual process::Future<ContainerStatus> status(
       const ContainerID& containerId) = 0;
+
+  // Get the the path where to checkpoint the
+  // exit status of the container with `containerId`.
+  virtual std::string getExitStatusCheckpointPath(
+      const ContainerID& containerId) = 0;
+
+protected:
+  // Build a path based on a hierarchy of containers whose leaf container
+  // is `containerId`. The `prefix` parameter is prepended to the
+  // `containerId` as we build the path up the tree (e.g. passing a
+  // `containersId` with a value of 3 and a prefix of `foo` would
+  // result in .../foo/1/foo/2/foo/3).
+  std::string buildPathFromHierarchy(
+      const ContainerID& containerId,
+      const string& prefix);
 };
 
 
@@ -115,12 +130,18 @@ public:
   virtual process::Future<ContainerStatus> status(
       const ContainerID& containerId);
 
+  virtual std::string getExitStatusCheckpointPath(
+      const ContainerID& containerId);
+
 protected:
-  PosixLauncher() {}
+  PosixLauncher(const Flags& _flags)
+    : flags(_flags) {}
 
   // The 'pid' is the process id of the first process and also the
   // process group id and session id.
   hashmap<ContainerID, pid_t> pids;
+
+  const Flags flags;
 };
 
 
@@ -134,7 +155,8 @@ public:
   virtual ~WindowsLauncher() {}
 
 private:
-  WindowsLauncher() {}
+  WindowsLauncher(const Flags& flags)
+    : PosixLauncher(flags) {}
 };
 
 } // namespace slave {

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb047cd7/src/slave/containerizer/mesos/linux_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.cpp b/src/slave/containerizer/mesos/linux_launcher.cpp
index 95dee95..7377316 100644
--- a/src/slave/containerizer/mesos/linux_launcher.cpp
+++ b/src/slave/containerizer/mesos/linux_launcher.cpp
@@ -54,6 +54,9 @@ namespace mesos {
 namespace internal {
 namespace slave {
 
+constexpr char LINUX_LAUNCHER_NAME[] = "linux";
+
+
 static ContainerID container(const string& cgroup)
 {
   string basename = Path(cgroup).basename();
@@ -379,6 +382,18 @@ Future<ContainerStatus> LinuxLauncher::status(const ContainerID& containerId)
 }
 
 
+string LinuxLauncher::getExitStatusCheckpointPath(
+    const ContainerID& containerId)
+{
+  return path::join(
+      flags.runtime_dir,
+      "launcher",
+      LINUX_LAUNCHER_NAME,
+      buildPathFromHierarchy(containerId, "containers"),
+      "exit_status");
+}
+
+
 string LinuxLauncher::cgroup(const ContainerID& containerId)
 {
   return path::join(flags.cgroups_root, containerId.value());

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb047cd7/src/slave/containerizer/mesos/linux_launcher.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.hpp b/src/slave/containerizer/mesos/linux_launcher.hpp
index c185222..8fbe1e9 100644
--- a/src/slave/containerizer/mesos/linux_launcher.hpp
+++ b/src/slave/containerizer/mesos/linux_launcher.hpp
@@ -55,6 +55,9 @@ public:
   virtual process::Future<ContainerStatus> status(
       const ContainerID& containerId);
 
+  virtual std::string getExitStatusCheckpointPath(
+      const ContainerID& containerId);
+
 private:
   LinuxLauncher(
       const Flags& flags,

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb047cd7/src/tests/containerizer/launcher.hpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/launcher.hpp b/src/tests/containerizer/launcher.hpp
index 7e5c243..94c62b7 100644
--- a/src/tests/containerizer/launcher.hpp
+++ b/src/tests/containerizer/launcher.hpp
@@ -78,6 +78,10 @@ public:
       status,
       process::Future<ContainerStatus>(const ContainerID& containerId));
 
+  MOCK_METHOD1(
+      getExitStatusCheckpointPath,
+      std::string(const ContainerID& containerId));
+
   process::Owned<slave::Launcher> real;
 };