diff --git a/gala-ops/server/client/client.go b/gala-ops/server/client/client.go index 3abe7d986f98375cdeb21a6ca5d327e12c4815f2..58ce2c602dddfa96d58668a34ff933c6e8cd23e0 100644 --- a/gala-ops/server/client/client.go +++ b/gala-ops/server/client/client.go @@ -1,9 +1,7 @@ package client import ( - "github.com/gin-gonic/gin" "openeuler.org/PilotGo/gala-ops-plugin/config" - "openeuler.org/PilotGo/gala-ops-plugin/httphandler" "openeuler.org/PilotGo/plugin-sdk/plugin" ) @@ -28,20 +26,5 @@ func Client() *plugin.Client { } func StartClient(conf *config.HttpConf) { - registerHandlers(globalClient.HttpEngine) - globalClient.Serve(conf.Addr) } - -func registerHandlers(engine *gin.Engine) { - api := engine.Group("/plugin/gala-ops/api") - { - // 脚本执行结果接口 - api.PUT("/run_script_result", httphandler.RunScriptResult) - - // 安装/升级/卸载gala-gopher监控终端 - api.PUT("/install_gopher", httphandler.InstallGopher) - api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) - api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) - } -} diff --git a/gala-ops/server/config/config.go b/gala-ops/server/config/config.go index 7c45146011e3aca0db232275e214c987c8d7a5b3..380a48e223a6dda47e8a85c855690f3b1b8ff333 100644 --- a/gala-ops/server/config/config.go +++ b/gala-ops/server/config/config.go @@ -28,7 +28,7 @@ type ServerConfig struct { PilotGo *PilotGoConf `yaml:"PilotGo"` } -const config_file = "./config.yaml" +const config_file = "./config.yml" var global_config ServerConfig diff --git a/gala-ops/server/go.mod b/gala-ops/server/go.mod index 2f14138b1ff22ebfd0c7129058e0a073e5c03432..bf86d8053c95ab26fde1c79dd76e9b5279c6d8a9 100644 --- a/gala-ops/server/go.mod +++ b/gala-ops/server/go.mod @@ -1,3 +1,31 @@ module openeuler.org/PilotGo/gala-ops-plugin go 1.19 + +require ( + github.com/gin-gonic/gin v1.7.1 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.13.0 // indirect + github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.6 // indirect + github.com/json-iterator/go v1.1.11 // indirect + github.com/kr/pretty v0.2.0 // indirect + github.com/leodido/go-urn v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/stretchr/testify v1.8.0 // indirect + github.com/ugorji/go/codec v1.1.7 // indirect + golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + google.golang.org/protobuf v1.28.1 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/gala-ops/server/go.sum b/gala-ops/server/go.sum new file mode 100644 index 0000000000000000000000000000000000000000..0e569d2447c62784f5ad53160a5cb06190c84b10 --- /dev/null +++ b/gala-ops/server/go.sum @@ -0,0 +1,26 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-gonic/gin v1.7.1 h1:qC89GU3p8TvKWMAVhEpmpB2CIb1hnqt2UdKZaP93mS8= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= +github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= +golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 h1:a5Yg6ylndHHYJqIPrdq0AhvR6KTvDTAvgBtaidhEevY= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index 9b865894a97521a2b74ec0983ba66653ff5ea222..205fa84558ebe499e2b15a12f0e33c021dbeae85 100644 --- a/gala-ops/server/httphandler/agent.go +++ b/gala-ops/server/httphandler/agent.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - "openeuler.org/PilotGo/gala-ops-plugin/pluginclient" + "openeuler.org/PilotGo/gala-ops-plugin/client" ) func InstallGopher(ctx *gin.Context) { @@ -21,7 +21,7 @@ func InstallGopher(ctx *gin.Context) { } cmd := "yum install -y gala-gopher && systemctl start gala-gopher" - cmdResults, err := pluginclient.Client().RunScript(param.Batch, cmd) + cmdResults, err := client.Client().RunScript(param.Batch, cmd) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ "code": -1, @@ -71,7 +71,7 @@ func UpgradeGopher(ctx *gin.Context) { } cmd := "systemctl stop gala-gopher && yum upgrade -y gala-gopher && systemctl start gala-gopher" - cmdResults, err := pluginclient.Client().RunScript(param.Batch, cmd) + cmdResults, err := client.Client().RunScript(param.Batch, cmd) if err != nil { ctx.JSON(http.StatusBadRequest, gin.H{ "code": -1, @@ -119,7 +119,7 @@ func UninstallGopher(ctx *gin.Context) { } cmd := "systemctl stop gala-gopher && yum autoremove -y gala-gopher" - cmdResults, err := pluginclient.Client().RunScript(param.Batch, cmd) + cmdResults, err := client.Client().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 4545bb6822f186dbd60fb7aa4e138007d60d9dc2..59ebc6d69bf3f8df6b76a481988f21926c401309 100644 --- a/gala-ops/server/main.go +++ b/gala-ops/server/main.go @@ -3,6 +3,10 @@ package main import ( "fmt" + "github.com/gin-gonic/gin" + + "openeuler.org/PilotGo/gala-ops-plugin/httphandler" + "openeuler.org/PilotGo/gala-ops-plugin/client" "openeuler.org/PilotGo/gala-ops-plugin/config" ) @@ -12,5 +16,20 @@ func main() { config.Init() + engine := client.Client().HttpEngine + registerHandlers(engine) client.StartClient(config.Config().Http) } + +func registerHandlers(engine *gin.Engine) { + api := engine.Group("/plugin/gala-ops/api") + { + // 脚本执行结果接口 + api.PUT("/run_script_result", httphandler.RunScriptResult) + + // 安装/升级/卸载gala-gopher监控终端 + api.PUT("/install_gopher", httphandler.InstallGopher) + api.PUT("/upgrade_gopher", httphandler.UpgradeGopher) + api.DELETE("/uninstall_gopher", httphandler.UninstallGopher) + } +} diff --git a/gala-ops/server/pluginclient/client.go b/gala-ops/server/pluginclient/client.go deleted file mode 100644 index c63a8ae824d7ddf7e95971608b590da372146f86..0000000000000000000000000000000000000000 --- a/gala-ops/server/pluginclient/client.go +++ /dev/null @@ -1,21 +0,0 @@ -package pluginclient - -import ( - "sync" - - "openeuler.org/PilotGo/plugin-sdk/plugin" -) - -var once sync.Once -var global_client *plugin.Client - -func NewClient(desc *plugin.PluginInfo) { - once.Do(func() { - // client init - global_client = plugin.DefaultClient(desc) - }) -} - -func Client() *plugin.Client { - return global_client -} diff --git a/gala-ops/web/.gitignore b/gala-ops/web/.gitignore index 6c4b4c34822993583880e1475976ecc4e31b06e8..76e051c0c609a93d68452ef20d5b201227c24c0d 100644 --- a/gala-ops/web/.gitignore +++ b/gala-ops/web/.gitignore @@ -1,6 +1,7 @@ .DS_Store node_modules /ismp-monitor-web +/dist # local env files diff --git a/go.work b/go.work index f19ff0c40f1d9319a53e59a1f48d729f2f5ae4c4..048a1d091d8853dce943a9d3f0cc10d6f816ed35 100644 --- a/go.work +++ b/go.work @@ -1,9 +1,9 @@ go 1.19 use ( - ./sdk ./PilotGo + ./gala-ops/server ./grafana/ ./prometheus/server - ./gala-ops/server + ./sdk )