Files
cloudpods/pkg/monitor/tasks/resolve_unused_task.go
zhaoxiangchun 89640938f0 新加diskunused的监控
1.suggestsys_const.go 中定义规则和资源列表中涉及到一些常量
2.suggestsysalart.go 1)新增一些列来匹配重用过滤;2)
进行删除相关操作时,通过task处理;
3.driverconfig.go 中包含目前driver中可以共用的函数
4.suggestsysruledrivers.go 调整driver interface 涉及的函数
2020-04-16 16:37:46 +08:00

61 lines
2.0 KiB
Go

// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tasks
import (
"context"
"fmt"
"yunion.io/x/jsonutils"
api "yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/monitor/models"
"yunion.io/x/onecloud/pkg/util/logclient"
)
type ResolveUnusedTask struct {
taskman.STask
}
func init() {
taskman.RegisterTask(ResolveUnusedTask{})
}
func (self *ResolveUnusedTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
suggestSysAlert := obj.(*models.SSuggestSysAlert)
err := models.GetSuggestSysRuleDrivers()[suggestSysAlert.Type].Resolve(suggestSysAlert)
if err != nil {
msg := fmt.Sprintf("fail to delete EIP %s", err)
self.taskFail(ctx, suggestSysAlert, msg)
}
err = suggestSysAlert.RealDelete(ctx, self.UserCred)
if err != nil {
msg := fmt.Sprintf("fail to delete SSuggestSysAlert %s", err)
self.taskFail(ctx, suggestSysAlert, msg)
}
logclient.AddActionLogWithStartable(self, suggestSysAlert, logclient.ACT_DELETE, nil, self.UserCred, true)
self.SetStageComplete(ctx, nil)
}
func (self *ResolveUnusedTask) taskFail(ctx context.Context, alert *models.SSuggestSysAlert, msg string) {
alert.SetStatus(self.UserCred, api.EIP_UNUSED_DELETE_FAIL, msg)
db.OpsLog.LogEvent(alert, db.ACT_DELOCATE, msg, self.GetUserCred())
logclient.AddActionLogWithStartable(self, alert, logclient.ACT_DELETE, msg, self.UserCred, false)
self.SetStageFailed(ctx, msg)
return
}