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 
56 {
57 public:
58  // This operation needs to take in a `RepeatedPtrField` of `QuotaConfig`
59  // to ensure all-or-nothing quota updates for multiple roles.
60  explicit UpdateQuota(
61  const google::protobuf::RepeatedPtrField<mesos::quota::QuotaConfig>&
62  quotaConfigs);
63 
64 protected:
65  Try<bool> perform(Registry* registry, hashset<SlaveID>* slaveIDs) override;
66 
67 private:
68  google::protobuf::RepeatedPtrField<mesos::quota::QuotaConfig> configs;
69 };
70 
71 
75 mesos::quota::QuotaInfo createQuotaInfo(
76  const mesos::quota::QuotaRequest& request);
77 
78 namespace validation {
79 
80 // `QuotaInfo` is valid if the following conditions are met:
81 // - Request includes a single role across all resources.
82 // - Irrelevant fields in `Resources` are not set
83 // (e.g. `ReservationInfo`).
84 // - Request only contains scalar `Resources`.
85 //
86 // TODO(bmahler): Remove this in favor of `validate` below. This
87 // requires some new logic outside of this function to prevent
88 // users from setting `limit` explicitly in the old API and
89 // setting the `limit` implicitly for users of the old API before
90 // calling into this.
91 Option<Error> quotaInfo(const mesos::quota::QuotaInfo& quotaInfo);
92 
93 } // namespace validation {
94 
113 Option<Error> validate(const mesos::quota::QuotaRequest& request);
114 
125 Option<Error> validate(const mesos::quota::QuotaConfig& config);
126 
127 } // namespace quota {
128 } // namespace master {
129 } // namespace internal {
130 } // namespace mesos {
131 
132 #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:55
Definition: master.hpp:27
Definition: check.hpp:33
Definition: agent.hpp:25
Option< Error > validate(const mesos::quota::QuotaRequest &request)
A QuotaRequest is valid if the following conditions are met:
Option< Error > quotaInfo(const mesos::quota::QuotaInfo &quotaInfo)
Definition: attributes.hpp:24
Definition: registrar.hpp:45
mesos::quota::QuotaInfo createQuotaInfo(const mesos::quota::QuotaRequest &request)
Creates a QuotaInfo protobuf from the QuotaRequest protobuf.
Try< bool > perform(Registry *registry, hashset< SlaveID > *slaveIDs) override
UpdateQuota(const google::protobuf::RepeatedPtrField< mesos::quota::QuotaConfig > &quotaConfigs)