You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/06/28 18:02:58 UTC

[1/3] mesos git commit: Added validation check on resources for reserve/unreserve call.

Repository: mesos
Updated Branches:
  refs/heads/master 0c0a938fa -> aaecd7230


Added validation check on resources for reserve/unreserve call.

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


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

Branch: refs/heads/master
Commit: d43f134874be130128b57929bc0917f25344d169
Parents: 0c0a938
Author: Abhishek Dasgupta <a1...@linux.vnet.ibm.com>
Authored: Tue Jun 28 11:00:59 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Tue Jun 28 11:00:59 2016 -0700

----------------------------------------------------------------------
 src/master/validation.cpp | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d43f1348/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index 9120b71..3009549 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -135,17 +135,35 @@ Option<Error> validate(
     case mesos::master::Call::GET_LEADING_MASTER:
       return None();
 
-    case mesos::master::Call::RESERVE_RESOURCES:
+    case mesos::master::Call::RESERVE_RESOURCES: {
       if (!call.has_reserve_resources()) {
         return Error("Expecting 'reserve_resources' to be present");
       }
+
+      Option<Error> error =
+        Resources::validate(call.reserve_resources().resources());
+
+      if (error.isSome()) {
+        return error;
+      }
+
       return None();
+    }
 
-    case mesos::master::Call::UNRESERVE_RESOURCES:
+    case mesos::master::Call::UNRESERVE_RESOURCES: {
       if (!call.has_unreserve_resources()) {
         return Error("Expecting 'unreserve_resources' to be present");
       }
+
+      Option<Error> error =
+        Resources::validate(call.unreserve_resources().resources());
+
+      if (error.isSome()) {
+        return error;
+      }
+
       return None();
+    }
 
     case mesos::master::Call::CREATE_VOLUMES:
       if (!call.has_create_volumes()) {


[3/3] mesos git commit: Implemented REMOVE_QUOTA Call in v1 master API.

Posted by an...@apache.org.
Implemented REMOVE_QUOTA Call in v1 master API.

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


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

Branch: refs/heads/master
Commit: aaecd723048ad96e0df736271d3ae9df6f7bd815
Parents: 14b8c3a
Author: Abhishek Dasgupta <a1...@linux.vnet.ibm.com>
Authored: Tue Jun 28 11:01:15 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Tue Jun 28 11:01:15 2016 -0700

----------------------------------------------------------------------
 src/master/http.cpp          |  2 +-
 src/master/master.hpp        |  8 ++++
 src/master/quota_handler.cpp | 23 +++++++++-
 src/tests/api_tests.cpp      | 91 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 121 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/aaecd723/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 7d6db2d..e827e69 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -595,7 +595,7 @@ Future<Response> Master::Http::api(
       return quotaHandler.set(call, principal);
 
     case mesos::master::Call::REMOVE_QUOTA:
-      return NotImplemented();
+      return quotaHandler.remove(call, principal);
 
     case mesos::master::Call::SUBSCRIBE: {
       Pipe pipe;

http://git-wip-us.apache.org/repos/asf/mesos/blob/aaecd723/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index daadebc..5c43f03 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1000,6 +1000,10 @@ private:
         const Option<std::string>& principal) const;
 
     process::Future<process::http::Response> remove(
+        const mesos::master::Call& call,
+        const Option<std::string>& principal) const;
+
+    process::Future<process::http::Response> remove(
         const process::http::Request& request,
         const Option<std::string>& principal) const;
 
@@ -1076,6 +1080,10 @@ private:
         bool forced) const;
 
     process::Future<process::http::Response> _remove(
+        const std::string& role,
+        const Option<std::string>& principal) const;
+
+    process::Future<process::http::Response> __remove(
         const std::string& role) const;
 
     // To perform actions related to quota management, we require access to the

http://git-wip-us.apache.org/repos/asf/mesos/blob/aaecd723/src/master/quota_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index 0ad7bc9..bf6a613 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -432,6 +432,17 @@ Future<http::Response> Master::QuotaHandler::__set(
 
 
 Future<http::Response> Master::QuotaHandler::remove(
+    const mesos::master::Call& call,
+    const Option<string>& principal) const
+{
+  CHECK_EQ(mesos::master::Call::REMOVE_QUOTA, call.type());
+  CHECK(call.has_remove_quota());
+
+  return _remove(call.remove_quota().role(), principal);
+}
+
+
+Future<http::Response> Master::QuotaHandler::remove(
     const http::Request& request,
     const Option<string>& principal) const
 {
@@ -474,14 +485,22 @@ Future<http::Response> Master::QuotaHandler::remove(
         "': Role '" + role + "' has no quota set");
   }
 
+  return _remove(role, principal);
+}
+
+
+Future<http::Response> Master::QuotaHandler::_remove(
+    const string& role,
+    const Option<string>& principal) const
+{
   return authorizeRemoveQuota(principal, master->quotas[role].info)
     .then(defer(master->self(), [=](bool authorized) -> Future<http::Response> {
-      return !authorized ? Forbidden() : _remove(role);
+      return !authorized ? Forbidden() : __remove(role);
     }));
 }
 
 
-Future<http::Response> Master::QuotaHandler::_remove(const string& role) const
+Future<http::Response> Master::QuotaHandler::__remove(const string& role) const
 {
   // Remove quota from the quota-related local state. We do this before
   // updating the registry in order to make sure that we are not already

http://git-wip-us.apache.org/repos/asf/mesos/blob/aaecd723/src/tests/api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp
index 32a0649..fd51fe9 100644
--- a/src/tests/api_tests.cpp
+++ b/src/tests/api_tests.cpp
@@ -1257,6 +1257,97 @@ TEST_P(MasterAPITest, SetQuota)
 }
 
 
+// This test verifies if we can remove a quota through `REMOVE_QUOTA` call,
+// after we set quota resources through `SET_QUOTA` call.
+TEST_P(MasterAPITest, RemoveQuota)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  v1::Resources quotaResources =
+    v1::Resources::parse("cpus:1;mem:512").get();
+
+  {
+    v1::master::Call v1Call;
+    v1Call.set_type(v1::master::Call::SET_QUOTA);
+
+    v1::quota::QuotaRequest* quotaRequest =
+      v1Call.mutable_set_quota()->mutable_quota_request();
+
+    // Use the force flag for setting quota that cannot be satisfied in
+    // this empty cluster without any agents.
+    quotaRequest->set_force(true);
+    quotaRequest->set_role("role1");
+    quotaRequest->mutable_guarantee()->CopyFrom(quotaResources);
+
+    ContentType contentType = GetParam();
+
+    // Send a quota request for the specified role.
+    Future<Response> response = process::http::post(
+        master.get()->pid,
+        "api/v1",
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+        serialize(contentType, v1Call),
+        stringify(contentType));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+  }
+
+  // Verify if the quota is set using `GET_QUOTA` call.
+  {
+    v1::master::Call v1Call;
+    v1Call.set_type(v1::master::Call::GET_QUOTA);
+
+    ContentType contentType = GetParam();
+
+    Future<v1::master::Response> v1Response =
+      post(master.get()->pid, v1Call, contentType);
+
+    AWAIT_READY(v1Response);
+    ASSERT_TRUE(v1Response->IsInitialized());
+    ASSERT_EQ(v1::master::Response::GET_QUOTA, v1Response->type());
+    ASSERT_EQ(1, v1Response->get_quota().status().infos().size());
+    EXPECT_EQ(quotaResources,
+      v1Response->get_quota().status().infos(0).guarantee());
+  }
+
+  // Remove the quota using `REMOVE_QUOTA` call.
+  {
+    v1::master::Call v1Call;
+    v1Call.set_type(v1::master::Call::REMOVE_QUOTA);
+    v1Call.mutable_remove_quota()->set_role("role1");
+
+    ContentType contentType = GetParam();
+
+    // Send a quota request for the specified role.
+    Future<Response> response = process::http::post(
+        master.get()->pid,
+        "api/v1",
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+        serialize(contentType, v1Call),
+        stringify(contentType));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+  }
+
+  // Verify if the quota is removed using `GET_QUOTA` call.
+  {
+    v1::master::Call v1Call;
+    v1Call.set_type(v1::master::Call::GET_QUOTA);
+
+    ContentType contentType = GetParam();
+
+    Future<v1::master::Response> v1Response =
+      post(master.get()->pid, v1Call, contentType);
+
+    AWAIT_READY(v1Response);
+    ASSERT_TRUE(v1Response->IsInitialized());
+    ASSERT_EQ(v1::master::Response::GET_QUOTA, v1Response->type());
+    ASSERT_EQ(0, v1Response->get_quota().status().infos().size());
+  }
+}
+
+
 // Test create and destroy persistent volumes through the master operator API.
 // In this test case, we create a persistent volume with the API, then launch a
 // task using the volume. Then we destroy the volume with the API after the task


