Files
EdgeAdmin/internal/web/actions/default/clusters/sync.go

45 lines
1.2 KiB
Go
Raw Normal View History

package clusters
2020-08-21 12:32:16 +08:00
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"
2020-09-26 08:07:18 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
2020-08-21 12:32:16 +08:00
)
2020-09-26 08:07:18 +08:00
// 同步集群
type SyncAction struct {
2020-08-21 12:32:16 +08:00
actionutils.ParentAction
}
func (this *SyncAction) RunPost(params struct{}) {
2020-08-21 12:32:16 +08:00
// TODO 将来可以单独选择某一个集群进行单独的同步
// 所有有变化的集群
2020-09-06 16:19:34 +08:00
clustersResp, err := this.RPC().NodeClusterRPC().FindAllChangedNodeClusters(this.AdminContext(), &pb.FindAllChangedNodeClustersRequest{})
2020-08-21 12:32:16 +08:00
if err != nil {
this.ErrorPage(err)
return
}
clusters := clustersResp.Clusters
for _, cluster := range clusters {
_, err := this.RPC().NodeRPC().SyncNodesVersionWithCluster(this.AdminContext(), &pb.SyncNodesVersionWithClusterRequest{
ClusterId: 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
}
2020-08-21 12:32:16 +08:00
}
this.Success()
}