You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/08/13 01:46:06 UTC

[2/6] mesos git commit: Updated 'HealthCheck' protobuf validation in docker executor.

Updated 'HealthCheck' protobuf validation in docker executor.

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


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

Branch: refs/heads/master
Commit: 1a6284b59aa0e2bd4afa6d422646a59e0d455521
Parents: b331947
Author: haosdent huang <ha...@gmail.com>
Authored: Sat Aug 13 02:11:05 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sat Aug 13 03:43:17 2016 +0200

----------------------------------------------------------------------
 src/docker/executor.cpp | 83 +++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1a6284b5/src/docker/executor.cpp
----------------------------------------------------------------------
diff --git a/src/docker/executor.cpp b/src/docker/executor.cpp
index 4c08e5d..0b58a64 100644
--- a/src/docker/executor.cpp
+++ b/src/docker/executor.cpp
@@ -44,6 +44,8 @@
 #include "docker/docker.hpp"
 #include "docker/executor.hpp"
 
+#include "health-check/health_checker.hpp"
+
 #include "logging/flags.hpp"
 #include "logging/logging.hpp"
 
@@ -478,54 +480,57 @@ private:
     }
 
     HealthCheck healthCheck = task.health_check();
-    if (!healthCheck.has_command()) {
-      cerr << "Unable to launch health process: "
-           << "Only command health check is supported now" << endl;
-      return;
-    }
 
-    // "docker exec" require docker version greater than 1.3.0.
-    Try<Nothing> validateVersion =
-      docker->validateVersion(Version(1, 3, 0));
+    // Validate the `HealthCheck` protobuf.
+    Option<Error> validateCheck =
+      mesos::internal::validation::healthCheck(healthCheck);
 
-    if (validateVersion.isError()) {
-      cerr << "Unable to launch health process: "
-           << validateVersion.error() << endl;
+    if (validateCheck.isSome()) {
+      cerr << "Unable to launch health check process: "
+           << validateCheck.get().message << endl;
       return;
     }
 
-    // Wrap the original health check command in "docker exec".
-    const CommandInfo& command = healthCheck.command();
-    if (!command.has_value()) {
-      cerr << "Unable to launch health process: "
-           << (command.shell() ? "Shell command" : "Executable path")
-           << " is not specified" << endl;
-      return;
-    }
+    // To make sure the health check runs in the same mount namespace
+    // with the container, we wrap the original command in `docker exec`.
+    if (healthCheck.has_command()) {
+      // `docker exec` requires docker version greater than 1.3.0.
+      Try<Nothing> validateVersion =
+        docker->validateVersion(Version(1, 3, 0));
+
+      if (validateVersion.isError()) {
+        cerr << "Unable to launch health check process: "
+             << validateVersion.error() << endl;
+        return;
+      }
 
-    vector<string> commandArguments;
-    commandArguments.push_back(docker->getPath());
-    commandArguments.push_back("exec");
-    commandArguments.push_back(containerName);
-
-    if (command.shell()) {
-      commandArguments.push_back("sh");
-      commandArguments.push_back("-c");
-      commandArguments.push_back("\"");
-      commandArguments.push_back(command.value());
-      commandArguments.push_back("\"");
-    } else {
-      commandArguments.push_back(command.value());
+      // Wrap the original health check command in `docker exec`.
+      const CommandInfo& command = healthCheck.command();
+
+      vector<string> commandArguments;
+      commandArguments.push_back(docker->getPath());
+      commandArguments.push_back("exec");
+      commandArguments.push_back(containerName);
+
+      if (command.shell()) {
+        commandArguments.push_back("sh");
+        commandArguments.push_back("-c");
+        commandArguments.push_back("\"");
+        commandArguments.push_back(command.value());
+        commandArguments.push_back("\"");
+      } else {
+        commandArguments.push_back(command.value());
 
-      foreach (const string& argument, command.arguments()) {
-        commandArguments.push_back(argument);
+        foreach (const string& argument, command.arguments()) {
+          commandArguments.push_back(argument);
+        }
       }
-    }
 
-    healthCheck.mutable_command()->set_shell(true);
-    healthCheck.mutable_command()->clear_arguments();
-    healthCheck.mutable_command()->set_value(
-        strings::join(" ", commandArguments));
+      healthCheck.mutable_command()->set_shell(true);
+      healthCheck.mutable_command()->clear_arguments();
+      healthCheck.mutable_command()->set_value(
+          strings::join(" ", commandArguments));
+    }
 
     JSON::Object json = JSON::protobuf(healthCheck);