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 // | |-- slaves
75 // | |-- latest (symlink)
76 // | |-- <slave_id>
77 // | |-- slave.info
78 // | |-- resource_providers
79 // | | |-- <type>
80 // | | |-- <name>
81 // | | |-- latest (symlink)
82 // | | |-- <resource_provider_id>
83 // | | |-- resource_provider.state
84 // | | |-- operations
85 // | | |-- <operation_uuid>
86 // | | |-- operation.updates
87 // | |-- frameworks
88 // | |-- <framework_id>
89 // | |-- framework.info
90 // | |-- framework.pid
91 // | |-- executors
92 // | |-- <executor_id>
93 // | |-- executor.info
94 // | |-- runs
95 // | |-- latest (symlink)
96 // | |-- <container_id> (sandbox)
97 // | |-- executor.sentinel (if completed)
98 // | |-- pids
99 // | | |-- forked.pid
100 // | | |-- libprocess.pid
101 // | |-- tasks
102 // | |-- <task_id>
103 // | |-- task.info
104 // | |-- task.updates
105 // |-- volumes
106 // | |-- roles
107 // | |-- <role>
108 // | |-- <persistence_id> (persistent volume)
109 // |-- provisioner
110 // |-- csi
111 
112 
114 {
115  SlaveID slaveId;
116  FrameworkID frameworkId;
117  ExecutorID executorId;
118  ContainerID containerId;
119 };
120 
121 
123  const std::string& rootDir,
124  const std::string& dir);
125 
126 
127 const char LATEST_SYMLINK[] = "latest";
128 
129 // Helpers for obtaining paths in the layout.
130 // NOTE: The parameter names should adhere to the following convention:
131 //
132 // (1) Use `workDir` if the helper expects the `--work_dir` flag.
133 //
134 // (2) Use `metaDir` if the helper expects the meta directory.
135 //
136 // (3) Use `rootDir` only if the helper is to be reused.
137 //
138 // TODO(chhsiao): Clean up the parameter names to follow the convention.
139 
140 std::string getMetaRootDir(const std::string& rootDir);
141 
142 
143 std::string getSandboxRootDir(const std::string& rootDir);
144 
145 
146 std::string getProvisionerDir(const std::string& rootDir);
147 
148 
149 std::string getCsiRootDir(const std::string& workDir);
150 
151 
152 std::string getLatestSlavePath(const std::string& rootDir);
153 
154 
155 std::string getBootIdPath(const std::string& rootDir);
156 
157 
158 std::string getSlaveInfoPath(
159  const std::string& rootDir,
160  const SlaveID& slaveId);
161 
162 
163 std::string getSlavePath(
164  const std::string& rootDir,
165  const SlaveID& slaveId);
166 
167 
169  const std::string& rootDir);
170 
171 
172 std::string getContainerPath(
173  const std::string& rootDir,
174  const ContainerID& containerId);
175 
176 
178  const std::string& rootDir,
179  const SlaveID& slaveId);
180 
181 
182 std::string getFrameworkPath(
183  const std::string& rootDir,
184  const SlaveID& slaveId,
185  const FrameworkID& frameworkId);
186 
187 
188 std::string getFrameworkPidPath(
189  const std::string& rootDir,
190  const SlaveID& slaveId,
191  const FrameworkID& frameworkId);
192 
193 
194 std::string getFrameworkInfoPath(
195  const std::string& rootDir,
196  const SlaveID& slaveId,
197  const FrameworkID& frameworkId);
198 
199 
201  const std::string& rootDir,
202  const SlaveID& slaveId,
203  const FrameworkID& frameworkId);
204 
205 
206 std::string getExecutorPath(
207  const std::string& rootDir,
208  const SlaveID& slaveId,
209  const FrameworkID& frameworkId,
210  const ExecutorID& executorId);
211 
212 
213 std::string getExecutorInfoPath(
214  const std::string& rootDir,
215  const SlaveID& slaveId,
216  const FrameworkID& frameworkId,
217  const ExecutorID& executorId);
218 
219 
221  const std::string& rootDir,
222  const SlaveID& slaveId,
223  const FrameworkID& frameworkId,
224  const ExecutorID& executorId);
225 
226 
227 std::string getExecutorRunPath(
228  const std::string& rootDir,
229  const SlaveID& slaveId,
230  const FrameworkID& frameworkId,
231  const ExecutorID& executorId,
232  const ContainerID& containerId);
233 
234 
235 std::string getExecutorHttpMarkerPath(
236  const std::string& rootDir,
237  const SlaveID& slaveId,
238  const FrameworkID& frameworkId,
239  const ExecutorID& executorId,
240  const ContainerID& containerId);
241 
242 
243 std::string getExecutorSentinelPath(
244  const std::string& rootDir,
245  const SlaveID& slaveId,
246  const FrameworkID& frameworkId,
247  const ExecutorID& executorId,
248  const ContainerID& containerId);
249 
250 
251 // Returns the "virtual" path used to expose the executor's sandbox
252 // via the /files endpoints: `/frameworks/FID/executors/EID/latest`.
253 std::string getExecutorVirtualPath(
254  const FrameworkID& frameworkId,
255  const ExecutorID& executorId);
256 
257 
258 std::string getExecutorLatestRunPath(
259  const std::string& rootDir,
260  const SlaveID& slaveId,
261  const FrameworkID& frameworkId,
262  const ExecutorID& executorId);
263 
264 
265 std::string getLibprocessPidPath(
266  const std::string& rootDir,
267  const SlaveID& slaveId,
268  const FrameworkID& frameworkId,
269  const ExecutorID& executorId,
270  const ContainerID& containerId);
271 
272 
273 std::string getForkedPidPath(
274  const std::string& rootDir,
275  const SlaveID& slaveId,
276  const FrameworkID& frameworkId,
277  const ExecutorID& executorId,
278  const ContainerID& containerId);
279 
280 
281 std::string getContainerRootfsPath(
282  const std::string& rootDir,
283  const SlaveID& slaveId,
284  const FrameworkID& frameworkId,
285  const ExecutorID& executorId,
286  const ContainerID& containerId);
287 
288 
290  const std::string& rootDir,
291  const SlaveID& slaveId,
292  const FrameworkID& frameworkId,
293  const ExecutorID& executorId,
294  const ContainerID& containerId);
295 
296 
297 std::string getTaskPath(
298  const std::string& rootDir,
299  const SlaveID& slaveId,
300  const FrameworkID& frameworkId,
301  const ExecutorID& executorId,
302  const ContainerID& containerId,
303  const TaskID& taskId);
304 
305 
306 std::string getTaskInfoPath(
307  const std::string& rootDir,
308  const SlaveID& slaveId,
309  const FrameworkID& frameworkId,
310  const ExecutorID& executorId,
311  const ContainerID& containerId,
312  const TaskID& taskId);
313 
314 
315 std::string getTaskUpdatesPath(
316  const std::string& rootDir,
317  const SlaveID& slaveId,
318  const FrameworkID& frameworkId,
319  const ExecutorID& executorId,
320  const ContainerID& containerId,
321  const TaskID& taskId);
322 
323 
325  const std::string& rootDir,
326  const SlaveID& slaveId);
327 
328 
330  const std::string& metaDir,
331  const SlaveID& slaveId);
332 
333 
334 std::string getResourceProviderPath(
335  const std::string& metaDir,
336  const SlaveID& slaveId,
337  const std::string& resourceProviderType,
338  const std::string& resourceProviderName,
339  const ResourceProviderID& resourceProviderId);
340 
341 
342 std::string getResourceProviderStatePath(
343  const std::string& metaDir,
344  const SlaveID& slaveId,
345  const std::string& resourceProviderType,
346  const std::string& resourceProviderName,
347  const ResourceProviderID& resourceProviderId);
348 
349 
351  const std::string& metaDir,
352  const SlaveID& slaveId,
353  const std::string& resourceProviderType,
354  const std::string& resourceProviderName);
355 
356 
358  const std::string& rootDir);
359 
360 
361 std::string getOperationPath(
362  const std::string& rootDir,
363  const id::UUID& operationUuid);
364 
365 
367  const std::string& rootDir,
368  const std::string& dir);
369 
370 
371 std::string getOperationUpdatesPath(
372  const std::string& rootDir,
373  const id::UUID& operationUuid);
374 
375 
376 std::string getResourcesInfoPath(
377  const std::string& rootDir);
378 
379 
380 std::string getResourcesTargetPath(
381  const std::string& rootDir);
382 
383 
385  const std::string& workDir);
386 
387 
388 std::string getPersistentVolumePath(
389  const std::string& workDir,
390  const std::string& role,
391  const std::string& persistenceId);
392 
393 
394 std::string getPersistentVolumePath(
395  const std::string& workDir,
396  const Resource& resource);
397 
398 
400  const std::string& rootDir,
401  const SlaveID& slaveId,
402  const FrameworkID& frameworkId,
403  const ExecutorID& executorId,
404  const ContainerID& containerId,
405  const Option<std::string>& user = None());
406 
407 
409  const std::string& directory,
410  const Option<std::string>& user);
411 
412 
413 std::string createSlaveDirectory(
414  const std::string& rootDir,
415  const SlaveID& slaveId);
416 
417 
419  const std::string& rootDir,
420  const SlaveID& slaveId,
421  const std::string& resourceProviderType,
422  const std::string& resourceProviderName,
423  const ResourceProviderID& resourceProviderId);
424 
425 
426 extern const char LIBPROCESS_PID_FILE[];
427 extern const char HTTP_MARKER_FILE[];
428 
429 } // namespace paths {
430 } // namespace slave {
431 } // namespace internal {
432 } // namespace mesos {
433 
434 #endif // __SLAVE_PATHS_HPP__
std::string getExecutorRunPath(const std::string &rootDir, const SlaveID &slaveId, const FrameworkID &frameworkId, const ExecutorID &executorId, const ContainerID &containerId)
Definition: check.hpp:33
ExecutorID executorId
Definition: paths.hpp:117
const char LATEST_SYMLINK[]
Definition: paths.hpp:127
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 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:118
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
Definition: spec.hpp:26
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)
Try< std::list< std::string > > getOperationPaths(const std::string &rootDir)
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)
SlaveID slaveId
Definition: paths.hpp:115
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:116
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 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)