ZKNS consistency fixes: removing old Port, renaming NamedPortMap to PortMap.

This commit is contained in:
Alain Jobart 2015-07-28 12:15:17 -07:00
Родитель 0ac6e67c08
Коммит 9ff9694ca7
4 изменённых файлов: 15 добавлений и 14 удалений

Просмотреть файл

@ -130,7 +130,7 @@ func (rz *zknsResolver) getSRV(qname string) ([]*pdnsReply, error) {
replies := make([]*pdnsReply, 0, 16)
for _, addr := range addrs.Entries {
content := fmt.Sprintf("%v\t%v %v %v", defaultPriority, defaultWeight, addr.NamedPortMap[portName], addr.Host)
content := fmt.Sprintf("%v\t%v %v %v", defaultPriority, defaultWeight, addr.PortMap[portName], addr.Host)
replies = append(replies, &pdnsReply{qname, "IN", "SRV", defaultTTL, defaultId, content})
}
return replies, nil

Просмотреть файл

@ -166,9 +166,8 @@ func (wr *Wrangler) exportVtnsToZkns(ctx context.Context, zconn zk.Conn, vtnsAdd
zknsAddrPath := fmt.Sprintf("%v/%v", zknsAddrPath, i)
zknsPaths = append(zknsPaths, zknsAddrPath)
zknsAddr := zkns.ZknsAddr{
Host: entry.Host,
Port: entry.PortMap["mysql"],
NamedPortMap: entry.PortMap,
Host: entry.Host,
PortMap: entry.PortMap,
}
err := writeAddr(zconn, zknsAddrPath, &zknsAddr)
if err != nil {

Просмотреть файл

@ -137,7 +137,7 @@ func (rz *zknsResolver) getSRV(qname string) ([]*pdnsReply, error) {
replies := make([]*pdnsReply, 0, 16)
for _, addr := range addrs.Entries {
content := fmt.Sprintf("%v\t%v %v %v", defaultPriority, defaultWeight, addr.NamedPortMap[portName], addr.Host)
content := fmt.Sprintf("%v\t%v %v %v", defaultPriority, defaultWeight, addr.PortMap[portName], addr.Host)
replies = append(replies, &pdnsReply{qname, "IN", "SRV", defaultTTL, defaultId, content})
}
return replies, nil

Просмотреть файл

@ -19,16 +19,18 @@ import (
type ZknsAddr struct {
// These fields came from a Python app originally that used a different
// naming convention.
Host string `json:"host"`
Port int32 `json:"port,omitempty"` // DEPRECATED
NamedPortMap map[string]int32 `json:"named_port_map"`
IPv4 string `json:"ipv4"`
version int // zk version to allow non-stomping writes
Host string `json:"host"`
PortMap map[string]int32 `json:"named_port_map"`
IPv4 string `json:"ipv4"`
version int // zk version to allow non-stomping writes
}
// NewAddr returns a new ZknsAddr.
func NewAddr(host string) *ZknsAddr {
return &ZknsAddr{Host: host, NamedPortMap: make(map[string]int32)}
return &ZknsAddr{
Host: host,
PortMap: make(map[string]int32),
}
}
// ZknsAddrs represents a list of individual entries. SRV records can
@ -53,7 +55,7 @@ func (zaddrs *ZknsAddrs) IsValidA() bool {
return false
}
for _, entry := range zaddrs.Entries {
if entry.IPv4 == "" || entry.Host != "" || len(entry.NamedPortMap) > 0 {
if entry.IPv4 == "" || entry.Host != "" || len(entry.PortMap) > 0 {
return false
}
}
@ -76,7 +78,7 @@ func (zaddrs *ZknsAddrs) IsValidSRV() bool {
return false
}
for _, zaddr := range zaddrs.Entries {
if zaddr.Host == "" || zaddr.IPv4 != "" || len(zaddr.NamedPortMap) == 0 {
if zaddr.Host == "" || zaddr.IPv4 != "" || len(zaddr.PortMap) == 0 {
return false
}
}
@ -156,7 +158,7 @@ func LookupName(zconn zk.Conn, addrPath string) ([]*net.SRV, error) {
// Set the weight to non-zero, otherwise the sort method is deactivated.
srv := &net.SRV{Target: addr.Host, Weight: 1}
if namedPort != "" {
srv.Port = uint16(addr.NamedPortMap[namedPort])
srv.Port = uint16(addr.PortMap[namedPort])
if srv.Port == 0 {
// If the port was requested and not defined it's probably
// a bug, so fail hard.