1616// under the License.
1717package org .apache .cloudstack .alert ;
1818
19+ import java .util .HashMap ;
1920import java .util .HashSet ;
21+ import java .util .Map ;
2022import java .util .Set ;
2123
2224import com .cloud .capacity .Capacity ;
2527public interface AlertService {
2628 public static class AlertType {
2729 private static Set <AlertType > defaultAlertTypes = new HashSet <AlertType >();
30+ private static Map <String , AlertType > allAlertTypesMap = new HashMap <>();
2831 private final String name ;
2932 private final short type ;
33+ private final boolean repetitionAllowed ;
3034
31- private AlertType (short type , String name , boolean isDefault ) {
35+ private AlertType (short type , String name , boolean isDefault , boolean repetitionAllowed ) {
3236 this .name = name ;
3337 this .type = type ;
38+ this .repetitionAllowed = repetitionAllowed ;
3439 if (isDefault ) {
3540 defaultAlertTypes .add (this );
3641 }
42+ allAlertTypesMap .put (name , this );
3743 }
3844
39- public static final AlertType ALERT_TYPE_MEMORY = new AlertType (Capacity .CAPACITY_TYPE_MEMORY , "ALERT.MEMORY" , true );
40- public static final AlertType ALERT_TYPE_CPU = new AlertType (Capacity .CAPACITY_TYPE_CPU , "ALERT.CPU" , true );
41- public static final AlertType ALERT_TYPE_STORAGE = new AlertType (Capacity .CAPACITY_TYPE_STORAGE , "ALERT.STORAGE" , true );
42- public static final AlertType ALERT_TYPE_STORAGE_ALLOCATED = new AlertType (Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED , "ALERT.STORAGE.ALLOCATED" , true );
45+ public static final AlertType ALERT_TYPE_MEMORY = new AlertType (Capacity .CAPACITY_TYPE_MEMORY , "ALERT.MEMORY" , true , false );
46+ public static final AlertType ALERT_TYPE_CPU = new AlertType (Capacity .CAPACITY_TYPE_CPU , "ALERT.CPU" , true , false );
47+ public static final AlertType ALERT_TYPE_STORAGE = new AlertType (Capacity .CAPACITY_TYPE_STORAGE , "ALERT.STORAGE" , true , false );
48+ public static final AlertType ALERT_TYPE_STORAGE_ALLOCATED = new AlertType (Capacity .CAPACITY_TYPE_STORAGE_ALLOCATED , "ALERT.STORAGE.ALLOCATED" , true , false );
4349 public static final AlertType ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = new AlertType (Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP , "ALERT.NETWORK.PUBLICIP" ,
44- true );
45- public static final AlertType ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET = new AlertType (Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET , "ALERT.NETWORK.IPV6SUBNET" , true );
46- public static final AlertType ALERT_TYPE_PRIVATE_IP = new AlertType (Capacity .CAPACITY_TYPE_PRIVATE_IP , "ALERT.NETWORK.PRIVATEIP" , true );
47- public static final AlertType ALERT_TYPE_SECONDARY_STORAGE = new AlertType (Capacity .CAPACITY_TYPE_SECONDARY_STORAGE , "ALERT.STORAGE.SECONDARY" , true );
48- public static final AlertType ALERT_TYPE_HOST = new AlertType ((short )7 , "ALERT.COMPUTE.HOST" , true );
49- public static final AlertType ALERT_TYPE_USERVM = new AlertType ((short )8 , "ALERT.USERVM" , true );
50- public static final AlertType ALERT_TYPE_DOMAIN_ROUTER = new AlertType ((short )9 , "ALERT.SERVICE.DOMAINROUTER" , true );
51- public static final AlertType ALERT_TYPE_CONSOLE_PROXY = new AlertType ((short )10 , "ALERT.SERVICE.CONSOLEPROXY" , true );
52- public static final AlertType ALERT_TYPE_ROUTING = new AlertType ((short )11 , "ALERT.NETWORK.ROUTING" , true );
53- public static final AlertType ALERT_TYPE_STORAGE_MISC = new AlertType ((short )12 , "ALERT.STORAGE.MISC" , true );
54- public static final AlertType ALERT_TYPE_USAGE_SERVER = new AlertType ((short )13 , "ALERT.USAGE" , true );
55- public static final AlertType ALERT_TYPE_MANAGEMENT_NODE = new AlertType ((short )14 , "ALERT.MANAGEMENT" , true );
56- public static final AlertType ALERT_TYPE_DOMAIN_ROUTER_MIGRATE = new AlertType ((short )15 , "ALERT.NETWORK.DOMAINROUTERMIGRATE" , true );
57- public static final AlertType ALERT_TYPE_CONSOLE_PROXY_MIGRATE = new AlertType ((short )16 , "ALERT.SERVICE.CONSOLEPROXYMIGRATE" , true );
58- public static final AlertType ALERT_TYPE_USERVM_MIGRATE = new AlertType ((short )17 , "ALERT.USERVM.MIGRATE" , true );
59- public static final AlertType ALERT_TYPE_VLAN = new AlertType ((short )18 , "ALERT.NETWORK.VLAN" , true );
60- public static final AlertType ALERT_TYPE_SSVM = new AlertType ((short )19 , "ALERT.SERVICE.SSVM" , true );
61- public static final AlertType ALERT_TYPE_USAGE_SERVER_RESULT = new AlertType ((short )20 , "ALERT.USAGE.RESULT" , true );
62- public static final AlertType ALERT_TYPE_STORAGE_DELETE = new AlertType ((short )21 , "ALERT.STORAGE.DELETE" , true );
63- public static final AlertType ALERT_TYPE_UPDATE_RESOURCE_COUNT = new AlertType ((short )22 , "ALERT.RESOURCE.COUNT" , true );
64- public static final AlertType ALERT_TYPE_USAGE_SANITY_RESULT = new AlertType ((short )23 , "ALERT.USAGE.SANITY" , true );
65- public static final AlertType ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = new AlertType ((short )24 , "ALERT.NETWORK.DIRECTPUBLICIP" , true );
66- public static final AlertType ALERT_TYPE_LOCAL_STORAGE = new AlertType ((short )25 , "ALERT.STORAGE.LOCAL" , true );
67- public static final AlertType ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = new AlertType ((short )26 , "ALERT.RESOURCE.EXCEED" , true );
68- public static final AlertType ALERT_TYPE_SYNC = new AlertType ((short )27 , "ALERT.TYPE.SYNC" , true );
69- public static final AlertType ALERT_TYPE_UPLOAD_FAILED = new AlertType ((short )28 , "ALERT.UPLOAD.FAILED" , true );
70- public static final AlertType ALERT_TYPE_OOBM_AUTH_ERROR = new AlertType ((short )29 , "ALERT.OOBM.AUTHERROR" , true );
71- public static final AlertType ALERT_TYPE_HA_ACTION = new AlertType ((short )30 , "ALERT.HA.ACTION" , true );
72- public static final AlertType ALERT_TYPE_CA_CERT = new AlertType ((short )31 , "ALERT.CA.CERT" , true );
73- public static final AlertType ALERT_TYPE_VM_SNAPSHOT = new AlertType ((short )32 , "ALERT.VM.SNAPSHOT" , true );
74- public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType ((short )32 , "ALERT.VR.PUBLIC.IFACE.MTU" , true );
75- public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType ((short )32 , "ALERT.VR.PRIVATE.IFACE.MTU" , true );
76- public static final AlertType ALERT_TYPE_EXTENSION_PATH_NOT_READY = new AlertType ((short )33 , "ALERT.TYPE.EXTENSION.PATH.NOT.READY" , true );
50+ true , false );
51+ public static final AlertType ALERT_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET = new AlertType (Capacity .CAPACITY_TYPE_VIRTUAL_NETWORK_IPV6_SUBNET , "ALERT.NETWORK.IPV6SUBNET" , true , false );
52+ public static final AlertType ALERT_TYPE_PRIVATE_IP = new AlertType (Capacity .CAPACITY_TYPE_PRIVATE_IP , "ALERT.NETWORK.PRIVATEIP" , true , false );
53+ public static final AlertType ALERT_TYPE_SECONDARY_STORAGE = new AlertType (Capacity .CAPACITY_TYPE_SECONDARY_STORAGE , "ALERT.STORAGE.SECONDARY" , true , false );
54+ public static final AlertType ALERT_TYPE_HOST = new AlertType ((short )7 , "ALERT.COMPUTE.HOST" , true , true );
55+ public static final AlertType ALERT_TYPE_USERVM = new AlertType ((short )8 , "ALERT.USERVM" , true , true );
56+ public static final AlertType ALERT_TYPE_DOMAIN_ROUTER = new AlertType ((short )9 , "ALERT.SERVICE.DOMAINROUTER" , true , true );
57+ public static final AlertType ALERT_TYPE_CONSOLE_PROXY = new AlertType ((short )10 , "ALERT.SERVICE.CONSOLEPROXY" , true , true );
58+ public static final AlertType ALERT_TYPE_ROUTING = new AlertType ((short )11 , "ALERT.NETWORK.ROUTING" , true , false );
59+ public static final AlertType ALERT_TYPE_STORAGE_MISC = new AlertType ((short )12 , "ALERT.STORAGE.MISC" , true , true );
60+ public static final AlertType ALERT_TYPE_USAGE_SERVER = new AlertType ((short )13 , "ALERT.USAGE" , true , false );
61+ public static final AlertType ALERT_TYPE_MANAGEMENT_NODE = new AlertType ((short )14 , "ALERT.MANAGEMENT" , true , true );
62+ public static final AlertType ALERT_TYPE_DOMAIN_ROUTER_MIGRATE = new AlertType ((short )15 , "ALERT.NETWORK.DOMAINROUTERMIGRATE" , true , false );
63+ public static final AlertType ALERT_TYPE_CONSOLE_PROXY_MIGRATE = new AlertType ((short )16 , "ALERT.SERVICE.CONSOLEPROXYMIGRATE" , true , false );
64+ public static final AlertType ALERT_TYPE_USERVM_MIGRATE = new AlertType ((short )17 , "ALERT.USERVM.MIGRATE" , true , false );
65+ public static final AlertType ALERT_TYPE_VLAN = new AlertType ((short )18 , "ALERT.NETWORK.VLAN" , true , false );
66+ public static final AlertType ALERT_TYPE_SSVM = new AlertType ((short )19 , "ALERT.SERVICE.SSVM" , true , true );
67+ public static final AlertType ALERT_TYPE_USAGE_SERVER_RESULT = new AlertType ((short )20 , "ALERT.USAGE.RESULT" , true , false );
68+ public static final AlertType ALERT_TYPE_STORAGE_DELETE = new AlertType ((short )21 , "ALERT.STORAGE.DELETE" , true , false );
69+ public static final AlertType ALERT_TYPE_UPDATE_RESOURCE_COUNT = new AlertType ((short )22 , "ALERT.RESOURCE.COUNT" , true , false );
70+ public static final AlertType ALERT_TYPE_USAGE_SANITY_RESULT = new AlertType ((short )23 , "ALERT.USAGE.SANITY" , true , false );
71+ public static final AlertType ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = new AlertType ((short )24 , "ALERT.NETWORK.DIRECTPUBLICIP" , true , false );
72+ public static final AlertType ALERT_TYPE_LOCAL_STORAGE = new AlertType ((short )25 , "ALERT.STORAGE.LOCAL" , true , false );
73+ public static final AlertType ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = new AlertType ((short )26 , "ALERT.RESOURCE.EXCEED" , true , true );
74+ public static final AlertType ALERT_TYPE_SYNC = new AlertType ((short )27 , "ALERT.TYPE.SYNC" , true , false );
75+ public static final AlertType ALERT_TYPE_UPLOAD_FAILED = new AlertType ((short )28 , "ALERT.UPLOAD.FAILED" , true , true );
76+ public static final AlertType ALERT_TYPE_OOBM_AUTH_ERROR = new AlertType ((short )29 , "ALERT.OOBM.AUTHERROR" , true , true );
77+ public static final AlertType ALERT_TYPE_HA_ACTION = new AlertType ((short )30 , "ALERT.HA.ACTION" , true , true );
78+ public static final AlertType ALERT_TYPE_CA_CERT = new AlertType ((short )31 , "ALERT.CA.CERT" , true , true );
79+ public static final AlertType ALERT_TYPE_VM_SNAPSHOT = new AlertType ((short )32 , "ALERT.VM.SNAPSHOT" , true , false );
80+ public static final AlertType ALERT_TYPE_VR_PUBLIC_IFACE_MTU = new AlertType ((short )32 , "ALERT.VR.PUBLIC.IFACE.MTU" , true , false );
81+ public static final AlertType ALERT_TYPE_VR_PRIVATE_IFACE_MTU = new AlertType ((short )32 , "ALERT.VR.PRIVATE.IFACE.MTU" , true , false );
82+ public static final AlertType ALERT_TYPE_EXTENSION_PATH_NOT_READY = new AlertType ((short )33 , "ALERT.TYPE.EXTENSION.PATH.NOT.READY" , true , true );
7783
7884 public short getType () {
7985 return type ;
@@ -83,6 +89,10 @@ public String getName() {
8389 return name ;
8490 }
8591
92+ public boolean isRepetitionAllowed () {
93+ return repetitionAllowed ;
94+ }
95+
8696 private static AlertType getAlertType (short type ) {
8797 for (AlertType alertType : defaultAlertTypes ) {
8898 if (alertType .getType () == type ) {
@@ -106,9 +116,13 @@ public static AlertType generateAlert(short type, String name) {
106116 if (defaultAlert != null && !defaultAlert .getName ().equalsIgnoreCase (name )) {
107117 throw new InvalidParameterValueException ("There is a default alert having type " + type + " and name " + defaultAlert .getName ());
108118 } else {
109- return new AlertType (type , name , false );
119+ return new AlertType (type , name , false , false );
110120 }
111121 }
122+
123+ public static AlertType getAlertTypeByName (String name ) {
124+ return allAlertTypesMap .get (name );
125+ }
112126 }
113127
114128 boolean generateAlert (AlertType alertType , long dataCenterId , Long podId , String msg );
0 commit comments