Apache Mesos
subsystem.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_SUBSYSTEM_HPP__
18 #define __CGROUPS_ISOLATOR_SUBSYSTEM_HPP__
19 
20 #include <string>
21 
22 #include <mesos/resources.hpp>
23 
24 #include <mesos/slave/isolator.hpp>
25 
26 #include <process/future.hpp>
27 #include <process/owned.hpp>
28 #include <process/process.hpp>
29 
30 #include <stout/nothing.hpp>
31 #include <stout/try.hpp>
32 
33 #include "slave/flags.hpp"
34 
35 namespace mesos {
36 namespace internal {
37 namespace slave {
38 
39 class SubsystemProcess;
40 
44 class Subsystem
45 {
46 public:
57  const Flags& flags,
58  const std::string& name,
59  const std::string& hierarchy);
60 
61  // We have unique ownership of the wrapped process and
62  // enforce that objects of this class cannot be copied.
63  //
64  // TODO(bbannier): Remove this once MESOS-5122 is resolved.
65  Subsystem(const Subsystem&) = delete;
66  Subsystem& operator=(const Subsystem&) = delete;
67 
68  ~Subsystem();
69 
75  std::string name() const;
76 
85  const ContainerID& containerId,
86  const std::string& cgroup);
87 
97  const ContainerID& containerId,
98  const std::string& cgroup,
99  const mesos::slave::ContainerConfig& containerConfig);
100 
110  const ContainerID& containerId,
111  const std::string& cgroup,
112  pid_t pid);
113 
123  const ContainerID& containerId,
124  const std::string& cgroup);
125 
136  const ContainerID& containerId,
137  const std::string& cgroup,
138  const Resources& resourceRequests,
139  const google::protobuf::Map<
140  std::string, Value::Scalar>& resourceLimits = {});
141 
152  const ContainerID& containerId,
153  const std::string& cgroup);
154 
164  const ContainerID& containerId,
165  const std::string& cgroup);
166 
180  const ContainerID& containerId,
181  const std::string& cgroup);
182 
183 private:
185 
187 };
188 
189 
190 class SubsystemProcess : public process::Process<SubsystemProcess>
191 {
192 public:
193  ~SubsystemProcess() override {}
194 
195  virtual std::string name() const = 0;
196 
198  const ContainerID& containerId,
199  const std::string& cgroup);
200 
202  const ContainerID& containerId,
203  const std::string& cgroup,
204  const mesos::slave::ContainerConfig& containerConfig);
205 
207  const ContainerID& containerId,
208  const std::string& cgroup,
209  pid_t pid);
210 
212  const ContainerID& containerId,
213  const std::string& cgroup);
214 
216  const ContainerID& containerId,
217  const std::string& cgroup,
218  const Resources& resourceRequests,
219  const google::protobuf::Map<
220  std::string, Value::Scalar>& resourceLimits = {});
221 
223  const ContainerID& containerId,
224  const std::string& cgroup);
225 
227  const ContainerID& containerId,
228  const std::string& cgroup);
229 
231  const ContainerID& containerId,
232  const std::string& cgroup);
233 
234 protected:
235  SubsystemProcess(const Flags& _flags, const std::string& _hierarchy);
236 
240  const Flags flags;
241 
245  const std::string hierarchy;
246 };
247 
248 } // namespace slave {
249 } // namespace internal {
250 } // namespace mesos {
251 
252 #endif // __CGROUPS_ISOLATOR_SUBSYSTEM_HPP__
static Try< process::Owned< Subsystem > > create(const Flags &flags, const std::string &name, const std::string &hierarchy)
Attempts to create a specific Subsystem object that will contain specific information associated with...
process::Future< Nothing > prepare(const ContainerID &containerId, const std::string &cgroup, const mesos::slave::ContainerConfig &containerConfig)
Prepare the cgroups subsystem for the associated container.
Definition: check.hpp:33
process::Future< mesos::slave::ContainerLimitation > watch(const ContainerID &containerId, const std::string &cgroup)
Watch the container and report if any resource constraint impacts it.
const Flags flags
Flags used to launch the agent.
Definition: subsystem.hpp:240
Definition: resources.hpp:83
process::Future< Nothing > isolate(const ContainerID &containerId, const std::string &cgroup, pid_t pid)
Isolate the associated container to cgroups subsystem.
Definition: flags.hpp:39
process::Future< Nothing > cleanup(const ContainerID &containerId, const std::string &cgroup)
Clean up the cgroups subsystem for the associated container.
std::string name() const
The cgroups subsystem name of this Subsystem object.
process::Future< Nothing > update(const ContainerID &containerId, const std::string &cgroup, const Resources &resourceRequests, const google::protobuf::Map< std::string, Value::Scalar > &resourceLimits={})
Update resources allocated to the associated container in this cgroups subsystem. ...
DWORD pid_t
Definition: windows.hpp:181
process::Future< Nothing > recover(const ContainerID &containerId, const std::string &cgroup)
Recover the cgroups subsystem for the associated container.
process::Future< ContainerStatus > status(const ContainerID &containerId, const std::string &cgroup)
Get the run-time status of cgroups subsystem specific properties associated with the container...
Definition: agent.hpp:25
Subsystem(const Subsystem &)=delete
Result< std::string > cgroup(pid_t pid)
Definition: subsystem.hpp:190
Subsystem & operator=(const Subsystem &)=delete
Definition: attributes.hpp:24
An abstraction for cgroups subsystem.
Definition: subsystem.hpp:44
Definition: executor.hpp:48
const std::string hierarchy
The hierarchy path of cgroups subsystem.
Definition: subsystem.hpp:245
process::Future< ResourceStatistics > usage(const ContainerID &containerId, const std::string &cgroup)
Gather resource usage statistics of the cgroups subsystem for the associated container.
Result< std::string > hierarchy(const std::string &subsystems)
Definition: owned.hpp:36
Definition: process.hpp:505
Definition: parse.hpp:33
~SubsystemProcess() override
Definition: subsystem.hpp:193