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_LAUNCH_INFO_FILE[] = "launch_info";
77 constexpr char STANDALONE_MARKER_FILE[] = "standalone.marker";
78 
79 
80 enum Mode
81 {
85 };
86 
87 // Returns a path representation of a ContainerID that can be used for
88 // creating cgroups or writing to the filesystem. A ContainerID can
89 // represent a nested container (i.e, it has a parent ContainerID) and
90 // the path representation includes all of the parents as directories
91 // in the path. Depending on the 'mode', the result can be the
92 // following for a nested container 'xxx.yyy':
93 // 1) mode == PREFIX: '<separator>/xxx/<separator>/yyy'
94 // 2) mode == SUFFIX: 'xxx/<separator>/yyy/<separator>'
95 // 3) mode == JOIN: 'xxx/<separator>/yyy'
96 std::string buildPath(
97  const ContainerID& containerId,
98  const std::string& separator,
99  const Mode& mode);
100 
101 
102 // The following helper function constructs the path
103 // for a container given the 'runtimeDir' that was
104 // used as well as the container `containerId`.
105 std::string getRuntimePath(
106  const std::string& runtimeDir,
107  const ContainerID& containerId);
108 
109 
110 // The helper method to read the pid file.
112  const std::string& runtimeDir,
113  const ContainerID& containerId);
114 
115 
116 // The helper method to read the status file.
118  const std::string& runtimeDir,
119  const ContainerID& containerId);
120 
121 
122 #ifndef __WINDOWS__
123 // The helper method to get the io switchboard directory path.
125  const std::string& runtimeDir,
126  const ContainerID& containerId);
127 
128 
129 // The helper method to get the io switchboard pid file path.
131  const std::string& runtimeDir,
132  const ContainerID& containerId);
133 
134 
135 // The helper method to get the io switchboard pid.
137  const std::string& runtimeDir,
138  const ContainerID& containerId);
139 
140 
141 // The helper method to get the socket file path.
143  const std::string& runtimeDir,
144  const ContainerID& containerId);
145 
146 
147 // The helper method to get the io switchboard provisional socket path,
148 // see comment in IOSwitchboardServer::create().
150  const std::string& socketPath);
151 
152 
153 // The helper method to get the io switchboard provisional socket path,
154 // see comment in IOSwitchboardServer::create().
156  const std::string& runtimeDir,
157  const ContainerID& containerId);
158 
159 
160 // The helper method to read the io switchboard socket file.
162  const std::string& runtimeDir,
163  const ContainerID& containerId);
164 #endif
165 
166 
167 // The helper method to get the destroy on recovery file path.
169  const std::string& runtimeDir,
170  const ContainerID& containerId);
171 
172 
173 // The helper method to check if we should
174 // destroy a container on recovery or not.
176  const std::string& runtimeDir,
177  const ContainerID& containerId);
178 
179 
180 // The helper method to read the container termination state.
182  const std::string& runtimeDir,
183  const ContainerID& containerId);
184 
185 
186 // The helper method to get the standalone container marker path.
188  const std::string& runtimeDir,
189  const ContainerID& containerId);
190 
191 
192 // The helper method to check if the given container is a standalone
193 // container or not. This is determined by the existence (or not) of
194 // a marker file in the container's runtime metadata directory.
196  const std::string& runtimeDir,
197  const ContainerID& containerId);
198 
199 
200 // The helper method to read the launch config of the contaienr.
202  const std::string& runtimeDir,
203  const ContainerID& containerId);
204 
205 
206 // The helper method to list all container IDs (including nested
207 // containers) from the container runtime directory. The order of
208 // returned vector is a result of pre-ordering walk (i.e., parent
209 // is inserted before its children).
211  const std::string& runtimeDir);
212 
213 
214 // The helper method to get the container launch information path.
215 std::string getContainerLaunchInfoPath(
216  const std::string& runtimeDir,
217  const ContainerID& containerId);
218 
219 
220 // The helper method to get the container launch information
221 // at the moment it was launched.
223  const std::string& runtimeDir,
224  const ContainerID& containerId);
225 
226 
227 // The helper method to get the sandbox path.
228 std::string getSandboxPath(
229  const std::string& rootSandboxPath,
230  const ContainerID& containerId);
231 
232 
233 // The helper method parses a given 'path' and returns the container
234 // ID of the container whose sandbox contains 'path'.
236  const ContainerID& rootContainerId,
237  const std::string& rootSandboxPath,
238  const std::string& path);
239 
240 } // namespace paths {
241 } // namespace containerizer {
242 } // namespace slave {
243 } // namespace internal {
244 } // namespace mesos {
245 
246 #endif // __MESOS_CONTAINERIZER_PATHS_HPP__
constexpr char FORCE_DESTROY_ON_RECOVERY_FILE[]
Definition: paths.hpp:73
Definition: path.hpp:26
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:76
Try< mode_t > mode(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:126
std::string getContainerIOSwitchboardSocketProvisionalPath(const std::string &socketPath)
constexpr char STANDALONE_MARKER_FILE[]
Definition: paths.hpp:77
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)