mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vinodk...@apache.org
Subject [2/2] mesos git commit: Changed operator API RPC handlers to `http::Response` in agent.
Date Thu, 09 Jun 2016 15:49:34 GMT
Changed operator API RPC handlers to `http::Response` in agent.

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


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

Branch: refs/heads/master
Commit: 22bc2d655b7e4567f8212bc151237d1b1e0d2939
Parents: 543e571
Author: haosdent huang <haosdent@gmail.com>
Authored: Thu Jun 9 11:49:21 2016 -0400
Committer: Vinod Kone <vinodkone@gmail.com>
Committed: Thu Jun 9 11:49:21 2016 -0400

----------------------------------------------------------------------
 src/slave/http.cpp  | 80 +++++++++++++++++++++++++-----------------------
 src/slave/slave.hpp | 20 +++++++-----
 2 files changed, 53 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/22bc2d65/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index c4dfa8f..67ad7a9 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -264,49 +264,37 @@ Future<Response> Slave::Http::api(
                       error.get().message);
   }
 
-  // This lambda serializes a `v1::agent::Response` into an `http::Response`.
-  auto serializer = [request](const v1::agent::Response& response_)
-                    -> Response {
-    ContentType responseContentType;
-    if (request.acceptsMediaType(APPLICATION_JSON)) {
-      responseContentType = ContentType::JSON;
-    } else if (request.acceptsMediaType(APPLICATION_PROTOBUF)) {
-      responseContentType = ContentType::PROTOBUF;
-    } else {
-      return NotAcceptable(
-          string("Expecting 'Accept' to allow ") +
-          "'" + APPLICATION_PROTOBUF + "' or '" + APPLICATION_JSON + "'");
-    }
-
-    // TODO(vinod): Support JSONP requests?
-    return OK(serialize(responseContentType, response_),
-              stringify(responseContentType));
-  };
-
   LOG(INFO) << "Processing call " << call.type();
 
+  ContentType responseContentType;
+  if (request.acceptsMediaType(APPLICATION_JSON)) {
+    responseContentType = ContentType::JSON;
+  } else if (request.acceptsMediaType(APPLICATION_PROTOBUF)) {
+    responseContentType = ContentType::PROTOBUF;
+  } else {
+    return NotAcceptable(
+        string("Expecting 'Accept' to allow ") +
+        "'" + APPLICATION_PROTOBUF + "' or '" + APPLICATION_JSON + "'");
+  }
+
   switch (call.type()) {
     case v1::agent::Call::UNKNOWN:
       return NotImplemented();
 
     case v1::agent::Call::GET_HEALTH:
-      return getHealth(call, principal)
-        .then(serializer);
+      return getHealth(call, principal, responseContentType);
 
     case v1::agent::Call::GET_FLAGS:
-      return getFlags(call, principal)
-        .then(serializer);
+      return getFlags(call, principal, responseContentType);
 
     case v1::agent::Call::GET_VERSION:
-      return getVersion(call, principal)
-        .then(serializer);
+      return getVersion(call, principal, responseContentType);
 
     case v1::agent::Call::GET_METRICS:
       return NotImplemented();
 
     case v1::agent::Call::GET_LOGGING_LEVEL:
-      return getLoggingLevel(call, principal)
-        .then(serializer);
+      return getLoggingLevel(call, principal, responseContentType);
 
     case v1::agent::Call::SET_LOGGING_LEVEL:
       return NotImplemented();
@@ -538,13 +526,18 @@ JSON::Object Slave::Http::_flags() const
 }
 
 
-Future<v1::agent::Response> Slave::Http::getFlags(
+Future<Response> Slave::Http::getFlags(
     const v1::agent::Call& call,
-    const Option<string>& principal) const
+    const Option<string>& principal,
+    const ContentType& responseContentType) const
 {
   CHECK_EQ(v1::agent::Call::GET_FLAGS, call.type());
 
-  return evolve<v1::agent::Response::GET_FLAGS>(_flags());
+  v1::agent::Response response =
+    evolve<v1::agent::Response::GET_FLAGS>(_flags());
+
+  return OK(serialize(responseContentType, response),
+            stringify(responseContentType));
 }
 
 
@@ -566,9 +559,10 @@ Future<Response> Slave::Http::health(const Request& request)
const
 }
 
 
-Future<v1::agent::Response> Slave::Http::getHealth(
+Future<Response> Slave::Http::getHealth(
     const v1::agent::Call& call,
-    const Option<string>& principal) const
+    const Option<string>& principal,
+    const ContentType& responseContentType) const
 {
   CHECK_EQ(v1::agent::Call::GET_HEALTH, call.type());
 
@@ -576,23 +570,30 @@ Future<v1::agent::Response> Slave::Http::getHealth(
   response.set_type(v1::agent::Response::GET_HEALTH);
   response.mutable_get_health()->set_healthy(true);
 
-  return response;
+  return OK(serialize(responseContentType, response),
+            stringify(responseContentType));
 }
 
 
-Future<v1::agent::Response> Slave::Http::getVersion(
+Future<Response> Slave::Http::getVersion(
     const v1::agent::Call& call,
-    const Option<string>& principal) const
+    const Option<string>& principal,
+    const ContentType& responseContentType) const
 {
   CHECK_EQ(v1::agent::Call::GET_VERSION, call.type());
 
-  return evolve<v1::agent::Response::GET_VERSION>(version());
+  v1::agent::Response response =
+    evolve<v1::agent::Response::GET_VERSION>(version());
+
+  return OK(serialize(responseContentType, response),
+            stringify(responseContentType));
 }
 
 
-Future<v1::agent::Response> Slave::Http::getLoggingLevel(
+Future<Response> Slave::Http::getLoggingLevel(
     const v1::agent::Call& call,
-    const Option<string>& principal) const
+    const Option<string>& principal,
+    const ContentType& responseContentType) const
 {
   CHECK_EQ(v1::agent::Call::GET_LOGGING_LEVEL, call.type());
 
@@ -600,7 +601,8 @@ Future<v1::agent::Response> Slave::Http::getLoggingLevel(
   response.set_type(v1::agent::Response::GET_LOGGING_LEVEL);
   response.mutable_get_logging_level()->set_level(FLAGS_v);
 
-  return response;
+  return OK(serialize(responseContentType, response),
+            stringify(responseContentType));
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/22bc2d65/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 52aeb0d..da8b0d7 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -511,21 +511,25 @@ private:
 
     // v1 agent API handlers.
 
-    process::Future<v1::agent::Response> getFlags(
+    process::Future<process::http::Response> getFlags(
         const v1::agent::Call& call,
-        const Option<std::string>& principal) const;
+        const Option<std::string>& principal,
+        const ContentType& responseContentType) const;
 
-    process::Future<v1::agent::Response> getHealth(
+    process::Future<process::http::Response> getHealth(
         const v1::agent::Call& call,
-        const Option<std::string>& principal) const;
+        const Option<std::string>& principal,
+        const ContentType& responseContentType) const;
 
-    process::Future<v1::agent::Response> getVersion(
+    process::Future<process::http::Response> getVersion(
         const v1::agent::Call& call,
-        const Option<std::string>& principal) const;
+        const Option<std::string>& principal,
+        const ContentType& responseContentType) const;
 
-    process::Future<v1::agent::Response> getLoggingLevel(
+    process::Future<process::http::Response> getLoggingLevel(
         const v1::agent::Call& call,
-        const Option<std::string>& principal) const;
+        const Option<std::string>& principal,
+        const ContentType& responseContentType) const;
 
     Slave* slave;
 


Mime
View raw message