| 810 | |
| 811 | |
| 812 | Try<string> createExecutorDirectory( |
| 813 | const string& rootDir, |
| 814 | const SlaveID& slaveId, |
| 815 | const FrameworkID& frameworkId, |
| 816 | const ExecutorID& executorId, |
| 817 | const ContainerID& containerId, |
| 818 | const Option<string>& user) |
| 819 | { |
| 820 | // These IDs should be valid as they are either assigned by the |
| 821 | // master/agent or validated by the master but we do a sanity check |
| 822 | // here before using them to create a directory. |
| 823 | CHECK_NONE(common::validation::validateSlaveID(slaveId)); |
| 824 | CHECK_NONE(common::validation::validateFrameworkID(frameworkId)); |
| 825 | CHECK_NONE(common::validation::validateExecutorID(executorId)); |
| 826 | CHECK_NONE(slave::validation::container::validateContainerId(containerId)); |
| 827 | |
| 828 | const string directory = |
| 829 | getExecutorRunPath(rootDir, slaveId, frameworkId, executorId, containerId); |
| 830 | |
| 831 | if (user.isSome()) { |
| 832 | LOG(INFO) << "Creating sandbox '" << directory << "'" |
| 833 | << " for user '" << user.get() << "'"; |
| 834 | } else { |
| 835 | LOG(INFO) << "Creating sandbox '" << directory << "'"; |
| 836 | } |
| 837 | |
| 838 | Try<Nothing> mkdir = createSandboxDirectory(directory, user); |
| 839 | if (mkdir.isError()) { |
| 840 | return Error( |
| 841 | "Failed to create executor directory '" + directory + "': " + |
| 842 | mkdir.error()); |
| 843 | } |
| 844 | |
| 845 | // Remove the previous "latest" symlink. |
| 846 | const string latest = |
| 847 | getExecutorLatestRunPath(rootDir, slaveId, frameworkId, executorId); |
| 848 | |
| 849 | if (os::exists(latest)) { |
| 850 | CHECK_SOME(os::rm(latest)) |
| 851 | << "Failed to remove latest symlink '" << latest << "'"; |
| 852 | } |
| 853 | |
| 854 | // Symlink the new executor directory to "latest". |
| 855 | Try<Nothing> symlink = ::fs::symlink(directory, latest); |
| 856 | if (symlink.isError()) { |
| 857 | return Error( |
| 858 | "Failed to symlink '" + directory + "' to '" + latest + "': " + |
| 859 | symlink.error()); |
| 860 | } |
| 861 | |
| 862 | return directory; |
| 863 | } |
| 864 | |
| 865 | |
| 866 | // Given a directory path and an optional user, create a directory |