Repository: mesos
Updated Branches:
  refs/heads/master 37dc886ee -> f9fe7f47c


Added helper function for /containers endpoint.

The helper function returns JSON::Array, which can be
reused by v1 Operator API GET_CONTAINERS.

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


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

Branch: refs/heads/master
Commit: c34d55c098737994d45482ea10cf38443d563bfe
Parents: 37dc886
Author: Jay Guo <guojian...@cn.ibm.com>
Authored: Mon Jun 27 23:41:15 2016 -0700
Committer: Vinod Kone <vinodk...@gmail.com>
Committed: Mon Jun 27 23:41:15 2016 -0700

----------------------------------------------------------------------
 src/slave/http.cpp  | 33 ++++++++++++++++++++++++---------
 src/slave/slave.hpp |  3 +++
 2 files changed, 27 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c34d55c0/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 30006c2..4917416 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -1148,6 +1148,27 @@ Future<Response> Slave::Http::containers(
 
 Future<Response> Slave::Http::_containers(const Request& request) const
 {
+  return __containers()
+      .then([request](const Future<JSON::Array>& result) -> Future<Response> {
+        if (!result.isReady()) {
+          LOG(WARNING) << "Could not collect container status and statistics: "
+                       << (result.isFailed()
+                            ? result.failure()
+                            : "Discarded");
+
+          return result.isFailed()
+            ? InternalServerError(result.failure())
+            : InternalServerError();
+        }
+
+        return process::http::OK(
+            result.get(), request.url.query.get("jsonp"));
+      });
+}
+
+
+Future<JSON::Array> Slave::Http::__containers() const
+{
   Owned<list<JSON::Object>> metadata(new list<JSON::Object>());
   list<Future<ContainerStatus>> statusFutures;
   list<Future<ResourceStatistics>> statsFutures;
@@ -1171,10 +1192,10 @@ Future<Response> Slave::Http::_containers(const 
Request& request) const
   }
 
   return await(await(statusFutures), await(statsFutures)).then(
-      [metadata, request](const tuple<
+      [metadata](const tuple<
           Future<list<Future<ContainerStatus>>>,
           Future<list<Future<ResourceStatistics>>>>& t)
-          -> Future<Response> {
+          -> Future<JSON::Array> {
         const list<Future<ContainerStatus>>& status = std::get<0>(t).get();
         const list<Future<ResourceStatistics>>& stats = std::get<1>(t).get();
         CHECK_EQ(status.size(), stats.size());
@@ -1222,13 +1243,7 @@ Future<Response> Slave::Http::_containers(const Request& 
request) const
           metadataIter++;
         }
 
-        return process::http::OK(result, request.url.query.get("jsonp"));
-      })
-      .repair([](const Future<Response>& future) {
-        LOG(WARNING) << "Could not collect container status and statistics: "
-                     << future.failure();
-
-        return InternalServerError();
+        return result;
       });
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c34d55c0/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 58ff2bf..383fb08 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -496,6 +496,9 @@ private:
     process::Future<process::http::Response> _containers(
         const process::http::Request& request) const;
 
+    // Helper function to collect containers status and resource statistics.
+    process::Future<JSON::Array> __containers() const;
+
     // Helper routines for endpoint authorization.
     Try<std::string> extractEndpoint(const process::http::URL& url) const;
 

Reply via email to