Apache Mesos
paths.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_CONTAINERIZER_PATHS_HPP__
18 #define __MESOS_CONTAINERIZER_PATHS_HPP__
19 
20 #include <sys/types.h>
21 
22 #include <string>
23 #include <vector>
24 
25 #include <process/address.hpp>
26 
27 #include <stout/result.hpp>
28 #include <stout/try.hpp>
29 
30 #include <mesos/mesos.hpp>
31 
33 
34 namespace mesos {
35 namespace internal {
36 namespace slave {
37 namespace containerizer {
38 namespace paths {
39 
40 
41 // The containerizer uses the runtime directory to checkpoint things
42 // for each container, like the PID of the first process executed
43 // within a container (i.e., the "PID 1") or the LaunchInfo associated
44 // with the given container.
45 //
46 // The file system layout is as follows:
47 //
48 // root ('--runtime_dir' flag)
49 // |-- containers
50 // |-- <container_id>
51 // |-- config
52 // |-- containers
53 // | |-- <container_id>
54 // | | |-- <more nesting of containers>
55 // | |-- pid
56 // | |-- ...
57 // |-- devices
58 // |-- force_destroy_on_recovery
59 // |-- io_switchboard
60 // | |-- pid
61 // | |-- socket
62 // |-- launch_info
63 // |-- mnt
64 // | |-- host_proc
65 // |-- pid
66 // |-- shm
67 // |-- standalone.marker
68 // |-- status
69 // |-- termination
70 
71 
72 constexpr char PID_FILE[] = "pid";
73 constexpr char CONTAINER_CONFIG_FILE[] = "config";
74 constexpr char STATUS_FILE[] = "status";
75 constexpr char TERMINATION_FILE[] = "termination";
76 constexpr char SOCKET_FILE[] = "socket";
77 constexpr char FORCE_DESTROY_ON_RECOVERY_FILE[] = "force_destroy_on_recovery";
78 constexpr char IO_SWITCHBOARD_DIRECTORY[] = "io_switchboard";
79 constexpr char MNT_DIRECTORY[] = "mnt";
80 constexpr char MNT_HOST_PROC[] = "host_proc";
81 constexpr char CONTAINER_DIRECTORY[] = "containers";
82 constexpr char CONTAINER_DEVICES_DIRECTORY[] = "devices";
83 constexpr char CONTAINER_LAUNCH_INFO_FILE[] = "launch_info";
84 constexpr char STANDALONE_MARKER_FILE[] = "standalone.marker";
85 constexpr char CONTAINER_SHM_DIRECTORY[] = "shm";
86 constexpr char AGENT_SHM_DIRECTORY[] = "/dev/shm";
87 constexpr char SECRET_DIRECTORY[] = ".secret";
88 
89 
90 enum Mode
91 {
95 };
96 
97 // Returns a path representation of a ContainerID that can be used for
98 // creating cgroups or writing to the filesystem. A ContainerID can
99 // represent a nested container (i.e, it has a parent ContainerID) and
100 // the path representation includes all of the parents as directories
101 // in the path. Depending on the 'mode', the result can be the
102 // following for a nested container 'xxx.yyy':
103 // 1) mode == PREFIX: '<separator>/xxx/<separator>/yyy'
104 // 2) mode == SUFFIX: 'xxx/<separator>/yyy/<separator>'
105 // 3) mode == JOIN: 'xxx/<separator>/yyy'
106 std::string buildPath(
107  const ContainerID& containerId,
108  const std::string& separator,
109  const Mode& mode);
110 
111 
112 // The following helper function constructs the path
113 // for a container given the 'runtimeDir' that was
114 // used as well as the container `containerId`.
115 std::string getRuntimePath(
116  const std::string& runtimeDir,
117  const ContainerID& containerId);
118 
119 
120 // Given a `runtimeDir`, construct a unique directory to stage
121 // per-container device nodes. This directory is initially created
122 // and populated by the `filesystem/linux` isolator. Any subsequent
123 // isolators may add devices to this directory and bind mount them
124 // into the container.
125 std::string getContainerDevicesPath(
126  const std::string& runtimeDir,
127  const ContainerID& containerId);
128 
129 
130 // The helper method to read the pid file.
132  const std::string& runtimeDir,
133  const ContainerID& containerId);
134 
135 
136 // The helper method to read the status file.
138  const std::string& runtimeDir,
139  const ContainerID& containerId);
140 
141 
142 #ifndef __WINDOWS__
143 // The helper method to get the io switchboard directory path.
145  const std::string& runtimeDir,
146  const ContainerID& containerId);
147 
148 
149 // The helper method to get the io switchboard pid file path.
151  const std::string& runtimeDir,
152  const ContainerID& containerId);
153 
154 
155 // The helper method to get the io switchboard pid.
157  const std::string& runtimeDir,
158  const ContainerID& containerId);
159 
160 
161 // The helper method to get the socket file path.
163  const std::string& runtimeDir,
164  const ContainerID& containerId);
165 
166 
167 // The helper method to get the io switchboard provisional socket path,
168 // see comment in IOSwitchboardServer::create().
170  const std::string& socketPath);
171 
172 
173 // The helper method to get the io switchboard provisional socket path,
174 // see comment in IOSwitchboardServer::create().
176  const std::string& runtimeDir,
177  const ContainerID& containerId);
178 
179 
180 // The helper method to read the io switchboard socket file.
182  const std::string& runtimeDir,
183  const ContainerID& containerId);
184 
185 // The helper method to get the host proc mount point path.
186 std::string getHostProcMountPointPath(
187  const std::string& runtimeDir,
188  const ContainerID& containerId);
189 #endif
190 
191 
192 // The helper method to get the destroy on recovery file path.
194  const std::string& runtimeDir,
195  const ContainerID& containerId);
196 
197 
198 // The helper method to check if we should
199 // destroy a container on recovery or not.
201  const std::string& runtimeDir,
202  const ContainerID& containerId);
203 
204 
205 // The helper method to read the container termination state.
207  const std::string& runtimeDir,
208  const ContainerID& containerId);
209 
210 
211 // The helper method to get the standalone container marker path.
213  const std::string& runtimeDir,
214  const ContainerID& containerId);
215 
216 
217 // The helper method to check if the given container is a standalone
218 // container or not. This is determined by the existence (or not) of
219 // a marker file in the container's runtime metadata directory.
221  const std::string& runtimeDir,
222  const ContainerID& containerId);
223 
224 
225 // The helper method to read the launch config of the contaienr.
227  const std::string& runtimeDir,
228  const ContainerID& containerId);
229 
230 
231 // The helper method to list all container IDs (including nested
232 // containers) from the container runtime directory. The order of
233 // returned vector is a result of pre-ordering walk (i.e., parent
234 // is inserted before its children).
236  const std::string& runtimeDir);
237 
238 
239 // The helper method to get the container launch information path.
240 std::string getContainerLaunchInfoPath(
241  const std::string& runtimeDir,
242  const ContainerID& containerId);
243 
244 
245 // The helper method to get the container launch information
246 // at the moment it was launched.
248  const std::string& runtimeDir,
249  const ContainerID& containerId);
250 
251 
252 // The helper method to get the sandbox path.
253 std::string getSandboxPath(
254  const std::string& rootSandboxPath,
255  const ContainerID& containerId);
256 
257 
258 // The helper method parses a given 'path' and returns the container
259 // ID of the container whose sandbox contains 'path'.
261  const ContainerID& rootContainerId,
262  const std::string& rootSandboxPath,
263  const std::string& path);
264 
265 
266 std::string getContainerShmPath(
267  const std::string& runtimeDir,
268  const ContainerID& containerId);
269 
270 
272  const std::string runtimeDir,
273  const ContainerID& containerId);
274 
275 
276 // Helper for determining the cgroup for a container (i.e., the path
277 // in a cgroup subsystem).
278 std::string getCgroupPath(
279  const std::string& cgroupsRoot,
280  const ContainerID& containerId);
281 
282 
283 // Helper for parsing the cgroup path to determine the container ID
284 // it belongs to.
286  const std::string& cgroupsRoot,
287  const std::string& cgroup);
288 
289 } // namespace paths {
290 } // namespace containerizer {
291 } // namespace slave {
292 } // namespace internal {
293 } // namespace mesos {
294 
295 #endif // __MESOS_CONTAINERIZER_PATHS_HPP__
constexpr char FORCE_DESTROY_ON_RECOVERY_FILE[]
Definition: paths.hpp:77
Definition: path.hpp:29
std::string getContainerDevicesPath(const std::string &runtimeDir, const ContainerID &containerId)
Definition: check.hpp:33
Option< ContainerID > parseCgroupPath(const std::string &cgroupsRoot, const std::string &cgroup)
Result< mesos::slave::ContainerTermination > getContainerTermination(const std::string &runtimeDir, const ContainerID &containerId)
Result< mesos::slave::ContainerConfig > getContainerConfig(const std::string &runtimeDir, const ContainerID &containerId)
std::string buildPath(const ContainerID &containerId, const std::string &separator, const Mode &mode)
constexpr char MNT_DIRECTORY[]
Definition: paths.hpp:79
constexpr char MNT_HOST_PROC[]
Definition: paths.hpp:80
constexpr char SOCKET_FILE[]
Definition: paths.hpp:76
std::string getContainerIOSwitchboardPath(const std::string &runtimeDir, const ContainerID &containerId)
constexpr char IO_SWITCHBOARD_DIRECTORY[]
Definition: paths.hpp:78
std::string getContainerIOSwitchboardPidPath(const std::string &runtimeDir, const ContainerID &containerId)
std::string paths()
Definition: os.hpp:138
constexpr char CONTAINER_SHM_DIRECTORY[]
Definition: paths.hpp:85
constexpr char TERMINATION_FILE[]
Definition: paths.hpp:75
std::string getContainerShmPath(const std::string &runtimeDir, const ContainerID &containerId)
constexpr char CONTAINER_DIRECTORY[]
Definition: paths.hpp:81
Definition: check.hpp:30
std::string getContainerForceDestroyOnRecoveryPath(const std::string &runtimeDir, const ContainerID &containerId)
std::string getContainerIOSwitchboardSocketPath(const std::string &runtimeDir, const ContainerID &containerId)
Result< pid_t > getContainerPid(const std::string &runtimeDir, const ContainerID &containerId)
std::string getCgroupPath(const std::string &cgroupsRoot, const ContainerID &containerId)
Try< ContainerID > parseSandboxPath(const ContainerID &rootContainerId, const std::string &rootSandboxPath, const std::string &path)
constexpr char CONTAINER_CONFIG_FILE[]
Definition: paths.hpp:73
std::string getRuntimePath(const std::string &runtimeDir, const ContainerID &containerId)
constexpr char STATUS_FILE[]
Definition: paths.hpp:74
Definition: agent.hpp:25
std::string getSandboxPath(const std::string &rootSandboxPath, const ContainerID &containerId)
constexpr char PID_FILE[]
Definition: paths.hpp:72
Result< std::string > cgroup(pid_t pid)
std::string getContainerLaunchInfoPath(const std::string &runtimeDir, const ContainerID &containerId)
std::string getStandaloneContainerMarkerPath(const std::string &runtimeDir, const ContainerID &containerId)
bool isStandaloneContainer(const std::string &runtimeDir, const ContainerID &containerId)
Try< std::string > getParentShmPath(const std::string runtimeDir, const ContainerID &containerId)
Try< std::vector< ContainerID > > getContainerIds(const std::string &runtimeDir)
constexpr char SECRET_DIRECTORY[]
Definition: paths.hpp:87
Definition: attributes.hpp:24
Result< mesos::slave::ContainerLaunchInfo > getContainerLaunchInfo(const std::string &runtimeDir, const ContainerID &containerId)
constexpr char AGENT_SHM_DIRECTORY[]
Definition: paths.hpp:86
constexpr char CONTAINER_LAUNCH_INFO_FILE[]
Definition: paths.hpp:83
constexpr char CONTAINER_DEVICES_DIRECTORY[]
Definition: paths.hpp:82
Try< mode_t > mode(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:168
std::string getHostProcMountPointPath(const std::string &runtimeDir, const ContainerID &containerId)
std::string getContainerIOSwitchboardSocketProvisionalPath(const std::string &socketPath)
constexpr char STANDALONE_MARKER_FILE[]
Definition: paths.hpp:84
Result< int > getContainerStatus(const std::string &runtimeDir, const ContainerID &containerId)
bool getContainerForceDestroyOnRecovery(const std::string &runtimeDir, const ContainerID &containerId)
Result< pid_t > getContainerIOSwitchboardPid(const std::string &runtimeDir, const ContainerID &containerId)
Result< process::network::unix::Address > getContainerIOSwitchboardAddress(const std::string &runtimeDir, const ContainerID &containerId)