Files
EdgeAdmin/internal/web/actions/default/clusters/index.go

86 lines
2.4 KiB
Go
Raw Normal View History

2020-09-06 16:19:34 +08:00
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-09-26 08:07:18 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
2020-09-06 16:19:34 +08:00
"github.com/iwind/TeaGo/maps"
2020-09-26 08:07:18 +08:00
"github.com/iwind/TeaGo/types"
2020-09-06 16:19:34 +08:00
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "cluster", "index")
}
func (this *IndexAction) RunGet(params struct{}) {
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClusters(this.AdminContext(), &pb.CountAllEnabledNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
clusterMaps := []maps.Map{}
if count > 0 {
clustersResp, err := this.RPC().NodeClusterRPC().ListEnabledNodeClusters(this.AdminContext(), &pb.ListEnabledNodeClustersRequest{
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, cluster := range clustersResp.Clusters {
2020-09-26 08:07:18 +08:00
// 全部节点数量
2020-09-06 16:19:34 +08:00
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ClusterId: cluster.Id})
if err != nil {
this.ErrorPage(err)
return
}
2020-09-26 08:07:18 +08:00
// 在线节点
countActiveNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
ClusterId: cluster.Id,
ActiveState: types.Int32(configutils.BoolStateYes),
})
if err != nil {
this.ErrorPage(err)
return
}
2020-11-16 13:03:45 +08:00
// DNS
dnsDomainName := ""
if cluster.DnsDomainId > 0 {
dnsInfoResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterDNS(this.AdminContext(), &pb.FindEnabledNodeClusterDNSRequest{NodeClusterId: cluster.Id})
2020-11-02 09:50:31 +08:00
if err != nil {
this.ErrorPage(err)
return
}
2020-11-16 13:03:45 +08:00
if dnsInfoResp.Domain != nil {
dnsDomainName = dnsInfoResp.Domain.Name
2020-11-02 09:50:31 +08:00
}
}
2020-09-06 16:19:34 +08:00
clusterMaps = append(clusterMaps, maps.Map{
2020-09-26 08:07:18 +08:00
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
"countAllNodes": countNodesResp.Count,
"countActiveNodes": countActiveNodesResp.Count,
2020-11-16 13:03:45 +08:00
"dnsDomainId": cluster.DnsDomainId,
"dnsName": cluster.DnsName,
"dnsDomainName": dnsDomainName,
2020-09-06 16:19:34 +08:00
})
}
}
this.Data["clusters"] = clusterMaps
this.Show()
}