mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-06 19:54:26 +08:00
fix(region): fix db_dispatcher duplicate notify (#18698)
Co-authored-by: 马鸿飞 <mahongfei@yunion.cn>
This commit is contained in:
@@ -1427,7 +1427,6 @@ func (dispatcher *DBModelDispatcher) Create(ctx context.Context, query jsonutils
|
||||
notes := model.GetShortDesc(ctx)
|
||||
OpsLog.LogEvent(model, ACT_CREATE, notes, userCred)
|
||||
logclient.AddActionLogWithContext(ctx, model, logclient.ACT_CREATE, notes, userCred, true)
|
||||
CallCreateNotifyHook(ctx, userCred, model)
|
||||
}
|
||||
manager.OnCreateComplete(ctx, []IModel{model}, userCred, ownerId, query, []jsonutils.JSONObject{data})
|
||||
return getItemDetails(manager, model, ctx, userCred, query)
|
||||
@@ -1878,7 +1877,6 @@ func DeleteModel(ctx context.Context, userCred mcclient.TokenCredential, item IM
|
||||
if userCred != nil {
|
||||
OpsLog.LogEvent(item, ACT_DELETE, item.GetShortDesc(ctx), userCred)
|
||||
logclient.AddSimpleActionLog(item, logclient.ACT_DELETE, item.GetShortDesc(ctx), userCred, true)
|
||||
CallDeleteNotifyHook(ctx, userCred, item)
|
||||
}
|
||||
if _, ok := item.(IStandaloneModel); ok && len(item.GetId()) > 0 {
|
||||
err := Metadata.RemoveAll(ctx, item, userCred)
|
||||
|
||||
@@ -22,13 +22,9 @@ import (
|
||||
|
||||
var (
|
||||
updateNotifyHook updateNotifyHookFunc
|
||||
createNotifyHook createNotifyHookFunc
|
||||
deleteNotifyHook deleteNotifyHookFunc
|
||||
)
|
||||
|
||||
type updateNotifyHookFunc func(ctx context.Context, userCred mcclient.TokenCredential, obj IModel)
|
||||
type createNotifyHookFunc func(ctx context.Context, userCred mcclient.TokenCredential, obj IModel)
|
||||
type deleteNotifyHookFunc func(ctx context.Context, userCred mcclient.TokenCredential, obj IModel)
|
||||
|
||||
func SetUpdateNotifyHook(f updateNotifyHookFunc) {
|
||||
if updateNotifyHook != nil {
|
||||
@@ -37,37 +33,9 @@ func SetUpdateNotifyHook(f updateNotifyHookFunc) {
|
||||
updateNotifyHook = f
|
||||
}
|
||||
|
||||
func SetCreateNotifyHook(f createNotifyHookFunc) {
|
||||
if createNotifyHook != nil {
|
||||
panic("createNotifyHook already set")
|
||||
}
|
||||
createNotifyHook = f
|
||||
}
|
||||
|
||||
func SetDeleteNotifyHook(f deleteNotifyHookFunc) {
|
||||
if deleteNotifyHook != nil {
|
||||
panic("deleteNotifyHook already set")
|
||||
}
|
||||
deleteNotifyHook = f
|
||||
}
|
||||
|
||||
func CallUpdateNotifyHook(ctx context.Context, userCred mcclient.TokenCredential, obj IModel) {
|
||||
if updateNotifyHook == nil {
|
||||
return
|
||||
}
|
||||
updateNotifyHook(ctx, userCred, obj)
|
||||
}
|
||||
|
||||
func CallCreateNotifyHook(ctx context.Context, userCred mcclient.TokenCredential, obj IModel) {
|
||||
if createNotifyHook == nil {
|
||||
return
|
||||
}
|
||||
createNotifyHook(ctx, userCred, obj)
|
||||
}
|
||||
|
||||
func CallDeleteNotifyHook(ctx context.Context, userCred mcclient.TokenCredential, obj IModel) {
|
||||
if deleteNotifyHook == nil {
|
||||
return
|
||||
}
|
||||
deleteNotifyHook(ctx, userCred, obj)
|
||||
}
|
||||
|
||||
@@ -55,28 +55,6 @@ func init() {
|
||||
Action: ActionUpdate,
|
||||
})
|
||||
})
|
||||
|
||||
db.SetCreateNotifyHook(func(ctx context.Context, userCred mcclient.TokenCredential, obj db.IModel) {
|
||||
_, ok := notifyDBHookResources.Load(obj.KeywordPlural())
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
EventNotify(ctx, userCred, SEventNotifyParam{
|
||||
Obj: obj,
|
||||
Action: ActionCreate,
|
||||
})
|
||||
})
|
||||
|
||||
db.SetDeleteNotifyHook(func(ctx context.Context, userCred mcclient.TokenCredential, obj db.IModel) {
|
||||
_, ok := notifyDBHookResources.Load(obj.KeywordPlural())
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
EventNotify(ctx, userCred, SEventNotifyParam{
|
||||
Obj: obj,
|
||||
Action: ActionDelete,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func AddNotifyDBHookResources(keywordPlurals ...string) {
|
||||
|
||||
@@ -3431,6 +3431,11 @@ func (hh *SHost) PostCreate(
|
||||
if err != nil {
|
||||
log.Errorf("CancelPendingUsage fail %s", err)
|
||||
}
|
||||
hh.SEnabledStatusInfrasResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: hh,
|
||||
Action: notifyclient.ActionCreate,
|
||||
})
|
||||
}
|
||||
|
||||
func (hh *SHost) StartBaremetalCreateTask(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, parentTaskId string) error {
|
||||
@@ -3848,6 +3853,14 @@ func (hh *SHost) PostUpdate(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
}
|
||||
}
|
||||
|
||||
func (hh *SHost) PostDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
hh.SEnabledStatusInfrasResourceBase.PostDelete(ctx, userCred)
|
||||
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
|
||||
Obj: hh,
|
||||
Action: notifyclient.ActionDelete,
|
||||
})
|
||||
}
|
||||
|
||||
func (hh *SHost) UpdateDnsRecords(isAdd bool) {
|
||||
for _, netif := range hh.GetHostNetInterfaces() {
|
||||
hh.UpdateDnsRecord(&netif, isAdd)
|
||||
|
||||
Reference in New Issue
Block a user