From 393423dd9c2503d440bd7ad82361259b50868696 Mon Sep 17 00:00:00 2001 From: wubijie Date: Wed, 27 Dec 2023 15:58:40 +0800 Subject: [PATCH] update vendor add extentions test and update vendor --- server/go.mod | 2 +- server/go.sum | 22 +----- server/main.go | 14 ---- .../openeuler/PilotGo/sdk/common/extention.go | 77 ++++++++++++++++++- .../openeuler/PilotGo/sdk/common/machine.go | 13 ++-- .../openeuler/PilotGo/sdk/common/script.go | 6 +- .../PilotGo/sdk/plugin/client/bindsync.go | 15 ++++ .../PilotGo/sdk/plugin/client/client.go | 32 ++++++-- .../PilotGo/sdk/plugin/client/config.go | 3 + .../PilotGo/sdk/plugin/client/extention.go | 4 +- .../PilotGo/sdk/plugin/client/handler.go | 22 ++++-- .../PilotGo/sdk/plugin/client/heartbeat.go | 8 +- .../PilotGo/sdk/plugin/client/machine.go | 4 + .../PilotGo/sdk/plugin/client/plugin.go | 6 +- .../PilotGo/sdk/plugin/client/script.go | 13 +++- .../PilotGo/sdk/plugin/client/service.go | 10 +++ server/vendor/modules.txt | 2 +- 17 files changed, 180 insertions(+), 73 deletions(-) create mode 100644 server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go diff --git a/server/go.mod b/server/go.mod index 180492e..4afefa5 100644 --- a/server/go.mod +++ b/server/go.mod @@ -3,7 +3,7 @@ module openeuler.org/PilotGo/redis-plugin go 1.20 require ( - gitee.com/openeuler/PilotGo/sdk v0.0.0-20231220070046-4f5d0a39b48f + gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f github.com/gin-gonic/gin v1.9.1 gopkg.in/yaml.v2 v2.4.0 gorm.io/driver/mysql v1.5.2 diff --git a/server/go.sum b/server/go.sum index 1931123..c3c0769 100644 --- a/server/go.sum +++ b/server/go.sum @@ -36,26 +36,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231019072242-b911c9979e39 h1:UV9/VLrs4pvuu0nVVelFXSrd/75U1+0bZ/SCqxMfL2Y= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231019072242-b911c9979e39/go.mod h1:iPlzp8pa9YCXF8oPwFw/QfqP8btwunhv+dnMd8y8KeU= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231106070541-1f96eb7967c2 h1:MWXqe0NFzw55TGRTl9E8fm4OeTCzoCd/W1IEJOT4lQ8= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231106070541-1f96eb7967c2/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231107034041-5710927e351e h1:Opeo2MOq6+MSL0lCwQkKpBtmsgfPgywtcYyJTIDeEns= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231107034041-5710927e351e/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231109024612-b4f4c12d9f24 h1:kqNxXxF3a4DJNqsp20WGTQN7VUIRtlL3aLUIuspk0sI= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231109024612-b4f4c12d9f24/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110012917-3eceb3662098 h1:OYoBm/IlipXyqzRztzOq9YNsLbuV8AsY0viV2xpPsik= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110012917-3eceb3662098/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110025008-81b873fcc950 h1:QhlDZUlfuazNlKFnRdG861oNn+sM3Xts/jEyrpeLeyI= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110025008-81b873fcc950/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110031525-bf462264e481 h1:ed0p10IBLpakMIi4POcoRY3uI3OlUTRfcAUHLJxCjUA= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231110031525-bf462264e481/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231130015721-7961ff6790fc h1:37ad5xTtVIQ5aR6JWMuxL0mJD+/EIeB9RWmcjV7B+f8= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231130015721-7961ff6790fc/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231130032403-02364be090ab h1:0IqUG+S8pNDjMRnhtxAjuSu2yyotEWc+mKhLpPWSJLU= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231130032403-02364be090ab/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231220070046-4f5d0a39b48f h1:M7KYvKHAYLFNcA6VlVh8eMzu40hde/cgB/qOjexzi/w= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20231220070046-4f5d0a39b48f/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f h1:DGwrH8ikENblWnxpTdF21OuQKcN3I4uLkp4oKi2nbuw= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f/go.mod h1:zEVmY3l48/CvR2kIM3DJpD/jWTG1qkOxRoHJii/D0us= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= diff --git a/server/main.go b/server/main.go index 3f01789..4f86d5a 100644 --- a/server/main.go +++ b/server/main.go @@ -4,7 +4,6 @@ import ( "fmt" "os" - "gitee.com/openeuler/PilotGo/sdk/common" "gitee.com/openeuler/PilotGo/sdk/logger" "gitee.com/openeuler/PilotGo/sdk/plugin/client" "openeuler.org/PilotGo/redis-plugin/config" @@ -41,19 +40,6 @@ func main() { server := router.InitRouter() global.GlobalClient = client.DefaultClient(plugin.Init(config.Config().PluginRedis, config.Config().RedisServer)) - global.GlobalClient.OnGetTags(func(uuids []string) []common.Tag { - var tags []common.Tag - for _, uuid := range uuids { - tag := common.Tag{ - UUID: uuid, - Type: "1", - Data: "lable", - } - tags = append(tags, tag) - } - return tags - }) - go router.RegisterAPIs(server) if err := server.Run(config.Config().HttpServer.Addr); err != nil { logger.Error("failed to run server: %s", err) diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go index 8f6d040..fa182ca 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go @@ -5,11 +5,84 @@ const ( ExtentionMachine = "machine" // 批处理扩展,增加选择批次时对批次的操作 ExtentionBatch = "batch" + // 主页面扩展,增加侧边栏入口及主页面 + ExtentionPage = "page" ) -type Extention struct { - PluginName string `json:"plugin_name"` +type Extention interface { + Clone() Extention +} + +type MachineExtention struct { + Type string `json:"type"` Name string `json:"name"` + URL string `json:"url"` + Permission string `json:"permission"` +} + +type BatchExtention struct { + Type string `json:"type"` + Name string `json:"name"` + URL string `json:"url"` + Permission string `json:"permission"` +} + +type PageExtention struct { Type string `json:"type"` + Name string `json:"name"` + IsIndex bool `json:"is_index"` URL string `json:"url"` + Permission string `json:"permission"` +} + +func (me *MachineExtention) Clone() Extention { + result := *me + return &result +} + +func (be *BatchExtention) Clone() Extention { + result := *be + return &result +} + +func (pe *PageExtention) Clone() Extention { + result := *pe + return &result +} + +// 解析extentions参数 +func ParseParameters(data []map[string]interface{}) []Extention { + var extentions []Extention + for _, v := range data { + switch v["type"] { + case ExtentionMachine: + me := &MachineExtention{ + Name: v["name"].(string), + URL: v["url"].(string), + Permission: v["permission"].(string), + Type: v["type"].(string), + } + extentions = append(extentions, me) + + case ExtentionBatch: + be := &BatchExtention{ + Name: v["name"].(string), + URL: v["url"].(string), + Permission: v["permission"].(string), + Type: v["type"].(string), + } + extentions = append(extentions, be) + + case ExtentionPage: + pe := &PageExtention{ + Name: v["name"].(string), + URL: v["url"].(string), + Permission: v["permission"].(string), + Type: v["type"].(string), + IsIndex: v["is_index"].(bool), + } + extentions = append(extentions, pe) + } + } + return extentions } diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go index e194752..33ef060 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go @@ -1,12 +1,13 @@ package common type MachineNode struct { - UUID string `json:"uuid"` - Department string `json:"department"` - IP string `json:"ip"` - CPUArch string `json:"cpu_arch"` - OS string `json:"os"` - State int `json:"state"` + UUID string `json:"uuid"` + Department string `json:"department"` + IP string `json:"ip"` + CPUArch string `json:"cpu_arch"` + OS string `json:"os"` + RunStatus string `json:"runstatus"` + MaintStatus string `json:"maintatatus"` } type Batch struct { diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go index 46a5312..8c61445 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go @@ -2,13 +2,9 @@ package common type AsyncCmdResult struct { TaskID string `json:"task_id"` - Result []*RunResult `json:"result"` + Result []*CmdResult `json:"result"` } -type RunResult struct { - CmdResult CmdResult `json:"cmd_result"` - Error interface{} `json:"error"` -} type CmdResult struct { MachineUUID string `json:"machine_uuid"` MachineIP string `json:"machine_ip"` diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go new file mode 100644 index 0000000..f73f97c --- /dev/null +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go @@ -0,0 +1,15 @@ +package client + +import ( + "gitee.com/openeuler/PilotGo/sdk/logger" +) + +func (c *Client) Wait4Bind() { + c.cond.L.Lock() + logger.Debug("等待bind中...") + for c.server == "" { + c.cond.Wait() // 等待条件变量被通知 + } + c.cond.L.Unlock() + logger.Debug("bind 成功!") +} 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 850f0d5..fb02875 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 @@ -1,6 +1,8 @@ package client import ( + "sync" + "gitee.com/openeuler/PilotGo/sdk/common" "github.com/gin-gonic/gin" ) @@ -9,6 +11,8 @@ type GetTagsCallback func([]string) []common.Tag type Client struct { PluginInfo *PluginInfo + // 并发锁 + l sync.Mutex // 远程PilotGo server地址 server string @@ -25,7 +29,11 @@ type Client struct { getTagsCallback GetTagsCallback // 用于平台扩展点功能 - extentions []*common.Extention + extentions []common.Extention + + //bind阻塞功能支持 + mu sync.Mutex + cond *sync.Cond } var global_client *Client @@ -40,6 +48,7 @@ func DefaultClient(desc *PluginInfo) *Client { asyncCmdResultChan: make(chan *common.AsyncCmdResult, 20), cmdProcessorCallbackMap: make(map[string]CallbackHandler), } + global_client.cond = sync.NewCond(&global_client.mu) return global_client } @@ -60,28 +69,28 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { c.Set("__internal__client_instance", client) }) { - mg.GET("/info", InfoHandler) + mg.GET("/info", infoHandler) // 绑定PilotGo server - mg.PUT("/bind", BindHandler) + mg.PUT("/bind", bindHandler) } api := router.Group("/plugin_manage/api/v1/") { api.GET("/extentions", func(c *gin.Context) { c.Set("__internal__client_instance", client) - }, ExtentionsHandler) + }, extentionsHandler) api.GET("/gettags", func(c *gin.Context) { c.Set("__internal__client_instance", client) - }, TagsHandler) + }, tagsHandler) api.POST("/event", func(c *gin.Context) { c.Set("__internal__client_instance", client) - }, EventHandler) + }, eventHandler) api.PUT("/command_result", func(c *gin.Context) { c.Set("__internal__client_instance", client) - }, CommandResultHandler) + }, commandResultHandler) } // pg := router.Group("/plugin/" + desc.Name) @@ -95,9 +104,16 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { // TODO: start command result process service client.startEventProcessor() client.startCommandResultProcessor() - client.SendHeartbeat() } func (client *Client) OnGetTags(callback GetTagsCallback) { client.getTagsCallback = callback } + +// client是否bind PilotGo server +func (client *Client) IsBind() bool { + client.l.Lock() + defer client.l.Unlock() + + return !(client.server == "") +} 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 35dcdfd..a23122e 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,6 +9,9 @@ import ( ) func (c *Client) ApplyConfig(batch *common.Batch, path, content string) error { + if !c.IsBind() { + return errors.New("unbind PilotGo-server platform") + } url := c.Server() + "/api/v1/pluginapi/apply_config" r, err := httputils.Put(url, nil) if err != nil { diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go index 4460e21..a0d233e 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go @@ -4,6 +4,6 @@ import ( "gitee.com/openeuler/PilotGo/sdk/common" ) -func (c *Client) RegisterExtention(exts []*common.Extention) { - c.extentions = exts +func (c *Client) RegisterExtention(exts []common.Extention) { + c.extentions = append(c.extentions, exts...) } 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 2ad545b..1438def 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 @@ -33,7 +33,7 @@ func ReverseProxyHandler(c *gin.Context) { proxy.ServeHTTP(c.Writer, c.Request) } -func InfoHandler(c *gin.Context) { +func infoHandler(c *gin.Context) { v, ok := c.Get("__internal__client_instance") if !ok { response.Fail(c, gin.H{"status": false}, "未获取到client值信息") @@ -53,7 +53,7 @@ func InfoHandler(c *gin.Context) { c.JSON(http.StatusOK, info) } -func BindHandler(c *gin.Context) { +func bindHandler(c *gin.Context) { port := c.Query("port") v, ok := c.Get("__internal__client_instance") @@ -66,12 +66,18 @@ func BindHandler(c *gin.Context) { response.Fail(c, gin.H{"status": false}, "client信息错误") return } - client.server = strings.Split(c.Request.RemoteAddr, ":")[0] + ":" + port - + server := strings.Split(c.Request.RemoteAddr, ":")[0] + ":" + port + if client.server == "" { + client.server = server + } else if client.server != "" && client.server != server { + logger.Error("已有PilotGo-server与此插件绑定") + } + client.cond.Broadcast() + client.sendHeartBeat() response.Success(c, nil, "bind server success") } -func EventHandler(c *gin.Context) { +func eventHandler(c *gin.Context) { j, err := io.ReadAll(c.Request.Body) // 接收数据 if err != nil { logger.Error("没获取到:%s", err.Error()) @@ -95,7 +101,7 @@ func EventHandler(c *gin.Context) { client.ProcessEvent(&msg) } -func ExtentionsHandler(c *gin.Context) { +func extentionsHandler(c *gin.Context) { v, ok := c.Get("__internal__client_instance") if !ok { response.Fail(c, gin.H{"status": false}, "未获取到client值信息") @@ -110,7 +116,7 @@ func ExtentionsHandler(c *gin.Context) { response.Success(c, client.extentions, "") } -func CommandResultHandler(c *gin.Context) { +func commandResultHandler(c *gin.Context) { j, err := io.ReadAll(c.Request.Body) // 接收数据 if err != nil { logger.Error("没获取到:%s", err.Error()) @@ -137,7 +143,7 @@ func CommandResultHandler(c *gin.Context) { } -func TagsHandler(c *gin.Context) { +func tagsHandler(c *gin.Context) { j, err := io.ReadAll(c.Request.Body) // 接收数据 if err != nil { logger.Error("没获取到:%s", err.Error()) diff --git a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go index 2c393a1..b0e1697 100644 --- a/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go +++ b/server/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go @@ -21,8 +21,8 @@ type PluginStatus struct { LastConnect time.Time } -func (client *Client) SendHeartbeat() { - clientID := client.PluginInfo.Url + "+" + client.PluginInfo.Name +func (client *Client) sendHeartBeat() { + clientID := client.PluginInfo.Url go func() { for { err := client.sendHeartbeat(clientID) @@ -36,9 +36,9 @@ func (client *Client) SendHeartbeat() { func (client *Client) sendHeartbeat(clientID string) error { p := &struct { - ClientID string `json:"clientID"` + PluginUrl string `json:"clientID"` }{ - ClientID: clientID, + PluginUrl: clientID, } ServerUrl := "http://" + client.Server() + "/api/v1/pluginapi/heartbeat" 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 6e7fce9..34acd4b 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 @@ -2,12 +2,16 @@ package client import ( "encoding/json" + "errors" "gitee.com/openeuler/PilotGo/sdk/common" "gitee.com/openeuler/PilotGo/sdk/utils/httputils" ) func (c *Client) MachineList() ([]*common.MachineNode, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } url := "http://" + c.Server() + "/api/v1/pluginapi/machine_list" r, err := httputils.Get(url, nil) if err != nil { 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 b3a9f50..c009d55 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 @@ -2,6 +2,7 @@ package client import ( "encoding/json" + "errors" "gitee.com/openeuler/PilotGo/sdk/common" "gitee.com/openeuler/PilotGo/sdk/utils/httputils" @@ -22,10 +23,13 @@ type PluginInfo struct { // 用于插件与PilotGo server通讯 type PluginFullInfo struct { PluginInfo - Extentions []*common.Extention + Extentions []common.Extention } func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } url := c.Server() + "/api/v1/pluginapi/plugins" r, err := httputils.Get(url, nil) if err != nil { 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 1477090..5809e5c 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 @@ -3,6 +3,7 @@ package client import ( "encoding/base64" "encoding/json" + "errors" "gitee.com/openeuler/PilotGo/sdk/common" "gitee.com/openeuler/PilotGo/sdk/utils/httputils" @@ -13,9 +14,13 @@ type CallbackHandler struct { TaskLen int } -type RunCommandCallback func([]*common.RunResult) +type RunCommandCallback func([]*common.CmdResult) func (c *Client) RunCommand(batch *common.Batch, cmd string) ([]*common.CmdResult, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } + url := "http://" + c.Server() + "/api/v1/pluginapi/run_command" p := &common.CmdStruct{ @@ -49,6 +54,9 @@ type ScriptStruct struct { } func (c *Client) RunScript(batch *common.Batch, script string, params []string) ([]*common.CmdResult, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } url := "http://" + c.Server() + "/api/v1/pluginapi/run_script" p := &ScriptStruct{ @@ -77,6 +85,9 @@ func (c *Client) RunScript(batch *common.Batch, script string, params []string) } func (c *Client) RunCommandAsync(batch *common.Batch, cmd string, callback RunCommandCallback) error { + if !c.IsBind() { + return errors.New("unbind PilotGo-server platform") + } url := "http://" + c.Server() + "/api/v1/pluginapi/run_command_async?plugin_name=" + c.PluginInfo.Name p := &common.CmdStruct{ 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 b9a9cbf..8790c9a 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 @@ -2,12 +2,16 @@ package client import ( "encoding/json" + "errors" "gitee.com/openeuler/PilotGo/sdk/common" "gitee.com/openeuler/PilotGo/sdk/utils/httputils" ) func (c *Client) ServiceStatus(batch *common.Batch, servicename string) ([]*common.ServiceResult, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } url := c.Server() + "/api/v1/pluginapi/service/:name" p := &common.ServiceStruct{ @@ -31,6 +35,9 @@ func (c *Client) ServiceStatus(batch *common.Batch, servicename string) ([]*comm } func (c *Client) StartService(batch *common.Batch, serviceName string) ([]*common.ServiceResult, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } url := c.Server() + "/api/v1/pluginapi/start_service" p := &common.ServiceStruct{ @@ -54,6 +61,9 @@ func (c *Client) StartService(batch *common.Batch, serviceName string) ([]*commo } func (c *Client) StopService(batch *common.Batch, serviceName string) ([]*common.ServiceResult, error) { + if !c.IsBind() { + return nil, errors.New("unbind PilotGo-server platform") + } url := c.Server() + "/api/v1/pluginapi/stop_service" p := &common.ServiceStruct{ diff --git a/server/vendor/modules.txt b/server/vendor/modules.txt index 10e3df2..7c9678b 100644 --- a/server/vendor/modules.txt +++ b/server/vendor/modules.txt @@ -1,4 +1,4 @@ -# gitee.com/openeuler/PilotGo/sdk v0.0.0-20231220070046-4f5d0a39b48f +# gitee.com/openeuler/PilotGo/sdk v0.0.0-20240110060359-307cb097716f ## explicit; go 1.17 gitee.com/openeuler/PilotGo/sdk/common gitee.com/openeuler/PilotGo/sdk/logger -- Gitee