From d3bf9c97659f0608c2408249a06ad5f3a264c815 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Tue, 21 Jan 2025 15:23:35 +0800 Subject: [PATCH] update sdk --- cmd/server/agentmanager/PAgentMap.go | 2 +- cmd/server/main.go | 2 +- cmd/server/pluginclient/meta.go | 4 +- go.mod | 2 +- go.sum | 8 +- .../openeuler/PilotGo/sdk/common/common.go | 45 +++++ .../openeuler/PilotGo/sdk/common/event.go | 61 ------- .../openeuler/PilotGo/sdk/common/extention.go | 7 + .../openeuler/PilotGo/sdk/common/machine.go | 7 + .../PilotGo/sdk/common/permission.go | 7 + .../openeuler/PilotGo/sdk/common/script.go | 7 + .../openeuler/PilotGo/sdk/common/service.go | 135 +++++++-------- .../openeuler/PilotGo/sdk/common/status.go | 7 + .../openeuler/PilotGo/sdk/common/tag.go | 7 + .../openeuler/PilotGo/sdk/logger/logger.go | 85 +++++----- .../PilotGo/sdk/plugin/client/batch.go | 7 + .../PilotGo/sdk/plugin/client/bindsync.go | 7 + .../PilotGo/sdk/plugin/client/client.go | 21 ++- .../PilotGo/sdk/plugin/client/config.go | 7 + .../PilotGo/sdk/plugin/client/event.go | 160 ------------------ .../PilotGo/sdk/plugin/client/extention.go | 7 + .../PilotGo/sdk/plugin/client/fileservice.go | 7 + .../PilotGo/sdk/plugin/client/handler.go | 31 +--- .../PilotGo/sdk/plugin/client/heartbeat.go | 7 + .../PilotGo/sdk/plugin/client/machine.go | 7 + .../PilotGo/sdk/plugin/client/permission.go | 7 + .../PilotGo/sdk/plugin/client/plugin.go | 22 ++- .../PilotGo/sdk/plugin/client/script.go | 7 + .../PilotGo/sdk/plugin/client/service.go | 7 + .../PilotGo/sdk/response/response.go | 46 +++++ .../sdk/utils/httputils/judgeProtocol.go | 7 + .../PilotGo/sdk/utils/httputils/request.go | 7 + vendor/modules.txt | 2 +- web/vite.config.ts | 14 +- 34 files changed, 381 insertions(+), 385 deletions(-) create mode 100644 vendor/gitee.com/openeuler/PilotGo/sdk/common/common.go delete mode 100644 vendor/gitee.com/openeuler/PilotGo/sdk/common/event.go delete mode 100644 vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go diff --git a/cmd/server/agentmanager/PAgentMap.go b/cmd/server/agentmanager/PAgentMap.go index b1e1a86..0bcb14c 100644 --- a/cmd/server/agentmanager/PAgentMap.go +++ b/cmd/server/agentmanager/PAgentMap.go @@ -68,7 +68,7 @@ func (am *AgentManager) InitMachineList() { machine_list, err := pluginclient.Global_Client.MachineList() if err != nil { - err = errors.Errorf(err.Error()) + err = errors.Errorf("%s", err.Error()) global.ERManager.ErrorTransmit("agentmanager", "error", err, true, true) } diff --git a/cmd/server/main.go b/cmd/server/main.go index 4472a8a..d5cb8de 100755 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -46,7 +46,7 @@ func main() { */ ermanager, err := resourcemanage.CreateErrorReleaseManager(global.RootContext, global.Close) if err != nil { - sdklogger.Fatal(err.Error()) + sdklogger.Fatal("%s", err.Error()) } global.ERManager = ermanager diff --git a/cmd/server/pluginclient/meta.go b/cmd/server/pluginclient/meta.go index 09c9a05..52c9d89 100644 --- a/cmd/server/pluginclient/meta.go +++ b/cmd/server/pluginclient/meta.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: Wangjunqi123 * Date: Mon Nov 4 14:30:13 2024 +0800 @@ -20,5 +20,7 @@ var PluginInfo = &client.PluginInfo{ Author: "wangjunqi", Email: "wangjunqi@kylinos.cn", Url: "", // 远端访问插件服务端的地址 + Icon: "Help", + MenuName: "集群拓扑", PluginType: "micro-app", } diff --git a/go.mod b/go.mod index f6535a6..bc1e205 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitee.com/openeuler/PilotGo-plugin-topology go 1.21 require ( - gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484 + gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8 github.com/fsouza/go-dockerclient v1.11.0 github.com/gin-contrib/timeout v0.0.3 github.com/gin-gonic/gin v1.9.1 diff --git a/go.sum b/go.sum index 5157a6b..041a55e 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484 h1:cb21Q6oVVLH5mCQ7Tb9lWpmpp3ZGYLtX4Y4DvkvgMtw= -gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484/go.mod h1:87giU5v2IkUx78GRfezNBHhDGqzlwhNICOVY+hUYSJM= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8 h1:J6BKrPKKpdkjBwthualuZUTra5qdYR2O62WHWlZBD3k= +gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8/go.mod h1:Et2wSYAR8hj9jMnSqwtyi8fA79q63tLvPcHwySiRG+g= github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8 h1:V8krnnfGj4pV65YLUm3C0/8bl7V5Nry2Pwvy3ru/wLc= github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8/go.mod h1:CzsSbkDixRphAF5hS6wbMKq0eI6ccJRb7/A0M6JBnwg= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= @@ -45,8 +45,8 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= -github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= -github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fsouza/go-dockerclient v1.11.0 h1:4ZAk6W7rPAtPXm7198EFqA5S68rwnNQORxlOA5OurCA= github.com/fsouza/go-dockerclient v1.11.0/go.mod h1:0I3TQCRseuPTzqlY4Y3ajfsg2VAdMQoazrkxJTiJg8s= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/common.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/common.go new file mode 100644 index 0000000..cedd84b --- /dev/null +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/common.go @@ -0,0 +1,45 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Tue Jul 23 15:50:05 2024 +0800 + */ +package common + +import ( + "encoding/json" + "time" +) + +type MessageData struct { + MsgType int `json:"msg_type_id"` + MessageType string `json:"msg_type"` + TimeStamp time.Time `json:"timestamp"` + Data interface{} `json:"data"` +} + +type EventMessage struct { + MessageType int `json:"msgType"` + MessageData string `json:"msgData"` +} + +type EventCallback func(e *EventMessage) + +func (msgData *MessageData) ToMessageDataString() (string, error) { + data, err := json.Marshal(msgData) + if err != nil { + return "", err + } + return string(data), nil +} + +type CommonResult struct { + Code int `json:"code"` + Message string `json:"msg"` + Data json.RawMessage `json:"data"` +} + +func (r *CommonResult) ParseData(d interface{}) error { + return json.Unmarshal(r.Data, d) +} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/event.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/event.go deleted file mode 100644 index df2eca2..0000000 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/event.go +++ /dev/null @@ -1,61 +0,0 @@ -package common - -import "encoding/json" - -// event消息类型定义 -const ( - // 主机安装软件包 - MsgPackageInstall = 0 - // 主机升级软件包 - MsgPackageUpdate = 1 - // 主机卸载软件包 - MsgPackageUninstall = 2 - // 主机ip变更 - MsgIPChange = 3 - - // 平台新增主机 - MsgHostAdd = 10 - // 平台移除主机 - MsgHostRemove = 11 - - // 插件添加 - MsgPluginAdd = 20 - // 插件卸载 - MsgPluginRemove = 21 -) - -type EventMessage struct { - MessageType int - MessageData string -} - -// 将 MessageData json字符串转换成指定结构体的message消息数据 -func ToMessage(d string, s interface{}) error { - return json.Unmarshal([]byte(d), s) -} - -type MDPackageInstall struct { - HostUUID string - Name string - Version string - Time string -} - -type MDPackageUpdate struct { - HostUUID string - Name string - Version string - Time string -} - -type MDPackageUninstall struct { - HostUUID string - Name string - Version string - Time string -} - -type MDIPChange struct { - HostUUID string - NewIP string -} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go index 90fe352..d848919 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/extention.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Gzx1999 + * Date: Tue Nov 7 15:01:17 2023 +0800 + */ package common const ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go index 2a8f7d0..387a6b4 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/machine.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package common type MachineNode struct { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go index ebbc060..7c0313d 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/permission.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Thu Jan 11 20:24:26 2024 +0800 + */ package common type Permission struct { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go index 8c61445..fbf5ae7 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/script.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Gzx1999 + * Date: Wed Oct 11 16:18:11 2023 +0800 + */ package common type AsyncCmdResult struct { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go index 2e9dde0..ac4ad73 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/service.go @@ -1,70 +1,65 @@ -package common - -import "encoding/json" - -const ( - ServiceActiveStatusRunning = "running" - ServiceActiveStatusExited = "exited" - ServiceActiveStatusWaiting = "waiting" - ServiceActiveStatusInactive = "inactive" - ServiceActiveStatusUnknown = "unknown" - - ServiceLoadedStatusEnabled = "enabled" - ServiceLoadedStatusDisabled = "disabled" - ServiceLoadedStatusStatic = "static" - ServiceLoadedStatusMask = "mask" - ServiceLoadedStatusUnknown = "unknown" -) - -const ( - ServiceUnit = "service" - SocketUnit = "socket" - TargetUnit = "target" - MountUnit = "mount" - AutomountUnit = "automount" - PathUnit = "path" - TimeUnit = "time" -) - -type ServiceResult struct { - MachineUUID string - MachineIP string - ServiceSample ServiceInfo -} - -type ServiceInfo struct { - ServiceName string - UnitName string - UnitType string - ServicePath string //配置文件放置的目录 - ServiceAfter string //在什么服务启动后启动 - ServiceBefore string //在什么服务启动前启动 - ServiceRequires string //需要的daemon - ServiceWants string //与requires相反 - ServiceEnvironmentFile string //启动脚本的环境配置文件 - ServiceExectStart string //实际执行daemon的指令或脚本程序 - ServiceActiveStatus string - ServiceLoadedStatus string - StartTime string -} - -type ServiceStruct struct { - Batch *Batch `json:"batch"` - ServiceName string `json:"service"` -} - -type Result struct { - Code int `json:"code"` - Mseeage string `json:"msg"` - Data []*ServiceResult `json:"data"` -} - -type CommonResult struct { - Code int `json:"code"` - Message string `json:"msg"` - Data json.RawMessage `json:"data"` -} - -func (r *CommonResult) ParseData(d interface{}) error { - return json.Unmarshal(r.Data, d) -} +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ +package common + +const ( + ServiceActiveStatusRunning = "running" + ServiceActiveStatusExited = "exited" + ServiceActiveStatusWaiting = "waiting" + ServiceActiveStatusInactive = "inactive" + ServiceActiveStatusUnknown = "unknown" + + ServiceLoadedStatusEnabled = "enabled" + ServiceLoadedStatusDisabled = "disabled" + ServiceLoadedStatusStatic = "static" + ServiceLoadedStatusMask = "mask" + ServiceLoadedStatusUnknown = "unknown" +) + +const ( + ServiceUnit = "service" + SocketUnit = "socket" + TargetUnit = "target" + MountUnit = "mount" + AutomountUnit = "automount" + PathUnit = "path" + TimeUnit = "time" +) + +type ServiceResult struct { + MachineUUID string + MachineIP string + ServiceSample ServiceInfo +} + +type ServiceInfo struct { + ServiceName string + UnitName string + UnitType string + ServicePath string //配置文件放置的目录 + ServiceAfter string //在什么服务启动后启动 + ServiceBefore string //在什么服务启动前启动 + ServiceRequires string //需要的daemon + ServiceWants string //与requires相反 + ServiceEnvironmentFile string //启动脚本的环境配置文件 + ServiceExectStart string //实际执行daemon的指令或脚本程序 + ServiceActiveStatus string + ServiceLoadedStatus string + StartTime string +} + +type ServiceStruct struct { + Batch *Batch `json:"batch"` + ServiceName string `json:"service"` +} + +type Result struct { + Code int `json:"code"` + Mseeage string `json:"msg"` + Data []*ServiceResult `json:"data"` +} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go index 5d0cd8c..2e6cef4 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/status.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ // 提供公共数据结构定义 package common diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go b/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go index dab5e54..5f8de3a 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/common/tag.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Thu Nov 2 16:38:53 2023 +0800 + */ package common const ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go b/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go index 6854d6f..aad3575 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/logger/logger.go @@ -1,17 +1,10 @@ -/****************************************************************************** - * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved. - * PilotGo is licensed under the Mulan PSL v2. - * You can use this software accodring to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - * Author: yangzhao1 - * Date: 2022-03-01 09:59:30 - * LastEditTime: 2022-04-05 11:37:16 - * Description: provide agent log manager of pilotgo - ******************************************************************************/ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package logger import ( @@ -26,7 +19,7 @@ import ( type LogOpts struct { Level string `yaml:"level"` - Driver string `yaml:"driver"` + Driver string `yaml:"driver" comment:"可选stdout和file.stdout:输出到终端控制台;file:输出到path下的指定文件。"` Path string `yaml:"path"` MaxFile int `yaml:"max_file"` MaxSize int `yaml:"max_size"` @@ -120,41 +113,45 @@ func Fatal(format string, args ...interface{}) { logrus.Fatalf(format, args...) } -func RequestLogger() gin.HandlerFunc { +func RequestLogger(_skipPaths []string) gin.HandlerFunc { + var skip map[string]struct{} + if len(_skipPaths) > 0 { + skip = make(map[string]struct{}, len(_skipPaths)) + + for _, path := range _skipPaths { + skip[path] = struct{}{} + } + } return func(c *gin.Context) { - // 开始时间 - startTime := time.Now() + start := time.Now() + path := c.Request.URL.Path + raw := c.Request.URL.RawQuery - // 处理请求 c.Next() - // 结束时间 - endTime := time.Now() - - // 执行时间 - latencyTime := endTime.Sub(startTime) - - // 请求方式 - reqMethod := c.Request.Method - - // 请求路由 - reqUri := c.Request.RequestURI - - // 状态码 - statusCode := c.Writer.Status() - - // 请求IP - clientIP := c.ClientIP() - - // 日志格式 - if reqUri != "/api/v1/pluginapi/heartbeat" && reqUri != "/plugin/prometheus/target" { - Debug("status_code:%d latency_time:%s client_ip:%s req_method:%s req_uri:%s", + if _, ok := skip[path]; !ok { + endTime := time.Now() + latency := endTime.Sub(start) + method := c.Request.Method + statusCode := c.Writer.Status() + clientIP := c.ClientIP() + errorMessage := c.Errors.ByType(gin.ErrorTypePrivate).String() + + if raw != "" { + path = path + "?" + raw + } + if latency > time.Minute { + latency = latency.Truncate(time.Second) + } + + Debug("%s status_code:%3d latency_time:%-13v client_ip:%-15s method:%-7s req_uri:%#v\n%s", + start.Format("2006-01-02 15:04:05"), statusCode, - latencyTime, + latency, clientIP, - reqMethod, - reqUri, - ) + method, + path, + errorMessage) } } } diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go index 088761a..70f1f99 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/batch.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Fri Jan 19 11:08:30 2024 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go index f73f97c..83145ca 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/bindsync.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Wed Dec 27 19:38:17 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go index 5c936d4..dcae6b8 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/client.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( @@ -23,8 +30,8 @@ type Client struct { token string // 用于event消息处理 - eventChan chan *common.EventMessage - eventCallbackMap map[int]EventCallback + EventChan chan *common.EventMessage + EventCallbackMap map[int]common.EventCallback // 用于异步command及script执行结果处理机 asyncCmdResultChan chan *common.AsyncCmdResult @@ -50,8 +57,8 @@ func DefaultClient(desc *PluginInfo) *Client { global_client = &Client{ PluginInfo: desc, - eventChan: make(chan *common.EventMessage, 20), - eventCallbackMap: make(map[int]EventCallback), + EventChan: make(chan *common.EventMessage, 20), + EventCallbackMap: make(map[int]common.EventCallback), asyncCmdResultChan: make(chan *common.AsyncCmdResult, 20), cmdProcessorCallbackMap: make(map[string]CallbackHandler), @@ -90,10 +97,6 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { c.Set("__internal__client_instance", client) }, tagsHandler) - api.POST("/event", func(c *gin.Context) { - c.Set("__internal__client_instance", client) - }, eventHandler) - api.PUT("/command_result", func(c *gin.Context) { c.Set("__internal__client_instance", client) }, commandResultHandler) @@ -108,7 +111,7 @@ func (client *Client) RegisterHandlers(router *gin.Engine) { // } // TODO: start command result process service - client.startEventProcessor() + // client.startEventProcessor() client.startCommandResultProcessor() } diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go index 643bb9b..41add3e 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/config.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go deleted file mode 100644 index 8d76833..0000000 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/event.go +++ /dev/null @@ -1,160 +0,0 @@ -package client - -import ( - "encoding/json" - "errors" - "net/http" - "strconv" - "strings" - - "gitee.com/openeuler/PilotGo/sdk/common" - "gitee.com/openeuler/PilotGo/sdk/utils/httputils" -) - -type EventCallback func(e *common.EventMessage) - -// 注册event事件监听 -func (c *Client) ListenEvent(eventTypes []int, callbacks []EventCallback) error { - var eventtypes []string - for _, i := range eventTypes { - eventtypes = append(eventtypes, strconv.Itoa(i)) - } - - url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") - r, err := httputils.Put(url, &httputils.Params{ - Body: c.PluginInfo, - Cookie: map[string]string{ - TokenCookie: c.token, - }, - }) - if err != nil { - return err - } - if r.StatusCode != http.StatusOK { - return errors.New("server process error:" + strconv.Itoa(r.StatusCode)) - } - - resp := &common.CommonResult{} - if err := json.Unmarshal(r.Body, resp); err != nil { - return err - } - if resp.Code != http.StatusOK { - return errors.New(resp.Message) - } - - data := &struct { - Status string `json:"status"` - Error string `json:"error"` - }{} - if err := resp.ParseData(data); err != nil { - return err - } - for i, eventType := range eventTypes { - c.registerEventCallback(eventType, callbacks[i]) - } - return nil -} - -// 取消注册event事件监听 -func (c *Client) UnListenEvent(eventTypes []int) error { - var eventtypes []string - for _, i := range eventTypes { - eventtypes = append(eventtypes, strconv.Itoa(i)) - } - - url := c.Server() + "/api/v1/pluginapi/listener?eventTypes=" + strings.Join(eventtypes, ",") - r, err := httputils.Delete(url, &httputils.Params{ - Body: c.PluginInfo, - Cookie: map[string]string{ - TokenCookie: c.token, - }, - }) - if err != nil { - return err - } - if r.StatusCode != http.StatusOK { - return errors.New("server process error:" + strconv.Itoa(r.StatusCode)) - } - - resp := &common.CommonResult{} - if err := json.Unmarshal(r.Body, resp); err != nil { - return err - } - if resp.Code != http.StatusOK { - return errors.New(resp.Message) - } - - data := &struct { - Status string `json:"status"` - Error string `json:"error"` - }{} - if err := resp.ParseData(data); err != nil { - return err - } - - for _, eventType := range eventTypes { - c.unregisterEventCallback(eventType) - } - return nil -} - -// 发布event事件 -func (c *Client) PublishEvent(msg common.EventMessage) error { - url := c.Server() + "/api/v1/pluginapi/publish_event" - r, err := httputils.Put(url, &httputils.Params{ - Body: &msg, - Cookie: map[string]string{ - TokenCookie: c.token, - }, - }) - if err != nil { - return err - } - if r.StatusCode != http.StatusOK { - return errors.New("server process error:" + strconv.Itoa(r.StatusCode)) - } - - resp := &common.CommonResult{} - if err := json.Unmarshal(r.Body, resp); err != nil { - return err - } - if resp.Code != http.StatusOK { - return errors.New(resp.Message) - } - - data := &struct { - Status string `json:"status"` - Error string `json:"error"` - }{} - if err := resp.ParseData(data); err != nil { - return err - } - return nil -} - -func (c *Client) registerEventCallback(eventType int, callback EventCallback) { - c.eventCallbackMap[eventType] = callback -} - -func (c *Client) unregisterEventCallback(eventType int) { - delete(c.eventCallbackMap, eventType) -} - -func (c *Client) ProcessEvent(event *common.EventMessage) { - c.eventChan <- event -} - -func (c *Client) startEventProcessor() { - go func() { - for { - e := <-c.eventChan - - // TODO: process event message - cb, ok := c.eventCallbackMap[e.MessageType] - if ok { - cb(e) - } - } - }() - -} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go index a0d233e..1f79550 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/extention.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Gzx1999 + * Date: Tue Nov 7 15:01:17 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go index fe67a8f..3fe24a8 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/fileservice.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Tue Mar 12 15:33:09 2024 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go index b8c9def..d8e1389 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/handler.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( @@ -85,30 +92,6 @@ func bindHandler(c *gin.Context) { response.Success(c, nil, "bind server success") } -func eventHandler(c *gin.Context) { - j, err := io.ReadAll(c.Request.Body) // 接收数据 - if err != nil { - logger.Error("没获取到:%s", err.Error()) - return - } - var msg common.EventMessage - if err := json.Unmarshal(j, &msg); err != nil { - logger.Error("反序列化结果失败%s", err.Error()) - return - } - - v, ok := c.Get("__internal__client_instance") - if !ok { - return - } - client, ok := v.(*Client) - if !ok { - return - } - - client.ProcessEvent(&msg) -} - func commandResultHandler(c *gin.Context) { j, err := io.ReadAll(c.Request.Body) // 接收数据 if err != nil { diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go index fa1fb9c..f4aedd3 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/heartbeat.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Mon Dec 18 10:57:09 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go index 94043cf..85bc229 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/machine.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go index 155b66e..10352de 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/permission.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: wubijie + * Date: Thu Jan 11 20:24:26 2024 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go index e878f33..3fb8822 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/plugin.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( @@ -10,12 +17,14 @@ import ( // 用于初始化Client type PluginInfo struct { + MenuName string `json:"menuName"` Name string `json:"name"` Version string `json:"version"` Description string `json:"description"` Author string `json:"author"` Email string `json:"email"` Url string `json:"url"` + Icon string `json:"icon"` PluginType string `json:"plugin_type"` ReverseDest string `json:"reverse_dest"` } @@ -27,11 +36,11 @@ type PluginFullInfo struct { Permissions []common.Permission } -func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { +func (c *Client) GetPlugins() ([]*PluginInfo, error) { if !c.IsBind() { return nil, errors.New("unbind PilotGo-server platform") } - url := c.Server() + "/api/v1/pluginapi/plugins" + url := "http://" + c.Server() + "/api/v1/pluginapi/plugins" r, err := httputils.Get(url, &httputils.Params{ Cookie: map[string]string{ TokenCookie: c.token, @@ -41,10 +50,13 @@ func (c *Client) GetPluginInfo(name string) (*PluginInfo, error) { return nil, err } - resp := &PluginInfo{} - if err := json.Unmarshal(r.Body, resp); err != nil { + resp := struct { + Code int `json:"code"` + Data []*PluginInfo `json:"data"` + }{} + if err := json.Unmarshal(r.Body, &resp); err != nil { return nil, err } - return resp, nil + return resp.Data, nil } diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go index 2d28745..ccf9776 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/script.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go index 2959712..a2fe2c6 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/plugin/client/service.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package client import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go b/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go index ac0d707..25087d5 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/response/response.go @@ -1,7 +1,16 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package response import ( + "fmt" "net/http" + "reflect" "github.com/gin-gonic/gin" ) @@ -38,3 +47,40 @@ type PaginationQ struct { Data interface{} `json:"data" comment:"muster be a pointer of slice gorm.Model"` TotalSize int `json:"total"` } + +// 结构体分页查询方法 +func DataPaging(p *PaginationQ, list interface{}, total int) (interface{}, error) { + data := make([]interface{}, 0) + if reflect.TypeOf(list).Kind() == reflect.Slice { + s := reflect.ValueOf(list) + for i := 0; i < s.Len(); i++ { + ele := s.Index(i) + data = append(data, ele.Interface()) + } + } + if p.PageSize < 1 { + p.PageSize = 10 + } + if p.Page < 1 { + p.Page = 1 + } + if total == 0 { + p.TotalSize = 0 + } + num := p.PageSize * (p.Page - 1) + if num > total { + return nil, fmt.Errorf("页码超出") + } + if p.PageSize*p.Page > total { + return data[num:], nil + } else { + if p.PageSize*p.Page < num { + return nil, fmt.Errorf("读取错误") + } + if p.PageSize*p.Page == 0 { + return data, nil + } else { + return data[num : p.Page*p.PageSize], nil + } + } +} diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go index 96d9f61..8b1c861 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/judgeProtocol.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: Wangjunqi123 + * Date: Wed Jun 12 14:00:31 2024 +0800 + */ package httputils import ( diff --git a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go index c5b7689..0f88478 100644 --- a/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go +++ b/vendor/gitee.com/openeuler/PilotGo/sdk/utils/httputils/request.go @@ -1,3 +1,10 @@ +/* + * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. + * PilotGo licensed under the Mulan Permissive Software License, Version 2. + * See LICENSE file for more details. + * Author: zhanghan2021 + * Date: Wed Sep 27 17:35:12 2023 +0800 + */ package httputils import ( diff --git a/vendor/modules.txt b/vendor/modules.txt index 032fc2d..00f7958 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# gitee.com/openeuler/PilotGo/sdk v0.0.0-20240711084602-e34bc1158484 +# gitee.com/openeuler/PilotGo/sdk v0.0.0-20241227025309-05f048f9c7d8 ## explicit; go 1.20 gitee.com/openeuler/PilotGo/sdk/common gitee.com/openeuler/PilotGo/sdk/logger diff --git a/web/vite.config.ts b/web/vite.config.ts index 6d13da8..0525639 100755 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -2,7 +2,7 @@ * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. - * Author: Wangjunqi123 + * Author: zhao_zhen_fang * Date: Mon Oct 9 11:19:00 2023 +0800 */ import { fileURLToPath, URL } from 'node:url' @@ -28,14 +28,22 @@ export default defineConfig({ server:{ proxy:{ "/plugin/topology/api": { - target: 'http://10.41.107.29:9991', + target: 'http://127.0.0.1:9991', // target: 'http://10.44.55.72:9991', changeOrigin:true, + secure: false, // rewrite: (path)=> path.replace("/^\/api/", ""), }, + '/plugin/elk/api': { + target: 'https://10.41.107.29:9993', + secure: false, + changeOrigin: true, + rewrite: path => path.replace(/^\//, '') + }, "/plugin/prometheus/api/v1": { - target: 'http://10.44.55.72:8090', + target: 'https://10.41.161.101:8090', changeOrigin:true, + secure: false, // rewrite: (path)=> path.replace("/^\/api/", ""), } } -- Gitee