Apache Mesos
resource_estimator.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 __MESOS_SLAVE_RESOURCE_ESTIMATOR_HPP__
18 #define __MESOS_SLAVE_RESOURCE_ESTIMATOR_HPP__
19 
20 #include <string>
21 
22 #include <mesos/resources.hpp>
23 
24 #include <process/future.hpp>
25 
26 #include <stout/lambda.hpp>
27 #include <stout/nothing.hpp>
28 #include <stout/option.hpp>
29 #include <stout/try.hpp>
30 
31 namespace mesos {
32 namespace slave {
33 
34 // A slave component used for oversubscription. It estimates and
35 // predicts the total resources used on the slave and informs the
36 // master about resources that can be oversubscribed.
38 {
39 public:
40  // Create a resource estimator instance of the given type specified
41  // by the user. If the type is not specified, a default resource
42  // estimator instance will be created.
44 
45  virtual ~ResourceEstimator() {}
46 
47  // Initializes this resource estimator. This method needs to be
48  // called before any other member method is called. It registers
49  // a callback in the resource estimator. The callback allows the
50  // resource estimator to fetch the current resource usage for each
51  // executor on slave.
52  virtual Try<Nothing> initialize(
53  const lambda::function<process::Future<ResourceUsage>()>& usage) = 0;
54 
55  // Returns the current estimation about the *maximum* amount of
56  // resources that can be oversubscribed on the slave. A new
57  // estimation will invalidate all the previously returned
58  // estimations. The slave will be calling this method periodically
59  // to forward it to the master. As a result, the estimator should
60  // respond with an estimate every time this method is called.
62 };
63 
64 } // namespace slave {
65 } // namespace mesos {
66 
67 #endif // __MESOS_SLAVE_RESOURCE_ESTIMATOR_HPP__
static Try< ResourceEstimator * > create(const Option< std::string > &type)
Definition: check.hpp:33
virtual process::Future< Resources > oversubscribable()=0
Definition: resource_estimator.hpp:37
Try< ResourceStatistics > usage(pid_t pid, bool mem=true, bool cpus=true)
virtual Try< Nothing > initialize(const lambda::function< process::Future< ResourceUsage >()> &usage)=0
Definition: agent.hpp:25
Try< uint32_t > type(const std::string &path)
virtual ~ResourceEstimator()
Definition: resource_estimator.hpp:45
Definition: future.hpp:58