Added support for contender and detector modules. Review: https://reviews.apache.org/r/44289/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cbbc8f0b Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cbbc8f0b Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cbbc8f0b Branch: refs/heads/master Commit: cbbc8f0ba622903fc0ee16f8fb9d587de067c4b3 Parents: 9c3a8a5 Author: Anurag Singh <anurag.prakash.si...@gmail.com> Authored: Wed Apr 6 15:08:44 2016 -0400 Committer: Kapil Arya <ka...@mesosphere.io> Committed: Wed Apr 6 18:36:18 2016 -0400 ---------------------------------------------------------------------- include/mesos/module/contender.hpp | 64 ++++++++++++++++++++++ include/mesos/module/detector.hpp | 64 ++++++++++++++++++++++ src/Makefile.am | 20 ++++++- src/examples/test_master_contender_module.cpp | 43 +++++++++++++++ src/examples/test_master_detector_module.cpp | 43 +++++++++++++++ src/local/local.cpp | 2 + src/master/contender/zookeeper.cpp | 4 ++ src/master/detector/zookeeper.cpp | 4 ++ src/module/manager.cpp | 2 + src/tests/module.cpp | 52 ++++++++++++++++++ src/tests/module.hpp | 2 + 11 files changed, 298 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/include/mesos/module/contender.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/module/contender.hpp b/include/mesos/module/contender.hpp new file mode 100644 index 0000000..f58c9d7 --- /dev/null +++ b/include/mesos/module/contender.hpp @@ -0,0 +1,64 @@ +// 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. + +#ifndef __MESOS_MODULE_CONTENDER_HPP__ +#define __MESOS_MODULE_CONTENDER_HPP__ + +#include <mesos/mesos.hpp> +#include <mesos/module.hpp> + +#include <mesos/master/contender.hpp> + +namespace mesos { +namespace modules { + +template <> +inline const char* kind<mesos::master::contender::MasterContender>() +{ + return "MasterContender"; +} + + +template <> +struct Module<mesos::master::contender::MasterContender> : ModuleBase +{ + Module( + const char* _moduleApiVersion, + const char* _mesosVersion, + const char* _authorName, + const char* _authorEmail, + const char* _description, + bool (*_compatible)(), + mesos::master::contender::MasterContender* + (*_create)(const Parameters& parameters)) + : ModuleBase( + _moduleApiVersion, + _mesosVersion, + mesos::modules::kind<mesos::master::contender::MasterContender>(), + _authorName, + _authorEmail, + _description, + _compatible), + create(_create) {} + + mesos::master::contender::MasterContender* (*create)( + const Parameters& parameters); +}; + +} // namespace modules { +} // namespace mesos { + +#endif // __MESOS_MODULE_CONTENDER_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/include/mesos/module/detector.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/module/detector.hpp b/include/mesos/module/detector.hpp new file mode 100644 index 0000000..184bf4b --- /dev/null +++ b/include/mesos/module/detector.hpp @@ -0,0 +1,64 @@ +// 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. + +#ifndef __MESOS_MODULE_DETECTOR_HPP__ +#define __MESOS_MODULE_DETECTOR_HPP__ + +#include <mesos/mesos.hpp> +#include <mesos/module.hpp> + +#include <mesos/master/detector.hpp> + +namespace mesos { +namespace modules { + +template <> +inline const char* kind<mesos::master::detector::MasterDetector>() +{ + return "MasterDetector"; +} + + +template <> +struct Module<mesos::master::detector::MasterDetector> : ModuleBase +{ + Module( + const char* _moduleApiVersion, + const char* _mesosVersion, + const char* _authorName, + const char* _authorEmail, + const char* _description, + bool (*_compatible)(), + mesos::master::detector::MasterDetector* + (*_create)(const Parameters& parameters)) + : ModuleBase( + _moduleApiVersion, + _mesosVersion, + mesos::modules::kind<mesos::master::detector::MasterDetector>(), + _authorName, + _authorEmail, + _description, + _compatible), + create(_create) {} + + mesos::master::detector::MasterDetector* (*create)( + const Parameters& parameters); +}; + +} // namespace modules { +} // namespace mesos { + +#endif // __MESOS_MODULE_DETECTOR_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 973302e..71c4308 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -475,7 +475,9 @@ masterdir = $(pkgincludedir)/master master_HEADERS = \ $(top_srcdir)/include/mesos/master/allocator.hpp \ - $(top_srcdir)/include/mesos/master/allocator.proto + $(top_srcdir)/include/mesos/master/allocator.proto \ + $(top_srcdir)/include/mesos/master/contender.hpp \ + $(top_srcdir)/include/mesos/master/detector.hpp nodist_master_HEADERS = \ ../include/mesos/master/allocator.pb.h @@ -495,7 +497,9 @@ module_HEADERS = \ $(top_srcdir)/include/mesos/module/module.hpp \ $(top_srcdir)/include/mesos/module/module.proto \ $(top_srcdir)/include/mesos/module/qos_controller.hpp \ - $(top_srcdir)/include/mesos/module/resource_estimator.hpp + $(top_srcdir)/include/mesos/module/resource_estimator.hpp \ + $(top_srcdir)/include/mesos/module/contender.hpp \ + $(top_srcdir)/include/mesos/module/detector.hpp nodist_module_HEADERS = \ ../include/mesos/module/module.pb.h @@ -1818,6 +1822,18 @@ libtestcontainer_logger_la_SOURCES = \ libtestcontainer_logger_la_CPPFLAGS = $(MESOS_CPPFLAGS) libtestcontainer_logger_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS) +# Library containing the test contender module. +noinst_LTLIBRARIES += libtestmastercontender.la +libtestmastercontender_la_SOURCES = examples/test_master_contender_module.cpp +libtestmastercontender_la_CPPFLAGS = $(MESOS_CPPFLAGS) +libtestmastercontender_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS) + +# Library containing the test detector module. +noinst_LTLIBRARIES += libtestmasterdetector.la +libtestmasterdetector_la_SOURCES = examples/test_master_detector_module.cpp +libtestmasterdetector_la_CPPFLAGS = $(MESOS_CPPFLAGS) +libtestmasterdetector_la_LDFLAGS = $(MESOS_TEST_MODULE_LDFLAGS) + # Library containing test Hook module. libtesthook_la_SOURCES = examples/test_hook_module.cpp libtesthook_la_CPPFLAGS = $(MESOS_CPPFLAGS) http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/examples/test_master_contender_module.cpp ---------------------------------------------------------------------- diff --git a/src/examples/test_master_contender_module.cpp b/src/examples/test_master_contender_module.cpp new file mode 100644 index 0000000..d50d9d8 --- /dev/null +++ b/src/examples/test_master_contender_module.cpp @@ -0,0 +1,43 @@ +// 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/contender.hpp> + +#include <mesos/module/contender.hpp> + +#include <stout/try.hpp> + +#include "master/contender/standalone.hpp" + +using namespace mesos; +using namespace mesos::master; +using namespace mesos::master::contender; + +// Declares a MasterContender module named +// 'org_apache_mesos_TestMasterContender'. +mesos::modules::Module<MasterContender> org_apache_mesos_TestMasterContender( + MESOS_MODULE_API_VERSION, + MESOS_VERSION, + "Apache Mesos", + "modu...@mesos.apache.org", + "Test MasterContender module.", + NULL, + [](const Parameters& parameters) -> MasterContender* { + return new StandaloneMasterContender(); + }); http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/examples/test_master_detector_module.cpp ---------------------------------------------------------------------- diff --git a/src/examples/test_master_detector_module.cpp b/src/examples/test_master_detector_module.cpp new file mode 100644 index 0000000..ff362db --- /dev/null +++ b/src/examples/test_master_detector_module.cpp @@ -0,0 +1,43 @@ +// 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/detector.hpp> + +#include <mesos/module/detector.hpp> + +#include <stout/try.hpp> + +#include "master/detector/standalone.hpp" + +using namespace mesos; +using namespace mesos::master; +using namespace mesos::master::detector; + +// Declares a MasterDetector module named +// 'org_apache_mesos_TestMasterDetector'. +mesos::modules::Module<MasterDetector> org_apache_mesos_TestMasterDetector( + MESOS_MODULE_API_VERSION, + MESOS_VERSION, + "Apache Mesos", + "modu...@mesos.apache.org", + "Test MasterDetector module.", + NULL, + [](const Parameters& parameters) -> MasterDetector* { + return new StandaloneMasterDetector(); + }); http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/local/local.cpp ---------------------------------------------------------------------- diff --git a/src/local/local.cpp b/src/local/local.cpp index 5165b33..df72ac5 100644 --- a/src/local/local.cpp +++ b/src/local/local.cpp @@ -27,6 +27,8 @@ #include <mesos/module/anonymous.hpp> #include <mesos/module/authorizer.hpp> +#include <mesos/module/contender.hpp> +#include <mesos/module/detector.hpp> #include <mesos/slave/resource_estimator.hpp> http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/master/contender/zookeeper.cpp ---------------------------------------------------------------------- diff --git a/src/master/contender/zookeeper.cpp b/src/master/contender/zookeeper.cpp index 59bca91..847c62e 100644 --- a/src/master/contender/zookeeper.cpp +++ b/src/master/contender/zookeeper.cpp @@ -16,6 +16,8 @@ #include <mesos/master/contender.hpp> +#include <mesos/module/contender.hpp> + #include <process/defer.hpp> #include <process/id.hpp> #include <process/process.hpp> @@ -26,6 +28,8 @@ #include "master/constants.hpp" #include "master/master.hpp" +#include "module/manager.hpp" + #include "zookeeper/contender.hpp" #include "zookeeper/detector.hpp" #include "zookeeper/group.hpp" http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/master/detector/zookeeper.cpp ---------------------------------------------------------------------- diff --git a/src/master/detector/zookeeper.cpp b/src/master/detector/zookeeper.cpp index 8f226b5..519a102 100644 --- a/src/master/detector/zookeeper.cpp +++ b/src/master/detector/zookeeper.cpp @@ -19,6 +19,8 @@ #include <mesos/master/detector.hpp> +#include <mesos/module/detector.hpp> + #include <process/defer.hpp> #include <process/dispatch.hpp> #include <process/future.hpp> @@ -41,6 +43,8 @@ #include "messages/messages.hpp" +#include "module/manager.hpp" + #include "zookeeper/detector.hpp" #include "zookeeper/group.hpp" #include "zookeeper/url.hpp" http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/module/manager.cpp ---------------------------------------------------------------------- diff --git a/src/module/manager.cpp b/src/module/manager.cpp index 7850fd3..9f88ec3 100644 --- a/src/module/manager.cpp +++ b/src/module/manager.cpp @@ -73,6 +73,8 @@ void ModuleManager::initialize() kindToVersion["Hook"] = MESOS_VERSION; kindToVersion["HttpAuthenticator"] = MESOS_VERSION; kindToVersion["Isolator"] = MESOS_VERSION; + kindToVersion["MasterContender"] = MESOS_VERSION; + kindToVersion["MasterDetector"] = MESOS_VERSION; kindToVersion["QoSController"] = MESOS_VERSION; kindToVersion["ResourceEstimator"] = MESOS_VERSION; kindToVersion["TestModule"] = MESOS_VERSION; http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/tests/module.cpp ---------------------------------------------------------------------- diff --git a/src/tests/module.cpp b/src/tests/module.cpp index 8cc305c..4b24048 100644 --- a/src/tests/module.cpp +++ b/src/tests/module.cpp @@ -222,6 +222,52 @@ static void addHttpAuthenticatorModules(Modules* modules) } +static void addMasterContenderModules(Modules* modules) +{ + CHECK_NOTNULL(modules); + + const string libraryPath = path::join( + tests::flags.build_dir, + "src", + ".libs", + os::libraries::expandName("testmastercontender")); + + // Now add our test anonymous 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, + TestMasterContender, + "org_apache_mesos_TestMasterContender"); +} + + +static void addMasterDetectorModules(Modules* modules) +{ + CHECK_NOTNULL(modules); + + const string libraryPath = path::join( + tests::flags.build_dir, + "src", + ".libs", + os::libraries::expandName("testmasterdetector")); + + // Now add our test anonymous 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, + TestMasterDetector, + "org_apache_mesos_TestMasterDetector"); +} + + Try<Nothing> initModules(const Option<Modules>& modules) { // First get the user provided modules. @@ -257,6 +303,12 @@ Try<Nothing> initModules(const Option<Modules>& modules) // Add HTTP authenticator modules from testhttpauthenticator library. addHttpAuthenticatorModules(&mergedModules); + // Add MasterContender module from testmastercontender library. + addMasterContenderModules(&mergedModules); + + // Add MasterDetector module from testmasterdetector library. + addMasterDetectorModules(&mergedModules); + return ModuleManager::load(mergedModules); } http://git-wip-us.apache.org/repos/asf/mesos/blob/cbbc8f0b/src/tests/module.hpp ---------------------------------------------------------------------- diff --git a/src/tests/module.hpp b/src/tests/module.hpp index 4b32f29..e661d95 100644 --- a/src/tests/module.hpp +++ b/src/tests/module.hpp @@ -49,6 +49,8 @@ enum ModuleID TestNoopResourceEstimator, TestLocalAuthorizer, TestSandboxContainerLogger, + TestMasterContender, + TestMasterDetector, LogrotateContainerLogger, TestHttpBasicAuthenticator };