You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/01/30 01:18:44 UTC

[3/3] mesos git commit: Updated resources quantity stripping to strip AllocationInfo.

Updated resources quantity stripping to strip AllocationInfo.

Currently, `Resources::createStrippedScalarQuantity()` attempts to
create a notion of a "quantity" of resources. In order to do this,
all distinguishing metadata between resources of the same name are
stripped. This currently includes, disk metadata, reservation
metadata (only for dynamic reservations), and shared resource
metadata. To maintain the notion of a quantity, this patch also
strips the allocation metadata.

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


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

Branch: refs/heads/master
Commit: 9df201ff2729ff9ebd290e0e8a8a67b4e1de3998
Parents: aa0ea8f
Author: Benjamin Mahler <bm...@apache.org>
Authored: Sun Jan 22 14:34:18 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Sun Jan 29 17:12:30 2017 -0800

----------------------------------------------------------------------
 include/mesos/resources.hpp    | 10 +++++-----
 include/mesos/v1/resources.hpp | 10 +++++-----
 src/common/resources.cpp       |  1 +
 src/tests/resources_tests.cpp  | 15 +++++++++++++++
 src/v1/resources.cpp           |  1 +
 5 files changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9df201ff/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index f8c3e8c..73e44be 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -420,11 +420,11 @@ public:
   Resources flatten() const;
 
   // Returns a Resources object that contains all the scalar resources
-  // in this object, but with their ReservationInfo and DiskInfo
-  // omitted. Note that the `role` and RevocableInfo, if any, are
-  // preserved. Because we clear ReservationInfo but preserve `role`,
-  // this means that stripping a dynamically reserved resource makes
-  // it effectively statically reserved.
+  // in this object, but with their ReservationInfo, AllocationInfo,
+  // and DiskInfo omitted. Note that the `role` and RevocableInfo,
+  // if any, are preserved. Because we clear ReservationInfo but
+  // preserve `role`, this means that stripping a dynamically
+  // reserved resource makes it effectively statically reserved.
   //
   // This is intended for code that would like to aggregate together
   // Resource values without regard for metadata like whether the

http://git-wip-us.apache.org/repos/asf/mesos/blob/9df201ff/include/mesos/v1/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/resources.hpp b/include/mesos/v1/resources.hpp
index e8b586a..1913229 100644
--- a/include/mesos/v1/resources.hpp
+++ b/include/mesos/v1/resources.hpp
@@ -404,11 +404,11 @@ public:
   Resources flatten() const;
 
   // Returns a Resources object that contains all the scalar resources
-  // in this object, but with their ReservationInfo and DiskInfo
-  // omitted. Note that the `role` and RevocableInfo, if any, are
-  // preserved. Because we clear ReservationInfo but preserve `role`,
-  // this means that stripping a dynamically reserved resource makes
-  // it effectively statically reserved.
+  // in this object, but with their ReservationInfo, AllocationInfo,
+  // and DiskInfo omitted. Note that the `role` and RevocableInfo,
+  // if any, are preserved. Because we clear ReservationInfo but
+  // preserve `role`, this means that stripping a dynamically
+  // reserved resource makes it effectively statically reserved.
   //
   // This is intended for code that would like to aggregate together
   // Resource values without regard for metadata like whether the

http://git-wip-us.apache.org/repos/asf/mesos/blob/9df201ff/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index b3eae51..cdf6a84 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -1221,6 +1221,7 @@ Resources Resources::createStrippedScalarQuantity() const
   foreach (const Resource& resource, resources) {
     if (resource.type() == Value::SCALAR) {
       Resource scalar = resource;
+      scalar.clear_allocation_info();
       scalar.clear_reservation();
       scalar.clear_disk();
       scalar.clear_shared();

http://git-wip-us.apache.org/repos/asf/mesos/blob/9df201ff/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index e1ac164..33f0ee0 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -2284,6 +2284,21 @@ TEST(ResourcesOperationTest, StrippedResourcesVolume)
 }
 
 
+TEST(ResourcesOperationTest, StrippedResourcesAllocated)
+{
+  Resources allocated = Resources::parse("cpus:1;mem:512").get();
+  allocated.allocate("role");
+
+  Resources stripped = allocated.createStrippedScalarQuantity();
+
+  // Allocation info should be stripped when
+  // converting to a quantity.
+  foreach (const Resource& resource, stripped) {
+    EXPECT_FALSE(resource.has_allocation_info());
+  }
+}
+
+
 TEST(ResourcesOperationTest, StrippedResourcesReserved)
 {
   Resources unreserved = Resources::parse("cpus:1;mem:512").get();

http://git-wip-us.apache.org/repos/asf/mesos/blob/9df201ff/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index 5ba7b65..6fd8687 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -1210,6 +1210,7 @@ Resources Resources::createStrippedScalarQuantity() const
   foreach (const Resource& resource, resources) {
     if (resource.type() == Value::SCALAR) {
       Resource scalar = resource;
+      scalar.clear_allocation_info();
       scalar.clear_reservation();
       scalar.clear_disk();
       scalar.clear_shared();