配置更新时立即向集群节点发消息

This commit is contained in:
刘祥超
2020-10-09 12:03:32 +08:00
parent 37130d2e23
commit 6a3374e5ff
13 changed files with 36 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
package common
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
@@ -8,15 +8,15 @@ import (
)
// 检查变更的集群列表
type ChangedClustersAction struct {
type CheckChangeAction struct {
actionutils.ParentAction
}
func (this *ChangedClustersAction) Init() {
func (this *CheckChangeAction) Init() {
this.Nav("", "", "")
}
func (this *ChangedClustersAction) RunGet(params struct {
func (this *CheckChangeAction) RunPost(params struct {
IsNotifying bool
}) {
timeout := time.NewTimer(55 * time.Second) // 比客户端提前结束,避免在客户端产生一个请求错误

View File

@@ -13,6 +13,8 @@ func init() {
Prefix("/clusters").
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).
Post("/sync", new(SyncAction)).
Post("/checkChange", new(CheckChangeAction)).
EndAll()
})
}

View File

@@ -1,16 +1,18 @@
package common
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 SyncClustersAction struct {
type SyncAction struct {
actionutils.ParentAction
}
func (this *SyncClustersAction) RunPost(params struct{}) {
func (this *SyncAction) RunPost(params struct{}) {
// TODO 将来可以单独选择某一个集群进行单独的同步
// 所有有变化的集群
@@ -29,6 +31,13 @@ func (this *SyncClustersAction) RunPost(params struct{}) {
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

@@ -1,17 +0,0 @@
package common
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(new(helpers.UserMustAuth)).
Prefix("/common").
Get("/changedClusters", new(ChangedClustersAction)).
Post("/syncClusters", new(SyncClustersAction)).
EndAll()
})
}

View File

@@ -97,6 +97,7 @@ func (this *IndexAction) RunGet(params struct{}) {
serverMaps = append(serverMaps, maps.Map{
"id": server.Id,
"isOn": server.IsOn,
"name": server.Name,
"cluster": maps.Map{
"id": server.Cluster.Id,

View File

@@ -6,7 +6,6 @@ import (
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/common"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dashboard"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/db"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/dns"