Repository: mesos Updated Branches: refs/heads/master 5a105893a -> fabf2edc8
Provided new overload of 'ProcessBase::route()'. Review: https://reviews.apache.org/r/65461/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6dbedb34 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6dbedb34 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6dbedb34 Branch: refs/heads/master Commit: 6dbedb34ec059eefae4391daf1b4f59c35ae95cf Parents: 5a10589 Author: Benno Evers <[email protected]> Authored: Fri Apr 13 13:12:45 2018 +0200 Committer: Alexander Rukletsov <[email protected]> Committed: Fri Apr 13 13:12:45 2018 +0200 ---------------------------------------------------------------------- 3rdparty/libprocess/include/process/logging.hpp | 10 +----- 3rdparty/libprocess/include/process/process.hpp | 32 ++++++++++++-------- .../libprocess/include/process/profiler.hpp | 32 ++++++-------------- 3rdparty/libprocess/src/metrics/metrics.cpp | 16 +++------- 4 files changed, 34 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/6dbedb34/3rdparty/libprocess/include/process/logging.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/logging.hpp b/3rdparty/libprocess/include/process/logging.hpp index f999767..aad7ce8 100644 --- a/3rdparty/libprocess/include/process/logging.hpp +++ b/3rdparty/libprocess/include/process/logging.hpp @@ -44,15 +44,7 @@ public: protected: virtual void initialize() { - if (authenticationRealm.isSome()) { - route("/toggle", authenticationRealm.get(), TOGGLE_HELP(), &This::toggle); - } else { - route("/toggle", - TOGGLE_HELP(), - [this](const http::Request& request) { - return This::toggle(request, None()); - }); - } + route("/toggle", authenticationRealm, TOGGLE_HELP(), &This::toggle); } private: http://git-wip-us.apache.org/repos/asf/mesos/blob/6dbedb34/3rdparty/libprocess/include/process/process.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/process.hpp b/3rdparty/libprocess/include/process/process.hpp index 8661706..c36df99 100644 --- a/3rdparty/libprocess/include/process/process.hpp +++ b/3rdparty/libprocess/include/process/process.hpp @@ -323,6 +323,8 @@ protected: AuthenticatedHttpRequestHandler; // TODO(arojas): Consider introducing an `authentication::Realm` type. + // TODO(bevers): Consider changing the type of the second argument to + // `const Option<std::string>&` for consistency with the version below. void route( const std::string& name, const std::string& realm, @@ -331,24 +333,30 @@ protected: const RouteOptions& options = RouteOptions()); /** - * @copydoc process::ProcessBase::route + * Forwards to the correct overload of `process::ProcessBase::route()`, + * depending on whether the authentication realm `realm` is present. */ - template <typename T> + template<typename T> void route( - const std::string& name, - const std::string& realm, - const Option<std::string>& help, - Future<http::Response> (T::*method)( - const http::Request&, - const Option<http::authentication::Principal>&), - const RouteOptions& options = RouteOptions()) + const std::string& name, + const Option<std::string>& realm, + const Option<std::string>& help, + Future<http::Response>(T::*method)( + const http::Request&, const Option<http::authentication::Principal>&), + const RouteOptions& options = RouteOptions()) { // Note that we use dynamic_cast here so a process can use // multiple inheritance if it sees so fit (e.g., to implement // multiple callback interfaces). - AuthenticatedHttpRequestHandler handler = - lambda::bind(method, dynamic_cast<T*>(this), lambda::_1, lambda::_2); - route(name, realm, help, handler, options); + if (realm.isSome()) { + AuthenticatedHttpRequestHandler handler = + lambda::bind(method, dynamic_cast<T*>(this), lambda::_1, lambda::_2); + route(name, realm.get(), help, handler, options); + } else { + HttpRequestHandler handler = + lambda::bind(method, dynamic_cast<T*>(this), lambda::_1, None()); + route(name, help, handler, options); + } } /** http://git-wip-us.apache.org/repos/asf/mesos/blob/6dbedb34/3rdparty/libprocess/include/process/profiler.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/profiler.hpp b/3rdparty/libprocess/include/process/profiler.hpp index 2991dd2..74890ae 100644 --- a/3rdparty/libprocess/include/process/profiler.hpp +++ b/3rdparty/libprocess/include/process/profiler.hpp @@ -33,29 +33,15 @@ public: protected: virtual void initialize() { - if (authenticationRealm.isSome()) { - route("/start", - authenticationRealm.get(), - START_HELP(), - &Profiler::start); - - route("/stop", - authenticationRealm.get(), - STOP_HELP(), - &Profiler::stop); - } else { - route("/start", - START_HELP(), - [this](const http::Request& request) { - return Profiler::start(request, None()); - }); - - route("/stop", - STOP_HELP(), - [this](const http::Request& request) { - return Profiler::stop(request, None()); - }); - } + route("/start", + authenticationRealm, + START_HELP(), + &Profiler::start); + + route("/stop", + authenticationRealm, + STOP_HELP(), + &Profiler::stop); } private: http://git-wip-us.apache.org/repos/asf/mesos/blob/6dbedb34/3rdparty/libprocess/src/metrics/metrics.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/metrics/metrics.cpp b/3rdparty/libprocess/src/metrics/metrics.cpp index 3a5bd3d..a5f78c3 100644 --- a/3rdparty/libprocess/src/metrics/metrics.cpp +++ b/3rdparty/libprocess/src/metrics/metrics.cpp @@ -96,18 +96,10 @@ MetricsProcess* MetricsProcess::create( void MetricsProcess::initialize() { - if (authenticationRealm.isSome()) { - route("/snapshot", - authenticationRealm.get(), - help(), - &MetricsProcess::_snapshot); - } else { - route("/snapshot", - help(), - [this](const http::Request& request) { - return _snapshot(request, None()); - }); - } + route("/snapshot", + authenticationRealm, + help(), + &MetricsProcess::_snapshot); }
