Used the new 'route()' overload from libprocess. Review: https://reviews.apache.org/r/65462/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fabf2edc Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fabf2edc Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fabf2edc Branch: refs/heads/master Commit: fabf2edc83eae6b32048e22edc18fe4d8738dbe1 Parents: 6dbedb3 Author: Benno Evers <bev...@mesosphere.com> Authored: Fri Apr 13 13:13:12 2018 +0200 Committer: Alexander Rukletsov <al...@apache.org> Committed: Fri Apr 13 13:13:12 2018 +0200 ---------------------------------------------------------------------- src/files/files.cpp | 145 ++++++++++++++++++++---------------------- src/master/registrar.cpp | 10 +-- 2 files changed, 69 insertions(+), 86 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/fabf2edc/src/files/files.cpp ---------------------------------------------------------------------- diff --git a/src/files/files.cpp b/src/files/files.cpp index c392019..8d896ed 100644 --- a/src/files/files.cpp +++ b/src/files/files.cpp @@ -172,6 +172,23 @@ private: const http::Request& request, const Option<Principal>& principal); + // These functions log the request before continuing to the actual function. + Future<http::Response> loggedBrowse( + const http::Request& request, + const Option<Principal>& principal); + + Future<http::Response> loggedRead( + const http::Request& request, + const Option<Principal>& principal); + + Future<http::Response> loggedDownload( + const http::Request& request, + const Option<Principal>& principal); + + Future<http::Response> loggedDebug( + const http::Request& request, + const Option<Principal>& principal); + const static string BROWSE_HELP; const static string READ_HELP; const static string DOWNLOAD_HELP; @@ -205,103 +222,77 @@ FilesProcess::FilesProcess( void FilesProcess::initialize() { - if (authenticationRealm.isSome()) { - auto browse_ = [this]( - const http::Request& request, - const Option<Principal>& principal) { - logRequest(request); - return _browse(request, principal); - }; - - auto read_ = [this]( - const http::Request& request, - const Option<Principal>& principal) { - logRequest(request); - return __read(request, principal); - }; - - auto download_ = [this]( - const http::Request& request, - const Option<Principal>& principal) { - logRequest(request); - return download(request, principal); - }; - - auto debug_ = [this]( - const http::Request& request, - const Option<Principal>& principal) { - logRequest(request); - return debug(request, principal); - }; - // TODO(ijimenez): Remove these endpoints at the end of the // deprecation cycle on 0.26. route("/browse.json", - authenticationRealm.get(), + authenticationRealm, FilesProcess::BROWSE_HELP, - browse_); + &FilesProcess::loggedBrowse); route("/read.json", - authenticationRealm.get(), + authenticationRealm, FilesProcess::READ_HELP, - read_); + &FilesProcess::loggedRead); route("/download.json", - authenticationRealm.get(), + authenticationRealm, FilesProcess::DOWNLOAD_HELP, - download_); + &FilesProcess::loggedDownload); route("/debug.json", - authenticationRealm.get(), + authenticationRealm, FilesProcess::DEBUG_HELP, - debug_); + &FilesProcess::loggedDebug); route("/browse", - authenticationRealm.get(), + authenticationRealm, FilesProcess::BROWSE_HELP, - browse_); + &FilesProcess::loggedBrowse); route("/read", - authenticationRealm.get(), + authenticationRealm, FilesProcess::READ_HELP, - read_); + &FilesProcess::loggedRead); route("/download", - authenticationRealm.get(), + authenticationRealm, FilesProcess::DOWNLOAD_HELP, - download_); + &FilesProcess::loggedDownload); route("/debug", - authenticationRealm.get(), + authenticationRealm, FilesProcess::DEBUG_HELP, - debug_); - } else { - auto browse_ = [this](const http::Request& request) { - logRequest(request); - return _browse(request, None()); - }; - - auto read_ = [this](const http::Request& request) { - logRequest(request); - return __read(request, None()); - }; - - auto download_ = [this](const http::Request& request) { - logRequest(request); - return download(request, None()); - }; - - auto debug_ = [this](const http::Request& request) { - logRequest(request); - return debug(request, None()); - }; + &FilesProcess::loggedDebug); +} - // TODO(ijimenez): Remove these endpoints at the end of the - // deprecation cycle on 0.26. - route("/browse.json", FilesProcess::BROWSE_HELP, browse_); - route("/read.json", FilesProcess::READ_HELP, read_); - route("/download.json", FilesProcess::DOWNLOAD_HELP, download_); - route("/debug.json", FilesProcess::DEBUG_HELP, debug_); - - route("/browse", FilesProcess::BROWSE_HELP, browse_); - route("/read", FilesProcess::READ_HELP, read_); - route("/download", FilesProcess::DOWNLOAD_HELP, download_); - route("/debug", FilesProcess::DEBUG_HELP, debug_); - } + +Future<http::Response> FilesProcess::loggedBrowse( + const http::Request& request, + const Option<Principal>& principal) +{ + logRequest(request); + return _browse(request, principal); +} + + +Future<http::Response> FilesProcess::loggedRead( + const http::Request& request, + const Option<Principal>& principal) +{ + logRequest(request); + return __read(request, principal); +} + + +Future<http::Response> FilesProcess::loggedDownload( + const http::Request& request, + const Option<Principal>& principal) +{ + logRequest(request); + return download(request, principal); +} + + +Future<http::Response> FilesProcess::loggedDebug( + const http::Request& request, + const Option<Principal>& principal) +{ + logRequest(request); + return debug(request, principal); } http://git-wip-us.apache.org/repos/asf/mesos/blob/fabf2edc/src/master/registrar.cpp ---------------------------------------------------------------------- diff --git a/src/master/registrar.cpp b/src/master/registrar.cpp index a835142..b0c2817 100644 --- a/src/master/registrar.cpp +++ b/src/master/registrar.cpp @@ -105,19 +105,11 @@ public: protected: virtual void initialize() { - if (authenticationRealm.isSome()) { route( "/registry", - authenticationRealm.get(), + authenticationRealm, registryHelp(), &RegistrarProcess::getRegistry); - } else { - route( - "/registry", - registryHelp(), - lambda::bind( - &RegistrarProcess::getRegistry, this, lambda::_1, None())); - } } private: