阶段性提交

This commit is contained in:
GoEdgeLab
2020-09-06 16:19:34 +08:00
parent 2ba46b9162
commit 124cbd3302
185 changed files with 5306 additions and 1832 deletions

View File

@@ -0,0 +1,23 @@
package api
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
type Helper struct {
}
func NewHelper() *Helper {
return &Helper{}
}
func (this *Helper) BeforeAction(action *actions.ActionObject) {
action.Data["teaMenu"] = "api"
selectedTabbar, _ := action.Data["mainTab"]
tabbar := actionutils.NewTabbar()
tabbar.Add("API节点", "", "/api", "", selectedTabbar == "node")
actionutils.SetTabbar(action, tabbar)
}

View File

@@ -0,0 +1,51 @@
package api
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "node", "index")
}
func (this *IndexAction) RunGet(params struct{}) {
countResp, err := this.RPC().APINodeRPC().CountAllEnabledAPINodes(this.AdminContext(), &pb.CountAllEnabledAPINodesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
nodeMaps := []maps.Map{}
if count > 0 {
nodesResp, err := this.RPC().APINodeRPC().ListEnabledAPINodes(this.AdminContext(), &pb.ListEnabledAPINodesRequest{
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
for _, node := range nodesResp.Nodes {
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"isOn": node.IsOn,
"name": node.Name,
"host": node.Host,
"port": node.Port,
})
}
}
this.Data["nodes"] = nodeMaps
this.Show()
}

View File

@@ -0,0 +1,19 @@
package api
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/api/node"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Prefix("/api").
Get("", new(IndexAction)).
GetPost("/node/create", new(node.CreateAction)).
EndAll()
})
}

View File

@@ -0,0 +1,50 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
type CreateAction struct {
actionutils.ParentAction
}
func (this *CreateAction) Init() {
this.Nav("", "node", "create")
}
func (this *CreateAction) RunGet(params struct{}) {
this.Show()
}
func (this *CreateAction) RunPost(params struct {
Name string
Host string
Port int
Description string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入API节点").
Field("host", params.Host).
Require("请输入主机地址").
Field("port", params.Port).
Gt(0, "端口不能小于1").
Lte(65535, "端口不能大于65535")
_, err := this.RPC().APINodeRPC().CreateAPINode(this.AdminContext(), &pb.CreateAPINodeRequest{
Name: params.Name,
Description: params.Description,
Host: params.Host,
Port: int32(params.Port),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,73 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"net/http"
"strconv"
)
type Helper struct {
}
func NewHelper() *Helper {
return &Helper{}
}
func (this *Helper) BeforeAction(action *actions.ActionObject) (goNext bool) {
if action.Request.Method != http.MethodGet {
return true
}
action.Data["teaMenu"] = "api"
nodeId := action.ParamInt64("nodeId")
nodeIdString := strconv.FormatInt(nodeId, 10)
// 节点信息
rpcClient, err := rpc.SharedRPC()
if err != nil {
logs.Error(err)
return
}
nodeResp, err := rpcClient.APINodeRPC().FindEnabledAPINode(rpcClient.Context(action.Context.GetInt64("adminId")), &pb.FindEnabledAPINodeRequest{NodeId: nodeId})
if err != nil {
action.WriteString(err.Error())
return
}
if nodeResp.Node == nil {
action.WriteString("node not found")
return
}
node := nodeResp.Node
// 顶部Tab栏
selectedTabbar, _ := action.Data["mainTab"]
tabbar := actionutils.NewTabbar()
tabbar.Add("当前节点:"+node.Name, "", "/api", "left long alternate arrow", false)
tabbar.Add("设置", "", "/api/node/settings?nodeId="+nodeIdString, "setting", selectedTabbar == "setting")
actionutils.SetTabbar(action, tabbar)
// 左侧菜单栏
secondMenuItem := action.Data.GetString("secondMenuItem")
switch selectedTabbar {
case "setting":
action.Data["leftMenuItems"] = this.createSettingMenu(nodeIdString, secondMenuItem)
}
return true
}
// 设置相关菜单
func (this *Helper) createSettingMenu(nodeIdString string, selectedItem string) (items []maps.Map) {
items = append(items, maps.Map{
"name": "基础设置",
"url": "/api/node/settings?nodeId=" + nodeIdString,
"isActive": selectedItem == "basic",
})
return
}

View File

@@ -0,0 +1,20 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Prefix("/api/node").
// 节点相关
GetPost("/settings", new(SettingsAction)).
EndAll()
})
}

View File

