diff --git a/server/config.yml.templete b/server/config.yml.templete index a5fe693ecb61cf88d35f27feca77de52bc4fda12..6fc471b0bc14df4e249ccf485006fb219fb8f443 100644 --- a/server/config.yml.templete +++ b/server/config.yml.templete @@ -5,8 +5,6 @@ prometheus_server: addr: "localhost:9090" http_server: addr: "localhost:8090" -pilotgo_server: - addr: "0.0.0.0:8888" log: level: debug driver: file #可选stdout和file。stdout:输出到终端控制台;file:输出到path下的指定文件。 diff --git a/server/config/config.go b/server/config/config.go index 1f61ab334ba6653e6fb8739e9d45dd32bbc8fe81..d51b65344b1304e3a8981ec7adf7e995f4416eba 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -34,7 +34,6 @@ type ServerConfig struct { PluginPrometheus *PluginPrometheus `yaml:"plugin_prometheus"` PrometheusServer *PrometheusServer `yaml:"prometheus_server"` HttpServer *HttpServer `yaml:"http_server"` - PilotGoServer *PilotGoServer `yaml:"pilotgo_server"` Logopts *logger.LogOpts `yaml:"log"` Mysql *MysqlDBInfo `yaml:"mysql"` } diff --git a/server/go.mod b/server/go.mod index 7367f3a8695b95bc7205c6b285f725ff3cbfeacd..d7bc47df0247a171fc17897591220a8ee2d541ff 100644 --- a/server/go.mod +++ b/server/go.mod @@ -16,7 +16,7 @@ require ( ) require ( - gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110131016-eda5d89f4a35 + gitee.com/openeuler/PilotGo/sdk v0.0.0-20231114113407-d762078e13db github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/gin-contrib/sse v0.1.0 // indirect diff --git a/server/go.sum b/server/go.sum index e54135fbaaefe1829efd7e50b34772dbb216a2a8..67b79e08f435d72be0625307c614f1198cf3a9f7 100644 --- a/server/go.sum +++ b/server/go.sum @@ -2,6 +2,8 @@ gitee.com/openeuler/PilotGo/sdk v0.0.0-20231023070842-ceefaa7dc2bd h1:npQZQQJ9vi gitee.com/openeuler/PilotGo/sdk v0.0.0-20231023070842-ceefaa7dc2bd/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110131016-eda5d89f4a35 h1:Lcp6rAHmRuq65iU2paz6w7k55mYT7n+3N4Lqa+xxlOg= gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110131016-eda5d89f4a35/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20231114113407-d762078e13db h1:Mh5VnWRGJFI33V5Acx0tilefUKvLhjbXU2QBnBRjgFY= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20231114113407-d762078e13db/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= diff --git a/server/main.go b/server/main.go index 50e38ffb6f80ac2bc6200a0c40cc6fbd86928d0c..92f28879e4ee919f89a834acf00fc0ab9eb5c6ea 100644 --- a/server/main.go +++ b/server/main.go @@ -40,7 +40,6 @@ func main() { router.RegisterAPIs(server) router.StaticRouter(server) service.GetTags() //pilotgo机器列表tag标签 - plugin.Client.Server = config.Config().PilotGoServer.Addr if err := server.Run(config.Config().HttpServer.Addr); err != nil { logger.Fatal("failed to run server: %v", err) diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go index 3de8b6df3ab7376c9dfe70f7bbbd7bd155616261..c35c46054a03d0853a519bd3ed67893c24133717 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go @@ -8,9 +8,11 @@ import ( type GetTagsCallback func([]string) []common.Tag type Client struct { - Server string PluginInfo *PluginInfo + // 远程PilotGo server地址 + server string + // 用于event消息处理 eventChan chan *common.EventMessage eventCallbackMap map[int]EventCallback @@ -46,6 +48,10 @@ func GetClient() *Client { return global_client } +func (client *Client) Server() string { + return client.server +} + // RegisterHandlers 注册一些插件标准的API接口,清单如下: // GET /plugin_manage/info func (client *Client) RegisterHandlers(router *gin.Engine) { @@ -55,6 +61,8 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { }) { mg.GET("/info", InfoHandler) + // 绑定PilotGo server + mg.PUT("/bind", BindHandler) } api := router.Group("/plugin_manage/api/v1/") diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go index cf87dbce49a9644e47e9824f23b3e0dda1770d9f..35dcdfd5ebb4cb8f6d99b63ec377f666f046c377 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go @@ -9,7 +9,7 @@ import ( ) func (c *Client) ApplyConfig(batch *common.Batch, path, content string) error { - url := c.Server + "/api/v1/pluginapi/apply_config" + url := c.Server() + "/api/v1/pluginapi/apply_config" r, err := httputils.Put(url, nil) if err != nil { return err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go index 6ad1ef727c08e7f925a4e6593b480c058a3593a4..4ec5f1b73fb3fbccd27662547302449161743400 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go @@ -20,7 +20,7 @@ func (c *Client) ListenEvent(eventTypes []int, callbacks []EventCallback) error eventtypes = append(eventtypes, strconv.Itoa(i)) } - url := c.Server + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") + url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") r, err := httputils.Put(url, &httputils.Params{ Body: c.PluginInfo, }) @@ -59,7 +59,7 @@ func (c *Client) UnListenEvent(eventTypes []int) error { eventtypes = append(eventtypes, strconv.Itoa(i)) } - url := c.Server + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") + url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") r, err := httputils.Delete(url, &httputils.Params{ Body: c.PluginInfo, }) @@ -94,7 +94,7 @@ func (c *Client) UnListenEvent(eventTypes []int) error { // 发布event事件 func (c *Client) PublishEvent(msg common.EventMessage) error { - url := c.Server + "/api/v1/pluginapi/publish_event" + url := c.Server() + "/api/v1/pluginapi/publish_event" r, err := httputils.Put(url, &httputils.Params{ Body: &msg, }) diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go index 3cd47e8186c22d32da25adfcb212cf29b6d49399..b72388df6fea8e74327b718d4ac9ebacb2247d9f 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go @@ -53,6 +53,22 @@ func InfoHandler(c *gin.Context) { c.JSON(http.StatusOK, info) } +func BindHandler(c *gin.Context) { + v, ok := c.Get("__internal__client_instance") + if !ok { + response.Fail(c, gin.H{"status": false}, "未获取到client值信息") + return + } + client, ok := v.(*Client) + if !ok { + response.Fail(c, gin.H{"status": false}, "client信息错误") + return + } + client.server = c.Request.RemoteAddr + + response.Success(c, nil, "bind server success") +} + func EventHandler(c *gin.Context) { j, err := io.ReadAll(c.Request.Body) // 接收数据 if err != nil { diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go index 64bcdb54831935212e24b5cabba52cdd00d991ac..6e7fce91f67b5a977bfdd1e396f4b8e42eed6a08 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go @@ -8,7 +8,7 @@ import ( ) func (c *Client) MachineList() ([]*common.MachineNode, error) { - url := "http://" + c.Server + "/api/v1/pluginapi/machine_list" + url := "http://" + c.Server() + "/api/v1/pluginapi/machine_list" r, err := httputils.Get(url, nil) if err != nil { return nil, err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go index 31c10e16e77ddd90eb833b5f29f37369266ec129..b3a9f50d7c7edd93ecae05fd333549f2cb9f0792 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go @@ -26,7 +26,7 @@ type PluginFullInfo struct { } func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { - url := c.Server + "/api/v1/pluginapi/plugins" + url := c.Server() + "/api/v1/pluginapi/plugins" r, err := httputils.Get(url, nil) if err != nil { return nil, err diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go index 2b1038f9d304b856ef9430b6426fbce87a7b11f5..1477090acc7a6aa4514b0a0b8f9a785ed431e972 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go @@ -16,7 +16,7 @@ type CallbackHandler struct { type RunCommandCallback func([]*common.RunResult) func (c *Client) RunCommand(batch *common.Batch, cmd string) ([]*common.CmdResult, error) { - url := "http://" + c.Server + "/api/v1/pluginapi/run_command" + url := "http://" + c.Server() + "/api/v1/pluginapi/run_command" p := &common.CmdStruct{ Batch: batch, @@ -49,7 +49,7 @@ type ScriptStruct struct { } func (c *Client) RunScript(batch *common.Batch, script string, params []string) ([]*common.CmdResult, error) { - url := "http://" + c.Server + "/api/v1/pluginapi/run_script" + url := "http://" + c.Server() + "/api/v1/pluginapi/run_script" p := &ScriptStruct{ Batch: batch, @@ -77,7 +77,7 @@ func (c *Client) RunScript(batch *common.Batch, script string, params []string) } func (c *Client) RunCommandAsync(batch *common.Batch, cmd string, callback RunCommandCallback) error { - url := "http://" + c.Server + "/api/v1/pluginapi/run_command_async?plugin_name=" + c.PluginInfo.Name + url := "http://" + c.Server() + "/api/v1/pluginapi/run_command_async?plugin_name=" + c.PluginInfo.Name p := &common.CmdStruct{ Batch: batch, diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go index 2913507352d7ecb825ee2deab1f3f2cbbc426988..b9a9cbfe1ada9ebcc11adda2da5e4f5538fadaf9 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go @@ -8,7 +8,7 @@ import ( ) func (c *Client) ServiceStatus(batch *common.Batch, servicename string) ([]*common.ServiceResult, error) { - url := c.Server + "/api/v1/pluginapi/service/:name" + url := c.Server() + "/api/v1/pluginapi/service/:name" p := &common.ServiceStruct{ Batch: batch, @@ -31,7 +31,7 @@ func (c *Client) ServiceStatus(batch *common.Batch, servicename string) ([]*comm } func (c *Client) StartService(batch *common.Batch, serviceName string) ([]*common.ServiceResult, error) { - url := c.Server + "/api/v1/pluginapi/start_service" + url := c.Server() + "/api/v1/pluginapi/start_service" p := &common.ServiceStruct{ Batch: batch, @@ -54,7 +54,7 @@ func (c *Client) StartService(batch *common.Batch, serviceName string) ([]*commo } func (c *Client) StopService(batch *common.Batch, serviceName string) ([]*common.ServiceResult, error) { - url := c.Server + "/api/v1/pluginapi/stop_service" + url := c.Server() + "/api/v1/pluginapi/stop_service" p := &common.ServiceStruct{ Batch: batch, diff --git a/server/vendor/modules.txt b/server/vendor/modules.txt index 55b373685907bf014c90e1087c1f88fcff54c897..b14208793cd63aa79a07581de9f8890ab07e5e8d 100644 --- a/server/vendor/modules.txt +++ b/server/vendor/modules.txt @@ -1,4 +1,4 @@ -# gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110131016-eda5d89f4a35 +# gitee.com/openeuler/PilotGo/sdk v0.0.0-20231114113407-d762078e13db ## explicit; go 1.17 gitee.com/openeuler/PilotGo/sdk/common gitee.com/openeuler/PilotGo/sdk/logger