| 44 | namespace detector { |
| 45 | |
| 46 | Try<MasterDetector*> MasterDetector::create( |
| 47 | const Option<string>& zk_, |
| 48 | const Option<string>& masterDetectorModule_, |
| 49 | const Option<Duration>& zkSessionTimeout_) |
| 50 | { |
| 51 | if (masterDetectorModule_.isSome()) { |
| 52 | return modules::ModuleManager::create<MasterDetector>( |
| 53 | masterDetectorModule_.get()); |
| 54 | } |
| 55 | |
| 56 | if (zk_.isNone()) { |
| 57 | return new StandaloneMasterDetector(); |
| 58 | } |
| 59 | |
| 60 | const string& zk = zk_.get(); |
| 61 | |
| 62 | if (strings::startsWith(zk, "zk://")) { |
| 63 | Try<zookeeper::URL> url = zookeeper::URL::parse(zk); |
| 64 | if (url.isError()) { |
| 65 | return Error(url.error()); |
| 66 | } |
| 67 | if (url->path == "/") { |
| 68 | return Error( |
| 69 | "Expecting a (chroot) path for ZooKeeper ('/' is not supported)"); |
| 70 | } |
| 71 | return new ZooKeeperMasterDetector( |
| 72 | url.get(), |
| 73 | zkSessionTimeout_.getOrElse(MASTER_DETECTOR_ZK_SESSION_TIMEOUT)); |
| 74 | } else if (strings::startsWith(zk, "file://")) { |
| 75 | // Load the configuration out of a file. While Mesos and related |
| 76 | // programs always use <stout/flags> to process the command line |
| 77 | // arguments (and therefore file://) this entrypoint is exposed by |
| 78 | // libmesos, with frameworks currently calling it and expecting it |
| 79 | // to do the argument parsing for them which roughly matches the |
| 80 | // argument parsing Mesos will do. |
| 81 | // TODO(cmaloney): Rework the libmesos exposed APIs to expose |
| 82 | // A "flags" endpoint where the framework can pass the command |
| 83 | // line arguments and they will be parsed by <stout/flags> and the |
| 84 | // needed flags extracted, and then change this interface to |
| 85 | // require final values from the flags. This means that a |
| 86 | // framework doesn't need to know how the flags are passed to |
| 87 | // match mesos' command line arguments if it wants, but if it |
| 88 | // needs to inspect/manipulate arguments, it can. |
| 89 | LOG(WARNING) << "Specifying master detection mechanism / ZooKeeper URL to " |
| 90 | "be read out of a file via 'file://' is deprecated inside " |
| 91 | "Mesos and will be removed in a future release."; |
| 92 | const string& path = zk.substr(7); |
| 93 | const Try<string> read = os::read(path); |
| 94 | if (read.isError()) { |
| 95 | return Error("Failed to read from file at '" + path + "'"); |
| 96 | } |
| 97 | |
| 98 | return create(strings::trim(read.get())); |
| 99 | } |
| 100 | |
| 101 | CHECK(!strings::startsWith(zk, "file://")); |
| 102 | |
| 103 | // Okay, try and parse what we got as a PID. |