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/03/28 01:35:11 UTC

[1/3] mesos git commit: Added quota to /roles endpoint of master.

Repository: mesos
Updated Branches:
  refs/heads/master 42f43ceb3 -> 52dfc2f00


Added quota to /roles endpoint of master.

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


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

Branch: refs/heads/master
Commit: 43108b575e5a5f18f3884fad91d137439ae82faa
Parents: 42f43ce
Author: Jay Guo <gu...@gmail.com>
Authored: Mon Mar 27 18:18:52 2017 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Mar 27 18:28:33 2017 -0700

----------------------------------------------------------------------
 src/common/http.cpp | 15 +++++++++++++++
 src/common/http.hpp |  3 +++
 src/master/http.cpp | 12 +++++++++++-
 3 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/43108b57/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index 7afbc61..98750a0 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -29,6 +29,7 @@
 #include <mesos/authentication/http/combined_authenticator.hpp>
 #include <mesos/authorizer/authorizer.hpp>
 #include <mesos/module/http_authenticator.hpp>
+#include <mesos/quota/quota.hpp>
 
 #include <process/authenticator.hpp>
 #include <process/dispatch.hpp>
@@ -491,6 +492,20 @@ JSON::Object model(const FileInfo& fileInfo)
   return file;
 }
 
+
+JSON::Object model(const quota::QuotaInfo& quotaInfo)
+{
+  JSON::Object object;
+
+  object.values["guarantee"] = model(quotaInfo.guarantee());
+  object.values["role"] = quotaInfo.role();
+  if (quotaInfo.has_principal()) {
+    object.values["principal"] = quotaInfo.principal();
+  }
+
+  return object;
+}
+
 }  // namespace internal {
 
 void json(JSON::ObjectWriter* writer, const Attributes& attributes)

http://git-wip-us.apache.org/repos/asf/mesos/blob/43108b57/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index 9a10312..b6e61f7 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -24,6 +24,8 @@
 
 #include <mesos/authorizer/authorizer.hpp>
 
+#include <mesos/quota/quota.hpp>
+
 #include <process/future.hpp>
 #include <process/http.hpp>
 #include <process/owned.hpp>
@@ -118,6 +120,7 @@ JSON::Object model(const ExecutorInfo& executorInfo);
 JSON::Array model(const Labels& labels);
 JSON::Object model(const Task& task);
 JSON::Object model(const FileInfo& fileInfo);
