Repository: mesos
Updated Branches:
  refs/heads/master effc3636d -> 441dd02cd


Added Sorter::allocation() overload for getting resources of a particular slave.

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


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

Branch: refs/heads/master
Commit: 1e596419298998eaff95e7ac9394ca6355879925
Parents: ac58067
Author: Vinod Kone <[email protected]>
Authored: Fri Jun 19 17:30:09 2015 -0700
Committer: Vinod Kone <[email protected]>
Committed: Sun Jun 21 11:50:58 2015 -0700

----------------------------------------------------------------------
 src/master/allocator/sorter/drf/sorter.cpp | 14 ++++++++++++++
 src/master/allocator/sorter/drf/sorter.hpp |  2 ++
 src/master/allocator/sorter/sorter.hpp     |  6 ++++++
 src/tests/sorter_tests.cpp                 | 21 ++++++++++-----------
 4 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1e596419/src/master/allocator/sorter/drf/sorter.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/drf/sorter.cpp 
b/src/master/allocator/sorter/drf/sorter.cpp
index 12434a0..85eef6b 100644
--- a/src/master/allocator/sorter/drf/sorter.cpp
+++ b/src/master/allocator/sorter/drf/sorter.cpp
@@ -156,10 +156,24 @@ void DRFSorter::update(
 
 hashmap<SlaveID, Resources> DRFSorter::allocation(const string& name)
 {
+  CHECK(contains(name));
+
   return allocations[name].resources;
 }
 
 
+Resources DRFSorter::allocation(const string& name, const SlaveID& slaveId)
+{
+  CHECK(contains(name));
+
+  if (allocations[name].resources.contains(slaveId)) {
+    return allocations[name].resources[slaveId];
+  }
+
+  return Resources();
+}
+
+
 void DRFSorter::unallocated(
     const string& name,
     const SlaveID& slaveId,

http://git-wip-us.apache.org/repos/asf/mesos/blob/1e596419/src/master/allocator/sorter/drf/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/drf/sorter.hpp 
b/src/master/allocator/sorter/drf/sorter.hpp
index d38925e..6aec14f 100644
--- a/src/master/allocator/sorter/drf/sorter.hpp
+++ b/src/master/allocator/sorter/drf/sorter.hpp
@@ -91,6 +91,8 @@ public:
 
   virtual hashmap<SlaveID, Resources> allocation(const std::string& name);
 
+  virtual Resources allocation(const std::string& name, const SlaveID& 
slaveId);
+
   virtual void add(const SlaveID& slaveId, const Resources& resources);
 
   virtual void remove(const SlaveID& slaveId, const Resources& resources);

http://git-wip-us.apache.org/repos/asf/mesos/blob/1e596419/src/master/allocator/sorter/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/sorter/sorter.hpp 
b/src/master/allocator/sorter/sorter.hpp
index 9f7d3cc..536a7ad 100644
--- a/src/master/allocator/sorter/sorter.hpp
+++ b/src/master/allocator/sorter/sorter.hpp
@@ -80,6 +80,12 @@ public:
   // Returns the resources that have been allocated to this client.
   virtual hashmap<SlaveID, Resources> allocation(const std::string& client) = 
0;
 
+  // Returns the given slave's resources that have been allocated to
+  // this client.
+  virtual Resources allocation(
+      const std::string& client,
+      const SlaveID& slaveId) = 0;
+
   // Add resources to the total pool of resources this
   // Sorter should consider.
   virtual void add(const SlaveID& slaveId, const Resources& resources) = 0;

http://git-wip-us.apache.org/repos/asf/mesos/blob/1e596419/src/tests/sorter_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/sorter_tests.cpp b/src/tests/sorter_tests.cpp
index 4013886..0db9a04 100644
--- a/src/tests/sorter_tests.cpp
+++ b/src/tests/sorter_tests.cpp
@@ -235,7 +235,7 @@ TEST(SorterTest, UpdateAllocation)
   volume.mutable_disk()->mutable_volume()->set_container_path("data");
 
   // Compute the updated allocation.
-  Resources oldAllocation = sorter.allocation("a")[slaveId];
+  Resources oldAllocation = sorter.allocation("a", slaveId);
   Try<Resources> newAllocation = oldAllocation.apply(CREATE(volume));
   ASSERT_SOME(newAllocation);
 
@@ -245,6 +245,7 @@ TEST(SorterTest, UpdateAllocation)
   hashmap<SlaveID, Resources> allocation = sorter.allocation("a");
   EXPECT_EQ(1u, allocation.size());
   EXPECT_EQ(newAllocation.get(), allocation[slaveId]);
+  EXPECT_EQ(newAllocation.get(), sorter.allocation("a", slaveId));
 }
 
 
@@ -274,10 +275,9 @@ TEST(SorterTest, MultipleSlaves)
   sorter.allocated("framework", slaveA, slaveResources);
   sorter.allocated("framework", slaveB, slaveResources);
 
-  hashmap<SlaveID, Resources> allocation = sorter.allocation("framework");
-  EXPECT_EQ(2u, allocation.size());
-  EXPECT_EQ(slaveResources, allocation[slaveA]);
-  EXPECT_EQ(slaveResources, allocation[slaveB]);
+  EXPECT_EQ(2u, sorter.allocation("framework").size());
+  EXPECT_EQ(slaveResources, sorter.allocation("framework", slaveA));
+  EXPECT_EQ(slaveResources, sorter.allocation("framework", slaveB));
 }
 
 
@@ -320,10 +320,9 @@ TEST(SorterTest, MultipleSlavesUpdateAllocation)
   sorter.update("framework", slaveA, slaveResources, newAllocation.get());
   sorter.update("framework", slaveB, slaveResources, newAllocation.get());
 
-  hashmap<SlaveID, Resources> allocation = sorter.allocation("framework");
-  EXPECT_EQ(2u, allocation.size());
-  EXPECT_EQ(newAllocation.get(), allocation[slaveA]);
-  EXPECT_EQ(newAllocation.get(), allocation[slaveB]);
+  EXPECT_EQ(2u, sorter.allocation("framework").size());
+  EXPECT_EQ(newAllocation.get(), sorter.allocation("framework", slaveA));
+  EXPECT_EQ(newAllocation.get(), sorter.allocation("framework", slaveB));
 }
 
 
@@ -440,8 +439,8 @@ TEST(SorterTest, RevocableResources)
   sorter.allocated("b", slaveId, b);
 
   // Check that the allocations are correct.
-  ASSERT_EQ(a, sorter.allocation("a")[slaveId]);
-  ASSERT_EQ(b, sorter.allocation("b")[slaveId]);
+  ASSERT_EQ(a, sorter.allocation("a", slaveId));
+  ASSERT_EQ(b, sorter.allocation("b", slaveId));
 
   // Check that the sort is correct.
   list<string> sorted = sorter.sort();

Reply via email to