|
| 1 | + |
| 2 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +// or more contributor license agreements. See the NOTICE file |
| 4 | +// distributed with this work for additional information |
| 5 | +// regarding copyright ownership. The ASF licenses this file |
| 6 | +// to you under the Apache License, Version 2.0 (the |
| 7 | +// "License"); you may not use this file except in compliance |
| 8 | +// with the License. You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, |
| 13 | +// software distributed under the License is distributed on an |
| 14 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +// KIND, either express or implied. See the License for the |
| 16 | +// specific language governing permissions and limitations |
| 17 | +// under the License. |
| 18 | +package org.apache.cloudstack.alert; |
| 19 | + |
| 20 | +import java.util.HashSet; |
| 21 | +import java.util.Set; |
| 22 | + |
| 23 | +import com.cloud.capacity.Capacity; |
| 24 | +import com.cloud.exception.InvalidParameterValueException; |
| 25 | + |
| 26 | +public interface AlertService { |
| 27 | + public static class AlertType { |
| 28 | + private static Set<AlertType> defaultAlertTypes = new HashSet<AlertType>(); |
| 29 | + private final String name; |
| 30 | + private final short type; |
| 31 | + |
| 32 | + private AlertType(short type, String name, boolean isDefault) { |
| 33 | + this.name = name; |
| 34 | + this.type = type; |
| 35 | + if (isDefault) { |
| 36 | + defaultAlertTypes.add(this); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + public static final AlertType ALERT_TYPE_MEMORY = new AlertType(Capacity.CAPACITY_TYPE_MEMORY, "ALERT.MEMORY", true); |
| 41 | + public static final AlertType ALERT_TYPE_CPU = new AlertType(Capacity.CAPACITY_TYPE_CPU, "ALERT.CPU", true); |
| 42 | + public static final AlertType ALERT_TYPE_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_STORAGE, "ALERT.STORAGE", true); |
| 43 | + public static final AlertType ALERT_TYPE_STORAGE_ALLOCATED = new AlertType(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, "ALERT.STORAGE.ALLOCATED", true); |
| 44 | + public static final AlertType ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = new AlertType(Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP, "ALERT.NETWORK.PUBLICIP", true); |
| 45 | + public static final AlertType ALERT_TYPE_PRIVATE_IP = new AlertType(Capacity.CAPACITY_TYPE_PRIVATE_IP, "ALERT.NETWORK.PRIVATEIP", true); |
| 46 | + public static final AlertType ALERT_TYPE_SECONDARY_STORAGE = new AlertType(Capacity.CAPACITY_TYPE_SECONDARY_STORAGE, "ALERT.STORAGE.SECONDARY", true); |
| 47 | + public static final AlertType ALERT_TYPE_HOST = new AlertType((short)7, "ALERT.COMPUTE.HOST", true); |
| 48 | + public static final AlertType ALERT_TYPE_USERVM = new AlertType((short)8, "ALERT.USERVM", true); |
| 49 | + public static final AlertType ALERT_TYPE_DOMAIN_ROUTER = new AlertType((short)9, "ALERT.SERVICE.DOMAINROUTER", true); |
| 50 | + public static final AlertType ALERT_TYPE_CONSOLE_PROXY = new AlertType((short)10, "ALERT.SERVICE.CONSOLEPROXY", true); |
| 51 | + public static final AlertType ALERT_TYPE_ROUTING = new AlertType((short)11, "ALERT.NETWORK.ROUTING", true); |
| 52 | + public static final AlertType ALERT_TYPE_STORAGE_MISC = new AlertType((short)12, "ALERT.STORAGE.MISC", true); |
| 53 | + public static final AlertType ALERT_TYPE_USAGE_SERVER = new AlertType((short)13, "ALERT.USAGE", true); |
| 54 | + public static final AlertType ALERT_TYPE_MANAGMENT_NODE = new AlertType((short)14, "ALERT.MANAGEMENT", true); |
| 55 | + public static final AlertType ALERT_TYPE_DOMAIN_ROUTER_MIGRATE = new AlertType((short)15, "ALERT.NETWORK.DOMAINROUTERMIGRATE", true); |
| 56 | + public static final AlertType ALERT_TYPE_CONSOLE_PROXY_MIGRATE = new AlertType((short)16, "ALERT.SERVICE.CONSOLEPROXYMIGRATE", true); |
| 57 | + public static final AlertType ALERT_TYPE_USERVM_MIGRATE = new AlertType((short)17, "ALERT.USERVM.MIGRATE", true); |
| 58 | + public static final AlertType ALERT_TYPE_VLAN = new AlertType((short)18, "ALERT.NETWORK.VLAN", true); |
| 59 | + public static final AlertType ALERT_TYPE_SSVM = new AlertType((short)19, "ALERT.SERVICE.SSVM", true); |
| 60 | + public static final AlertType ALERT_TYPE_USAGE_SERVER_RESULT = new AlertType((short)20, "ALERT.USAGE.RESULT", true); |
| 61 | + public static final AlertType ALERT_TYPE_STORAGE_DELETE = new AlertType((short)21, "ALERT.STORAGE.DELETE", true); |
| 62 | + public static final AlertType ALERT_TYPE_UPDATE_RESOURCE_COUNT = new AlertType((short)22, "ALERT.RESOURCE.COUNT", true); |
| 63 | + public static final AlertType ALERT_TYPE_USAGE_SANITY_RESULT = new AlertType((short)23, "ALERT.USAGE.SANITY", true); |
| 64 | + public static final AlertType ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = new AlertType((short)24, "ALERT.NETWORK.DIRECTPUBLICIP", true); |
| 65 | + public static final AlertType ALERT_TYPE_LOCAL_STORAGE = new AlertType((short)25, "ALERT.STORAGE.LOCAL", true); |
| 66 | + public static final AlertType ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = new AlertType((short)26, "ALERT.RESOURCE.EXCEED", true); |
| 67 | + public static final AlertType ALERT_TYPE_SYNC = new AlertType((short)27, "ALERT.TYPE.SYNC", true); |
| 68 | + |
| 69 | + public short getType() { |
| 70 | + return type; |
| 71 | + } |
| 72 | + |
| 73 | + public String getName() { |
| 74 | + return name; |
| 75 | + } |
| 76 | + |
| 77 | + private static AlertType getAlertType(short type) { |
| 78 | + for (AlertType alertType : defaultAlertTypes) { |
| 79 | + if (alertType.getType() == type) { |
| 80 | + return alertType; |
| 81 | + } |
| 82 | + } |
| 83 | + return null; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public String toString() { |
| 88 | + return String.valueOf(this.getType()); |
| 89 | + } |
| 90 | + |
| 91 | + public static AlertType generateAlert(short type, String name) { |
| 92 | + AlertType defaultAlert = getAlertType(type); |
| 93 | + if (defaultAlert != null && !defaultAlert.getName().equalsIgnoreCase(name)) { |
| 94 | + throw new InvalidParameterValueException("There is a default alert having type " + type + " and name " + defaultAlert.getName()); |
| 95 | + } else { |
| 96 | + return new AlertType(type, name, false); |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + boolean generateAlert(AlertType alertType, long dataCenterId, Long podId, String msg); |
| 102 | + |
| 103 | +} |
0 commit comments