fix(region): disk fail notify (#24673)

This commit is contained in:
屈轩
2026-04-14 16:27:31 +08:00
committed by GitHub
parent fc6079ed86
commit cb24c2d97e
15 changed files with 113 additions and 5 deletions
+2
View File
@@ -27,4 +27,6 @@ func init() {
cmd.Update(new(options.TopicUpdateOptions))
cmd.Show(new(options.TopicOptions))
cmd.Delete(new(options.TopicOptions))
cmd.Perform("add-actions", new(options.TopicAddActionInput))
cmd.Perform("add-resources", new(options.TopicAddResourcesInput))
}
+8
View File
@@ -94,3 +94,11 @@ type STopicCreateInput struct {
Actions []string `json:"actions"`
WebconsoleDisable bool `json:"webconsole_disable"`
}
type TopicAddActionInput struct {
Actions []string `json:"actions"`
}
type TopicAddResourcesInput struct {
Resources []string `json:"resources"`
}
@@ -138,6 +138,11 @@ func (task *DiskBatchCreateTask) SaveScheduleResult(ctx context.Context, obj uti
task.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
db.OpsLog.LogEvent(disk, db.ACT_ALLOCATE_FAIL, err, task.UserCred)
notifyclient.NotifySystemErrorWithCtx(ctx, disk.Id, disk.Name, api.DISK_ALLOC_FAILED, err.Error())
notifyclient.EventNotify(ctx, task.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionCreate,
IsFail: true,
})
}
data := utils.GetBatchParamsAtIndex(task, index)
@@ -24,6 +24,7 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"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"
)
@@ -82,5 +83,10 @@ func (self *DiskChangeStorageTypeTask) OnInit(ctx context.Context, obj db.IStand
func (self *DiskChangeStorageTypeTask) taskFail(ctx context.Context, disk *models.SDisk, err error) {
disk.SetStatus(ctx, self.GetUserCred(), api.DISK_MIGRATE_FAIL, "")
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_MIGRATE, err, self.UserCred, false)
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionMigrate,
IsFail: true,
})
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
}
@@ -102,6 +102,11 @@ func (self *DiskCreateTask) OnStorageCacheImageComplete(ctx context.Context, dis
func (self *DiskCreateTask) OnStartAllocateFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
disk.SetStatus(ctx, self.UserCred, api.DISK_ALLOC_FAILED, data.String())
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_ALLOCATE, data, self.UserCred, false)
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionCreate,
IsFail: true,
})
self.SetStageFailed(ctx, data)
}
@@ -155,6 +160,11 @@ func (self *DiskCreateTask) OnDiskReadyFailed(ctx context.Context, disk *models.
}
disk.SetStatus(ctx, self.UserCred, status, data.String())
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_ALLOCATE, data, self.UserCred, false)
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionCreate,
IsFail: true,
})
self.SetStageFailed(ctx, data)
}
@@ -231,6 +231,11 @@ func (self *DiskDeleteTask) OnGuestDiskDeleteCompleteFailed(ctx context.Context,
disk.SetStatus(ctx, self.GetUserCred(), api.DISK_DEALLOC_FAILED, reason.String())
self.SetStageFailed(ctx, reason)
db.OpsLog.LogEvent(disk, db.ACT_DELOCATE_FAIL, disk.GetShortDesc(ctx), self.GetUserCred())
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionDelete,
IsFail: true,
})
logclient.AddActionLogWithContext(ctx, disk, logclient.ACT_DELOCATE, reason, self.UserCred, false)
}
@@ -276,5 +281,10 @@ func (self *StorageDeleteRbdDiskTask) DeleteDisk(ctx context.Context, storage *m
func (self *StorageDeleteRbdDiskTask) OnDeleteDiskFailed(ctx context.Context, storage *models.SStorage, data jsonutils.JSONObject) {
deleteDisk, _ := data.GetString("delete_disk")
db.OpsLog.LogEvent(storage, db.ACT_DELETE_OBJECT, fmt.Sprintf("delete disk %s failed", deleteDisk), self.UserCred)
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: storage,
Action: notifyclient.ActionDelete,
IsFail: true,
})
self.DeleteDisk(ctx, storage, self.Params)
}
@@ -54,6 +54,11 @@ func (self *DiskResetTask) getSnapshot() (*models.SSnapshot, error) {
func (self *DiskResetTask) TaskFailed(ctx context.Context, disk *models.SDisk, reason error) {
disk.SetStatus(ctx, self.UserCred, api.DISK_READY, "")
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_RESET_DISK, reason, self.UserCred, false)
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionReset,
IsFail: true,
})
snapshot, _ := self.getSnapshot()
if snapshot != nil {
logclient.AddActionLogWithStartable(self, snapshot, logclient.ACT_RESET_DISK, reason, self.UserCred, false)
@@ -25,6 +25,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"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/mcclient"
"yunion.io/x/onecloud/pkg/util/logclient"
@@ -97,6 +98,11 @@ func (self *DiskResizeTask) OnStartResizeDiskFailed(ctx context.Context, disk *m
self.SetStageFailed(ctx, jsonutils.Marshal(reason))
db.OpsLog.LogEvent(disk, db.ACT_RESIZE_FAIL, reason, self.GetUserCred())
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_RESIZE, reason, self.UserCred, false)
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionResize,
IsFail: true,
})
}
func (self *DiskResizeTask) OnDiskResizeComplete(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
@@ -157,5 +163,10 @@ func (self *DiskResizeTask) OnDiskResizeCompleteFailed(ctx context.Context, disk
self.SetDiskReady(ctx, disk, self.GetUserCred(), data.String())
db.OpsLog.LogEvent(disk, db.ACT_RESIZE_FAIL, disk.GetShortDesc(ctx), self.UserCred)
logclient.AddActionLogWithStartable(self, disk, logclient.ACT_RESIZE, data, self.UserCred, false)
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionResize,
IsFail: true,
})
self.SetStageFailed(ctx, data)
}
@@ -24,6 +24,7 @@ import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
"yunion.io/x/onecloud/pkg/compute/models"
)
@@ -83,6 +84,11 @@ func (self *HADiskCreateTask) OnDiskReady(
func (self *HADiskCreateTask) OnBackupAllocateFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) {
disk.SetStatus(ctx, self.UserCred, api.DISK_BACKUP_ALLOC_FAILED, data.String())
notifyclient.EventNotify(ctx, self.UserCred, notifyclient.SEventNotifyParam{
Obj: disk,
Action: notifyclient.ActionCreate,
IsFail: true,
})
self.SetStageFailed(ctx, data)
}
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package disk
package dnszone
import (
"context"
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package disk
package dnszone
import (
"context"
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package disk
package dnszone
import (
"context"
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package disk
package dnszone
import (
"context"
+18
View File
@@ -118,3 +118,21 @@ type TopicCreateOptions struct {
func (rl *TopicCreateOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(rl), nil
}
type TopicAddActionInput struct {
TopicOptions
Actions []string `json:"actions"`
}
func (rl *TopicAddActionInput) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(rl), nil
}
type TopicAddResourcesInput struct {
TopicOptions
Resources []string `json:"resources"`
}
func (rl *TopicAddResourcesInput) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(rl), nil
}
+28 -1
View File
@@ -75,7 +75,7 @@ type STopic struct {
db.SEnabledStatusStandaloneResourceBase
Type string `width:"20" nullable:"false" create:"required" update:"user" list:"user"`
Results tristate.TriState `default:"true"`
Results tristate.TriState `default:"true" create:"optional" get:"user" list:"user"`
TitleCn string `length:"medium" nullable:"true" charset:"utf8" list:"user" update:"user" create:"optional"`
TitleEn string `length:"medium" nullable:"true" charset:"utf8" list:"user" update:"user" create:"optional"`
ContentCn string `length:"medium" nullable:"true" charset:"utf8" list:"user" update:"user" create:"optional"`
@@ -485,6 +485,7 @@ func initTopicElement(name string, t *STopic) {
api.TOPIC_RESOURCE_LOADBALANCER,
api.TOPIC_RESOURCE_DBINSTANCE,
api.TOPIC_RESOURCE_ELASTICCACHE,
api.TOPIC_RESOURCE_DISK,
api.TOPIC_RESOURCE_CLOUDPHONE,
)
t.addAction(
@@ -947,6 +948,32 @@ func (t *STopic) PreCheckPerformAction(
return nil
}
func (t *STopic) PerformAddActions(
ctx context.Context, userCred mcclient.TokenCredential,
query jsonutils.JSONObject, data api.TopicAddActionInput,
) (jsonutils.JSONObject, error) {
for _, action := range data.Actions {
if len(action) == 0 {
continue
}
t.addAction(notify.SAction(action))
}
return nil, nil
}
func (t *STopic) PerformAddResources(
ctx context.Context, userCred mcclient.TokenCredential,
query jsonutils.JSONObject, data api.TopicAddResourcesInput,
) (jsonutils.JSONObject, error) {
for _, resource := range data.Resources {
if len(resource) == 0 {
continue
}
t.addResources(resource)
}
return nil, nil
}
func init() {
converter = &sConverter{
resource2Value: &sync.Map{},