mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mp...@apache.org
Subject [2/2] mesos git commit: Resources: Added `toUnreserved()` and `(push|pop)Reservation`.
Date Sat, 17 Jun 2017 09:18:53 GMT
Resources: Added `toUnreserved()` and `(push|pop)Reservation`.

This patches introduces utilities `toUnreserved`, `pushReservation` and
`popReservation`. They are intended to replace the current `flatten`.
We'll switch over to use them once the 'post-reservation-refinement'
format is used for `Resources`.

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


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

Branch: refs/heads/master
Commit: 4f16535704ac6f8417dfcef6c6347658114db97e
Parents: fe6a3eb
Author: Michael Park <mpark@apache.org>
Authored: Wed Jun 14 21:28:04 2017 -0700
Committer: Michael Park <mpark@apache.org>
Committed: Sat Jun 17 02:00:52 2017 -0700

----------------------------------------------------------------------
 include/mesos/resources.hpp    | 17 +++++++++++++++
 include/mesos/v1/resources.hpp | 17 +++++++++++++++
 src/common/resources.cpp       | 42 +++++++++++++++++++++++++++++++++++++
 src/v1/resources.cpp           | 42 +++++++++++++++++++++++++++++++++++++
 4 files changed, 118 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4f165357/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index 2b55847..d380a59 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -424,14 +424,31 @@ public:
   // 'reservation' field is cleared.
   // Returns an Error when the role is invalid or the reservation
   // is set when the role is '*'.
+  //
+  // TODO(mpark): Switch over to using `(push|pop)Reservation` and remove this
+  //              once we change to the 'post-reservation-refinement' format.
   Try<Resources> flatten(
       const std::string& role,
       const Option<Resource::ReservationInfo>& reservation = None()) const;
 
   // Equivalent to `flatten("*")` except it returns a Resources directly
   // because the result is always a valid in this case.
+  //
+  // TODO(mpark): Switch over to using `toUnreserved` and remove this once
+  //              we change to the 'post-reservation-refinement' format.
   Resources flatten() const;
 
+  // Returns a `Resources` object with the new reservation added to the back.
+  // The new reservation must be a valid refinement of the current reservation.
+  Resources pushReservation(const Resource::ReservationInfo& reservation) const;
+
+  // Returns a `Resources` object with the last reservation removed.
+  // Every resource in `Resources` must have `resource.reservations_size() > 0`.
+  Resources popReservation() const;
+
+  // Returns a `Resources` object with all of the reservations removed.
+  Resources toUnreserved() const;
+
   // Returns a Resources object that contains all the scalar resources
   // in this object, but with their AllocationInfo, ReservationInfo,
   // DiskInfo, and SharedInfo omitted. The `role` and RevocableInfo,

http://git-wip-us.apache.org/repos/asf/mesos/blob/4f165357/include/mesos/v1/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/resources.hpp b/include/mesos/v1/resources.hpp
index 7c6e856..66c2b21 100644
--- a/include/mesos/v1/resources.hpp
+++ b/include/mesos/v1/resources.hpp
@@ -424,14 +424,31 @@ public:
   // 'reservation' field is cleared.
   // Returns an Error when the role is invalid or the reservation
   // is set when the role is '*'.
+  //
+  // TODO(mpark): Switch over to using `(push|pop)Reservation` and remove this
+  //              once we change to the 'post-reservation-refinement' format.
   Try<Resources> flatten(
       const std::string& role,
       const Option<Resource::ReservationInfo>& reservation = None()) const;
 
   // Equivalent to `flatten("*")` except it returns a Resources directly
   // because the result is always a valid in this case.
+  //
+  // TODO(mpark): Switch over to using `toUnreserved` and remove this once
+  //              we change to the 'post-reservation-refinement' format.
   Resources flatten() const;
 
+  // Returns a `Resources` object with the new reservation added to the back.
+  // The new reservation must be a valid refinement of the current reservation.
+  Resources pushReservation(const Resource::ReservationInfo& reservation) const;
+
+  // Returns a `Resources` object with the last reservation removed.
+  // Every resource in `Resources` must have `resource.reservations_size() > 0`.
+  Resources popReservation() const;
+
+  // Returns a `Resources` object with all of the reservations removed.
+  Resources toUnreserved() const;
+
   // Returns a Resources object that contains all the scalar resources
   // in this object, but with their AllocationInfo, ReservationInfo,
   // DiskInfo, and SharedInfo omitted. The `role` and RevocableInfo,

http://git-wip-us.apache.org/repos/asf/mesos/blob/4f165357/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 7672938..f12ab97 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -1330,6 +1330,48 @@ Resources Resources::flatten() const
 }
 
 
+Resources Resources::pushReservation(
+    const Resource::ReservationInfo& reservation) const
+{
+  Resources result;
+
+  foreach (Resource_ resource_, *this) {
+    resource_.resource.add_reservations()->CopyFrom(reservation);
+    CHECK_NONE(Resources::validate(resource_.resource));
+    result.add(resource_);
+  }
+
+  return result;
+}
+
+
+Resources Resources::popReservation() const
+{
+  Resources result;
+
+  foreach (Resource_ resource_, resources) {
+    CHECK_GE(resource_.resource.reservations_size(), 0);
+    resource_.resource.mutable_reservations()->RemoveLast();
+    result.add(resource_);
+  }
+
+  return result;
+}
+
+
+Resources Resources::toUnreserved() const
+{
+  Resources result;
+
+  foreach (Resource_ resource_, *this) {
+    resource_.resource.clear_reservations();
+    result.add(resource_);
+  }
+
+  return result;
+}
+
+
 Resources Resources::createStrippedScalarQuantity() const
 {
   Resources stripped;

http://git-wip-us.apache.org/repos/asf/mesos/blob/4f165357/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index 5558805..30644ee 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -1332,6 +1332,48 @@ Resources Resources::flatten() const
 }
 
 
+Resources Resources::pushReservation(
+    const Resource::ReservationInfo& reservation) const
+{
+  Resources result;
+
+  foreach (Resource_ resource_, *this) {
+    resource_.resource.add_reservations()->CopyFrom(reservation);
+    CHECK_NONE(Resources::validate(resource_.resource));
+    result.add(resource_);
+  }
+
+  return result;
+}
+
+
+Resources Resources::popReservation() const
+{
+  Resources result;
+
+  foreach (Resource_ resource_, resources) {
+    CHECK_GE(resource_.resource.reservations_size(), 0);
+    resource_.resource.mutable_reservations()->RemoveLast();
+    result.add(resource_);
+  }
+
+  return result;
+}
+
+
+Resources Resources::toUnreserved() const
+{
+  Resources result;
+
+  foreach (Resource_ resource_, *this) {
+    resource_.resource.clear_reservations();
+    result.add(resource_);
+  }
+
+  return result;
+}
+
+
 Resources Resources::createStrippedScalarQuantity() const
 {
   Resources stripped;


Mime
View raw message