实现数据库节点管理

This commit is contained in:
GoEdgeLab
2020-10-08 17:54:57 +08:00
parent ab4452b37f
commit 1b47a0173c
14 changed files with 440 additions and 4 deletions

View File

@@ -1,6 +1,10 @@
package db
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
@@ -11,5 +15,36 @@ func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct{}) {
countResp, err := this.RPC().DBNodeRPC().CountAllEnabledDBNodes(this.AdminContext(), &pb.CountAllEnabledDBNodesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
listResp, err := this.RPC().DBNodeRPC().ListEnabledDBNodes(this.AdminContext(), &pb.ListEnabledDBNodesRequest{
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
nodeMaps := []maps.Map{}
for _, node := range listResp.Nodes {
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"isOn": node.IsOn,
"name": node.Name,
"host": node.Host,
"port": node.Port,
"database": node.Database,
})
}
this.Data["nodes"] = nodeMaps
this.Data["page"] = page.AsHTML()
this.Show()
}