Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(region): fix db_dispatcher duplicate notify #18698

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/cloudcommon/db/db_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 0 additions & 32 deletions pkg/cloudcommon/db/notify_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/compute/models/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down