Added a test allocator module.

The test allocator module is a built-in HierarchicalDRFAllocator put in
a module.

NOTE: Here we add harness code to load the module, tests will be wired
up later in the patch stack.

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


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

Branch: refs/heads/master
Commit: a5f270fe513ecb50021eb06d429a1a84e260f98a
Parents: 079fc0af
Author: Alexander Rukletsov <[email protected]>
Authored: Tue Apr 21 12:11:03 2015 -0700
Committer: Niklas Q. Nielsen <[email protected]>
Committed: Tue Apr 21 12:11:03 2015 -0700

----------------------------------------------------------------------
 src/Makefile.am                        |  6 ++++
 src/examples/test_allocator_module.cpp | 53 +++++++++++++++++++++++++++++
 src/tests/module.cpp                   | 32 +++++++++++++++++
 src/tests/module.hpp                   |  3 +-
 4 files changed, 93 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a5f270fe/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index afca3c8..93c7c8a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1355,6 +1355,12 @@ libtestauthentication_la_SOURCES = 
examples/test_authentication_modules.cpp
 libtestauthentication_la_CPPFLAGS = $(MESOS_CPPFLAGS)
 libtestauthentication_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
 
+# Library containing the test DRF allocator module.
+noinst_LTLIBRARIES += libtestallocator.la
+libtestallocator_la_SOURCES = examples/test_allocator_module.cpp
+libtestallocator_la_CPPFLAGS = $(MESOS_CPPFLAGS)
+libtestallocator_la_LDFLAGS = $(MESOS_MODULE_LDFLAGS)
+
 # Library containing test Hook module.
 noinst_LTLIBRARIES += libtesthook.la
 libtesthook_la_SOURCES = examples/test_hook_module.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/a5f270fe/src/examples/test_allocator_module.cpp
----------------------------------------------------------------------
diff --git a/src/examples/test_allocator_module.cpp 
b/src/examples/test_allocator_module.cpp
new file mode 100644
index 0000000..5fe68e3
--- /dev/null
+++ b/src/examples/test_allocator_module.cpp
@@ -0,0 +1,53 @@
+/**
+ * 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/mesos.hpp>
+#include <mesos/module.hpp>
+
+#include <mesos/master/allocator.hpp>
+
+#include <mesos/module/allocator.hpp>
+
+#include <stout/try.hpp>
+
+#include "master/constants.hpp"
+
+#include "master/allocator/mesos/hierarchical.hpp"
+
+using namespace mesos;
+
+using mesos::master::allocator::Allocator;
+using mesos::internal::master::allocator::HierarchicalDRFAllocator;
+
+
+static Allocator* createDRFAllocator(const Parameters& parameters)
+{
+  return new HierarchicalDRFAllocator();
+}
+
+
+// Declares a DRFAllocator module named
+// 'org_apache_mesos_TestDRFAllocator'.
+mesos::modules::Module<Allocator> org_apache_mesos_TestDRFAllocator(
+    MESOS_MODULE_API_VERSION,
+    MESOS_VERSION,
+    "Apache Mesos",
+    "[email protected]",
+    "Test DRFAllocator module.",
+    NULL,
+    createDRFAllocator);

http://git-wip-us.apache.org/repos/asf/mesos/blob/a5f270fe/src/tests/module.cpp
----------------------------------------------------------------------
diff --git a/src/tests/module.cpp b/src/tests/module.cpp
index b81144f..c4f8119 100644
--- a/src/tests/module.cpp
+++ b/src/tests/module.cpp
@@ -53,6 +53,8 @@ static void addModule(
 // Add available Isolator modules.
 static void addIsolatorModules(Modules* modules)
 {
+  CHECK_NOTNULL(modules);
+
   const string libraryPath = path::join(
       tests::flags.build_dir,
       "src",
@@ -73,6 +75,8 @@ static void addIsolatorModules(Modules* modules)
 // Add available Authentication modules.
 static void addAuthenticationModules(Modules* modules)
 {
+  CHECK_NOTNULL(modules);
+
   const string libraryPath = path::join(
       tests::flags.build_dir,
       "src",
@@ -96,6 +100,8 @@ static void addAuthenticationModules(Modules* modules)
 
 static void addHookModules(Modules* modules)
 {
+  CHECK_NOTNULL(modules);
+
   const string libraryPath = path::join(
       tests::flags.build_dir,
       "src",
@@ -114,6 +120,8 @@ static void addHookModules(Modules* modules)
 
 static void addAnonymousModules(Modules* modules)
 {
+  CHECK_NOTNULL(modules);
+
   const string libraryPath = path::join(
       tests::flags.build_dir,
       "src",
@@ -131,6 +139,27 @@ static void addAnonymousModules(Modules* modules)
 }
 
 
+// Add available Allocator modules.
+static void addAllocatorModules(Modules* modules)
+{
+  CHECK_NOTNULL(modules);
+
+  const string libraryPath = path::join(
+      tests::flags.build_dir,
+      "src",
+      ".libs",
+      os::libraries::expandName("testallocator"));
+
+  // Now add our allocator module.
+  Modules::Library* library = modules->add_libraries();
+  library->set_file(libraryPath);
+
+  // To add a new module from this library, create a new ModuleID enum
+  // and tie it with a module name.
+  addModule(library, TestDRFAllocator, "org_apache_mesos_TestDRFAllocator");
+}
+
+
 Try<Nothing> initModules(const Option<Modules>& modules)
 {
   // First get the user provided modules.
@@ -151,6 +180,9 @@ Try<Nothing> initModules(const Option<Modules>& modules)
   // Add anonymous modules from testanonymous library.
   addAnonymousModules(&mergedModules);
 
+  // Add allocator modules from testallocator library.
+  addAllocatorModules(&mergedModules);
+
   return ModuleManager::load(mergedModules);
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/a5f270fe/src/tests/module.hpp
----------------------------------------------------------------------
diff --git a/src/tests/module.hpp b/src/tests/module.hpp
index 65e567f..c379f01 100644
--- a/src/tests/module.hpp
+++ b/src/tests/module.hpp
@@ -46,7 +46,8 @@ enum ModuleID
   TestCRAMMD5Authenticatee,
   TestCRAMMD5Authenticator,
   TestHook,
-  TestAnonymous
+  TestAnonymous,
+  TestDRFAllocator
 };
 
 

Reply via email to