| 62 | |
| 63 | |
| 64 | int main(int argc, char** argv) |
| 65 | { |
| 66 | Flags flags; |
| 67 | flags.setUsageMessage("Usage: " + Path(argv[0]).basename() + " <master>"); |
| 68 | |
| 69 | // Load flags from environment and command line, and remove |
| 70 | // them from argv. |
| 71 | Try<flags::Warnings> load = flags.load(None(), &argc, &argv); |
| 72 | |
| 73 | if (flags.help) { |
| 74 | cout << flags.usage() << endl; |
| 75 | return EXIT_SUCCESS; |
| 76 | } |
| 77 | |
| 78 | if (load.isError()) { |
| 79 | cerr << flags.usage(load.error()) << endl; |
| 80 | return EXIT_FAILURE; |
| 81 | } |
| 82 | |
| 83 | // Log any flag warnings. |
| 84 | foreach (const flags::Warning& warning, load->warnings) { |
| 85 | cerr << warning.message << endl; |
| 86 | } |
| 87 | |
| 88 | // 'master' argument must be the only argument left after parsing. |
| 89 | if (argc != 2) { |
| 90 | cerr << flags.usage("There must be only one argument: <master>") << endl; |
| 91 | return EXIT_FAILURE; |
| 92 | } |
| 93 | |
| 94 | string master = argv[1]; |
| 95 | Try<mesos::master::detector::MasterDetector*> detector = |
| 96 | mesos::master::detector::MasterDetector::create(master); |
| 97 | |
| 98 | if (detector.isError()) { |
| 99 | cerr << "Failed to create a master detector: " << detector.error() << endl; |
| 100 | return EXIT_FAILURE; |
| 101 | } |
| 102 | |
| 103 | Future<Option<MasterInfo>> masterInfo = detector.get()->detect(); |
| 104 | |
| 105 | if (!masterInfo.await(flags.timeout)) { |
| 106 | cerr << "Failed to detect master from '" << master |
| 107 | << "' within " << flags.timeout << endl; |
| 108 | return -1; |
| 109 | } else { |
| 110 | CHECK(!masterInfo.isDiscarded()); |
| 111 | |
| 112 | if (masterInfo.isFailed()) { |
| 113 | cerr << "Failed to detect master from '" << master |
| 114 | << "': " << masterInfo.failure() << endl; |
| 115 | return EXIT_FAILURE; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // The future is not satisfied unless the result is Some. |
| 120 | CHECK_SOME(masterInfo.get()); |
| 121 | cout << strings::remove(masterInfo->get().pid(), "master@") << endl; |
nothing calls this directly
no test coverage detected