You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/11/25 22:18:18 UTC

mesos git commit: Quota: Added a force flag to override capacityHeuristic check.

Repository: mesos
Updated Branches:
  refs/heads/master 6fbcd7663 -> 0efadbafa


Quota: Added a force flag to override capacityHeuristic check.

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


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

Branch: refs/heads/master
Commit: 0efadbafada3bec2dcbda3360774649250c9b02e
Parents: 6fbcd76
Author: Joerg Schad <jo...@mesosphere.io>
Authored: Wed Nov 25 16:00:31 2015 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Wed Nov 25 16:17:53 2015 -0500

----------------------------------------------------------------------
 src/master/quota_handler.cpp     | 16 +++++++---
 src/tests/master_quota_tests.cpp | 59 +++++++++++++++++++++++++++++++++--
 2 files changed, 67 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0efadbaf/src/master/quota_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index b8e501b..31ebd91 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -27,6 +27,7 @@
 
 #include <stout/json.hpp>
 #include <stout/protobuf.hpp>
+#include <stout/strings.hpp>
 
 #include "logging/logging.hpp"
 
@@ -221,11 +222,16 @@ Future<http::Response> Master::QuotaHandler::set(
 
   const QuotaInfo& quotaInfo = create.get();
 
-  // Validate whether a quota request can be satisfied.
-  Option<Error> error = capacityHeuristic(quotaInfo);
-  if (error.isSome()) {
-    return Conflict("Heuristic capacity check for set quota request failed: " +
-                    error.get().message);
+  // The force flag can be used to overwrite the capacityHeuristic check.
+  if (values.contains("force") && strings::lower(values["force"]) == "true") {
+    VLOG(1) << "Using force flag to override quota capacityHeuristic check";
+  } else {
+    // Validate whether a quota request can be satisfied.
+    Option<Error> error = capacityHeuristic(quotaInfo);
+    if (error.isSome()) {
+      return Conflict("Heuristic capacity check for set quota request "
+                      "failed: " + error.get().message);
+    }
   }
 
   // Populate master's quota-related local state. We do this before updating

http://git-wip-us.apache.org/repos/asf/mesos/blob/0efadbaf/src/tests/master_quota_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index 16b291d..c2b73d5 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -121,12 +121,19 @@ protected:
   }
 
   // Generates a quota request from the specified resources.
-  string createRequestBody(const Resources& resources) const
+  string createRequestBody(const Resources& resources, bool force = false) const
   {
-    return strings::format("resources=%s", JSON::protobuf(
+    string request = strings::format("resources=%s", JSON::protobuf(
         static_cast<const RepeatedPtrField<Resource>&>(resources))).get();
+
+    if (force) {
+      request += "&force=true";
+    }
+
+    return request;
   }
 
+
 protected:
   const std::string ROLE1{"role1"};
   const std::string ROLE2{"role2"};
@@ -428,7 +435,6 @@ TEST_F(MasterQuotaTest, SetInvalidResourceInfos)
 //   * Multiple quotas in the cluster, sufficient free resources for a new
 //     request, but some resources are blocked in outstanding offers
 //     (rescinding).
-//   * Sanity check is disabled with the `--force` flag.
 //   * Deactivated or disconnected agents are not considered during quota
 //     capability heuristics.
 
@@ -480,6 +486,53 @@ TEST_F(MasterQuotaTest, InsufficientResourcesSingleAgent)
 }
 
 
+// Checks that the force flag overrides the `capacityHeuristic` check.
+TEST_F(MasterQuotaTest, InsufficientResourcesForce)
+{
+  TestAllocator<> allocator;
+  EXPECT_CALL(allocator, initialize(_, _, _, _));
+
+  Try<PID<Master>> master = StartMaster(&allocator);
+  ASSERT_SOME(master);
+
+  // Wait until the agent registers.
+  Future<Resources> agentTotalResources;
+  EXPECT_CALL(allocator, addSlave(_, _, _, _, _))
+    .WillOnce(DoAll(InvokeAddSlave(&allocator),
+                    FutureArg<3>(&agentTotalResources)));
+
+  Try<PID<Slave>> agent = StartSlave();
+  ASSERT_SOME(agent);
+
+  AWAIT_READY(agentTotalResources);
+  EXPECT_EQ(defaultAgentResources, agentTotalResources.get());
+
+  // Our quota request requires more resources than are available on the agent
+  // (and in the cluster).
+  Resources quotaResources =
+    agentTotalResources.get().filter(
+        [=](const Resource& resource) {
+          return (resource.name() == "cpus" || resource.name() == "mem");
+        }) +
+    Resources::parse("cpus:1;mem:1024").get();
+
+  quotaResources = quotaResources.flatten(ROLE1);
+
+  EXPECT_FALSE(agentTotalResources.get().contains(quotaResources.flatten()));
+
+  Future<Response> response = process::http::post(
+      master.get(),
+      "quota",
+      createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+      createRequestBody(quotaResources, true));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+    << response.get().body;
+
+  Shutdown();
+}
+
+
 // Checks that a quota request is not satisfied if there are not enough
 // resources.
 TEST_F(MasterQuotaTest, InsufficientResourcesMultipleAgents)