实现HTTP部分功能

This commit is contained in:
GoEdgeLab
2020-09-26 08:07:18 +08:00
parent 72865127b7
commit 86229e5a6f
32 changed files with 280 additions and 147 deletions

View File

@@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/configs/nodes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
@@ -24,12 +24,15 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ClusterId int64
InstalledState int
ActiveState int
}) {
this.Data["installState"] = params.InstalledState
this.Data["activeState"] = params.ActiveState
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
ClusterId: params.ClusterId,
InstallState: types.Int32(params.InstalledState),
ActiveState: types.Int32(params.ActiveState),
})
if err != nil {
this.ErrorPage(err)
@@ -44,10 +47,12 @@ func (this *IndexAction) RunGet(params struct {
Size: page.Size,
ClusterId: params.ClusterId,
InstallState: types.Int32(params.InstalledState),
ActiveState: types.Int32(params.ActiveState),
})
nodeMaps := []maps.Map{}
for _, node := range nodesResp.Nodes {
// 状态
isSynced := false
status := &nodes.NodeStatus{}
if len(node.Status) > 0 && node.Status != "null" {
err = json.Unmarshal([]byte(node.Status), &status)
@@ -55,7 +60,8 @@ func (this *IndexAction) RunGet(params struct {
logs.Error(err)
continue
}
status.IsActive = time.Now().Unix()-status.UpdatedAt < 120 // 2分钟之内认为活跃
status.IsActive = time.Now().Unix()-status.UpdatedAt <= 60 // N秒之内认为活跃
isSynced = status.ConfigVersion == node.Version
}
// IP
@@ -96,6 +102,7 @@ func (this *IndexAction) RunGet(params struct {
"id": node.Cluster.Id,
"name": node.Cluster.Name,
},
"isSynced": isSynced,
"ipAddresses": ipAddresses,
})
}

View File

@@ -1,9 +1,11 @@
package clusters
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
type IndexAction struct {
@@ -35,19 +37,30 @@ func (this *IndexAction) RunGet(params struct{}) {
return
}
for _, cluster := range clustersResp.Clusters {
// 节点数量
// 全部节点数量
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ClusterId: cluster.Id})
if err != nil {
this.ErrorPage(err)
return
}
// 在线节点
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
}
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
"hasGrant": cluster.GrantId > 0,
"countNodes": countNodesResp.Count,
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
"hasGrant": cluster.GrantId > 0,
"countAllNodes": countNodesResp.Count,
"countActiveNodes": countActiveNodesResp.Count,
})
}
}