MCPcopy Create free account
hub / github.com/apache/mesos / create

Method create

src/master/contender/contender.cpp:37–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35namespace contender {
36
37Try<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 + "'");

Callers

nothing calls this directly

Calls 12

startsWithFunction · 0.85
trimFunction · 0.85
getOrElseMethod · 0.80
errorMethod · 0.65
parseFunction · 0.50
ErrorFunction · 0.50
readFunction · 0.50
createFunction · 0.50
isSomeMethod · 0.45
getMethod · 0.45
isNoneMethod · 0.45
isErrorMethod · 0.45

Tested by

no test coverage detected