You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/12/22 21:06:50 UTC
[3/3] mesos git commit: Quota: Cleaned up HTTP handling code and
tests.
Quota: Cleaned up HTTP handling code and tests.
Define a variable earlier in the handler for clarity; add consts; add
and re-order using directive where appropriate.
Review: https://reviews.apache.org/r/41603/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/92e8aee5
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/92e8aee5
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/92e8aee5
Branch: refs/heads/master
Commit: 92e8aee580d9797acaf3cd80f26ba5b6415f2c9b
Parents: 3cfe880
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Tue Dec 22 14:59:23 2015 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Tue Dec 22 15:06:30 2015 -0500
----------------------------------------------------------------------
src/master/quota_handler.cpp | 32 ++++++++++++++++++--------------
src/tests/master_quota_tests.cpp | 12 ++++++------
2 files changed, 24 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/92e8aee5/src/master/quota_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index 8a6e5e3..1d84ef5 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -18,6 +18,8 @@
#include <vector>
+#include <google/protobuf/repeated_field.h>
+
#include <mesos/resources.hpp>
#include <mesos/quota/quota.hpp>
@@ -29,6 +31,7 @@
#include <stout/json.hpp>
#include <stout/protobuf.hpp>
+#include <stout/stringify.hpp>
#include <stout/strings.hpp>
#include <stout/utils.hpp>
@@ -39,8 +42,7 @@
namespace http = process::http;
-using std::string;
-using std::vector;
+using google::protobuf::RepeatedPtrField;
using http::Accepted;
using http::BadRequest;
@@ -48,17 +50,20 @@ using http::Conflict;
using http::OK;
using http::Unauthorized;
+using mesos::quota::QuotaInfo;
+
using process::Future;
using process::Owned;
-using mesos::quota::QuotaInfo;
+using std::string;
+using std::vector;
+
namespace mesos {
namespace internal {
namespace master {
// Creates a `QuotaInfo` protobuf from the quota request.
-static Try<QuotaInfo> createQuotaInfo(
- google::protobuf::RepeatedPtrField<Resource> resources)
+static Try<QuotaInfo> createQuotaInfo(RepeatedPtrField<Resource> resources)
{
VLOG(1) << "Constructing QuotaInfo from resources protobuf";
@@ -276,9 +281,8 @@ Future<http::Response> Master::QuotaHandler::set(
}
// Create protobuf representation of resources.
- Try<google::protobuf::RepeatedPtrField<Resource>> resources =
- ::protobuf::parse<google::protobuf::RepeatedPtrField<Resource>>(
- resourcesJSON.get());
+ Try<RepeatedPtrField<Resource>> resources =
+ ::protobuf::parse<RepeatedPtrField<Resource>>(resourcesJSON.get());
if (resources.isError()) {
return BadRequest(
@@ -294,8 +298,10 @@ Future<http::Response> Master::QuotaHandler::set(
request.body + "': " + create.error());
}
+ const QuotaInfo& quotaInfo = create.get();
+
// Check that the `QuotaInfo` is a valid quota request.
- Try<Nothing> validate = quota::validation::quotaInfo(create.get());
+ Try<Nothing> validate = quota::validation::quotaInfo(quotaInfo);
if (validate.isError()) {
return BadRequest(
"Failed to validate set quota request JSON '" + request.body + "': " +
@@ -303,22 +309,20 @@ Future<http::Response> Master::QuotaHandler::set(
}
// Check that the role is on the role whitelist, if it exists.
- if (!master->isWhitelistedRole(create.get().role())) {
+ if (!master->isWhitelistedRole(quotaInfo.role())) {
return BadRequest(
"Failed to validate set quota request JSON '" + request.body +
- "': Unknown role '" + create.get().role() + "'");
+ "': Unknown role '" + quotaInfo.role() + "'");
}
// Check that we are not updating an existing quota.
// TODO(joerg84): Update error message once quota update is in place.
- if (master->quotas.contains(create.get().role())) {
+ if (master->quotas.contains(quotaInfo.role())) {
return BadRequest(
"Failed to validate set quota request JSON '" + request.body +
"': Can not set quota for a role that already has quota");
}
- const QuotaInfo& quotaInfo = create.get();
-
// The force flag can be used to overwrite the `capacityHeuristic` check.
Result<JSON::Boolean> force = parse.get().find<JSON::Boolean>("force");
if (force.isError()) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/92e8aee5/src/tests/master_quota_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index 42a91e7..2f1bc3a 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -41,9 +41,6 @@
#include "tests/allocator.hpp"
#include "tests/mesos.hpp"
-using std::string;
-using std::vector;
-
using google::protobuf::RepeatedPtrField;
using mesos::internal::master::Master;
@@ -61,6 +58,9 @@ using process::http::OK;
using process::http::Response;
using process::http::Unauthorized;
+using std::string;
+using std::vector;
+
using testing::_;
using testing::DoAll;
using testing::Eq;
@@ -197,7 +197,7 @@ TEST_F(MasterQuotaTest, SetInvalidRequest)
// Tests whether a quota request with invalid JSON fails.
{
- string badRequest =
+ const string badRequest =
"{"
" invalidJson"
"}";
@@ -210,7 +210,7 @@ TEST_F(MasterQuotaTest, SetInvalidRequest)
// Tests whether a quota request with missing 'resource' field fails.
{
- string badRequest =
+ const string badRequest =
"{"
" \"unknownField\":\"unknownValue\""
"}";
@@ -223,7 +223,7 @@ TEST_F(MasterQuotaTest, SetInvalidRequest)
// Tests whether a quota request with invalid resources fails.
{
- string badRequest =
+ const string badRequest =
"{"
" \"resources\":"
" ["