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/28 15:04:08 UTC
[08/10] mesos git commit: Added support for TCP health checks.
Added support for TCP health checks.
Review: https://reviews.apache.org/r/49360/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1d004920
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1d004920
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1d004920
Branch: refs/heads/master
Commit: 1d00492086a3b8298c2f23fd5196d31d0bfef73d
Parents: 2b80207
Author: haosdent huang <ha...@gmail.com>
Authored: Fri Aug 26 16:33:52 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Sun Aug 28 16:42:57 2016 +0200
----------------------------------------------------------------------
src/health-check/health_checker.cpp | 80 +++++++++++++++++++++++++++++++-
src/health-check/health_checker.hpp | 6 +++
2 files changed, 85 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/1d004920/src/health-check/health_checker.cpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.cpp b/src/health-check/health_checker.cpp
index 4dd573b..e5e7b94 100644
--- a/src/health-check/health_checker.cpp
+++ b/src/health-check/health_checker.cpp
@@ -444,7 +444,85 @@ Future<Nothing> HealthCheckerProcess::_tcpHealthCheck()
CHECK_EQ(HealthCheck::TCP, check.type());
CHECK(check.has_tcp());
- promise.fail("TCP health check is not supported");
+ const HealthCheck::TCPCheckInfo& tcp = check.tcp();
+
+ VLOG(1) << "Launching TCP health check at port '" << tcp.port() << "'";
+
+ // TODO(haosdent): Replace `bash` with a tiny binary to support
+ // TCP health check with half-open.
+ const vector<string> argv = {
+ "bash",
+ "-c",
+ "</dev/tcp/" + DEFAULT_DOMAIN + "/" + stringify(tcp.port())
+ };
+
+ Try<Subprocess> s = subprocess(
+ "bash",
+ argv,
+ Subprocess::PATH("/dev/null"),
+ Subprocess::PIPE(),
+ Subprocess::PIPE());
+
+ if (s.isError()) {
+ return Failure("Failed to create the bash subprocess: " + s.error());
+ }
+
+ pid_t bashPid = s->pid();
+ Duration timeout = Seconds(check.timeout_seconds());
+
+ return await(
+ s->status(),
+ process::io::read(s->out().get()),
+ process::io::read(s->err().get()))
+ .after(timeout,
+ [timeout, bashPid](Future<tuple<Future<Option<int>>,
+ Future<string>,
+ Future<string>>> future) {
+ future.discard();
+
+ if (bashPid != -1) {
+ // Cleanup the bash process.
+ VLOG(1) << "Killing the TCP health check process " << bashPid;
+
+ os::killtree(bashPid, SIGKILL);
+ }
+
+ return Failure(
+ "bash has not returned after " + stringify(timeout) + "; aborting");
+ })
+ .then(defer(self(), &Self::__tcpHealthCheck, lambda::_1));
+}
+
+
+Future<Nothing> HealthCheckerProcess::__tcpHealthCheck(
+ const tuple<
+ Future<Option<int>>,
+ Future<string>,
+ Future<string>>& t)
+{
+ Future<Option<int>> status = std::get<0>(t);
+ if (!status.isReady()) {
+ return Failure(
+ "Failed to get the exit status of the bash process: " +
+ (status.isFailed() ? status.failure() : "discarded"));
+ }
+
+ if (status->isNone()) {
+ return Failure("Failed to reap the bash process");
+ }
+
+ int statusCode = status->get();
+ if (statusCode != 0) {
+ Future<string> error = std::get<2>(t);
+ if (!error.isReady()) {
+ return Failure("bash returned " + WSTRINGIFY(statusCode) +
+ "; reading stderr failed: " +
+ (error.isFailed() ? error.failure() : "discarded"));
+ }
+
+ return Failure("bash returned " + WSTRINGIFY(statusCode) + ": " +
+ error.get());
+ }
return Nothing();
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/1d004920/src/health-check/health_checker.hpp
----------------------------------------------------------------------
diff --git a/src/health-check/health_checker.hpp b/src/health-check/health_checker.hpp
index 83a3384..52acdef 100644
--- a/src/health-check/health_checker.hpp
+++ b/src/health-check/health_checker.hpp
@@ -91,6 +91,12 @@ private:
process::Future<Nothing> _tcpHealthCheck();
+ process::Future<Nothing> __tcpHealthCheck(
+ const std::tuple<
+ process::Future<Option<int>>,
+ process::Future<std::string>,
+ process::Future<std::string>>& t);
+
void reschedule();
process::Promise<Nothing> promise;