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
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -1355,6 +1355,7 @@ func (this *NodeService) FindAllEnabledNodesDNSWithNodeClusterId(ctx context.Con
 | 
				
			|||||||
				Id:              int64(node.Id),
 | 
									Id:              int64(node.Id),
 | 
				
			||||||
				Name:            node.Name,
 | 
									Name:            node.Name,
 | 
				
			||||||
				IpAddr:          ip,
 | 
									IpAddr:          ip,
 | 
				
			||||||
 | 
									NodeIPAddressId: int64(ipAddress.Id),
 | 
				
			||||||
				Routes:          pbRoutes,
 | 
									Routes:          pbRoutes,
 | 
				
			||||||
				NodeClusterId:   req.NodeClusterId,
 | 
									NodeClusterId:   req.NodeClusterId,
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
@@ -1382,10 +1383,25 @@ 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地址
 | 
				
			||||||
 | 
						var ipAddr string
 | 
				
			||||||
 | 
						var ipAddrId int64 = 0
 | 
				
			||||||
 | 
						if req.NodeIPAddrId > 0 {
 | 
				
			||||||
 | 
							address, err := models.SharedNodeIPAddressDAO.FindEnabledAddress(tx, req.NodeIPAddrId)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								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)
 | 
				
			||||||
	if req.NodeClusterId > 0 {
 | 
						if req.NodeClusterId > 0 {
 | 
				
			||||||
@@ -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,6 +1520,12 @@ func (this *NodeService) UpdateNodeDNS(ctx context.Context, req *pb.UpdateNodeDN
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// 修改IP
 | 
						// 修改IP
 | 
				
			||||||
	if len(req.IpAddr) > 0 {
 | 
						if len(req.IpAddr) > 0 {
 | 
				
			||||||
 | 
							if req.NodeIPAddressId > 0 { // 指定了IP地址ID
 | 
				
			||||||
 | 
								err = models.SharedNodeIPAddressDAO.UpdateAddressIP(tx, req.NodeIPAddressId, req.IpAddr)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return nil, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else { // 没有指定IP地址ID
 | 
				
			||||||
			ipAddrId, err := models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddressId(tx, req.NodeId, true, nodeconfigs.NodeRoleNode)
 | 
								ipAddrId, err := models.SharedNodeIPAddressDAO.FindFirstNodeAccessIPAddressId(tx, req.NodeId, true, nodeconfigs.NodeRoleNode)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return nil, err
 | 
									return nil, err
 | 
				
			||||||
@@ -1519,6 +1542,7 @@ func (this *NodeService) UpdateNodeDNS(ctx context.Context, req *pb.UpdateNodeDN
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return this.Success()
 | 
						return this.Success()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user