You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2016/04/10 12:47:50 UTC
[2/3] mesos git commit: Supported querying weight infos via /weights.
Supported querying weight infos via /weights.
Review: https://reviews.apache.org/r/44512/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a28f9e5e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a28f9e5e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a28f9e5e
Branch: refs/heads/master
Commit: a28f9e5e4180c26cd708cdf6dada3ba24813926d
Parents: 579e772
Author: Yongqiao Wang <yq...@cn.ibm.com>
Authored: Sun Apr 10 00:19:43 2016 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Sun Apr 10 02:50:20 2016 -0700
----------------------------------------------------------------------
docs/weights.md | 41 ++++++++++++++++++++++++++++++++++---
src/master/http.cpp | 14 +++++++------
src/master/master.hpp | 3 +++
src/master/weights_handler.cpp | 22 ++++++++++++++++++++
4 files changed, 71 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/a28f9e5e/docs/weights.md
----------------------------------------------------------------------
diff --git a/docs/weights.md b/docs/weights.md
index a942513..59d1579 100644
--- a/docs/weights.md
+++ b/docs/weights.md
@@ -19,13 +19,21 @@ is deprecated.
# Operator HTTP Endpoint
-The master `/weights` HTTP endpoint enables operators to update weights. The
-endpoint currently offers a REST-like interface and only supports update
-requests using PUT.
+The master `/weights` HTTP endpoint enables operators to configure weights. The
+endpoint currently offers a REST-like interface and supports the following operations:
+
+* [Updating](#putRequest) weights with PUT.
+* [Querying](#getRequest) the currently set weights with GET.
The endpoint can optionally use authentication and authorization. See the
[authentication guide](authentication.md) for details.
+<a name="putRequest"></a>
+## Update
+
+The operator can update the weights by sending an HTTP PUT request to the `/weights`
+endpoint.
+
An example request to the `/weights` endpoint could look like this (using the
JSON definitions below):
@@ -59,3 +67,30 @@ The operator will receive one of the following HTTP response codes:
* `400 BadRequest`: Invalid arguments (e.g., invalid JSON, non-positive weights).
* `401 Unauthorized`: Unauthenticated request.
* `403 Forbidden`: Unauthorized request.
+
+<a name="getRequest"></a>
+## Query
+
+The operator can query the configured weights by sending an HTTP GET request
+to the `/weights` endpoint.
+
+ $ curl -X GET http://<master-ip>:<port>/weights
+
+The response message body includes a JSON representation of the current
+configured weights, for example:
+
+ [
+ {
+ "role": "role2",
+ "weight": 3.5
+ },
+ {
+ "role": "role1",
+ "weight": 2.0
+ }
+ ]
+
+The operator will receive one of the following HTTP response codes:
+
+* `200 OK`: Success.
+* `401 Unauthorized`: Unauthenticated request.
http://git-wip-us.apache.org/repos/asf/mesos/blob/a28f9e5e/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index f781fd0..626c88f 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -1208,18 +1208,20 @@ Future<Response> Master::Http::weights(
const Request& request,
const Option<string>& principal) const
{
+ // TODO(Yongqiao Wang): `/roles` endpoint also shows the weights information,
+ // consider erasing the duplicated information later.
+ if (request.method == "GET") {
+ return weightsHandler.get(request);
+ }
+
// Dispatch based on HTTP method to separate `WeightsHandler`.
if (request.method == "PUT") {
return weightsHandler.update(request, principal);
}
- // TODO(Yongqiao Wang): Like /quota, we should also add query logic
- // for /weights to keep consistent. Then /roles no longer needs to
- // show weight information.
-
return MethodNotAllowed(
- {"PUT"},
- "Expecting 'PUT', received '" + request.method + "'");
+ {"GET", "PUT"},
+ "Expecting 'GET' or 'PUT', received '" + request.method + "'");
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/a28f9e5e/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 4d99a07..1f480f0 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1032,6 +1032,9 @@ private:
CHECK_NOTNULL(master);
}
+ process::Future<process::http::Response> get(
+ const process::http::Request& request) const;
+
process::Future<process::http::Response> update(
const process::http::Request& request,
const Option<std::string>& principal) const;
http://git-wip-us.apache.org/repos/asf/mesos/blob/a28f9e5e/src/master/weights_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/weights_handler.cpp b/src/master/weights_handler.cpp
index e88bf2a..10a1fbc 100644
--- a/src/master/weights_handler.cpp
+++ b/src/master/weights_handler.cpp
@@ -51,6 +51,28 @@ namespace mesos {
namespace internal {
namespace master {
+Future<http::Response> Master::WeightsHandler::get(
+ const http::Request& request) const
+{
+ VLOG(1) << "Handling get weights request.";
+
+ // Check that the request type is GET which is guaranteed by the master.
+ CHECK_EQ("GET", request.method);
+
+ RepeatedPtrField<WeightInfo> weightInfos;
+
+ // Create an entry for each weight.
+ foreachpair (const std::string& role, double weight, master->weights) {
+ WeightInfo weightInfo;
+ weightInfo.set_role(role);
+ weightInfo.set_weight(weight);
+ weightInfos.Add()->CopyFrom(weightInfo);
+ }
+
+ return OK(JSON::protobuf(weightInfos), request.url.query.get("jsonp"));
+}
+
+
Future<http::Response> Master::WeightsHandler::update(
const http::Request& request,
const Option<std::string>& principal) const