单个节点支持多个DNS线路

This commit is contained in:
刘祥超
2020-11-16 13:03:45 +08:00
parent 8abf806ce9
commit b466868da1
43 changed files with 348 additions and 124 deletions

View File

@@ -76,8 +76,8 @@ func (this *CreateNodeAction) RunPost(params struct {
SshHost string
SshPort int
DnsDomainId int64
DnsRoute string
DnsDomainId int64
DnsRoutesJSON []byte
Must *actions.Must
}) {
@@ -94,6 +94,13 @@ func (this *CreateNodeAction) RunPost(params struct {
this.Fail("请选择所在集群")
}
dnsRouteCodes := []string{}
err := json.Unmarshal(params.DnsRoutesJSON, &dnsRouteCodes)
if err != nil {
this.ErrorPage(err)
return
}
// TODO 检查登录授权
loginInfo := &pb.NodeLogin{
Id: 0,
@@ -113,7 +120,7 @@ func (this *CreateNodeAction) RunPost(params struct {
GroupId: params.GroupId,
Login: loginInfo,
DnsDomainId: params.DnsDomainId,
DnsRoute: params.DnsRoute,
DnsRoutes: dnsRouteCodes,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -97,6 +97,12 @@ func (this *IndexAction) RunGet(params struct {
}
}
// DNS
dnsRouteNames := []string{}
for _, route := range node.DnsRoutes {
dnsRouteNames = append(dnsRouteNames, route.Name)
}
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
@@ -122,9 +128,10 @@ func (this *IndexAction) RunGet(params struct {
"id": node.Cluster.Id,
"name": node.Cluster.Name,
},
"isSynced": isSynced,
"ipAddresses": ipAddresses,
"group": groupMap,
"isSynced": isSynced,
"ipAddresses": ipAddresses,
"group": groupMap,
"dnsRouteNames": dnsRouteNames,
})
}
this.Data["nodes"] = nodeMaps

View File

@@ -70,6 +70,21 @@ func (this *NodeAction) RunGet(params struct {
})
}
// DNS相关
dnsInfoResp, err := this.RPC().NodeRPC().FindEnabledNodeDNS(this.AdminContext(), &pb.FindEnabledNodeDNSRequest{NodeId: params.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
dnsRouteMaps := []maps.Map{}
for _, dnsInfo := range dnsInfoResp.Node.Routes {
dnsRouteMaps = append(dnsRouteMaps, maps.Map{
"name": dnsInfo.Name,
"code": dnsInfo.Code,
})
}
this.Data["dnsRoutes"] = dnsRouteMaps
// 登录信息
var loginMap maps.Map = nil
if node.Login != nil {

View File

@@ -60,6 +60,38 @@ func (this *UpdateAction) RunGet(params struct {
})
}
// DNS相关
dnsInfoResp, err := this.RPC().NodeRPC().FindEnabledNodeDNS(this.AdminContext(), &pb.FindEnabledNodeDNSRequest{NodeId: params.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
dnsRouteMaps := []maps.Map{}
for _, dnsInfo := range dnsInfoResp.Node.Routes {
dnsRouteMaps = append(dnsRouteMaps, maps.Map{
"name": dnsInfo.Name,
"code": dnsInfo.Code,
})
}
this.Data["dnsRoutes"] = dnsRouteMaps
this.Data["allDNSRoutes"] = []maps.Map{}
this.Data["dnsDomainId"] = dnsInfoResp.Node.DnsDomainId
if dnsInfoResp.Node.DnsDomainId > 0 {
routesMaps := []maps.Map{}
routesResp, err := this.RPC().DNSDomainRPC().FindAllDNSDomainRoutes(this.AdminContext(), &pb.FindAllDNSDomainRoutesRequest{DnsDomainId: dnsInfoResp.Node.DnsDomainId})
if err != nil {
this.ErrorPage(err)
return
}
for _, route := range routesResp.Routes {
routesMaps = append(routesMaps, maps.Map{
"name": route.Name,
"code": route.Code,
})
}
this.Data["allDNSRoutes"] = routesMaps
}
// 登录信息
var loginMap maps.Map = nil
if node.Login != nil {
@@ -152,6 +184,9 @@ func (this *UpdateAction) RunPost(params struct {
MaxCPU int32
IsOn bool
DnsDomainId int64
DnsRoutesJSON []byte
Must *actions.Must
}) {
// 创建日志
@@ -170,6 +205,13 @@ func (this *UpdateAction) RunPost(params struct {
this.Fail("请选择所在集群")
}
dnsRouteCodes := []string{}
err := json.Unmarshal(params.DnsRoutesJSON, &dnsRouteCodes)
if err != nil {
this.ErrorPage(err)
return
}
// TODO 检查登录授权
loginInfo := &pb.NodeLogin{
Id: params.LoginId,
@@ -183,14 +225,16 @@ func (this *UpdateAction) RunPost(params struct {
}
// 保存
_, err := this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{
NodeId: params.NodeId,
GroupId: params.GroupId,
Name: params.Name,
ClusterId: params.ClusterId,
Login: loginInfo,
MaxCPU: params.MaxCPU,
IsOn: params.IsOn,
_, err = this.RPC().NodeRPC().UpdateNode(this.AdminContext(), &pb.UpdateNodeRequest{
NodeId: params.NodeId,
GroupId: params.GroupId,
Name: params.Name,
ClusterId: params.ClusterId,
Login: loginInfo,
MaxCPU: params.MaxCPU,
IsOn: params.IsOn,
DnsDomainId: params.DnsDomainId,
DnsRoutes: dnsRouteCodes,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -2,7 +2,6 @@ package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
@@ -55,20 +54,16 @@ func (this *IndexAction) RunGet(params struct{}) {
return
}
// grant
var grantMap maps.Map = nil
if cluster.GrantId > 0 {
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: cluster.GrantId})
// DNS
dnsDomainName := ""
if cluster.DnsDomainId > 0 {
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: cluster.Id})
if err != nil {
this.ErrorPage(err)
return
}
if grantResp.Grant != nil {
grantMap = maps.Map{
"id": grantResp.Grant.Id,
"name": grantResp.Grant.Name,
"methodName": grantutils.FindGrantMethodName(grantResp.Grant.Method),
}
if dnsInfoResp.Domain != nil {
dnsDomainName = dnsInfoResp.Domain.Name
}
}
@@ -76,9 +71,11 @@ func (this *IndexAction) RunGet(params struct{}) {
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
"grant": grantMap,
"countAllNodes": countNodesResp.Count,
"countActiveNodes": countActiveNodesResp.Count,
"dnsDomainId": cluster.DnsDomainId,
"dnsName": cluster.DnsName,
"dnsDomainName": dnsDomainName,
})
}
}

View File

@@ -67,16 +67,31 @@ 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": maps.Map{
"name": node.Route.Name,
"code": node.Route.Code,
},
"clusterId": node.ClusterId,
})
if len(node.Routes) > 0 {
for _, route := range node.Routes {
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.ClusterId,
})
}
} else {
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
"ipAddr": node.IpAddr,
"route": maps.Map{
"name": "",
"code": "",
},
"clusterId": node.ClusterId,
})
}
}
this.Data["nodes"] = nodeMaps

View File

@@ -1,6 +1,9 @@
package domainutils
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
"regexp"
"strings"
)
@@ -16,3 +19,30 @@ func ValidateDomainFormat(domain string) bool {
return true
}
// 转换线路列表
func ConvertRoutesToMaps(routes []*pb.DNSRoute) []maps.Map {
result := []maps.Map{}
for _, route := range routes {
result = append(result, maps.Map{
"name": route.Name,
"code": route.Code,
})
}
return result
}
// 筛选线路
func FilterRoutes(routes []*pb.DNSRoute, allRoutes []*pb.DNSRoute) []*pb.DNSRoute {
routeCodes := []string{}
for _, route := range allRoutes {
routeCodes = append(routeCodes, route.Code)
}
result := []*pb.DNSRoute{}
for _, route := range routes {
if lists.ContainsString(routeCodes, route.Code) {
result = append(result, route)
}
}
return result
}

