Repository: mesos
Updated Branches:
  refs/heads/master acaed399f -> c4366d8b9


Explictly validated that all resources specified in reserve or unreserve 
operations are dynamically reserved.

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


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

Branch: refs/heads/master
Commit: bbd0582c86e10689ccc078ea6253205436a0890b
Parents: acaed39
Author: Vinod Kone <[email protected]>
Authored: Fri May 15 15:46:05 2015 -0700
Committer: Vinod Kone <[email protected]>
Committed: Fri May 15 16:38:13 2015 -0700

----------------------------------------------------------------------
 src/master/validation.cpp | 35 ++++++++++-------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bbd0582c/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index c3e96ae..b53608f 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -53,21 +53,6 @@ static bool invalid(char c)
 
 namespace resource {
 
-// Validates that all the given resources are dynamically-reserved.
-Option<Error> validateDynamicReservation(
-    const RepeatedPtrField<Resource>& resources)
-{
-  foreach (const Resource& resource, resources) {
-    if (!resource.has_reservation()) {
-      return Error(
-          "Resource " + stringify(resource) +
-          " does not have the 'reservation' field set");
-    }
-  }
-
-  return None();
-}
-
 
 // Validates the DiskInfos specified in the given resources (if
 // exist). Returns error if any DiskInfo is found invalid or
@@ -558,16 +543,16 @@ Option<Error> validate(
     return Error("Invalid resources: " + error.get().message);
   }
 
-  error = resource::validateDynamicReservation(reserve.resources());
-  if (error.isSome()) {
-    return Error("Not a dynamic reservation: " + error.get().message);
-  }
-
   if (principal.isNone()) {
     return Error("A framework without a principal cannot reserve resources.");
   }
 
   foreach (const Resource& resource, reserve.resources()) {
+    if (!Resources::isDynamicallyReserved(resource)) {
+      return Error(
+          "Resource " + stringify(resource) + " is not dynamically reserved");
+    }
+
     if (resource.role() != role) {
       return Error(
           "The reserved resource's role '" + resource.role() +
@@ -605,11 +590,6 @@ Option<Error> validate(
     return Error("Invalid resources: " + error.get().message);
   }
 
-  error = resource::validateDynamicReservation(unreserve.resources());
-  if (error.isSome()) {
-    return Error("Not a dynamic reservation: " + error.get().message);
-  }
-
   if (!hasPrincipal) {
     return Error("A framework without a principal cannot unreserve 
resources.");
   }
@@ -621,6 +601,11 @@ Option<Error> validate(
   // any 'principal' to unreserve any other 'principal's resources.
 
   foreach (const Resource& resource, unreserve.resources()) {
+    if (!Resources::isDynamicallyReserved(resource)) {
+      return Error(
+          "Resource " + stringify(resource) + " is not dynamically reserved");
+    }
+
     if (Resources::isPersistentVolume(resource)) {
       return Error(
           "A dynamically reserved persistent volume " +

Reply via email to