You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/05/30 01:25:31 UTC

[09/11] mesos git commit: Implemented v1::agent::Call::GET_HEALTH.

Implemented v1::agent::Call::GET_HEALTH.

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


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

Branch: refs/heads/master
Commit: 7f5ec4a048e68f0a8eeda0a6199644917a0a2520
Parents: 4bf5fce
Author: Vinod Kone <vi...@gmail.com>
Authored: Sat May 28 22:38:34 2016 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Sun May 29 18:00:49 2016 -0700

----------------------------------------------------------------------
 src/slave/http.cpp      | 17 ++++++++++++++++-
 src/slave/slave.hpp     |  5 +++++
 src/tests/api_tests.cpp | 26 ++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7f5ec4a0/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 27c3e63..7121675 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -288,7 +288,8 @@ Future<Response> Slave::Http::api(
       return NotImplemented();
 
     case v1::agent::Call::GET_HEALTH:
-      return NotImplemented();
+      return getHealth(call, principal)
+        .then(serializer);
 
     case v1::agent::Call::GET_FLAGS:
       return getFlags(call, principal)
@@ -561,6 +562,20 @@ Future<Response> Slave::Http::health(const Request& request) const
 }
 
 
+Future<v1::agent::Response> Slave::Http::getHealth(
+    const v1::agent::Call& call,
+    const Option<string>& principal) const
+{
+  CHECK_EQ(v1::agent::Call::GET_HEALTH, call.type());
+
+  v1::agent::Response response;
+  response.set_type(v1::agent::Response::GET_HEALTH);
+  response.mutable_get_health()->set_healthy(true);
+
+  return response;
+}
+
+
 string Slave::Http::STATE_HELP() {
   return HELP(
     TLDR(

http://git-wip-us.apache.org/repos/asf/mesos/blob/7f5ec4a0/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 75a673e..91d687a 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -507,10 +507,15 @@ private:
         const std::string& method) const;
 
     // v1 agent API handlers.
+
     process::Future<v1::agent::Response> getFlags(
         const v1::agent::Call& call,
         const Option<std::string>& principal) const;
 
+    process::Future<v1::agent::Response> getHealth(
+        const v1::agent::Call& call,
+        const Option<std::string>& principal) const;
+
     Slave* slave;
 
     // Used to rate limit the statistics endpoint.

http://git-wip-us.apache.org/repos/asf/mesos/blob/7f5ec4a0/src/tests/api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp
index 7fbf08e..d1210bc 100644
--- a/src/tests/api_tests.cpp
+++ b/src/tests/api_tests.cpp
@@ -200,6 +200,32 @@ TEST_P(AgentAPITest, GetFlags)
   ASSERT_EQ(v1::agent::Response::GET_FLAGS, v1Response.get().type());
 }
 
+
+TEST_P(AgentAPITest, GetHealth)
+{
+  Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover);
+
+  StandaloneMasterDetector detector;
+  Try<Owned<cluster::Slave>> slave = this->StartSlave(&detector);
+  ASSERT_SOME(slave);
+
+  // Wait until the agent has finished recovery.
+  AWAIT_READY(__recover);
+
+  v1::agent::Call v1Call;
+  v1Call.set_type(v1::agent::Call::GET_HEALTH);
+
+  ContentType contentType = GetParam();
+
+  Future<v1::agent::Response> v1Response =
+    post(slave.get()->pid, v1Call, contentType);
+
+  AWAIT_READY(v1Response);
+  ASSERT_TRUE(v1Response.get().IsInitialized());
+  ASSERT_EQ(v1::agent::Response::GET_HEALTH, v1Response.get().type());
+  ASSERT_TRUE(v1Response.get().get_health().healthy());
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {