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/05/14 18:48:26 UTC

[1/2] mesos git commit: Wired up --allocator flag in master.

Repository: mesos
Updated Branches:
  refs/heads/master 7f5e6fb05 -> 614efe18c


Wired up --allocator flag in master.

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


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

Branch: refs/heads/master
Commit: 614efe18cf3c7b02a2f3c8269c8eb76cbbe4ddd4
Parents: 86d48d4
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Thu May 14 09:29:52 2015 -0700
Committer: Niklas Q. Nielsen <ni...@qni.dk>
Committed: Thu May 14 09:47:48 2015 -0700

----------------------------------------------------------------------
 src/master/flags.cpp | 13 +++++++++----
 src/master/flags.hpp |  1 +
 src/master/main.cpp  |  2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/614efe18/src/master/flags.cpp
----------------------------------------------------------------------
diff --git a/src/master/flags.cpp b/src/master/flags.cpp
index 5798989..e2de1c4 100644
--- a/src/master/flags.cpp
+++ b/src/master/flags.cpp
@@ -342,12 +342,17 @@ mesos::internal::master::Flags::Flags()
   add(&Flags::authenticators,
       "authenticators",
       "Authenticator implementation to use when authenticating frameworks\n"
-      "and/or slaves. Use the default '" +
-        DEFAULT_AUTHENTICATOR +
-        "', or\n"
-        "load an alternate authenticator module using --modules.",
+      "and/or slaves. Use the default '" + DEFAULT_AUTHENTICATOR + "', or\n"
+      "load an alternate authenticator module using --modules.",
       DEFAULT_AUTHENTICATOR);
 
+  add(&Flags::allocator,
+      "allocator",
+      "Allocator to use for resource allocation to frameworks.\n"
+      "Use the default '" + DEFAULT_ALLOCATOR + "' allocator, or\n"
+      "load an alternate allocator module using --modules.",
+      DEFAULT_ALLOCATOR);
+
   add(&Flags::hooks,
       "hooks",
       "A comma separated list of hook modules to be\n"

http://git-wip-us.apache.org/repos/asf/mesos/blob/614efe18/src/master/flags.hpp
----------------------------------------------------------------------
diff --git a/src/master/flags.hpp b/src/master/flags.hpp
index 996cf38..84fa238 100644
--- a/src/master/flags.hpp
+++ b/src/master/flags.hpp
@@ -68,6 +68,7 @@ public:
   Option<Duration> offer_timeout;
   Option<Modules> modules;
   std::string authenticators;
+  std::string allocator;
   Option<std::string> hooks;
 
 #ifdef WITH_NETWORK_ISOLATOR

http://git-wip-us.apache.org/repos/asf/mesos/blob/614efe18/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index 5b87602..d5666bc 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -202,7 +202,7 @@ int main(int argc, char** argv)
   }
 
   // Create an instance of allocator.
-  const std::string allocatorName = DEFAULT_ALLOCATOR;
+  const std::string allocatorName = flags.allocator;
   Try<Allocator*> allocator = Allocator::create(allocatorName);
 
   if (allocator.isError()) {


[2/2] mesos git commit: Added a modules-aware factory for allocators.

Posted by nn...@apache.org.
Added a modules-aware factory for allocators.

With the support of allocator modules, it should be possible to select
and instantiate an allocator based on its name.

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


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

Branch: refs/heads/master
Commit: 86d48d41bf3e1232bc34059caeebeca151715962
Parents: 7f5e6fb
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Thu May 14 09:26:42 2015 -0700
Committer: Niklas Q. Nielsen <ni...@qni.dk>
Committed: Thu May 14 09:47:48 2015 -0700

----------------------------------------------------------------------
 include/mesos/master/allocator.hpp          |  6 +++
 src/Makefile.am                             |  1 +
 src/master/allocator/allocator.cpp          | 52 ++++++++++++++++++++++++
 src/master/allocator/mesos/allocator.hpp    |  4 +-
 src/master/allocator/mesos/hierarchical.hpp |  2 +
 src/master/constants.cpp                    |  1 +
 src/master/constants.hpp                    |  3 ++
 src/master/main.cpp                         | 19 +++++----
 8 files changed, 79 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/include/mesos/master/allocator.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/master/allocator.hpp b/include/mesos/master/allocator.hpp
index e821bf3..0328ae4 100644
--- a/include/mesos/master/allocator.hpp
+++ b/include/mesos/master/allocator.hpp
@@ -32,6 +32,7 @@
 #include <stout/hashset.hpp>
 #include <stout/lambda.hpp>
 #include <stout/option.hpp>
+#include <stout/try.hpp>
 
 namespace mesos {
 namespace master {
@@ -50,6 +51,11 @@ namespace allocator {
 class Allocator
 {
 public:
+  // Attempts either to create a built-in DRF allocator or to load an
+  // allocator instance from a module using the given name. If Try
+  // does not report an error, the wrapped Allocator* is not null.
+  static Try<Allocator*> create(const std::string& name);
+
   Allocator() {}
 
   virtual ~Allocator() {}

http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 58ebe1a..34755cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -341,6 +341,7 @@ libmesos_no_3rdparty_la_SOURCES =					\
 	master/registrar.cpp						\
 	master/repairer.cpp						\
 	master/validation.cpp						\
+	master/allocator/allocator.cpp					\
 	master/allocator/sorter/drf/sorter.cpp				\
 	module/manager.cpp						\
 	sched/constants.cpp						\

http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/src/master/allocator/allocator.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/allocator.cpp b/src/master/allocator/allocator.cpp
new file mode 100644
index 0000000..4221404
--- /dev/null
+++ b/src/master/allocator/allocator.cpp
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <mesos/master/allocator.hpp>
+
+#include <mesos/module/allocator.hpp>
+
+#include "master/constants.hpp"
+
+#include "master/allocator/mesos/hierarchical.hpp"
+
+#include "module/manager.hpp"
+
+using std::string;
+
+using mesos::internal::master::allocator::HierarchicalDRFAllocator;
+
+namespace mesos {
+namespace master {
+namespace allocator {
+
+Try<Allocator*> Allocator::create(const string& name)
+{
+  // Create an instance of the default allocator. If other than the
+  // default allocator is requested, search for it in loaded modules.
+  // NOTE: We do not need an extra not-null check, because both
+  // ModuleManager and built-in allocator factory do that already.
+  if (name == mesos::internal::master::DEFAULT_ALLOCATOR) {
+    return HierarchicalDRFAllocator::create();
+  }
+
+  return modules::ModuleManager::create<Allocator>(name);
+}
+
+} // namespace allocator {
+} // namespace master {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/src/master/allocator/mesos/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp
index 2681af5..e6f6114 100644
--- a/src/master/allocator/mesos/allocator.hpp
+++ b/src/master/allocator/mesos/allocator.hpp
@@ -187,7 +187,9 @@ template <typename AllocatorProcess>
 Try<mesos::master::allocator::Allocator*>
 MesosAllocator<AllocatorProcess>::create()
 {
-  return new MesosAllocator<AllocatorProcess>();
+  mesos::master::allocator::Allocator* allocator =
+    new MesosAllocator<AllocatorProcess>();
+  return CHECK_NOTNULL(allocator);
 }
 
 template <typename AllocatorProcess>

http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index c22f044..4b36d42 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -38,6 +38,8 @@
 #include "master/allocator/mesos/allocator.hpp"
 #include "master/allocator/sorter/drf/sorter.hpp"
 
+#include "master/constants.hpp"
+
 namespace mesos {
 namespace internal {
 namespace master {

http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/src/master/constants.cpp
----------------------------------------------------------------------
diff --git a/src/master/constants.cpp b/src/master/constants.cpp
index 9ee17e9..8c7174a 100644
--- a/src/master/constants.cpp
+++ b/src/master/constants.cpp
@@ -43,6 +43,7 @@ const uint32_t TASK_LIMIT = 100;
 const std::string MASTER_INFO_LABEL = "info";
 const Duration ZOOKEEPER_SESSION_TIMEOUT = Seconds(10);
 const std::string DEFAULT_AUTHENTICATOR = "crammd5";
+const std::string DEFAULT_ALLOCATOR = "HierarchicalDRF";
 
 } // namespace master {
 } // namespace internal {

http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/src/master/constants.hpp
----------------------------------------------------------------------
diff --git a/src/master/constants.hpp b/src/master/constants.hpp
index c386eab..57cf8fb 100644
--- a/src/master/constants.hpp
+++ b/src/master/constants.hpp
@@ -108,6 +108,9 @@ extern const Duration ZOOKEEPER_SESSION_TIMEOUT;
 // Name of the default, CRAM-MD5 authenticator.
 extern const std::string DEFAULT_AUTHENTICATOR;
 
+// Name of the default, HierarchicalDRF authenticator.
+extern const std::string DEFAULT_ALLOCATOR;
+
 } // namespace master {
 } // namespace internal {
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/86d48d41/src/master/main.cpp
----------------------------------------------------------------------
diff --git a/src/master/main.cpp b/src/master/main.cpp
index 18f8c31..5b87602 100644
--- a/src/master/main.cpp
+++ b/src/master/main.cpp
@@ -80,6 +80,8 @@ using namespace zookeeper;
 
 using mesos::MasterInfo;
 
+using mesos::master::allocator::Allocator;
+
 using mesos::modules::Anonymous;
 using mesos::modules::ModuleManager;
 
@@ -200,15 +202,16 @@ int main(int argc, char** argv)
   }
 
   // Create an instance of allocator.
-  Try<mesos::master::allocator::Allocator*> allocator_ =
-    allocator::HierarchicalDRFAllocator::create();
+  const std::string allocatorName = DEFAULT_ALLOCATOR;
+  Try<Allocator*> allocator = Allocator::create(allocatorName);
 
-  if (allocator_.isError()) {
-    EXIT(1) << "Failed to create an instance of HierarchicalDRFAllocator: "
-            << allocator_.error();
+  if (allocator.isError()) {
+    EXIT(1) << "Failed to create '" << allocatorName << "' allocator: "
+            << allocator.error();
   }
 
-  mesos::master::allocator::Allocator* allocator = allocator_.get();
+  CHECK_NOTNULL(allocator.get());
+  LOG(INFO) << "Using '" << allocatorName << "' allocator";
 
   state::Storage* storage = NULL;
   Log* log = NULL;
@@ -361,7 +364,7 @@ int main(int argc, char** argv)
 
   Master* master =
     new Master(
-      allocator,
+      allocator.get(),
       registrar,
       repairer,
       &files,
@@ -381,7 +384,7 @@ int main(int argc, char** argv)
   process::wait(master->self());
 
   delete master;
-  delete allocator;
+  delete allocator.get();
 
   delete registrar;
   delete repairer;