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 59f32c8807c2d477fb36334addcc3ce4d49e5d8d Author: Meng Zhu <[email protected]> AuthorDate: Thu Mar 7 23:07:54 2019 -0800 Added validation for `QuotaConfig`. A `QuotaConfig` is valid if the following conditions are met: (1) The config has a valid non-"*" role. (2) Resource scalar values are non-negative and finite. (3) If both guarantees and limits are set for a particular resource, then guarantee <= limit for that resource. Review: https://reviews.apache.org/r/70161 --- src/master/quota.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/master/quota.hpp | 12 +++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/master/quota.cpp b/src/master/quota.cpp index 671626c..62b788f 100644 --- a/src/master/quota.cpp +++ b/src/master/quota.cpp @@ -27,10 +27,14 @@ #include <stout/option.hpp> #include <stout/set.hpp> +#include "common/resource_quantities.hpp" #include "common/resources_utils.hpp" +#include "common/validation.hpp" +using google::protobuf::Map; using google::protobuf::RepeatedPtrField; +using mesos::quota::QuotaConfig; using mesos::quota::QuotaInfo; using mesos::quota::QuotaRequest; @@ -292,6 +296,62 @@ Option<Error> validate(const QuotaRequest& request) return None(); } +Option<Error> validate(const QuotaConfig& config) +{ + if (!config.has_role()) { + return Error("'QuotaConfig.role' must be set"); + } + + // Check the provided role is valid. + Option<Error> error = roles::validate(config.role()); + if (error.isSome()) { + return Error("Invalid 'QuotaConfig.role': " + error->message); + } + + // Disallow quota for '*' role. + if (config.role() == "*") { + return Error( + "Invalid 'QuotaConfig.role': setting quota for the" + " default '*' role is not supported"); + } + + // Validate scalar values. + foreach (auto&& guarantee, config.guarantees()) { + Option<Error> error = + common::validation::validateInputScalarValue(guarantee.second.value()); + + if (error.isSome()) { + return Error( + "Invalid guarantee configuration {'" + guarantee.first + "': " + + stringify(guarantee.second) + "}: " + error->message); + } + } + + foreach (auto&& limit, config.limits()) { + Option<Error> error = + common::validation::validateInputScalarValue(limit.second.value()); + + if (error.isSome()) { + return Error( + "Invalid limit configuration {'" + limit.first + "': " + + stringify(limit.second) + "}: " + error->message); + } + } + + // Validate guarantees <= limits. + ResourceLimits limits{config.limits()}; + ResourceQuantities guarantees{config.guarantees()}; + + if (!limits.contains(guarantees)) { + return Error( + "'QuotaConfig.guarantees' " + stringify(config.guarantees()) + + " is not contained within the 'QuotaConfig.limits' " + + stringify(config.limits())); + } + + return None(); +} + } // namespace quota { } // namespace master { } // namespace internal { diff --git a/src/master/quota.hpp b/src/master/quota.hpp index 5cd2bb0..959e312 100644 --- a/src/master/quota.hpp +++ b/src/master/quota.hpp @@ -133,6 +133,18 @@ Option<Error> quotaInfo(const mesos::quota::QuotaInfo& quotaInfo); */ Option<Error> validate(const mesos::quota::QuotaRequest& request); +/** + * A `QuotaConfig` is valid if the following conditions are met: + * + * (1) The config has a valid non-"*" role. + * + * (2) Resource scalar values are non-negative and finite. + * + * (3) If both guarantees and limits are set for a particular + * resource, then guarantee <= limit for that resource. + */ +Option<Error> validate(const mesos::quota::QuotaConfig& config); + } // namespace quota { } // namespace master { } // namespace internal {
