diff --git a/internal/web/actions/default/clusters/cluster/createNode.go b/internal/web/actions/default/clusters/cluster/createNode.go index ccebf73f..772c2c88 100644 --- a/internal/web/actions/default/clusters/cluster/createNode.go +++ b/internal/web/actions/default/clusters/cluster/createNode.go @@ -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) diff --git a/internal/web/actions/default/clusters/cluster/index.go b/internal/web/actions/default/clusters/cluster/index.go index b233c78c..f1bccd6a 100644 --- a/internal/web/actions/default/clusters/cluster/index.go +++ b/internal/web/actions/default/clusters/cluster/index.go @@ -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 diff --git a/internal/web/actions/default/clusters/cluster/node/node.go b/internal/web/actions/default/clusters/cluster/node/node.go index 45ebdc61..5865ea42 100644 --- a/internal/web/actions/default/clusters/cluster/node/node.go +++ b/internal/web/actions/default/clusters/cluster/node/node.go @@ -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 { diff --git a/internal/web/actions/default/clusters/cluster/node/update.go b/internal/web/actions/default/clusters/cluster/node/update.go index 7126d28a..f2e6f20b 100644 --- a/internal/web/actions/default/clusters/cluster/node/update.go +++ b/internal/web/actions/default/clusters/cluster/node/update.go @@ -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) diff --git a/internal/web/actions/default/clusters/index.go b/internal/web/actions/default/clusters/index.go index c1df9d6f..3ac66eca 100644 --- a/internal/web/actions/default/clusters/index.go +++ b/internal/web/actions/default/clusters/index.go @@ -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, }) } } diff --git a/internal/web/actions/default/dns/clusters/cluster.go b/internal/web/actions/default/dns/clusters/cluster.go index 87af4e6b..4a0b3ada 100644 --- a/internal/web/actions/default/dns/clusters/cluster.go +++ b/internal/web/actions/default/dns/clusters/cluster.go @@ -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 diff --git a/internal/web/actions/default/dns/domains/domainutils/utils.go b/internal/web/actions/default/dns/domains/domainutils/utils.go index 0f8c9ec3..793a03d5 100644 --- a/internal/web/actions/default/dns/domains/domainutils/utils.go +++ b/internal/web/actions/default/dns/domains/domainutils/utils.go @@ -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 +} diff --git a/internal/web/actions/default/dns/issues/updateNodePopup.go b/internal/web/actions/default/dns/issues/updateNodePopup.go index 7a7e89f9..a62b37d8 100644 --- a/internal/web/actions/default/dns/issues/updateNodePopup.go +++ b/internal/web/actions/default/dns/issues/updateNodePopup.go @@ -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) diff --git a/web/public/js/components/dns/dns-route-selector.js b/web/public/js/components/dns/dns-route-selector.js new file mode 100644 index 00000000..4bbb42ba --- /dev/null +++ b/web/public/js/components/dns/dns-route-selector.js @@ -0,0 +1,79 @@ +Vue.component("dns-route-selector", { + props: ["v-all-routes", "v-routes"], + data: function () { + let routes = this.vRoutes + if (routes == null) { + routes = [] + } + return { + routes: routes, + routeCodes: routes.$map(function (k, v) { + return v.code + }), + isAdding: false, + routeCode: "" + } + }, + methods: { + add: function () { + this.isAdding = true + }, + cancel: function () { + this.isAdding = false + }, + confirm: function () { + if (this.routeCode.length == 0) { + return + } + if (this.routeCodes.$contains(this.routeCode)) { + teaweb.warn("已经添加过此线路,不能重复添加") + return + } + let that = this + let route = this.vAllRoutes.$find(function (k, v) { + return v.code == that.routeCode + }) + if (route == null) { + return + } + + this.routeCodes.push(this.routeCode) + this.routes.push(route) + + this.routeCode = "" + this.isAdding = false + }, + remove: function (route) { + this.routeCodes.$removeValue(route.code) + this.routes.$removeIf(function (k, v) { + return v.code == route.code + }) + } + }, + template: `
` +}) \ No newline at end of file diff --git a/web/views/@default/@layout_override.css b/web/views/@default/@layout_override.css index d66ddeab..70a57103 100644 --- a/web/views/@default/@layout_override.css +++ b/web/views/@default/@layout_override.css @@ -18,4 +18,8 @@ form .fields { .link.grey:hover { color: #4183c4 !important; } +table th.center, +table td.center { + text-align: center !important; +} /*# sourceMappingURL=@layout_override.css.map */ \ No newline at end of file diff --git a/web/views/@default/@layout_override.css.map b/web/views/@default/@layout_override.css.map index 6d6bc8b8..281f253a 100644 --- a/web/views/@default/@layout_override.css.map +++ b/web/views/@default/@layout_override.css.map @@ -1 +1 @@ -{"version":3,"sources":["@layout_override.less"],"names":[],"mappings":"AACA,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,QAAO;EACrG,oCAAA;;AAGD,GAAG,OAAO,SAAU,MAAK,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,QAAS,QAAO;EACzF,oCAAA;;AAGD,GAAG,MAAM;EACR,kCAAA;;AAID,IACC;EACC,2BAAA;;AAKF,KAAK;EACJ,sBAAA;;AAGD,KAAK,KAAK;EACT,yBAAA","file":"@layout_override.css"} \ No newline at end of file +{"version":3,"sources":["@layout_override.less"],"names":[],"mappings":"AACA,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,MAAM,QAAS,QAAO;EACrG,oCAAA;;AAGD,GAAG,OAAO,SAAU,MAAK,QAAS,OAAM;AAAS,GAAG,OAAO,SAAU,MAAK,QAAS,QAAO;EACzF,oCAAA;;AAGD,GAAG,MAAM;EACR,kCAAA;;AAID,IACC;EACC,2BAAA;;AAKF,KAAK;EACJ,sBAAA;;AAGD,KAAK,KAAK;EACT,yBAAA;;AAID,KACC,GAAE;AADH,KACY,GAAE;EACZ,6BAAA","file":"@layout_override.css"} \ No newline at end of file diff --git a/web/views/@default/@layout_override.less b/web/views/@default/@layout_override.less index b11c2f60..0ce11554 100644 --- a/web/views/@default/@layout_override.less +++ b/web/views/@default/@layout_override.less @@ -26,3 +26,10 @@ form { .link.grey:hover { color: #4183c4 !important; } + +// table +table { + th.center, td.center { + text-align: center !important; + } +} diff --git a/web/views/@default/api/index.html b/web/views/@default/api/index.html index 214c10ec..229add79 100644 --- a/web/views/@default/api/index.html +++ b/web/views/@default/api/index.html @@ -6,7 +6,7 @@暂时还没有节点。
-| 节点名称 | diff --git a/web/views/@default/clusters/cluster/createNode.html b/web/views/@default/clusters/cluster/createNode.html index dc4f7771..800c1f29 100644 --- a/web/views/@default/clusters/cluster/createNode.html +++ b/web/views/@default/clusters/cluster/createNode.html @@ -23,10 +23,7 @@DNS线路 |
-
+ 可用线路是根据集群设置的域名获取的,注意DNS服务商可能对这些线路有所限制。 |
|---|
| 分组名称 | -节点数 | +节点数 | 操作 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{group.name}} | -+ | {{group.countNodes}} 0 | diff --git a/web/views/@default/clusters/cluster/index.html b/web/views/@default/clusters/cluster/index.html index 8b05affd..969479db 100644 --- a/web/views/@default/clusters/cluster/index.html +++ b/web/views/@default/clusters/cluster/index.html @@ -45,23 +45,24 @@
| ID | +ID | 节点名称 | 所属分组 | -IP | -CPU | -内存 | +IP | +DNS线路 | +CPU | +内存 | -状态 | +状态 | 操作 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{node.id}} | +{{node.id}} | {{node.name}} | {{node.group.name}} @@ -79,14 +80,20 @@ |
+
+
+ -
+ {{routeName}}
+ |
+ {{node.status.cpuUsageText}} - | -+ | {{node.status.memUsageText}} - | -+ |
健康问题
diff --git a/web/views/@default/clusters/cluster/installManual.html b/web/views/@default/clusters/cluster/installManual.html
index 0ff33bb4..f35f1991 100644
--- a/web/views/@default/clusters/cluster/installManual.html
+++ b/web/views/@default/clusters/cluster/installManual.html
@@ -7,7 +7,7 @@
所有未安装节点-
|