diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index 17fe8ef350c2d7e750ab566ff6f4cbec3876f560..00d5b28b344b0a64e6666f5ecd4a7c023df2017a 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 23e0085c73486e25cdcbfc69f7f48c738498e6a9..bafdc727cfa6cd4df04084b5a26f92568f6cb654 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 bb9cf8fbb11c2096819cbd913cfb36c2d8393f74..6dc050fb4be63012511619f24fe5b1da71a59656 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 }