Killed ports allocation in C++ Resources. Review: https://reviews.apache.org/r/28090
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/85728f85 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/85728f85 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/85728f85 Branch: refs/heads/master Commit: 85728f85afaf6db0fd2e55cd8d7b2135a4941310 Parents: a01773b Author: Jie Yu <[email protected]> Authored: Tue Nov 18 21:35:54 2014 -0800 Committer: Jie Yu <[email protected]> Committed: Wed Nov 19 00:14:25 2014 -0800 ---------------------------------------------------------------------- include/mesos/resources.hpp | 4 ---- src/common/resources.cpp | 30 ------------------------------ src/tests/resources_tests.cpp | 28 ---------------------------- 3 files changed, 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/85728f85/include/mesos/resources.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp index c8a261f..86b70df 100644 --- a/include/mesos/resources.hpp +++ b/include/mesos/resources.hpp @@ -154,10 +154,6 @@ public: // TODO(vinod): Provide a Ranges abstraction. Option<Value::Ranges> ports() const; - // Helper function to extract the given number of ports from the - // "ports" resource. - Option<Value::Ranges> ports(size_t numPorts) const; - // TODO(jieyu): Consider returning an EphemeralPorts abstraction // which holds the ephemeral ports allocation logic. Option<Value::Ranges> ephemeral_ports() const; http://git-wip-us.apache.org/repos/asf/mesos/blob/85728f85/src/common/resources.cpp ---------------------------------------------------------------------- diff --git a/src/common/resources.cpp b/src/common/resources.cpp index 458c1cd..8474cdd 100644 --- a/src/common/resources.cpp +++ b/src/common/resources.cpp @@ -637,36 +637,6 @@ Option<Value::Ranges> Resources::ports() const return None(); } -Option<Value::Ranges> Resources::ports(size_t numPorts) const -{ - Value::Ranges total; - - foreach (const Resource& resource, resources) { - if (resource.name() == "ports" && - resource.type() == Value::RANGES && - isAllocatable(resource)) { - foreach (const Value::Range& range, resource.ranges().range()) { - size_t interval = range.end() - range.begin() + 1; - if (numPorts < interval) { - Value::Range* lastRange = total.add_range(); - lastRange->set_begin(range.begin()); - lastRange->set_end(range.begin() + numPorts - 1); - - return total; - } else { - total.add_range()->CopyFrom(range); - numPorts -= interval; - - if (numPorts == 0) { - return total; - } - } - } - } - } - - return None(); -} Option<Value::Ranges> Resources::ephemeral_ports() const { http://git-wip-us.apache.org/repos/asf/mesos/blob/85728f85/src/tests/resources_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp index c8d069a..8d1e86a 100644 --- a/src/tests/resources_tests.cpp +++ b/src/tests/resources_tests.cpp @@ -156,34 +156,6 @@ TEST(ResourcesTest, Resources) } -TEST(ResourcesTest, Ports) -{ - // Extract one Value::Range. - Resources r = Resources::parse("ports:[10000-20000, 30000-50000]").get(); - Option<Value::Ranges> ports = r.ports(5); - EXPECT_SOME(ports); - EXPECT_EQ("[10000-10004]", stringify(ports.get())); - - // Extract two Value::Ranges. - r = Resources::parse("ports:[10000-10000, 20000-50000]").get(); - ports = r.ports(5); - EXPECT_SOME(ports); - EXPECT_EQ("[10000-10000, 20000-20003]", stringify(ports.get())); - - // Extract mutiple Value::Ranges. - r = Resources::parse("ports:[10000-10001, 10003-10004, 10007-10009," - "10020-20000]").get(); - ports = r.ports(10); - EXPECT_SOME(ports); - EXPECT_EQ("[10000-10001, 10003-10004, 10007-10009, 10020-10022]", - stringify(ports.get())); - - // Not enough ports. - r = Resources::parse("ports:[10000-10004]").get(); - EXPECT_TRUE(r.ports(10).isNone()); -} - - TEST(ResourcesTest, Printing) { Resources r = Resources::parse(
