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/16 17:18:15 UTC

[2/5] mesos git commit: Quota: Created stubs for quota set requests.

Quota: Created stubs for quota set requests.

Processing quota request consists of several stages: request
validation, sanity check and so on. This patch creates a basic
workflow for quota requests, while the stages are implemented
in subsequent patches.

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


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

Branch: refs/heads/master
Commit: 462f64d30b192498ded7804894eae98f984a21c6
Parents: 77b5de7
Author: Alexander Rukletsov <ru...@gmail.com>
Authored: Mon Nov 16 09:37:45 2015 +0100
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Nov 16 17:01:17 2015 +0100

----------------------------------------------------------------------
 src/CMakeLists.txt           |  1 +
 src/Makefile.am              |  2 ++
 src/master/master.hpp        | 22 +++++++++++-----
 src/master/quota.cpp         | 33 +++++++++++++++++++++++
 src/master/quota.hpp         | 38 +++++++++++++++++++++++++++
 src/master/quota_handler.cpp | 55 +++++++++++++++++++++++++++++++++++++--
 6 files changed, 143 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/462f64d3/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d548d5e..9a2c70d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -140,6 +140,7 @@ set(MASTER_SRC
   master/maintenance.cpp
   master/master.cpp
   master/metrics.cpp
+  master/quota.cpp
   master/quota_handler.cpp
   master/registry.hpp
   master/registry.proto

http://git-wip-us.apache.org/repos/asf/mesos/blob/462f64d3/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index ba9ba11..5aac0ee 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -548,6 +548,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   master/maintenance.cpp						\
   master/master.cpp							\
   master/metrics.cpp							\
+  master/quota.cpp							\
   master/quota_handler.cpp						\
   master/registrar.cpp							\
   master/repairer.cpp							\
@@ -653,6 +654,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   master/maintenance.hpp						\
   master/master.hpp							\
   master/metrics.hpp							\
+  master/quota.hpp							\
   master/registrar.hpp							\
   master/registry.hpp							\
   master/repairer.hpp							\

http://git-wip-us.apache.org/repos/asf/mesos/blob/462f64d3/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 055a626..a6a1598 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -38,6 +38,8 @@
 
 #include <mesos/module/authenticator.hpp>
 
+#include <mesos/quota/quota.hpp>
+
 #include <mesos/scheduler/scheduler.hpp>
 
 #include <process/limiter.hpp>
@@ -860,12 +862,7 @@ private:
     }
 
     process::Future<process::http::Response> set(
-        const process::http::Request& request) const
-    {
-      // TODO(joerg84): For now this is just a stub. It will be filled as
-      // part of MESOS-1791.
-      return process::http::NotImplemented();
-    }
+        const process::http::Request& request) const;
 
     process::Future<process::http::Response> remove(
         const process::http::Request& request) const
@@ -1234,6 +1231,15 @@ private:
 
   hashmap<std::string, Role*> roles;
 
+  struct Quota
+  {
+    // Holds the quota protobuf, as constructed from an operator's request.
+    mesos::quota::QuotaInfo info;
+  };
+
+  // We store quotas by role because we set them at the role level.
+  hashmap<std::string, Quota> quotas;
+
   // Authenticator names as supplied via flags.
   std::vector<std::string> authenticatorNames;
 
@@ -1969,6 +1975,10 @@ struct Role
 
   mesos::master::RoleInfo info;
 
+  // NOTE: The quota for this role is stored in the master. This avoids
+  // duplication of this information and prevents a strict association of quota
+  // with roles in the future.
+
   hashmap<FrameworkID, Framework*> frameworks;
 };
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/462f64d3/src/master/quota.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota.cpp b/src/master/quota.cpp
new file mode 100644
index 0000000..5508b86
--- /dev/null
+++ b/src/master/quota.cpp
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "master/quota.hpp"
+
+namespace mesos {
+namespace internal {
+namespace master {
+namespace quota {
+
+namespace validation {
+
+} // namespace validation {
+
+} // namespace quota {
+} // namespace master {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/462f64d3/src/master/quota.hpp
----------------------------------------------------------------------
diff --git a/src/master/quota.hpp b/src/master/quota.hpp
new file mode 100644
index 0000000..89b0e76
--- /dev/null
+++ b/src/master/quota.hpp
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MASTER_QUOTA_HPP__
+#define __MASTER_QUOTA_HPP__
+
+#include <mesos/quota/quota.hpp>
+
+namespace mesos {
+namespace internal {
+namespace master {
+namespace quota {
+
+namespace validation {
+
+} // namespace validation {
+
+} // namespace quota {
+} // namespace master {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __MASTER_QUOTA_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/462f64d3/src/master/quota_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/quota_handler.cpp b/src/master/quota_handler.cpp
index 9e3b722..7c14188 100644
--- a/src/master/quota_handler.cpp
+++ b/src/master/quota_handler.cpp
@@ -16,14 +16,65 @@
 * limitations under the License
 */
 
+#include <mesos/resources.hpp>
+
+#include <mesos/quota/quota.hpp>
+
+#include <process/defer.hpp>
+#include <process/future.hpp>
+#include <process/http.hpp>
+
+#include <stout/protobuf.hpp>
+
 #include "master/master.hpp"
 
+namespace http = process::http;
+
+using std::string;
+
+using http::Accepted;
+using http::BadRequest;
+using http::Conflict;
+using http::OK;
+
+using process::Future;
+
+using mesos::quota::QuotaInfo;
 namespace mesos {
 namespace internal {
 namespace master {
 
-// TODO(joerg84): For right now this is a stub to enable cooperation.
-// It will be filled as part of MESOS-1791.
+Future<http::Response> Master::QuotaHandler::set(
+    const http::Request& request) const
+{
+  // Authenticate and authorize the request.
+  // TODO(alexr): Check Master::Http::authenticate() for an example.
+
+  // TODO(alexr): Validate and convert the request to internal protobuf message.
+
+  // Validate whether a quota request can be satisfied.
+  // TODO(alexr): Implement as per MESOS-3073.
+
+  // 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.
+  QuotaInfo quotaInfo;
+  master->quotas[quotaInfo.role()] = Quota{quotaInfo};
+
+  // Update the registry with the new quota.
+  // TODO(alexr): MESOS-3165.
+
+  // We are all set, grant the request.
+  // TODO(alexr): Implement as per MESOS-3073.
+  // TODO(alexr): This should be done after registry operation succeeds.
+
+  // Notfify allocator.
+  master->allocator->setQuota(quotaInfo.role(), quotaInfo);
+
+  return OK();
+}
 
 } // namespace master {
 } // namespace internal {