mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Co-authored-by: 屈轩 <qu_xuan@icloud.com>
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
@@ -42,17 +41,17 @@ func init() {
|
||||
err error
|
||||
)
|
||||
if args.Oldsdk {
|
||||
msg := notify.SNotifyMessage{
|
||||
msg := modules.SNotifyMessage{
|
||||
Uid: args.Receivers,
|
||||
Robots: args.Robots,
|
||||
ContactType: notify.TNotifyChannel(args.ContactType),
|
||||
ContactType: modules.TNotifyChannel(args.ContactType),
|
||||
Topic: args.TOPIC,
|
||||
Priority: notify.TNotifyPriority(args.Priority),
|
||||
Priority: modules.TNotifyPriority(args.Priority),
|
||||
Msg: args.MESSAGE,
|
||||
Remark: "",
|
||||
Broadcast: false,
|
||||
}
|
||||
err = notify.Notifications.Send(s, msg)
|
||||
err = modules.Notifications.Send(s, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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 notify
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/notify"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(&modules.NotifyAction)
|
||||
cmd.List(new(options.SNotifyActionListInput))
|
||||
cmd.Create(new(options.SNotifyActionCreateInput))
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// 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 notify
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/notify"
|
||||
options "yunion.io/x/onecloud/pkg/mcclient/options/notify"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := shell.NewResourceCmd(&modules.NotifyResource)
|
||||
cmd.List(new(options.SNotifyResourceListInput))
|
||||
cmd.Create(new(options.SNotifyResourceCreateInput))
|
||||
}
|
||||
@@ -25,4 +25,8 @@ func init() {
|
||||
cmd.List(new(options.TopicListOptions))
|
||||
cmd.Update(new(options.TopicUpdateOptions))
|
||||
cmd.Show(new(options.TopicOptions))
|
||||
cmd.Perform("add-action", new(options.STopicAddActionInput))
|
||||
cmd.Perform("add-resource", new(options.STopicAddResourceInput))
|
||||
cmd.Perform("remove-action", new(options.STopicAddActionInput))
|
||||
cmd.Perform("remove-resource", new(options.STopicAddResourceInput))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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 notify
|
||||
@@ -0,0 +1,22 @@
|
||||
// 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 notify
|
||||
|
||||
import "yunion.io/x/onecloud/pkg/apis"
|
||||
|
||||
type SNotifyElementCreateInput struct {
|
||||
apis.EnabledStatusStandaloneResourceCreateInput
|
||||
Name string
|
||||
}
|
||||
@@ -74,3 +74,11 @@ type PerformDisableInput struct {
|
||||
|
||||
type STopicGroupKeys []string
|
||||
type TopicAdvanceDays []int
|
||||
|
||||
type STopicActionInput struct {
|
||||
ActionId string
|
||||
}
|
||||
|
||||
type STopicResourceInput struct {
|
||||
ResourceId string
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ var (
|
||||
NotifyTemplate modulebase.ResourceManager
|
||||
NotifyTopic modulebase.ResourceManager
|
||||
NotifySubscriber modulebase.ResourceManager
|
||||
NotifyAction modulebase.ResourceManager
|
||||
NotifyResource modulebase.ResourceManager
|
||||
Configs ConfigsManager
|
||||
)
|
||||
|
||||
@@ -91,6 +93,18 @@ func init() {
|
||||
)
|
||||
modules.Register(&NotifySubscriber)
|
||||
|
||||
NotifyAction = modules.NewNotifyv2Manager(
|
||||
"notify_action",
|
||||
"notify_actions",
|
||||
[]string{},
|
||||
[]string{},
|
||||
)
|
||||
NotifyResource = modules.NewNotifyv2Manager(
|
||||
"notify_resource",
|
||||
"notify_resources",
|
||||
[]string{},
|
||||
[]string{},
|
||||
)
|
||||
// important: Notifications' init must be behind Notication's init
|
||||
Notifications = NotificationManager{
|
||||
Notification,
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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 notify
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
type SNotifyActionListInput struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
|
||||
func (rl *SNotifyActionListInput) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(rl)
|
||||
}
|
||||
|
||||
type SNotifyActionCreateInput struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (rl *SNotifyActionCreateInput) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(rl)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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 notify
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
type SNotifyResourceListInput struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
|
||||
func (rl *SNotifyResourceListInput) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(rl)
|
||||
}
|
||||
|
||||
type SNotifyResourceCreateInput struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (rl *SNotifyResourceCreateInput) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(rl)
|
||||
}
|
||||
@@ -67,3 +67,29 @@ func (opts *TopicUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
func (so *TopicUpdateOptions) GetId() string {
|
||||
return so.ID
|
||||
}
|
||||
|
||||
type STopicAddActionInput struct {
|
||||
ID string
|
||||
ACTION_ID string
|
||||
}
|
||||
|
||||
func (opt *STopicAddActionInput) GetId() string {
|
||||
return opt.ID
|
||||
}
|
||||
|
||||
func (rl *STopicAddActionInput) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(rl)
|
||||
}
|
||||
|
||||
type STopicAddResourceInput struct {
|
||||
ID string
|
||||
RESOURCE_ID string
|
||||
}
|
||||
|
||||
func (opt *STopicAddResourceInput) GetId() string {
|
||||
return opt.ID
|
||||
}
|
||||
|
||||
func (rl *STopicAddResourceInput) Params() (jsonutils.JSONObject, error) {
|
||||
return options.ListStructToParams(rl)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"golang.org/x/text/language"
|
||||
|
||||
comapi "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/apis/notify"
|
||||
api "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
schapi "yunion.io/x/onecloud/pkg/apis/scheduledtask"
|
||||
"yunion.io/x/onecloud/pkg/i18n"
|
||||
@@ -79,8 +78,8 @@ func init() {
|
||||
stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_START, i18n.NewTableEntry().EN("start").CN("开机"))
|
||||
stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_SYNC, i18n.NewTableEntry().EN("sync").CN("同步"))
|
||||
|
||||
specFieldTrans[notify.TOPIC_RESOURCE_SCALINGPOLICY] = spI18nTable
|
||||
specFieldTrans[notify.TOPIC_RESOURCE_SCHEDULEDTASK] = stI18nTable
|
||||
specFieldTrans[api.TOPIC_RESOURCE_SCALINGPOLICY] = spI18nTable
|
||||
specFieldTrans[api.TOPIC_RESOURCE_SCHEDULEDTASK] = stI18nTable
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -314,6 +313,16 @@ func init() {
|
||||
"cloudphone",
|
||||
"云手机",
|
||||
},
|
||||
sI18nElme{
|
||||
api.TOPIC_RESOURCE_ACCOUNT_STATUS,
|
||||
"account",
|
||||
"云账号",
|
||||
},
|
||||
sI18nElme{
|
||||
api.TOPIC_RESOURCE_SERVICE,
|
||||
"service",
|
||||
"服务",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionCreate),
|
||||
"created",
|
||||
@@ -439,5 +448,81 @@ func init() {
|
||||
"reset",
|
||||
"重置",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionChangeIpaddr),
|
||||
"change_ipaddr",
|
||||
"修改IP地址",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionChecksumTest),
|
||||
"checksum_test",
|
||||
"一致性检查",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionCleanData),
|
||||
"clean_data",
|
||||
"清理数据",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionDelBackupServer),
|
||||
"delete_backup_server",
|
||||
"删除主机备份",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionMysqlOutOfSync),
|
||||
"mysql_out_of_sync",
|
||||
"数据库不一致",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionNetOutOfSync),
|
||||
"net_out_of_sync",
|
||||
"网络拓扑不一致",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionServerPanicked),
|
||||
"server_panicked",
|
||||
"主机崩溃",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionServiceAbnormal),
|
||||
"service_abnormal",
|
||||
"服务异常",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionPasswordExpireSoon),
|
||||
"password_expire_soon",
|
||||
"密码即将过期",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionSystemPanic),
|
||||
"panic",
|
||||
"系统崩溃",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionExceedCount),
|
||||
"exceed_count",
|
||||
"超过数量",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionIsolatedDeviceCreate),
|
||||
"isolated_device_create",
|
||||
"新增透传设备",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionIsolatedDeviceUpdate),
|
||||
"isolated_device_update",
|
||||
"修改透传设备",
|
||||
},
|
||||
sI18nElme{
|
||||
string(api.ActionIsolatedDeviceDelete),
|
||||
"isolated_device_delete",
|
||||
"删除透传设备",
|
||||
},
|
||||
|
||||
sI18nElme{
|
||||
string(api.ActionStatusChanged),
|
||||
"status_changed",
|
||||
"状态变更",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ func InitDB() error {
|
||||
ConfigManager,
|
||||
TemplateManager,
|
||||
ReceiverNotificationManager,
|
||||
NotifyActionManager,
|
||||
NotifyResourceManager,
|
||||
TopicManager,
|
||||
RobotManager,
|
||||
SubscriberManager,
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
// 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 models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SNotifyActionManager struct {
|
||||
db.SEnabledStatusStandaloneResourceBaseManager
|
||||
}
|
||||
|
||||
var NotifyActionManager *SNotifyActionManager
|
||||
|
||||
func init() {
|
||||
NotifyActionManager = &SNotifyActionManager{
|
||||
SEnabledStatusStandaloneResourceBaseManager: db.NewEnabledStatusStandaloneResourceBaseManager(
|
||||
SNotifyAction{},
|
||||
"notify_actions_tbl",
|
||||
"notify_action",
|
||||
"notify_actions",
|
||||
),
|
||||
}
|
||||
NotifyActionManager.SetVirtualObject(NotifyActionManager)
|
||||
}
|
||||
|
||||
type SNotifyAction struct {
|
||||
db.SEnabledStatusStandaloneResourceBase
|
||||
}
|
||||
|
||||
func (sm *SNotifyActionManager) InitializeData() error {
|
||||
ctx := context.Background()
|
||||
actions := []api.SAction{
|
||||
api.ActionCreate,
|
||||
api.ActionDelete,
|
||||
api.ActionPendingDelete,
|
||||
api.ActionUpdate,
|
||||
api.ActionRebuildRoot,
|
||||
api.ActionResetPassword,
|
||||
api.ActionChangeConfig,
|
||||
api.ActionExpiredRelease,
|
||||
api.ActionExecute,
|
||||
api.ActionChangeIpaddr,
|
||||
api.ActionSyncStatus,
|
||||
api.ActionCleanData,
|
||||
api.ActionMigrate,
|
||||
api.ActionCreateBackupServer,
|
||||
api.ActionDelBackupServer,
|
||||
api.ActionSyncCreate,
|
||||
api.ActionSyncUpdate,
|
||||
api.ActionSyncDelete,
|
||||
api.ActionOffline,
|
||||
api.ActionSystemPanic,
|
||||
api.ActionSystemException,
|
||||
api.ActionChecksumTest,
|
||||
api.ActionLock,
|
||||
api.ActionExceedCount,
|
||||
api.ActionSyncAccountStatus,
|
||||
api.ActionPasswordExpireSoon,
|
||||
api.ActionNetOutOfSync,
|
||||
api.ActionMysqlOutOfSync,
|
||||
api.ActionServiceAbnormal,
|
||||
api.ActionServerPanicked,
|
||||
api.ActionAttach,
|
||||
api.ActionDetach,
|
||||
api.ActionIsolatedDeviceCreate,
|
||||
api.ActionIsolatedDeviceUpdate,
|
||||
api.ActionIsolatedDeviceDelete,
|
||||
api.ActionStatusChanged,
|
||||
api.ActionStart,
|
||||
api.ActionStop,
|
||||
api.ActionRestart,
|
||||
api.ActionReset,
|
||||
}
|
||||
dbActions := []SNotifyAction{}
|
||||
q := NotifyActionManager.Query().In("id", actions)
|
||||
err := db.FetchModelObjects(NotifyActionManager, q, &dbActions)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetch topic_actions")
|
||||
}
|
||||
dbActionMap := map[api.SAction]struct{}{}
|
||||
for _, dbAction := range dbActions {
|
||||
dbActionMap[api.SAction(dbAction.Id)] = struct{}{}
|
||||
}
|
||||
for i, action := range actions {
|
||||
if _, ok := dbActionMap[action]; !ok {
|
||||
NotifyAction := SNotifyAction{}
|
||||
NotifyAction.Id = string(actions[i])
|
||||
NotifyAction.Name = string(actions[i])
|
||||
NotifyAction.Enabled = tristate.True
|
||||
NotifyActionManager.TableSpec().InsertOrUpdate(ctx, &NotifyAction)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SNotifyActionManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.SNotifyElementCreateInput) (api.SNotifyElementCreateInput, error) {
|
||||
_, err := manager.SEnabledStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.EnabledStatusStandaloneResourceCreateInput)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "validateCreate")
|
||||
}
|
||||
count, err := manager.Query().Equals("name", input.Name).CountWithError()
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "fetch count")
|
||||
}
|
||||
if count > 0 {
|
||||
return input, errors.Wrap(httperrors.ErrDuplicateName, "%s has been exist")
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// Copyright Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version . (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-.
|
||||
//
|
||||
// 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 models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/tristate"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SNotifyResourceManager struct {
|
||||
db.SEnabledStatusStandaloneResourceBaseManager
|
||||
}
|
||||
|
||||
var NotifyResourceManager *SNotifyResourceManager
|
||||
|
||||
func init() {
|
||||
NotifyResourceManager = &SNotifyResourceManager{
|
||||
SEnabledStatusStandaloneResourceBaseManager: db.NewEnabledStatusStandaloneResourceBaseManager(
|
||||
SNotifyResource{},
|
||||
"notify_resources_tbl",
|
||||
"notify_resource",
|
||||
"notify_resources",
|
||||
),
|
||||
}
|
||||
NotifyResourceManager.SetVirtualObject(NotifyResourceManager)
|
||||
}
|
||||
|
||||
type SNotifyResource struct {
|
||||
db.SEnabledStatusStandaloneResourceBase
|
||||
}
|
||||
|
||||
func (sm *SNotifyResourceManager) InitializeData() error {
|
||||
ctx := context.Background()
|
||||
resources := []string{
|
||||
api.TOPIC_RESOURCE_SERVER,
|
||||
api.TOPIC_RESOURCE_SCALINGGROUP,
|
||||
api.TOPIC_RESOURCE_SCALINGPOLICY,
|
||||
api.TOPIC_RESOURCE_IMAGE,
|
||||
api.TOPIC_RESOURCE_DISK,
|
||||
api.TOPIC_RESOURCE_SNAPSHOT,
|
||||
api.TOPIC_RESOURCE_INSTANCESNAPSHOT,
|
||||
api.TOPIC_RESOURCE_SNAPSHOTPOLICY,
|
||||
api.TOPIC_RESOURCE_NETWORK,
|
||||
api.TOPIC_RESOURCE_EIP,
|
||||
api.TOPIC_RESOURCE_SECGROUP,
|
||||
api.TOPIC_RESOURCE_LOADBALANCER,
|
||||
api.TOPIC_RESOURCE_LOADBALANCERACL,
|
||||
api.TOPIC_RESOURCE_LOADBALANCERCERTIFICATE,
|
||||
api.TOPIC_RESOURCE_BUCKET,
|
||||
api.TOPIC_RESOURCE_DBINSTANCE,
|
||||
api.TOPIC_RESOURCE_ELASTICCACHE,
|
||||
api.TOPIC_RESOURCE_SCHEDULEDTASK,
|
||||
api.TOPIC_RESOURCE_BAREMETAL,
|
||||
api.TOPIC_RESOURCE_VPC,
|
||||
api.TOPIC_RESOURCE_DNSZONE,
|
||||
api.TOPIC_RESOURCE_NATGATEWAY,
|
||||
api.TOPIC_RESOURCE_WEBAPP,
|
||||
api.TOPIC_RESOURCE_CDNDOMAIN,
|
||||
api.TOPIC_RESOURCE_FILESYSTEM,
|
||||
api.TOPIC_RESOURCE_WAF,
|
||||
api.TOPIC_RESOURCE_KAFKA,
|
||||
api.TOPIC_RESOURCE_ELASTICSEARCH,
|
||||
api.TOPIC_RESOURCE_MONGODB,
|
||||
api.TOPIC_RESOURCE_DNSRECORDSET,
|
||||
api.TOPIC_RESOURCE_LOADBALANCERLISTENER,
|
||||
api.TOPIC_RESOURCE_LOADBALANCERBACKEDNGROUP,
|
||||
api.TOPIC_RESOURCE_HOST,
|
||||
api.TOPIC_RESOURCE_TASK,
|
||||
api.TOPIC_RESOURCE_CLOUDPODS_COMPONENT,
|
||||
api.TOPIC_RESOURCE_DB_TABLE_RECORD,
|
||||
api.TOPIC_RESOURCE_USER,
|
||||
api.TOPIC_RESOURCE_ACTION_LOG,
|
||||
api.TOPIC_RESOURCE_ACCOUNT_STATUS,
|
||||
api.TOPIC_RESOURCE_NET,
|
||||
api.TOPIC_RESOURCE_SERVICE,
|
||||
api.TOPIC_RESOURCE_VM_INTEGRITY_CHECK,
|
||||
api.TOPIC_RESOURCE_PROJECT,
|
||||
api.TOPIC_RESOURCE_CLOUDPHONE,
|
||||
}
|
||||
dbResources := []SNotifyResource{}
|
||||
q := NotifyResourceManager.Query().In("id", resources)
|
||||
err := db.FetchModelObjects(NotifyResourceManager, q, &dbResources)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetch topic_resources")
|
||||
}
|
||||
dbResourceMap := map[string]struct{}{}
|
||||
for _, dbResource := range dbResources {
|
||||
dbResourceMap[dbResource.Id] = struct{}{}
|
||||
}
|
||||
for i, resource := range resources {
|
||||
if _, ok := dbResourceMap[resource]; !ok {
|
||||
NotifyResource := SNotifyResource{}
|
||||
NotifyResource.Id = resources[i]
|
||||
NotifyResource.Name = resources[i]
|
||||
NotifyResource.Enabled = tristate.True
|
||||
NotifyResourceManager.TableSpec().InsertOrUpdate(ctx, &NotifyResource)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *SNotifyResourceManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.SNotifyElementCreateInput) (api.SNotifyElementCreateInput, error) {
|
||||
_, err := manager.SEnabledStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, input.EnabledStatusStandaloneResourceCreateInput)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "validateCreate")
|
||||
}
|
||||
count, err := manager.Query().Equals("name", input.Name).CountWithError()
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "fetch count")
|
||||
}
|
||||
if count > 0 {
|
||||
return input, errors.Wrap(httperrors.ErrDuplicateName, "%s has been exist")
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/apis/notify"
|
||||
api "yunion.io/x/onecloud/pkg/apis/notify"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -269,7 +268,7 @@ func (r *SRobot) PerformDisable(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
|
||||
func (r *SRobot) PostDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
q := SubscriberManager.Query().Equals("type", notify.SUBSCRIBER_TYPE_ROBOT).Equals("identification", r.GetId())
|
||||
q := SubscriberManager.Query().Equals("type", api.SUBSCRIBER_TYPE_ROBOT).Equals("identification", r.GetId())
|
||||
subscribers := make([]SSubscriber, 0, 2)
|
||||
err := db.FetchModelObjects(SubscriberManager, q, &subscribers)
|
||||
if err != nil {
|
||||
|
||||
+408
-543
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
||||
// 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 models
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
)
|
||||
|
||||
type STopicActionManager struct {
|
||||
db.SJointResourceBaseManager
|
||||
}
|
||||
|
||||
var TopicActionManager *STopicActionManager
|
||||
|
||||
func init() {
|
||||
TopicActionManager = &STopicActionManager{
|
||||
SJointResourceBaseManager: db.NewJointResourceBaseManager(
|
||||
STopicAction{},
|
||||
"topic_actions_tbl",
|
||||
"topic_action",
|
||||
"topic_actions",
|
||||
TopicManager,
|
||||
NotifyActionManager,
|
||||
),
|
||||
}
|
||||
TopicActionManager.SetVirtualObject(TopicActionManager)
|
||||
}
|
||||
|
||||
type STopicAction struct {
|
||||
db.SJointResourceBase
|
||||
|
||||
ActionId string `width:"64" nullable:"false" create:"required" update:"user" list:"user"`
|
||||
TopicId string `width:"64" nullable:"false" create:"required" update:"user" list:"user"`
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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 models
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
)
|
||||
|
||||
type STopicResourceManager struct {
|
||||
db.SJointResourceBaseManager
|
||||
}
|
||||
|
||||
var TopicResourceManager *STopicResourceManager
|
||||
|
||||
func init() {
|
||||
TopicResourceManager = &STopicResourceManager{
|
||||
SJointResourceBaseManager: db.NewJointResourceBaseManager(
|
||||
STopicResource{},
|
||||
"topic_resources_tbl",
|
||||
"topic_resource",
|
||||
"topic_resources",
|
||||
TopicManager,
|
||||
NotifyResourceManager,
|
||||
),
|
||||
}
|
||||
TopicResourceManager.SetVirtualObject(TopicResourceManager)
|
||||
}
|
||||
|
||||
type STopicResource struct {
|
||||
db.SJointResourceBase
|
||||
|
||||
ResourceId string `width:"64" nullable:"false" create:"required" update:"user" list:"user"`
|
||||
TopicId string `width:"64" nullable:"false" create:"required" update:"user" list:"user"`
|
||||
}
|
||||
@@ -67,6 +67,8 @@ func InitHandlers(app *appsrv.Application) {
|
||||
models.SubscriberManager,
|
||||
models.EmailQueueManager,
|
||||
models.NotificationGroupManager,
|
||||
models.NotifyActionManager,
|
||||
models.NotifyResourceManager,
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
|
||||
Reference in New Issue
Block a user