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 2016/12/18 01:13:46 UTC
[1/2] mesos git commit: Updated Resources to handle
Resource.AllocationInfo.
Repository: mesos
Updated Branches:
refs/heads/master 50f9abcb5 -> 980f660ac
Updated Resources to handle Resource.AllocationInfo.
With the addition of `Resource.AllocationInfo`, we must prevent the
loss of allocation information when performing addition and
subtraction of resources.
Review: https://reviews.apache.org/r/54842
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0a193327
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0a193327
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0a193327
Branch: refs/heads/master
Commit: 0a1933273d0e122c42734e6f113aa31eea1644dd
Parents: 50f9abc
Author: Benjamin Mahler <bm...@apache.org>
Authored: Sat Dec 17 16:19:15 2016 -0600
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Sat Dec 17 16:39:02 2016 -0600
----------------------------------------------------------------------
src/common/resources.cpp | 54 ++++++++++++++++++++++++++++++++++++++
src/tests/resources_tests.cpp | 43 ++++++++++++++++++++++++++++++
src/v1/resources.cpp | 54 ++++++++++++++++++++++++++++++++++++++
3 files changed, 151 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/0a193327/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 16f6de6..7dbeefc 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -53,6 +53,30 @@ namespace mesos {
/////////////////////////////////////////////////
bool operator==(
+ const Resource::AllocationInfo& left,
+ const Resource::AllocationInfo& right)
+{
+ if (left.has_role() != right.has_role()) {
+ return false;
+ }
+
+ if (left.has_role() && left.role() != right.role()) {
+ return false;
+ }
+
+ return true;
+}
+
+
+bool operator!=(
+ const Resource::AllocationInfo& left,
+ const Resource::AllocationInfo& right)
+{
+ return !(left == right);
+}
+
+
+bool operator==(
const Resource::ReservationInfo& left,
const Resource::ReservationInfo& right)
{
@@ -185,6 +209,16 @@ bool operator==(const Resource& left, const Resource& right)
return false;
}
+ // Check AllocationInfo.
+ if (left.has_allocation_info() != right.has_allocation_info()) {
+ return false;
+ }
+
+ if (left.has_allocation_info() &&
+ left.allocation_info() != right.allocation_info()) {
+ return false;
+ }
+
// Check ReservationInfo.
if (left.has_reservation() != right.has_reservation()) {
return false;
@@ -255,6 +289,16 @@ static bool addable(const Resource& left, const Resource& right)
return false;
}
+ // Check AllocationInfo.
+ if (left.has_allocation_info() != right.has_allocation_info()) {
+ return false;
+ }
+
+ if (left.has_allocation_info() &&
+ left.allocation_info() != right.allocation_info()) {
+ return false;
+ }
+
// Check ReservationInfo.
if (left.has_reservation() != right.has_reservation()) {
return false;
@@ -323,6 +367,16 @@ static bool subtractable(const Resource& left, const Resource& right)
return false;
}
+ // Check AllocationInfo.
+ if (left.has_allocation_info() != right.has_allocation_info()) {
+ return false;
+ }
+
+ if (left.has_allocation_info() &&
+ left.allocation_info() != right.allocation_info()) {
+ return false;
+ }
+
// Check ReservationInfo.
if (left.has_reservation() != right.has_reservation()) {
return false;
http://git-wip-us.apache.org/repos/asf/mesos/blob/0a193327/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index c0ff977..8dfb1be 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -2768,6 +2768,49 @@ static Resource createAllocatedResource(
}
+TEST(AllocatedResourcesTest, Equality)
+{
+ Resources cpus1 = createAllocatedResource("cpus", "1", "*");
+ Resources cpus2 = createAllocatedResource("cpus", "1", "role1");
+
+ EXPECT_EQ(cpus1, cpus1);
+ EXPECT_NE(cpus1, cpus2);
+}
+
+
+TEST(AllocatedResourcesTest, Contains)
+{
+ Resources cpus1 = createAllocatedResource("cpus", "1", "*");
+ Resources cpus2 = createAllocatedResource("cpus", "1", "role1");
+
+ EXPECT_TRUE((cpus1 + cpus2).contains(cpus1));
+ EXPECT_TRUE((cpus1 + cpus2).contains(cpus2));
+}
+
+
+TEST(AllocatedResourcesTest, Addition)
+{
+ Resources cpus1 = createAllocatedResource("cpus", "1", "*");
+ Resources cpus2 = createAllocatedResource("cpus", "1", "role1");
+
+ EXPECT_EQ(2u, (cpus1 + cpus2).size());
+ EXPECT_SOME_EQ(2.0, (cpus1 + cpus2).cpus());
+}
+
+
+TEST(AllocatedResourcesTest, Subtraction)
+{
+ Resources cpus1 = createAllocatedResource("cpus", "1", "*");
+ Resources cpus2 = createAllocatedResource("cpus", "1", "role1");
+
+ EXPECT_TRUE((cpus1 - cpus1).empty());
+ EXPECT_TRUE((cpus2 - cpus2).empty());
+
+ EXPECT_EQ(cpus1, cpus1 - cpus2);
+ EXPECT_EQ(cpus2, cpus2 - cpus1);
+}
+
+
TEST(AllocatedResourcesTest, Allocations)
{
Resources cpus1 = createAllocatedResource("cpus", "1", "*");
http://git-wip-us.apache.org/repos/asf/mesos/blob/0a193327/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index a1adf1b..859f738 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -55,6 +55,30 @@ namespace v1 {
/////////////////////////////////////////////////
bool operator==(
+ const Resource::AllocationInfo& left,
+ const Resource::AllocationInfo& right)
+{
+ if (left.has_role() != right.has_role()) {
+ return false;
+ }
+
+ if (left.has_role() && left.role() != right.role()) {
+ return false;
+ }
+
+ return true;
+}
+
+
+bool operator!=(
+ const Resource::AllocationInfo& left,
+ const Resource::AllocationInfo& right)
+{
+ return !(left == right);
+}
+
+
+bool operator==(
const Resource::ReservationInfo& left,
const Resource::ReservationInfo& right)
{
@@ -187,6 +211,16 @@ bool operator==(const Resource& left, const Resource& right)
return false;
}
+ // Check AllocationInfo.
+ if (left.has_allocation_info() != right.has_allocation_info()) {
+ return false;
+ }
+
+ if (left.has_allocation_info() &&
+ left.allocation_info() != right.allocation_info()) {
+ return false;
+ }
+
// Check ReservationInfo.
if (left.has_reservation() != right.has_reservation()) {
return false;
@@ -257,6 +291,16 @@ static bool addable(const Resource& left, const Resource& right)
return false;
}
+ // Check AllocationInfo.
+ if (left.has_allocation_info() != right.has_allocation_info()) {
+ return false;
+ }
+
+ if (left.has_allocation_info() &&
+ left.allocation_info() != right.allocation_info()) {
+ return false;
+ }
+
// Check ReservationInfo.
if (left.has_reservation() != right.has_reservation()) {
return false;
@@ -325,6 +369,16 @@ static bool subtractable(const Resource& left, const Resource& right)
return false;
}
+ // Check AllocationInfo.
+ if (left.has_allocation_info() != right.has_allocation_info()) {
+ return false;
+ }
+
+ if (left.has_allocation_info() &&
+ left.allocation_info() != right.allocation_info()) {
+ return false;
+ }
+
// Check ReservationInfo.
if (left.has_reservation() != right.has_reservation()) {
return false;
[2/2] mesos git commit: Added a CHECK when adding a framework in the
allocator.
Posted by bm...@apache.org.
Added a CHECK when adding a framework in the allocator.
Review: https://reviews.apache.org/r/54837
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/980f660a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/980f660a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/980f660a
Branch: refs/heads/master
Commit: 980f660ac4045fe8751ce843223a75d3d84348e0
Parents: 0a19332
Author: Benjamin Mahler <bm...@apache.org>
Authored: Wed Dec 7 17:59:47 2016 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Sat Dec 17 19:13:07 2016 -0600
----------------------------------------------------------------------
src/master/allocator/mesos/hierarchical.cpp | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/980f660a/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index a8cbc8d..91b1ec4 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -223,6 +223,7 @@ void HierarchicalAllocatorProcess::addFramework(
bool active)
{
CHECK(initialized);
+ CHECK(!frameworks.contains(frameworkId));
const string& role = frameworkInfo.role();