package clusters import ( "strings" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/httpdns/httpdnsutils" "github.com/iwind/TeaGo/maps" ) type ClusterAction struct { actionutils.ParentAction } func (this *ClusterAction) Init() { this.Nav("httpdns", "cluster", "index") } func (this *ClusterAction) RunGet(params struct { ClusterId int64 InstalledState int ActiveState int Keyword string }) { httpdnsutils.AddLeftMenu(this.Parent()) cluster, err := findClusterMap(this.Parent(), params.ClusterId) if err != nil { this.ErrorPage(err) return } httpdnsutils.AddClusterTabbar(this.Parent(), cluster.GetString("name"), params.ClusterId, "node") nodes, err := listNodeMaps(this.Parent(), params.ClusterId) if err != nil { this.ErrorPage(err) return } nodes = filterClusterNodes(nodes, params.InstalledState, params.ActiveState, params.Keyword) this.Data["clusterId"] = params.ClusterId this.Data["cluster"] = cluster this.Data["installState"] = params.InstalledState this.Data["activeState"] = params.ActiveState this.Data["keyword"] = params.Keyword this.Data["nodes"] = nodes this.Data["hasNodes"] = len(nodes) > 0 this.Data["page"] = "" this.Show() } func filterClusterNodes(nodes []maps.Map, installedState int, activeState int, keyword string) []maps.Map { keyword = strings.ToLower(strings.TrimSpace(keyword)) result := make([]maps.Map, 0, len(nodes)) for _, node := range nodes { isInstalled := node.GetBool("isInstalled") if installedState == 1 && !isInstalled { continue } if installedState == 2 && isInstalled { continue } status := node.GetMap("status") isOnline := node.GetBool("isOn") && node.GetBool("isUp") && status.GetBool("isActive") if activeState == 1 && !isOnline { continue } if activeState == 2 && isOnline { continue } if len(keyword) > 0 { hit := strings.Contains(strings.ToLower(node.GetString("name")), keyword) if !hit { ipAddresses, ok := node["ipAddresses"].([]maps.Map) if ok { for _, ipAddr := range ipAddresses { if strings.Contains(strings.ToLower(ipAddr.GetString("ip")), keyword) { hit = true break } } } } if !hit { continue } } result = append(result, node) } return result }