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:05 UTC
[1/6] mesos git commit: Added 'HealthCheck' protobuf validation.
Repository: mesos
Updated Branches:
refs/heads/master b2ae63af6 -> a536cef67
Added 'HealthCheck' protobuf validation.
Review: https://reviews.apache.org/r/50994/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b3319473
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b3319473
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b3319473
Branch: refs/heads/master
Commit: b3319473f18c872db6638d7cdcba607d18345107
Parents: b2ae63a
Author: haosdent huang <ha...@gmail.com>
Authored: Sat Aug 13 01:34:37 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sat Aug 13 03:43:16 2016 +0200
----------------------------------------------------------------------
src/health-check/health_checker.cpp | 82 +++++++++++++++++++++++---------
src/health-check/health_checker.hpp | 7 +++
src/master/validation.cpp | 17 +++++++
src/master/validation.hpp | 3 ++
src/tests/health_check_tests.cpp | 2 +
5 files changed, 88 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b3319473/src/health-check/health_checker.cpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.cpp b/src/health-check/health_checker.cpp
index d43cb05..50d598e 100644
--- a/src/health-check/health_checker.cpp
+++ b/src/health-check/health_checker.cpp
@@ -66,12 +66,9 @@ Try<Owned<HealthChecker>> HealthChecker::create(
const TaskID& taskID)
{
// Validate the 'HealthCheck' protobuf.
- if (check.has_http() && check.has_command()) {
- return Error("Both 'http' and 'command' health check requested");
- }
-
- if (!check.has_http() && !check.has_command()) {
- return Error("Expecting one of 'http' or 'command' health check");
+ Option<Error> error = validation::healthCheck(check);
+ if (error.isSome()) {
+ return error.get();
}
Owned<HealthCheckerProcess> process(new HealthCheckerProcess(
@@ -184,13 +181,8 @@ void HealthCheckerProcess::success()
void HealthCheckerProcess::_healthCheck()
{
- if (check.has_http()) {
- promise.fail("HTTP health check is not supported");
- return;
- }
-
- if (!check.has_command()) {
- promise.fail("No check found in health check");
+ if (check.type() != HealthCheck::COMMAND) {
+ promise.fail("Only command health checks are supported");
return;
}
@@ -208,11 +200,6 @@ void HealthCheckerProcess::_healthCheck()
if (command.shell()) {
// Use the shell variant.
- if (!command.has_value()) {
- promise.fail("Shell command is not specified");
- return;
- }
-
VLOG(2) << "Launching health command '" << command.value() << "'";
external = subprocess(
@@ -224,11 +211,6 @@ void HealthCheckerProcess::_healthCheck()
environment);
} else {
// Use the exec variant.
- if (!command.has_value()) {
- promise.fail("Executable path is not specified");
- return;
- }
-
vector<string> argv;
foreach (const string& arg, command.arguments()) {
argv.push_back(arg);
@@ -300,5 +282,59 @@ void HealthCheckerProcess::reschedule()
delay(Seconds(check.interval_seconds()), self(), &Self::_healthCheck);
}
+
+namespace validation {
+
+Option<Error> healthCheck(const HealthCheck& check)
+{
+ if (!check.has_type()) {
+ return Error("HealthCheck must specify 'type'");
+ }
+
+ if (check.type() == HealthCheck::COMMAND) {
+ if (!check.has_command()) {
+ return Error("Expecting 'command' to be set for command health check");
+ }
+
+ const CommandInfo& command = check.command();
+
+ if (!command.has_value()) {
+ string commandType =
+ (command.shell() ? "'shell command'" : "'executable path'");
+
+ return Error("Command health check must contain " + commandType);
+ }
+ } else if (check.type() == HealthCheck::HTTP) {
+ if (!check.has_http()) {
+ return Error("Expecting 'http' to be set for HTTP health check");
+ }
+
+ const HealthCheck::HTTPCheckInfo& http = check.http();
+
+ if (http.has_scheme() &&
+ http.scheme() != "https" &&
+ http.scheme() != "https") {
+ return Error("Unsupported HTTP health check scheme: '" + http.scheme() +
+ "'");
+ }
+
+ if (http.has_path() && !strings::startsWith(http.path(), '/')) {
+ return Error("The path '" + http.path() + "' of HTTP health check must "
+ "start with '/'");
+ }
+ } else if (check.type() == HealthCheck::TCP) {
+ if (!check.has_tcp()) {
+ return Error("Expecting 'tcp' to be set for TCP health check");
+ }
+ } else {
+ return Error("Unsupported health check type: '" +
+ HealthCheck::Type_Name(check.type()) + "'");
+ }
+
+ return None();
+}
+
+} // namespace validation {
+
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/b3319473/src/health-check/health_checker.hpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.hpp b/src/health-check/health_checker.hpp
index 7bc345b..3b40ee6 100644
--- a/src/health-check/health_checker.hpp
+++ b/src/health-check/health_checker.hpp
@@ -87,6 +87,13 @@ private:
process::Time startTime;
};
+
+namespace validation {
+
+Option<Error> healthCheck(const HealthCheck& check);
+
+} // namespace validation {
+
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/b3319473/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index af18e5a..7884191 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -29,6 +29,8 @@
#include <stout/none.hpp>
#include <stout/stringify.hpp>
+#include "health-check/health_checker.hpp"
+
#include "master/master.hpp"
#include "master/validation.hpp"
@@ -736,6 +738,20 @@ Option<Error> validateKillPolicy(const TaskInfo& task)
}
+Option<Error> validateHealthCheck(const TaskInfo& task)
+{
+ if (task.has_health_check()) {
+ Option<Error> error =
+ mesos::internal::validation::healthCheck(task.health_check());
+
+ if (error.isSome()) {
+ return Error("Task uses invalid health check: " + error.get().message);
+ }
+ }
+
+ return None();
+}
+
} // namespace internal {
@@ -759,6 +775,7 @@ Option<Error> validate(
lambda::bind(internal::validateExecutorInfo, task, framework, slave),
lambda::bind(internal::validateResources, task),
lambda::bind(internal::validateKillPolicy, task),
+ lambda::bind(internal::validateHealthCheck, task),
lambda::bind(
internal::validateResourceUsage, task, framework, slave, offered)
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/b3319473/src/master/validation.hpp
----------------------------------------------------------------------
diff --git a/src/master/validation.hpp b/src/master/validation.hpp
index 43d876b..fd00609 100644
--- a/src/master/validation.hpp
+++ b/src/master/validation.hpp
@@ -98,6 +98,9 @@ Option<Error> validateResources(const TaskInfo& task);
// Validates the kill policy of the task.
Option<Error> validateKillPolicy(const TaskInfo& task);
+// Validates the health check of the task.
+Option<Error> validateHealthCheck(const TaskInfo& task);
+
} // namespace internal {
} // namespace task {
http://git-wip-us.apache.org/repos/asf/mesos/blob/b3319473/src/tests/health_check_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/health_check_tests.cpp b/src/tests/health_check_tests.cpp
index 3b44d80..2680274 100644
--- a/src/tests/health_check_tests.cpp
+++ b/src/tests/health_check_tests.cpp
@@ -135,6 +135,7 @@ public:
}
}
+ healthCheck.set_type(HealthCheck::COMMAND);
healthCheck.mutable_command()->CopyFrom(healthCommand);
healthCheck.set_delay_seconds(0);
healthCheck.set_interval_seconds(0);
@@ -353,6 +354,7 @@ TEST_F(HealthCheckTest, ROOT_HealthyTaskWithContainerImage)
container->mutable_mesos()->mutable_image()->CopyFrom(image);
HealthCheck* health = task.mutable_health_check();
+ health->set_type(HealthCheck::COMMAND);
health->mutable_command()->set_value("exit 0");
Future<TaskStatus> statusRunning;
[5/6] mesos git commit: Wrapped `HealthChecker` into `health`
namespace.
Posted by al...@apache.org.
Wrapped `HealthChecker` into `health` namespace.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/95361781
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/95361781
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/95361781
Branch: refs/heads/master
Commit: 953617819cfd8e83e44850af0c7872f83fefa9e8
Parents: 23aa2f4
Author: Alexander Rukletsov <al...@apache.org>
Authored: Sat Aug 13 03:39:24 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sat Aug 13 03:43:19 2016 +0200
----------------------------------------------------------------------
src/docker/executor.cpp | 3 +--
src/health-check/health_checker.cpp | 2 ++
src/health-check/health_checker.hpp | 2 ++
src/health-check/main.cpp | 4 ++--
src/launcher/executor.cpp | 11 ++++++-----
src/master/validation.cpp | 3 +--
src/tests/health_check_tests.cpp | 2 +-
7 files changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/95361781/src/docker/executor.cpp
----------------------------------------------------------------------
diff --git a/src/docker/executor.cpp b/src/docker/executor.cpp
index 0b58a64..ba70749 100644
--- a/src/docker/executor.cpp
+++ b/src/docker/executor.cpp
@@ -482,8 +482,7 @@ private:
HealthCheck healthCheck = task.health_check();
// Validate the `HealthCheck` protobuf.
- Option<Error> validateCheck =
- mesos::internal::validation::healthCheck(healthCheck);
+ Option<Error> validateCheck = health::validation::healthCheck(healthCheck);
if (validateCheck.isSome()) {
cerr << "Unable to launch health check process: "
http://git-wip-us.apache.org/repos/asf/mesos/blob/95361781/src/health-check/health_checker.cpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.cpp b/src/health-check/health_checker.cpp
index becf145..45a5fe0 100644
--- a/src/health-check/health_checker.cpp
+++ b/src/health-check/health_checker.cpp
@@ -59,6 +59,7 @@ using std::vector;
namespace mesos {
namespace internal {
+namespace health {
Try<Owned<HealthChecker>> HealthChecker::create(
const HealthCheck& check,
@@ -377,5 +378,6 @@ Option<Error> healthCheck(const HealthCheck& check)
} // namespace validation {
+} // namespace health {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/95361781/src/health-check/health_checker.hpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.hpp b/src/health-check/health_checker.hpp
index 00a14c6..b4548f3 100644
--- a/src/health-check/health_checker.hpp
+++ b/src/health-check/health_checker.hpp
@@ -34,6 +34,7 @@
namespace mesos {
namespace internal {
+namespace health {
// Forward declarations.
class HealthCheckerProcess;
@@ -97,6 +98,7 @@ Option<Error> healthCheck(const HealthCheck& check);
} // namespace validation {
+} // namespace health {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/95361781/src/health-check/main.cpp
----------------------------------------------------------------------
diff --git a/src/health-check/main.cpp b/src/health-check/main.cpp
index 0b13926..5346e30 100644
--- a/src/health-check/main.cpp
+++ b/src/health-check/main.cpp
@@ -151,7 +151,7 @@ int main(int argc, char** argv)
TaskID taskID;
taskID.set_value(flags.task_id.get());
- mesos::internal::HealthCheckerProcess process(
+ mesos::internal::health::HealthCheckerProcess process(
check.get(),
flags.executor.get(),
taskID);
@@ -160,7 +160,7 @@ int main(int argc, char** argv)
process::Future<Nothing> checking =
process::dispatch(
- process, &mesos::internal::HealthCheckerProcess::healthCheck);
+ process, &mesos::internal::health::HealthCheckerProcess::healthCheck);
checking.await();
http://git-wip-us.apache.org/repos/asf/mesos/blob/95361781/src/launcher/executor.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/executor.cpp b/src/launcher/executor.cpp
index 7967684..2d04edb 100644
--- a/src/launcher/executor.cpp
+++ b/src/launcher/executor.cpp
@@ -409,10 +409,11 @@ protected:
cout << "Forked command at " << pid << endl;
if (task->has_health_check()) {
- Try<Owned<HealthChecker>> _checker = HealthChecker::create(
- task->health_check(),
- self(),
- task->task_id());
+ Try<Owned<health::HealthChecker>> _checker =
+ health::HealthChecker::create(
+ task->health_check(),
+ self(),
+ task->task_id());
if (_checker.isError()) {
// TODO(gilbert): Consider ABORT and return a TASK_FAILED here.
@@ -745,7 +746,7 @@ private:
Owned<MesosBase> mesos;
LinkedHashMap<UUID, Call::Update> updates; // Unacknowledged updates.
Option<TaskInfo> task; // Unacknowledged task.
- Owned<HealthChecker> checker;
+ Owned<health::HealthChecker> checker;
};
} // namespace internal {
http://git-wip-us.apache.org/repos/asf/mesos/blob/95361781/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index 7884191..52d9137 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -741,8 +741,7 @@ Option<Error> validateKillPolicy(const TaskInfo& task)
Option<Error> validateHealthCheck(const TaskInfo& task)
{
if (task.has_health_check()) {
- Option<Error> error =
- mesos::internal::validation::healthCheck(task.health_check());
+ Option<Error> error = health::validation::healthCheck(task.health_check());
if (error.isSome()) {
return Error("Task uses invalid health check: " + error.get().message);
http://git-wip-us.apache.org/repos/asf/mesos/blob/95361781/src/tests/health_check_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/health_check_tests.cpp b/src/tests/health_check_tests.cpp
index 9de8563..e69c4f5 100644
--- a/src/tests/health_check_tests.cpp
+++ b/src/tests/health_check_tests.cpp
@@ -164,7 +164,7 @@ public:
// This tests ensures `HealthCheck` protobuf is validated correctly.
TEST_F(HealthCheckTest, HealthCheckProtobufValidation)
{
- using namespace mesos::internal;
+ using namespace mesos::internal::health;
// Health check type must be set to a known value.
{
[4/6] mesos git commit: Added a test for `HealthCheck` protobuf
validation.
Posted by al...@apache.org.
Added a test for `HealthCheck` protobuf validation.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/23aa2f44
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/23aa2f44
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/23aa2f44
Branch: refs/heads/master
Commit: 23aa2f445c7a19dba9d7f8f1211f7a8802284440
Parents: 72efadf
Author: Alexander Rukletsov <al...@apache.org>
Authored: Sat Aug 13 02:59:11 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sat Aug 13 03:43:19 2016 +0200
----------------------------------------------------------------------
src/tests/health_check_tests.cpp | 68 +++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/23aa2f44/src/tests/health_check_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/health_check_tests.cpp b/src/tests/health_check_tests.cpp
index 2680274..9de8563 100644
--- a/src/tests/health_check_tests.cpp
+++ b/src/tests/health_check_tests.cpp
@@ -24,6 +24,8 @@
#include "docker/docker.hpp"
+#include "health-check/health_checker.hpp"
+
#include "slave/slave.hpp"
#include "slave/containerizer/docker.hpp"
@@ -159,6 +161,72 @@ public:
};
+// This tests ensures `HealthCheck` protobuf is validated correctly.
+TEST_F(HealthCheckTest, HealthCheckProtobufValidation)
+{
+ using namespace mesos::internal;
+
+ // Health check type must be set to a known value.
+ {
+ HealthCheck healthCheckProto;
+
+ Option<Error> validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+
+ healthCheckProto.set_type(HealthCheck::UNKNOWN);
+ validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+ }
+
+ // The associated with the type health description must be present.
+ {
+ HealthCheck healthCheckProto;
+
+ healthCheckProto.set_type(HealthCheck::COMMAND);
+ Option<Error> validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+
+ healthCheckProto.set_type(HealthCheck::HTTP);
+ validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+
+ healthCheckProto.set_type(HealthCheck::TCP);
+ validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+ }
+
+ // Command health check must specify an actual command in `command.value`.
+ {
+ HealthCheck healthCheckProto;
+
+ healthCheckProto.set_type(HealthCheck::COMMAND);
+ healthCheckProto.mutable_command()->CopyFrom(CommandInfo());
+ Option<Error> validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+ }
+
+ // HTTP health check may specify a known scheme and a path starting with '/'.
+ {
+ HealthCheck healthCheckProto;
+
+ healthCheckProto.set_type(HealthCheck::HTTP);
+ healthCheckProto.mutable_http()->set_port(8080);
+
+ Option<Error> validate = validation::healthCheck(healthCheckProto);
+ EXPECT_NONE(validate);
+
+ healthCheckProto.mutable_http()->set_scheme("ftp");
+ validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+
+ healthCheckProto.mutable_http()->set_scheme("https");
+ healthCheckProto.mutable_http()->set_path("healthz");
+ validate = validation::healthCheck(healthCheckProto);
+ EXPECT_SOME(validate);
+ }
+}
+
+
// Testing a healthy task reporting one healthy status to scheduler.
TEST_F(HealthCheckTest, HealthyTask)
{
[6/6] mesos git commit: Removed extra `HealthCheck` validation in
docker executor.
Posted by al...@apache.org.
Removed extra `HealthCheck` validation in docker executor.
The extra validation of the `HealthCheck` protobuf in the docker
executor is not necessary. The `HealthCheck` protobuf will be first
validated by the master as part of the `TaskInfo` validation and then
the modified version of the protobuf by the health check library.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a536cef6
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a536cef6
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a536cef6
Branch: refs/heads/master
Commit: a536cef67d2f250f60eb2f991e62402dae0590a1
Parents: 9536178
Author: Alexander Rukletsov <al...@apache.org>
Authored: Sat Aug 13 03:41:45 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sat Aug 13 03:43:19 2016 +0200
----------------------------------------------------------------------
src/docker/executor.cpp | 3 ---
1 file changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/a536cef6/src/docker/executor.cpp
----------------------------------------------------------------------
diff --git a/src/docker/executor.cpp b/src/docker/executor.cpp
index ba70749..4a755f3 100644
--- a/src/docker/executor.cpp
+++ b/src/docker/executor.cpp
@@ -481,9 +481,6 @@ private:
HealthCheck healthCheck = task.health_check();
- // Validate the `HealthCheck` protobuf.
- Option<Error> validateCheck = health::validation::healthCheck(healthCheck);
-
if (validateCheck.isSome()) {
cerr << "Unable to launch health check process: "
<< validateCheck.get().message << endl;
[2/6] mesos git commit: Updated 'HealthCheck' protobuf validation in
docker executor.
Posted by al...@apache.org.
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);
[3/6] mesos git commit: Dispatched health check by type.
Posted by al...@apache.org.
Dispatched health check by type.
Review: https://reviews.apache.org/r/50996/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/72efadff
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/72efadff
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/72efadff
Branch: refs/heads/master
Commit: 72efadff0e76b55208baa4e27f5e91d248d4a63c
Parents: 1a6284b
Author: haosdent huang <ha...@gmail.com>
Authored: Sat Aug 13 02:17:03 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sat Aug 13 03:43:18 2016 +0200
----------------------------------------------------------------------
src/health-check/health_checker.cpp | 47 ++++++++++++++++++++++++++++++--
src/health-check/health_checker.hpp | 5 +++-
2 files changed, 48 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/72efadff/src/health-check/health_checker.cpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.cpp b/src/health-check/health_checker.cpp
index 50d598e..becf145 100644
--- a/src/health-check/health_checker.cpp
+++ b/src/health-check/health_checker.cpp
@@ -181,10 +181,33 @@ void HealthCheckerProcess::success()
void HealthCheckerProcess::_healthCheck()
{
- if (check.type() != HealthCheck::COMMAND) {
- promise.fail("Only command health checks are supported");
- return;
+ switch (check.type()) {
+ case HealthCheck::COMMAND: {
+ _commandHealthCheck();
+ return;
+ }
+
+ case HealthCheck::HTTP: {
+ _httpHealthCheck();
+ return;
+ }
+
+ case HealthCheck::TCP: {
+ _tcpHealthCheck();
+ return;
+ }
+
+ default: {
+ UNREACHABLE();
+ }
}
+}
+
+
+void HealthCheckerProcess::_commandHealthCheck()
+{
+ CHECK_EQ(HealthCheck::COMMAND, check.type());
+ CHECK(check.has_command());
const CommandInfo& command = check.command();
@@ -274,6 +297,24 @@ void HealthCheckerProcess::_healthCheck()
}
+void HealthCheckerProcess::_httpHealthCheck()
+{
+ CHECK_EQ(HealthCheck::HTTP, check.type());
+ CHECK(check.has_http());
+
+ promise.fail("HTTP health check is not supported");
+}
+
+
+void HealthCheckerProcess::_tcpHealthCheck()
+{
+ CHECK_EQ(HealthCheck::TCP, check.type());
+ CHECK(check.has_tcp());
+
+ promise.fail("TCP health check is not supported");
+}
+
+
void HealthCheckerProcess::reschedule()
{
VLOG(1) << "Rescheduling health check in "
http://git-wip-us.apache.org/repos/asf/mesos/blob/72efadff/src/health-check/health_checker.hpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.hpp b/src/health-check/health_checker.hpp
index 3b40ee6..00a14c6 100644
--- a/src/health-check/health_checker.hpp
+++ b/src/health-check/health_checker.hpp
@@ -71,11 +71,14 @@ public:
private:
void failure(const std::string& message);
-
void success();
void _healthCheck();
+ void _commandHealthCheck();
+ void _httpHealthCheck();
+ void _tcpHealthCheck();
+
void reschedule();
process::Promise<Nothing> promise;