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