You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/05/28 23:56:23 UTC

mesos git commit: Removed inconsistency from routing endpoints in agent code.

Repository: mesos
Updated Branches:
  refs/heads/master 6aca482b8 -> 0a6862571


Removed inconsistency from routing endpoints in agent code.

The master and agent code for routing endpoints are made
consistent. Now they both capture 'this' variable in the
lambda calls in routing function arguments. Continuations
are no longer need to be static.

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


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

Branch: refs/heads/master
Commit: 0a68625713189415fdf4913dab844207a2289cd3
Parents: 6aca482
Author: Abhishek Dasgupta <a1...@linux.vnet.ibm.com>
Authored: Sat May 28 16:38:34 2016 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Sat May 28 16:56:23 2016 -0700

----------------------------------------------------------------------
 src/slave/http.cpp  | 46 ++++++++++++++++------------------------------
 src/slave/slave.cpp | 19 +++++++++----------
 src/slave/slave.hpp | 16 ++++++++--------
 3 files changed, 33 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0a686257/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index dd1f509..64a99d5 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -366,8 +366,6 @@ Future<Response> Slave::Http::flags(
     return MethodNotAllowed({"GET"}, request.method);
   }
 
-  const Flags slaveFlags = slave->flags;
-
   Try<string> endpoint = extractEndpoint(request.url);
   if (endpoint.isError()) {
     return Failure("Failed to extract endpoint: " + endpoint.error());
@@ -376,26 +374,24 @@ Future<Response> Slave::Http::flags(
   return authorizeEndpoint(principal, endpoint.get(), request.method)
     .then(defer(
         slave->self(),
-        [request, slaveFlags](bool authorized) -> Future<Response> {
+        [this, request](bool authorized) -> Future<Response> {
           if (!authorized) {
             return Forbidden();
           }
 
-          return _flags(request, slaveFlags);
+          return _flags(request);
         }));
 }
 
 
-Future<Response> Slave::Http::_flags(
-  const Request& request,
-  const Flags& slaveFlags)
+Future<Response> Slave::Http::_flags(const Request& request) const
 {
   JSON::Object object;
 
   {
     JSON::Object flags;
-    foreachvalue (const flags::Flag& flag, slaveFlags) {
-      Option<string> value = flag.stringify(slaveFlags);
+    foreachvalue (const flags::Flag& flag, slave->flags) {
+      Option<string> value = flag.stringify(slave->flags);
       if (value.isSome()) {
         flags.values[flag.effective_name().value] = value.get();
       }
@@ -648,9 +644,6 @@ Future<Response> Slave::Http::statistics(
     return MethodNotAllowed({"GET"}, request.method);
   }
 
-  const PID<Slave> pid = slave->self();
-  Shared<RateLimiter> limiter = statisticsLimiter;
-
   Try<string> endpoint = extractEndpoint(request.url);
   if (endpoint.isError()) {
     return Failure("Failed to extract endpoint: " + endpoint.error());
@@ -658,15 +651,16 @@ Future<Response> Slave::Http::statistics(
 
   return authorizeEndpoint(principal, endpoint.get(), request.method)
     .then(defer(
-        pid,
-        [pid, limiter, request](bool authorized) -> Future<Response> {
+        slave->self(),
+        [this, request](bool authorized) -> Future<Response> {
           if (!authorized) {
             return Forbidden();
           }
 
-          return limiter->acquire()
-            .then(defer(pid, &Slave::usage))
-            .then(defer(pid, [request](const ResourceUsage& usage) {
+          return statisticsLimiter->acquire()
+            .then(defer(slave->self(), &Slave::usage))
+            .then(defer(slave->self(),
+                  [this, request](const ResourceUsage& usage) {
               return _statistics(usage, request);
             }));
         }))
@@ -681,7 +675,7 @@ Future<Response> Slave::Http::statistics(
 
 Response Slave::Http::_statistics(
     const ResourceUsage& usage,
-    const Request& request)
+    const Request& request) const
 {
   JSON::Array result;
 
@@ -766,28 +760,20 @@ Future<Response> Slave::Http::containers(
     return Failure("Failed to extract endpoint: " + endpoint.error());
   }
 
-  const PID<Slave> pid = slave->self();
-
-  // NOTE: We should not leak the slave instance because the its
-  // lifetime is not guaranteed. See MESOS-5293 for details.
-  const Slave* localSlave = slave;
-
   return authorizeEndpoint(principal, endpoint.get(), request.method)
     .then(defer(
-        pid,
-        [pid, localSlave, request](bool authorized) -> Future<Response> {
+        slave->self(),
+        [this, request](bool authorized) -> Future<Response> {
           if (!authorized) {
             return Forbidden();
           }
 
-          return _containers(request, localSlave);
+          return _containers(request);
         }));
 }
 
 
-Future<Response> Slave::Http::_containers(
-    const Request& request,
-    const Slave* slave)
+Future<Response> Slave::Http::_containers(const Request& request) const
 {
   Owned<list<JSON::Object>> metadata(new list<JSON::Object>());
   list<Future<ContainerStatus>> statusFutures;

http://git-wip-us.apache.org/repos/asf/mesos/blob/0a686257/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 9fcf334..97d15da 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -149,6 +149,7 @@ Slave::Slave(const std::string& id,
   : ProcessBase(id),
     state(RECOVERING),
     flags(_flags),
+    http(this),
     completedFrameworks(MAX_COMPLETED_FRAMEWORKS),
     detector(_detector),
     containerizer(_containerizer),
@@ -700,12 +701,10 @@ void Slave::initialize()
       &Slave::ping,
       &PingSlaveMessage::connected);
 
-  // Setup HTTP routes.
-  Http http = Http(this);
 
   route("/api/v1/executor",
         Http::EXECUTOR_HELP(),
-        [http](const process::http::Request& request) {
+        [this](const process::http::Request& request) {
           Http::log(request);
           return http.executor(request);
         });
@@ -715,7 +714,7 @@ void Slave::initialize()
   route("/state.json",
         DEFAULT_HTTP_AUTHENTICATION_REALM,
         Http::STATE_HELP(),
-        [http](const process::http::Request& request,
+        [this](const process::http::Request& request,
                const Option<string>& principal) {
           Http::log(request);
           return http.state(request, principal);
@@ -723,7 +722,7 @@ void Slave::initialize()
   route("/state",
         DEFAULT_HTTP_AUTHENTICATION_REALM,
         Http::STATE_HELP(),
-        [http](const process::http::Request& request,
+        [this](const process::http::Request& request,
                const Option<string>& principal) {
           Http::log(request);
           return http.state(request, principal);
@@ -731,20 +730,20 @@ void Slave::initialize()
   route("/flags",
         DEFAULT_HTTP_AUTHENTICATION_REALM,
         Http::FLAGS_HELP(),
-        [http](const process::http::Request& request,
+        [this](const process::http::Request& request,
                const Option<string>& principal) {
           Http::log(request);
           return http.flags(request, principal);
         });
   route("/health",
         Http::HEALTH_HELP(),
-        [http](const process::http::Request& request) {
+        [this](const process::http::Request& request) {
           return http.health(request);
         });
   route("/monitor/statistics",
         DEFAULT_HTTP_AUTHENTICATION_REALM,
         Http::STATISTICS_HELP(),
-        [http](const process::http::Request& request,
+        [this](const process::http::Request& request,
                const Option<string>& principal) {
           return http.statistics(request, principal);
         });
@@ -753,14 +752,14 @@ void Slave::initialize()
   route("/monitor/statistics.json",
         DEFAULT_HTTP_AUTHENTICATION_REALM,
         Http::STATISTICS_HELP(),
-        [http](const process::http::Request& request,
+        [this](const process::http::Request& request,
                const Option<string>& principal) {
           return http.statistics(request, principal);
         });
   route("/containers",
         DEFAULT_HTTP_AUTHENTICATION_REALM,
         Http::CONTAINERS_HELP(),
-        [http](const process::http::Request& request,
+        [this](const process::http::Request& request,
                const Option<string>& principal) {
           return http.containers(request, principal);
         });

http://git-wip-us.apache.org/repos/asf/mesos/blob/0a686257/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index f48e4b6..78a6ecf 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -474,20 +474,18 @@ private:
 
   private:
     // Continuations.
-    static process::Future<process::http::Response> _flags(
-        const process::http::Request& request,
-        const Flags& flags);
+    process::Future<process::http::Response> _flags(
+        const process::http::Request& request) const;
 
     // Make continuation for `statistics` `static` as it might
     // execute when the invoking `Http` is already destructed.
-    static process::http::Response _statistics(
+    process::http::Response _statistics(
         const ResourceUsage& usage,
-        const process::http::Request& request);
+        const process::http::Request& request) const;
 
     // Continuation for `/containers` endpoint
-    static process::Future<process::http::Response> _containers(
-        const process::http::Request& request,
-        const Slave* slave);
+    process::Future<process::http::Response> _containers(
+        const process::http::Request& request) const;
 
     // Helper routines for endpoint authorization.
     Try<std::string> extractEndpoint(const process::http::URL& url) const;
@@ -557,6 +555,8 @@ private:
 
   const Flags flags;
 
+  const Http http;
+
   SlaveInfo info;
 
   // Resources that are checkpointed by the slave.