Repository: mesos Updated Branches: refs/heads/master 75f65bd33 -> 7d9a5b564
Updated error messages in weights handler. While writing log or error messages we adhere the following style: - No period at the end (there are exceptions though, e.g., one is when constructing request responses. - When splitting a string over multiple lines, put a space at the beginning of the following line in contrast to the end of the previous line. Review: https://reviews.apache.org/r/45863/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e10814f2 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e10814f2 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e10814f2 Branch: refs/heads/master Commit: e10814f27edd8b3c1b71a4a31ce22380778c3ee3 Parents: 75f65bd Author: Alexander Rukletsov <ruklet...@gmail.com> Authored: Mon Apr 11 17:21:39 2016 +0200 Committer: Alexander Rukletsov <al...@apache.org> Committed: Mon Apr 11 17:21:39 2016 +0200 ---------------------------------------------------------------------- src/master/weights_handler.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/e10814f2/src/master/weights_handler.cpp ---------------------------------------------------------------------- diff --git a/src/master/weights_handler.cpp b/src/master/weights_handler.cpp index 10a1fbc..07cc992 100644 --- a/src/master/weights_handler.cpp +++ b/src/master/weights_handler.cpp @@ -18,6 +18,8 @@ #include <list> +#include <mesos/roles.hpp> + #include <mesos/authorizer/authorizer.hpp> #include <process/collect.hpp> @@ -85,8 +87,8 @@ Future<http::Response> Master::WeightsHandler::update( Try<JSON::Array> parse = JSON::parse<JSON::Array>(request.body); if (parse.isError()) { return BadRequest( - "Failed to parse update request JSON ('" + request.body + "': " + - parse.error()); + "Failed to parse update weights request JSON ('" + + request.body + "'): " + parse.error()); } // Create Protobuf representation of weights. @@ -104,24 +106,27 @@ Future<http::Response> Master::WeightsHandler::update( for (WeightInfo& weightInfo : weightInfos.get()) { string role = strings::trim(weightInfo.role()); - if (role.empty()) { + Option<Error> roleError = roles::validate(role); + if (roleError.isSome()) { return BadRequest( - "Role cannot be empty for weight '" + - stringify(weightInfo.weight()) + "'"); + "Failed to validate update weights request JSON: Invalid role '" + + role + "': " + roleError.get().message); } - if (weightInfo.weight() <= 0) { + // Check that the role is on the role whitelist, if it exists. + if (!master->isWhitelistedRole(role)) { return BadRequest( - "Invalid weight '" + stringify(weightInfo.weight()) + - "' for role '" + role + "'. Weights must be positive."); + "Failed to validate update weights request JSON: Unknown role '" + + role + "'"); } - if (!master->isWhitelistedRole(role)) { + if (weightInfo.weight() <= 0) { return BadRequest( - "Invalid role: '" + role + "', which must exist in the static " + - "list of roles, specified when the master is started" + - " (via the --roles flag)."); + "Failed to validate update weights request JSON for role '" + + role + "': Invalid weight '" + stringify(weightInfo.weight()) + + "': Weights must be positive"); } + weightInfo.set_role(role); validatedWeightInfos.push_back(weightInfo); roles.push_back(role);