You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2018/04/13 11:25:28 UTC

[1/2] mesos git commit: Provided new overload of 'ProcessBase::route()'.

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 <be...@mesosphere.com>
Authored: Fri Apr 13 13:12:45 2018 +0200
Committer: Alexander Rukletsov <al...@apache.org>
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);
 }
 
 


[2/2] mesos git commit: Used the new 'route()' overload from libprocess.

Posted by al...@apache.org.
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 <be...@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: