func newTestMasterInfo(id int) []byte { miPb := util.NewMasterInfo(fmt.Sprintf("master(%d)@localhost:5050", id), 123456789, 400) data, err := proto.Marshal(miPb) if err != nil { panic(err) } return data }
// Super-useful utility func that attempts to build a mesos.MasterInfo from a // upid.UPID specification. An attempt is made to determine the IP address of // the UPID's Host and any errors during such resolution will result in a nil // returned result. A nil result is also returned upon errors parsing the Port // specification of the UPID. // // TODO(jdef) make this a func of upid.UPID so that callers can invoke somePid.MasterInfo()? // func CreateMasterInfo(pid *upid.UPID) *mesos.MasterInfo { if pid == nil { return nil } port, err := strconv.Atoi(pid.Port) if err != nil { log.Errorf("failed to parse port: %v", err) return nil } //TODO(jdef) what about (future) ipv6 support? var ipv4 net.IP if ipv4 = net.ParseIP(pid.Host); ipv4 != nil { // This is needed for the people cross-compiling from macos to linux. // The cross-compiled version of net.LookupIP() fails to handle plain IPs. // See https://github.com/basho-labs/mesos-go/pull/117 } else if addrs, err := net.LookupIP(pid.Host); err == nil { for _, ip := range addrs { if ip = ip.To4(); ip != nil { ipv4 = ip break } } if ipv4 == nil { log.Errorf("host does not resolve to an IPv4 address: %v", pid.Host) return nil } } else { log.Errorf("failed to lookup IPs for host '%v': %v", pid.Host, err) return nil } packedip := binary.BigEndian.Uint32(ipv4) // network byte order is big-endian mi := util.NewMasterInfo(pid.ID, packedip, uint32(port)) mi.Pid = proto.String(pid.String()) if pid.Host != "" { mi.Hostname = proto.String(pid.Host) } return mi }