实现完整的集群、域名同步

This commit is contained in:
GoEdgeLab
2020-11-14 21:28:14 +08:00
parent 28325f45a9
commit c1ec6a0319
17 changed files with 279 additions and 61 deletions

View File

@@ -68,10 +68,11 @@ func (this *ClusterAction) RunGet(params struct {
nodeMaps := []maps.Map{}
for _, node := range nodesResp.Nodes {
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
"ipAddr": node.IpAddr,
"route": node.Route,
"id": node.Id,
"name": node.Name,
"ipAddr": node.IpAddr,
"route": node.Route,
"clusterId": node.ClusterId,
})
}
this.Data["nodes"] = nodeMaps
@@ -92,5 +93,13 @@ func (this *ClusterAction) RunGet(params struct {
}
this.Data["servers"] = serverMaps
// 检查解析记录是否有变化
checkChangesResp, err := this.RPC().NodeClusterRPC().CheckNodeClusterDNSChanges(this.AdminContext(), &pb.CheckNodeClusterDNSChangesRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["dnsHasChanges"] = checkChangesResp.IsChanged
this.Show()
}

View File

@@ -0,0 +1,46 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type SyncAction struct {
actionutils.ParentAction
}
func (this *SyncAction) RunPost(params struct {
ClusterId int64
}) {
// 记录日志
this.CreateLog(oplogs.LevelInfo, "同步集群 %d 的DNS设置", params.ClusterId)
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
domain := dnsInfoResp.Domain
if domain == nil || domain.Id <= 0 {
this.Fail("此集群尚未设置域名")
}
syncResp, err := this.RPC().DNSDomainRPC().SyncDNSDomainData(this.AdminContext(), &pb.SyncDNSDomainDataRequest{
DnsDomainId: domain.Id,
NodeClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
if syncResp.ShouldFix {
this.Fail("请先修改当前页面中红色标记的问题")
}
if !syncResp.IsOk {
this.Fail(syncResp.Error)
}
this.Success()
}

View File

@@ -23,6 +23,7 @@ func init() {
// 集群
Prefix("/dns/clusters").
Get("/cluster", new(clusters.ClusterAction)).
Post("/sync", new(clusters.SyncAction)).
// 服务商
Prefix("/dns/providers").
@@ -47,9 +48,8 @@ func init() {
// 问题修复
Prefix("/dns/issues").
Data("teaSubMenu", "issue").
Get("", new(issues.IndexAction)).
GetPost("", new(issues.IndexAction)).
GetPost("/updateNodePopup", new(issues.UpdateNodePopupAction)).
GetPost("/updateServerPopup", new(issues.UpdateServerPopupAction)).
EndData().
EndAll()

View File

@@ -1,6 +1,10 @@
package issues
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
@@ -11,5 +15,27 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
this.Data["issues"] = []interface{}{}
this.Show()
}
func (this *IndexAction) RunPost(params struct{}) {
issuesResp, err := this.RPC().DNSRPC().FindAllDNSIssues(this.AdminContext(), &pb.FindAllDNSIssuesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
issueMaps := []maps.Map{}
for _, issue := range issuesResp.Issues {
issueMaps = append(issueMaps, maps.Map{
"target": issue.Target,
"targetId": issue.TargetId,
"type": issue.Type,
"description": issue.Description,
"params": issue.Params,
})
}
this.Data["issues"] = issueMaps
this.Success()
}

View File

@@ -35,6 +35,7 @@ func (this *UpdateNodePopupAction) RunGet(params struct {
this.Data["ipAddr"] = dnsInfo.IpAddr
this.Data["route"] = dnsInfo.Route
this.Data["domainId"] = dnsInfo.DnsDomainId
this.Data["domainName"] = dnsInfo.DnsDomainName
// 读取所有线路
routes := []string{}

View File

@@ -1,15 +0,0 @@
package issues
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
type UpdateServerPopupAction struct {
actionutils.ParentAction
}
func (this *UpdateServerPopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdateServerPopupAction) RunGet(params struct{}) {
this.Show()
}

View File

@@ -60,15 +60,15 @@ func (this *ProviderAction) RunGet(params struct {
dataUpdatedTime = timeutil.FormatTime("Y-m-d H:i:s", domain.DataUpdatedAt)
}
domainMaps = append(domainMaps, maps.Map{
"id": domain.Id,
"name": domain.Name,
"isOn": domain.IsOn,
"dataUpdatedTime": dataUpdatedTime,
"countRoutes": len(domain.Routes),
"countServerRecords": domain.ServerRecords,
"allServersResolved": domain.AllServersResolved,
"countClusterRecords": domain.ClusterRecords,
"allClustersResolved": domain.AllClustersResolved,
"id": domain.Id,
"name": domain.Name,
"isOn": domain.IsOn,
"dataUpdatedTime": dataUpdatedTime,
"countRoutes": len(domain.Routes),
"countServerRecords": domain.CountServerRecords,
"serversChanged": domain.ServersChanged,
"countNodeRecords": domain.CountNodeRecords,
"nodesChanged": domain.NodesChanged,
})
}
this.Data["domains"] = domainMaps