2020-10-09 12:03:32 +08:00
|
|
|
package clusters
|
2020-08-21 12:32:16 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
2020-10-09 12:03:32 +08:00
|
|
|
"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
|
|
|
// 同步集群
|
2020-10-09 12:03:32 +08:00
|
|
|
type SyncAction struct {
|
2020-08-21 12:32:16 +08:00
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-09 12:03:32 +08:00
|
|
|
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
|
|
|
|
|
}
|
2020-10-09 12:03:32 +08:00
|
|
|
|
|
|
|
|
// 发送通知
|
|
|
|
|
_, 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()
|
|
|
|
|
}
|