Files
EdgeAdmin/internal/web/actions/default/dns/domains/nodesPopup.go

147 lines
3.7 KiB
Go
Raw Normal View History

2020-12-23 16:49:53 +08:00
package domains
import (
2021-07-31 22:23:07 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
2020-12-23 16:49:53 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type NodesPopupAction struct {
actionutils.ParentAction
}
func (this *NodesPopupAction) Init() {
this.Nav("", "", "")
}
func (this *NodesPopupAction) RunGet(params struct {
DomainId int64
}) {
this.Data["domainId"] = params.DomainId
2020-12-23 16:49:53 +08:00
// 域名信息
2022-09-18 10:22:58 +08:00
domainResp, err := this.RPC().DNSDomainRPC().FindBasicDNSDomain(this.AdminContext(), &pb.FindBasicDNSDomainRequest{
2020-12-23 16:49:53 +08:00
DnsDomainId: params.DomainId,
})
if err != nil {
this.ErrorPage(err)
return
}
var domain = domainResp.DnsDomain
2020-12-23 16:49:53 +08:00
if domain == nil {
this.NotFound("dnsDomain", params.DomainId)
return
}
this.Data["domain"] = domain.Name
// 集群
var clusterMaps = []maps.Map{}
2020-12-23 16:49:53 +08:00
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithDNSDomainId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithDNSDomainIdRequest{DnsDomainId: params.DomainId})
if err != nil {
this.ErrorPage(err)
return
}
for _, cluster := range clustersResp.NodeClusters {
// 默认值
var defaultRoute = cluster.DnsDefaultRoute
2020-12-23 16:49:53 +08:00
// 节点DNS解析记录
nodesResp, err := this.RPC().NodeRPC().FindAllEnabledNodesDNSWithNodeClusterId(this.AdminContext(), &pb.FindAllEnabledNodesDNSWithNodeClusterIdRequest{
NodeClusterId: cluster.Id,
IsInstalled: true,
})
2020-12-23 16:49:53 +08:00
if err != nil {
this.ErrorPage(err)
return
}
var nodeMaps = []maps.Map{}
2020-12-23 16:49:53 +08:00
for _, node := range nodesResp.Nodes {
if len(node.Routes) > 0 {
for _, route := range node.Routes {
// 检查是否有域名解析记录
var isResolved = false
2020-12-23 16:49:53 +08:00
if len(route.Name) > 0 && len(node.IpAddr) > 0 && len(cluster.DnsName) > 0 {
2021-07-31 22:23:07 +08:00
var recordType = "A"
if utils.IsIPv6(node.IpAddr) {
recordType = "AAAA"
}
2020-12-23 16:49:53 +08:00
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.AdminContext(), &pb.ExistDNSDomainRecordRequest{
DnsDomainId: params.DomainId,
Name: cluster.DnsName,
2021-07-31 22:23:07 +08:00
Type: recordType,
2020-12-23 16:49:53 +08:00
Route: route.Code,
Value: node.IpAddr,
})
if err != nil {
this.ErrorPage(err)
return
}
isResolved = checkResp.IsOk
2020-12-23 16:49:53 +08:00
}
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
"ipAddr": node.IpAddr,
"route": maps.Map{
"name": route.Name,
"code": route.Code,
},
"clusterId": node.NodeClusterId,
"isOk": isResolved,
2020-12-23 16:49:53 +08:00
})
}
} else {
// 默认线路
var isResolved = false
if len(defaultRoute) > 0 {
var recordType = "A"
if utils.IsIPv6(node.IpAddr) {
recordType = "AAAA"
}
checkResp, err := this.RPC().DNSDomainRPC().ExistDNSDomainRecord(this.AdminContext(), &pb.ExistDNSDomainRecordRequest{
DnsDomainId: cluster.DnsDomainId,
Name: cluster.DnsName,
Type: recordType,
Route: defaultRoute,
Value: node.IpAddr,
})
if err != nil {
this.ErrorPage(err)
return
}
isResolved = checkResp.IsOk
}
2020-12-23 16:49:53 +08:00
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
"ipAddr": node.IpAddr,
"route": maps.Map{
"name": "",
"code": "",
},
"clusterId": node.NodeClusterId,
"isOk": isResolved,
2020-12-23 16:49:53 +08:00
})
}
}
if len(nodeMaps) == 0 {
continue
}
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
"dnsName": cluster.DnsName,
"nodes": nodeMaps,
})
}
this.Data["clusters"] = clusterMaps
this.Show()
}