Repository: mesos Updated Branches: refs/heads/master 6bb460d1c -> f15d37ce5
Filter revocable resources. Review: https://reviews.apache.org/r/34308 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f15d37ce Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f15d37ce Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f15d37ce Branch: refs/heads/master Commit: f15d37ce5727d01a4ed215a40670f2dfc8042179 Parents: 6bb460d Author: Ian Downes <[email protected]> Authored: Thu May 21 15:36:15 2015 -0700 Committer: Vinod Kone <[email protected]> Committed: Thu May 21 15:41:19 2015 -0700 ---------------------------------------------------------------------- include/mesos/resources.hpp | 3 +++ src/common/resources.cpp | 6 ++++++ src/tests/resources_tests.cpp | 13 +++++++++++++ 3 files changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/f15d37ce/include/mesos/resources.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp index 1e98c13..6feb1be 100644 --- a/include/mesos/resources.hpp +++ b/include/mesos/resources.hpp @@ -189,6 +189,9 @@ public: // Returns the persistent volumes. Resources persistentVolumes() const; + // Returns the revocable resources. + Resources revocable() 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, reservation) pair. This is used to cross http://git-wip-us.apache.org/repos/asf/mesos/blob/f15d37ce/src/common/resources.cpp ---------------------------------------------------------------------- diff --git a/src/common/resources.cpp b/src/common/resources.cpp index 92b9e7f..d93f38e 100644 --- a/src/common/resources.cpp +++ b/src/common/resources.cpp @@ -632,6 +632,12 @@ Resources Resources::persistentVolumes() const } +Resources Resources::revocable() const +{ + return filter(isRevocable); +} + + Resources Resources::flatten( const string& role, const Option<Resource::ReservationInfo>& reservation) const http://git-wip-us.apache.org/repos/asf/mesos/blob/f15d37ce/src/tests/resources_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp index 99b2cfc..459a68b 100644 --- a/src/tests/resources_tests.cpp +++ b/src/tests/resources_tests.cpp @@ -1245,6 +1245,19 @@ TEST(RevocableResourceTest, Contains) EXPECT_TRUE((r1 + r3).contains(r3)); } + +// This test verifies that revocable resources can be filtered. +TEST(RevocableResourceTest, Filter) +{ + Resources r1 = createRevocableResource("cpus", "1", "*", true); + EXPECT_EQ(r1, r1.revocable()); + + Resources r2 = createRevocableResource("cpus", "1", "*", false); + EXPECT_TRUE(r2.revocable().empty()); + + EXPECT_EQ(r1, (r1 + r2).revocable()); +} + } // namespace tests { } // namespace internal { } // namespace mesos {
