Refactored 'Master::Http::getExecutors()' into helper function.

This helper function will be reused by `GetExecutors` and `GetState`.

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


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

Branch: refs/heads/master
Commit: 532f66a3a9c98bdb2259091851707cb9e42da0ea
Parents: 3a988e2
Author: Zhitao Li <zhitaoli...@gmail.com>
Authored: Tue Jul 5 21:25:53 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Tue Jul 5 22:32:57 2016 -0700

----------------------------------------------------------------------
 src/master/http.cpp   | 32 ++++++++++++++++++++++----------
 src/master/master.hpp |  3 +++
 2 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/532f66a3/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 7020095..7085b07 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -1425,6 +1425,23 @@ Future<Response> Master::Http::getExecutors(
 {
   CHECK_EQ(mesos::master::Call::GET_EXECUTORS, call.type());
 
+  return _getExecutors(principal)
+    .then(
+      [contentType](const mesos::master::Response::GetExecutors& getExecutors)
+        -> Future<Response> {
+      mesos::master::Response response;
+      response.set_type(mesos::master::Response::GET_EXECUTORS);
+      response.mutable_get_executors()->CopyFrom(getExecutors);
+
+      return OK(serialize(contentType, evolve(response)),
+                stringify(contentType));
+    });
+}
+
+
+Future<mesos::master::Response::GetExecutors> Master::Http::_getExecutors(
+    const Option<std::string>& principal) const
+{
   // Retrieve `ObjectApprover`s for authorizing frameworks and executors.
   Future<Owned<ObjectApprover>> frameworksApprover;
   Future<Owned<ObjectApprover>> executorsApprover;
@@ -1448,7 +1465,7 @@ Future<Response> Master::Http::getExecutors(
     .then(defer(master->self(),
         [=](const tuple<Owned<ObjectApprover>,
                         Owned<ObjectApprover>>& approvers)
-          -> Response {
+          -> Future<mesos::master::Response::GetExecutors> {
       // Get approver from tuple.
       Owned<ObjectApprover> frameworksApprover;
       Owned<ObjectApprover> executorsApprover;
@@ -1475,11 +1492,7 @@ Future<Response> Master::Http::getExecutors(
         frameworks.push_back(framework.get());
       }
 
-      mesos::master::Response response;
-      response.set_type(mesos::master::Response::GET_EXECUTORS);
-
-      mesos::master::Response::GetExecutors* getExecutors =
-        response.mutable_get_executors();
+      mesos::master::Response::GetExecutors getExecutors;
 
       foreach (const Framework* framework, frameworks) {
         foreachpair (const SlaveID& slaveId,
@@ -1494,7 +1507,7 @@ Future<Response> Master::Http::getExecutors(
             }
 
             mesos::master::Response::GetExecutors::Executor* executor =
-              getExecutors->add_executors();
+              getExecutors.add_executors();
 
             executor->mutable_executor_info()->CopyFrom(info);
             executor->mutable_slave_id()->CopyFrom(slaveId);
@@ -1515,7 +1528,7 @@ Future<Response> Master::Http::getExecutors(
           foreachvalue (const ExecutorInfo& info, executors) {
             if (!master->frameworks.registered.contains(frameworkId)) {
               mesos::master::Response::GetExecutors::Executor* executor =
-                getExecutors->add_orphan_executors();
+                getExecutors.add_orphan_executors();
 
               executor->mutable_executor_info()->CopyFrom(info);
               executor->mutable_slave_id()->CopyFrom(slave->id);
@@ -1524,8 +1537,7 @@ Future<Response> Master::Http::getExecutors(
         }
       }
 
-      return OK(serialize(contentType, evolve(response)),
-                stringify(contentType));
+      return getExecutors;
     }));
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/532f66a3/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 6f2a2b5..de64e3d 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1497,6 +1497,9 @@ private:
         const Option<std::string>& principal,
         ContentType contentType) const;
 
+    process::Future<mesos::master::Response::GetExecutors> _getExecutors(
+        const Option<std::string>& principal) const;
+
     Master* master;
 
     // NOTE: The quota specific pieces of the Operator API are factored

Reply via email to