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