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 __SLAVE_PATHS_HPP__
18 #define __SLAVE_PATHS_HPP__
19 
20 #include <list>
21 #include <string>
22 
23 #include <mesos/mesos.hpp>
24 
25 #include <stout/try.hpp>
26 #include <stout/uuid.hpp>
27 
28 namespace mesos {
29 namespace internal {
30 namespace slave {
31 namespace paths {
32 
33 
34 // The slave leverages the file system for a number of purposes:
35 //
36 // (1) For executor sandboxes and disk volumes.
37 //
38 // (2) For checkpointing metadata in order to support "slave
39 // recovery". That is, allow the slave to restart without
40 // affecting the tasks / executors.
41 //
42 // (3) To detect reboots (by checkpointing the boot id), in which
43 // case everything has died so no recovery should be attempted.
44 //
45 // (4) For checkpointing resources that persist across slaves.
46 // This includes things like persistent volumes and dynamic
47 // reservations.
48 //
49 // (5) For provisioning root filesystems for containers.
50 //
51 // (6) For CSI plugins to preserve data that persist across slaves.
52 //
53 // The file system layout is as follows:
54 //
55 // root ('--work_dir' flag)
56 // |-- containers
57 // | |-- <container_id> (sandbox)
58 // |-- slaves
59 // | |-- latest (symlink)
60 // | |-- <slave_id>
61 // | |-- frameworks
62 // | |-- <framework_id>
63 // | |-- executors
64 // | |-- <executor_id>
65 // | |-- runs
66 // | |-- latest (symlink)
67 // | |-- <container_id> (sandbox)
68 // |-- meta
69 // | |-- boot_id
70 // | |-- resources
71 // | | |-- resources.info
72 // | | |-- resources.target
73 // | |-- slaves
74 // | |-- latest (symlink)
75 // | |-- <slave_id>
76 // | |-- slave.info
77 // | |-- resource_providers
78 // | | |-- <type>
79 // | | |-- <name>
80 // | | |-- latest (symlink)
81 // | | |-- <resource_provider_id>
82 // | | |-- resource_provider.state
83 // | | |-- operations
84 // | | |-- <operation_uuid>
85 // | | |-- operation.updates
86 // | |-- frameworks
87 // | |-- <framework_id>
88 // | |-- framework.info
89 // | |-- framework.pid
90 // | |-- executors
91 // | |-- <executor_id>
92 // | |-- executor.info
93 // | |-- runs
94 // | |-- latest (symlink)
95 // | |-- <container_id> (sandbox)
96 // | |-- executor.sentinel (if completed)
97 // | |-- pids
98 // | | |-- forked.pid
99 // | | |-- libprocess.pid
100 // | |-- tasks
101 // | |-- <task_id>
102 // | |-- task.info
103 // | |-- task.updates
104 // |-- volumes
105 // | |-- roles
106 // | |-- <role>
107 // | |-- <persistence_id> (persistent volume)
108 // |-- provisioner
109 // |-- csi
110 
111 
113 {
114  SlaveID slaveId;
115  FrameworkID frameworkId;
116  ExecutorID executorId;
117  ContainerID containerId;
118 };
119 
120 
122  const std::string& rootDir,
123  const std::string& dir);
124 
125 
126 const char LATEST_SYMLINK[] = "latest";
127 
128 // Helpers for obtaining paths in the layout.
129 // NOTE: The parameter names should adhere to the following convention:
130 //
131 // (1) Use `workDir` if the helper expects the `--work_dir` flag.
132 //
133 // (2) Use `metaDir` if the helper expects the meta directory.
134 //
135 // (3) Use `rootDir` only if the helper is to be reused.
136 //
137 // TODO(chhsiao): Clean up the parameter names to follow the convention.
138 
139 std::string getMetaRootDir(const std::string& rootDir);
140 
141 
142 std::string getSandboxRootDir(const std::string& rootDir);
143 
144 
145 std::string getProvisionerDir(const std::string& rootDir);
146 
147 
148 std::string getCsiRootDir(const std::string& workDir);
149 
150 
151 std::string getLatestSlavePath(const std::string& rootDir);
152 
153 
154 std::string getBootIdPath(const std::string& rootDir);
155 
156 
157 std::string getSlaveInfoPath(
158  const std::string& rootDir,
159  const SlaveID& slaveId);
160 
161 
162 std::string getSlavePath(
163  const std::string& rootDir,
164  const SlaveID& slaveId);
165 
166 
168  const std::string& rootDir);
169 
170 
171 std::string getContainerPath(
172  const std::string& rootDir,
173  const ContainerID& containerId);
174 
175 
177  const std::string& rootDir,
178  const SlaveID& slaveId);
179 
180 
181 std::string getFrameworkPath(
182  const std::string& rootDir,
183  const SlaveID& slaveId,
184  const FrameworkID& frameworkId);
185 
186 
187 std::string getFrameworkPidPath(
188  const std::string& rootDir,
189  const SlaveID& slaveId,
190  const FrameworkID& frameworkId);
191 
192 
193 std::string getFrameworkInfoPath(
194  const std::string& rootDir,
195  const SlaveID& slaveId,
196  const FrameworkID& frameworkId);
197 
198 
200  const std::string& rootDir,
201  const SlaveID& slaveId,
202  const FrameworkID& frameworkId);
203 
204 
205 std::string getExecutorPath(
206  const std::string& rootDir,
207  const SlaveID& slaveId,
208  const FrameworkID& frameworkId,
209  const ExecutorID& executorId);
210 
211 
212 std::string getExecutorInfoPath(
213  const std::string& rootDir,
214  const SlaveID& slaveId,
215  const FrameworkID& frameworkId,
216  const ExecutorID& executorId);
217 
218 
220  const std::string& rootDir,
221  const SlaveID& slaveId,
222  const FrameworkID& frameworkId,
223  const ExecutorID& executorId);
224 
225 
226 std::string getExecutorRunPath(
227  const std::string& rootDir,
228  const SlaveID& slaveId,
229  const FrameworkID& frameworkId,
230  const ExecutorID& executorId,
231  const ContainerID& containerId);
232 
233 
234 std::string getExecutorHttpMarkerPath(
235  const std::string& rootDir,
236  const SlaveID& slaveId,
237  const FrameworkID& frameworkId,
238  const ExecutorID& executorId,
239  const ContainerID& containerId);
240 
241 
242 std::string getExecutorSentinelPath(
243  const std::string& rootDir,
244  const SlaveID& slaveId,
245  const FrameworkID& frameworkId,
246  const ExecutorID& executorId,
247  const ContainerID& containerId);
248 
249 
250 // Returns the "virtual" path used to expose the executor's sandbox
251 // via the /files endpoints: `/frameworks/FID/executors/EID/latest`.
252 std::string getExecutorVirtualPath(
253  const FrameworkID& frameworkId,
254  const ExecutorID& executorId);
255 
256 
257 std::string getExecutorLatestRunPath(
258  const std::string& rootDir,
259  const SlaveID& slaveId,
260  const FrameworkID& frameworkId,
261  const ExecutorID& executorId);
262 
263 
264 std::string getLibprocessPidPath(
265  const std::string& rootDir,
266  const SlaveID& slaveId,
267  const FrameworkID& frameworkId,
268  const ExecutorID& executorId,
269  const ContainerID& containerId);
270 
271 
272 std::string getForkedPidPath(
273  const std::string& rootDir,
274  const SlaveID& slaveId,
275  const FrameworkID& frameworkId,
276  const ExecutorID& executorId,
277  const ContainerID& containerId);
278 
279 
280 std::string getContainerRootfsPath(
281  const std::string& rootDir,
282  const SlaveID& slaveId,
283  const FrameworkID& frameworkId,
284  const ExecutorID& executorId,
285  const ContainerID& containerId);
286 
287 
289  const std::string& rootDir,
290  const SlaveID& slaveId,
291  const FrameworkID& frameworkId,
292  const ExecutorID& executorId,
293  const ContainerID& containerId);
294 
295 
296 std::string getTaskPath(
297  const std::string& rootDir,
298  const SlaveID& slaveId,
299  const FrameworkID& frameworkId,
300  const ExecutorID& executorId,
301  const ContainerID& containerId,
302  const TaskID& taskId);
303 
304 
305 std::string getTaskInfoPath(
306  const std::string& rootDir,
307  const SlaveID& slaveId,
308  const FrameworkID& frameworkId,
309  const ExecutorID& executorId,
310  const ContainerID& containerId,
311  const TaskID& taskId);
312 
313 
314 std::string getTaskUpdatesPath(
315  const std::string& rootDir,
316  const SlaveID& slaveId,
317  const FrameworkID& frameworkId,
318  const ExecutorID& executorId,
319  const ContainerID& containerId,
320  const TaskID& taskId);
321 
322 
324  const std::string& rootDir,
325  const SlaveID& slaveId);
326 
327 
329  const std::string& metaDir,
330  const SlaveID& slaveId);
331 
332 
333 std::string getResourceProviderPath(
334  const std::string& metaDir,
335  const SlaveID& slaveId,
336  const std::string& resourceProviderType,
337  const std::string& resourceProviderName,
338  const ResourceProviderID& resourceProviderId);
339 
340 
341 std::string getResourceProviderStatePath(
342  const std::string& metaDir,
343  const SlaveID& slaveId,
344  const std::string& resourceProviderType,
345  const std::string& resourceProviderName,
346  const ResourceProviderID& resourceProviderId);
347 
348 
350  const std::string& metaDir,
351  const SlaveID& slaveId,
352  const std::string& resourceProviderType,
353  const std::string& resourceProviderName);
354 
355 
357  const std::string& rootDir);
358 
359 
360 std::string getOperationPath(
361  const std::string& rootDir,
362  const id::UUID& operationUuid);
363 
364 
366  const std::string& rootDir,
367  const std::string& dir);
368 
369 
370 std::string getOperationUpdatesPath(
371  const std::string& rootDir,
372  const id::UUID& operationUuid);
373 
374 
375 std::string getResourcesInfoPath(
376  const std::string& rootDir);
377 
378 
379 std::string getResourcesTargetPath(
380  const std::string& rootDir);
381 
382 
383 std::string getPersistentVolumePath(
384  const std::string& workDir,
385  const std::string& role,
386  const std::string& persistenceId);
387 
388 
389 std::string getPersistentVolumePath(
390  const std::string& workDir,
391  const Resource& resource);
392 
393 
394 std::string createExecutorDirectory(
395  const std::string& rootDir,
396  const SlaveID& slaveId,
397  const FrameworkID& frameworkId,
398  const ExecutorID& executorId,
399  const ContainerID& containerId,
400  const Option<std::string>& user = None());
401 
402 
404  const std::string& directory,
405  const Option<std::string>& user);
406 
407 
408 std::string createSlaveDirectory(
409  const std::string& rootDir,
410  const SlaveID& slaveId);
411 
412 
414  const std::string& rootDir,
415  const SlaveID& slaveId,
416  const std::string& resourceProviderType,
417  const std::string& resourceProviderName,
418  const ResourceProviderID& resourceProviderId);
419 
420 
421 extern const char LIBPROCESS_PID_FILE[];
422 extern const char HTTP_MARKER_FILE[];
423 
424 } // namespace paths {
425 } // namespace slave {
426 } // namespace internal {
427 } // namespace mesos {
428 
429 #endif // __SLAVE_PATHS_HPP__
std::string getExecutorRunPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
Definition: try.hpp:34
ExecutorID executorId
Definition: paths.hpp:116
const char LATEST_SYMLINK[]
Definition: paths.hpp:126
Try< std::list< std::string > > getExecutorPaths(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId)
Try< id::UUID > parseOperationPath(const std::string &rootDir, const std::string &dir)
std::string getExecutorPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId)
std::string getSandboxRootDir(const std::string &rootDir)
Try< std::list< std::string > > getFrameworkPaths(const std::string &rootDir, const SlaveID &slaveId)
std::string getContainerPath(const std::string &rootDir, const ContainerID &containerId)
Result< std::string > user(Option< uid_t > uid=None())
Definition: su.hpp:277
std::string paths()
Definition: os.hpp:136
std::string getFrameworkPidPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId)
std::string getOperationUpdatesPath(const std::string &rootDir, const id::UUID &operationUuid)
std::string getResourcesTargetPath(const std::string &rootDir)
std::string getSlaveInfoPath(const std::string &rootDir, const SlaveID &slaveId)
std::string createSlaveDirectory(const std::string &rootDir, const SlaveID &slaveId)
ContainerID containerId
Definition: paths.hpp:117
Try< std::list< std::string > > getExecutorRunPaths(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId)
std::string createResourceProviderDirectory(const std::string &rootDir, const SlaveID &slaveId, const std::string &resourceProviderType, const std::string &resourceProviderName, const ResourceProviderID &resourceProviderId)
std::string getResourceProviderPath(const std::string &metaDir, const SlaveID &slaveId, const std::string &resourceProviderType, const std::string &resourceProviderName, const ResourceProviderID &resourceProviderId)
std::string getCsiRootDir(const std::string &workDir)
std::string getResourceProviderStatePath(const std::string &metaDir, const SlaveID &slaveId, const std::string &resourceProviderType, const std::string &resourceProviderName, const ResourceProviderID &resourceProviderId)
std::string getSlavePath(const std::string &rootDir, const SlaveID &slaveId)
std::string getBootIdPath(const std::string &rootDir)
std::string createExecutorDirectory(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId, const Option< std::string > &user=None())
std::string getProvisionerDir(const std::string &rootDir)
Definition: uuid.hpp:35
std::string getResourceProviderRegistryPath(const std::string &rootDir, const SlaveID &slaveId)
std::string getExecutorLatestRunPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId)
std::string getMetaRootDir(const std::string &rootDir)
std::string getTaskPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId, const TaskID &taskId)
std::string getLatestResourceProviderPath(const std::string &metaDir, const SlaveID &slaveId, const std::string &resourceProviderType, const std::string &resourceProviderName)
std::string getOperationPath(const std::string &rootDir, const id::UUID &operationUuid)
Try< std::list< std::string > > getOperationPaths(const std::string &rootDir)
Definition: none.hpp:27
std::string getExecutorHttpMarkerPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
std::string getFrameworkInfoPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId)
std::string getFrameworkPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId)
std::string getResourcesInfoPath(const std::string &rootDir)
SlaveID slaveId
Definition: paths.hpp:114
Try< ExecutorRunPath > parseExecutorRunPath(const std::string &rootDir, const std::string &dir)
std::string getLibprocessPidPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
FrameworkID frameworkId
Definition: paths.hpp:115
std::string getPersistentVolumePath(const std::string &workDir, const std::string &role, const std::string &persistenceId)
Try< std::list< std::string > > getResourceProviderPaths(const std::string &metaDir, const SlaveID &slaveId)
Try< Nothing > createSandboxDirectory(const std::string &directory, const Option< std::string > &user)
std::string getForkedPidPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
std::string getExecutorInfoPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId)
std::string getContainerRootfsPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
Try< std::list< std::string > > getContainerPaths(const std::string &rootDir)
std::string getExecutorSentinelPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
std::string getLatestSlavePath(const std::string &rootDir)
std::string getTaskInfoPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId, const TaskID &taskId)
std::string getTaskUpdatesPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId, const TaskID &taskId)
std::string getExecutorVirtualPath(const FrameworkID &frameworkId, const ExecutorID &executorId)
Try< std::list< std::string > > getTaskPaths(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)