mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-16 05:36:36 +08:00
实现健康检查配置、立即执行健康检查
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type HealthAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *HealthAction) Init() {
|
||||
this.Nav("", "setting", "")
|
||||
this.SecondMenu("health")
|
||||
}
|
||||
|
||||
func (this *HealthAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
}) {
|
||||
configResp, err := this.RPC().NodeClusterRPC().FindNodeClusterHealthCheckConfig(this.AdminContext(), &pb.FindNodeClusterHealthCheckConfigRequest{ClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var config *serverconfigs.HealthCheckConfig = nil
|
||||
if len(configResp.HealthCheckConfig) > 0 {
|
||||
config = &serverconfigs.HealthCheckConfig{}
|
||||
err = json.Unmarshal(configResp.HealthCheckConfig, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["healthCheckConfig"] = config
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *HealthAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
HealthCheckJSON []byte
|
||||
Must *actions.Must
|
||||
}) {
|
||||
config := &serverconfigs.HealthCheckConfig{}
|
||||
err := json.Unmarshal(params.HealthCheckJSON, config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().NodeClusterRPC().UpdateNodeClusterHealthCheck(this.AdminContext(), &pb.UpdateNodeClusterHealthCheckRequest{
|
||||
ClusterId: params.ClusterId,
|
||||
HealthCheckJSON: params.HealthCheckJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type HealthRunAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *HealthRunAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *HealthRunAction) RunGet(params struct{}) {
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *HealthRunAction) RunPost(params struct {
|
||||
ClusterId int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
resp, err := this.RPC().NodeClusterRPC().ExecuteNodeClusterHealthCheck(this.AdminContext(), &pb.ExecuteNodeClusterHealthCheckRequest{ClusterId: params.ClusterId})
|
||||
if err != nil {
|
||||
this.Fail(err.Error())
|
||||
}
|
||||
|
||||
this.Data["results"] = resp.Results
|
||||
this.Success()
|
||||
}
|
||||
@@ -13,6 +13,8 @@ func init() {
|
||||
Helper(clusters.NewClusterHelper()).
|
||||
Prefix("/clusters/cluster/settings").
|
||||
GetPost("", new(IndexAction)).
|
||||
GetPost("/health", new(HealthAction)).
|
||||
GetPost("/healthRun", new(HealthRunAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user