This is an automated email from the ASF dual-hosted git repository. mzhu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 817545318da364efdff7c9c3f888d0d7aa94da23 Author: Meng Zhu <[email protected]> AuthorDate: Tue Jul 30 18:48:32 2019 -0700 Updated quota related endpoints to return quota configurations. Added quota configuration information (that includes both guarantees and limits) in V1 GET_QUOTA call and V0 GET "/quota". To keep backwards compatibility, the infos field which only includes the guarantees are continue to be filled. An additional field configs was added. Also extended an existing test to cover the changes in the endpoints. Review: https://reviews.apache.org/r/71159 --- src/master/quota_handler.cpp | 15 +++++ src/tests/master_quota_tests.cpp | 136 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 150 insertions(+), 1 deletion(-) diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp index 15b02b0..f28eb27 100644 --- a/src/master/quota_handler.cpp +++ b/src/master/quota_handler.cpp @@ -409,6 +409,21 @@ Future<QuotaStatus> Master::QuotaHandler::_status( } return info; }(); + + *status.add_configs() = ["aIt]() { + QuotaConfig config; + config.set_role(quotaIt->first); + + foreach (auto& quantity, quotaIt->second.guarantees) { + (*config.mutable_guarantees())[quantity.first] = quantity.second; + } + + foreach (auto& limit, quotaIt->second.limits) { + (*config.mutable_limits())[limit.first] = limit.second; + } + + return config; + }(); } } diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp index 02b1e8d..b5fe235 100644 --- a/src/tests/master_quota_tests.cpp +++ b/src/tests/master_quota_tests.cpp @@ -140,6 +140,15 @@ static string createUpdateQuotaRequestBody( } +static string createGetQuotaRequestBody() +{ + mesos::master::Call call; + call.set_type(mesos::master::Call::GET_QUOTA); + + return stringify(JSON::protobuf(call)); +} + + // Quota tests that are allocator-agnostic (i.e. we expect every // allocator to implement basic quota guarantees) are in this // file. All tests are split into logical groups: @@ -211,7 +220,7 @@ protected: }; -TEST_F(MasterQuotaTest, UpdateQuota) +TEST_F(MasterQuotaTest, UpdateAndGetQuota) { TestAllocator<> allocator; EXPECT_CALL(allocator, initialize(_, _, _)); @@ -233,6 +242,7 @@ TEST_F(MasterQuotaTest, UpdateQuota) AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); + // Verify "/roles". response = process::http::get( master.get()->pid, "roles", @@ -275,6 +285,130 @@ TEST_F(MasterQuotaTest, UpdateQuota) EXPECT_EQ(*expected, *parse) << "expected " << stringify(*expected) << " vs actual " << stringify(*parse); + + // Verify `GET_QUOTA`. + response = process::http::post( + master.get()->pid, "/api/v1", headers, createGetQuotaRequestBody()); + + AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); + + expected = JSON::parse( + "{" + " \"type\": \"GET_QUOTA\"," + " \"get_quota\": {" + " \"status\": {" + " \"infos\": [" + " {" + " \"role\": \"role1\"," + " \"guarantee\": [" + " {" + " \"name\": \"cpus\"," + " \"type\": \"SCALAR\"," + " \"scalar\": {" + " \"value\": 1" + " }" + " }," + " {" + " \"name\": \"mem\"," + " \"type\": \"SCALAR\"," + " \"scalar\": {" + " \"value\": 1024" + " }" + " }" + " ]" + " }" + " ]," + " \"configs\": [" + " {" + " \"role\": \"role1\"," + " \"guarantees\": {" + " \"mem\": {" + " \"value\": 1024" + " }," + " \"cpus\": {" + " \"value\": 1" + " }" + " }," + " \"limits\": {" + " \"mem\": {" + " \"value\": 2048" + " }," + " \"cpus\": {" + " \"value\": 2" + " }" + " }" + " }" + " ]" + " }" + " }" + "}"); + ASSERT_SOME(expected); + + Try<JSON::Value> actual = JSON::parse(response->body); + ASSERT_SOME(actual); + + EXPECT_EQ(*expected, *(actual)); + + // Verify get "/quota". + response = process::http::get( + master.get()->pid, + "quota", + None(), + createBasicAuthHeaders(DEFAULT_CREDENTIAL)); + + AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); + + expected = JSON::parse( + "{" + " \"infos\": [" + " {" + " \"role\": \"role1\"," + " \"guarantee\": [" + " {" + " \"name\": \"cpus\"," + " \"type\": \"SCALAR\"," + " \"scalar\": {" + " \"value\": 1" + " }" + " }," + " {" + " \"name\": \"mem\"," + " \"type\": \"SCALAR\"," + " \"scalar\": {" + " \"value\": 1024" + " }" + " }" + " ]" + " }" + " ]," + " \"configs\": [" + " {" + " \"role\": \"role1\"," + " \"guarantees\": {" + " \"mem\": {" + " \"value\": 1024" + " }," + " \"cpus\": {" + " \"value\": 1" + " }" + " }," + " \"limits\": {" + " \"mem\": {" + " \"value\": 2048" + " }," + " \"cpus\": {" + " \"value\": 2" + " }" + " }" + " }" + " ]" + "}"); + ASSERT_SOME(expected); + + actual = JSON::parse(response->body); + ASSERT_SOME(actual); + + EXPECT_EQ(*expected, *(actual)); }
