// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. package ipaddrs import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/maps" ) type IndexAction struct { actionutils.ParentAction } func (this *IndexAction) Init() { this.Nav("", "", "index") } func (this *IndexAction) RunGet(params struct { ClusterId int64 UpState int8 Keyword string }) { this.Data["clusterId"] = params.ClusterId this.Data["upState"] = params.UpState this.Data["keyword"] = params.Keyword countResp, err := this.RPC().NodeIPAddressRPC().CountAllEnabledNodeIPAddresses(this.AdminContext(), &pb.CountAllEnabledNodeIPAddressesRequest{ NodeClusterId: params.ClusterId, Role: nodeconfigs.NodeRoleNode, UpState: int32(params.UpState), Keyword: params.Keyword, }) if err != nil { this.ErrorPage(err) return } var count = countResp.Count var page = this.NewPage(count) this.Data["page"] = page.AsHTML() addrsResp, err := this.RPC().NodeIPAddressRPC().ListEnabledNodeIPAddresses(this.AdminContext(), &pb.ListEnabledNodeIPAddressesRequest{ NodeClusterId: params.ClusterId, Role: nodeconfigs.NodeRoleNode, UpState: int32(params.UpState), Keyword: params.Keyword, Offset: page.Offset, Size: page.Size, }) if err != nil { this.ErrorPage(err) return } var addrMaps = []maps.Map{} for _, addr := range addrsResp.NodeIPAddresses { nodeResp, err := this.RPC().NodeRPC().FindEnabledBasicNode(this.AdminContext(), &pb.FindEnabledBasicNodeRequest{NodeId: addr.NodeId}) if err != nil { this.ErrorPage(err) return } var node = nodeResp.Node if node == nil || node.NodeCluster == nil { continue } // 阈值数量 countThresholdsResp, err := this.RPC().NodeIPAddressThresholdRPC().CountAllEnabledNodeIPAddressThresholds(this.AdminContext(), &pb.CountAllEnabledNodeIPAddressThresholdsRequest{NodeIPAddressId: addr.Id}) if err != nil { this.ErrorPage(err) return } var countThresholds = countThresholdsResp.Count // 专属集群 var clusterMaps = []maps.Map{} for _, cluster := range addr.NodeClusters { clusterMaps = append(clusterMaps, maps.Map{ "id": cluster.Id, "name": cluster.Name, }) } addrMaps = append(addrMaps, maps.Map{ "id": addr.Id, "name": addr.Name, "description": addr.Description, "ip": addr.Ip, "canAccess": addr.CanAccess, "isOn": addr.IsOn, "isUp": addr.IsUp, "isHealthy": addr.IsHealthy, "hasThresholds": countThresholds > 0, "node": maps.Map{"id": node.Id, "name": node.Name}, "cluster": maps.Map{"id": node.NodeCluster.Id, "name": node.NodeCluster.Name}, "backupIP": addr.BackupIP, "clusters": clusterMaps, }) } this.Data["addrs"] = addrMaps this.Show() }