单个节点支持多个DNS线路

This commit is contained in:
GoEdgeLab
2020-11-16 13:03:45 +08:00
parent 4d0f3611a5
commit 71c682470c
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,
})
}
}