You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/07/18 03:25:31 UTC

[1/2] mesos git commit: Tested the per-role allocated resources in the agent endpoint.

Repository: mesos
Updated Branches:
  refs/heads/master 2120b76b1 -> 53fc25dd0


Tested the per-role allocated resources in the agent endpoint.

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


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

Branch: refs/heads/master
Commit: 197fc042ec0120bb872517c9faf7f08fb74837b1
Parents: 2120b76
Author: Andrei Budnik <ab...@mesosphere.com>
Authored: Mon Jul 17 20:07:04 2017 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Jul 17 20:07:32 2017 -0700

----------------------------------------------------------------------
 src/tests/reservation_endpoints_tests.cpp | 112 +++++++++++++++++++++++--
 1 file changed, 107 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/197fc042/src/tests/reservation_endpoints_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_endpoints_tests.cpp b/src/tests/reservation_endpoints_tests.cpp
index 05b505f..34ad48e 100644
--- a/src/tests/reservation_endpoints_tests.cpp
+++ b/src/tests/reservation_endpoints_tests.cpp
@@ -1528,17 +1528,17 @@ TEST_F(ReservationEndpointsTest, DifferentPrincipalsSameRole)
 }
 
 
-// This test verifies that unreserved resources and dynamic reservations are
-// reflected in the agent's "/state" endpoint. Separately exposing reservations
-// from the agent's endpoint is necessary because it's not a guarantee that
-// it matches the master's versions.
+// This test verifies that unreserved resources, dynamic reservations, allocated
+// resources per each role are reflected in the agent's "/state" endpoint.
+// Separately exposing reservations from the agent's endpoint is necessary
+// because it's not a guarantee that it matches the master's versions.
 TEST_F(ReservationEndpointsTest, AgentStateEndpointResources)
 {
   Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
-  slaveFlags.resources = "cpus:4;mem:2048;disk:4096";
+  slaveFlags.resources = "cpus:4;mem:2048;disk:4096;cpus(role):2;mem(role):512";
 
   Future<SlaveRegisteredMessage> slaveRegisteredMessage =
     FUTURE_PROTOBUF(SlaveRegisteredMessage(), master.get()->pid, _);
@@ -1578,6 +1578,40 @@ TEST_F(ReservationEndpointsTest, AgentStateEndpointResources)
   Clock::settle();
   Clock::resume();
 
+  FrameworkInfo frameworkInfo = createFrameworkInfo();
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(
+      &sched, frameworkInfo, master.get()->pid, DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(sched, registered(&driver, _, _));
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+  driver.start();
+
+  AWAIT_READY(offers);
+  EXPECT_FALSE(offers->empty());
+
+  Offer offer = offers.get()[0];
+
+  Future<TaskStatus> status;
+  EXPECT_CALL(sched, statusUpdate(_, _))
+    .WillOnce(FutureArg<1>(&status));
+
+  Resources taskResources = Resources::parse(
+      "cpus(role):2;mem(role):512;cpus:2;mem:1024").get();
+
+  TaskInfo task = createTask(offer.slave_id(), taskResources, "sleep 1000");
+
+  driver.acceptOffers({offer.id()}, {LAUNCH({task})});
+
+  AWAIT_READY(status);
+  ASSERT_EQ(TASK_RUNNING, status->state());
+
   Future<Response> response = process::http::get(
       agent.get()->pid,
       "state",
@@ -1596,6 +1630,12 @@ TEST_F(ReservationEndpointsTest, AgentStateEndpointResources)
     JSON::Value expected = JSON::parse(
         R"~(
         {
+          "role": {
+            "cpus": 2.0,
+            "disk": 0.0,
+            "gpus": 0.0,
+            "mem": 512.0
+          },
           "role1": {
             "cpus": 1.0,
             "disk": 1024.0,
@@ -1611,6 +1651,21 @@ TEST_F(ReservationEndpointsTest, AgentStateEndpointResources)
     JSON::Value expected = JSON::parse(
         R"~(
         {
+          "role": {
+            "cpus": 2.0,
+            "disk": 0.0,
+            "gpus": 0.0,
+            "mem": 512.0
+          }
+        })~").get();
+
+    EXPECT_EQ(expected, state.values["reserved_resources_allocated"]);
+  }
+
+  {
+    JSON::Value expected = JSON::parse(
+        R"~(
+        {
           "cpus": 3.0,
           "disk": 3072.0,
           "gpus": 0.0,
@@ -1622,9 +1677,53 @@ TEST_F(ReservationEndpointsTest, AgentStateEndpointResources)
   }
 
   {
+    // NOTE: executor consumes extra 0.1 cpus and 32.0 mem
+    JSON::Value expected = JSON::parse(
+        R"~(
+        {
+          "cpus": 2.1,
+          "disk": 0.0,
+          "gpus": 0.0,
+          "mem": 1056.0
+        })~").get();
+
+    EXPECT_EQ(expected, state.values["unreserved_resources_allocated"]);
+  }
+
+  {
     JSON::Value expected = JSON::parse(strings::format(
         R"~(
         {
+          "role": [
+            {
+              "name": "cpus",
+              "type": "SCALAR",
+              "scalar": {
+                "value": 2.0
+              },
+              "role": "role",
+              "reservations": [
+                {
+                  "role": "role",
+                  "type": "STATIC"
+                }
+              ]
+            },
+            {
+              "name": "mem",
+              "type": "SCALAR",
+              "scalar": {
+                "value": 512.0
+              },
+              "role": "role",
+              "reservations": [
+                {
+                  "role": "role",
+                  "type": "STATIC"
+                }
+              ]
+            }
+          ],
           "role1": [
             {
               "name": "cpus",
@@ -1737,6 +1836,9 @@ TEST_F(ReservationEndpointsTest, AgentStateEndpointResources)
 
     EXPECT_EQ(expected, state.values["unreserved_resources_full"]);
   }
+
+  driver.stop();
+  driver.join();
 }
 
 } // namespace tests {


[2/2] mesos git commit: Removed a misleading comment in the reservation endpoint tests.

Posted by bm...@apache.org.
Removed a misleading comment in the reservation endpoint tests.

This comment seemed to suggest that the reason for exposing
the reserved resources in the agent endpoint was that because
it is only *eventually* consistent with the master's state.
However, we expose agent state in both agent and master
endpoints because of the differing availability and performance
of the two components, as well as because the state is distributed
across the two (and we want to show the state at each distribution
point).


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

Branch: refs/heads/master
Commit: 53fc25dd0c83d4d5995a23e6fd383f3d3ae86f41
Parents: 197fc04
Author: Benjamin Mahler <bm...@apache.org>
Authored: Mon Jul 17 20:09:04 2017 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Jul 17 20:09:04 2017 -0700

----------------------------------------------------------------------
 src/tests/reservation_endpoints_tests.cpp | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/53fc25dd/src/tests/reservation_endpoints_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_endpoints_tests.cpp b/src/tests/reservation_endpoints_tests.cpp
index 34ad48e..3278732 100644
--- a/src/tests/reservation_endpoints_tests.cpp
+++ b/src/tests/reservation_endpoints_tests.cpp
@@ -1530,8 +1530,6 @@ TEST_F(ReservationEndpointsTest, DifferentPrincipalsSameRole)
 
 // This test verifies that unreserved resources, dynamic reservations, allocated
 // resources per each role are reflected in the agent's "/state" endpoint.
-// Separately exposing reservations from the agent's endpoint is necessary
-// because it's not a guarantee that it matches the master's versions.
 TEST_F(ReservationEndpointsTest, AgentStateEndpointResources)
 {
   Try<Owned<cluster::Master>> master = StartMaster();