Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6EF6F200AE4 for ; Thu, 9 Jun 2016 17:49:35 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6DC9D160A29; Thu, 9 Jun 2016 15:49:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 98F64160A58 for ; Thu, 9 Jun 2016 17:49:34 +0200 (CEST) Received: (qmail 9544 invoked by uid 500); 9 Jun 2016 15:49:33 -0000 Mailing-List: contact commits-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list commits@mesos.apache.org Received: (qmail 9528 invoked by uid 99); 9 Jun 2016 15:49:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jun 2016 15:49:33 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A6823DFF32; Thu, 9 Jun 2016 15:49:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vinodkone@apache.org To: commits@mesos.apache.org Date: Thu, 09 Jun 2016 15:49:34 -0000 Message-Id: <07fadb3e8736435db93b13b09fc64b35@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] mesos git commit: Changed operator API RPC handlers to `http::Response` in agent. archived-at: Thu, 09 Jun 2016 15:49:35 -0000 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 Authored: Thu Jun 9 11:49:21 2016 -0400 Committer: Vinod Kone 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 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 Slave::Http::getFlags( +Future Slave::Http::getFlags( const v1::agent::Call& call, - const Option& principal) const + const Option& principal, + const ContentType& responseContentType) const { CHECK_EQ(v1::agent::Call::GET_FLAGS, call.type()); - return evolve(_flags()); + v1::agent::Response response = + evolve(_flags()); + + return OK(serialize(responseContentType, response), + stringify(responseContentType)); } @@ -566,9 +559,10 @@ Future Slave::Http::health(const Request& request) const } -Future Slave::Http::getHealth( +Future Slave::Http::getHealth( const v1::agent::Call& call, - const Option& principal) const + const Option& principal, + const ContentType& responseContentType) const { CHECK_EQ(v1::agent::Call::GET_HEALTH, call.type()); @@ -576,23 +570,30 @@ Future 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 Slave::Http::getVersion( +Future Slave::Http::getVersion( const v1::agent::Call& call, - const Option& principal) const + const Option& principal, + const ContentType& responseContentType) const { CHECK_EQ(v1::agent::Call::GET_VERSION, call.type()); - return evolve(version()); + v1::agent::Response response = + evolve(version()); + + return OK(serialize(responseContentType, response), + stringify(responseContentType)); } -Future Slave::Http::getLoggingLevel( +Future Slave::Http::getLoggingLevel( const v1::agent::Call& call, - const Option& principal) const + const Option& principal, + const ContentType& responseContentType) const { CHECK_EQ(v1::agent::Call::GET_LOGGING_LEVEL, call.type()); @@ -600,7 +601,8 @@ Future 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 getFlags( + process::Future getFlags( const v1::agent::Call& call, - const Option& principal) const; + const Option& principal, + const ContentType& responseContentType) const; - process::Future getHealth( + process::Future getHealth( const v1::agent::Call& call, - const Option& principal) const; + const Option& principal, + const ContentType& responseContentType) const; - process::Future getVersion( + process::Future getVersion( const v1::agent::Call& call, - const Option& principal) const; + const Option& principal, + const ContentType& responseContentType) const; - process::Future getLoggingLevel( + process::Future getLoggingLevel( const v1::agent::Call& call, - const Option& principal) const; + const Option& principal, + const ContentType& responseContentType) const; Slave* slave;