mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-04 16:00:24 +08:00
修复域名解析--集群中单节点多IP时无法修改IP的Bug
This commit is contained in:
@@ -1344,7 +1344,7 @@ func (this *NodeService) FindAllEnabledNodesDNSWithNodeClusterId(ctx context.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, ipAddress := range ipAddresses {
|
for _, ipAddress := range ipAddresses {
|
||||||
ip := ipAddress.DNSIP()
|
var ip = ipAddress.DNSIP()
|
||||||
if len(ip) == 0 {
|
if len(ip) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1352,11 +1352,12 @@ func (this *NodeService) FindAllEnabledNodesDNSWithNodeClusterId(ctx context.Con
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result = append(result, &pb.NodeDNSInfo{
|
result = append(result, &pb.NodeDNSInfo{
|
||||||
Id: int64(node.Id),
|
Id: int64(node.Id),
|
||||||
Name: node.Name,
|
Name: node.Name,
|
||||||
IpAddr: ip,
|
IpAddr: ip,
|
||||||
Routes: pbRoutes,
|
NodeIPAddressId: int64(ipAddress.Id),
|
||||||
NodeClusterId: req.NodeClusterId,
|
Routes: pbRoutes,
|
||||||
|
NodeClusterId: req.NodeClusterId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1382,9 +1383,24 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
|
|||||||
return &pb.FindEnabledNodeDNSResponse{Node: nil}, nil
|
return &pb.FindEnabledNodeDNSResponse{Node: nil}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ipAddr, _, err := models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddress(tx, int64(node.Id), true, nodeconfigs.NodeRoleNode)
|
// 查询节点IP地址
|
||||||
if err != nil {
|
var ipAddr string
|
||||||
return nil, err
|
var ipAddrId int64 = 0
|
||||||
|
if req.NodeIPAddrId > 0 {
|
||||||
|
address, err := models.SharedNodeIPAddressDAO.FindEnabledAddress(tx, req.NodeIPAddrId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if address != nil {
|
||||||
|
ipAddr = address.Ip
|
||||||
|
ipAddrId = int64(address.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ipAddrId == 0 {
|
||||||
|
ipAddr, ipAddrId, err = models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddress(tx, int64(node.Id), true, nodeconfigs.NodeRoleNode)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var clusterId = int64(node.ClusterId)
|
var clusterId = int64(node.ClusterId)
|
||||||
@@ -1400,13 +1416,13 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
|
|||||||
return &pb.FindEnabledNodeDNSResponse{Node: nil}, nil
|
return &pb.FindEnabledNodeDNSResponse{Node: nil}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsDomainId := int64(clusterDNS.DnsDomainId)
|
var dnsDomainId = int64(clusterDNS.DnsDomainId)
|
||||||
dnsDomainName, err := dns.SharedDNSDomainDAO.FindDNSDomainName(tx, dnsDomainId)
|
dnsDomainName, err := dns.SharedDNSDomainDAO.FindDNSDomainName(tx, dnsDomainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pbRoutes := []*pb.DNSRoute{}
|
var pbRoutes = []*pb.DNSRoute{}
|
||||||
if dnsDomainId > 0 {
|
if dnsDomainId > 0 {
|
||||||
routeCodes, err := node.DNSRouteCodesForDomainId(dnsDomainId)
|
routeCodes, err := node.DNSRouteCodesForDomainId(dnsDomainId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1430,6 +1446,7 @@ func (this *NodeService) FindEnabledNodeDNS(ctx context.Context, req *pb.FindEna
|
|||||||
Id: int64(node.Id),
|
Id: int64(node.Id),
|
||||||
Name: node.Name,
|
Name: node.Name,
|
||||||
IpAddr: ipAddr,
|
IpAddr: ipAddr,
|
||||||
|
NodeIPAddressId: ipAddrId,
|
||||||
Routes: pbRoutes,
|
Routes: pbRoutes,
|
||||||
NodeClusterId: clusterId,
|
NodeClusterId: clusterId,
|
||||||
NodeClusterDNSName: clusterDNS.DnsName,
|
NodeClusterDNSName: clusterDNS.DnsName,
|
||||||
@@ -1458,7 +1475,7 @@ func (this *NodeService) UpdateNodeDNS(ctx context.Context, req *pb.UpdateNodeDN
|
|||||||
return nil, errors.New("node not found")
|
return nil, errors.New("node not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
routeCodeMap := node.DNSRouteCodes()
|
var routeCodeMap = node.DNSRouteCodes()
|
||||||
if req.DnsDomainId > 0 {
|
if req.DnsDomainId > 0 {
|
||||||
if len(req.Routes) > 0 {
|
if len(req.Routes) > 0 {
|
||||||
var m = map[int64][]string{} // domainId => codes
|
var m = map[int64][]string{} // domainId => codes
|
||||||
@@ -1503,20 +1520,27 @@ func (this *NodeService) UpdateNodeDNS(ctx context.Context, req *pb.UpdateNodeDN
|
|||||||
|
|
||||||
// 修改IP
|
// 修改IP
|
||||||
if len(req.IpAddr) > 0 {
|
if len(req.IpAddr) > 0 {
|
||||||
ipAddrId, err := models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddressId(tx, req.NodeId, true, nodeconfigs.NodeRoleNode)
|
if req.NodeIPAddressId > 0 { // 指定了IP地址ID
|
||||||
if err != nil {
|
err = models.SharedNodeIPAddressDAO.UpdateAddressIP(tx, req.NodeIPAddressId, req.IpAddr)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if ipAddrId > 0 {
|
|
||||||
err = models.SharedNodeIPAddressDAO.UpdateAddressIP(tx, ipAddrId, req.IpAddr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else { // 没有指定IP地址ID
|
||||||
_, err = models.SharedNodeIPAddressDAO.CreateAddress(tx, adminId, req.NodeId, nodeconfigs.NodeRoleNode, "DNS IP", req.IpAddr, true, true, 0)
|
ipAddrId, err := models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddressId(tx, req.NodeId, true, nodeconfigs.NodeRoleNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if ipAddrId > 0 {
|
||||||
|
err = models.SharedNodeIPAddressDAO.UpdateAddressIP(tx, ipAddrId, req.IpAddr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_, err = models.SharedNodeIPAddressDAO.CreateAddress(tx, adminId, req.NodeId, nodeconfigs.NodeRoleNode, "DNS IP", req.IpAddr, true, true, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user