Minor cleanup for quota validation code.

Review: https://reviews.apache.org/r/57165/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2d7f2848
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2d7f2848
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2d7f2848

Branch: refs/heads/master
Commit: 2d7f284868b90cf9f36c39ede1af63970fde6f52
Parents: e9cd708
Author: Neil Conway <[email protected]>
Authored: Thu Mar 9 11:47:25 2017 -0500
Committer: Neil Conway <[email protected]>
Committed: Thu Mar 9 11:48:08 2017 -0500

----------------------------------------------------------------------
 src/master/quota.cpp         | 24 +++++++++---------------
 src/master/quota_handler.cpp |  2 +-
 2 files changed, 10 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2d7f2848/src/master/quota.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota.cpp b/src/master/quota.cpp
index 847ec06..3e0d280 100644
--- a/src/master/quota.cpp
+++ b/src/master/quota.cpp
@@ -110,15 +110,10 @@ Option<Error> quotaInfo(const QuotaInfo& quotaInfo)
     return Error("QuotaInfo must specify a role");
   }
 
-  if (quotaInfo.role().empty()) {
-    return Error("QuotaInfo must specify a non-empty role");
-  }
-
   // Check the provided role is valid.
   Option<Error> roleError = roles::validate(quotaInfo.role());
   if (roleError.isSome()) {
-    return Error(
-        "QuotaInfo with invalid role: " + roleError.get().message);
+    return Error("QuotaInfo with invalid role: " + roleError->message);
   }
 
   // Disallow quota for '*' role.
@@ -132,7 +127,7 @@ Option<Error> quotaInfo(const QuotaInfo& quotaInfo)
   // only way that we offer non-revocable resources. Setting quota
   // with an empty guarantee would mean the role is not entitled to
   // get non-revocable offers.
-  if (quotaInfo.guarantee().size() == 0) {
+  if (quotaInfo.guarantee().empty()) {
     return Error("QuotaInfo with empty 'guarantee'");
   }
 
@@ -141,25 +136,24 @@ Option<Error> quotaInfo(const QuotaInfo& quotaInfo)
     Option<Error> resourceError = Resources::validate(resource);
     if (resourceError.isSome()) {
       return Error(
-          "QuotaInfo with invalid resource: " + resourceError.get().message);
+          "QuotaInfo with invalid resource: " + resourceError->message);
     }
 
-    // Check that `resource` does not contain non-relevant fields for quota.
+    // Check that `resource` does not contain fields that are
+    // irrelevant for quota.
 
     if (resource.has_reservation()) {
-      return Error("QuotaInfo may not contain ReservationInfo");
+      return Error("QuotaInfo must not contain ReservationInfo");
     }
     if (resource.has_disk()) {
-      return Error("QuotaInfo may not contain DiskInfo");
+      return Error("QuotaInfo must not contain DiskInfo");
     }
     if (resource.has_revocable()) {
-      return Error("QuotaInfo may not contain RevocableInfo");
+      return Error("QuotaInfo must not contain RevocableInfo");
     }
 
-    // Check that the `Resource` is scalar.
     if (resource.type() != Value::SCALAR) {
-      return Error(
-          "QuotaInfo may not include non-scalar resources");
+      return Error("QuotaInfo must not include non-scalar resources");
     }
 
     // Check that the role is either unset or default.

http://git-wip-us.apache.org/repos/asf/mesos/blob/2d7f2848/src/master/quota_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index ce1f064..36ea1ac 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -290,7 +290,7 @@ Future<QuotaStatus> Master::QuotaHandler::_status(
         if (authorized) {
           status.add_infos()->CopyFrom(*quotaInfoIt);
         }
-      ++quotaInfoIt;
+        ++quotaInfoIt;
       }
 
       return status;

Reply via email to