| 170 | |
| 171 | |
| 172 | PID<Master> launch(const Flags& flags, Allocator* _allocator) |
| 173 | { |
| 174 | if (master != nullptr) { |
| 175 | LOG(FATAL) << "Can only launch one local cluster at a time (for now)"; |
| 176 | } |
| 177 | |
| 178 | if (_allocator == nullptr) { |
| 179 | // Create a default allocator. |
| 180 | Try<Allocator*> defaultAllocator = HierarchicalDRFAllocator::create(); |
| 181 | if (defaultAllocator.isError()) { |
| 182 | EXIT(EXIT_FAILURE) |
| 183 | << "Failed to create an instance of HierarchicalDRFAllocator: " |
| 184 | << defaultAllocator.error(); |
| 185 | } |
| 186 | |
| 187 | // Update caller's instance. |
| 188 | _allocator = defaultAllocator.get(); |
| 189 | |
| 190 | // Save the instance for deleting later. |
| 191 | allocator = defaultAllocator.get(); |
| 192 | } else { |
| 193 | // TODO(benh): Figure out the behavior of allocator pointer and |
| 194 | // remove the else block. |
| 195 | allocator = nullptr; |
| 196 | } |
| 197 | |
| 198 | files = new Files(); |
| 199 | |
| 200 | { |
| 201 | // Use to propagate necessary flags to master. Without this, the |
| 202 | // load call will spit out an error unless their corresponding |
| 203 | // environment variables explicitly set. |
| 204 | map<string, string> propagatedFlags; |
| 205 | propagatedFlags["work_dir"] = path::join(flags.work_dir, "master"); |
| 206 | |
| 207 | master::Flags masterFlags; |
| 208 | Try<flags::Warnings> load = masterFlags.load( |
| 209 | propagatedFlags, |
| 210 | false, |
| 211 | "MESOS_"); |
| 212 | |
| 213 | if (load.isError()) { |
| 214 | EXIT(EXIT_FAILURE) |
| 215 | << "Failed to start a local cluster while loading" |
| 216 | << " master flags from the environment: " << load.error(); |
| 217 | } |
| 218 | |
| 219 | // Log any flag warnings. |
| 220 | foreach (const flags::Warning& warning, load->warnings) { |
| 221 | LOG(WARNING) << warning.message; |
| 222 | } |
| 223 | |
| 224 | // Attempt to create the `work_dir` for master as a convenience. |
| 225 | Try<Nothing> mkdir = os::mkdir(masterFlags.work_dir.get()); |
| 226 | if (mkdir.isError()) { |
| 227 | EXIT(EXIT_FAILURE) |
| 228 | << "Failed to create the work_dir for master '" |
| 229 | << masterFlags.work_dir.get() << "': " << mkdir.error(); |