Apache Mesos
cgroups.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 __CGROUPS_ISOLATOR_HPP__
18 #define __CGROUPS_ISOLATOR_HPP__
19 
20 #include <string>
21 
22 #include <mesos/resources.hpp>
23 
24 #include <process/future.hpp>
25 #include <process/owned.hpp>
26 
27 #include <stout/hashmap.hpp>
28 #include <stout/hashset.hpp>
29 #include <stout/multihashmap.hpp>
30 #include <stout/nothing.hpp>
31 #include <stout/option.hpp>
32 #include <stout/try.hpp>
33 
34 #include "slave/flags.hpp"
35 
37 
39 
40 namespace mesos {
41 namespace internal {
42 namespace slave {
43 
44 // This isolator manages all cgroups subsystems for containers, and delegate
45 // most operations on cgroups subsystem to specific `Subsystem` class.
47 {
48 public:
50 
51  ~CgroupsIsolatorProcess() override;
52 
53  bool supportsNesting() override;
54  bool supportsStandalone() override;
55 
57  const std::vector<mesos::slave::ContainerState>& states,
58  const hashset<ContainerID>& orphans) override;
59 
61  const ContainerID& containerId,
62  const mesos::slave::ContainerConfig& containerConfig) override;
63 
65  const ContainerID& containerId,
66  pid_t pid) override;
67 
69  const ContainerID& containerId) override;
70 
72  const ContainerID& containerId,
73  const Resources& resourceRequests,
74  const google::protobuf::Map<
75  std::string, Value::Scalar>& resourceLimits = {}) override;
76 
78  const ContainerID& containerId) override;
79 
81  const ContainerID& containerId) override;
82 
84  const ContainerID& containerId) override;
85 
86 private:
87  struct Info
88  {
89  Info(const ContainerID& _containerId, const std::string& _cgroup)
90  : containerId(_containerId), cgroup(_cgroup) {}
91 
92  const ContainerID containerId;
93  const std::string cgroup;
94 
95  // This promise will complete if a container is impacted by a resource
96  // limitation and should be terminated.
98 
99  // This `hashset` stores the name of subsystems which are recovered
100  // or prepared for the container.
101  hashset<std::string> subsystems;
102  };
103 
105  const Flags& _flags,
106  const multihashmap<std::string, process::Owned<Subsystem>>&
107  _subsystems);
108 
109  process::Future<Nothing> _recover(
110  const hashset<ContainerID>& orphans,
111  const std::vector<process::Future<Nothing>>& futures);
112 
113  process::Future<Nothing> __recover(
114  const hashset<ContainerID>& unknownOrphans,
115  const std::vector<process::Future<Nothing>>& futures);
116 
117  process::Future<Nothing> ___recover(
118  const ContainerID& containerId);
119 
120  process::Future<Nothing> ____recover(
121  const ContainerID& containerId,
122  const hashset<std::string>& recoveredSubsystems,
123  const std::vector<process::Future<Nothing>>& futures);
124 
126  const ContainerID& containerId,
127  const mesos::slave::ContainerConfig& containerConfig,
128  const std::vector<process::Future<Nothing>>& futures);
129 
131  const ContainerID& containerId,
132  const mesos::slave::ContainerConfig& containerConfig);
133 
134  process::Future<Nothing> _isolate(
135  const std::vector<process::Future<Nothing>>& futures,
136  const ContainerID& containerId,
137  pid_t pid);
138 
139  void _watch(
140  const ContainerID& containerId,
142 
143  process::Future<Nothing> _update(
144  const std::vector<process::Future<Nothing>>& futures);
145 
146  process::Future<Nothing> _cleanup(
147  const ContainerID& containerId,
148  const std::vector<process::Future<Nothing>>& futures);
149 
150  process::Future<Nothing> __cleanup(
151  const ContainerID& containerId,
152  const std::vector<process::Future<Nothing>>& futures);
153 
154  process::Owned<Info> findCgroupInfo(const ContainerID& containerId) const;
155 
156  const Flags flags;
157 
158  // We map hierarchy path and `Subsystem` in subsystems. Same hierarchy may
159  // map to multiple Subsystems. For example, our cgroups hierarchies may
160  // mount like below in the machine:
161  // /cgroup/cpu,cpuacct -> cpu
162  // /cgroup/cpu,cpuacct -> cpuacct
163  // /cgroup/memory -> memory
164  // As we see, subsystem 'cpu' and 'cpuacct' are co-mounted at
165  // '/cgroup/cpu,cpuacct'.
167 
168  // Store cgroups associated information for containers.
170 };
171 
172 } // namespace slave {
173 } // namespace internal {
174 } // namespace mesos {
175 
176 #endif // __CGROUPS_ISOLATOR_HPP__
process::Future< Option< mesos::slave::ContainerLaunchInfo > > prepare(const ContainerID &containerId, const mesos::slave::ContainerConfig &containerConfig) override
Definition: check.hpp:33
process::Future< Nothing > cleanup(const ContainerID &containerId) override
static Try< mesos::slave::Isolator * > create(const Flags &flags)
Definition: resources.hpp:83
process::Future< Nothing > recover(const std::vector< mesos::slave::ContainerState > &states, const hashset< ContainerID > &orphans) override
Definition: flags.hpp:39
process::Future< Nothing > update(const ContainerID &containerId, const Resources &resourceRequests, const google::protobuf::Map< std::string, Value::Scalar > &resourceLimits={}) override
Definition: hashmap.hpp:38
DWORD pid_t
Definition: windows.hpp:181
Definition: multihashmap.hpp:34
process::Future< mesos::slave::ContainerLimitation > watch(const ContainerID &containerId) override
Definition: agent.hpp:25
Result< std::string > cgroup(const std::string &hierarchyName, pid_t pid)
process::Future< ResourceStatistics > usage(const ContainerID &containerId) override
process::Future< ContainerStatus > status(const ContainerID &containerId) override
Definition: attributes.hpp:24
process::Future< Nothing > isolate(const ContainerID &containerId, pid_t pid) override
Definition: owned.hpp:36
Definition: parse.hpp:33