mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-14 14:50:24 +08:00
单个节点支持多个DNS线路
This commit is contained in:
@@ -19,7 +19,7 @@ func (this *DNSDomain) DecodeRoutes() ([]*dnsclients.Route, error) {
|
||||
}
|
||||
|
||||
// 检查是否包含某个线路
|
||||
func (this *DNSDomain) ContainsRoute(route string) (bool, error) {
|
||||
func (this *DNSDomain) ContainsRouteCode(route string) (bool, error) {
|
||||
routes, err := this.DecodeRoutes()
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@@ -458,11 +458,11 @@ func (this *NodeClusterDAO) CheckClusterDNS(cluster *NodeCluster) (issues []*pb.
|
||||
for _, node := range nodes {
|
||||
nodeId := int64(node.Id)
|
||||
|
||||
route, err := node.DNSRoute(domainId)
|
||||
routeCodes, err := node.DNSRouteCodesForDomainId(domainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(route) == 0 {
|
||||
if len(routeCodes) == 0 {
|
||||
issues = append(issues, &pb.DNSIssue{
|
||||
Target: node.Name,
|
||||
TargetId: nodeId,
|
||||
@@ -477,22 +477,24 @@ func (this *NodeClusterDAO) CheckClusterDNS(cluster *NodeCluster) (issues []*pb.
|
||||
}
|
||||
|
||||
// 检查线路是否在已有线路中
|
||||
routeOk, err := domain.ContainsRoute(route)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !routeOk {
|
||||
issues = append(issues, &pb.DNSIssue{
|
||||
Target: node.Name,
|
||||
TargetId: nodeId,
|
||||
Type: "node",
|
||||
Description: "线路已经失效,请重新选择",
|
||||
Params: map[string]string{
|
||||
"clusterName": cluster.Name,
|
||||
"clusterId": numberutils.FormatInt64(clusterId),
|
||||
},
|
||||
})
|
||||
continue
|
||||
for _, routeCode := range routeCodes {
|
||||
routeOk, err := domain.ContainsRouteCode(routeCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !routeOk {
|
||||
issues = append(issues, &pb.DNSIssue{
|
||||
Target: node.Name,
|
||||
TargetId: nodeId,
|
||||
Type: "node",
|
||||
Description: "线路已经失效,请重新选择",
|
||||
Params: map[string]string{
|
||||
"clusterName": cluster.Name,
|
||||
"clusterId": numberutils.FormatInt64(clusterId),
|
||||
},
|
||||
})
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// 检查IP地址
|
||||
|
||||
@@ -629,12 +629,12 @@ func (this *NodeDAO) FindEnabledNodeDNS(nodeId int64) (*Node, error) {
|
||||
}
|
||||
|
||||
// 修改节点的DNS信息
|
||||
func (this *NodeDAO) UpdateNodeDNS(nodeId int64, routes map[int64]string) error {
|
||||
func (this *NodeDAO) UpdateNodeDNS(nodeId int64, routes map[int64][]string) error {
|
||||
if nodeId <= 0 {
|
||||
return errors.New("invalid nodeId")
|
||||
}
|
||||
if routes == nil {
|
||||
routes = map[int64]string{}
|
||||
routes = map[int64][]string{}
|
||||
}
|
||||
routesJSON, err := json.Marshal(routes)
|
||||
if err != nil {
|
||||
|
||||
@@ -41,28 +41,28 @@ func (this *Node) DecodeStatus() (*nodeconfigs.NodeStatus, error) {
|
||||
}
|
||||
|
||||
// 所有的DNS线路
|
||||
func (this *Node) DNSRoutes() (map[int64]string, error) {
|
||||
routes := map[int64]string{} // domainId => route
|
||||
func (this *Node) DNSRouteCodes() (map[int64][]string, error) {
|
||||
routes := map[int64][]string{} // domainId => routes
|
||||
if len(this.DnsRoutes) == 0 || this.DnsRoutes == "null" {
|
||||
return routes, nil
|
||||
}
|
||||
err := json.Unmarshal([]byte(this.DnsRoutes), &routes)
|
||||
if err != nil {
|
||||
return map[int64]string{}, err
|
||||
return map[int64][]string{}, err
|
||||
}
|
||||
return routes, nil
|
||||
}
|
||||
|
||||
// DNS线路
|
||||
func (this *Node) DNSRoute(dnsDomainId int64) (string, error) {
|
||||
routes := map[int64]string{} // domainId => route
|
||||
func (this *Node) DNSRouteCodesForDomainId(dnsDomainId int64) ([]string, error) {
|
||||
routes := map[int64][]string{} // domainId => routes
|
||||
if len(this.DnsRoutes) == 0 || this.DnsRoutes == "null" {
|
||||
return "", nil
|
||||
return nil, nil
|
||||
}
|
||||
err := json.Unmarshal([]byte(this.DnsRoutes), &routes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
route, _ := routes[dnsDomainId]
|
||||
return route, nil
|
||||
domainRoutes, _ := routes[dnsDomainId]
|
||||
return domainRoutes, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user