Apache Mesos
quota.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __MASTER_QUOTA_HPP__
18 #define __MASTER_QUOTA_HPP__
19 
20 #include <string>
21 
22 #include <google/protobuf/repeated_field.h>
23 
24 #include <mesos/mesos.hpp>
25 
26 #include <mesos/quota/quota.hpp>
27 
28 #include <stout/error.hpp>
29 #include <stout/hashset.hpp>
30 #include <stout/option.hpp>
31 #include <stout/try.hpp>
32 
33 #include "master/registrar.hpp"
34 #include "master/registry.hpp"
35 
36 namespace mesos {
37 namespace internal {
38 namespace master {
39 namespace quota {
40 
41 // We do not impose any constraints upon quota registry operations.
42 // It is up to the master and allocator to determine whether a quota
43 // request is valid. Hence quota registry operations never fail (i.e.
44 // `perform()` never returns an `Error`). Note that this does not
45 // influence registry failures, e.g. a network partition may occur and
46 // will render the operation hanging (i.e. `Future` for the operation
47 // will not be set).
48 
62 {
63 public:
64  explicit UpdateQuota(const mesos::quota::QuotaInfo& quotaInfo);
65 
66 protected:
67  Try<bool> perform(Registry* registry, hashset<SlaveID>* slaveIDs);
68 
69 private:
70  const mesos::quota::QuotaInfo info;
71 };
72 
73 
81 {
82 public:
83  explicit RemoveQuota(const std::string& _role);
84 
85 protected:
86  Try<bool> perform(Registry* registry, hashset<SlaveID>* slaveIDs);
87 
88 private:
89  const std::string role;
90 };
91 
92 
97  const mesos::quota::QuotaRequest& request);
98 
103  const std::string& role,
104  const google::protobuf::RepeatedPtrField<Resource>& resources);
105 
106 
107 namespace validation {
108 
109 // `QuotaInfo` is valid if the following conditions are met:
110 // - Request includes a single role across all resources.
111 // - Irrelevant fields in `Resources` are not set
112 // (e.g. `ReservationInfo`).
113 // - Request only contains scalar `Resources`.
114 Option<Error> quotaInfo(const mesos::quota::QuotaInfo& quotaInfo);
115 
116 } // namespace validation {
117 
118 } // namespace quota {
119 } // namespace master {
120 } // namespace internal {
121 } // namespace mesos {
122 
123 #endif // __MASTER_QUOTA_HPP__
Future< Response > request(const Request &request, bool streamedResponse=false)
Asynchronously sends an HTTP request to the process and returns the HTTP response once the entire res...
Sets quota for a role.
Definition: quota.hpp:61
Definition: try.hpp:34
Try< bool > perform(Registry *registry, hashset< SlaveID > *slaveIDs)
UpdateQuota(const mesos::quota::QuotaInfo &quotaInfo)
Removes quota for a role.
Definition: quota.hpp:80
Option< Error > quotaInfo(const mesos::quota::QuotaInfo &quotaInfo)
Try< bool > perform(Registry *registry, hashset< SlaveID > *slaveIDs)
Try< mesos::quota::QuotaInfo > createQuotaInfo(const mesos::quota::QuotaRequest &request)
Creates a QuotaInfo protobuf from the QuotaRequest protobuf.
Definition: registrar.hpp:45