[2/3] mesos git commit: Implemented GET_QUOTA Call in v1 master API.

Posted by an...@apache.org.
Implemented GET_QUOTA Call in v1 master API.

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


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

Branch: refs/heads/master
Commit: 14b8c3aac071d791d3cf0f38f91d5c35b5857f1e
Parents: d43f134
Author: Abhishek Dasgupta <a1...@linux.vnet.ibm.com>
Authored: Tue Jun 28 11:01:09 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Tue Jun 28 11:01:09 2016 -0700

----------------------------------------------------------------------
 include/mesos/master/master.proto    |  1 +
 include/mesos/v1/master/master.proto |  1 +
 src/master/http.cpp                  |  2 +-
 src/master/master.hpp                | 11 +++--
 src/master/quota_handler.cpp         | 78 +++++++++++++++++++------------
 src/tests/api_tests.cpp              | 54 +++++++++++++++++++++
 6 files changed, 113 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/14b8c3aa/include/mesos/master/master.proto
----------------------------------------------------------------------
diff --git a/include/mesos/master/master.proto b/include/mesos/master/master.proto
index f63cc5a..b993652 100644
--- a/include/mesos/master/master.proto
+++ b/include/mesos/master/master.proto
@@ -351,6 +351,7 @@ message Response {
     required maintenance.Schedule schedule = 1;
   }
 
