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