Repository: mesos
Updated Branches:
  refs/heads/master e65f580bf -> 96ecebe0b


Offer shared resources to frameworks only if opted in.

Added a new capability SHARED_RESOURCES that frameworks need to opt
in if they are interested in receiving shared resources in their
offers.

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


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

Branch: refs/heads/master
Commit: f07a1752f0220681bf6cc6162b6732e9c825ce3b
Parents: e65f580
Author: Anindya Sinha <anindya_si...@apple.com>
Authored: Fri Sep 16 08:29:58 2016 -0700
Committer: Jiang Yan Xu <xuj...@apple.com>
Committed: Fri Sep 16 08:29:58 2016 -0700

----------------------------------------------------------------------
 include/mesos/mesos.proto                   |  1 -
 include/mesos/v1/mesos.proto                |  1 -
 src/master/allocator/mesos/hierarchical.cpp | 22 ++++++++++++++++------
 src/master/allocator/mesos/hierarchical.hpp |  3 +++
 src/tests/hierarchical_allocator_tests.cpp  |  2 ++
 5 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f07a1752/include/mesos/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto
index 06c2367..7241c11 100644
--- a/include/mesos/mesos.proto
+++ b/include/mesos/mesos.proto
@@ -295,7 +295,6 @@ message FrameworkInfo {
       GPU_RESOURCES = 3;
 
       // Receive offers with resources that are shared.
-      // TODO(anindya_sinha): This is currently a no-op.
       SHARED_RESOURCES = 4;
 
       // Indicates that the framework is prepared to handle the

http://git-wip-us.apache.org/repos/asf/mesos/blob/f07a1752/include/mesos/v1/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto
index 68b90bd..04eaeb3 100644
--- a/include/mesos/v1/mesos.proto
+++ b/include/mesos/v1/mesos.proto
@@ -295,7 +295,6 @@ message FrameworkInfo {
       GPU_RESOURCES = 3;
 
       // Receive offers with resources that are shared.
-      // TODO(anindya_sinha): This is currently a no-op.
       SHARED_RESOURCES = 4;
 
       // Indicates that the framework is prepared to handle the

http://git-wip-us.apache.org/repos/asf/mesos/blob/f07a1752/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp 
b/src/master/allocator/mesos/hierarchical.cpp
index e866fd2..2d56bd0 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -266,6 +266,9 @@ void HierarchicalAllocatorProcess::addFramework(
   frameworks[frameworkId].gpuAware = protobuf::frameworkHasCapability(
       frameworkInfo, FrameworkInfo::Capability::GPU_RESOURCES);
 
+  frameworks[frameworkId].shared = protobuf::frameworkHasCapability(
+      frameworkInfo, FrameworkInfo::Capability::SHARED_RESOURCES);
+
   LOG(INFO) << "Added framework " << frameworkId;
 
   allocate();
@@ -399,6 +402,9 @@ void HierarchicalAllocatorProcess::updateFramework(
 
   frameworks[frameworkId].gpuAware = protobuf::frameworkHasCapability(
       frameworkInfo, FrameworkInfo::Capability::GPU_RESOURCES);
+
+  frameworks[frameworkId].shared = protobuf::frameworkHasCapability(
+      frameworkInfo, FrameworkInfo::Capability::SHARED_RESOURCES);
 }
 
 
@@ -1417,12 +1423,14 @@ void HierarchicalAllocatorProcess::allocate(
         // past allocations.
         Resources available =
           (slaves[slaveId].total - slaves[slaveId].allocated).nonShared();
-        available += slaves[slaveId].total.shared();
 
         // Offer a shared resource only if it has not been offered in
         // this offer cycle to a framework.
-        if (offeredSharedResources.contains(slaveId)) {
-          available -= offeredSharedResources[slaveId];
+        if (frameworks[frameworkId].shared) {
+          available += slaves[slaveId].total.shared();
+          if (offeredSharedResources.contains(slaveId)) {
+            available -= offeredSharedResources[slaveId];
+          }
         }
 
         // The resources we offer are the unreserved resources as well as the
@@ -1571,12 +1579,14 @@ void HierarchicalAllocatorProcess::allocate(
         // past allocations.
         Resources available =
           (slaves[slaveId].total - slaves[slaveId].allocated).nonShared();
-        available += slaves[slaveId].total.shared();
 
         // Offer a shared resource only if it has not been offered in
         // this offer cycle to a framework.
-        if (offeredSharedResources.contains(slaveId)) {
-          available -= offeredSharedResources[slaveId];
+        if (frameworks[frameworkId].shared) {
+          available += slaves[slaveId].total.shared();
+          if (offeredSharedResources.contains(slaveId)) {
+            available -= offeredSharedResources[slaveId];
+          }
         }
 
         // The resources we offer are the unreserved resources as well as the

http://git-wip-us.apache.org/repos/asf/mesos/blob/f07a1752/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp 
b/src/master/allocator/mesos/hierarchical.hpp
index 1f5f380..2c31471 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -289,6 +289,9 @@ protected:
     // the documentation for the GPU_RESOURCES Capability.
     bool gpuAware;
 
+    // Whether the framework desires shared resources.
+    bool shared;
+
     // Active offer and inverse offer filters for the framework.
     hashmap<SlaveID, hashset<OfferFilter*>> offerFilters;
     hashmap<SlaveID, hashset<InverseOfferFilter*>> inverseOfferFilters;

http://git-wip-us.apache.org/repos/asf/mesos/blob/f07a1752/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp 
b/src/tests/hierarchical_allocator_tests.cpp
index 7705de9..208937f 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -1286,6 +1286,8 @@ TEST_F(HierarchicalAllocatorTest, 
UpdateAllocationSharedPersistentVolume)
 
   // Initially, all the resources are allocated.
   FrameworkInfo framework = createFrameworkInfo("role1");
+  framework.add_capabilities()->set_type(
+      FrameworkInfo::Capability::SHARED_RESOURCES);
   allocator->addFramework(
       framework.id(), framework, hashmap<SlaveID, Resources>());
 

Reply via email to