From 9a2d1afc1920c8e835f068d12101de3d2b40e3b6 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Wed, 7 Jun 2023 15:09:55 +0800 Subject: [PATCH] apply sdk/plugin/client.GetClient() in gala-ops --- gala-ops/server/httphandler/agent.go | 14 +++++++------- gala-ops/server/main.go | 14 +++----------- gala-ops/server/plugin/prometheus.go | 4 ++-- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index 17fe8ef3..00d5b28b 100644 --- a/gala-ops/server/httphandler/agent.go +++ b/gala-ops/server/httphandler/agent.go @@ -9,7 +9,7 @@ import ( "openeuler.org/PilotGo/gala-ops-plugin/plugin" ) -func InstallGopher(ctx *gin.Context, client *client.Client) { +func InstallGopher(ctx *gin.Context) { // TODO param := &struct { Batch []string @@ -22,7 +22,7 @@ func InstallGopher(ctx *gin.Context, client *client.Client) { } cmd := "yum install -y gala-gopher && systemctl start gala-gopher" - cmdResults, err := client.RunScript(param.Batch, cmd) + cmdResults, err := client.GetClient().RunScript(param.Batch, cmd) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ "code": -1, @@ -55,7 +55,7 @@ func InstallGopher(ctx *gin.Context, client *client.Client) { ret = append(ret, d) } - err = plugin.MonitorTargets(monitorTargets, client) + err = plugin.MonitorTargets(monitorTargets) if err != nil { fmt.Println("error: failed to add gala-gopher to prometheus monitor targets") } @@ -67,7 +67,7 @@ func InstallGopher(ctx *gin.Context, client *client.Client) { }) } -func UpgradeGopher(ctx *gin.Context, client *client.Client) { +func UpgradeGopher(ctx *gin.Context) { // TODO param := &struct { Batch []string @@ -80,7 +80,7 @@ func UpgradeGopher(ctx *gin.Context, client *client.Client) { } cmd := "systemctl stop gala-gopher && yum upgrade -y gala-gopher && systemctl start gala-gopher" - cmdResults, err := client.RunScript(param.Batch, cmd) + cmdResults, err := client.GetClient().RunScript(param.Batch, cmd) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ "code": -1, @@ -115,7 +115,7 @@ func UpgradeGopher(ctx *gin.Context, client *client.Client) { }) } -func UninstallGopher(ctx *gin.Context, client *client.Client) { +func UninstallGopher(ctx *gin.Context) { // TODO param := &struct { Batch []string @@ -128,7 +128,7 @@ func UninstallGopher(ctx *gin.Context, client *client.Client) { } cmd := "systemctl stop gala-gopher && yum autoremove -y gala-gopher" - cmdResults, err := client.RunScript(param.Batch, cmd) + cmdResults, err := client.GetClient().RunScript(param.Batch, cmd) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ "code": -1, diff --git a/gala-ops/server/main.go b/gala-ops/server/main.go index 23e0085c..bafdc727 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -14,8 +14,6 @@ import ( const Version = "0.0.1" -var GlobalClient *client.Client - var PluginInfo = &client.PluginInfo{ Name: "gala-ops", Version: Version, @@ -63,14 +61,8 @@ func InitRouter(router *gin.Engine) { // api.PUT("/run_script_result", httphandler.RunScriptResult) // 安装/升级/卸载gala-gopher监控终端 - api.PUT("/install_gopher", func(ctx *gin.Context) { - httphandler.InstallGopher(ctx, GlobalClient) - }) - api.PUT("/upgrade_gopher", func(ctx *gin.Context) { - httphandler.UpgradeGopher(ctx, GlobalClient) - }) - api.DELETE("/uninstall_gopher", func(ctx *gin.Context) { - httphandler.UninstallGopher(ctx, GlobalClient) - }) + api.PUT("/install_gopher", httphandler.InstallGopher) + api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) + api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) } } diff --git a/gala-ops/server/plugin/prometheus.go b/gala-ops/server/plugin/prometheus.go index bb9cf8fb..6dc050fb 100644 --- a/gala-ops/server/plugin/prometheus.go +++ b/gala-ops/server/plugin/prometheus.go @@ -11,8 +11,8 @@ func addTargets(targets []string, url string) error { return nil } -func MonitorTargets(targets []string, client *client.Client) error { - plugin, err := client.GetPluginInfo("prometheus") +func MonitorTargets(targets []string) error { + plugin, err := client.GetClient().GetPluginInfo("prometheus") if err != nil { return err } -- Gitee