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 2014/12/12 22:58:14 UTC
[4/6] mesos git commit: Removed Resources::extract in favor of
reservation-based helpers.
Removed Resources::extract in favor of reservation-based helpers.
Review: https://reviews.apache.org/r/28986
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/92fb5948
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/92fb5948
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/92fb5948
Branch: refs/heads/master
Commit: 92fb5948255a58a5680cbe3bcc2d78945d524480
Parents: d347d4f
Author: Benjamin Mahler <be...@gmail.com>
Authored: Thu Dec 11 17:26:16 2014 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Dec 12 13:39:13 2014 -0800
----------------------------------------------------------------------
include/mesos/resources.hpp | 6 ------
src/common/resources.cpp | 22 +++++++---------------
src/master/hierarchical_allocator_process.hpp | 4 ++--
src/tests/hierarchical_allocator_tests.cpp | 8 ++++----
4 files changed, 13 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fb5948/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index eae983a..296553a 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -117,12 +117,6 @@ public:
// Returns the unreserved resources.
Resources unreserved() const;
- // Returns all resources in this object that are marked with the
- // specified role.
- // TODO(bmahler): Remove this in favor of the more explicit
- // reservation-based methods above.
- Resources extract(const std::string& role) const;
-
// Returns a Resources object with the same amount of each resource
// type as these Resources, but with all Resource objects marked as
// the specified role.
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fb5948/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 03d40f8..9bf7ae9 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -477,20 +477,6 @@ Resources Resources::unreserved() const
}
-Resources Resources::extract(const string& role) const
-{
- Resources r;
-
- foreach (const Resource& resource, resources) {
- if (resource.role() == role) {
- r += resource;
- }
- }
-
- return r;
-}
-
-
Resources Resources::flatten(const string& role) const
{
Resources flattened;
@@ -514,7 +500,13 @@ public:
Resources apply(const Resources& resources) const
{
- return type == ANY? resources : resources.extract(role);
+ if (type == ANY) {
+ return resources;
+ } else if (role == "*") {
+ return resources.unreserved();
+ } else {
+ return resources.reserved(role);
+ }
}
private:
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fb5948/src/master/hierarchical_allocator_process.hpp
----------------------------------------------------------------------
diff --git a/src/master/hierarchical_allocator_process.hpp b/src/master/hierarchical_allocator_process.hpp
index 610fcd9..94995c0 100644
--- a/src/master/hierarchical_allocator_process.hpp
+++ b/src/master/hierarchical_allocator_process.hpp
@@ -711,10 +711,10 @@ HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::allocate(
FrameworkID frameworkId;
frameworkId.set_value(frameworkIdValue);
- Resources unreserved = slaves[slaveId].available.extract("*");
+ Resources unreserved = slaves[slaveId].available.unreserved();
Resources resources = unreserved;
if (role != "*") {
- resources += slaves[slaveId].available.extract(role);
+ resources += slaves[slaveId].available.reserved(role);
}
// If the resources are not allocatable, ignore.
http://git-wip-us.apache.org/repos/asf/mesos/blob/92fb5948/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 7e3dcd5..5e617ff 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -444,7 +444,7 @@ TEST_F(HierarchicalAllocatorTest, Reservations)
EXPECT_EQ(2u, allocation.get().resources.size());
EXPECT_TRUE(allocation.get().resources.contains(slave1.id()));
EXPECT_TRUE(allocation.get().resources.contains(slave2.id()));
- EXPECT_EQ(slave1.resources() + Resources(slave2.resources()).extract("*"),
+ EXPECT_EQ(slave1.resources() + Resources(slave2.resources()).unreserved(),
sum(allocation.get().resources.values()));
// framework2 should get all of its reserved resources on slave2.
@@ -456,7 +456,7 @@ TEST_F(HierarchicalAllocatorTest, Reservations)
EXPECT_EQ(framework2.id(), allocation.get().frameworkId);
EXPECT_EQ(1u, allocation.get().resources.size());
EXPECT_TRUE(allocation.get().resources.contains(slave2.id()));
- EXPECT_EQ(Resources(slave2.resources()).extract("role2"),
+ EXPECT_EQ(Resources(slave2.resources()).reserved("role2"),
sum(allocation.get().resources.values()));
}
@@ -487,7 +487,7 @@ TEST_F(HierarchicalAllocatorTest, RecoverResources)
EXPECT_EQ(slave.resources(), sum(allocation.get().resources.values()));
// Recover the reserved resources, expect them to be re-offered.
- Resources reserved = Resources(slave.resources()).extract("role1");
+ Resources reserved = Resources(slave.resources()).reserved("role1");
allocator->recoverResources(
allocation.get().frameworkId,
@@ -505,7 +505,7 @@ TEST_F(HierarchicalAllocatorTest, RecoverResources)
EXPECT_EQ(reserved, sum(allocation.get().resources.values()));
// Recover the unreserved resources, expect them to be re-offered.
- Resources unreserved = Resources(slave.resources()).extract("*");
+ Resources unreserved = Resources(slave.resources()).unreserved();
allocator->recoverResources(
allocation.get().frameworkId,