From 4b49bcec8f8af399ad91d4b5c50066c53343880d Mon Sep 17 00:00:00 2001 From: rainzm Date: Fri, 11 Sep 2020 19:57:03 +0800 Subject: [PATCH] feat: add WithCtx version to notifyclient function --- pkg/cloudcommon/notifyclient/notify.go | 212 +++++++++++++----- pkg/compute/models/disks.go | 2 +- pkg/compute/models/guest_actions.go | 9 +- pkg/compute/tasks/disk_batch_create_task.go | 2 +- .../tasks/elasticcache_account_create_task.go | 2 +- .../tasks/elasticcache_account_delete_task.go | 2 +- ...lasticcache_account_reset_password_task.go | 2 +- .../tasks/elasticcache_acl_create_task.go | 2 +- .../tasks/elasticcache_acl_delete_task.go | 2 +- .../tasks/elasticcache_acl_update_task.go | 2 +- ...iccache_allocate_public_connection_task.go | 2 +- .../tasks/elasticcache_backup_create_task.go | 2 +- ...asticcache_backup_restore_instance_task.go | 2 +- .../tasks/elasticcache_change_spec_task.go | 2 +- pkg/compute/tasks/elasticcache_create_task.go | 2 +- pkg/compute/tasks/elasticcache_delete_task.go | 2 +- .../tasks/elasticcache_flush_instance.go | 2 +- .../elasticcache_parameter_update_task.go | 2 +- ...ticcache_release_public_connection_task.go | 2 +- .../tasks/elasticcache_restart_task.go | 2 +- .../elasticcache_set_maintain_time_task.go | 2 +- pkg/compute/tasks/elasticcache_sync_task.go | 2 +- .../elasticcache_update_auth_mode_task.go | 2 +- .../elasticcache_update_backup_policy_task.go | 2 +- pkg/compute/tasks/guest_batch_create_task.go | 2 +- pkg/compute/tasks/guest_create_task.go | 10 +- pkg/compute/tasks/guest_delete_task.go | 1 + pkg/compute/tasks/guest_live_migrate_task.go | 6 +- pkg/compute/tasks/guest_rebuild_root_task.go | 1 + .../tasks/instance_snapshot_create_task.go | 2 +- .../tasks/instance_snapshot_reset_task.go | 2 +- .../tasks/loadbalancer_acl_create_task.go | 2 +- .../tasks/loadbalancer_acl_delete_task.go | 2 +- .../tasks/loadbalancer_acl_sync_task.go | 2 +- .../tasks/loadbalancer_backend_create_task.go | 2 +- .../tasks/loadbalancer_backend_sync_task.go | 2 +- .../loadbalancer_backendgroup_create_task.go | 2 +- .../loadbalancer_backendgroup_delete_task.go | 2 +- .../loadbalancer_certificate_create_task.go | 2 +- .../loadbalancer_certificate_delete_task.go | 2 +- pkg/compute/tasks/loadbalancer_create_task.go | 2 +- pkg/compute/tasks/loadbalancer_delete_task.go | 2 +- .../loadbalancer_listener_create_task.go | 2 +- .../loadbalancer_listener_delete_task.go | 2 +- .../loadbalancer_listener_rule_create_task.go | 2 +- .../loadbalancer_listener_rule_delete_task.go | 2 +- .../tasks/loadbalancer_listener_start_task.go | 2 +- .../tasks/loadbalancer_listener_stop_task.go | 2 +- .../tasks/loadbalancer_listener_sync_task.go | 2 +- .../loadbalancer_listener_syncstatus_task.go | 2 +- pkg/compute/tasks/loadbalancer_start_task.go | 2 +- pkg/compute/tasks/loadbalancer_stop_task.go | 2 +- .../tasks/loadbalancer_syncstatus_task.go | 2 +- pkg/compute/tasks/schedule.go | 2 +- .../tasks/snapshot_policy_delete_task.go | 2 +- pkg/compute/tasks/snapshotpolicy_disk_task.go | 2 +- pkg/httperrors/httperrors.go | 23 +- pkg/image/tasks/image_convert_task.go | 4 +- 58 files changed, 235 insertions(+), 131 deletions(-) diff --git a/pkg/cloudcommon/notifyclient/notify.go b/pkg/cloudcommon/notifyclient/notify.go index 218593910a..135307b87b 100644 --- a/pkg/cloudcommon/notifyclient/notify.go +++ b/pkg/cloudcommon/notifyclient/notify.go @@ -24,16 +24,19 @@ import ( "sync" "time" + "golang.org/x/text/language" + "yunion.io/x/jsonutils" "yunion.io/x/log" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/consts" + "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" "yunion.io/x/onecloud/pkg/mcclient/modulebase" "yunion.io/x/onecloud/pkg/mcclient/modules" - "yunion.io/x/onecloud/pkg/mcclient/modules/notify" + npk "yunion.io/x/onecloud/pkg/mcclient/modules/notify" ) var ( @@ -51,7 +54,20 @@ func init() { templatesTable = make(map[string]*template.Template) } -func getTemplateString(topic string, contType string, channel notify.TNotifyChannel) ([]byte, error) { +func getLangSuffix(ctx context.Context) string { + lang := httperrors.Lang(ctx) + switch lang { + case language.English: + return "en" + case language.Chinese: + return "cn" + default: + return "en" + } +} + +func getTemplateString(ctx context.Context, topic string, contType string, channel npk.TNotifyChannel) ([]byte, error) { + contType = contType + "@" + getLangSuffix(ctx) if len(channel) > 0 { path := filepath.Join(consts.NotifyTemplateDir, consts.GetServiceType(), contType, fmt.Sprintf("%s.%s", topic, string(channel))) cont, err := ioutil.ReadFile(path) @@ -63,13 +79,13 @@ func getTemplateString(topic string, contType string, channel notify.TNotifyChan return ioutil.ReadFile(path) } -func getTemplate(topic string, contType string, channel notify.TNotifyChannel) (*template.Template, error) { +func getTemplate(ctx context.Context, topic string, contType string, channel npk.TNotifyChannel) (*template.Template, error) { key := fmt.Sprintf("%s.%s.%s", topic, contType, channel) templatesTableLock.Lock() defer templatesTableLock.Unlock() if _, ok := templatesTable[key]; !ok { - cont, err := getTemplateString(topic, contType, channel) + cont, err := getTemplateString(ctx, topic, contType, channel) if err != nil { return nil, err } @@ -82,8 +98,8 @@ func getTemplate(topic string, contType string, channel notify.TNotifyChannel) ( return templatesTable[key], nil } -func getContent(topic string, contType string, channel notify.TNotifyChannel, data jsonutils.JSONObject) (string, error) { - tmpl, err := getTemplate(topic, contType, channel) +func getContent(ctx context.Context, topic string, contType string, channel npk.TNotifyChannel, data jsonutils.JSONObject) (string, error) { + tmpl, err := getTemplate(ctx, topic, contType, channel) if err != nil { return "", err } @@ -96,22 +112,36 @@ func getContent(topic string, contType string, channel notify.TNotifyChannel, da return buf.String(), nil } -func Notify(recipientId []string, isGroup bool, priority notify.TNotifyPriority, event string, - data jsonutils.JSONObject) { +func NotifyWithCtx(ctx context.Context, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { + notify(ctx, recipientId, isGroup, priority, event, data) +} + +func Notify(recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { + notify(context.Background(), recipientId, isGroup, priority, event, data) +} + +func notify(ctx context.Context, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { switch priority { - case notify.NotifyPriorityCritical: - NotifyCritical(recipientId, isGroup, event, data) - case notify.NotifyPriorityImportant: - NotifyImportant(recipientId, isGroup, event, data) + case npk.NotifyPriorityCritical: + notifyCritical(ctx, recipientId, isGroup, event, data) + case npk.NotifyPriorityImportant: + notifyImportant(ctx, recipientId, isGroup, event, data) default: - NotifyNormal(recipientId, isGroup, event, data) + notifyNormal(ctx, recipientId, isGroup, event, data) } } -func RawNotify(recipientId []string, isGroup bool, channel notify.TNotifyChannel, priority notify.TNotifyPriority, - event string, data jsonutils.JSONObject) { +func RawNotifyWithCtx(ctx context.Context, recipientId []string, isGroup bool, channel npk.TNotifyChannel, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { + rawNotify(ctx, recipientId, isGroup, channel, priority, event, data) +} + +func RawNotify(recipientId []string, isGroup bool, channel npk.TNotifyChannel, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { + rawNotify(context.Background(), recipientId, isGroup, channel, priority, event, data) +} + +func rawNotify(ctx context.Context, recipientId []string, isGroup bool, channel npk.TNotifyChannel, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { log.Infof("notify %s event %s priority %s", recipientId, event, priority) - msg := notify.SNotifyMessage{} + msg := npk.SNotifyMessage{} if isGroup { msg.Gid = recipientId } else { @@ -119,12 +149,12 @@ func RawNotify(recipientId []string, isGroup bool, channel notify.TNotifyChannel } msg.Priority = priority msg.ContactType = channel - topic, _ := getContent(event, "title", channel, data) + topic, _ := getContent(ctx, event, "title", channel, data) if len(topic) == 0 { topic = event } msg.Topic = topic - body, _ := getContent(event, "content", channel, data) + body, _ := getContent(ctx, event, "content", channel, data) if len(body) == 0 { body, _ = data.GetString() } @@ -132,69 +162,103 @@ func RawNotify(recipientId []string, isGroup bool, channel notify.TNotifyChannel // log.Debugf("send notification %s %s", topic, body) notifyClientWorkerMan.Run(func() { s := auth.GetAdminSession(context.Background(), consts.GetRegion(), "") - notify.Notifications.Send(s, msg) + npk.Notifications.Send(s, msg) }, nil, nil) } func NotifyNormal(recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { - for _, c := range []notify.TNotifyChannel{ - notify.NotifyByEmail, - notify.NotifyByDingTalk, - notify.NotifyByWebConsole, - notify.NotifyByFeishu, - notify.NotifyByWorkwx, + notifyNormal(context.Background(), recipientId, isGroup, event, data) +} + +func NotifyNormalWithCtx(ctx context.Context, recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { + notifyNormal(ctx, recipientId, isGroup, event, data) +} + +func notifyNormal(ctx context.Context, recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { + for _, c := range []npk.TNotifyChannel{ + npk.NotifyByEmail, + npk.NotifyByDingTalk, + npk.NotifyByWebConsole, + npk.NotifyByFeishu, + npk.NotifyByWorkwx, } { - RawNotify(recipientId, isGroup, + rawNotify(ctx, recipientId, isGroup, c, - notify.NotifyPriorityNormal, + npk.NotifyPriorityNormal, event, data) } } func NotifyImportant(recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { - for _, c := range []notify.TNotifyChannel{ - notify.NotifyByEmail, - notify.NotifyByDingTalk, - notify.NotifyByMobile, - notify.NotifyByWebConsole, - notify.NotifyByFeishu, - notify.NotifyByWorkwx, + notifyImportant(context.Background(), recipientId, isGroup, event, data) +} + +func NotifyImportantWithCtx(ctx context.Context, recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { + notifyImportant(ctx, recipientId, isGroup, event, data) +} + +func notifyImportant(ctx context.Context, recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { + for _, c := range []npk.TNotifyChannel{ + npk.NotifyByEmail, + npk.NotifyByDingTalk, + npk.NotifyByMobile, + npk.NotifyByWebConsole, + npk.NotifyByFeishu, + npk.NotifyByWorkwx, } { - RawNotify(recipientId, isGroup, + rawNotify(ctx, recipientId, isGroup, c, - notify.NotifyPriorityImportant, + npk.NotifyPriorityImportant, event, data) } } func NotifyCritical(recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { - for _, c := range []notify.TNotifyChannel{ - notify.NotifyByEmail, - notify.NotifyByDingTalk, - notify.NotifyByMobile, - notify.NotifyByWebConsole, - notify.NotifyByFeishu, - notify.NotifyByWorkwx, + notifyCritical(context.Background(), recipientId, isGroup, event, data) +} + +func NotifyCriticalWithCtx(ctx context.Context, recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { + notifyCritical(ctx, recipientId, isGroup, event, data) +} + +func notifyCritical(ctx context.Context, recipientId []string, isGroup bool, event string, data jsonutils.JSONObject) { + for _, c := range []npk.TNotifyChannel{ + npk.NotifyByEmail, + npk.NotifyByDingTalk, + npk.NotifyByMobile, + npk.NotifyByWebConsole, + npk.NotifyByFeishu, + npk.NotifyByWorkwx, } { - RawNotify(recipientId, isGroup, + rawNotify(ctx, recipientId, isGroup, c, - notify.NotifyPriorityCritical, + npk.NotifyPriorityCritical, event, data) } } // NotifyAllWithoutRobot will send messages via all contacnt type from exclude robot contact type such as dingtalk-robot. -func NotifyAllWithoutRobot(recipientId []string, isGroup bool, priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) error { - return notifyRobot("no", recipientId, isGroup, priority, event, data) +func NotifyAllWithoutRobot(recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error { + return notifyRobot(context.Background(), "no", recipientId, isGroup, priority, event, data) +} + +// NotifyAllWithoutRobot will send messages via all contacnt type from exclude robot contact type such as dingtalk-robot. +func NotifyAllWithoutRobotWithCtx(ctx context.Context, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error { + return notifyRobot(ctx, "no", recipientId, isGroup, priority, event, data) } // NotifyRobot will send messages via all robot contact type such as dingtalk-robot. -func NotifyRobot(recipientId []string, isGroup bool, priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) error { - return notifyRobot("only", recipientId, isGroup, priority, event, data) +func NotifyRobot(recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error { + return notifyRobot(context.Background(), "only", recipientId, isGroup, priority, event, data) } -func notifyRobot(robot string, recipientId []string, isGroup bool, priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) error { - s := auth.GetAdminSession(context.Background(), consts.GetRegion(), "") +// NotifyRobot will send messages via all robot contact type such as dingtalk-robot. +func NotifyRobotWithCtx(ctx context.Context, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error { + return notifyRobot(ctx, "only", recipientId, isGroup, priority, event, data) +} + +func notifyRobot(ctx context.Context, robot string, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error { + s := auth.GetAdminSession(ctx, consts.GetRegion(), "") params := jsonutils.NewDict() params.Set("robot", jsonutils.NewString(robot)) result, err := modules.NotifyConfig.PerformClassAction(s, "get-types", params) @@ -204,21 +268,37 @@ func notifyRobot(robot string, recipientId []string, isGroup bool, priority noti jarray, _ := result.Get("types") cTypes := jarray.(*jsonutils.JSONArray).GetStringArray() for _, ct := range cTypes { - RawNotify(recipientId, isGroup, notify.TNotifyChannel(ct), priority, event, data) + RawNotifyWithCtx(ctx, recipientId, isGroup, npk.TNotifyChannel(ct), priority, event, data) } return nil } -func SystemNotify(priority notify.TNotifyPriority, event string, data jsonutils.JSONObject) { +func SystemNotify(priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { + systemNotify(context.Background(), priority, event, data) +} + +func SystemNotifyWithCtx(ctx context.Context, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { + systemNotify(ctx, priority, event, data) +} + +func systemNotify(ctx context.Context, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) { // userId - Notify(notifyAdminUsers, false, priority, event, data) + notify(ctx, notifyAdminUsers, false, priority, event, data) // groupId - Notify(notifyAdminGroups, true, priority, event, data) + notify(ctx, notifyAdminGroups, true, priority, event, data) } func NotifyGeneralSystemError(data jsonutils.JSONObject) { - SystemNotify(notify.NotifyPriorityCritical, SYSTEM_ERROR, data) + notifyGeneralSystemError(context.Background(), data) +} + +func NotifyGeneralSystemErrorWithCtx(ctx context.Context, data jsonutils.JSONObject) { + notifyGeneralSystemError(ctx, data) +} + +func notifyGeneralSystemError(ctx context.Context, data jsonutils.JSONObject) { + systemNotify(ctx, npk.NotifyPriorityCritical, SYSTEM_ERROR, data) } type SSystemEventMsg struct { @@ -230,6 +310,14 @@ type SSystemEventMsg struct { } func NotifySystemError(idstr string, name string, event string, reason string) { + notifySystemError(context.Background(), idstr, name, event, reason) +} + +func NotifySystemErrorWithCtx(ctx context.Context, idstr string, name string, event string, reason string) { + notifySystemError(ctx, idstr, name, event, reason) +} + +func notifySystemError(ctx context.Context, idstr string, name string, event string, reason string) { msg := SSystemEventMsg{ Id: idstr, Name: name, @@ -237,10 +325,18 @@ func NotifySystemError(idstr string, name string, event string, reason string) { Reason: reason, Created: time.Now(), } - SystemNotify(notify.NotifyPriorityCritical, SYSTEM_ERROR, jsonutils.Marshal(msg)) + systemNotify(ctx, npk.NotifyPriorityCritical, SYSTEM_ERROR, jsonutils.Marshal(msg)) } func NotifySystemWarning(idstr string, name string, event string, reason string) { + notifySystemWarning(context.Background(), idstr, name, event, reason) +} + +func NotifySystemWarningWithCtx(ctx context.Context, idstr string, name string, event string, reason string) { + notifySystemWarning(ctx, idstr, name, event, reason) +} + +func notifySystemWarning(ctx context.Context, idstr string, name string, event string, reason string) { msg := SSystemEventMsg{ Id: idstr, Name: name, @@ -248,7 +344,7 @@ func NotifySystemWarning(idstr string, name string, event string, reason string) Reason: reason, Created: time.Now(), } - SystemNotify(notify.NotifyPriorityImportant, SYSTEM_WARNING, jsonutils.Marshal(msg)) + systemNotify(ctx, npk.NotifyPriorityImportant, SYSTEM_WARNING, jsonutils.Marshal(msg)) } func parseIdName(idName string) (string, string) { diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index 818bff17e6..e534f69173 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -2286,7 +2286,7 @@ func (manager *SDiskManager) AutoDiskSnapshot(ctx context.Context, userCred mccl onFail: db.OpsLog.LogEvent(disk, db.ACT_DISK_AUTO_SNAPSHOT_FAIL, err.Error(), userCred) reason := fmt.Sprintf("Disk auto create snapshot failed: %s", err.Error()) - notifyclient.NotifySystemError(disk.Id, disk.Name, db.ACT_DISK_AUTO_SNAPSHOT_FAIL, reason) + notifyclient.NotifySystemErrorWithCtx(ctx, disk.Id, disk.Name, db.ACT_DISK_AUTO_SNAPSHOT_FAIL, reason) } } diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 1b5f56bd84..986ccb1291 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -150,6 +150,7 @@ func (self *SGuest) PerformEvent(ctx context.Context, userCred mcclient.TokenCre db.OpsLog.LogEvent(self, db.ACT_GUEST_PANICKED, data.String(), userCred) logclient.AddSimpleActionLog(self, logclient.ACT_GUEST_PANICKED, data.String(), userCred, true) self.NotifyServerEvent( + ctx, userCred, notifyclient.SERVER_PANICKED, notify.NotifyPriorityNormal, @@ -820,7 +821,7 @@ func (self *SGuest) StartGuestDeployTask( } func (self *SGuest) NotifyServerEvent( - userCred mcclient.TokenCredential, event string, priority notify.TNotifyPriority, + ctx context.Context, userCred mcclient.TokenCredential, event string, priority notify.TNotifyPriority, loginInfo bool, kwargs *jsonutils.JSONDict, notifyAdmin bool, ) { meta, err := self.GetAllMetadata(nil) @@ -860,9 +861,9 @@ func (self *SGuest) NotifyServerEvent( } } } - notifyclient.Notify([]string{userCred.GetUserId()}, false, priority, event, kwargs) + notifyclient.NotifyWithCtx(ctx, []string{userCred.GetUserId()}, false, priority, event, kwargs) if notifyAdmin { - notifyclient.SystemNotify(priority, event, kwargs) + notifyclient.SystemNotifyWithCtx(ctx, priority, event, kwargs) } } @@ -876,7 +877,7 @@ func (self *SGuest) NotifyAdminServerEvent(ctx context.Context, event string, pr } else { kwargs.Add(jsonutils.NewString(self.ProjectId), "tenant") } - notifyclient.SystemNotify(priority, event, kwargs) + notifyclient.SystemNotifyWithCtx(ctx, priority, event, kwargs) } func (self *SGuest) StartGuestStopTask(ctx context.Context, userCred mcclient.TokenCredential, isForce bool, parentTaskId string) error { diff --git a/pkg/compute/tasks/disk_batch_create_task.go b/pkg/compute/tasks/disk_batch_create_task.go index efeb49d4a7..2df5aec8e3 100644 --- a/pkg/compute/tasks/disk_batch_create_task.go +++ b/pkg/compute/tasks/disk_batch_create_task.go @@ -129,7 +129,7 @@ func (self *DiskBatchCreateTask) SaveScheduleResult(ctx context.Context, obj ISc disk.SetStatus(self.UserCred, api.DISK_ALLOC_FAILED, err.Error()) self.SetStageFailed(ctx, jsonutils.Marshal(err)) db.OpsLog.LogEvent(disk, db.ACT_ALLOCATE_FAIL, err, self.UserCred) - notifyclient.NotifySystemError(disk.Id, disk.Name, api.DISK_ALLOC_FAILED, err.Error()) + notifyclient.NotifySystemErrorWithCtx(ctx, disk.Id, disk.Name, api.DISK_ALLOC_FAILED, err.Error()) } diskConfig, err := self.GetFirstDisk() diff --git a/pkg/compute/tasks/elasticcache_account_create_task.go b/pkg/compute/tasks/elasticcache_account_create_task.go index cb358598cb..b4cd8747c0 100644 --- a/pkg/compute/tasks/elasticcache_account_create_task.go +++ b/pkg/compute/tasks/elasticcache_account_create_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheAccountCreateTask) taskFail(ctx context.Context, elastic elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_ACCOUNT_STATUS_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_ACCOUNT_STATUS_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_ACCOUNT_STATUS_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_account_delete_task.go b/pkg/compute/tasks/elasticcache_account_delete_task.go index 1aa17a5c04..3c02e1f30b 100644 --- a/pkg/compute/tasks/elasticcache_account_delete_task.go +++ b/pkg/compute/tasks/elasticcache_account_delete_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheAccountDeleteTask) taskFail(ctx context.Context, ea *mod ea.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_ACCOUNT_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(ea, db.ACT_DELETE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, ea, logclient.ACT_DELETE, reason, self.UserCred, false) - notifyclient.NotifySystemError(ea.Id, ea.Name, api.ELASTIC_CACHE_ACCOUNT_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, ea.Id, ea.Name, api.ELASTIC_CACHE_ACCOUNT_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_account_reset_password_task.go b/pkg/compute/tasks/elasticcache_account_reset_password_task.go index 3021122c47..294556269e 100644 --- a/pkg/compute/tasks/elasticcache_account_reset_password_task.go +++ b/pkg/compute/tasks/elasticcache_account_reset_password_task.go @@ -45,7 +45,7 @@ func (self *ElasticcacheAccountResetPasswordTask) taskFail(ctx context.Context, } db.OpsLog.LogEvent(ea, db.ACT_RESET_PASSWORD, reason, self.UserCred) logclient.AddActionLogWithStartable(self, ea, logclient.ACT_RESET_PASSWORD, reason, self.UserCred, false) - notifyclient.NotifySystemError(ea.Id, ea.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, ea.Id, ea.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_acl_create_task.go b/pkg/compute/tasks/elasticcache_acl_create_task.go index 5f87b37935..5fcd1430e2 100644 --- a/pkg/compute/tasks/elasticcache_acl_create_task.go +++ b/pkg/compute/tasks/elasticcache_acl_create_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheAclCreateTask) taskFail(ctx context.Context, ea *models. ea.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_ACL_STATUS_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(ea, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, ea, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(ea.Id, ea.Name, api.ELASTIC_CACHE_ACL_STATUS_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, ea.Id, ea.Name, api.ELASTIC_CACHE_ACL_STATUS_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_acl_delete_task.go b/pkg/compute/tasks/elasticcache_acl_delete_task.go index 96e63e8cf7..d6edbb61bd 100644 --- a/pkg/compute/tasks/elasticcache_acl_delete_task.go +++ b/pkg/compute/tasks/elasticcache_acl_delete_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheAclDeleteTask) taskFail(ctx context.Context, ea *models. ea.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_ACL_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(ea, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, ea, logclient.ACT_DELETE, reason, self.UserCred, false) - notifyclient.NotifySystemError(ea.Id, ea.Name, api.ELASTIC_CACHE_ACL_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, ea.Id, ea.Name, api.ELASTIC_CACHE_ACL_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_acl_update_task.go b/pkg/compute/tasks/elasticcache_acl_update_task.go index 61ecd39ac1..5d240aaa24 100644 --- a/pkg/compute/tasks/elasticcache_acl_update_task.go +++ b/pkg/compute/tasks/elasticcache_acl_update_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheAclUpdateTask) taskFail(ctx context.Context, ea *models. ea.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_ACL_STATUS_UPDATE_FAILED, reason.String()) db.OpsLog.LogEvent(ea, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, ea, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(ea.Id, ea.Name, api.ELASTIC_CACHE_ACL_STATUS_UPDATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, ea.Id, ea.Name, api.ELASTIC_CACHE_ACL_STATUS_UPDATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go b/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go index 107a0cf702..ddae60026b 100644 --- a/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go +++ b/pkg/compute/tasks/elasticcache_allocate_public_connection_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheAllocatePublicConnectionTask) taskFail(ctx context.Conte elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGING, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_ALLOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_backup_create_task.go b/pkg/compute/tasks/elasticcache_backup_create_task.go index 9d430d6f9f..378777ac40 100644 --- a/pkg/compute/tasks/elasticcache_backup_create_task.go +++ b/pkg/compute/tasks/elasticcache_backup_create_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheBackupCreateTask) taskFail(ctx context.Context, elasticc elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go b/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go index 1ac09d0f6f..806f974eb2 100644 --- a/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go +++ b/pkg/compute/tasks/elasticcache_backup_restore_instance_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheBackupRestoreInstanceTask) taskFail(ctx context.Context, eb.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(eb, db.ACT_CONVERT_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, eb, logclient.ACT_RESTORE, reason, self.UserCred, false) - notifyclient.NotifySystemError(eb.Id, eb.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, eb.Id, eb.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_change_spec_task.go b/pkg/compute/tasks/elasticcache_change_spec_task.go index 142c55358d..81e84f1602 100644 --- a/pkg/compute/tasks/elasticcache_change_spec_task.go +++ b/pkg/compute/tasks/elasticcache_change_spec_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheChangeSpecTask) taskFail(ctx context.Context, ec *models ec.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) db.OpsLog.LogEvent(ec, db.ACT_CHANGE_FLAVOR, reason, self.UserCred) logclient.AddActionLogWithStartable(self, ec, logclient.ACT_VM_CHANGE_FLAVOR, reason, self.UserCred, false) - notifyclient.NotifySystemError(ec.Id, ec.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, ec.Id, ec.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_create_task.go b/pkg/compute/tasks/elasticcache_create_task.go index ea6d4e07cf..abe95c20af 100644 --- a/pkg/compute/tasks/elasticcache_create_task.go +++ b/pkg/compute/tasks/elasticcache_create_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheCreateTask) taskFail(ctx context.Context, elasticcache * elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_delete_task.go b/pkg/compute/tasks/elasticcache_delete_task.go index 85740be192..70f13d77eb 100644 --- a/pkg/compute/tasks/elasticcache_delete_task.go +++ b/pkg/compute/tasks/elasticcache_delete_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheDeleteTask) taskFail(ctx context.Context, elasticcache * elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RELEASE_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_DELETE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_RELEASE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_RELEASE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_flush_instance.go b/pkg/compute/tasks/elasticcache_flush_instance.go index 120b1ec05e..77d67ccc61 100644 --- a/pkg/compute/tasks/elasticcache_flush_instance.go +++ b/pkg/compute/tasks/elasticcache_flush_instance.go @@ -40,7 +40,7 @@ func (self *ElasticcacheFlushInstanceTask) taskFail(ctx context.Context, elastic elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_FLUSHING_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_FLUSH_INSTANCE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_FLUSH_INSTANCE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_FLUSHING_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_FLUSHING_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_parameter_update_task.go b/pkg/compute/tasks/elasticcache_parameter_update_task.go index 5701ad8352..1ad8363389 100644 --- a/pkg/compute/tasks/elasticcache_parameter_update_task.go +++ b/pkg/compute/tasks/elasticcache_parameter_update_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheParameterUpdateTask) taskFail(ctx context.Context, ep *m ep.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_PARAMETER_STATUS_UPDATE_FAILED, reason.String()) db.OpsLog.LogEvent(ep, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, ep, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(ep.Id, ep.Name, api.ELASTIC_CACHE_PARAMETER_STATUS_UPDATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, ep.Id, ep.Name, api.ELASTIC_CACHE_PARAMETER_STATUS_UPDATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_release_public_connection_task.go b/pkg/compute/tasks/elasticcache_release_public_connection_task.go index 508f0fadb3..7a3d1bd70c 100644 --- a/pkg/compute/tasks/elasticcache_release_public_connection_task.go +++ b/pkg/compute/tasks/elasticcache_release_public_connection_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheReleasePublicConnectionTask) taskFail(ctx context.Contex elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGING, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_restart_task.go b/pkg/compute/tasks/elasticcache_restart_task.go index e25557be37..02ec74c695 100644 --- a/pkg/compute/tasks/elasticcache_restart_task.go +++ b/pkg/compute/tasks/elasticcache_restart_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheRestartTask) taskFail(ctx context.Context, elasticcache elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_RESTART_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_RESTART_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_VM_RESTART, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_RESTART_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_RESTART_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_set_maintain_time_task.go b/pkg/compute/tasks/elasticcache_set_maintain_time_task.go index 38f8eff737..67ef53d601 100644 --- a/pkg/compute/tasks/elasticcache_set_maintain_time_task.go +++ b/pkg/compute/tasks/elasticcache_set_maintain_time_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheSetMaintainTimeTask) taskFail(ctx context.Context, elast elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_sync_task.go b/pkg/compute/tasks/elasticcache_sync_task.go index 6c06bbf58f..31d0c6e878 100644 --- a/pkg/compute/tasks/elasticcache_sync_task.go +++ b/pkg/compute/tasks/elasticcache_sync_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheSyncTask) taskFail(ctx context.Context, elasticcache *mo elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_SYNC_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_SYNC_CONF, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_SYNC_CONF, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_SYNC_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_SYNC_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_update_auth_mode_task.go b/pkg/compute/tasks/elasticcache_update_auth_mode_task.go index 744cbef2c5..d689087078 100644 --- a/pkg/compute/tasks/elasticcache_update_auth_mode_task.go +++ b/pkg/compute/tasks/elasticcache_update_auth_mode_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheUpdateAuthModeTask) taskFail(ctx context.Context, elasti elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/elasticcache_update_backup_policy_task.go b/pkg/compute/tasks/elasticcache_update_backup_policy_task.go index 170fd8b3be..82d7479b17 100644 --- a/pkg/compute/tasks/elasticcache_update_backup_policy_task.go +++ b/pkg/compute/tasks/elasticcache_update_backup_policy_task.go @@ -40,7 +40,7 @@ func (self *ElasticcacheUpdateBackupPolicyTask) taskFail(ctx context.Context, el elasticcache.SetStatus(self.GetUserCred(), api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) db.OpsLog.LogEvent(elasticcache, db.ACT_UPDATE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, elasticcache, logclient.ACT_UPDATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, elasticcache.Id, elasticcache.Name, api.ELASTIC_CACHE_STATUS_CHANGE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/guest_batch_create_task.go b/pkg/compute/tasks/guest_batch_create_task.go index d5d3bd78e3..4dffe85c68 100644 --- a/pkg/compute/tasks/guest_batch_create_task.go +++ b/pkg/compute/tasks/guest_batch_create_task.go @@ -277,7 +277,7 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS self.clearPendingUsage(ctx, guest) db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred) logclient.AddActionLogWithStartable(self, obj, logclient.ACT_ALLOCATE, err, self.GetUserCred(), false) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_CREATE_FAILED, err.Error()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_CREATE_FAILED, err.Error()) self.SetStageFailed(ctx, jsonutils.Marshal(err)) } } diff --git a/pkg/compute/tasks/guest_create_task.go b/pkg/compute/tasks/guest_create_task.go index d9bc2768dc..7ded0ea8ce 100644 --- a/pkg/compute/tasks/guest_create_task.go +++ b/pkg/compute/tasks/guest_create_task.go @@ -69,7 +69,7 @@ func (self *GuestCreateTask) OnDiskPreparedFailed(ctx context.Context, obj db.IS guest.SetStatus(self.UserCred, api.VM_DISK_FAILED, "allocation failed") db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, data, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_ALLOCATE, data, self.UserCred, false) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_DISK_FAILED, data.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_DISK_FAILED, data.String()) self.SetStageFailed(ctx, data) } @@ -98,7 +98,7 @@ func (self *GuestCreateTask) OnCdromPreparedFailed(ctx context.Context, obj db.I guest.SetStatus(self.UserCred, api.VM_DISK_FAILED, "") db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, data, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_ALLOCATE, data, self.UserCred, false) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_DISK_FAILED, fmt.Sprintf("cdrom_failed %s", data)) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_DISK_FAILED, fmt.Sprintf("cdrom_failed %s", data)) self.SetStageFailed(ctx, data) } @@ -141,7 +141,7 @@ func (self *GuestCreateTask) OnDeployGuestDescComplete(ctx context.Context, obj func (self *GuestCreateTask) notifyServerCreated(ctx context.Context, guest *models.SGuest) { guest.NotifyServerEvent( - self.UserCred, notifyclient.SERVER_CREATED, + ctx, self.UserCred, notifyclient.SERVER_CREATED, notify.NotifyPriorityImportant, true, nil, false, ) guest.NotifyAdminServerEvent(ctx, notifyclient.SERVER_CREATED_ADMIN, notify.NotifyPriorityImportant) @@ -152,7 +152,7 @@ func (self *GuestCreateTask) OnDeployGuestDescCompleteFailed(ctx context.Context guest.SetStatus(self.UserCred, api.VM_DEPLOY_FAILED, "deploy_failed") db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, data, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_ALLOCATE, data, self.UserCred, false) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_DEPLOY_FAILED, data.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_DEPLOY_FAILED, data.String()) self.SetStageFailed(ctx, data) } @@ -193,7 +193,7 @@ func (self *GuestCreateTask) OnDeployEipCompleteFailed(ctx context.Context, obj guest.SetStatus(self.UserCred, api.VM_ASSOCIATE_EIP_FAILED, "deploy_failed") db.OpsLog.LogEvent(guest, db.ACT_EIP_ATTACH, data, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_EIP_ASSOCIATE, data, self.UserCred, false) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_ASSOCIATE_EIP_FAILED, data.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_ASSOCIATE_EIP_FAILED, data.String()) self.SetStageFailed(ctx, data) } diff --git a/pkg/compute/tasks/guest_delete_task.go b/pkg/compute/tasks/guest_delete_task.go index f2e004817c..4071ff8eba 100644 --- a/pkg/compute/tasks/guest_delete_task.go +++ b/pkg/compute/tasks/guest_delete_task.go @@ -321,6 +321,7 @@ func (self *GuestDeleteTask) DeleteGuest(ctx context.Context, guest *models.SGue func (self *GuestDeleteTask) NotifyServerDeleted(ctx context.Context, guest *models.SGuest) { guest.NotifyServerEvent( + ctx, self.UserCred, notifyclient.SERVER_DELETED, notify.NotifyPriorityImportant, diff --git a/pkg/compute/tasks/guest_live_migrate_task.go b/pkg/compute/tasks/guest_live_migrate_task.go index a6a45ade80..7ddddfa07d 100644 --- a/pkg/compute/tasks/guest_live_migrate_task.go +++ b/pkg/compute/tasks/guest_live_migrate_task.go @@ -475,7 +475,7 @@ func (self *GuestMigrateTask) TaskFailed(ctx context.Context, guest *models.SGue db.OpsLog.LogEvent(guest, db.ACT_MIGRATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, reason, self.UserCred, false) self.SetStageFailed(ctx, reason) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_MIGRATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_MIGRATE_FAILED, reason.String()) } //ManagedGuestMigrateTask @@ -527,7 +527,7 @@ func (self *ManagedGuestMigrateTask) OnMigrateCompleteFailed(ctx context.Context db.OpsLog.LogEvent(guest, db.ACT_MIGRATE_FAIL, data, self.UserCred) logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, data, self.UserCred, false) self.SetStageFailed(ctx, data) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_MIGRATE_FAILED, data.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_MIGRATE_FAILED, data.String()) } //ManagedGuestLiveMigrateTask @@ -565,5 +565,5 @@ func (self *ManagedGuestLiveMigrateTask) OnMigrateCompleteFailed(ctx context.Con db.OpsLog.LogEvent(guest, db.ACT_MIGRATE_FAIL, data, self.UserCred) logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, data, self.UserCred, false) self.SetStageFailed(ctx, data) - notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_MIGRATE_FAILED, data.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.Id, guest.Name, api.VM_MIGRATE_FAILED, data.String()) } diff --git a/pkg/compute/tasks/guest_rebuild_root_task.go b/pkg/compute/tasks/guest_rebuild_root_task.go index 3d27733ef4..ba40ae85f4 100644 --- a/pkg/compute/tasks/guest_rebuild_root_task.go +++ b/pkg/compute/tasks/guest_rebuild_root_task.go @@ -177,6 +177,7 @@ func (self *GuestRebuildRootTask) OnRebuildAllDisksComplete(ctx context.Context, } db.OpsLog.LogEvent(guest, db.ACT_REBUILD_ROOT, "", self.UserCred) guest.NotifyServerEvent( + ctx, self.UserCred, notifyclient.SERVER_REBUILD_ROOT, notify.NotifyPriorityImportant, diff --git a/pkg/compute/tasks/instance_snapshot_create_task.go b/pkg/compute/tasks/instance_snapshot_create_task.go index f6d2fddd71..5bbc733de8 100644 --- a/pkg/compute/tasks/instance_snapshot_create_task.go +++ b/pkg/compute/tasks/instance_snapshot_create_task.go @@ -64,7 +64,7 @@ func (self *InstanceSnapshotCreateTask) taskFail( db.OpsLog.LogEvent(isp, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, isp, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(isp.GetId(), isp.Name, compute.INSTANCE_SNAPSHOT_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, isp.GetId(), isp.Name, compute.INSTANCE_SNAPSHOT_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/instance_snapshot_reset_task.go b/pkg/compute/tasks/instance_snapshot_reset_task.go index ff426b3f02..63943006d6 100644 --- a/pkg/compute/tasks/instance_snapshot_reset_task.go +++ b/pkg/compute/tasks/instance_snapshot_reset_task.go @@ -45,7 +45,7 @@ func (self *InstanceSnapshotResetTask) taskFail( db.OpsLog.LogEvent(guest, db.ACT_VM_RESET_SNAPSHOT_FAILED, reason, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_RESET, reason, self.UserCred, false) - notifyclient.NotifySystemError(guest.GetId(), isp.Name, compute.VM_SNAPSHOT_RESET_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, guest.GetId(), isp.Name, compute.VM_SNAPSHOT_RESET_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_acl_create_task.go b/pkg/compute/tasks/loadbalancer_acl_create_task.go index 60041fcee9..40bb81ebb0 100644 --- a/pkg/compute/tasks/loadbalancer_acl_create_task.go +++ b/pkg/compute/tasks/loadbalancer_acl_create_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerAclCreateTask) taskFail(ctx context.Context, lbacl *mode lbacl.SetStatus(self.GetUserCred(), api.LB_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(lbacl, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, api.LB_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbacl.Id, lbacl.Name, api.LB_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_acl_delete_task.go b/pkg/compute/tasks/loadbalancer_acl_delete_task.go index 37d77ba5ac..92e8f328ba 100644 --- a/pkg/compute/tasks/loadbalancer_acl_delete_task.go +++ b/pkg/compute/tasks/loadbalancer_acl_delete_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerAclDeleteTask) taskFail(ctx context.Context, lbacl *mode lbacl.SetStatus(self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(lbacl, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbacl.Id, lbacl.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_acl_sync_task.go b/pkg/compute/tasks/loadbalancer_acl_sync_task.go index 356b026ef1..24ac71225b 100644 --- a/pkg/compute/tasks/loadbalancer_acl_sync_task.go +++ b/pkg/compute/tasks/loadbalancer_acl_sync_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerAclSyncTask) taskFail(ctx context.Context, lbacl *models lbacl.SetStatus(self.GetUserCred(), api.LB_SYNC_CONF_FAILED, reason.String()) db.OpsLog.LogEvent(lbacl, db.ACT_SYNC_CONF, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_SYNC_CONF, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, api.LB_SYNC_CONF_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbacl.Id, lbacl.Name, api.LB_SYNC_CONF_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_backend_create_task.go b/pkg/compute/tasks/loadbalancer_backend_create_task.go index 9a0c5e59eb..7bc99bc89d 100644 --- a/pkg/compute/tasks/loadbalancer_backend_create_task.go +++ b/pkg/compute/tasks/loadbalancer_backend_create_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerBackendCreateTask) taskFail(ctx context.Context, lbb *mo lbb.SetStatus(self.GetUserCred(), api.LB_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(lbb, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbb, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbb.Id, lbb.Name, api.LB_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbb.Id, lbb.Name, api.LB_CREATE_FAILED, reason.String()) lbbg := lbb.GetLoadbalancerBackendGroup() if lbbg != nil { logclient.AddActionLogWithStartable(self, lbbg, logclient.ACT_LB_ADD_BACKEND, reason, self.UserCred, false) diff --git a/pkg/compute/tasks/loadbalancer_backend_sync_task.go b/pkg/compute/tasks/loadbalancer_backend_sync_task.go index 6de94683b8..0b6c069fc7 100644 --- a/pkg/compute/tasks/loadbalancer_backend_sync_task.go +++ b/pkg/compute/tasks/loadbalancer_backend_sync_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerBackendSyncTask) taskFail(ctx context.Context, lbb *mode lbb.SetStatus(self.GetUserCred(), api.LB_SYNC_CONF_FAILED, reason.String()) db.OpsLog.LogEvent(lbb, db.ACT_SYNC_CONF, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbb, logclient.ACT_SYNC_CONF, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbb.Id, lbb.Name, api.LB_SYNC_CONF_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbb.Id, lbb.Name, api.LB_SYNC_CONF_FAILED, reason.String()) lbbg := lbb.GetLoadbalancerBackendGroup() if lbbg != nil { logclient.AddActionLogWithStartable(self, lbbg, logclient.ACL_LB_SYNC_BACKEND_CONF, reason, self.UserCred, false) diff --git a/pkg/compute/tasks/loadbalancer_backendgroup_create_task.go b/pkg/compute/tasks/loadbalancer_backendgroup_create_task.go index ed3546f520..26df81304d 100644 --- a/pkg/compute/tasks/loadbalancer_backendgroup_create_task.go +++ b/pkg/compute/tasks/loadbalancer_backendgroup_create_task.go @@ -56,7 +56,7 @@ func (self *LoadbalancerLoadbalancerBackendGroupCreateTask) taskFail(ctx context lbacl.SetStatus(self.GetUserCred(), api.LB_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(lbacl, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbacl, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbacl.Id, lbacl.Name, api.LB_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbacl.Id, lbacl.Name, api.LB_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_backendgroup_delete_task.go b/pkg/compute/tasks/loadbalancer_backendgroup_delete_task.go index 88df0aff1d..8185e80b2e 100644 --- a/pkg/compute/tasks/loadbalancer_backendgroup_delete_task.go +++ b/pkg/compute/tasks/loadbalancer_backendgroup_delete_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerBackendGroupDeleteTask) taskFail(ctx context.Context, lb lbbg.SetStatus(self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(lbbg, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbbg, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbbg.Id, lbbg.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbbg.Id, lbbg.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_certificate_create_task.go b/pkg/compute/tasks/loadbalancer_certificate_create_task.go index c624c2a094..e8d7851648 100644 --- a/pkg/compute/tasks/loadbalancer_certificate_create_task.go +++ b/pkg/compute/tasks/loadbalancer_certificate_create_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerCertificateCreateTask) taskFail(ctx context.Context, lbc lbcert.SetStatus(self.GetUserCred(), api.LB_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(lbcert, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbcert.Id, lbcert.Name, api.LB_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbcert.Id, lbcert.Name, api.LB_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_certificate_delete_task.go b/pkg/compute/tasks/loadbalancer_certificate_delete_task.go index 9edeca2745..05b319a2a1 100644 --- a/pkg/compute/tasks/loadbalancer_certificate_delete_task.go +++ b/pkg/compute/tasks/loadbalancer_certificate_delete_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerCertificateDeleteTask) taskFail(ctx context.Context, lbc lbcert.SetStatus(self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(lbcert, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbcert, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbcert.Id, lbcert.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbcert.Id, lbcert.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_create_task.go b/pkg/compute/tasks/loadbalancer_create_task.go index 245b278c25..e825597679 100644 --- a/pkg/compute/tasks/loadbalancer_create_task.go +++ b/pkg/compute/tasks/loadbalancer_create_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerCreateTask) taskFail(ctx context.Context, lb *models.SLo lb.SetStatus(self.GetUserCred(), api.LB_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(lb, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lb, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lb.Id, lb.Name, api.LB_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lb.Id, lb.Name, api.LB_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_delete_task.go b/pkg/compute/tasks/loadbalancer_delete_task.go index 87e53613f9..2b8abf7216 100644 --- a/pkg/compute/tasks/loadbalancer_delete_task.go +++ b/pkg/compute/tasks/loadbalancer_delete_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerDeleteTask) taskFail(ctx context.Context, lb *models.SLo lb.SetStatus(self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(lb, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lb, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lb.Id, lb.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lb.Id, lb.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_listener_create_task.go b/pkg/compute/tasks/loadbalancer_listener_create_task.go index ad9885ba77..29c107c01e 100644 --- a/pkg/compute/tasks/loadbalancer_listener_create_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_create_task.go @@ -159,7 +159,7 @@ func (self *LoadbalancerListenerCreateTask) taskFail(ctx context.Context, lblis lblis.SetStatus(self.GetUserCred(), api.LB_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(lblis, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lblis.Id, lblis.Name, api.LB_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lblis.Id, lblis.Name, api.LB_CREATE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_listener_delete_task.go b/pkg/compute/tasks/loadbalancer_listener_delete_task.go index 9a1c284f15..1adaf0cbd3 100644 --- a/pkg/compute/tasks/loadbalancer_listener_delete_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_delete_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerListenerDeleteTask) taskFail(ctx context.Context, lblis lblis.SetStatus(self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(lblis, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lblis.Id, lblis.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lblis.Id, lblis.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_listener_rule_create_task.go b/pkg/compute/tasks/loadbalancer_listener_rule_create_task.go index 91b8be837b..670bdf4097 100644 --- a/pkg/compute/tasks/loadbalancer_listener_rule_create_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_rule_create_task.go @@ -206,7 +206,7 @@ func (self *LoadbalancerListenerRuleCreateTask) taskFail(ctx context.Context, lb lbr.SetStatus(self.GetUserCred(), api.LB_CREATE_FAILED, reason.String()) db.OpsLog.LogEvent(lbr, db.ACT_ALLOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbr, logclient.ACT_CREATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbr.Id, lbr.Name, api.LB_CREATE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbr.Id, lbr.Name, api.LB_CREATE_FAILED, reason.String()) lblis := lbr.GetLoadbalancerListener() if lblis != nil { logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_LB_ADD_LISTENER_RULE, reason, self.UserCred, false) diff --git a/pkg/compute/tasks/loadbalancer_listener_rule_delete_task.go b/pkg/compute/tasks/loadbalancer_listener_rule_delete_task.go index 668b3ced70..5278151694 100644 --- a/pkg/compute/tasks/loadbalancer_listener_rule_delete_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_rule_delete_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerListenerRuleDeleteTask) taskFail(ctx context.Context, lb lbr.SetStatus(self.GetUserCred(), api.LB_STATUS_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(lbr, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lbr, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lbr.Id, lbr.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lbr.Id, lbr.Name, api.LB_STATUS_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_listener_start_task.go b/pkg/compute/tasks/loadbalancer_listener_start_task.go index 1afe81e111..e402afbf75 100644 --- a/pkg/compute/tasks/loadbalancer_listener_start_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_start_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerListenerStartTask) taskFail(ctx context.Context, lblis * lblis.SetStatus(self.GetUserCred(), api.LB_STATUS_DISABLED, reason.String()) db.OpsLog.LogEvent(lblis, db.ACT_ENABLE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_ENABLE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lblis.Id, lblis.Name, api.LB_STATUS_DISABLED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lblis.Id, lblis.Name, api.LB_STATUS_DISABLED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_listener_stop_task.go b/pkg/compute/tasks/loadbalancer_listener_stop_task.go index 701de1c9bc..5b7b1f85e7 100644 --- a/pkg/compute/tasks/loadbalancer_listener_stop_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_stop_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerListenerStopTask) taskFail(ctx context.Context, lblis *m lblis.SetStatus(self.GetUserCred(), api.LB_STATUS_ENABLED, reason.String()) db.OpsLog.LogEvent(lblis, db.ACT_DISABLE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_DISABLE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lblis.Id, lblis.Name, api.LB_STATUS_ENABLED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lblis.Id, lblis.Name, api.LB_STATUS_ENABLED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_listener_sync_task.go b/pkg/compute/tasks/loadbalancer_listener_sync_task.go index 39918df64e..5cd994ed9e 100644 --- a/pkg/compute/tasks/loadbalancer_listener_sync_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_sync_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerListenerSyncTask) taskFail(ctx context.Context, lblis *m lblis.SetStatus(self.GetUserCred(), api.LB_SYNC_CONF_FAILED, reason.String()) db.OpsLog.LogEvent(lblis, db.ACT_SYNC_CONF, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_SYNC_CONF, reason, self.UserCred, false) - notifyclient.NotifySystemError(lblis.Id, lblis.Name, api.LB_SYNC_CONF_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lblis.Id, lblis.Name, api.LB_SYNC_CONF_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_listener_syncstatus_task.go b/pkg/compute/tasks/loadbalancer_listener_syncstatus_task.go index b2085ea274..71884ba684 100644 --- a/pkg/compute/tasks/loadbalancer_listener_syncstatus_task.go +++ b/pkg/compute/tasks/loadbalancer_listener_syncstatus_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerListenerSyncstatusTask) taskFail(ctx context.Context, lb lblis.SetStatus(self.GetUserCred(), api.LB_STATUS_UNKNOWN, reason.String()) db.OpsLog.LogEvent(lblis, db.ACT_SYNC_STATUS, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lblis, logclient.ACT_SYNC_STATUS, reason, self.UserCred, false) - notifyclient.NotifySystemError(lblis.Id, lblis.Name, api.LB_SYNC_CONF_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lblis.Id, lblis.Name, api.LB_SYNC_CONF_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_start_task.go b/pkg/compute/tasks/loadbalancer_start_task.go index 2595a3877d..290acf853d 100644 --- a/pkg/compute/tasks/loadbalancer_start_task.go +++ b/pkg/compute/tasks/loadbalancer_start_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerStartTask) taskFail(ctx context.Context, lb *models.SLoa lb.SetStatus(self.GetUserCred(), api.LB_STATUS_DISABLED, reason.String()) db.OpsLog.LogEvent(lb, db.ACT_ENABLE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lb, logclient.ACT_ENABLE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lb.Id, lb.Name, api.LB_STATUS_DISABLED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lb.Id, lb.Name, api.LB_STATUS_DISABLED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_stop_task.go b/pkg/compute/tasks/loadbalancer_stop_task.go index 01c651c534..51524cc358 100644 --- a/pkg/compute/tasks/loadbalancer_stop_task.go +++ b/pkg/compute/tasks/loadbalancer_stop_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerStopTask) taskFail(ctx context.Context, lb *models.SLoad lb.SetStatus(self.GetUserCred(), api.LB_STATUS_ENABLED, reason.String()) db.OpsLog.LogEvent(lb, db.ACT_DISABLE, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lb, logclient.ACT_DISABLE, reason, self.UserCred, false) - notifyclient.NotifySystemError(lb.Id, lb.Name, api.LB_STATUS_ENABLED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lb.Id, lb.Name, api.LB_STATUS_ENABLED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/loadbalancer_syncstatus_task.go b/pkg/compute/tasks/loadbalancer_syncstatus_task.go index 4713419869..10944a8d3c 100644 --- a/pkg/compute/tasks/loadbalancer_syncstatus_task.go +++ b/pkg/compute/tasks/loadbalancer_syncstatus_task.go @@ -40,7 +40,7 @@ func (self *LoadbalancerSyncstatusTask) taskFail(ctx context.Context, lb *models lb.SetStatus(self.GetUserCred(), api.LB_STATUS_UNKNOWN, reason.String()) db.OpsLog.LogEvent(lb, db.ACT_SYNC_STATUS, reason, self.UserCred) logclient.AddActionLogWithStartable(self, lb, logclient.ACT_SYNC_STATUS, reason, self.UserCred, false) - notifyclient.NotifySystemError(lb.Id, lb.Name, api.LB_SYNC_CONF_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, lb.Id, lb.Name, api.LB_SYNC_CONF_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/schedule.go b/pkg/compute/tasks/schedule.go index cd3111b0f2..ef4034ba9e 100644 --- a/pkg/compute/tasks/schedule.go +++ b/pkg/compute/tasks/schedule.go @@ -70,7 +70,7 @@ func (self *SSchedTask) OnScheduleFailCallback(ctx context.Context, obj ISchedul obj.SetStatus(self.GetUserCred(), api.VM_SCHEDULE_FAILED, reason.String()) db.OpsLog.LogEvent(obj, db.ACT_ALLOCATE_FAIL, reason, self.GetUserCred()) logclient.AddActionLogWithStartable(self, obj, logclient.ACT_ALLOCATE, reason, self.GetUserCred(), false) - notifyclient.NotifySystemError(obj.GetId(), obj.GetName(), api.VM_SCHEDULE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, obj.GetId(), obj.GetName(), api.VM_SCHEDULE_FAILED, reason.String()) } func (self *SSchedTask) OnScheduleComplete(ctx context.Context, items []db.IStandaloneModel, data *jsonutils.JSONDict) { diff --git a/pkg/compute/tasks/snapshot_policy_delete_task.go b/pkg/compute/tasks/snapshot_policy_delete_task.go index 19d2d0fb93..d411364925 100644 --- a/pkg/compute/tasks/snapshot_policy_delete_task.go +++ b/pkg/compute/tasks/snapshot_policy_delete_task.go @@ -39,7 +39,7 @@ func (self *SnapshotPolicyDeleteTask) taskFail(ctx context.Context, sp *models.S sp.SetStatus(self.GetUserCred(), api.SNAPSHOT_POLICY_DELETE_FAILED, reason.String()) db.OpsLog.LogEvent(sp, db.ACT_DELOCATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, sp, logclient.ACT_DELOCATE, reason, self.UserCred, false) - notifyclient.NotifySystemError(sp.Id, sp.Name, api.SNAPSHOT_POLICY_DELETE_FAILED, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, sp.Id, sp.Name, api.SNAPSHOT_POLICY_DELETE_FAILED, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/snapshotpolicy_disk_task.go b/pkg/compute/tasks/snapshotpolicy_disk_task.go index 074569f18a..603c965e94 100644 --- a/pkg/compute/tasks/snapshotpolicy_disk_task.go +++ b/pkg/compute/tasks/snapshotpolicy_disk_task.go @@ -57,7 +57,7 @@ func (self *SnapshotPolicyApplyTask) taskFail(ctx context.Context, disk *models. db.OpsLog.LogEvent(disk, db.ACT_APPLY_SNAPSHOT_POLICY_FAILED, reason, self.UserCred) logclient.AddActionLogWithStartable(self, disk, logclient.ACT_APPLY_SNAPSHOT_POLICY, reason, self.UserCred, false) - notifyclient.NotifySystemError(disk.GetId(), disk.Name, compute.DISK_APPLY_SNAPSHOT_FAIL, reason.String()) + notifyclient.NotifySystemErrorWithCtx(ctx, disk.GetId(), disk.Name, compute.DISK_APPLY_SNAPSHOT_FAIL, reason.String()) self.SetStageFailed(ctx, reason) } diff --git a/pkg/httperrors/httperrors.go b/pkg/httperrors/httperrors.go index 2e213488f6..3b1adecd9f 100644 --- a/pkg/httperrors/httperrors.go +++ b/pkg/httperrors/httperrors.go @@ -100,15 +100,7 @@ func formatDetails(ctx context.Context, errData httputils.Error, msg string) str if errData.Id == "" { details = msg } else { - var ( - langv = ctx.Value(ctxLangKey) - lang language.Tag - ) - if langv != nil { - lang = langv.(language.Tag) - } else { - lang = language.English - } + lang := Lang(ctx) a := make([]interface{}, len(errData.Fields)) for i := range errData.Fields { a[i] = errData.Fields[i] @@ -118,6 +110,19 @@ func formatDetails(ctx context.Context, errData httputils.Error, msg string) str return details } +func Lang(ctx context.Context) language.Tag { + var ( + langv = ctx.Value(ctxLangKey) + lang language.Tag + ) + if langv != nil { + lang = langv.(language.Tag) + } else { + lang = language.English + } + return lang +} + func HTTPError(ctx context.Context, w http.ResponseWriter, msg string, statusCode int, class string, errData httputils.Error) { details := formatDetails(ctx, errData, msg) if statusCode >= 300 && statusCode <= 400 { diff --git a/pkg/image/tasks/image_convert_task.go b/pkg/image/tasks/image_convert_task.go index de3b30c224..2bb6970d5f 100644 --- a/pkg/image/tasks/image_convert_task.go +++ b/pkg/image/tasks/image_convert_task.go @@ -61,8 +61,8 @@ func (self *ImageConvertTask) OnInit(ctx context.Context, obj db.IStandaloneMode if err == nil { kwargs.Set("os_type", jsonutils.NewString(osType.Value)) } - notifyclient.SystemNotify(notify.NotifyPriorityNormal, notifyclient.IMAGE_ACTIVED, kwargs) - notifyclient.NotifyImportant([]string{self.UserCred.GetUserId()}, false, notifyclient.IMAGE_ACTIVED, kwargs) + notifyclient.SystemNotifyWithCtx(ctx, notify.NotifyPriorityNormal, notifyclient.IMAGE_ACTIVED, kwargs) + notifyclient.NotifyImportantWithCtx(ctx, []string{self.UserCred.GetUserId()}, false, notifyclient.IMAGE_ACTIVED, kwargs) } return nil, err })