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 // |-- pid
64 // |-- standalone.marker
65 // |-- status
66 // |-- termination
67 
68 
69 constexpr char PID_FILE[] = "pid";
70 constexpr char CONTAINER_CONFIG_FILE[] = "config";
71 constexpr char STATUS_FILE[] = "status";
72 constexpr char TERMINATION_FILE[] = "termination";
73 constexpr char SOCKET_FILE[] = "socket";
74 constexpr char FORCE_DESTROY_ON_RECOVERY_FILE[] = "force_destroy_on_recovery";
75 constexpr char IO_SWITCHBOARD_DIRECTORY[] = "io_switchboard";
76 constexpr char CONTAINER_DIRECTORY[] = "containers";
77 constexpr char CONTAINER_DEVICES_DIRECTORY[] = "devices";
78 constexpr char CONTAINER_LAUNCH_INFO_FILE[] = "launch_info";
79 constexpr char STANDALONE_MARKER_FILE[] = "standalone.marker";
80 
81 
82 enum Mode
83 {
87 };
88 
89 // Returns a path representation of a ContainerID that can be used for
90 // creating cgroups or writing to the filesystem. A ContainerID can
91 // represent a nested container (i.e, it has a parent ContainerID) and
92 // the path representation includes all of the parents as directories
93 // in the path. Depending on the 'mode', the result can be the
94 // following for a nested container 'xxx.yyy':
95 // 1) mode == PREFIX: '<separator>/xxx/<separator>/yyy'
96 // 2) mode == SUFFIX: 'xxx/<separator>/yyy/<separator>'
97 // 3) mode == JOIN: 'xxx/<separator>/yyy'
98 std::string buildPath(
99  const ContainerID& containerId,
100  const std::string& separator,
101  const Mode& mode);
102 
103 
104 // The following helper function constructs the path
105 // for a container given the 'runtimeDir' that was
106 // used as well as the container `containerId`.
107 std::string getRuntimePath(
108  const std::string& runtimeDir,
109  const ContainerID& containerId);
110 
111 
112 // Given a `runtimeDir`, construct a unique directory to stage
113 // per-container device nodes. This directory is initially created
114 // and populated by the `filesystem/linux` isolator. Any subsequent
115 // isolators may add devices to this directory and bind mount them
116 // into the container.
117 std::string getContainerDevicesPath(
118  const std::string& runtimeDir,
119  const ContainerID& containerId);
120 
121 
122 // The helper method to read the pid file.
124  const std::string& runtimeDir,
125  const ContainerID& containerId);
126 
127 
128 // The helper method to read the status file.
130  const std::string& runtimeDir,
131  const ContainerID& containerId);
132 
133 
134 #ifndef __WINDOWS__
135 // The helper method to get the io switchboard directory path.
137  const std::string& runtimeDir,
138  const ContainerID& containerId);
139 
140 
141 // The helper method to get the io switchboard pid file path.
143  const std::string& runtimeDir,
144  const ContainerID& containerId);
145 
146 
147 // The helper method to get the io switchboard pid.
149  const std::string& runtimeDir,
150  const ContainerID& containerId);
151 
152 
153 // The helper method to get the socket file path.
155  const std::string& runtimeDir,
156  const ContainerID& containerId);
157 
158 
159 // The helper method to get the io switchboard provisional socket path,
160 // see comment in IOSwitchboardServer::create().
162  const std::string& socketPath);
163 
164 
165 // The helper method to get the io switchboard provisional socket path,
166 // see comment in IOSwitchboardServer::create().
168  const std::string& runtimeDir,
169  const ContainerID& containerId);
170 
171 
172 // The helper method to read the io switchboard socket file.
174  const std::string& runtimeDir,
175  const ContainerID& containerId);
176 #endif
177 
178 
179 // The helper method to get the destroy on recovery file path.
181  const std::string& runtimeDir,
182  const ContainerID& containerId);
183 
184 
185 // The helper method to check if we should
186 // destroy a container on recovery or not.
188  const std::string& runtimeDir,
189  const ContainerID& containerId);
190 
191 
192 // The helper method to read the container termination state.
194  const std::string& runtimeDir,
195  const ContainerID& containerId);
196 
197 
198 // The helper method to get the standalone container marker path.
200  const std::string& runtimeDir,
201  const ContainerID& containerId);
202 
203 
204 // The helper method to check if the given container is a standalone
205 // container or not. This is determined by the existence (or not) of
206 // a marker file in the container's runtime metadata directory.
208  const std::string& runtimeDir,
209  const ContainerID& containerId);
210 
211 
212 // The helper method to read the launch config of the contaienr.
214  const std::string& runtimeDir,
215  const ContainerID& containerId);
216 
217 
218 // The helper method to list all container IDs (including nested
219 // containers) from the container runtime directory. The order of
220 // returned vector is a result of pre-ordering walk (i.e., parent
221 // is inserted before its children).
223  const std::string& runtimeDir);
224 
225 
226 // The helper method to get the container launch information path.
227 std::string getContainerLaunchInfoPath(
228  const std::string& runtimeDir,
229  const ContainerID& containerId);
230 
231 
232 // The helper method to get the container launch information
233 // at the moment it was launched.
235  const std::string& runtimeDir,
236  const ContainerID& containerId);
237 
238 
239 // The helper method to get the sandbox path.
240 std::string getSandboxPath(
241  const std::string& rootSandboxPath,
242  const ContainerID& containerId);
243 
244 
245 // The helper method parses a given 'path' and returns the container
246 // ID of the container whose sandbox contains 'path'.
248  const ContainerID& rootContainerId,
249  const std::string& rootSandboxPath,
250  const std::string& path);
251 
252 } // namespace paths {
253 } // namespace containerizer {
254 } // namespace slave {
255 } // namespace internal {
256 } // namespace mesos {
257 
258 #endif // __MESOS_CONTAINERIZER_PATHS_HPP__
constexpr char FORCE_DESTROY_ON_RECOVERY_FILE[]
Definition: paths.hpp:74
Definition: path.hpp:26
std::string getContainerDevicesPath(const std::string &runtimeDir, const ContainerID &containerId)
Definition: check.hpp:33
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 SOCKET_FILE[]
Definition: paths.hpp:73
std::string getContainerIOSwitchboardPath(const std::string &runtimeDir, const ContainerID &containerId)
constexpr char IO_SWITCHBOARD_DIRECTORY[]
Definition: paths.hpp:75
std::string getContainerIOSwitchboardPidPath(const std::string &runtimeDir, const ContainerID &containerId)
std::string paths()
Definition: os.hpp:137
constexpr char TERMINATION_FILE[]
Definition: paths.hpp:72
constexpr char CONTAINER_DIRECTORY[]
Definition: paths.hpp:76
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)
Try< ContainerID > parseSandboxPath(const ContainerID &rootContainerId, const std::string &rootSandboxPath, const std::string &path)
constexpr char CONTAINER_CONFIG_FILE[]
Definition: paths.hpp:70
std::string getRuntimePath(const std::string &runtimeDir, const ContainerID &containerId)
constexpr char STATUS_FILE[]
Definition: paths.hpp:71
Definition: spec.hpp:26
std::string getSandboxPath(const std::string &rootSandboxPath, const ContainerID &containerId)
constexpr char PID_FILE[]
Definition: paths.hpp:69
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::vector< ContainerID > > getContainerIds(const std::string &runtimeDir)
Definition: attributes.hpp:24
Result< mesos::slave::ContainerLaunchInfo > getContainerLaunchInfo(const std::string &runtimeDir, const ContainerID &containerId)
constexpr char CONTAINER_LAUNCH_INFO_FILE[]
Definition: paths.hpp:78
constexpr char CONTAINER_DEVICES_DIRECTORY[]
Definition: paths.hpp:77
Try< mode_t > mode(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:159
std::string getContainerIOSwitchboardSocketProvisionalPath(const std::string &socketPath)
constexpr char STANDALONE_MARKER_FILE[]
Definition: paths.hpp:79
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)