本文整理汇总了Golang中github.com/mesos/mesos-go/mesosproto.MasterInfo.GetIp方法的典型用法代码示例。如果您正苦于以下问题:Golang MasterInfo.GetIp方法的具体用法?Golang MasterInfo.GetIp怎么用?Golang MasterInfo.GetIp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mesos/mesos-go/mesosproto.MasterInfo
的用法示例。
在下文中一共展示了MasterInfo.GetIp方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MasterConnStr
func MasterConnStr(masterInfo *mesos.MasterInfo) string {
ip := make([]byte, 4)
native.PutUint32(ip, masterInfo.GetIp())
addr := net.IP(ip).To4().String()
port := masterInfo.GetPort()
return fmt.Sprintf("%s:%d", addr, port)
}
示例2: masterHostPort
func masterHostPort(info *mesos.MasterInfo) string {
host := info.GetHostname()
if host == "" {
// unpack IPv4
octets := make([]byte, 4)
binary.BigEndian.PutUint32(octets, info.GetIp())
ipv4 := net.IP(octets)
host = ipv4.String()
}
return net.JoinHostPort(host, masterPort(info))
}
示例3: masterAddr
// 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))
}
示例4: onLeaderChange
func (d *ZkLeaderDetector) onLeaderChange(info *mesos.MasterInfo) {
if info == nil {
log.Errorln("No leader available in Zookeeper")
} else {
leader := ""
if host := info.GetHostname(); host != "" {
leader = host
} else {
// unpack IPv4
octets := make([]byte, 4, 4)
binary.BigEndian.PutUint32(octets, info.GetIp())
ipv4 := net.IP(octets)
leader = ipv4.String()
}
leader = fmt.Sprintf("%s:%d", leader, info.GetPort())
log.Infoln("New master in Zookeeper", leader)
d.newLeader <- &leader
}
}
示例5: extractMasterAddress
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
}
示例6: hostFromMasterInfo
func (m *Mesos) hostFromMasterInfo(mi *mesosproto.MasterInfo) MesosHost {
var ipstring = ""
var port = ""
if mi != nil {
if host := mi.GetHostname(); host != "" {
ip, err := net.LookupIP(host)
if err != nil {
ipstring = host
} else {
for _, i := range ip {
four := i.To4()
if four != nil {
ipstring = i.String()
break
}
}
// If control reaches here there are no IPv4 addresses
// returned by net.LookupIP. Use the hostname as ipstring
//
ipstring = host
}
} else {
octets := make([]byte, 4, 4)
binary.BigEndian.PutUint32(octets, mi.GetIp())
ipv4 := net.IP(octets)
ipstring = ipv4.String()
}
}
if len(ipstring) > 0 {
port = fmt.Sprint(mi.GetPort())
}
return MesosHost{
host: ipstring,
port: port,
isLeader: false,
}
}
示例7: ProtoBufToMesosHost
func ProtoBufToMesosHost(mi *proto.MasterInfo) *MesosHost {
ipstring := ""
port := ""
log.WithField("mi.GetHostname()", mi.GetHostname()).Debug("protobuf MasterInfo")
log.WithField("mi.GetIp()", packedIpToString(mi.GetIp())).Debug("protobuf MasterInfo")
log.WithField("mi.GetPort()", fmt.Sprint(mi.GetPort())).Debug("protobuf MasterInfo")
if host := mi.GetHostname(); host != "" {
if ip, err := net.LookupIP(host); err == nil {
for _, i := range ip {
if four := i.To4(); four != nil {
ipstring = i.String()
break
}
}
}
}
if ipstring == "" {
ipstring = packedIpToString(mi.GetIp())
}
if ipstring == "" {
ipstring = mi.GetHostname()
}
if len(ipstring) > 0 {
port = fmt.Sprint(mi.GetPort())
}
return &MesosHost{
Host: mi.GetHostname(),
Ip: ipstring,
Port: int(mi.GetPort()),
PortString: port,
IsLeader: false,
IsRegistered: false,
}
}
示例8: Reregistered
func (sched *testScheduler) Reregistered(dr SchedulerDriver, mi *mesos.MasterInfo) {
log.Infoln("Sched.Reregistered() called")
sched.s.Equal(mi.GetIp(), uint32(123456))
sched.ch <- true
}
示例9: Registered
func (sched *testScheduler) Registered(dr SchedulerDriver, fw *mesos.FrameworkID, mi *mesos.MasterInfo) {
log.Infoln("Sched.Registered() called.")
sched.s.Equal(fw.GetValue(), sched.s.registeredFrameworkId.GetValue(), "driver did not register the expected framework ID")
sched.s.Equal(mi.GetIp(), uint32(123456))
sched.ch <- true
}
示例10: Reregistered
func (self *MesosManager) Reregistered(driver sched.SchedulerDriver, mi *mesos.MasterInfo) {
log.Printf("OnReregisterd master:%v:%v", Inet_itoa(mi.GetIp()), mi.GetPort())
}
示例11: Registered
func (self *MesosManager) Registered(driver sched.SchedulerDriver, fid *mesos.FrameworkID, mi *mesos.MasterInfo) {
log.Printf("OnRegisterd master:%v:%v, frameworkId:%v", Inet_itoa(mi.GetIp()), mi.GetPort(), fid.GetValue())
}
示例12: masterString
func masterString(info *mesos.MasterInfo) string {
return fmt.Sprintf("Id %v Ip %v Hostname %v Port %v Version %v Pid %v",
info.GetId(), info.GetIp(), info.GetHostname(), info.GetPort(), info.GetVersion(), info.GetPid())
}
示例13: validMasterInfo
func validMasterInfo(info *mesos.MasterInfo) bool {
return info.GetHostname() != "" || info.GetIp() != 0
}