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:
49  static Try<mesos::slave::Isolator*> create(const Flags& flags);
50 
51  virtual ~CgroupsIsolatorProcess();
52 
53  virtual bool supportsNesting();
54  virtual bool supportsStandalone();
55 
57  const std::list<mesos::slave::ContainerState>& states,
58  const hashset<ContainerID>& orphans);
59 
61  const ContainerID& containerId,
62  const mesos::slave::ContainerConfig& containerConfig);
63 
65  const ContainerID& containerId,
66  pid_t pid);
67 
69  const ContainerID& containerId);
70 
72  const ContainerID& containerId,
73  const Resources& resources);
74 
76  const ContainerID& containerId);
77 
79  const ContainerID& containerId);
80 
82  const ContainerID& containerId);
83 
84 protected:
85  virtual void initialize();
86 
87  virtual void finalize();
88 
89 private:
90  struct Info
91  {
92  Info(const ContainerID& _containerId, const std::string& _cgroup)
93  : containerId(_containerId), cgroup(_cgroup) {}
94 
95  const ContainerID containerId;
96  const std::string cgroup;
97 
98  // This promise will complete if a container is impacted by a resource
99  // limitation and should be terminated.
101 
102  // This `hashset` stores the name of subsystems which are recovered
103  // or prepared for the container.
104  hashset<std::string> subsystems;
105  };
106 
108  const Flags& _flags,
109  const hashmap<std::string, std::string>& _hierarchies,
110  const multihashmap<std::string, process::Owned<Subsystem>>& _subsystems);
111 
112  process::Future<Nothing> _recover(
113  const hashset<ContainerID>& orphans,
114  const std::list<process::Future<Nothing>>& futures);
115 
116  process::Future<Nothing> __recover(
117  const hashset<ContainerID>& unknownOrphans,
118  const std::list<process::Future<Nothing>>& futures);
119 
120  process::Future<Nothing> ___recover(
121  const ContainerID& containerId);
122 
123  process::Future<Nothing> ____recover(
124  const ContainerID& containerId,
125  const hashset<std::string>& recoveredSubsystems,
126  const std::list<process::Future<Nothing>>& futures);
127 
129  const ContainerID& containerId,
130  const mesos::slave::ContainerConfig& containerConfig,
131  const std::list<process::Future<Nothing>>& futures);
132 
133  process::Future<Nothing> _isolate(
134  const std::list<process::Future<Nothing>>& futures);
135 
136  void _watch(
137  const ContainerID& containerId,
139 
140  process::Future<Nothing> _update(
141  const std::list<process::Future<Nothing>>& futures);
142 
143  process::Future<Nothing> _cleanup(
144  const ContainerID& containerId,
145  const std::list<process::Future<Nothing>>& futures);
146 
147  process::Future<Nothing> __cleanup(
148  const ContainerID& containerId,
149  const std::list<process::Future<Nothing>>& futures);
150 
151  const Flags flags;
152 
153  // Map from subsystem name to hierarchy path.
155 
156  // We map hierarchy path and `Subsystem` in subsystems. Same hierarchy may
157  // map to multiple Subsystems. For example, our cgroups hierarchies may
158  // mount like below in the machine:
159  // /cgroup/cpu,cpuacct -> cpu
160  // /cgroup/cpu,cpuacct -> cpuacct
161  // /cgroup/memory -> memory
162  // As we see, subsystem 'cpu' and 'cpuacct' are co-mounted at
163  // '/cgroup/cpu,cpuacct'.
165 
166  // Store cgroups associated information for containers.
168 };
169 
170 } // namespace slave {
171 } // namespace internal {
172 } // namespace mesos {
173 
174 #endif // __CGROUPS_ISOLATOR_HPP__
virtual process::Future< Nothing > update(const ContainerID &containerId, const Resources &resources)
virtual process::Future< Nothing > cleanup(const ContainerID &containerId)
virtual process::Future< mesos::slave::ContainerLimitation > watch(const ContainerID &containerId)
Definition: try.hpp:34
virtual process::Future< Nothing > isolate(const ContainerID &containerId, pid_t pid)
static Try< mesos::slave::Isolator * > create(const Flags &flags)
Definition: resources.hpp:79
Definition: flags.hpp:39
DWORD pid_t
Definition: windows.hpp:187
Definition: multihashmap.hpp:34
Result< std::string > cgroup(pid_t pid)
virtual void initialize()
Invoked when a process gets spawned.
virtual void finalize()
Invoked when a process is terminated.
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
virtual process::Future< Nothing > recover(const std::list< mesos::slave::ContainerState > &states, const hashset< ContainerID > &orphans)
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId)
virtual process::Future< Option< mesos::slave::ContainerLaunchInfo > > prepare(const ContainerID &containerId, const mesos::slave::ContainerConfig &containerConfig)
Definition: owned.hpp:35
virtual process::Future< ContainerStatus > status(const ContainerID &containerId)