You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2015/06/04 02:26:50 UTC

mesos git commit: Added callback to the estimator to retrieve usages from the monitor.

Repository: mesos
Updated Branches:
  refs/heads/master 0607e58b5 -> 4b214747c


Added callback to the estimator to retrieve usages from the monitor.

This is neccessary, since ResourceEstimator needs data (current
statistics for each executor) on which it will base its slack
predictions.

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


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

Branch: refs/heads/master
Commit: 4b214747ccf09e00e7db080a0f4c102b8aabdb47
Parents: 0607e58
Author: Bartek Plotka <bw...@gmail.com>
Authored: Wed Jun 3 17:13:13 2015 -0700
Committer: Niklas Q. Nielsen <ni...@qni.dk>
Committed: Wed Jun 3 17:13:15 2015 -0700

----------------------------------------------------------------------
 include/mesos/slave/resource_estimator.hpp | 11 ++++++++---
 src/slave/resource_estimators/noop.cpp     |  3 ++-
 src/slave/resource_estimators/noop.hpp     |  7 ++++++-
 src/slave/slave.cpp                        |  5 +++--
 src/tests/mesos.hpp                        | 18 +++++++++++-------
 src/tests/oversubscription_tests.cpp       |  6 +++---
 6 files changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4b214747/include/mesos/slave/resource_estimator.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/slave/resource_estimator.hpp b/include/mesos/slave/resource_estimator.hpp
index e7f5dec..45e0b19 100644
--- a/include/mesos/slave/resource_estimator.hpp
+++ b/include/mesos/slave/resource_estimator.hpp
@@ -25,6 +25,7 @@
 
 #include <process/future.hpp>
 
+#include <stout/lambda.hpp>
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
 #include <stout/try.hpp>
@@ -46,9 +47,13 @@ public:
   virtual ~ResourceEstimator() {}
 
   // Initializes this resource estimator. This method needs to be
-  // called before any other member method is called.
-  // TODO(jieyu): Pass ResourceMonitor* once it's exposed.
-  virtual Try<Nothing> initialize() = 0;
+  // called before any other member method is called. It registers
+  // a callback in the resource estimator. The callback allows the
+  // resource estimator to fetch the current resource usage for each
+  // executor on slave.
+  virtual Try<Nothing> initialize(
+      const lambda::function<
+          process::Future<std::list<ResourceUsage>>()>& usages) = 0;
 
   // Returns the current estimation about the *maximum* amount of
   // resources that can be oversubscribed on the slave. A new

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b214747/src/slave/resource_estimators/noop.cpp
----------------------------------------------------------------------
diff --git a/src/slave/resource_estimators/noop.cpp b/src/slave/resource_estimators/noop.cpp
index 3fb44d6..772eb4e 100644
--- a/src/slave/resource_estimators/noop.cpp
+++ b/src/slave/resource_estimators/noop.cpp
@@ -59,7 +59,8 @@ NoopResourceEstimator::~NoopResourceEstimator()
 }
 
 
-Try<Nothing> NoopResourceEstimator::initialize()
+Try<Nothing> NoopResourceEstimator::initialize(
+    const lambda::function<Future<std::list<ResourceUsage>>()>& usages)
 {
   if (process.get() != NULL) {
     return Error("Noop resource estimator has already been initialized");

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b214747/src/slave/resource_estimators/noop.hpp
----------------------------------------------------------------------
diff --git a/src/slave/resource_estimators/noop.hpp b/src/slave/resource_estimators/noop.hpp
index 2234ed6..7a44e6d 100644
--- a/src/slave/resource_estimators/noop.hpp
+++ b/src/slave/resource_estimators/noop.hpp
@@ -21,6 +21,8 @@
 
 #include <mesos/slave/resource_estimator.hpp>
 
+#include <stout/lambda.hpp>
+
 #include <process/owned.hpp>
 
 namespace mesos {
@@ -39,7 +41,10 @@ class NoopResourceEstimator : public mesos::slave::ResourceEstimator
 public:
   virtual ~NoopResourceEstimator();
 
-  virtual Try<Nothing> initialize();
+  virtual Try<Nothing> initialize(
+      const lambda::function<
+          process::Future<std::list<ResourceUsage>>()>& usages);
+
   virtual process::Future<Resources> oversubscribable();
 
 protected:

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b214747/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 271cb03..e264fb9 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -323,8 +323,9 @@ void Slave::initialize()
             << "' for --gc_disk_headroom. Must be between 0.0 and 1.0.";
   }
 
-  // TODO(jieyu): Pass ResourceMonitor* to 'initialize'.
-  Try<Nothing> initialize = resourceEstimator->initialize();
+  Try<Nothing> initialize = resourceEstimator->initialize(
+      lambda::bind(&ResourceMonitor::usages, &monitor));
+
   if (initialize.isError()) {
     EXIT(1) << "Failed to initialize the resource estimator: "
             << initialize.error();

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b214747/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index aeeed61..7e134b7 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -715,9 +715,9 @@ class MockResourceEstimator : public mesos::slave::ResourceEstimator
 public:
   MockResourceEstimator()
   {
-    ON_CALL(*this, initialize())
+    ON_CALL(*this, initialize(_))
       .WillByDefault(Return(Nothing()));
-    EXPECT_CALL(*this, initialize())
+    EXPECT_CALL(*this, initialize(_))
       .WillRepeatedly(DoDefault());
 
     ON_CALL(*this, oversubscribable())
@@ -728,11 +728,15 @@ public:
 
   virtual ~MockResourceEstimator() {}
 
-  MOCK_METHOD0(initialize,
-               Try<Nothing>());
-
-  MOCK_METHOD0(oversubscribable,
-               process::Future<Resources>());
+  MOCK_METHOD1(
+      initialize,
+      Try<Nothing>(
+          const lambda::function<
+              process::Future<std::list<ResourceUsage>>()>&));
+
+  MOCK_METHOD0(
+      oversubscribable,
+      process::Future<Resources>());
 };
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b214747/src/tests/oversubscription_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/oversubscription_tests.cpp b/src/tests/oversubscription_tests.cpp
index f047b90..b1a10a9 100644
--- a/src/tests/oversubscription_tests.cpp
+++ b/src/tests/oversubscription_tests.cpp
@@ -87,7 +87,7 @@ TEST_F(OversubscriptionTest, ForwardUpdateSlaveMessage)
 
   MockResourceEstimator resourceEstimator;
 
-  EXPECT_CALL(resourceEstimator, initialize());
+  EXPECT_CALL(resourceEstimator, initialize(_));
 
   Queue<Resources> estimations;
   // We expect 2 calls:
@@ -147,7 +147,7 @@ TEST_F(OversubscriptionTest, RevocableOffer)
   // Start the slave with test resource estimator.
   MockResourceEstimator resourceEstimator;
 
-  EXPECT_CALL(resourceEstimator, initialize());
+  EXPECT_CALL(resourceEstimator, initialize(_));
 
   Queue<Resources> estimations;
   // We expect 2 calls:
@@ -217,7 +217,7 @@ TEST_F(OversubscriptionTest, RescindRevocableOffer)
   // Start the slave with test resource estimator.
   MockResourceEstimator resourceEstimator;
 
-  EXPECT_CALL(resourceEstimator, initialize());
+  EXPECT_CALL(resourceEstimator, initialize(_));
 
   Queue<Resources> estimations;
   // We expect 3 calls: