mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mp...@apache.org
Subject [05/21] mesos git commit: Resources: Adjusted the utilities to the new resource format [5/20].
Date Tue, 20 Jun 2017 09:46:41 GMT
Resources: Adjusted the utilities to the new resource format [5/20].

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


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

Branch: refs/heads/master
Commit: 0bae26707645f515317b3860b22df822dd85e718
Parents: 9ac264b
Author: Michael Park <mpark@apache.org>
Authored: Sun Jun 18 22:04:29 2017 -0700
Committer: Michael Park <mpark@apache.org>
Committed: Tue Jun 20 02:30:25 2017 -0700

----------------------------------------------------------------------
 src/common/resources.cpp       | 25 ++++++++++++++++++++-----
 src/common/resources_utils.cpp | 10 ++++++++--
 src/v1/resources.cpp           | 25 ++++++++++++++++++++-----
 3 files changed, 48 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0bae2670/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 22bc24e..c088ee2 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -1510,7 +1510,18 @@ Resources Resources::createStrippedScalarQuantity() const
       Resource scalar = resource;
       scalar.clear_provider_id();
       scalar.clear_allocation_info();
-      scalar.clear_reservation();
+
+      // We collapse the stack of reservations here to a single `STATIC`
+      // reservation in order to maintain existing behavior of ignoring
+      // the reservation type, and keeping the reservation role.
+      if (Resources::isReserved(scalar)) {
+        Resource::ReservationInfo collapsedReservation;
+        collapsedReservation.set_type(Resource::ReservationInfo::STATIC);
+        collapsedReservation.set_role(Resources::reservationRole(scalar));
+        scalar.clear_reservations();
+        scalar.add_reservations()->CopyFrom(collapsedReservation);
+      }
+
       scalar.clear_disk();
       scalar.clear_shared();
       stripped.add(scalar);
@@ -1562,8 +1573,10 @@ Try<Resources> Resources::apply(const Offer::Operation& operation)
const
       foreach (const Resource& reserved, operation.reserve().resources()) {
         if (!Resources::isReserved(reserved)) {
           return Error("Invalid RESERVE Operation: Resource must be reserved");
-        } else if (!reserved.has_reservation()) {
-          return Error("Invalid RESERVE Operation: Missing 'reservation'");
+        } else if (!Resources::isDynamicallyReserved(reserved)) {
+          return Error(
+              "Invalid RESERVE Operation: Resource must be"
+              " dynamically reserved");
         }
 
         Resources unreserved = Resources(reserved).flatten();
@@ -1588,8 +1601,10 @@ Try<Resources> Resources::apply(const Offer::Operation& operation)
const
       foreach (const Resource& reserved, operation.unreserve().resources()) {
         if (!Resources::isReserved(reserved)) {
           return Error("Invalid UNRESERVE Operation: Resource is not reserved");
-        } else if (!reserved.has_reservation()) {
-          return Error("Invalid UNRESERVE Operation: Missing 'reservation'");
+        } else if (!Resources::isDynamicallyReserved(reserved)) {
+          return Error(
+              "Invalid UNRESERVE Operation: Resource is not"
+              " dynamically reserved");
         }
 
         if (!result.contains(reserved)) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/0bae2670/src/common/resources_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources_utils.cpp b/src/common/resources_utils.cpp
index 19c89bf..4671477 100644
--- a/src/common/resources_utils.cpp
+++ b/src/common/resources_utils.cpp
@@ -52,9 +52,15 @@ Try<Resources> applyCheckpointedResources(
 
     Resource stripped = resource;
 
+    // Since only unreserved and statically reserved resources can be specified
+    // on the agent, we strip away all of the dynamic reservations here to
+    // deduce the agent resources on which to apply the checkpointed resources.
     if (Resources::isDynamicallyReserved(resource)) {
-      stripped.set_role("*");
-      stripped.clear_reservation();
+      Resource::ReservationInfo reservation = stripped.reservations(0);
+      stripped.clear_reservations();
+      if (reservation.type() == Resource::ReservationInfo::STATIC) {
+        stripped.add_reservations()->CopyFrom(reservation);
+      }
     }
 
     // Strip persistence and volume from the disk info so that we can

http://git-wip-us.apache.org/repos/asf/mesos/blob/0bae2670/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index d03577f..0fd8eac 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -1512,7 +1512,18 @@ Resources Resources::createStrippedScalarQuantity() const
       Resource scalar = resource;
       scalar.clear_provider_id();
       scalar.clear_allocation_info();
-      scalar.clear_reservation();
+
+      // We collapse the stack of reservations here to a single `STATIC`
+      // reservation in order to maintain existing behavior of ignoring
+      // the reservation type, and keeping the reservation role.
+      if (Resources::isReserved(scalar)) {
+        Resource::ReservationInfo collapsedReservation;
+        collapsedReservation.set_type(Resource::ReservationInfo::STATIC);
+        collapsedReservation.set_role(Resources::reservationRole(scalar));
+        scalar.clear_reservations();
+        scalar.add_reservations()->CopyFrom(collapsedReservation);
+      }
+
       scalar.clear_disk();
       scalar.clear_shared();
       stripped.add(scalar);
@@ -1564,8 +1575,10 @@ Try<Resources> Resources::apply(const Offer::Operation& operation)
const
       foreach (const Resource& reserved, operation.reserve().resources()) {
         if (!Resources::isReserved(reserved)) {
           return Error("Invalid RESERVE Operation: Resource must be reserved");
-        } else if (!reserved.has_reservation()) {
-          return Error("Invalid RESERVE Operation: Missing 'reservation'");
+        } else if (!Resources::isDynamicallyReserved(reserved)) {
+          return Error(
+              "Invalid RESERVE Operation: Resource must be"
+              " dynamically reserved");
         }
 
         Resources unreserved = Resources(reserved).flatten();
@@ -1590,8 +1603,10 @@ Try<Resources> Resources::apply(const Offer::Operation& operation)
const
       foreach (const Resource& reserved, operation.unreserve().resources()) {
         if (!Resources::isReserved(reserved)) {
           return Error("Invalid UNRESERVE Operation: Resource is not reserved");
-        } else if (!reserved.has_reservation()) {
-          return Error("Invalid UNRESERVE Operation: Missing 'reservation'");
+        } else if (!Resources::isDynamicallyReserved(reserved)) {
+          return Error(
+              "Invalid UNRESERVE Operation: Resource is not"
+              " dynamically reserved");
         }
 
         if (!result.contains(reserved)) {


Mime
View raw message