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& resources) override;
74 
76  const ContainerID& containerId) override;
77 
79  const ContainerID& containerId) override;
80 
82  const ContainerID& containerId) override;
83 
84 private:
85  struct Info
86  {
87  Info(const ContainerID& _containerId, const std::string& _cgroup)
88  : containerId(_containerId), cgroup(_cgroup) {}
89 
90  const ContainerID containerId;
91  const std::string cgroup;
92 
93  // This promise will complete if a container is impacted by a resource
94  // limitation and should be terminated.
96 
97  // This `hashset` stores the name of subsystems which are recovered
98  // or prepared for the container.
99  hashset<std::string> subsystems;
100  };
101 
103  const Flags& _flags,
104  const multihashmap<std::string, process::Owned<Subsystem>>&
105  _subsystems);
106 
107  process::Future<Nothing> _recover(
108  const hashset<ContainerID>& orphans,
109  const std::vector<process::Future<Nothing>>& futures);
110 
111  process::Future<Nothing> __recover(
112  const hashset<ContainerID>& unknownOrphans,
113  const std::vector<process::Future<Nothing>>& futures);
114 
115  process::Future<Nothing> ___recover(
116  const ContainerID& containerId);
117 
118  process::Future<Nothing> ____recover(
119  const ContainerID& containerId,
120  const hashset<std::string>& recoveredSubsystems,
121  const std::vector<process::Future<Nothing>>& futures);
122 
124  const ContainerID& containerId,
125  const mesos::slave::ContainerConfig& containerConfig,
126  const std::vector<process::Future<Nothing>>& futures);
127 
129  const ContainerID& containerId,
130  const mesos::slave::ContainerConfig& containerConfig);
131 
132  process::Future<Nothing> _isolate(
133  const std::vector<process::Future<Nothing>>& futures);
134 
135  void _watch(
136  const ContainerID& containerId,
138 
139  process::Future<Nothing> _update(
140  const std::vector<process::Future<Nothing>>& futures);
141 
142  process::Future<Nothing> _cleanup(
143  const ContainerID& containerId,
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  const Flags flags;
151 
152  // We map hierarchy path and `Subsystem` in subsystems. Same hierarchy may
153  // map to multiple Subsystems. For example, our cgroups hierarchies may
154  // mount like below in the machine:
155  // /cgroup/cpu,cpuacct -> cpu
156  // /cgroup/cpu,cpuacct -> cpuacct
157  // /cgroup/memory -> memory
158  // As we see, subsystem 'cpu' and 'cpuacct' are co-mounted at
159  // '/cgroup/cpu,cpuacct'.
161 
162  // Store cgroups associated information for containers.
164 };
165 
166 } // namespace slave {
167 } // namespace internal {
168 } // namespace mesos {
169 
170 #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:81
process::Future< Nothing > recover(const std::vector< mesos::slave::ContainerState > &states, const hashset< ContainerID > &orphans) override
Definition: flags.hpp:39
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: spec.hpp:26
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
process::Future< Nothing > update(const ContainerID &containerId, const Resources &resources) override