Skip to content

Commit

Permalink
fix(region): fix db_dispatcher duplicate notify (#18698)
Browse files Browse the repository at this point in the history
Co-authored-by: 马鸿飞 <mahongfei@yunion.cn>
  • Loading branch information
gouqi11 and 马鸿飞 authored Nov 15, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent bd90a44 commit 0dbb094
Showing 4 changed files with 13 additions and 56 deletions.
2 changes: 0 additions & 2 deletions pkg/cloudcommon/db/db_dispatcher.go
Original file line number Diff line number Diff line change
@@ -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)
32 changes: 0 additions & 32 deletions pkg/cloudcommon/db/notify_hook.go
Original file line number Diff line number Diff line change
@@ -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)
}
22 changes: 0 additions & 22 deletions pkg/cloudcommon/notifyclient/notify.go
Original file line number Diff line number Diff line change
@@ -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) {
13 changes: 13 additions & 0 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0dbb094

Please sign in to comment.