增加节点同步状态提示和任务列表

This commit is contained in:
刘祥超
2021-01-17 16:47:29 +08:00
parent a79d375f4e
commit f7054c69e9
23 changed files with 557 additions and 245 deletions

View File

@@ -1,37 +0,0 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
// 检查变更的集群列表
type CheckChangeAction struct {
actionutils.ParentAction
}
func (this *CheckChangeAction) Init() {
this.Nav("", "", "")
}
func (this *CheckChangeAction) RunPost(params struct {
IsNotifying bool
}) {
resp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
result := []maps.Map{}
for _, cluster := range resp.NodeClusters {
result = append(result, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
this.Data["clusters"] = result
this.Success()
}

View File

@@ -15,14 +15,12 @@ func init() {
Prefix("/clusters").
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).
Post("/sync", new(SyncAction)).
Post("/checkChange", new(CheckChangeAction)).
// 只要登录即可访问的Action
EndHelpers().
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeCommon)).
Post("/options", new(OptionsAction)).
EndAll()
})
}

View File

@@ -1,44 +0,0 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/nodeutils"
"github.com/TeaOSLab/EdgeCommon/pkg/messageconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
// 同步集群
type SyncAction struct {
actionutils.ParentAction
}
func (this *SyncAction) RunPost(params struct{}) {
// TODO 将来可以单独选择某一个集群进行单独的同步
// 所有有变化的集群
clustersResp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
clusters := clustersResp.NodeClusters
for _, cluster := range clusters {
_, err := this.RPC().NodeRPC().SyncNodesVersionWithCluster(this.AdminContext(), &pb.SyncNodesVersionWithClusterRequest{
NodeClusterId: cluster.Id,
})
if err != nil {
this.ErrorPage(err)
return
}
// 发送通知
_, err = nodeutils.SendMessageToCluster(this.AdminContext(), cluster.Id, messageconfigs.MessageCodeConfigChanged, &messageconfigs.ConfigChangedMessage{}, 10)
if err != nil {
this.ErrorPage(err)
return
}
}
this.Success()
}

View File

@@ -0,0 +1,23 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type CheckAction struct {
actionutils.ParentAction
}
func (this *CheckAction) RunPost(params struct{}) {
resp, err := this.RPC().NodeTaskRPC().ExistsNodeTasks(this.AdminContext(), &pb.ExistsNodeTasksRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["isDoing"] = resp.ExistTasks
this.Data["hasError"] = resp.ExistError
this.Success()
}

View File

@@ -0,0 +1,24 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
TaskId int64
}) {
defer this.CreateLogInfo("删除同步任务 %d", params.TaskId)
_, err := this.RPC().NodeTaskRPC().DeleteNodeTask(this.AdminContext(), &pb.DeleteNodeTaskRequest{NodeTaskId: params.TaskId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,22 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"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(configloaders.AdminModuleCodeNode)).
Helper(clusterutils.NewClustersHelper()).
Prefix("/clusters/tasks").
GetPost("/listPopup", new(ListPopupAction)).
Post("/check", new(CheckAction)).
Post("/delete", new(DeleteAction)).
EndAll()
})
}

View File

@@ -0,0 +1,67 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type ListPopupAction struct {
actionutils.ParentAction
}
func (this *ListPopupAction) Init() {
this.Nav("", "", "")
}
func (this *ListPopupAction) RunGet(params struct{}) {
this.retrieveTasks()
this.Show()
}
func (this *ListPopupAction) RunPost(params struct {
Must *actions.Must
}) {
this.retrieveTasks()
this.Success()
}
func (this *ListPopupAction) retrieveTasks() {
resp, err := this.RPC().NodeTaskRPC().FindNodeClusterTasks(this.AdminContext(), &pb.FindNodeClusterTasksRequest{})
if err != nil {
this.ErrorPage(err)
return
}
countTasks := 0
clusterMaps := []maps.Map{}
for _, cluster := range resp.ClusterTasks {
taskMaps := []maps.Map{}
for _, task := range cluster.NodeTasks {
countTasks++
taskMaps = append(taskMaps, maps.Map{
"id": task.Id,
"type": task.Type,
"node": maps.Map{
"id": task.Node.Id,
"name": task.Node.Name,
},
"isOk": task.IsOk,
"error": task.Error,
"isDone": task.IsDone,
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", task.UpdatedAt),
})
}
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.ClusterId,
"name": cluster.ClusterName,
"tasks": taskMaps,
})
}
this.Data["clusters"] = clusterMaps
this.Data["countTasks"] = countTasks
}