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 read the io switchboard socket file.
149  const std::string& runtimeDir,
150  const ContainerID& containerId);
151 #endif
152 
153 
154 // The helper method to get the destroy on recovery file path.
156  const std::string& runtimeDir,
157  const ContainerID& containerId);
158 
159 
160 // The helper method to check if we should
161 // destroy a container on recovery or not.
163  const std::string& runtimeDir,
164  const ContainerID& containerId);
165 
166 
167 // The helper method to read the container termination state.
169  const std::string& runtimeDir,
170  const ContainerID& containerId);
171 
172 
173 // The helper method to get the standalone container marker path.
175  const std::string& runtimeDir,
176  const ContainerID& containerId);
177 
178 
179 // The helper method to check if the given container is a standalone
180 // container or not. This is determined by the existence (or not) of
181 // a marker file in the container's runtime metadata directory.
183  const std::string& runtimeDir,
184  const ContainerID& containerId);
185 
186 
187 // The helper method to read the launch config of the contaienr.
189  const std::string& runtimeDir,
190  const ContainerID& containerId);
191 
192 
193 // The helper method to list all container IDs (including nested
194 // containers) from the container runtime directory. The order of
195 // returned vector is a result of pre-ordering walk (i.e., parent
196 // is inserted before its children).
198  const std::string& runtimeDir);
199 
200 
201 // The helper method to get the container launch information path.
202 std::string getContainerLaunchInfoPath(
203  const std::string& runtimeDir,
204  const ContainerID& containerId);
205 
206 
207 // The helper method to get the container launch information
208 // at the moment it was launched.
210  const std::string& runtimeDir,
211  const ContainerID& containerId);
212 
213 
214 // The helper method to get the sandbox path.
215 std::string getSandboxPath(
216  const std::string& rootSandboxPath,
217  const ContainerID& containerId);
218 
219 
220 // The helper method parses a given 'path' and returns the container
221 // ID of the container whose sandbox contains 'path'.
223  const ContainerID& rootContainerId,
224  const std::string& rootSandboxPath,
225  const std::string& path);
226 
227 } // namespace paths {
228 } // namespace containerizer {
229 } // namespace slave {
230 } // namespace internal {
231 } // namespace mesos {
232 
233 #endif // __MESOS_CONTAINERIZER_PATHS_HPP__
constexpr char FORCE_DESTROY_ON_RECOVERY_FILE[]
Definition: paths.hpp:73
Definition: try.hpp:34
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: result.hpp:40
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
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)
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
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)