func MasterInfoToMesosHost(mi *proto.MasterInfo) *MesosHost { if mi == nil { return &MesosHost{ Host: "", Ip: "", Port: 0, PortString: "", IsLeader: false, IsRegistered: false, } } addr := mi.GetAddress() if addr.GetHostname() != "" { return &MesosHost{ Host: addr.GetHostname(), Ip: addr.GetIp(), Port: int(addr.GetPort()), PortString: fmt.Sprintf("%d", addr.GetPort()), IsLeader: false, IsRegistered: false, } } else { log.Debug("Using old protobuf format") // Old protobuf format return ProtoBufToMesosHost(mi) } }
// masterAddr returns an address (ip:port) from the given *mesos.MasterInfo or // an empty string if it nil. // // BUG(tsenart): The byte order of the `ip` field in MasterInfo is platform // dependent. We assume that Mesos is compiled with the same architecture as // Mesos-DNS and hence same byte order. If this isn't the case, the address // returned will be wrong. This only affects Mesos versions < 0.24.0 func masterAddr(info *mesos.MasterInfo) string { if info == nil { return "" } ip, port := "", int64(0) if addr := info.GetAddress(); addr != nil { // Mesos >= 0.24.0 ip, port = addr.GetIp(), int64(addr.GetPort()) } else { // Mesos < 0.24.0 ipv4 := make([]byte, net.IPv4len) byteOrder.PutUint32(ipv4, info.GetIp()) ip, port = net.IP(ipv4).String(), int64(info.GetPort()) } return net.JoinHostPort(ip, strconv.FormatInt(port, 10)) }
func extractMasterAddress(info *mesos.MasterInfo) (host string, port int) { if info != nil { host = info.GetAddress().GetHostname() if host == "" { host = info.GetAddress().GetIp() } if host != "" { // use port from Address port = int(info.GetAddress().GetPort()) } else { // deprecated: get host and port directly from MasterInfo (and not Address) host = info.GetHostname() if host == "" { host = unpackIPv4(info.GetIp()) } port = int(info.GetPort()) } } return }