From 81588c92ae231cdad7f19b373f44901690d5612a Mon Sep 17 00:00:00 2001 From: rainzm Date: Fri, 18 Dec 2020 13:05:24 +0800 Subject: [PATCH 1/2] feat(region): distinguish between pending delete and delete notification --- pkg/cloudcommon/notifyclient/events.go | 11 ++++++----- pkg/compute/tasks/guest_delete_task.go | 10 +++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/cloudcommon/notifyclient/events.go b/pkg/cloudcommon/notifyclient/events.go index 9535c95c6e..3f321dc9c3 100644 --- a/pkg/cloudcommon/notifyclient/events.go +++ b/pkg/cloudcommon/notifyclient/events.go @@ -41,11 +41,12 @@ type SAction string var ( Event SEvent - ActionCreate SAction = "create" - ActionUpdate SAction = "update" - ActionDelete SAction = "delete" - ActionRebuildRoot SAction = "rebuild_root" - ActionChangeConfig SAction = "change_config" + ActionCreate SAction = "create" + ActionUpdate SAction = "update" + ActionDelete SAction = "delete" + ActionPendingDelete SAction = "pending_delete" + ActionRebuildRoot SAction = "rebuild_root" + ActionChangeConfig SAction = "change_config" ) type SEvent struct { diff --git a/pkg/compute/tasks/guest_delete_task.go b/pkg/compute/tasks/guest_delete_task.go index 7e1a294ce0..f2d69f206e 100644 --- a/pkg/compute/tasks/guest_delete_task.go +++ b/pkg/compute/tasks/guest_delete_task.go @@ -337,15 +337,19 @@ func (self *GuestDeleteTask) DeleteGuest(ctx context.Context, guest *models.SGue // guest.RemoveAllMetadata(ctx, self.UserCred) db.OpsLog.LogEvent(guest, db.ACT_DELOCATE, nil, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_DELOCATE, nil, self.UserCred, true) - if !guest.IsSystem && !isPendingDeleted { - self.NotifyServerDeleted(ctx, guest) + if !guest.IsSystem { + if !isPendingDeleted { + self.NotifyServerDeleted(ctx, guest) + } else { + notifyclient.NotifyWebhook(ctx, self.UserCred, guest, notifyclient.ActionDelete) + } } models.HostManager.ClearSchedDescCache(guest.HostId) self.SetStageComplete(ctx, nil) } func (self *GuestDeleteTask) NotifyServerDeleted(ctx context.Context, guest *models.SGuest) { - notifyclient.NotifyWebhook(ctx, self.UserCred, guest, notifyclient.ActionDelete) + notifyclient.NotifyWebhook(ctx, self.UserCred, guest, notifyclient.ActionPendingDelete) guest.NotifyServerEvent( ctx, self.UserCred, From bf378452a47d57a64dfbd4eadc1a84e5e559f49c Mon Sep 17 00:00:00 2001 From: rainzm Date: Fri, 18 Dec 2020 13:06:08 +0800 Subject: [PATCH 2/2] feat(region): send webhook server_create when canceling pending delete --- pkg/compute/models/guest_actions.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 25b6059956..9691fcb558 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -2659,6 +2659,7 @@ func (self *SGuest) DoCancelPendingDelete(ctx context.Context, userCred mcclient if err != nil { return err } + notifyclient.NotifyWebhook(ctx, userCred, self, notifyclient.ActionCreate) return nil }