From 1e596a216f4fa36755b69fba5a748022ea36a87d Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 1 Mar 2023 11:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8A=82=E7=82=B9IP=E5=9C=B0=E5=9D=80=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E8=AE=BE=E7=BD=AE=E4=B8=93=E5=B1=9E=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/clusters/cluster/node/detail.go | 39 ++++++-- .../default/clusters/cluster/node/update.go | 11 +++ .../clusters/clusterutils/cluster_helper.go | 2 +- .../default/nodes/ipAddresses/createPopup.go | 21 ++++ .../nodes/ipAddresses/ipaddressutils/utils.go | 97 ++++++++++++++++--- .../default/nodes/ipAddresses/updatePopup.go | 20 ++++ .../node/node-ip-address-cluters-selector.js | 53 ++++++++++ .../components/node/node-ip-addresses-box.js | 21 +++- .../clusters/cluster/node/detail.html | 8 +- .../clusters/cluster/node/update.html | 2 +- .../nodes/ipAddresses/createPopup.html | 6 +- .../nodes/ipAddresses/updatePopup.html | 8 +- .../@default/nodes/ipAddresses/updatePopup.js | 10 ++ 13 files changed, 265 insertions(+), 33 deletions(-) create mode 100644 web/public/js/components/node/node-ip-address-cluters-selector.js diff --git a/internal/web/actions/default/clusters/cluster/node/detail.go b/internal/web/actions/default/clusters/cluster/node/detail.go index 75f9b37d..bcef8d30 100644 --- a/internal/web/actions/default/clusters/cluster/node/detail.go +++ b/internal/web/actions/default/clusters/cluster/node/detail.go @@ -89,7 +89,7 @@ func (this *DetailAction) RunGet(params struct { return } var ipAddresses = ipAddressesResp.NodeIPAddresses - ipAddressMaps := []maps.Map{} + var ipAddressMaps = []maps.Map{} for _, addr := range ipAddressesResp.NodeIPAddresses { thresholds, err := ipaddressutils.InitNodeIPAddressThresholds(this.Parent(), addr.Id) if err != nil { @@ -103,6 +103,15 @@ func (this *DetailAction) RunGet(params struct { addr.Ip = addr.BackupIP } + // 专属集群 + var addrClusterMaps = []maps.Map{} + for _, addrCluster := range addr.NodeClusters { + addrClusterMaps = append(addrClusterMaps, maps.Map{ + "id": addrCluster.Id, + "name": addrCluster.Name, + }) + } + ipAddressMaps = append(ipAddressMaps, maps.Map{ "id": addr.Id, "name": addr.Name, @@ -111,6 +120,7 @@ func (this *DetailAction) RunGet(params struct { "canAccess": addr.CanAccess, "isOn": addr.IsOn, "isUp": addr.IsUp, + "clusters": addrClusterMaps, "thresholds": thresholds, }) } @@ -152,16 +162,31 @@ func (this *DetailAction) RunGet(params struct { if !addr.CanAccess || !addr.IsUp || !addr.IsOn { continue } + + // 过滤集群 + if len(addr.NodeClusters) > 0 { + var inCluster = false + for _, addrCluster := range addr.NodeClusters { + if addrCluster.Id == cluster.Id { + inCluster = true + } + } + if !inCluster { + continue + } + } + for _, route := range dnsInfo.Routes { var recordType = "A" if utils.IsIPv6(addr.Ip) { recordType = "AAAA" } recordMaps = append(recordMaps, maps.Map{ - "name": dnsInfo.NodeClusterDNSName + "." + domainName, - "type": recordType, - "route": route.Name, - "value": addr.Ip, + "name": dnsInfo.NodeClusterDNSName + "." + domainName, + "type": recordType, + "route": route.Name, + "value": addr.Ip, + "clusterName": cluster.Name, }) } } @@ -179,8 +204,8 @@ func (this *DetailAction) RunGet(params struct { } } - grantMap := maps.Map{} - grantId := loginParams.GetInt64("grantId") + var grantMap = maps.Map{} + var grantId = loginParams.GetInt64("grantId") if grantId > 0 { grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId}) if err != nil { diff --git a/internal/web/actions/default/clusters/cluster/node/update.go b/internal/web/actions/default/clusters/cluster/node/update.go index b8779ac3..3123d80b 100644 --- a/internal/web/actions/default/clusters/cluster/node/update.go +++ b/internal/web/actions/default/clusters/cluster/node/update.go @@ -64,12 +64,22 @@ func (this *UpdateAction) RunGet(params struct { } var ipAddressMaps = []maps.Map{} for _, addr := range ipAddressesResp.NodeIPAddresses { + // 阈值 thresholds, err := ipaddressutils.InitNodeIPAddressThresholds(this.Parent(), addr.Id) if err != nil { this.ErrorPage(err) return } + // 专属集群 + var clusterMaps = []maps.Map{} + for _, addrCluster := range addr.NodeClusters { + clusterMaps = append(clusterMaps, maps.Map{ + "id": addrCluster.Id, + "name": addrCluster.Name, + }) + } + ipAddressMaps = append(ipAddressMaps, maps.Map{ "id": addr.Id, "name": addr.Name, @@ -78,6 +88,7 @@ func (this *UpdateAction) RunGet(params struct { "isOn": addr.IsOn, "isUp": addr.IsUp, "thresholds": thresholds, + "clusters": clusterMaps, }) } diff --git a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go index d8687d21..d5a62ae3 100644 --- a/internal/web/actions/default/clusters/clusterutils/cluster_helper.go +++ b/internal/web/actions/default/clusters/clusterutils/cluster_helper.go @@ -68,7 +68,7 @@ func (this *ClusterHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNext actionutils.SetTabbar(action, tabbar) // 左侧菜单 - secondMenuItem := action.Data.GetString("secondMenuItem") + var secondMenuItem = action.Data.GetString("secondMenuItem") switch selectedTabbar { case "setting": var menuItems = this.createSettingMenu(cluster, clusterInfo, secondMenuItem) diff --git a/internal/web/actions/default/nodes/ipAddresses/createPopup.go b/internal/web/actions/default/nodes/ipAddresses/createPopup.go index d4f8c678..dbfa476d 100644 --- a/internal/web/actions/default/nodes/ipAddresses/createPopup.go +++ b/internal/web/actions/default/nodes/ipAddresses/createPopup.go @@ -5,6 +5,7 @@ import ( teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/utils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" @@ -20,8 +21,18 @@ func (this *CreatePopupAction) Init() { } func (this *CreatePopupAction) RunGet(params struct { + NodeId int64 SupportThresholds bool }) { + // 专属集群 + clusterMaps, err := ipaddressutils.FindNodeClusterMapsWithNodeId(this.Parent(), params.NodeId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["clusters"] = clusterMaps + + // 阈值 this.Data["supportThresholds"] = params.SupportThresholds this.Show() @@ -33,6 +44,7 @@ func (this *CreatePopupAction) RunPost(params struct { Name string IsUp bool ThresholdsJSON []byte + ClusterIds []int64 Must *actions.Must }) { @@ -57,6 +69,14 @@ func (this *CreatePopupAction) RunPost(params struct { _ = json.Unmarshal(params.ThresholdsJSON, &thresholds) } + // 专属集群 + // 目前只考虑CDN边缘集群 + clusterMaps, err := ipaddressutils.FindNodeClusterMaps(this.Parent(), params.ClusterIds) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["ipAddress"] = maps.Map{ "name": params.Name, "canAccess": params.CanAccess, @@ -65,6 +85,7 @@ func (this *CreatePopupAction) RunPost(params struct { "isOn": true, "isUp": params.IsUp, "thresholds": thresholds, + "clusters": clusterMaps, } this.Success() } diff --git a/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go b/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go index b6f6d9de..a1478aa9 100644 --- a/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go +++ b/internal/web/actions/default/nodes/ipAddresses/ipaddressutils/utils.go @@ -11,14 +11,28 @@ import ( // UpdateNodeIPAddresses 保存一组IP地址 func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, role nodeconfigs.NodeRole, ipAddressesJSON []byte) error { - addresses := []maps.Map{} + var addresses = []maps.Map{} err := json.Unmarshal(ipAddressesJSON, &addresses) if err != nil { return err } for _, addr := range addresses { var resultAddrIds = []int64{} - addrId := addr.GetInt64("id") + var addrId = addr.GetInt64("id") + + // 专属集群 + var addrClusterIds = []int64{} + var addrClusters = addr.GetSlice("clusters") + if len(addrClusters) > 0 { + for _, addrCluster := range addrClusters { + var m = maps.NewMap(addrCluster) + var clusterId = m.GetInt64("id") + if clusterId > 0 { + addrClusterIds = append(addrClusterIds, clusterId) + } + } + } + if addrId > 0 { resultAddrIds = append(resultAddrIds, addrId) @@ -36,6 +50,7 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, CanAccess: addr.GetBool("canAccess"), IsOn: isOn, IsUp: addr.GetBool("isUp"), + ClusterIds: addrClusterIds, }) if err != nil { return err @@ -47,12 +62,13 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, if len(result) == 1 { // 单个创建 createResp, err := parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddress(parentAction.AdminContext(), &pb.CreateNodeIPAddressRequest{ - NodeId: nodeId, - Role: role, - Name: addr.GetString("name"), - Ip: result[0], - CanAccess: addr.GetBool("canAccess"), - IsUp: addr.GetBool("isUp"), + NodeId: nodeId, + Role: role, + Name: addr.GetString("name"), + Ip: result[0], + CanAccess: addr.GetBool("canAccess"), + IsUp: addr.GetBool("isUp"), + NodeClusterIds: addrClusterIds, }) if err != nil { return err @@ -62,13 +78,14 @@ func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, } else if len(result) > 1 { // 批量创建 createResp, err := parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddresses(parentAction.AdminContext(), &pb.CreateNodeIPAddressesRequest{ - NodeId: nodeId, - Role: role, - Name: addr.GetString("name"), - IpList: result, - CanAccess: addr.GetBool("canAccess"), - IsUp: addr.GetBool("isUp"), - GroupValue: ipStrings, + NodeId: nodeId, + Role: role, + Name: addr.GetString("name"), + IpList: result, + CanAccess: addr.GetBool("canAccess"), + IsUp: addr.GetBool("isUp"), + GroupValue: ipStrings, + NodeClusterIds: addrClusterIds, }) if err != nil { return err @@ -140,3 +157,53 @@ func InitNodeIPAddressThresholds(parentAction *actionutils.ParentAction, addrId } return thresholds, nil } + +// FindNodeClusterMapsWithNodeId 根据节点读取集群信息 +func FindNodeClusterMapsWithNodeId(parentAction *actionutils.ParentAction, nodeId int64) ([]maps.Map, error) { + var clusterMaps = []maps.Map{} + if nodeId > 0 { // CDN边缘节点 + nodeResp, err := parentAction.RPC().NodeRPC().FindEnabledNode(parentAction.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: nodeId}) + if err != nil { + return nil, err + } + var node = nodeResp.Node + if node != nil { + var clusters = []*pb.NodeCluster{} + if node.NodeCluster != nil { + clusters = append(clusters, nodeResp.Node.NodeCluster) + } + if len(node.SecondaryNodeClusters) > 0 { + clusters = append(clusters, node.SecondaryNodeClusters...) + } + for _, cluster := range clusters { + clusterMaps = append(clusterMaps, maps.Map{ + "id": cluster.Id, + "name": cluster.Name, + "isChecked": false, + }) + } + } + } + return clusterMaps, nil +} + +// FindNodeClusterMaps 根据一组集群ID读取集群信息 +func FindNodeClusterMaps(parentAction *actionutils.ParentAction, clusterIds []int64) ([]maps.Map, error) { + var clusterMaps = []maps.Map{} + if len(clusterIds) > 0 { + for _, clusterId := range clusterIds { + clusterResp, err := parentAction.RPC().NodeClusterRPC().FindEnabledNodeCluster(parentAction.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: clusterId}) + if err != nil { + return nil, err + } + var cluster = clusterResp.NodeCluster + if cluster != nil { + clusterMaps = append(clusterMaps, maps.Map{ + "id": cluster.Id, + "name": cluster.Name, + }) + } + } + } + return clusterMaps, nil +} diff --git a/internal/web/actions/default/nodes/ipAddresses/updatePopup.go b/internal/web/actions/default/nodes/ipAddresses/updatePopup.go index ec245ec3..eefa5f27 100644 --- a/internal/web/actions/default/nodes/ipAddresses/updatePopup.go +++ b/internal/web/actions/default/nodes/ipAddresses/updatePopup.go @@ -5,6 +5,7 @@ import ( teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" "github.com/TeaOSLab/EdgeAdmin/internal/utils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" @@ -21,9 +22,18 @@ func (this *UpdatePopupAction) Init() { } func (this *UpdatePopupAction) RunGet(params struct { + NodeId int64 AddressId int64 SupportThresholds bool }) { + // 专属集群 + clusterMaps, err := ipaddressutils.FindNodeClusterMapsWithNodeId(this.Parent(), params.NodeId) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["clusters"] = clusterMaps + this.Data["supportThresholds"] = params.SupportThresholds this.Show() @@ -37,6 +47,7 @@ func (this *UpdatePopupAction) RunPost(params struct { IsOn bool IsUp bool ThresholdsJSON []byte + ClusterIds []int64 Must *actions.Must }) { @@ -81,6 +92,14 @@ func (this *UpdatePopupAction) RunPost(params struct { _ = json.Unmarshal(params.ThresholdsJSON, &thresholds) } + // 专属集群 + // 目前只考虑CDN边缘集群 + clusterMaps, err := ipaddressutils.FindNodeClusterMaps(this.Parent(), params.ClusterIds) + if err != nil { + this.ErrorPage(err) + return + } + this.Data["ipAddress"] = maps.Map{ "name": params.Name, "ip": params.IP, @@ -89,6 +108,7 @@ func (this *UpdatePopupAction) RunPost(params struct { "isOn": params.IsOn, "isUp": isUp, "thresholds": thresholds, + "clusters": clusterMaps, } this.Success() diff --git a/web/public/js/components/node/node-ip-address-cluters-selector.js b/web/public/js/components/node/node-ip-address-cluters-selector.js new file mode 100644 index 00000000..9d0b5504 --- /dev/null +++ b/web/public/js/components/node/node-ip-address-cluters-selector.js @@ -0,0 +1,53 @@ +Vue.component("node-ip-address-clusters-selector", { + props: ["vClusters"], + mounted: function () { + this.checkClusters() + }, + data: function () { + let clusters = this.vClusters + if (clusters == null) { + clusters = [] + } + return { + clusters: clusters, + hasCheckedCluster: false, + clustersVisible: false + } + }, + methods: { + checkClusters: function () { + let that = this + + let b = false + this.clusters.forEach(function (cluster) { + if (cluster.isChecked) { + b = true + } + }) + + this.hasCheckedCluster = b + + return b + }, + changeCluster: function (cluster) { + cluster.isChecked = !cluster.isChecked + this.checkClusters() + }, + showClusters: function () { + this.clustersVisible = !this.clustersVisible + } + }, + template: `
+ 默认用于所有集群   修改 +
+ {{cluster.name}}   修改 +

当前IP仅在所选集群中有效。

+
+
+
+ + {{cluster.name}} + +
+
` +}) \ No newline at end of file diff --git a/web/public/js/components/node/node-ip-addresses-box.js b/web/public/js/components/node/node-ip-addresses-box.js index 9dbc1ca2..37669881 100644 --- a/web/public/js/components/node/node-ip-addresses-box.js +++ b/web/public/js/components/node/node-ip-addresses-box.js @@ -1,10 +1,16 @@ // 节点IP地址管理(标签形式) Vue.component("node-ip-addresses-box", { - props: ["v-ip-addresses", "role"], + props: ["v-ip-addresses", "role", "v-node-id"], data: function () { + let nodeId = this.vNodeId + if (nodeId == null) { + nodeId = 0 + } + return { ipAddresses: (this.vIpAddresses == null) ? [] : this.vIpAddresses, - supportThresholds: this.role != "ns" + supportThresholds: this.role != "ns", + nodeId: nodeId } }, methods: { @@ -13,7 +19,7 @@ Vue.component("node-ip-addresses-box", { window.UPDATING_NODE_IP_ADDRESS = null let that = this; - teaweb.popup("/nodes/ipAddresses/createPopup?supportThresholds=" + (this.supportThresholds ? 1 : 0), { + teaweb.popup("/nodes/ipAddresses/createPopup?nodeId=" + this.nodeId + "&supportThresholds=" + (this.supportThresholds ? 1 : 0), { callback: function (resp) { that.ipAddresses.push(resp.data.ipAddress); }, @@ -24,10 +30,10 @@ Vue.component("node-ip-addresses-box", { // 修改地址 updateIPAddress: function (index, address) { - window.UPDATING_NODE_IP_ADDRESS = address + window.UPDATING_NODE_IP_ADDRESS = teaweb.clone(address) let that = this; - teaweb.popup("/nodes/ipAddresses/updatePopup?supportThresholds=" + (this.supportThresholds ? 1 : 0), { + teaweb.popup("/nodes/ipAddresses/updatePopup?nodeId=" + this.nodeId + "&supportThresholds=" + (this.supportThresholds ? 1 : 0), { callback: function (resp) { Vue.set(that.ipAddresses, index, resp.data.ipAddress); }, @@ -58,6 +64,11 @@ Vue.component("node-ip-addresses-box", { [down] [{{address.thresholds.length}}个阈值]   + +   专属集群:[{{cluster.name}}] +   + + diff --git a/web/views/@default/clusters/cluster/node/detail.html b/web/views/@default/clusters/cluster/node/detail.html index 9984b2bc..72971741 100644 --- a/web/views/@default/clusters/cluster/node/detail.html +++ b/web/views/@default/clusters/cluster/node/detail.html @@ -22,7 +22,7 @@
-
+
[IPv6] {{address.ip}} (原:{{address.originIP}}) ({{address.name}},不可访问 @@ -30,6 +30,10 @@ [off] [down] [阈值] + + +   专属集群:[{{cluster.name}}] +
@@ -51,6 +55,7 @@ + @@ -59,6 +64,7 @@ + diff --git a/web/views/@default/nodes/ipAddresses/createPopup.html b/web/views/@default/nodes/ipAddresses/createPopup.html index aa954e2b..d2dd67b1 100644 --- a/web/views/@default/nodes/ipAddresses/createPopup.html +++ b/web/views/@default/nodes/ipAddresses/createPopup.html @@ -12,7 +12,7 @@ - + + + + +
集群 记录名 记录类型 线路
{{record.clusterName}} {{record.name}} {{record.type}} diff --git a/web/views/@default/clusters/cluster/node/update.html b/web/views/@default/clusters/cluster/node/update.html index 11b53139..5740afaf 100644 --- a/web/views/@default/clusters/cluster/node/update.html +++ b/web/views/@default/clusters/cluster/node/update.html @@ -26,7 +26,7 @@
IP地址 * - +

用于访问节点和域名解析等。

是否可以访问允许公开访问
@@ -46,6 +46,10 @@
专属集群
diff --git a/web/views/@default/nodes/ipAddresses/updatePopup.html b/web/views/@default/nodes/ipAddresses/updatePopup.html index 0829d1eb..257e3a62 100644 --- a/web/views/@default/nodes/ipAddresses/updatePopup.html +++ b/web/views/@default/nodes/ipAddresses/updatePopup.html @@ -14,7 +14,7 @@ - 是否可以访问 + 允许公开访问
@@ -28,7 +28,7 @@ - 是否启用 + 启用当前IP
@@ -58,6 +58,10 @@ + + 专属集群 + + diff --git a/web/views/@default/nodes/ipAddresses/updatePopup.js b/web/views/@default/nodes/ipAddresses/updatePopup.js index da22a175..b7b57598 100644 --- a/web/views/@default/nodes/ipAddresses/updatePopup.js +++ b/web/views/@default/nodes/ipAddresses/updatePopup.js @@ -4,5 +4,15 @@ Tea.context(function () { this.address = window.parent.UPDATING_NODE_IP_ADDRESS if (this.address != null) { this.address.isUp = (this.address.isUp ? 1 : 0) + + // 专属集群 + if (this.address.clusters != null) { + let selectedClusterIds = this.address.clusters.map(function (cluster) { + return cluster.id + }) + this.clusters.forEach(function (cluster) { + cluster.isChecked = selectedClusterIds.$contains(cluster.id) + }) + } } }) \ No newline at end of file