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 2016/01/15 23:58:03 UTC
[1/3] mesos git commit: Quota: Cleaned up tests.
Repository: mesos
Updated Branches:
refs/heads/master 579edcc85 -> b075f415a
Quota: Cleaned up tests.
Changes made:
- removed extra ';' in resources string;
- renamed variables for clarity;
- updated comments;
- removed explicit conversion to `Resources`;
- wrapped test cases in {} blocks.
Review: https://reviews.apache.org/r/41938/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e23429c8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e23429c8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e23429c8
Branch: refs/heads/master
Commit: e23429c80b01a1f01266a5184daac8007763c2b8
Parents: 579edcc
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Fri Jan 15 17:34:01 2016 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Fri Jan 15 17:46:25 2016 -0500
----------------------------------------------------------------------
src/tests/master_quota_tests.cpp | 139 +++++++++++++++++++---------------
src/tests/registrar_tests.cpp | 46 +++++------
2 files changed, 99 insertions(+), 86 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e23429c8/src/tests/master_quota_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index df9622f..53bcfde 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -150,6 +150,7 @@ protected:
// while irrelevant fields are not present.
// TODO(alexr): Tests to implement:
+// * Implicit roles are used in the master.
// * Role is absent.
// * Role is an empty string.
// * Role is '*'?
@@ -157,7 +158,7 @@ protected:
// Verifies that a request for a non-existent role is rejected when
// using an explicitly configured list of role names.
-TEST_F(MasterQuotaTest, NonExistentRole)
+TEST_F(MasterQuotaTest, SetForNonExistentRole)
{
Try<PID<Master>> master = StartMaster();
ASSERT_SOME(master);
@@ -183,7 +184,7 @@ TEST_F(MasterQuotaTest, NonExistentRole)
// Quota requests with invalid structure should return a '400 Bad Request'.
-TEST_F(MasterQuotaTest, SetInvalidRequest)
+TEST_F(MasterQuotaTest, InvalidSetRequest)
{
Try<PID<Master>> master = StartMaster();
ASSERT_SOME(master);
@@ -294,7 +295,7 @@ TEST_F(MasterQuotaTest, SetNonScalar)
// A quota request with a role set in any of the `Resource` objects
// should return a '400 Bad Request'.
-TEST_F(MasterQuotaTest, ResourcesSpecifyRole)
+TEST_F(MasterQuotaTest, SetWithResourcesSpecifyingRole)
{
Try<PID<Master>> master = StartMaster();
ASSERT_SOME(master);
@@ -303,7 +304,7 @@ TEST_F(MasterQuotaTest, ResourcesSpecifyRole)
// we start looking at available resources.
// Create a quota request with the 'role' field set in resources.
- Resources quotaResources = Resources::parse("cpus:1;mem:512;", ROLE1).get();
+ Resources quotaResources = Resources::parse("cpus:1;mem:512", ROLE1).get();
Future<Response> response = process::http::post(
master.get(),
@@ -341,7 +342,7 @@ TEST_F(MasterQuotaTest, SetExistingQuota)
EXPECT_EQ(defaultAgentResources, agentTotalResources.get());
// We request quota for a portion of resources available on the agent.
- Resources quotaResources = Resources::parse("cpus:1;mem:512;").get();
+ Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
EXPECT_TRUE(agentTotalResources.get().contains(quotaResources));
Future<Response> response = process::http::post(
@@ -421,11 +422,11 @@ TEST_F(MasterQuotaTest, SetInvalidResourceInfos)
{
Resources quotaResources = Resources::parse("cpus:4;mem:512").get();
- Resource volume = Resources::parse("disk", "128", ROLE1).get();
- volume.mutable_reservation()->CopyFrom(
+ Resource reserved = Resources::parse("disk", "128", ROLE1).get();
+ reserved.mutable_reservation()->CopyFrom(
createReservationInfo(DEFAULT_CREDENTIAL.principal()));
- quotaResources += volume;
+ quotaResources += reserved;
Future<Response> response = process::http::post(
master.get(),
@@ -471,7 +472,8 @@ TEST_F(MasterQuotaTest, RemoveSingleQuota)
createBasicAuthHeaders(DEFAULT_CREDENTIAL));
};
- // Ensure that we can't remove quota for a role that is unknown to the master.
+ // Ensure that we can't remove quota for a role that is unknown to
+ // the master when using explicitly configured list of role names.
{
Future<Response> response = removeQuota("quota/" + UNKNOWN_ROLE);
@@ -584,37 +586,44 @@ TEST_F(MasterQuotaTest, StatusSingleQuota)
EXPECT_TRUE(agentTotalResources.get().contains(quotaResources));
// Send a quota request for the specified role.
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ {
+ Future<Response> response = process::http::post(
+ master.get(),
+ "quota",
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+ createRequestBody(ROLE1, quotaResources));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response) << response.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
+ }
// Query the master quota endpoint.
- response = process::http::get(
- master.get(),
- "quota",
- None(),
- createBasicAuthHeaders(DEFAULT_CREDENTIAL));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response) << response.get().body;
+ {
+ Future<Response> response = process::http::get(
+ master.get(),
+ "quota",
+ None(),
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL));
- EXPECT_SOME_EQ(
- "application/json",
- response.get().headers.get("Content-Type"));
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
- const Try<JSON::Object> parse =
- JSON::parse<JSON::Object>(response.get().body);
+ EXPECT_SOME_EQ(
+ "application/json",
+ response.get().headers.get("Content-Type"));
- ASSERT_SOME(parse);
+ const Try<JSON::Object> parse =
+ JSON::parse<JSON::Object>(response.get().body);
- // Convert JSON response to `QuotaStatus` protobuf.
- const Try<QuotaStatus> status = ::protobuf::parse<QuotaStatus>(parse.get());
- ASSERT_FALSE(status.isError());
+ ASSERT_SOME(parse);
- ASSERT_EQ(1, status.get().infos().size());
- EXPECT_EQ(quotaResources, status.get().infos(0).guarantee());
+ // Convert JSON response to `QuotaStatus` protobuf.
+ const Try<QuotaStatus> status = ::protobuf::parse<QuotaStatus>(parse.get());
+ ASSERT_FALSE(status.isError());
+
+ ASSERT_EQ(1, status.get().infos().size());
+ EXPECT_EQ(quotaResources, status.get().infos(0).guarantee());
+ }
Shutdown();
}
@@ -835,7 +844,7 @@ TEST_F(MasterQuotaTest, AvailableResourcesSingleAgent)
AWAIT_READY(receivedQuotaRequest);
EXPECT_EQ(ROLE1, receivedQuotaRequest.get().role());
- EXPECT_EQ(quotaResources, Resources(receivedQuotaRequest.get().guarantee()));
+ EXPECT_EQ(quotaResources, receivedQuotaRequest.get().guarantee());
Shutdown();
}
@@ -904,7 +913,7 @@ TEST_F(MasterQuotaTest, AvailableResourcesMultipleAgents)
AWAIT_READY(receivedQuotaRequest);
EXPECT_EQ(ROLE1, receivedQuotaRequest.get().role());
- EXPECT_EQ(quotaResources, Resources(receivedQuotaRequest.get().guarantee()));
+ EXPECT_EQ(quotaResources, receivedQuotaRequest.get().guarantee());
Shutdown();
}
@@ -1062,7 +1071,7 @@ TEST_F(MasterQuotaTest, AvailableResourcesAfterRescinding)
// got lost in-between.
AWAIT_READY(receivedQuotaRequest);
EXPECT_EQ(ROLE2, receivedQuotaRequest.get().role());
- EXPECT_EQ(quotaResources, Resources(receivedQuotaRequest.get().guarantee()));
+ EXPECT_EQ(quotaResources, receivedQuotaRequest.get().guarantee());
Shutdown();
}
@@ -1194,28 +1203,32 @@ TEST_F(MasterQuotaTest, UnauthenticatedQuotaRequest)
// The master is configured so that only requests from `DEFAULT_CREDENTIAL`
// are authenticated.
- Credential credential;
- credential.set_principal("unknown-principal");
- credential.set_secret("test-secret");
+ {
+ Credential credential;
+ credential.set_principal("unknown-principal");
+ credential.set_secret("test-secret");
- Future<Response> response1 = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(credential),
- createRequestBody(ROLE1, quotaResources));
+ Future<Response> response = process::http::post(
+ master.get(),
+ "quota",
+ createBasicAuthHeaders(credential),
+ createRequestBody(ROLE1, quotaResources));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(
- Unauthorized(vector<string>()).status, response1) << response1.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(
+ Unauthorized(vector<string>()).status, response) << response.get().body;
+ }
// The absense of credentials leads to authentication failure as well.
- Future<Response> response2 = process::http::post(
- master.get(),
- "quota",
- None(),
- createRequestBody(ROLE1, quotaResources));
+ {
+ Future<Response> response = process::http::post(
+ master.get(),
+ "quota",
+ None(),
+ createRequestBody(ROLE1, quotaResources));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(
- Unauthorized(vector<string>()).status, response2) << response2.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(
+ Unauthorized(vector<string>()).status, response) << response.get().body;
+ }
Shutdown();
}
@@ -1261,7 +1274,7 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
// As we don't care about the enforcement of quota but only the
// authorization of the quota request we set the force flag in the post
// request below to override the capacity heuristic check.
- Resources quotaResources = Resources::parse("cpus:1;mem:512;").get();
+ Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
// Note that we set the force flag because we are setting a quota that
// cannot currently be satisfied by the resources in the cluster (because
@@ -1281,7 +1294,7 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
// As we don't care about the enforcement of quota but only the
// authorization of the quota request we set the force flag in the post
// request below to override the capacity heuristic check.
- Resources quotaResources = Resources::parse("cpus:1;mem:512;").get();
+ Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
Future<QuotaInfo> quotaInfo;
EXPECT_CALL(allocator, setQuota(Eq(ROLE1), _))
@@ -1297,8 +1310,8 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
createBasicAuthHeaders(DEFAULT_CREDENTIAL),
createRequestBody(ROLE1, quotaResources, true));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(
- OK().status, response) << response.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
AWAIT_READY(quotaInfo);
@@ -1337,8 +1350,8 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
"quota/" + ROLE1,
createBasicAuthHeaders(DEFAULT_CREDENTIAL));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(
- OK().status, response) << response.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
AWAIT_READY(receivedRemoveRequest);
}
@@ -1380,7 +1393,7 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequestsWithoutPrincipal)
// As we don't care about the enforcement of quota but only the
// authorization of the quota request we set the force flag in the post
// request below to override the capacity heuristic check.
- Resources quotaResources = Resources::parse("cpus:1;mem:512;").get();
+ Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
// Create a HTTP request without authorization headers. Note that we set the
// force flag because we are setting a quota that cannot currently be
@@ -1391,8 +1404,8 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequestsWithoutPrincipal)
None(),
createRequestBody(ROLE1, quotaResources, true));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(
- OK().status, response) << response.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
}
// Remove the previously requested quota without providing authorization
@@ -1403,8 +1416,8 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequestsWithoutPrincipal)
"quota/" + ROLE1,
None());
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(
- OK().status, response) << response.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
}
Shutdown();
http://git-wip-us.apache.org/repos/asf/mesos/blob/e23429c8/src/tests/registrar_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/registrar_tests.cpp b/src/tests/registrar_tests.cpp
index 91781dd..8374742 100644
--- a/src/tests/registrar_tests.cpp
+++ b/src/tests/registrar_tests.cpp
@@ -677,24 +677,24 @@ TEST_P(RegistrarTest, StopMaintenance)
// Tests that adding and updating quotas in the registry works properly.
TEST_P(RegistrarTest, UpdateQuota)
{
- // Prepare `QuotaInfo` protobufs used in the test.
- const std::string role1 = "role1";
- const std::string role2 = "role2";
+ const std::string ROLE1 = "role1";
+ const std::string ROLE2 = "role2";
// NOTE: `quotaResources1` yields a collection with two `Resource`
// objects once converted to `RepeatedPtrField`.
Resources quotaResources1 = Resources::parse("cpus:1;mem:1024").get();
Resources quotaResources2 = Resources::parse("cpus:2").get();
+ // Prepare `QuotaInfo` protobufs used in the test.
QuotaInfo quota1;
- quota1.set_role(role1);
+ quota1.set_role(ROLE1);
quota1.mutable_guarantee()->CopyFrom(quotaResources1);
Option<Error> validateError1 = quota::validation::quotaInfo(quota1);
EXPECT_NONE(validateError1);
QuotaInfo quota2;
- quota2.set_role(role2);
+ quota2.set_role(ROLE2);
quota2.mutable_guarantee()->CopyFrom(quotaResources1);
Option<Error> validateError2 = quota::validation::quotaInfo(quota2);
@@ -718,13 +718,13 @@ TEST_P(RegistrarTest, UpdateQuota)
// Check that the recovered quota matches the one we stored.
ASSERT_EQ(1, registry.get().quotas().size());
- EXPECT_EQ(role1, registry.get().quotas(0).info().role());
+ EXPECT_EQ(ROLE1, registry.get().quotas(0).info().role());
ASSERT_EQ(2, registry.get().quotas(0).info().guarantee().size());
Resources storedResources(registry.get().quotas(0).info().guarantee());
EXPECT_EQ(quotaResources1, storedResources);
- // Change quota for `role1`.
+ // Change quota for `ROLE1`.
quota1.mutable_guarantee()->CopyFrom(quotaResources2);
// Update the only stored quota.
@@ -738,7 +738,7 @@ TEST_P(RegistrarTest, UpdateQuota)
// Check that the recovered quota matches the one we updated.
ASSERT_EQ(1, registry.get().quotas().size());
- EXPECT_EQ(role1, registry.get().quotas(0).info().role());
+ EXPECT_EQ(ROLE1, registry.get().quotas(0).info().role());
ASSERT_EQ(1, registry.get().quotas(0).info().guarantee().size());
Resources storedResources(registry.get().quotas(0).info().guarantee());
@@ -758,10 +758,10 @@ TEST_P(RegistrarTest, UpdateQuota)
// been added.
// TODO(alexr): Consider removing dependency on the order.
ASSERT_EQ(2, registry.get().quotas().size());
- EXPECT_EQ(role1, registry.get().quotas(0).info().role());
+ EXPECT_EQ(ROLE1, registry.get().quotas(0).info().role());
ASSERT_EQ(1, registry.get().quotas(0).info().guarantee().size());
- EXPECT_EQ(role2, registry.get().quotas(1).info().role());
+ EXPECT_EQ(ROLE2, registry.get().quotas(1).info().role());
ASSERT_EQ(2, registry.get().quotas(1).info().guarantee().size());
Resources storedResources(registry.get().quotas(1).info().guarantee());
@@ -786,13 +786,13 @@ TEST_P(RegistrarTest, UpdateQuota)
// TODO(alexr): Consider removing dependency on the order.
ASSERT_EQ(2, registry.get().quotas().size());
- EXPECT_EQ(role1, registry.get().quotas(0).info().role());
+ EXPECT_EQ(ROLE1, registry.get().quotas(0).info().role());
ASSERT_EQ(1, registry.get().quotas(0).info().guarantee().size());
Resources storedResources1(registry.get().quotas(0).info().guarantee());
EXPECT_EQ(quotaResources2, storedResources1);
- EXPECT_EQ(role2, registry.get().quotas(1).info().role());
+ EXPECT_EQ(ROLE2, registry.get().quotas(1).info().role());
ASSERT_EQ(1, registry.get().quotas(1).info().guarantee().size());
Resources storedResources2(registry.get().quotas(1).info().guarantee());
@@ -804,8 +804,8 @@ TEST_P(RegistrarTest, UpdateQuota)
// Tests removing quotas from the registry.
TEST_P(RegistrarTest, RemoveQuota)
{
- const std::string role1 = "role1";
- const std::string role2 = "role2";
+ const std::string ROLE1 = "role1";
+ const std::string ROLE2 = "role2";
{
// Prepare the registrar; see the comment above why we need to do this in
@@ -814,21 +814,21 @@ TEST_P(RegistrarTest, RemoveQuota)
Future<Registry> registry = registrar.recover(master);
AWAIT_READY(registry);
- // Prepare `QuotaInfo` protobufs.
// NOTE: `quotaResources` yields a collection with two `Resource`
// objects once converted to `RepeatedPtrField`.
Resources quotaResources1 = Resources::parse("cpus:1;mem:1024").get();
Resources quotaResources2 = Resources::parse("cpus:2").get();
+ // Prepare `QuotaInfo` protobufs.
QuotaInfo quota1;
- quota1.set_role(role1);
+ quota1.set_role(ROLE1);
quota1.mutable_guarantee()->CopyFrom(quotaResources1);
Option<Error> validateError1 = quota::validation::quotaInfo(quota1);
EXPECT_NONE(validateError1);
QuotaInfo quota2;
- quota2.set_role(role2);
+ quota2.set_role(ROLE2);
quota2.mutable_guarantee()->CopyFrom(quotaResources2);
Option<Error> validateError2 = quota::validation::quotaInfo(quota2);
@@ -848,11 +848,11 @@ TEST_P(RegistrarTest, RemoveQuota)
// added.
// TODO(alexr): Consider removing dependency on the order.
ASSERT_EQ(2, registry.get().quotas().size());
- EXPECT_EQ(role1, registry.get().quotas(0).info().role());
- EXPECT_EQ(role2, registry.get().quotas(1).info().role());
+ EXPECT_EQ(ROLE1, registry.get().quotas(0).info().role());
+ EXPECT_EQ(ROLE2, registry.get().quotas(1).info().role());
// Remove quota for `role2`.
- AWAIT_EQ(true, registrar.apply(Owned<Operation>(new RemoveQuota(role2))));
+ AWAIT_EQ(true, registrar.apply(Owned<Operation>(new RemoveQuota(ROLE2))));
}
{
@@ -862,10 +862,10 @@ TEST_P(RegistrarTest, RemoveQuota)
// Check that there is only one quota left in the registry.
ASSERT_EQ(1, registry.get().quotas().size());
- EXPECT_EQ(role1, registry.get().quotas(0).info().role());
+ EXPECT_EQ(ROLE1, registry.get().quotas(0).info().role());
- // Remove quota for `role1`.
- AWAIT_EQ(true, registrar.apply(Owned<Operation>(new RemoveQuota(role1))));
+ // Remove quota for `ROLE1`.
+ AWAIT_EQ(true, registrar.apply(Owned<Operation>(new RemoveQuota(ROLE1))));
}
{
[3/3] mesos git commit: Quota: Replaced `QuotaInfo` with `Quota` in
allocator.
Posted by jo...@apache.org.
Quota: Replaced `QuotaInfo` with `Quota` in allocator.
Review: https://reviews.apache.org/r/41949/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b075f415
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b075f415
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b075f415
Branch: refs/heads/master
Commit: b075f415aad92e87d1c25dd2a7b92b7096134238
Parents: a88e2a1
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Fri Jan 15 17:46:49 2016 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Fri Jan 15 17:56:33 2016 -0500
----------------------------------------------------------------------
include/mesos/master/allocator.hpp | 2 +-
src/master/allocator/mesos/allocator.hpp | 6 ++---
src/master/allocator/mesos/hierarchical.cpp | 16 +++++------
src/master/allocator/mesos/hierarchical.hpp | 4 +--
src/master/quota_handler.cpp | 6 +++--
src/tests/allocator.hpp | 2 +-
src/tests/hierarchical_allocator_tests.cpp | 32 +++++++++++-----------
src/tests/master_quota_tests.cpp | 34 +++++++++++-------------
8 files changed, 49 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/include/mesos/master/allocator.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/master/allocator.hpp b/include/mesos/master/allocator.hpp
index fcebcab..e163669 100644
--- a/include/mesos/master/allocator.hpp
+++ b/include/mesos/master/allocator.hpp
@@ -361,7 +361,7 @@ public:
*/
virtual void setQuota(
const std::string& role,
- const mesos::quota::QuotaInfo& quota) = 0;
+ const Quota& quota) = 0;
/**
* Informs the allocator to remove quota for the given role.
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/src/master/allocator/mesos/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/allocator.hpp b/src/master/allocator/mesos/allocator.hpp
index 50ef3b2..581eaad 100644
--- a/src/master/allocator/mesos/allocator.hpp
+++ b/src/master/allocator/mesos/allocator.hpp
@@ -144,7 +144,7 @@ public:
void setQuota(
const std::string& role,
- const mesos::quota::QuotaInfo& quota);
+ const Quota& quota);
void removeQuota(
const std::string& role);
@@ -268,7 +268,7 @@ public:
virtual void setQuota(
const std::string& role,
- const mesos::quota::QuotaInfo& quota) = 0;
+ const Quota& quota) = 0;
virtual void removeQuota(
const std::string& role) = 0;
@@ -600,7 +600,7 @@ inline void MesosAllocator<AllocatorProcess>::reviveOffers(
template <typename AllocatorProcess>
inline void MesosAllocator<AllocatorProcess>::setQuota(
const std::string& role,
- const mesos::quota::QuotaInfo& quota)
+ const Quota& quota)
{
process::dispatch(
process,
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/src/master/allocator/mesos/hierarchical.cpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.cpp b/src/master/allocator/mesos/hierarchical.cpp
index 512aaed..72e69a0 100644
--- a/src/master/allocator/mesos/hierarchical.cpp
+++ b/src/master/allocator/mesos/hierarchical.cpp
@@ -37,8 +37,6 @@ using std::vector;
using mesos::master::InverseOfferStatus;
-using mesos::quota::QuotaInfo;
-
using process::Failure;
using process::Future;
using process::Timeout;
@@ -196,7 +194,7 @@ void HierarchicalAllocatorProcess::recover(
// NOTE: `quotaRoleSorter` is updated implicitly in `setQuota()`.
foreachpair (const string& role, const Quota& quota, quotas) {
- setQuota(role, quota.info);
+ setQuota(role, quota);
}
LOG(INFO) << "Triggered allocator recovery: waiting for "
@@ -978,7 +976,7 @@ void HierarchicalAllocatorProcess::reviveOffers(
void HierarchicalAllocatorProcess::setQuota(
const string& role,
- const QuotaInfo& quota)
+ const Quota& quota)
{
CHECK(initialized);
@@ -1004,7 +1002,7 @@ void HierarchicalAllocatorProcess::setQuota(
}
// TODO(alexr): Print all quota info for the role.
- LOG(INFO) << "Set quota " << quota.guarantee() << " for role '" << role
+ LOG(INFO) << "Set quota " << quota.info.guarantee() << " for role '" << role
<< "'";
// Trigger the allocation explicitly in order to promptly react to the
@@ -1023,7 +1021,7 @@ void HierarchicalAllocatorProcess::removeQuota(
CHECK(quotaRoleSorter->contains(role));
// TODO(alexr): Print all quota info for the role.
- LOG(INFO) << "Removed quota " << quotas[role].guarantee()
+ LOG(INFO) << "Removed quota " << quotas[role].info.guarantee()
<< " for role '" << role << "'";
// Remove the role from the quota'ed allocation group.
@@ -1160,7 +1158,7 @@ void HierarchicalAllocatorProcess::allocate(
// alternatives are:
// * A custom sorter that is aware of quotas and sorts accordingly.
// * Removing satisfied roles from the sorter.
- if (roleConsumedResources.contains(quotas[role].guarantee())) {
+ if (roleConsumedResources.contains(quotas[role].info.guarantee())) {
break;
}
@@ -1226,11 +1224,11 @@ void HierarchicalAllocatorProcess::allocate(
// Frameworks in a quota'ed role may temporarily reject resources by
// filtering or suppressing offers. Hence quotas may not be fully allocated.
Resources unallocatedQuotaResources;
- foreachpair (const string& name, const QuotaInfo& quota, quotas) {
+ foreachpair (const string& name, const Quota& quota, quotas) {
// Compute the amount of quota that the role does not have allocated.
// NOTE: Reserved and revocable resources are excluded in `quotaRoleSorter`.
Resources allocated = Resources::sum(quotaRoleSorter->allocation(name));
- const Resources required = quota.guarantee();
+ const Resources required = quota.info.guarantee();
unallocatedQuotaResources += (required - allocated);
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/src/master/allocator/mesos/hierarchical.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator/mesos/hierarchical.hpp b/src/master/allocator/mesos/hierarchical.hpp
index 5f08b6e..7fb9933 100644
--- a/src/master/allocator/mesos/hierarchical.hpp
+++ b/src/master/allocator/mesos/hierarchical.hpp
@@ -182,7 +182,7 @@ public:
void setQuota(
const std::string& role,
- const mesos::quota::QuotaInfo& quota);
+ const Quota& quota);
void removeQuota(
const std::string& role);
@@ -378,7 +378,7 @@ protected:
//
// NOTE: We currently associate quota with roles, but this may
// change in the future.
- hashmap<std::string, mesos::quota::QuotaInfo> quotas;
+ hashmap<std::string, Quota> quotas;
// Slaves to send offers for.
Option<hashset<std::string>> whitelist;
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/src/master/quota_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index ace6537..f44736c 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -365,12 +365,14 @@ Future<http::Response> Master::QuotaHandler::_set(
}
}
+ Quota quota = Quota{quotaInfo};
+
// Populate master's quota-related local state. We do this before updating
// the registry in order to make sure that we are not already trying to
// satisfy a request for this role (since this is a multi-phase event).
// NOTE: We do not need to remove quota for the role if the registry update
// fails because in this case the master fails as well.
- master->quotas[quotaInfo.role()] = Quota{quotaInfo};
+ master->quotas[quotaInfo.role()] = quota;
// Update the registry with the new quota and acknowledge the request.
return master->registrar->apply(Owned<Operation>(
@@ -379,7 +381,7 @@ Future<http::Response> Master::QuotaHandler::_set(
// See the top comment in "master/quota.hpp" for why this check is here.
CHECK(result);
- master->allocator->setQuota(quotaInfo.role(), quotaInfo);
+ master->allocator->setQuota(quotaInfo.role(), quota);
// Rescind outstanding offers to facilitate satisfying the quota request.
// NOTE: We set quota before we rescind to avoid a race. If we were to
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/src/tests/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/tests/allocator.hpp b/src/tests/allocator.hpp
index 9bdfaec..206e9ac 100644
--- a/src/tests/allocator.hpp
+++ b/src/tests/allocator.hpp
@@ -444,7 +444,7 @@ public:
MOCK_METHOD2(setQuota, void(
const std::string&,
- const mesos::quota::QuotaInfo&));
+ const Quota&));
MOCK_METHOD1(removeQuota, void(
const std::string&));
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 769b0e3..9362dd3 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -52,8 +52,6 @@ using mesos::internal::master::allocator::HierarchicalDRFAllocator;
using mesos::master::allocator::Allocator;
-using mesos::quota::QuotaInfo;
-
using process::Clock;
using process::Future;
@@ -202,13 +200,13 @@ protected:
return frameworkInfo;
}
- static QuotaInfo createQuotaInfo(const string& role, const string& resources)
+ static Quota createQuota(const string& role, const string& resources)
{
- QuotaInfo quota;
- quota.set_role(role);
- quota.mutable_guarantee()->CopyFrom(Resources::parse(resources).get());
+ mesos::quota::QuotaInfo quotaInfo;
+ quotaInfo.set_role(role);
+ quotaInfo.mutable_guarantee()->CopyFrom(Resources::parse(resources).get());
- return quota;
+ return Quota{quotaInfo};
}
Resources createRevocableResources(
@@ -1204,7 +1202,7 @@ TEST_F(HierarchicalAllocatorTest, QuotaProvidesQuarantee)
allocator->addFramework(
framework1.id(), framework1, hashmap<SlaveID, Resources>());
- const QuotaInfo quota1 = createQuotaInfo(QUOTA_ROLE, "cpus:2;mem:1024");
+ const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:2;mem:1024");
allocator->setQuota(QUOTA_ROLE, quota1);
// Create `framework2` in a non-quota'ed role.
@@ -1330,7 +1328,7 @@ TEST_F(HierarchicalAllocatorTest, RemoveQuota)
SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
SlaveInfo agent2 = createSlaveInfo("cpus:1;mem:512;disk:0");
- const QuotaInfo quota1 = createQuotaInfo(QUOTA_ROLE, "cpus:2;mem:1024");
+ const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:2;mem:1024");
// Notify allocator of agents, frameworks, quota and current allocations.
allocator->setQuota(QUOTA_ROLE, quota1);
@@ -1418,7 +1416,7 @@ TEST_F(HierarchicalAllocatorTest, MultipleFrameworksInRoleWithQuota)
allocator->addFramework(
framework1a.id(), framework1a, hashmap<SlaveID, Resources>());
- const QuotaInfo quota1 = createQuotaInfo(QUOTA_ROLE, "cpus:4;mem:2048");
+ const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:4;mem:2048");
allocator->setQuota(QUOTA_ROLE, quota1);
// Create `framework2` in a non-quota'ed role.
@@ -1539,7 +1537,7 @@ TEST_F(HierarchicalAllocatorTest, QuotaAllocationGranularity)
framework1.id(), framework1, hashmap<SlaveID, Resources>());
// Set quota to be less than the agent resources.
- const QuotaInfo quota1 = createQuotaInfo(QUOTA_ROLE, "cpus:0.5;mem:200");
+ const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:0.5;mem:200");
allocator->setQuota(QUOTA_ROLE, quota1);
// Create `framework2` in a non-quota'ed role.
@@ -1561,7 +1559,7 @@ TEST_F(HierarchicalAllocatorTest, QuotaAllocationGranularity)
AWAIT_READY(allocation);
EXPECT_EQ(framework1.id(), allocation.get().frameworkId);
EXPECT_EQ(agent1.resources(), Resources::sum(allocation.get().resources));
- EXPECT_TRUE(Resources(agent1.resources()).contains(quota1.guarantee()));
+ EXPECT_TRUE(Resources(agent1.resources()).contains(quota1.info.guarantee()));
// Total cluster resources: cpus=1, mem=512.
// QUOTA_ROLE share = 1 (cpus=1, mem=512) [quota: cpus=0.5, mem=200]
@@ -1598,7 +1596,7 @@ TEST_F(HierarchicalAllocatorTest, DRFWithQuota)
SlaveInfo agent1 = createSlaveInfo("cpus:1;mem:512;disk:0");
- const QuotaInfo quota1 = createQuotaInfo(QUOTA_ROLE, "cpus:0.25;mem:128");
+ const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:0.25;mem:128");
// Notify allocator of agents, frameworks, quota and current allocations.
allocator->setQuota(QUOTA_ROLE, quota1);
@@ -1624,7 +1622,7 @@ TEST_F(HierarchicalAllocatorTest, DRFWithQuota)
agent1,
None(),
agent1.resources(),
- {std::make_pair(framework1.id(), Resources(quota1.guarantee()))});
+ {std::make_pair(framework1.id(), Resources(quota1.info.guarantee()))});
// Some resources on `agent1` are now being used by `framework1` as part
// of its role quota. All quotas are satisfied, all available resources
@@ -1635,7 +1633,7 @@ TEST_F(HierarchicalAllocatorTest, DRFWithQuota)
Future<Allocation> allocation = allocations.get();
AWAIT_READY(allocation);
EXPECT_EQ(framework2.id(), allocation.get().frameworkId);
- EXPECT_EQ(agent1.resources() - Resources(quota1.guarantee()),
+ EXPECT_EQ(agent1.resources() - Resources(quota1.info.guarantee()),
Resources::sum(allocation.get().resources));
// Total cluster resources (1 agent): cpus=1, mem=512.
@@ -1777,7 +1775,7 @@ TEST_F(HierarchicalAllocatorTest, QuotaAgainstStarvation)
filter0s);
// We set quota for the "starving" `QUOTA_ROLE` role.
- QuotaInfo quota1 = createQuotaInfo(QUOTA_ROLE, "cpus:2;mem:1024");
+ Quota quota1 = createQuota(QUOTA_ROLE, "cpus:2;mem:1024");
allocator->setQuota(QUOTA_ROLE, quota1);
// Since `QUOTA_ROLE` is under quota, `agent2`'s resources will
@@ -1816,7 +1814,7 @@ TEST_F(HierarchicalAllocatorTest, QuotaAbsentFramework)
allocator->addSlave(agent2.id(), agent2, None(), agent2.resources(), EMPTY);
// Set quota for the quota'ed role.
- const QuotaInfo quota1 = createQuotaInfo(QUOTA_ROLE, "cpus:2;mem:1024");
+ const Quota quota1 = createQuota(QUOTA_ROLE, "cpus:2;mem:1024");
allocator->setQuota(QUOTA_ROLE, quota1);
// Add `framework1` in the non-quota'ed role.
http://git-wip-us.apache.org/repos/asf/mesos/blob/b075f415/src/tests/master_quota_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index 9d390d2..e8cb074 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -47,9 +47,7 @@ using mesos::internal::master::Master;
using mesos::internal::slave::Slave;
-using mesos::quota::QuotaInfo;
using mesos::quota::QuotaStatus;
-
using process::Future;
using process::PID;
@@ -741,7 +739,7 @@ TEST_F(MasterQuotaTest, AvailableResourcesSingleAgent)
EXPECT_TRUE(agentTotalResources.get().contains(quotaResources));
// Send a quota request for the specified role.
- Future<QuotaInfo> receivedQuotaRequest;
+ Future<Quota> receivedQuotaRequest;
EXPECT_CALL(allocator, setQuota(Eq(ROLE1), _))
.WillOnce(DoAll(InvokeSetQuota(&allocator),
FutureArg<1>(&receivedQuotaRequest)));
@@ -758,8 +756,8 @@ TEST_F(MasterQuotaTest, AvailableResourcesSingleAgent)
// got lost in-between.
AWAIT_READY(receivedQuotaRequest);
- EXPECT_EQ(ROLE1, receivedQuotaRequest.get().role());
- EXPECT_EQ(quotaResources, receivedQuotaRequest.get().guarantee());
+ EXPECT_EQ(ROLE1, receivedQuotaRequest.get().info.role());
+ EXPECT_EQ(quotaResources, receivedQuotaRequest.get().info.guarantee());
Shutdown();
}
@@ -810,7 +808,7 @@ TEST_F(MasterQuotaTest, AvailableResourcesMultipleAgents)
});
// Send a quota request for the specified role.
- Future<QuotaInfo> receivedQuotaRequest;
+ Future<Quota> receivedQuotaRequest;
EXPECT_CALL(allocator, setQuota(Eq(ROLE1), _))
.WillOnce(DoAll(InvokeSetQuota(&allocator),
FutureArg<1>(&receivedQuotaRequest)));
@@ -827,8 +825,8 @@ TEST_F(MasterQuotaTest, AvailableResourcesMultipleAgents)
// got lost in-between.
AWAIT_READY(receivedQuotaRequest);
- EXPECT_EQ(ROLE1, receivedQuotaRequest.get().role());
- EXPECT_EQ(quotaResources, receivedQuotaRequest.get().guarantee());
+ EXPECT_EQ(ROLE1, receivedQuotaRequest.get().info.role());
+ EXPECT_EQ(quotaResources, receivedQuotaRequest.get().info.guarantee());
Shutdown();
}
@@ -958,7 +956,7 @@ TEST_F(MasterQuotaTest, AvailableResourcesAfterRescinding)
.Times(2);
// Send a quota request for the specified role.
- Future<QuotaInfo> receivedQuotaRequest;
+ Future<Quota> receivedQuotaRequest;
EXPECT_CALL(allocator, setQuota(Eq(ROLE2), _))
.WillOnce(DoAll(InvokeSetQuota(&allocator),
FutureArg<1>(&receivedQuotaRequest)));
@@ -985,8 +983,8 @@ TEST_F(MasterQuotaTest, AvailableResourcesAfterRescinding)
// The quota request is granted and reached the allocator. Make sure nothing
// got lost in-between.
AWAIT_READY(receivedQuotaRequest);
- EXPECT_EQ(ROLE2, receivedQuotaRequest.get().role());
- EXPECT_EQ(quotaResources, receivedQuotaRequest.get().guarantee());
+ EXPECT_EQ(ROLE2, receivedQuotaRequest.get().info.role());
+ EXPECT_EQ(quotaResources, receivedQuotaRequest.get().info.guarantee());
Shutdown();
}
@@ -1052,7 +1050,7 @@ TEST_F(MasterQuotaTest, NoAuthenticationNoAuthorization)
{
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
- Future<QuotaInfo> receivedSetRequest;
+ Future<Quota> receivedSetRequest;
EXPECT_CALL(allocator, setQuota(Eq(ROLE1), _))
.WillOnce(DoAll(InvokeSetQuota(&allocator),
FutureArg<1>(&receivedSetRequest)));
@@ -1202,10 +1200,10 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
// request below to override the capacity heuristic check.
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
- Future<QuotaInfo> quotaInfo;
+ Future<Quota> quota;
EXPECT_CALL(allocator, setQuota(Eq(ROLE1), _))
.WillOnce(DoAll(InvokeSetQuota(&allocator),
- FutureArg<1>("aInfo)));
+ FutureArg<1>("a)));
Future<Response> response = process::http::post(
master.get(),
@@ -1216,16 +1214,16 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
<< response.get().body;
- AWAIT_READY(quotaInfo);
+ AWAIT_READY(quota);
// Extract the principal from `DEFAULT_CREDENTIAL` because `EXPECT_EQ`
// does not compile if `DEFAULT_CREDENTIAL.principal()` is used as an
// argument.
const string principal = DEFAULT_CREDENTIAL.principal();
- EXPECT_EQ(ROLE1, quotaInfo.get().role());
- EXPECT_EQ(principal, quotaInfo.get().principal());
- EXPECT_EQ(quotaResources, quotaInfo.get().guarantee());
+ EXPECT_EQ(ROLE1, quota.get().info.role());
+ EXPECT_EQ(principal, quota.get().info.principal());
+ EXPECT_EQ(quotaResources, quota.get().info.guarantee());
}
// Try to remove the previously requested quota using a principal that is
[2/3] mesos git commit: Quota: Simplified tests.
Posted by jo...@apache.org.
Quota: Simplified tests.
For clarity and in order not to distract a reader with copy-paste code:
- some tests were merged together;
- removed creation of agents where possible and used force flag
in quota request instead.
Review: https://reviews.apache.org/r/41939/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a88e2a1d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a88e2a1d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a88e2a1d
Branch: refs/heads/master
Commit: a88e2a1da2926db5414b48fc6f8965642ea44ddb
Parents: e23429c
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Fri Jan 15 17:36:03 2016 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Fri Jan 15 17:46:34 2016 -0500
----------------------------------------------------------------------
src/tests/master_quota_tests.cpp | 442 +++++++++++++---------------------
1 file changed, 172 insertions(+), 270 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/a88e2a1d/src/tests/master_quota_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index 53bcfde..9d390d2 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -166,7 +166,6 @@ TEST_F(MasterQuotaTest, SetForNonExistentRole)
// We do not need an agent since a request should be rejected before we
// start looking at available resources.
- // We request quota for a portion of resources available on the agent.
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
// Send a quota request for a non-existent role.
@@ -267,8 +266,9 @@ TEST_F(MasterQuotaTest, InvalidSetRequest)
}
-// A quota request with non-scalar resources should return a '400 Bad Request'.
-TEST_F(MasterQuotaTest, SetNonScalar)
+// Checks that a quota set request is not satisfied if any invalid field is
+// set or provided data are not supported.
+TEST_F(MasterQuotaTest, SetRequestWithInvalidData)
{
Try<PID<Master>> master = StartMaster();
ASSERT_SOME(master);
@@ -276,111 +276,41 @@ TEST_F(MasterQuotaTest, SetNonScalar)
// We do not need an agent since a request should be rejected before
// we start looking at available resources.
- // Quota set request including non-scalar port resources.
- Resources quotaResources =
- Resources::parse("cpus:1;mem:512;ports:[31000-31001]").get();
-
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
-
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
- << response.get().body;
-
- Shutdown();
-}
-
-
-// A quota request with a role set in any of the `Resource` objects
-// should return a '400 Bad Request'.
-TEST_F(MasterQuotaTest, SetWithResourcesSpecifyingRole)
-{
- Try<PID<Master>> master = StartMaster();
- ASSERT_SOME(master);
-
- // We do not need an agent since a request should be rejected before
- // we start looking at available resources.
-
- // Create a quota request with the 'role' field set in resources.
- Resources quotaResources = Resources::parse("cpus:1;mem:512", ROLE1).get();
-
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
-
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
- << response.get().body;
-
- Shutdown();
-}
-
-
-// Updating an exiting quota via POST to the '/master/quota endpoint' should
-// return a '400 BadRequest'.
-TEST_F(MasterQuotaTest, SetExistingQuota)
-{
- 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());
-
- // We request quota for a portion of resources available on the agent.
- Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
- EXPECT_TRUE(agentTotalResources.get().contains(quotaResources));
-
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
-
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response) << response.get().body;
+ // Wrap the `http::post` into a lambda for readability of the test.
+ auto postQuota = [this, &master](
+ const string& role, const Resources& resources) {
+ return process::http::post(
+ master.get(),
+ "quota",
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+ createRequestBody(role, resources));
+ };
- // Try to set quota via post a second time.
- response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ // A quota set request with non-scalar resources (e.g. ports) should return
+ // '400 Bad Request'.
+ {
+ Resources quotaResources =
+ Resources::parse("cpus:1;mem:512;ports:[31000-31001]").get();
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
- << response.get().body;
+ Future<Response> response = postQuota(ROLE1, quotaResources);
- Shutdown();
-}
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
+ << response.get().body;
+ }
+ // A quota set request with a role set in any of the `Resource` objects
+ // should return '400 Bad Request'.
+ {
+ Resources quotaResources = Resources::parse("cpus:1;mem:512", ROLE1).get();
-// Checks whether a quota request with any invalid field set is rejected:
-// * `ReservationInfo`.
-// * `RevocableInfo`.
-// * `DiskInfo`.
-TEST_F(MasterQuotaTest, SetInvalidResourceInfos)
-{
- Try<PID<Master>> master = StartMaster();
- ASSERT_SOME(master);
+ Future<Response> response = postQuota(ROLE1, quotaResources);
- // We do not need an agent since a request should be rejected before
- // we start looking at available resources.
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
+ << response.get().body;
+ }
- // Create a quota set request with `DiskInfo` and check that the
- // request returns a '400 Bad Request' return code.
+ // A quota set request with the `DiskInfo` field set should return
+ // '400 Bad Request'.
{
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
@@ -388,18 +318,14 @@ TEST_F(MasterQuotaTest, SetInvalidResourceInfos)
volume.mutable_disk()->CopyFrom(createDiskInfo("id1", "path1"));
quotaResources += volume;
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ Future<Response> response = postQuota(ROLE1, quotaResources);
AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
<< response.get().body;
}
- // Create a quota set request with `RevocableInfo` and check that
- // the request returns a '400 Bad Request' return code.
+ // A quota set request with the `RevocableInfo` field set should return
+ // '400 Bad Request'.
{
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
@@ -407,18 +333,14 @@ TEST_F(MasterQuotaTest, SetInvalidResourceInfos)
revocable.mutable_revocable();
quotaResources += revocable;
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ Future<Response> response = postQuota(ROLE1, quotaResources);
AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
<< response.get().body;
}
- // Create a quota set request with `ReservationInfo` and check that
- // the request returns a '400 Bad Request' return code.
+ // A quota set request with the `ReservationInfo` field set should return
+ // '400 Bad Request'.
{
Resources quotaResources = Resources::parse("cpus:4;mem:512").get();
@@ -428,11 +350,48 @@ TEST_F(MasterQuotaTest, SetInvalidResourceInfos)
quotaResources += reserved;
+ Future<Response> response = postQuota(ROLE1, quotaResources);
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
+ << response.get().body;
+ }
+
+ Shutdown();
+}
+
+
+// Updating an exiting quota via POST to the '/master/quota endpoint' should
+// return a '400 BadRequest'.
+TEST_F(MasterQuotaTest, SetExistingQuota)
+{
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ // Use the force flag for setting quota that cannot be satisfied in
+ // this empty cluster without any agents.
+ const bool FORCE = true;
+
+ Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
+
+ // Set quota for the role without quota set.
+ {
Future<Response> response = process::http::post(
master.get(),
"quota",
createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ createRequestBody(ROLE1, quotaResources, FORCE));
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
+ }
+
+ // Try to set quota via post a second time.
+ {
+ Future<Response> response = process::http::post(
+ master.get(),
+ "quota",
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+ createRequestBody(ROLE1, quotaResources, FORCE));
AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
<< response.get().body;
@@ -452,17 +411,9 @@ TEST_F(MasterQuotaTest, RemoveSingleQuota)
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());
+ // Use the force flag for setting quota that cannot be satisfied in
+ // this empty cluster without any agents.
+ const bool FORCE = true;
// Wrap the `http::requestDelete` into a lambda for readability of the test.
auto removeQuota = [this, &master](const string& path) {
@@ -491,15 +442,13 @@ TEST_F(MasterQuotaTest, RemoveSingleQuota)
// Ensure we can remove the quota we have requested before.
{
- // Request quota for a portion of the resources available on the agent.
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
- EXPECT_TRUE(agentTotalResources.get().contains(quotaResources));
Future<Response> response = process::http::post(
master.get(),
"quota",
createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ createRequestBody(ROLE1, quotaResources, FORCE));
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
<< response.get().body;
@@ -523,67 +472,45 @@ TEST_F(MasterQuotaTest, RemoveSingleQuota)
}
-// Tests whether we can retrieve empty quota status (i.e. no quota set)
-// from /master/quota endpoint via a GET request against /quota.
-TEST_F(MasterQuotaTest, StatusNoQuotas)
+// Tests whether we can retrieve the current quota status from
+// /master/quota endpoint via a GET request against /quota.
+TEST_F(MasterQuotaTest, Status)
{
Try<PID<Master>> master = StartMaster();
ASSERT_SOME(master);
- // Query the master quota endpoint.
- Future<Response> response = process::http::get(
- master.get(),
- "quota",
- None(),
- createBasicAuthHeaders(DEFAULT_CREDENTIAL));
-
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response) << response.get().body;
-
- EXPECT_SOME_EQ(
- "application/json",
- response.get().headers.get("Content-Type"));
-
- const Try<JSON::Object> parse =
- JSON::parse<JSON::Object>(response.get().body);
-
- ASSERT_SOME(parse);
-
- // Convert JSON response to `QuotaStatus` protobuf.
- const Try<QuotaStatus> status = ::protobuf::parse<QuotaStatus>(parse.get());
- ASSERT_FALSE(status.isError());
-
- EXPECT_EQ(0, status.get().infos().size());
-
- Shutdown();
-}
+ // Use the force flag for setting quota that cannot be satisfied in
+ // this empty cluster without any agents.
+ const bool FORCE = true;
+ Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
-// Tests whether we can retrieve the current quota status from
-// /master/quota endpoint via a GET request against /quota.
-TEST_F(MasterQuotaTest, StatusSingleQuota)
-{
- TestAllocator<> allocator;
- EXPECT_CALL(allocator, initialize(_, _, _, _));
+ // Query the master quota endpoint when no quota is set.
+ {
+ Future<Response> response = process::http::get(
+ master.get(),
+ "quota",
+ None(),
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL));
- Try<PID<Master>> master = StartMaster(&allocator);
- ASSERT_SOME(master);
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
- Future<Resources> agentTotalResources;
- EXPECT_CALL(allocator, addSlave(_, _, _, _, _))
- .WillOnce(DoAll(InvokeAddSlave(&allocator),
- FutureArg<3>(&agentTotalResources)));
+ EXPECT_SOME_EQ(
+ "application/json",
+ response.get().headers.get("Content-Type"));
- // Start one agent and wait until it registers.
- Try<PID<Slave>> agent = StartSlave();
- ASSERT_SOME(agent);
+ const Try<JSON::Object> parse =
+ JSON::parse<JSON::Object>(response.get().body);
- AWAIT_READY(agentTotalResources);
- EXPECT_EQ(defaultAgentResources, agentTotalResources.get());
+ ASSERT_SOME(parse);
- // We request quota for a portion of resources available on the agents.
- Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
+ // Convert JSON response to `QuotaStatus` protobuf.
+ const Try<QuotaStatus> status = ::protobuf::parse<QuotaStatus>(parse.get());
+ ASSERT_FALSE(status.isError());
- EXPECT_TRUE(agentTotalResources.get().contains(quotaResources));
+ EXPECT_EQ(0, status.get().infos().size());
+ }
// Send a quota request for the specified role.
{
@@ -591,13 +518,13 @@ TEST_F(MasterQuotaTest, StatusSingleQuota)
master.get(),
"quota",
createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ createRequestBody(ROLE1, quotaResources, FORCE));
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
<< response.get().body;
}
- // Query the master quota endpoint.
+ // Query the master quota endpoint when quota is set for a single role.
{
Future<Response> response = process::http::get(
master.get(),
@@ -648,7 +575,7 @@ TEST_F(MasterQuotaTest, StatusSingleQuota)
// capability heuristics.
// Checks that a quota request is not satisfied if there are not enough
-// resources.
+// resources on a single agent and the force flag is not set.
TEST_F(MasterQuotaTest, InsufficientResourcesSingleAgent)
{
TestAllocator<> allocator;
@@ -680,66 +607,37 @@ TEST_F(MasterQuotaTest, InsufficientResourcesSingleAgent)
EXPECT_FALSE(agentTotalResources.get().contains(quotaResources));
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
-
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(Conflict().status, response)
- << response.get().body;
-
- Shutdown();
-}
-
-
-// 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();
+ // Since there are not enough resources in the cluster, `capacityHeuristic`
+ // check fails rendering the request unsuccessful.
+ {
+ Future<Response> response = process::http::post(master.get(),
+ "quota",
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+ createRequestBody(ROLE1, quotaResources));
- EXPECT_FALSE(agentTotalResources.get().contains(quotaResources));
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(Conflict().status, response)
+ << response.get().body;
+ }
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources, true));
+ // Force flag should override the `capacityHeuristic` check and make the
+ // request succeed.
+ {
+ Future<Response> response = process::http::post(
+ master.get(),
+ "quota",
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+ createRequestBody(ROLE1, quotaResources, true));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
- << response.get().body;
+ 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.
+// resources on multiple agents and the force flag is not set.
TEST_F(MasterQuotaTest, InsufficientResourcesMultipleAgents)
{
TestAllocator<> allocator;
@@ -786,14 +684,31 @@ TEST_F(MasterQuotaTest, InsufficientResourcesMultipleAgents)
EXPECT_FALSE((agent1TotalResources.get() + agent2TotalResources.get())
.contains(quotaResources));
- Future<Response> response = process::http::post(
- master.get(),
- "quota",
- createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources));
+ // Since there are not enough resources in the cluster, `capacityHeuristic`
+ // check fails which rendering the request unsuccessful.
+ {
+ Future<Response> response = process::http::post(
+ master.get(),
+ "quota",
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+ createRequestBody(ROLE1, quotaResources));
- AWAIT_EXPECT_RESPONSE_STATUS_EQ(Conflict().status, response)
- << response.get().body;
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(Conflict().status, response)
+ << response.get().body;
+ }
+
+ // Force flag should override the `capacityHeuristic` check and make the
+ // request succeed.
+ {
+ Future<Response> response = process::http::post(
+ master.get(),
+ "quota",
+ createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+ createRequestBody(ROLE1, quotaResources, true));
+
+ AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+ << response.get().body;
+ }
Shutdown();
}
@@ -1129,23 +1044,13 @@ TEST_F(MasterQuotaTest, NoAuthenticationNoAuthorization)
Try<PID<Master>> master = StartMaster(&allocator, masterFlags);
ASSERT_SOME(master);
- // Start an agent and wait until its resources are available.
- 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());
+ // Use the force flag for setting quota that cannot be satisfied in
+ // this empty cluster without any agents.
+ const bool FORCE = true;
// Check whether quota can be set.
{
- // Request quota for a portion of the resources available on the agent.
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
- EXPECT_TRUE(agentTotalResources.get().contains(quotaResources));
Future<QuotaInfo> receivedSetRequest;
EXPECT_CALL(allocator, setQuota(Eq(ROLE1), _))
@@ -1157,7 +1062,7 @@ TEST_F(MasterQuotaTest, NoAuthenticationNoAuthorization)
master.get(),
"quota",
None(),
- createRequestBody(ROLE1, quotaResources));
+ createRequestBody(ROLE1, quotaResources, FORCE));
// Quota request succeeds and reaches the allocator.
AWAIT_READY(receivedSetRequest);
@@ -1267,6 +1172,10 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
Try<PID<Master>> master = StartMaster(&allocator, masterFlags);
ASSERT_SOME(master);
+ // Use the force flag for setting quota that cannot be satisfied in
+ // this empty cluster without any agents.
+ const bool FORCE = true;
+
// Try to request quota using a principal that is not the default principal.
// This request will fail because only the default principal is authorized
// to do that.
@@ -1276,14 +1185,11 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
// request below to override the capacity heuristic check.
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
- // Note that we set the force flag because we are setting a quota that
- // cannot currently be satisfied by the resources in the cluster (because
- // there are no agents).
Future<Response> response = process::http::post(
master.get(),
"quota",
createBasicAuthHeaders(DEFAULT_CREDENTIAL_2),
- createRequestBody(ROLE1, quotaResources, true));
+ createRequestBody(ROLE1, quotaResources, FORCE));
AWAIT_EXPECT_RESPONSE_STATUS_EQ(
Unauthorized("Mesos master").status, response) << response.get().body;
@@ -1301,14 +1207,11 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
.WillOnce(DoAll(InvokeSetQuota(&allocator),
FutureArg<1>("aInfo)));
- // Note that we set the force flag because we are setting a quota that
- // cannot currently be satisfied by the resources in the cluster (because
- // there are no agents).
Future<Response> response = process::http::post(
master.get(),
"quota",
createBasicAuthHeaders(DEFAULT_CREDENTIAL),
- createRequestBody(ROLE1, quotaResources, true));
+ createRequestBody(ROLE1, quotaResources, FORCE));
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
<< response.get().body;
@@ -1365,9 +1268,6 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequests)
// The authorizer will map the absence of a principal to "ANY".
TEST_F(MasterQuotaTest, AuthorizeQuotaRequestsWithoutPrincipal)
{
- TestAllocator<> allocator;
- EXPECT_CALL(allocator, initialize(_, _, _, _));
-
// Setup ACLs so that any principal can set quotas for `ROLE1` and remove
// anyone's quotas.
ACLs acls;
@@ -1385,9 +1285,13 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequestsWithoutPrincipal)
masterFlags.authenticate_http = false;
masterFlags.credentials = None();
- Try<PID<Master>> master = StartMaster(&allocator, masterFlags);
+ Try<PID<Master>> master = StartMaster(masterFlags);
ASSERT_SOME(master);
+ // Use the force flag for setting quota that cannot be satisfied in
+ // this empty cluster without any agents.
+ const bool FORCE = true;
+
// Request quota without providing authorization headers.
{
// As we don't care about the enforcement of quota but only the
@@ -1395,14 +1299,12 @@ TEST_F(MasterQuotaTest, AuthorizeQuotaRequestsWithoutPrincipal)
// request below to override the capacity heuristic check.
Resources quotaResources = Resources::parse("cpus:1;mem:512").get();
- // Create a HTTP request without authorization headers. Note that we set the
- // force flag because we are setting a quota that cannot currently be
- // satisfied by the resources in the cluster (because there are no agents).
+ // Create an HTTP request without authorization headers.
Future<Response> response = process::http::post(
master.get(),
"quota",
None(),
- createRequestBody(ROLE1, quotaResources, true));
+ createRequestBody(ROLE1, quotaResources, FORCE));
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
<< response.get().body;