| 86 | |
| 87 | |
| 88 | Try<ExecutorRunPath> parseExecutorRunPath( |
| 89 | const string& _rootDir, |
| 90 | const string& dir) |
| 91 | { |
| 92 | // TODO(josephw): Consider using `<regex>` here, which requires GCC 4.9+. |
| 93 | |
| 94 | // Make sure there's a separator at the end of the `rootdir` so that |
| 95 | // we don't accidentally slice off part of a directory. |
| 96 | const string rootDir = path::join(_rootDir, ""); |
| 97 | |
| 98 | if (!strings::startsWith(dir, rootDir)) { |
| 99 | return Error( |
| 100 | "Directory '" + dir + "' does not fall under " |
| 101 | "the root directory: " + rootDir); |
| 102 | } |
| 103 | |
| 104 | vector<string> tokens = strings::tokenize( |
| 105 | dir.substr(rootDir.size()), stringify(os::PATH_SEPARATOR)); |
| 106 | |
| 107 | // A complete executor run path consists of at least 8 tokens, which |
| 108 | // includes the four named directories and the four IDs. |
| 109 | if (tokens.size() < 8) { |
| 110 | return Error( |
| 111 | "Path after root directory is not long enough to be an " |
| 112 | "executor run path: " + path::join(tokens)); |
| 113 | } |
| 114 | |
| 115 | // All four named directories much match. |
| 116 | if (tokens[0] == SLAVES_DIR && |
| 117 | tokens[2] == FRAMEWORKS_DIR && |
| 118 | tokens[4] == EXECUTORS_DIR && |
| 119 | tokens[6] == EXECUTOR_RUNS_DIR) { |
| 120 | ExecutorRunPath path; |
| 121 | |
| 122 | path.slaveId.set_value(tokens[1]); |
| 123 | path.frameworkId.set_value(tokens[3]); |
| 124 | path.executorId.set_value(tokens[5]); |
| 125 | path.containerId.set_value(tokens[7]); |
| 126 | |
| 127 | return path; |
| 128 | } |
| 129 | |
| 130 | return Error("Could not parse executor run path from directory: " + dir); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | string getMetaRootDir(const string& rootDir) |