+  // Contains the cluster's configured quotas.
   message GetQuota {
     required quota.QuotaStatus status = 1;
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/14b8c3aa/include/mesos/v1/master/master.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/master/master.proto b/include/mesos/v1/master/master.proto
index d98281d..9d05f92 100644
--- a/include/mesos/v1/master/master.proto
+++ b/include/mesos/v1/master/master.proto
@@ -352,6 +352,7 @@ message Response {
     required maintenance.Schedule schedule = 1;
   }
 
+  // Contains the cluster's configured quotas.
   message GetQuota {
     required quota.QuotaStatus status = 1;
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/14b8c3aa/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index e089fe9..7d6db2d 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -589,7 +589,7 @@ Future<Response> Master::Http::api(
       return stopMaintenance(call, principal, acceptType);
 
     case mesos::master::Call::GET_QUOTA:
-      return NotImplemented();
+      return quotaHandler.status(call, principal, acceptType);
 
     case mesos::master::Call::SET_QUOTA:
       return quotaHandler.set(call, principal);

http://git-wip-us.apache.org/repos/asf/mesos/blob/14b8c3aa/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index ed7ea72..daadebc 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -983,6 +983,11 @@ private:
 
     // Returns a list of set quotas.
     process::Future<process::http::Response> status(
+        const mesos::master::Call& call,
+        const Option<std::string>& principal,
+        ContentType contentType) const;
+
+    process::Future<process::http::Response> status(
         const process::http::Request& request,
         const Option<std::string>& principal) const;
 
@@ -1059,10 +1064,8 @@ private:
         const Option<std::string>& principal,
         const mesos::quota::QuotaInfo& quotaInfo) const;
 
-    process::Future<process::http::Response> _status(
-        const process::http::Request& request,
-        const std::vector<mesos::quota::QuotaInfo>& quotaInfos,
-        const std::list<bool>& authorized) const;
+    process::Future<mesos::quota::QuotaStatus> _status(
+        const Option<std::string>& principal) const;
 
     process::Future<process::http::Response> _set(
         const mesos::quota::QuotaRequest& quotaRequest,

http://git-wip-us.apache.org/repos/asf/mesos/blob/14b8c3aa/src/master/quota_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index 4fa7533..0ad7bc9 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -206,6 +206,25 @@ void Master::QuotaHandler::rescindOffers(const QuotaInfo& request) const
 
 
 Future<http::Response> Master::QuotaHandler::status(
+    const mesos::master::Call& call,
+    const Option<string>& principal,
+    ContentType contentType) const
+{
+  CHECK_EQ(mesos::master::Call::GET_QUOTA, call.type());
+
+  return _status(principal)
+    .then([contentType](const QuotaStatus& status) -> Future<http::Response> {
+      mesos::master::Response response;
+      response.set_type(mesos::master::Response::GET_QUOTA);
+      response.mutable_get_quota()->mutable_status()->CopyFrom(status);
+
+      return OK(serialize(contentType, evolve(response)),
+                stringify(contentType));
+    });
+}
+
+
+Future<http::Response> Master::QuotaHandler::status(
     const http::Request& request,
     const Option<string>& principal) const
 {
@@ -214,6 +233,16 @@ Future<http::Response> Master::QuotaHandler::status(
   // Check that the request type is GET which is guaranteed by the master.
   CHECK_EQ("GET", request.method);
 
+  return _status(principal)
+    .then([request](const QuotaStatus& status) -> Future<http::Response> {
+      return OK(JSON::protobuf(status), request.url.query.get("jsonp"));
+    });
+}
+
+
+Future<QuotaStatus> Master::QuotaHandler::_status(
+    const Option<string>& principal) const
+{
   // Quotas can be updated during preparation of the response.
   // Copy current view of the collection to avoid conflicts.
   vector<QuotaInfo> quotaInfos;
@@ -235,36 +264,27 @@ Future<http::Response> Master::QuotaHandler::status(
     .then(defer(
         master->self(),
         [=](const list<bool>& authorizedRolesCollected)
-            -> Future<http::Response> {
-      return _status(request, quotaInfos, authorizedRolesCollected);
-    }));
-}
-
-
-Future<http::Response> Master::QuotaHandler::_status(
-    const http::Request& request,
-    const vector<QuotaInfo>& quotaInfos,
-    const list<bool>& authorizedRoles) const
-{
-  CHECK(quotaInfos.size() == authorizedRoles.size());
-
-  QuotaStatus status;
-  status.mutable_infos()->Reserve(static_cast<int>(quotaInfos.size()));
-
-  // Create an entry (including role and resources) for each quota,
-  // except those filtered out based on the authorizer's response.
-  //
-  // NOTE: This error-prone code will be removed with
-  // the introduction of authorization filters.
-  auto quotaInfoIt = quotaInfos.begin();
-  foreach (const bool& authorized, authorizedRoles) {
-    if (authorized) {
-      status.add_infos()->CopyFrom(*quotaInfoIt);
-    }
-    ++quotaInfoIt;
-  }
+            -> Future<QuotaStatus> {
+      CHECK(quotaInfos.size() == authorizedRolesCollected.size());
+
+      QuotaStatus status;
+      status.mutable_infos()->Reserve(static_cast<int>(quotaInfos.size()));
+
+      // Create an entry (including role and resources) for each quota,
+      // except those filtered out based on the authorizer's response.
+      //
+      // NOTE: This error-prone code will be removed with
+      // the introduction of authorization filters.
+      auto quotaInfoIt = quotaInfos.begin();
+      foreach (const bool& authorized, authorizedRolesCollected) {
+        if (authorized) {
+          status.add_infos()->CopyFrom(*quotaInfoIt);
+        }
+      ++quotaInfoIt;
+      }
 
-  return OK(JSON::protobuf(status), request.url.query.get("jsonp"));
+      return status;
+    }));
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/14b8c3aa/src/tests/api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/api_tests.cpp b/src/tests/api_tests.cpp
index 7b5c761..32a0649 100644
--- a/src/tests/api_tests.cpp
+++ b/src/tests/api_tests.cpp
@@ -1169,6 +1169,60 @@ TEST_P(MasterAPITest, Subscribe)
 }
 
 
+// This test verifies if we can retrieve the current quota status through
+// `GET_QUOTA` call, after we set quota resources through `SET_QUOTA` call.
+TEST_P(MasterAPITest, GetQuota)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  v1::Resources quotaResources =
+    v1::Resources::parse("cpus:1;mem:512").get();
+
+  ContentType contentType = GetParam();
+
+  {
+    v1::master::Call v1Call;
+    v1Call.set_type(v1::master::Call::SET_QUOTA);
+
+    v1::quota::QuotaRequest* quotaRequest =
+      v1Call.mutable_set_quota()->mutable_quota_request();
+
+    // Use the force flag for setting quota that cannot be satisfied in
+    // this empty cluster without any agents.
+    quotaRequest->set_force(true);
+    quotaRequest->set_role("role1");
+    quotaRequest->mutable_guarantee()->CopyFrom(quotaResources);
+
+    // Send a quota request for the specified role.
+    Future<Response> response = process::http::post(
+        master.get()->pid,
+        "api/v1",
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+        serialize(contentType, v1Call),
+        stringify(contentType));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+  }
+
+  // Verify the quota is set using the `GET_QUOTA` call.
+  {
+    v1::master::Call v1Call;
+    v1Call.set_type(v1::master::Call::GET_QUOTA);
+
+    Future<v1::master::Response> v1Response =
+      post(master.get()->pid, v1Call, contentType);
+
+    AWAIT_READY(v1Response);
+    ASSERT_TRUE(v1Response->IsInitialized());
+    ASSERT_EQ(v1::master::Response::GET_QUOTA, v1Response->type());
+    ASSERT_EQ(1, v1Response->get_quota().status().infos().size());
+    EXPECT_EQ(quotaResources,
+              v1Response->get_quota().status().infos(0).guarantee());
+  }
+}
+
+
 TEST_P(MasterAPITest, SetQuota)
 {
   Try<Owned<cluster::Master>> master = StartMaster();