Export "reserved_resources" in the agent HTTP endpoint.

Also the 'resource' field now exposes the total resources, which is
consistent with the same field in the master's /slaves endpoint.

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


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

Branch: refs/heads/master
Commit: cc27c3296905c95e0c83fa6510c401efbc998400
Parents: 06eea53
Author: Jiang Yan Xu <xuj...@apple.com>
Authored: Tue Sep 13 09:55:47 2016 -0700
Committer: Jiang Yan Xu <xuj...@apple.com>
Committed: Mon Sep 19 14:59:11 2016 -0700

----------------------------------------------------------------------
 src/slave/http.cpp  | 10 +++++++---
 src/slave/slave.cpp |  4 ++++
 2 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cc27c329/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index 427072d..e1ba653 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -980,14 +980,18 @@ Future<Response> Slave::Http::state(
         writer->field("pid", string(slave->self()));
         writer->field("hostname", slave->info.hostname());
 
-        writer->field("resources", Resources(slave->info.resources()));
+        const Resources& totalResources = slave->totalResources;
+
+        writer->field("resources", totalResources);
+        writer->field("reserved_resources", totalResources.reservations());
+        writer->field("unreserved_resources", totalResources.unreserved());
 
         writer->field(
             "reserved_resources_full",
-            [this](JSON::ObjectWriter* writer) {
+            [&totalResources](JSON::ObjectWriter* writer) {
               foreachpair (const string& role,
                            const Resources& resources,
-                           slave->totalResources.reservations()) {
+                           totalResources.reservations()) {
                 writer->field(role, [&resources](JSON::ArrayWriter* writer) {
                   foreach (const Resource& resource, resources) {
                     writer->element(JSON::Protobuf(resource));

http://git-wip-us.apache.org/repos/asf/mesos/blob/cc27c329/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 5ef5594..7a9a541a 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -526,6 +526,10 @@ void Slave::initialize()
         HookManager::slaveResourcesDecorator(info));
   }
 
+  // Initialize `totalResources` with `info.resources`, checkpointed
+  // resources will be applied later during recovery.
+  totalResources = resources.get();
+
   LOG(INFO) << "Agent resources: " << info.resources();
 
   info.mutable_attributes()->CopyFrom(attributes);

Reply via email to