* Creates a MasterInfo protobuf from the process's UPID. * * This is only used by the `StandaloneMasterDetector` (used in tests * and outside tests when ZK is not used). * * For example, when we start a slave with * `--master=master@127.0.0.1:5050`, since the slave (and consequently * its detector) doesn't have enough information about `MasterInfo`, it * tries to construct it based on the
| 622 | * as derived from the `UPID`. |
| 623 | */ |
| 624 | MasterInfo createMasterInfo(const UPID& pid) |
| 625 | { |
| 626 | MasterInfo info; |
| 627 | info.set_id(stringify(pid) + "-" + id::UUID::random().toString()); |
| 628 | |
| 629 | // NOTE: Currently, we store the ip in network order, which should |
| 630 | // be fixed. See MESOS-1201 for more details. |
| 631 | // TODO(marco): `ip` and `port` are deprecated in favor of `address`; |
| 632 | // remove them both after the deprecation cycle. |
| 633 | info.set_ip(pid.address.ip.in()->s_addr); |
| 634 | info.set_port(pid.address.port); |
| 635 | |
| 636 | info.mutable_address()->set_ip(stringify(pid.address.ip)); |
| 637 | info.mutable_address()->set_port(pid.address.port); |
| 638 | |
| 639 | info.set_pid(pid); |
| 640 | |
| 641 | Try<string> hostname = net::getHostname(pid.address.ip); |
| 642 | if (hostname.isSome()) { |
| 643 | // Hostname is deprecated; but we need to update it |
| 644 | // to maintain backward compatibility. |
| 645 | // TODO(marco): Remove once we deprecate it. |
| 646 | info.set_hostname(hostname.get()); |
| 647 | info.mutable_address()->set_hostname(hostname.get()); |
| 648 | } |
| 649 | |
| 650 | foreach (const MasterInfo::Capability& capability, |
| 651 | mesos::internal::master::MASTER_CAPABILITIES()) { |
| 652 | info.add_capabilities()->CopyFrom(capability); |
| 653 | } |
| 654 | |
| 655 | return info; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | Label createLabel(const string& key, const Option<string>& value) |