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 2018/07/23 22:34:07 UTC

mesos git commit: Added a helper for capability filtering in the allocator.

Repository: mesos
Updated Branches:
  refs/heads/master a7638a833 -> 1dde95311


Added a helper for capability filtering in the allocator.

`isCapableOfReceivingAgent(` returns whether a framework is capable
of receiving any resources on the agent.

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


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

Branch: refs/heads/master
Commit: 1dde9531104415c7759ebc1fb560bb55e16bbd8b
Parents: a7638a8
Author: Meng Zhu <mz...@mesosphere.io>
Authored: Mon Jul 23 15:32:03 2018 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Jul 23 15:32:03 2018 -0700

----------------------------------------------------------------------
 src/master/allocator/mesos/hierarchical.cpp | 50 ++++++++++++------------
 src/master/allocator/mesos/hierarchical.hpp | 13 ++++++
 2 files changed, 38 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1dde9531/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 707dd6b..7b4e9db 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -58,7 +58,6 @@ using process::Owned;
 using process::PID;
 using process::Timeout;
 
-using mesos::internal::protobuf::framework::Capabilities;
 
 namespace mesos {
 namespace internal {
@@ -1800,18 +1799,7 @@ void HierarchicalAllocatorProcess::__allocate()
 
         Slave& slave = slaves.at(slaveId);
 
-        // Only offer resources from slaves that have GPUs to
-        // frameworks that are capable of receiving GPUs.
-        // See MESOS-5634.
-        if (filterGpuResources &&
-            !framework.capabilities.gpuResources &&
-            slave.getTotal().gpus().getOrElse(0) > 0) {
-          continue;
-        }
-
-        // If this framework is not region-aware, don't offer it
-        // resources on agents in remote regions.
-        if (!framework.capabilities.regionAware && isRemoteSlave(slave)) {
+        if (!isCapableOfReceivingAgent(framework.capabilities, slave)) {
           continue;
         }
 
@@ -2044,18 +2032,7 @@ void HierarchicalAllocatorProcess::__allocate()
         const Framework& framework = frameworks.at(frameworkId);
         Slave& slave = slaves.at(slaveId);
 
-        // Only offer resources from slaves that have GPUs to
-        // frameworks that are capable of receiving GPUs.
-        // See MESOS-5634.
-        if (filterGpuResources &&
-            !framework.capabilities.gpuResources &&
-            slave.getTotal().gpus().getOrElse(0) > 0) {
-          continue;
-        }
-
-        // If this framework is not region-aware, don't offer it
-        // resources on agents in remote regions.
-        if (!framework.capabilities.regionAware && isRemoteSlave(slave)) {
+        if (!isCapableOfReceivingAgent(framework.capabilities, slave)) {
           continue;
         }
 
@@ -2731,6 +2708,28 @@ bool HierarchicalAllocatorProcess::isRemoteSlave(const Slave& slave) const
 }
 
 
+bool HierarchicalAllocatorProcess::isCapableOfReceivingAgent(
+    const protobuf::framework::Capabilities& frameworkCapabilities,
+    const Slave& slave) const
+{
+  // Only offer resources from slaves that have GPUs to
+  // frameworks that are capable of receiving GPUs.
+  // See MESOS-5634.
+  if (filterGpuResources && !frameworkCapabilities.gpuResources &&
+      slave.getTotal().gpus().getOrElse(0) > 0) {
+    return false;
+  }
+
+  // If this framework is not region-aware, don't offer it
+  // resources on agents in remote regions.
+  if (!frameworkCapabilities.regionAware && isRemoteSlave(slave)) {
+    return false;
+  }
+
+  return true;
+}
+
+
 void HierarchicalAllocatorProcess::trackAllocatedResources(
     const SlaveID& slaveId,
     const FrameworkID& frameworkId,
@@ -2803,6 +2802,7 @@ void HierarchicalAllocatorProcess::untrackAllocatedResources(
   }
 }
 
+
 } // namespace internal {
 } // namespace allocator {
 } // namespace master {

http://git-wip-us.apache.org/repos/asf/mesos/blob/1dde9531/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 702e7c0..43278a9 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -313,6 +313,8 @@ protected:
   friend Metrics;
   Metrics metrics;
 
+  // TODO(mzhu): Pull out the nested Framework struct for clearer
+  // logic division with the allocator.
   struct Framework
   {
     Framework(
@@ -355,6 +357,8 @@ protected:
 
   hashmap<FrameworkID, Framework> frameworks;
 
+  // TODO(mzhu): Pull out the nested Slave class for clearer
+  // logic division with the allocator.
   class Slave
   {
   public:
@@ -642,6 +646,15 @@ private:
   // the agent and the master are both configured with a fault domain.
   bool isRemoteSlave(const Slave& slave) const;
 
+  // Helper function that checks if a framework is capable of
+  // receiving resources on the agent based on the framework capability.
+  //
+  // TODO(mzhu): Make this a `Framework` member function once we pull
+  // `struct Framework` out from being nested.
+  bool isCapableOfReceivingAgent(
+      const protobuf::framework::Capabilities& frameworkCapabilities,
+      const Slave& slave) const;
+
   // Helper to track allocated resources on an agent.
   void trackAllocatedResources(
       const SlaveID& slaveId,