Cleaned up logs and ordering in "quota_handler.cpp". Rearrange function definitions so that they follow the common sequence for quota actions: status (GET) - > set (POST) -> remove (DELETE). Use "set" instead of "request" in log entry to avoid confusion.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6e4f70b7 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6e4f70b7 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6e4f70b7 Branch: refs/heads/master Commit: 6e4f70b7ac7403840d2fad4e94f0eeffa8b72d94 Parents: 8e616a0 Author: Alexander Rukletsov <al...@apache.org> Authored: Tue May 17 14:39:03 2016 +0200 Committer: Alexander Rukletsov <al...@apache.org> Committed: Tue May 17 14:45:08 2016 +0200 ---------------------------------------------------------------------- src/master/quota_handler.cpp | 134 +++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/6e4f70b7/src/master/quota_handler.cpp ---------------------------------------------------------------------- diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp index 4e81716..86a2e17 100644 --- a/src/master/quota_handler.cpp +++ b/src/master/quota_handler.cpp @@ -205,6 +205,69 @@ void Master::QuotaHandler::rescindOffers(const QuotaInfo& request) const } +Future<http::Response> Master::QuotaHandler::status( + const http::Request& request, + const Option<string>& principal) const +{ + VLOG(1) << "Handling quota status request"; + + // Check that the request type is GET which is guaranteed by the master. + CHECK_EQ("GET", request.method); + + // Quotas can be updated during preparation of the response. + // Copy current view of the collection to avoid conflicts. + vector<QuotaInfo> quotaInfos; + quotaInfos.reserve(master->quotas.size()); + + foreachvalue (const Quota& quota, master->quotas) { + quotaInfos.push_back(quota.info); + } + + // Create a list of authorization actions for each role we may return. + // + // TODO(alexr): Use an authorization filter here once they are available. + list<Future<bool>> authorizedRoles; + foreach (const QuotaInfo& info, quotaInfos) { + authorizedRoles.push_back(authorizeGetQuota(principal, info.role())); + } + + return process::collect(authorizedRoles) + .then(defer( + master->self(), + [=](const list<bool>& authorizedRolesCollected) + -> Future<http::Response> { + return _status(request, quotaInfos, authorizedRolesCollected); + })); +} + + +Future<http::Response> Master::QuotaHandler::_status( + const http::Request& request, + const vector<QuotaInfo>& quotaInfos, + const list<bool>& authorizedRoles) const +{ + CHECK(quotaInfos.size() == authorizedRoles.size()); + + QuotaStatus status; + status.mutable_infos()->Reserve(static_cast<int>(quotaInfos.size())); + + // Create an entry (including role and resources) for each quota, + // except those filtered out based on the authorizer's response. + // + // NOTE: This error-prone code will be removed with + // the introduction of authorization filters. + auto quotaInfoIt = quotaInfos.begin(); + foreach (const bool& authorized, authorizedRoles) { + if (authorized) { + status.add_infos()->CopyFrom(*quotaInfoIt); + } + ++quotaInfoIt; + } + + return OK(JSON::protobuf(status), request.url.query.get("jsonp")); +} + + Future<http::Response> Master::QuotaHandler::set( const http::Request& request, const Option<string>& principal) const @@ -416,69 +479,6 @@ Future<http::Response> Master::QuotaHandler::_remove(const string& role) const } -Future<http::Response> Master::QuotaHandler::status( - const http::Request& request, - const Option<string>& principal) const -{ - VLOG(1) << "Handling quota status request"; - - // Check that the request type is GET which is guaranteed by the master. - CHECK_EQ("GET", request.method); - - // Quotas can be updated during preparation of the response. - // Copy current view of the collection to avoid conflicts. - vector<QuotaInfo> quotaInfos; - quotaInfos.reserve(master->quotas.size()); - - foreachvalue (const Quota& quota, master->quotas) { - quotaInfos.push_back(quota.info); - } - - // Create a list of authorization actions for each role we may return. - // - // TODO(alexr): Use an authorization filter here once they are available. - list<Future<bool>> authorizedRoles; - foreach (const QuotaInfo& info, quotaInfos) { - authorizedRoles.push_back(authorizeGetQuota(principal, info.role())); - } - - return process::collect(authorizedRoles) - .then(defer( - master->self(), - [=](const list<bool>& authorizedRolesCollected) - -> Future<http::Response> { - return _status(request, quotaInfos, authorizedRolesCollected); - })); -} - - -Future<http::Response> Master::QuotaHandler::_status( - const http::Request& request, - const vector<QuotaInfo>& quotaInfos, - const list<bool>& authorizedRoles) const -{ - CHECK(quotaInfos.size() == authorizedRoles.size()); - - QuotaStatus status; - status.mutable_infos()->Reserve(static_cast<int>(quotaInfos.size())); - - // Create an entry (including role and resources) for each quota, - // except those filtered out based on the authorizer's response. - // - // NOTE: This error-prone code will be removed with - // the introduction of authorization filters. - auto quotaInfoIt = quotaInfos.begin(); - foreach (const bool& authorized, authorizedRoles) { - if (authorized) { - status.add_infos()->CopyFrom(*quotaInfoIt); - } - ++quotaInfoIt; - } - - return OK(JSON::protobuf(status), request.url.query.get("jsonp")); -} - - Future<bool> Master::QuotaHandler::authorizeGetQuota( const Option<string>& principal, const string& role) const @@ -489,8 +489,7 @@ Future<bool> Master::QuotaHandler::authorizeGetQuota( LOG(INFO) << "Authorizing principal '" << (principal.isSome() ? principal.get() : "ANY") - << "' to get quota for role " - << role << "."; + << "' to get quota for role '" << role << "'"; authorization::Request request; request.set_action(authorization::GET_QUOTA_WITH_ROLE); @@ -515,7 +514,7 @@ Future<bool> Master::QuotaHandler::authorizeSetQuota( LOG(INFO) << "Authorizing principal '" << (principal.isSome() ? principal.get() : "ANY") - << "' to request quota for role '" << role << "'"; + << "' to set quota for role '" << role << "'"; authorization::Request request; request.set_action(authorization::SET_QUOTA_WITH_ROLE); @@ -541,8 +540,7 @@ Future<bool> Master::QuotaHandler::authorizeRemoveQuota( LOG(INFO) << "Authorizing principal '" << (requestPrincipal.isSome() ? requestPrincipal.get() : "ANY") << "' to remove quota set by '" - << (quotaPrincipal.isSome() ? quotaPrincipal.get() : "ANY") - << "'"; + << (quotaPrincipal.isSome() ? quotaPrincipal.get() : "ANY") << "'"; authorization::Request request; request.set_action(authorization::DESTROY_QUOTA_WITH_PRINCIPAL);