@@ -0,0 +1,78 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type SettingsAction struct {
actionutils.ParentAction
}
func (this *SettingsAction) Init() {
this.Nav("", "setting", "")
this.SecondMenu("basic")
}
func (this *SettingsAction) RunGet(params struct {
NodeId int64
}) {
nodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{
NodeId: params.NodeId,
})
if err != nil {
this.ErrorPage(err)
return
}
node := nodeResp.Node
if node == nil {
this.WriteString("要操作的节点不存在")
return
}
this.Data["node"] = maps.Map{
"id": node.Id,
"name": node.Name,
"description": node.Description,
"host": node.Host,
"port": node.Port,
}
this.Show()
}
// 保存基础设置
func (this *SettingsAction) RunPost(params struct {
NodeId int64
Name string
Host string
Port int
Description string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入API节点").
Field("host", params.Host).
Require("请输入主机地址").
Field("port", params.Port).
Gt(0, "端口不能小于1").
Lte(65535, "端口不能大于65535")
_, err := this.RPC().APINodeRPC().UpdateAPINode(this.AdminContext(), &pb.UpdateAPINodeRequest{
NodeId: params.NodeId,
Name: params.Name,
Description: params.Description,
Host: params.Host,
Port: int32(params.Port),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -1,4 +1,4 @@
package nodes
package cluster
import (
"encoding/json"
@@ -16,11 +16,16 @@ type IndexAction struct {
}
func (this *IndexAction) Init() {
this.Nav("", "node", "index")
this.Nav("", "node", "")
this.SecondMenu("nodes")
}
func (this *IndexAction) RunGet(params struct{}) {
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodes(this.AdminContext(), &pb.CountAllEnabledNodesRequest{})
func (this *IndexAction) RunGet(params struct {
ClusterId int64
}) {
countResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{
ClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
@@ -29,9 +34,10 @@ func (this *IndexAction) RunGet(params struct{}) {
page := this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
nodesResp, err := this.RPC().NodeRPC().ListEnabledNodes(this.AdminContext(), &pb.ListEnabledNodesRequest{
Offset: page.Offset,
Size: page.Size,
nodesResp, err := this.RPC().NodeRPC().ListEnabledNodesMatch(this.AdminContext(), &pb.ListEnabledNodesMatchRequest{
Offset: page.Offset,
Size: page.Size,
ClusterId: params.ClusterId,
})
nodeMaps := []maps.Map{}
for _, node := range nodesResp.Nodes {
@@ -62,8 +68,9 @@ func (this *IndexAction) RunGet(params struct{}) {
}
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
"id": node.Id,
"name": node.Name,
"isInstalled": node.IsInstalled,
"status": maps.Map{
"isActive": status.IsActive,
"updatedAt": status.UpdatedAt,

View File

@@ -0,0 +1,26 @@
package cluster
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node"
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(clusters.NewClusterHelper()).
Prefix("/clusters/cluster").
Get("", new(IndexAction)).
// 节点相关
Get("/node", new(node.NodeAction)).
GetPost("/node/create", new(node.CreateAction)).
GetPost("/node/update", new(node.UpdateAction)).
GetPost("/node/install", new(node.InstallAction)).
Post("/node/updateInstallStatus", new(node.UpdateInstallStatusAction)).
EndAll()
})
}

View File

@@ -1,4 +1,4 @@
package nodes
package node
import (
"encoding/json"
@@ -13,28 +13,11 @@ type CreateAction struct {
}
func (this *CreateAction) Init() {
this.Nav("", "node", "create")
this.Nav("", "node", "")
this.SecondMenu("nodes")
}
func (this *CreateAction) RunGet(params struct{}) {
// 所有集群
resp, err := this.RPC().NodeClusterRPC().FindAllEnabledClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
}
if err != nil {
this.ErrorPage(err)
return
}
clusterMaps := []maps.Map{}
for _, cluster := range resp.Clusters {
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
this.Data["clusters"] = clusterMaps
this.Show()
}

View File

@@ -0,0 +1,65 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
)
type InstallAction struct {
actionutils.ParentAction
}
func (this *InstallAction) Init() {
this.Nav("", "node", "install")
this.SecondMenu("nodes")
}
func (this *InstallAction) RunGet(params struct {
NodeId int64
}) {
this.Data["nodeId"] = params.NodeId
// 节点
nodeResp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: params.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
node := nodeResp.Node
if node == nil {
this.WriteString("找不到要操作的节点")
return
}
// 集群
var clusterMap maps.Map = nil
if node.Cluster != nil {
clusterId := node.Cluster.Id
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: clusterId})
if err != nil {
this.ErrorPage(err)
return
}
cluster := clusterResp.Cluster
if cluster != nil {
clusterMap = maps.Map{
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
}
}
}
this.Data["node"] = maps.Map{
"id": node.Id,
"name": node.Name,
"installDir": node.InstallDir,
"isInstalled": node.IsInstalled,
"uniqueId": node.UniqueId,
"secret": node.Secret,
"cluster": clusterMap,
}
this.Show()
}

View File

@@ -1,4 +1,4 @@
package nodes
package node
import (
"encoding/json"
@@ -13,7 +13,8 @@ type NodeAction struct {
}
func (this *NodeAction) Init() {
this.Nav("", "node", "index")
this.Nav("", "node", "node")
this.SecondMenu("nodes")
}
func (this *NodeAction) RunGet(params struct {
@@ -34,9 +35,19 @@ func (this *NodeAction) RunGet(params struct {
var clusterMap maps.Map = nil
if node.Cluster != nil {
clusterMap = maps.Map{
"id": node.Cluster.Id,
"name": node.Cluster.Name,
clusterId := node.Cluster.Id
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: clusterId})
if err != nil {
this.ErrorPage(err)
return
}
cluster := clusterResp.Cluster
if cluster != nil {
clusterMap = maps.Map{
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
}
}
}
@@ -100,6 +111,10 @@ func (this *NodeAction) RunGet(params struct {
"ipAddresses": ipAddressMaps,
"cluster": clusterMap,
"login": loginMap,
"installDir": node.InstallDir,
"isInstalled": node.IsInstalled,
"uniqueId": node.UniqueId,
"secret": node.Secret,
}
this.Show()

View File

@@ -1,4 +1,4 @@
package nodes
package node
import (
"encoding/json"
@@ -14,7 +14,8 @@ type UpdateAction struct {
}
func (this *UpdateAction) Init() {
this.Nav("", "node", "index")
this.Nav("", "node", "update")
this.SecondMenu("nodes")
}
func (this *UpdateAction) RunGet(params struct {
@@ -104,7 +105,7 @@ func (this *UpdateAction) RunGet(params struct {
}
// 所有集群
resp, err := this.RPC().NodeClusterRPC().FindAllEnabledClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
resp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
}

View File

@@ -0,0 +1,26 @@
package node
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
)
type UpdateInstallStatusAction struct {
actionutils.ParentAction
}
func (this *UpdateInstallStatusAction) RunPost(params struct {
NodeId int64
IsInstalled bool
}) {
_, err := this.RPC().NodeRPC().UpdateNodeIsInstalled(this.AdminContext(), &pb.UpdateNodeIsInstalledRequest{
NodeId: params.NodeId,
IsInstalled: params.IsInstalled,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,89 @@
package settings
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "")
this.SecondMenu("basic")
}
func (this *IndexAction) RunGet(params struct {
ClusterId int64
}) {
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{ClusterId: params.ClusterId})
if err != nil {
this.ErrorPage(err)
return
}
cluster := clusterResp.Cluster
if cluster == nil {
this.WriteString("not found cluster")
return
}
// 认证
var grantMap interface{} = 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
}
grant := grantResp.Grant
if grant != nil {
grantMap = maps.Map{
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
}
}
}
this.Data["grant"] = grantMap
this.Data["cluster"] = maps.Map{
"id": cluster.Id,
"name": cluster.Name,
"installDir": cluster.InstallDir,
}
this.Show()
}
// 保存设置
func (this *IndexAction) RunPost(params struct {
ClusterId int64
Name string
GrantId int64
InstallDir string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入集群名称")
_, err := this.RPC().NodeClusterRPC().UpdateNodeCluster(this.AdminContext(), &pb.UpdateNodeClusterRequest{
ClusterId: params.ClusterId,
Name: params.Name,
GrantId: params.GrantId,
InstallDir: params.InstallDir,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,18 @@
package settings
import (
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(clusters.NewClusterHelper()).
Prefix("/clusters/cluster/settings").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -0,0 +1,84 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"net/http"
"strconv"
)
type ClusterHelper struct {
}
func NewClusterHelper() *ClusterHelper {
return &ClusterHelper{}
}
func (this *ClusterHelper) BeforeAction(action *actions.ActionObject) {
if action.Request.Method != http.MethodGet {
return
}
action.Data["teaMenu"] = "clusters"
selectedTabbar := action.Data.GetString("mainTab")
clusterId := action.ParamInt64("clusterId")
clusterIdString := strconv.FormatInt(clusterId, 10)
action.Data["clusterId"] = clusterId
rpcClient, err := rpc.SharedRPC()
if err != nil {
logs.Error(err)
return
}
clusterResp, err := rpcClient.NodeClusterRPC().FindEnabledNodeCluster(rpcClient.Context(action.Context.GetInt64("adminId")), &pb.FindEnabledNodeClusterRequest{ClusterId: clusterId})
if err != nil {
logs.Error(err)
return
}
cluster := clusterResp.Cluster
if cluster == nil {
action.WriteString("can not find cluster")
return
}
tabbar := actionutils.NewTabbar()
tabbar.Add("当前集群:"+cluster.Name, "", "/clusters", "left long alternate arrow", false)
tabbar.Add("节点", "", "/clusters/cluster?clusterId="+clusterIdString, "server", selectedTabbar == "node")
tabbar.Add("设置", "", "/clusters/cluster/settings?clusterId="+clusterIdString, "setting", selectedTabbar == "setting")
actionutils.SetTabbar(action, tabbar)
// 左侧菜单
secondMenuItem := action.Data.GetString("secondMenuItem")
switch selectedTabbar {
case "setting":
action.Data["leftMenuItems"] = this.createSettingMenu(clusterIdString, secondMenuItem)
case "node":
action.Data["leftMenuItems"] = this.createNodeMenu(clusterIdString, secondMenuItem)
}
}
// 节点菜单
func (this *ClusterHelper) createNodeMenu(clusterId string, selectedItem string) (items []maps.Map) {
items = append(items, maps.Map{
"name": "节点列表",
"url": "/clusters/cluster?clusterId=" + clusterId,
"isActive": selectedItem == "nodes",
})
return
}
// 设置菜单
func (this *ClusterHelper) createSettingMenu(clusterId string, selectedItem string) (items []maps.Map) {
items = append(items, maps.Map{
"name": "基础设置",
"url": "/clusters/cluster/settings?clusterId=" + clusterId,
"isActive": selectedItem == "basic",
})
return
}

View File

@@ -0,0 +1,43 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
type CreateAction struct {
actionutils.ParentAction
}
func (this *CreateAction) Init() {
this.Nav("", "cluster", "create")
}
func (this *CreateAction) RunGet(params struct{}) {
this.Show()
}
func (this *CreateAction) RunPost(params struct {
Name string
GrantId int64
InstallDir string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入集群名称")
_, err := this.RPC().NodeClusterRPC().CreateNodeCluster(this.AdminContext(), &pb.CreateNodeClusterRequest{
Name: params.Name,
GrantId: params.GrantId,
InstallDir: params.InstallDir,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,23 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
type Helper struct {
}
func NewHelper() *Helper {
return &Helper{}
}
func (this *Helper) BeforeAction(action *actions.ActionObject) {
action.Data["teaMenu"] = "clusters"
selectedTabbar, _ := action.Data["mainTab"]
tabbar := actionutils.NewTabbar()
tabbar.Add("集群", "", "/clusters", "", selectedTabbar == "cluster")
actionutils.SetTabbar(action, tabbar)
}

View File

@@ -0,0 +1,57 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
)
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 {
// 节点数量
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesMatch(this.AdminContext(), &pb.CountAllEnabledNodesMatchRequest{ClusterId: cluster.Id})
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,
})
}
}
this.Data["clusters"] = clusterMaps
this.Show()
}

View File

@@ -0,0 +1,18 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Prefix("/clusters").
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).
EndAll()
})
}

View File

@@ -15,7 +15,7 @@ func (this *ChangedClustersAction) Init() {
}
func (this *ChangedClustersAction) RunGet(params struct{}) {
resp, err := this.RPC().NodeClusterRPC().FindAllChangedClusters(this.AdminContext(), &pb.FindAllChangedClustersRequest{})
resp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return

View File

@@ -13,7 +13,7 @@ func (this *SyncClustersAction) RunPost(params struct{}) {
// TODO 将来可以单独选择某一个集群进行单独的同步
// 所有有变化的集群
clustersResp, err := this.RPC().NodeClusterRPC().FindAllChangedClusters(this.AdminContext(), &pb.FindAllChangedClustersRequest{})
clustersResp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return

View File

@@ -13,11 +13,7 @@ func init() {
Helper(new(helpers.UserMustAuth)).
Helper(new(Helper)).
Prefix("/nodes").
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).
Post("/delete", new(DeleteAction)).
GetPost("/update", new(UpdateAction)).
Get("/node", new(NodeAction)).
// IP地址
GetPost("/ipAddresses/createPopup", new(ipAddresses.CreatePopupAction)).

View File

@@ -20,7 +20,7 @@ func (this *CreateAction) Init() {
func (this *CreateAction) RunGet(params struct{}) {
// 所有集群
resp, err := this.RPC().NodeClusterRPC().FindAllEnabledClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
resp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
}

View File

@@ -71,7 +71,7 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
// TABBAR
selectedTabbar, _ := action.Data["mainTab"]
tabbar := actionutils.NewTabbar()
tabbar.Add("当前:"+serverConfig.Name, "", "/servers", "left long alternate arrow", false)
tabbar.Add("当前服务"+serverConfig.Name, "", "/servers", "left long alternate arrow", false)
tabbar.Add("看板", "", "/servers/server/board?serverId="+serverIdString, "dashboard", selectedTabbar == "board")
tabbar.Add("日志", "", "/servers/server/log?serverId="+serverIdString, "history", selectedTabbar == "log")
tabbar.Add("统计", "", "/servers/server/stat?serverId="+serverIdString, "chart area", selectedTabbar == "stat")