Merge pull request #7910 from rainzm/notify/ti

Feat & Fix of Notify
This commit is contained in:
Zexi Li
2020-09-16 11:32:41 +08:00
committed by GitHub
111 changed files with 310 additions and 146 deletions
@@ -1 +0,0 @@
您的{{ .brand }}主机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。
@@ -1 +0,0 @@
您的{{ .brand }}主机{{ .name }}已经创建成功,服务器IP地址为{{ .ips }}{{ if .account }}初始帐号为{{ .account }}{{ end }}{{ if .keypair }}访问ssh密钥为{{ .keypair }}{{ end }}{{ if .password }}初始密码为{{ .password }}{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问云主机。
@@ -1 +0,0 @@
项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经创建成功。
@@ -1 +0,0 @@
您的{{ .brand }}主机{{ .name }}已经删除。
@@ -1 +0,0 @@
项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经删除。
@@ -1 +0,0 @@
您的{{ .brand }}主机{{ .name }}系统崩溃了: {{ .reason }}
@@ -1 +0,0 @@
您的{{ .brand }}主机{{ .name }}重装系统成功,{{ if .account }}初始帐号为{{ .account }}{{ end }}{{ if .keypair }}访问密钥为{{ .keypair }}{{ end }}{{ if .password }}初始密码为{{ .password }}{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问云主机。
@@ -0,0 +1 @@
您的{{ .brand }}虚拟机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。
@@ -0,0 +1 @@
您的{{ .brand }}虚拟机{{ .name }}已经创建成功,虚拟机IP地址为{{ .ips }}{{ if .account }}初始帐号为{{ .account }}{{ end }}{{ if .keypair }}访问ssh密钥为{{ .keypair }}{{ end }}{{ if .password }}初始密码为{{ .password }}{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问虚拟机。
@@ -0,0 +1 @@
项目{{ .tenant }}的{{ .brand }}虚拟机{{ .name }}已经创建成功。
@@ -0,0 +1 @@
您的{{ .brand }}虚拟机{{ .name }}已经删除。
@@ -0,0 +1 @@
项目{{ .tenant }}的{{ .brand }}虚拟机{{ .name }}已经删除。
@@ -0,0 +1 @@
您的{{ .brand }}虚拟机{{ .name }}系统崩溃了: {{ .reason }}
@@ -0,0 +1 @@
您的{{ .brand }}虚拟机{{ .name }}重装系统成功,{{ if .account }}初始帐号为{{ .account }}{{ end }}{{ if .keypair }}访问密钥为{{ .keypair }}{{ end }}{{ if .password }}初始密码为{{ .password }}{{ end }}请使用{{ if .windows }}远程桌面连接器(RDC){{ else }}SSH{{ end }}或控制面板控制台访问虚拟机。
@@ -0,0 +1 @@
The instance type of your {{ .brand }} virtual machine {{ .name }} has been changed to: {{ index .flavor_info "cpu" }}-core CPU, {{ index .flavor_info "memory" }}M memory, {{ index .flavor_info "datadisk" }}G data disk, {{ index .flavor_info "ebw" }}M bandwidth.
@@ -0,0 +1 @@
Your {{ .brand }} virtual machine {{ .name }} has been created successfully. The VM's IP address is {{ .ips }}, {{ if .account }}initial account is {{ .account }}, {{ end }}{{ if .keypair }}the access ssh key is {{ .keypair }}, {{ end }}{{ if .password }}the initial password is {{ .password }}, {{ end }}and please use {{ if .windows }}Remote Desktop Connector (RDC){{ else }}SSH{{ end }} or the control panel console to access the VM.
@@ -0,0 +1 @@
The {{ .brand }} virtual machine {{ .name }} of the project {{ .tenant }} has been created successfully.
@@ -0,0 +1 @@
Your {{ .brand }} virtual machine {{ .name }} has been deleted.
@@ -0,0 +1 @@
The {{ .brand }} virtual machine {{ .name }} of the project {{ .tenant }} has been deleted.
@@ -0,0 +1 @@
Your {{ .brand }} virtual machine {{ .name }} system crashed: {{ .reason }}
@@ -0,0 +1 @@
Your {{ .brand }} virtual machine {{ .name }} is successfully reinstalled. The VM's {{ if .account }}initial account is {{ .account }}, {{ end }}{{ if .keypair }}the access key is {{ .keypair }}, {{ end }}{{ if .password }}the initial password is {{ .password }}, {{ end }}and please use {{ if .windows }}remote desktop connection (RDC){{ else }}SSH{{ end }} or the control panel console to access the virtual machine.
@@ -0,0 +1,6 @@
System error message
Resource: {{ .name}}
Resource ID: {{ .id }}
Event: {{ .event }}
Reason: {{ .reason }}
Time: {{ .created }}
@@ -0,0 +1,6 @@
System warning message
Resource: {{ .name}}
Resource ID: {{ .id }}
Event: {{ .event }}
Reason: {{ .reason }}
Time: {{ .created }}
@@ -1 +0,0 @@
您的{{ .brand }}主机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。
@@ -1 +0,0 @@
{{ .brand }}主机{{ .Name }}创建成功
@@ -1 +0,0 @@
项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经创建成功
@@ -1 +0,0 @@
{{ .brand }}主机{{ .name }}删除通知
@@ -1 +0,0 @@
项目{{ .tenant }}的{{ .brand }}主机{{ .name }}已经删除
@@ -1 +0,0 @@
您的{{ .brand }}主机{{ .name }}系统崩溃了
@@ -1 +0,0 @@
{{ .brand }}主机{{ .name }}重装系统成功
@@ -0,0 +1 @@
您的{{ .brand }}虚拟机{{ .name }}的套餐类型已经更改为 CPU:{{ index .flavor_info "cpu" }}核,内存:{{ index .flavor_info "memory" }}M,数据盘:{{ index .flavor_info "datadisk" }}G,带宽: {{ index .flavor_info "ebw" }}M。
@@ -0,0 +1 @@
{{ .brand }}虚拟机{{ .Name }}创建成功
@@ -0,0 +1 @@
项目{{ .tenant }}的{{ .brand }}虚拟机{{ .name }}已经创建成功
@@ -0,0 +1 @@
{{ .brand }}虚拟机{{ .name }}删除通知
@@ -0,0 +1 @@
项目{{ .tenant }}的{{ .brand }}虚拟机{{ .name }}已经删除
@@ -0,0 +1 @@
您的{{ .brand }}虚拟机{{ .name }}系统崩溃了
@@ -0,0 +1 @@
{{ .brand }}虚拟机{{ .name }}重装系统成功
@@ -0,0 +1 @@
The instance type of your {{ .brand }} virtual machine {{ .name }} has been changed to: {{ index .flavor_info "cpu" }}-core CPU, {{ index .flavor_info "memory" }}M memory, {{ index .flavor_info "datadisk" }}G data disk, {{ index .flavor_info "ebw" }}M bandwidth
@@ -0,0 +1 @@
The {{ .brand }} virtual machine {{ .Name }} created successfully
@@ -0,0 +1 @@
The {{ .brand }} virtual machine {{ .name }} of the project {{ .tenant }} has been created successfully
@@ -0,0 +1 @@
The {{ .brand }} virtual machine {{ .name }} has been deleted
@@ -0,0 +1 @@
The {{ .brand }} virtual machine {{ .name }} of the project {{ .tenant }} has been deleted
@@ -0,0 +1 @@
Your {{ .brand }} virtual machine {{ .name }} system crashed
@@ -0,0 +1 @@
The {{ .brand }} virtual machine {{ .name }} successfully reinstalled the system
@@ -0,0 +1 @@
System error message {{ .name }} {{ .event }}
@@ -0,0 +1 @@
System warning message {{ .name }} {{ .event }}
+165 -58
View File
@@ -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,29 @@ 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 NotifyError(ctx context.Context, userCred mcclient.TokenCredential, idstr, name, event, reason string) {
msg := SSystemEventMsg{
Id: idstr,
Name: name,
Event: event,
Reason: reason,
Created: time.Now(),
}
notify(ctx, []string{userCred.GetUserId()}, false, 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 +355,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) {
+1 -1
View File
@@ -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)
}
}
+5 -4
View File
@@ -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 {
+1 -1
View File
@@ -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()
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
+1 -1
View File
@@ -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)
}
@@ -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)
}
@@ -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)
}
+1 -1
View File
@@ -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))
}
}
@@ -26,6 +26,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
@@ -317,5 +318,6 @@ func (self *GuestChangeConfigTask) markStageFailed(ctx context.Context, guest *m
guest.SetStatus(self.UserCred, api.VM_CHANGE_FLAVOR_FAIL, reason.String())
db.OpsLog.LogEvent(guest, db.ACT_CHANGE_FLAVOR_FAIL, reason, self.UserCred)
logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_CHANGE_FLAVOR, reason, self.UserCred, false)
notifyclient.NotifyError(ctx, self.UserCred, guest.GetId(), guest.GetName(), logclient.ACT_VM_CHANGE_FLAVOR, reason.String())
self.SetStageFailed(ctx, reason)
}
+5 -5
View File
@@ -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)
}
+1
View File
@@ -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,
+3 -3
View File
@@ -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())
}
@@ -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,
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
@@ -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)
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
@@ -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)
}
@@ -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)
}
@@ -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)
}
@@ -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)
}

Some files were not shown because too many files have changed in this diff Show More