@@ -18,7 +18,6 @@ import (
1818 "context"
1919 "fmt"
2020 "strings"
21- "sync"
2221
2322 "yunion.io/x/jsonutils"
2423 "yunion.io/x/log"
@@ -973,194 +972,3 @@ func (t *STopic) PerformAddResources(
973972 }
974973 return nil , nil
975974}
976-
977- func init () {
978- converter = & sConverter {
979- resource2Value : & sync.Map {},
980- value2Resource : & sync.Map {},
981- action2Value : & sync.Map {},
982- value2Action : & sync.Map {},
983- }
984- converter .registerResource (
985- map [string ]int {
986- notify .TOPIC_RESOURCE_SERVER : 0 ,
987- notify .TOPIC_RESOURCE_SCALINGGROUP : 1 ,
988- notify .TOPIC_RESOURCE_SCALINGPOLICY : 2 ,
989- notify .TOPIC_RESOURCE_IMAGE : 3 ,
990- notify .TOPIC_RESOURCE_DISK : 4 ,
991- notify .TOPIC_RESOURCE_SNAPSHOT : 5 ,
992- notify .TOPIC_RESOURCE_INSTANCESNAPSHOT : 6 ,
993- notify .TOPIC_RESOURCE_SNAPSHOTPOLICY : 7 ,
994- notify .TOPIC_RESOURCE_NETWORK : 8 ,
995- notify .TOPIC_RESOURCE_EIP : 9 ,
996- notify .TOPIC_RESOURCE_SECGROUP : 10 ,
997- notify .TOPIC_RESOURCE_LOADBALANCER : 11 ,
998- notify .TOPIC_RESOURCE_LOADBALANCERACL : 12 ,
999- notify .TOPIC_RESOURCE_LOADBALANCERCERTIFICATE : 13 ,
1000- notify .TOPIC_RESOURCE_BUCKET : 14 ,
1001- notify .TOPIC_RESOURCE_DBINSTANCE : 15 ,
1002- notify .TOPIC_RESOURCE_ELASTICCACHE : 16 ,
1003- notify .TOPIC_RESOURCE_SCHEDULEDTASK : 17 ,
1004- notify .TOPIC_RESOURCE_BAREMETAL : 18 ,
1005- notify .TOPIC_RESOURCE_VPC : 19 ,
1006- notify .TOPIC_RESOURCE_DNSZONE : 20 ,
1007- notify .TOPIC_RESOURCE_NATGATEWAY : 21 ,
1008- notify .TOPIC_RESOURCE_WEBAPP : 22 ,
1009- notify .TOPIC_RESOURCE_CDNDOMAIN : 23 ,
1010- notify .TOPIC_RESOURCE_FILESYSTEM : 24 ,
1011- notify .TOPIC_RESOURCE_WAF : 25 ,
1012- notify .TOPIC_RESOURCE_KAFKA : 26 ,
1013- notify .TOPIC_RESOURCE_ELASTICSEARCH : 27 ,
1014- notify .TOPIC_RESOURCE_MONGODB : 28 ,
1015- notify .TOPIC_RESOURCE_DNSRECORDSET : 29 ,
1016- notify .TOPIC_RESOURCE_LOADBALANCERLISTENER : 30 ,
1017- notify .TOPIC_RESOURCE_LOADBALANCERBACKEDNGROUP : 31 ,
1018- notify .TOPIC_RESOURCE_HOST : 32 ,
1019- notify .TOPIC_RESOURCE_TASK : 33 ,
1020- notify .TOPIC_RESOURCE_CLOUDPODS_COMPONENT : 34 ,
1021- notify .TOPIC_RESOURCE_DB_TABLE_RECORD : 35 ,
1022- notify .TOPIC_RESOURCE_USER : 36 ,
1023- notify .TOPIC_RESOURCE_ACTION_LOG : 37 ,
1024- notify .TOPIC_RESOURCE_ACCOUNT_STATUS : 38 ,
1025- notify .TOPIC_RESOURCE_NET : 39 ,
1026- notify .TOPIC_RESOURCE_SERVICE : 40 ,
1027- notify .TOPIC_RESOURCE_VM_INTEGRITY_CHECK : 41 ,
1028- notify .TOPIC_RESOURCE_PROJECT : 42 ,
1029- },
1030- )
1031- converter .registerAction (
1032- map [notify.SAction ]int {
1033- notify .ActionCreate : 0 ,
1034- notify .ActionDelete : 1 ,
1035- notify .ActionPendingDelete : 2 ,
1036- notify .ActionUpdate : 3 ,
1037- notify .ActionRebuildRoot : 4 ,
1038- notify .ActionResetPassword : 5 ,
1039- notify .ActionChangeConfig : 6 ,
1040- notify .ActionExpiredRelease : 7 ,
1041- notify .ActionExecute : 8 ,
1042- notify .ActionChangeIpaddr : 9 ,
1043- notify .ActionSyncStatus : 10 ,
1044- notify .ActionCleanData : 11 ,
1045- notify .ActionMigrate : 12 ,
1046- notify .ActionCreateBackupServer : 13 ,
1047- notify .ActionDelBackupServer : 14 ,
1048- notify .ActionSyncCreate : 15 ,
1049- notify .ActionSyncUpdate : 16 ,
1050- notify .ActionSyncDelete : 17 ,
1051- notify .ActionOffline : 18 ,
1052- notify .ActionSystemPanic : 19 ,
1053- notify .ActionSystemException : 20 ,
1054- notify .ActionChecksumTest : 21 ,
1055- notify .ActionLock : 22 ,
1056- notify .ActionExceedCount : 23 ,
1057- notify .ActionSyncAccountStatus : 24 ,
1058- notify .ActionPasswordExpireSoon : 25 ,
1059- notify .ActionNetOutOfSync : 26 ,
1060- notify .ActionMysqlOutOfSync : 27 ,
1061- notify .ActionServiceAbnormal : 28 ,
1062- notify .ActionServerPanicked : 29 ,
1063- notify .ActionAttach : 30 ,
1064- notify .ActionDetach : 31 ,
1065- notify .ActionIsolatedDeviceCreate : 32 ,
1066- notify .ActionIsolatedDeviceUpdate : 33 ,
1067- notify .ActionIsolatedDeviceDelete : 34 ,
1068- notify .ActionStatusChanged : 35 ,
1069- },
1070- )
1071- }
1072-
1073- var converter * sConverter
1074-
1075- type sConverter struct {
1076- resource2Value * sync.Map
1077- value2Resource * sync.Map
1078- action2Value * sync.Map
1079- value2Action * sync.Map
1080- }
1081-
1082- type sResourceValue struct {
1083- resource string
1084- value int
1085- }
1086-
1087- type sActionValue struct {
1088- action string
1089- value int
1090- }
1091-
1092- func (rc * sConverter ) registerResource (resourceValues map [string ]int ) {
1093- for resource , value := range resourceValues {
1094- if v , ok := rc .resource2Value .Load (resource ); ok && v .(int ) != value {
1095- log .Fatalf ("resource '%s' has been mapped to value '%d', and it is not allowed to map to another value '%d'" , resource , v , value )
1096- }
1097- if r , ok := rc .value2Resource .Load (value ); ok && r .(string ) != resource {
1098- log .Fatalf ("value '%d' has been mapped to resource '%s', and it is not allowed to map to another resource '%s'" , value , r , resource )
1099- }
1100- rc .resource2Value .Store (resource , value )
1101- rc .value2Resource .Store (value , resource )
1102- }
1103- }
1104-
1105- func (rc * sConverter ) registerAction (actionValues map [notify.SAction ]int ) {
1106- for action , value := range actionValues {
1107- if v , ok := rc .action2Value .Load (action ); ok && v .(int ) != value {
1108- log .Fatalf ("action '%s' has been mapped to value '%d', and it is not allowed to map to another value '%d'" , action , v , value )
1109- }
1110- if a , ok := rc .value2Action .Load (value ); ok && a .(notify.SAction ) != action {
1111- log .Fatalf ("value '%d' has been mapped to action '%s', and it is not allowed to map to another action '%s'" , value , a , action )
1112- }
1113- rc .action2Value .Store (action , value )
1114- rc .value2Action .Store (value , action )
1115- }
1116- }
1117-
1118- func (rc * sConverter ) resourceValue (resource string ) int {
1119- v , ok := rc .resource2Value .Load (resource )
1120- if ! ok {
1121- return - 1
1122- }
1123- return v .(int )
1124- }
1125-
1126- func (rc * sConverter ) resource (resourceValue int ) string {
1127- r , ok := rc .value2Resource .Load (resourceValue )
1128- if ! ok {
1129- return ""
1130- }
1131- return r .(string )
1132- }
1133-
1134- func (rc * sConverter ) actionValue (action notify.SAction ) int {
1135- v , ok := rc .action2Value .Load (action )
1136- if ! ok {
1137- return - 1
1138- }
1139- return v .(int )
1140- }
1141-
1142- func (rc * sConverter ) action (actionValue int ) notify.SAction {
1143- a , ok := rc .value2Action .Load (actionValue )
1144- if ! ok {
1145- return notify .SAction ("" )
1146- }
1147- return a .(notify.SAction )
1148- }
1149-
1150- func (self * STopic ) GetEnabledSubscribers (domainId , projectId string ) ([]SSubscriber , error ) {
1151- q := SubscriberManager .Query ().Equals ("topic_id" , self .Id ).IsTrue ("enabled" )
1152- q = q .Filter (sqlchemy .OR (
1153- sqlchemy .AND (
1154- sqlchemy .Equals (q .Field ("resource_scope" ), api .SUBSCRIBER_SCOPE_PROJECT ),
1155- sqlchemy .Equals (q .Field ("resource_attribution_id" ), projectId ),
1156- ),
1157- sqlchemy .AND (
1158- sqlchemy .Equals (q .Field ("resource_scope" ), api .SUBSCRIBER_SCOPE_DOMAIN ),
1159- sqlchemy .Equals (q .Field ("resource_attribution_id" ), domainId ),
1160- ),
1161- sqlchemy .Equals (q .Field ("resource_scope" ), api .SUBSCRIBER_SCOPE_SYSTEM ),
1162- ))
1163- ret := []SSubscriber {}
1164- err := db .FetchModelObjects (SubscriberManager , q , & ret )
1165- return ret , err
1166- }
0 commit comments