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:49 UTC
[1/3] mesos git commit: Updated the authentication.md to use absolute
paths.
Repository: mesos
Updated Branches:
refs/heads/master 84778eeee -> 0e5680c51
Updated the authentication.md to use absolute paths.
Previous sample paths (~/credentials) caused issues when used from the
command line.
Review: https://reviews.apache.org/r/45895/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/579e772b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/579e772b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/579e772b
Branch: refs/heads/master
Commit: 579e772b536450c98270003444264f732e86964c
Parents: 84778ee
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Sun Apr 10 01:38:04 2016 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Sun Apr 10 01:42:10 2016 -0700
----------------------------------------------------------------------
docs/authentication.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/579e772b/docs/authentication.md
----------------------------------------------------------------------
diff --git a/docs/authentication.md b/docs/authentication.md
index dfdd28c..1084e63 100644
--- a/docs/authentication.md
+++ b/docs/authentication.md
@@ -118,11 +118,11 @@ the `Credential.principal` into `FrameworkInfo.principal` when registering.
]
}
-2. Start the master using the credentials file (assuming the file is `~/credentials`):
+2. Start the master using the credentials file (assuming the file is `/home/user/credentials`):
- ./bin/mesos-master.sh --ip=127.0.0.1 --work_dir=/var/lib/mesos --authenticate --authenticate_slaves --credentials=~/credentials
+ ./bin/mesos-master.sh --ip=127.0.0.1 --work_dir=/var/lib/mesos --authenticate --authenticate_slaves --credentials=/home/user/credentials
-3. Create another file with a single credential in it (`~/slave_credential`):
+3. Create another file with a single credential in it (`/home/user/slave_credential`):
{
"principal": "principal1",
@@ -131,7 +131,7 @@ the `Credential.principal` into `FrameworkInfo.principal` when registering.
4. Start the slave:
- ./bin/mesos-slave.sh --master=127.0.0.1:5050 --credential=~/slave_credential
+ ./bin/mesos-slave.sh --master=127.0.0.1:5050 --credential=/home/user/slave_credential
5. Your new slave should have now successfully authenticated with the master.
[3/3] mesos git commit: Added authentication test for /weights GET
request.
Posted by me...@apache.org.
Added authentication test for /weights GET request.
Review: https://reviews.apache.org/r/45203/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0e5680c5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0e5680c5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0e5680c5
Branch: refs/heads/master
Commit: 0e5680c51ce7479f294cc654007a007f2eaeb05d
Parents: a28f9e5
Author: Yongqiao Wang <yq...@cn.ibm.com>
Authored: Sun Apr 10 00:40:50 2016 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Sun Apr 10 02:50:22 2016 -0700
----------------------------------------------------------------------
src/tests/dynamic_weights_tests.cpp | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/0e5680c5/src/tests/dynamic_weights_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/dynamic_weights_tests.cpp b/src/tests/dynamic_weights_tests.cpp
index 614ff2d..f89b89d 100644
--- a/src/tests/dynamic_weights_tests.cpp
+++ b/src/tests/dynamic_weights_tests.cpp
@@ -540,6 +540,33 @@ TEST_F(DynamicWeightsTest, UnauthenticatedUpdateWeightRequest)
}
+// Checks that a weight query request is rejected for unauthenticated
+// principals.
+TEST_F(DynamicWeightsTest, UnauthenticatedQueryWeightRequest)
+{
+ // The master is configured so that only requests from `DEFAULT_CREDENTIAL`
+ // are authenticated.
+ Try<Owned<cluster::Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Credential credential;
+ credential.set_principal("unknown-principal");
+ credential.set_secret("test-secret");
+
+ // Send a weight query request.
+ Future<Response> response = process::http::request(
+ process::http::createRequest(
+ master.get()->pid,
+ "GET",
+ false,
+ "weights",
+ createBasicAuthHeaders(credential)));
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(Unauthorized({}).status, response)
+ << response.get().body;
+}
+
+
// Checks that an authorized principal can update weight with implicit roles.
TEST_F(DynamicWeightsTest, AuthorizedWeightUpdateRequest)
{
[2/3] mesos git commit: Supported querying weight infos via /weights.
Posted by me...@apache.org.
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