From 86bcfdaa039c9719ecd863d3e956de1c331d82af Mon Sep 17 00:00:00 2001 From: zhanghan Date: Mon, 25 Nov 2024 17:51:15 +0800 Subject: [PATCH] event message notice for plugin online --- cmd/server/app/network/controller/plugin.go | 8 +++---- cmd/server/app/network/controller/user.go | 2 +- cmd/server/app/service/plugin/heartbeat.go | 25 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cmd/server/app/network/controller/plugin.go b/cmd/server/app/network/controller/plugin.go index 9de093aa..c27fe547 100644 --- a/cmd/server/app/network/controller/plugin.go +++ b/cmd/server/app/network/controller/plugin.go @@ -82,8 +82,8 @@ func AddPluginHandler(c *gin.Context) { } msgData := commonSDK.MessageData{ - MsgType: eventSDK.MsgPluginRemove, - MessageType: eventSDK.GetMessageTypeString(eventSDK.MsgPluginRemove), + MsgType: eventSDK.MsgPluginAdd, + MessageType: eventSDK.GetMessageTypeString(eventSDK.MsgPluginAdd), TimeStamp: time.Now(), Data: eventSDK.MDPluginChange{ PluginName: p.Name, @@ -98,7 +98,7 @@ func AddPluginHandler(c *gin.Context) { return } ms := commonSDK.EventMessage{ - MessageType: eventSDK.MsgUserLogin, + MessageType: eventSDK.MsgPluginAdd, MessageData: msgDataString, } plugin.PublishEvent(ms) @@ -193,7 +193,7 @@ func UnloadPluginHandler(c *gin.Context) { return } ms := commonSDK.EventMessage{ - MessageType: eventSDK.MsgUserLogin, + MessageType: eventSDK.MsgPluginRemove, MessageData: msgDataString, } plugin.PublishEvent(ms) diff --git a/cmd/server/app/network/controller/user.go b/cmd/server/app/network/controller/user.go index 0efa42ca..48c77fdb 100644 --- a/cmd/server/app/network/controller/user.go +++ b/cmd/server/app/network/controller/user.go @@ -167,7 +167,7 @@ func Logout(c *gin.Context) { return } ms := commonSDK.EventMessage{ - MessageType: eventSDK.MsgUserLogin, + MessageType: eventSDK.MsgUserLogout, MessageData: msgDataString, } plugin.PublishEvent(ms) diff --git a/cmd/server/app/service/plugin/heartbeat.go b/cmd/server/app/service/plugin/heartbeat.go index 6668abeb..a0bffa7c 100644 --- a/cmd/server/app/service/plugin/heartbeat.go +++ b/cmd/server/app/service/plugin/heartbeat.go @@ -3,9 +3,12 @@ package plugin import ( "time" + eventSDK "gitee.com/openeuler/PilotGo-plugins/event/sdk" "gitee.com/openeuler/PilotGo/pkg/dbmanager/redismanager" "gitee.com/openeuler/PilotGo/sdk/logger" "gitee.com/openeuler/PilotGo/sdk/plugin/client" + + commonSDK "gitee.com/openeuler/PilotGo/sdk/common" "k8s.io/apimachinery/pkg/util/wait" ) @@ -43,6 +46,28 @@ func checkAndRebind() { LastConnect: time.Now(), } redismanager.Set(key, value) + + // + msgData := commonSDK.MessageData{ + MsgType: eventSDK.MsgPluginOnline, + MessageType: eventSDK.GetMessageTypeString(eventSDK.MsgPluginOnline), + TimeStamp: time.Now(), + Data: eventSDK.MDPluginChange{ + PluginName: p.Name, + Version: p.Version, + Url: p.Url, + Description: p.Description, + }, + } + msgDataString, err := msgData.ToMessageDataString() + if err != nil { + logger.Error("event message data marshal failed:%v", err.Error()) + } + ms := commonSDK.EventMessage{ + MessageType: eventSDK.MsgPluginOnline, + MessageData: msgDataString, + } + PublishEvent(ms) } } } -- Gitee