View File

@@ -1,8 +1,10 @@
package issues
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns/domains/domainutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
@@ -33,12 +35,12 @@ func (this *UpdateNodePopupAction) RunGet(params struct {
return
}
this.Data["ipAddr"] = dnsInfo.IpAddr
this.Data["route"] = dnsInfo.Route.Code
this.Data["routes"] = domainutils.ConvertRoutesToMaps(dnsInfo.Routes)
this.Data["domainId"] = dnsInfo.DnsDomainId
this.Data["domainName"] = dnsInfo.DnsDomainName
// 读取所有线路
routeMaps := []maps.Map{}
allRouteMaps := []maps.Map{}
if dnsInfo.DnsDomainId > 0 {
routesResp, err := this.RPC().DNSDomainRPC().FindAllDNSDomainRoutes(this.AdminContext(), &pb.FindAllDNSDomainRoutesRequest{DnsDomainId: dnsInfo.DnsDomainId})
if err != nil {
@@ -47,37 +49,26 @@ func (this *UpdateNodePopupAction) RunGet(params struct {
}
if len(routesResp.Routes) > 0 {
for _, route := range routesResp.Routes {
routeMaps = append(routeMaps, maps.Map{
allRouteMaps = append(allRouteMaps, maps.Map{
"name": route.Name,
"code": route.Code,
})
}
}
}
this.Data["routes"] = routeMaps
// 是否包含现有线路
if len(routeMaps) > 0 {
isRouteValid := false
for _, route := range routeMaps {
if route.GetString("code") == dnsInfo.Route.Code {
isRouteValid = true
break
}
}
if !isRouteValid {
this.Data["route"] = routeMaps[0].GetString("code")
// 筛选
this.Data["routes"] = domainutils.ConvertRoutesToMaps(domainutils.FilterRoutes(dnsInfo.Routes, routesResp.Routes))
}
}
this.Data["allRoutes"] = allRouteMaps
this.Show()
}
func (this *UpdateNodePopupAction) RunPost(params struct {
NodeId int64
IpAddr string
DomainId int64
Route string
NodeId int64
IpAddr string
DomainId int64
DnsRoutesJSON []byte
Must *actions.Must
CSRF *actionutils.CSRF
@@ -85,6 +76,13 @@ func (this *UpdateNodePopupAction) RunPost(params struct {
// 操作日志
this.CreateLog(oplogs.LevelInfo, "修改节点 %d 的DNS设置", params.NodeId)
routes := []string{}
err := json.Unmarshal(params.DnsRoutesJSON, &routes)
if err != nil {
this.ErrorPage(err)
return
}
params.Must.
Field("ipAddr", params.IpAddr).
Require("请输入IP地址")
@@ -94,11 +92,11 @@ func (this *UpdateNodePopupAction) RunPost(params struct {
}
// 执行修改
_, err := this.RPC().NodeRPC().UpdateNodeDNS(this.AdminContext(), &pb.UpdateNodeDNSRequest{
_, err = this.RPC().NodeRPC().UpdateNodeDNS(this.AdminContext(), &pb.UpdateNodeDNSRequest{
NodeId: params.NodeId,
IpAddr: params.IpAddr,
DnsDomainId: params.DomainId,
Route: params.Route,
Routes: routes,
})
if err != nil {
this.ErrorPage(err)