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

89 lines
2.5 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-11-02 09:50:31 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
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-02 09:50:31 +08:00
// grant
var grantMap maps.Map = nil
if cluster.GrantId > 0 {
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: cluster.GrantId})
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),
}
}
}
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,
2020-11-02 09:50:31 +08:00
"grant": grantMap,
2020-09-26 08:07:18 +08:00
"countAllNodes": countNodesResp.Count,
"countActiveNodes": countActiveNodesResp.Count,
2020-09-06 16:19:34 +08:00
})
}
}
this.Data["clusters"] = clusterMaps
this.Show()
}