+JSON::Object model(const quota::QuotaInfo& quotaInfo);
 
 void json(JSON::ObjectWriter* writer, const Task& task);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/43108b57/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 862b68f..96409f6 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -3321,6 +3321,7 @@ Future<Response> Master::Http::stateSummary(
 JSON::Object model(
     const string& name,
     Option<double> weight,
+    Option<Quota> quota,
     Option<Role*> _role)
 {
   JSON::Object object;
@@ -3332,6 +3333,10 @@ JSON::Object model(
     object.values["weight"] = 1.0; // Default weight.
   }
 
+  if (quota.isSome()) {
+    object.values["quota"] = model(quota->info);
+  }
+
   if (_role.isNone()) {
     object.values["resources"] = model(Resources());
     object.values["frameworks"] = JSON::Array();
@@ -3468,12 +3473,17 @@ Future<Response> Master::Http::roles(
             weight = master->weights[name];
           }
 
+          Option<Quota> quota = None();
+          if (master->quotas.contains(name)) {
+            quota = master->quotas.at(name);
+          }
+
           Option<Role*> role = None();
           if (master->roles.contains(name)) {
             role = master->roles.at(name);
           }
 
-          array.values.push_back(model(name, weight, role));
+          array.values.push_back(model(name, weight, quota, role));
         }
 
         object.values["roles"] = std::move(array);


[3/3] mesos git commit: Modified WebUI to display quota under `roles` tab.

Posted by bm...@apache.org.
Modified WebUI to display quota under `roles` tab.

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


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

Branch: refs/heads/master
Commit: 52dfc2f0082756e480f3099adca1b2fa50180807
Parents: b66047f
Author: Jay Guo <gu...@gmail.com>
Authored: Mon Mar 27 18:31:17 2017 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Mar 27 18:33:18 2017 -0700

----------------------------------------------------------------------
 src/webui/master/static/roles.html | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/52dfc2f0/src/webui/master/static/roles.html
----------------------------------------------------------------------
diff --git a/src/webui/master/static/roles.html b/src/webui/master/static/roles.html
index a8ca03e..7578852 100644
--- a/src/webui/master/static/roles.html
+++ b/src/webui/master/static/roles.html
@@ -14,10 +14,10 @@
       <th data-key="name" data-sort>Role</th>
       <th data-key="weight">Weight</th>
       <th data-key="frameworks.length">Frameworks</th>
-      <th data-key="resources.cpus">CPUs</th>
-      <th data-key="resources.gpus">GPUs</th>
-      <th data-key="resources.mem">Mem</th>
-      <th data-key="resources.disk">Disk</th>
+      <th data-key="resources.cpus">CPUs (Allocated / Quota)</th>
+      <th data-key="resources.gpus">GPUs (Allocated / Quota)</th>
+      <th data-key="resources.mem">Mem (Allocated / Quota)</th>
+      <th data-key="resources.disk">Disk (Allocated / Quota)</th>
     </tr>
   </thead>
   <tbody>
@@ -25,10 +25,10 @@
       <td>{{role.name}}</td>
       <td>{{role.weight | number}}</td>
       <td>{{role.frameworks.length | number}}</td>
-      <td>{{role.resources.cpus | decimalFloat}}</td>
-      <td>{{role.resources.gpus | decimalFloat}}</td>
-      <td>{{role.resources.mem * (1024 * 1024) | dataSize}}</td>
-      <td>{{role.resources.disk * (1024 * 1024) | dataSize}}</td>
+      <td>{{role.resources.cpus | decimalFloat}} / {{(role.quota.guarantee.cpus || 0) | decimalFloat}}</td>
+      <td>{{role.resources.gpus | decimalFloat}} / {{(role.quota.guarantee.gpus || 0) | decimalFloat}}</td>
+      <td>{{role.resources.mem * (1024 * 1024) | dataSize}} / {{(role.quota.guarantee.mem || 0) * (1024 * 1024) | dataSize}}</td>
+      <td>{{role.resources.disk * (1024 * 1024) | dataSize}} / {{(role.quota.guarantee.disk || 0) * (1024 * 1024) | dataSize}}</td>
     </tr>
   </tbody>
 </table>


[2/3] mesos git commit: Added a test to check /roles endpoint of master includes quota info.

Posted by bm...@apache.org.
Added a test to check /roles endpoint of master includes quota info.

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


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

Branch: refs/heads/master
Commit: b66047f8c834ac404e8bd82c8f18c1b57f5958c2
Parents: 43108b5
Author: Jay Guo <gu...@gmail.com>
Authored: Mon Mar 27 18:30:30 2017 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Mar 27 18:31:03 2017 -0700

----------------------------------------------------------------------
 src/tests/role_tests.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b66047f8/src/tests/role_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/role_tests.cpp b/src/tests/role_tests.cpp
index 1d58d7b..0433c05 100644
--- a/src/tests/role_tests.cpp
+++ b/src/tests/role_tests.cpp
@@ -375,6 +375,77 @@ TEST_F(RoleTest, EndpointNoFrameworks)
 }
 
 
+// This test ensures that quota information is included
+// in /roles endpoint of master.
+TEST_F_TEMP_DISABLED_ON_WINDOWS(RoleTest, RolesEndpointContainsQuota)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
+
+  mesos::quota::QuotaRequest request;
+  request.set_role("foo");
+  request.mutable_guarantee()->CopyFrom(quotaResources);
+
+  // Use the force flag for setting quota that cannot be satisfied in
+  // this empty cluster without any agents.
+  request.set_force(true);
+
+  {
+    Future<Response> response = process::http::post(
+        master.get()->pid,
+        "quota",
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+        stringify(JSON::protobuf(request)));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+      << response->body;
+  }
+
+  // Query the master roles endpoint and check it contains quota.
+  {
+    Future<Response> response = process::http::get(
+        master.get()->pid,
+        "roles",
+        None(),
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+      << response->body;
+
+    Try<JSON::Object> parse = JSON::parse<JSON::Object>(response->body);
+    ASSERT_SOME(parse);
+
+    Result<JSON::Array> roles = parse->find<JSON::Array>("roles");
+    ASSERT_SOME(roles);
+    EXPECT_EQ(1u, roles->values.size());
+
+    JSON::Value role = roles->values[0].as<JSON::Value>();
+
+    Try<JSON::Value> expected = JSON::parse(
+        "{"
+          "\"quota\":"
+            "{"
+              "\"guarantee\":"
+                "{"
+                  "\"cpus\":1.0,"
+                  "\"disk\":0,"
+                  "\"gpus\":0,"
+                  "\"mem\":512.0"
+                "},"
+              "\"principal\":\"test-principal\","
+              "\"role\":\"foo\""
+            "}"
+        "}"
+    );
+    ASSERT_SOME(expected);
+
+    EXPECT_TRUE(role.contains(expected.get()));
+  }
+}
+
+
 // This test checks that when using implicit roles, the "/roles"
 // endpoint shows roles that have a configured weight even if they
 // have no registered frameworks.
@@ -541,7 +612,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(RoleTest, EndpointImplicitRolesQuotas)
       "}");
 
   ASSERT_SOME(expected);
-  EXPECT_EQ(expected.get(), parse.get());
+  EXPECT_TRUE(parse->contains(expected.get()));
 
   // Remove the quota, and check that the role no longer appears in
   // the "/roles" endpoint.