|
19 | 19 | import java.io.UnsupportedEncodingException; |
20 | 20 | import java.text.DecimalFormat; |
21 | 21 | import java.util.ArrayList; |
| 22 | +import java.util.Arrays; |
22 | 23 | import java.util.Date; |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.HashSet; |
|
82 | 83 | import com.cloud.utils.component.ManagerBase; |
83 | 84 | import com.cloud.utils.concurrency.NamedThreadFactory; |
84 | 85 | import com.cloud.utils.db.SearchCriteria; |
| 86 | +import org.jetbrains.annotations.Nullable; |
85 | 87 |
|
86 | 88 | public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable { |
| 89 | + public static final List<AlertType> ALERTS = Arrays.asList(AlertType.ALERT_TYPE_HOST |
| 90 | + , AlertType.ALERT_TYPE_USERVM |
| 91 | + , AlertType.ALERT_TYPE_DOMAIN_ROUTER |
| 92 | + , AlertType.ALERT_TYPE_CONSOLE_PROXY |
| 93 | + , AlertType.ALERT_TYPE_SSVM |
| 94 | + , AlertType.ALERT_TYPE_STORAGE_MISC |
| 95 | + , AlertType.ALERT_TYPE_MANAGEMENT_NODE |
| 96 | + , AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED |
| 97 | + , AlertType.ALERT_TYPE_UPLOAD_FAILED |
| 98 | + , AlertType.ALERT_TYPE_OOBM_AUTH_ERROR |
| 99 | + , AlertType.ALERT_TYPE_HA_ACTION |
| 100 | + , AlertType.ALERT_TYPE_CA_CERT); |
87 | 101 | protected Logger logger = Logger.getLogger(AlertManagerImpl.class.getName()); |
88 | 102 |
|
89 | 103 | private static final long INITIAL_CAPACITY_CHECK_DELAY = 30L * 1000L; // Thirty seconds expressed in milliseconds. |
@@ -723,15 +737,7 @@ public void clearAlert(short alertType, long dataCenterId, Long podId) { |
723 | 737 | public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content) |
724 | 738 | throws MessagingException, UnsupportedEncodingException { |
725 | 739 | logger.warn(String.format("alertType=[%s] dataCenterId=[%s] podId=[%s] clusterId=[%s] message=[%s].", alertType, dataCenterId, podId, clusterId, subject)); |
726 | | - AlertVO alert = null; |
727 | | - if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) && (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) |
728 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) && (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) |
729 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) |
730 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGEMENT_NODE) && (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) |
731 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) && (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) |
732 | | - && (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) && (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) { |
733 | | - alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId); |
734 | | - } |
| 740 | + AlertVO alert = getAlertForTrivialAlertType(alertType, dataCenterId, podId, clusterId); |
735 | 741 |
|
736 | 742 | if (alert == null) { |
737 | 743 | AlertVO newAlert = new AlertVO(); |
@@ -773,6 +779,15 @@ public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long c |
773 | 779 |
|
774 | 780 | } |
775 | 781 |
|
| 782 | + @Nullable |
| 783 | + private AlertVO getAlertForTrivialAlertType(AlertType alertType, long dataCenterId, Long podId, Long clusterId) { |
| 784 | + AlertVO alert = null; |
| 785 | + if (!ALERTS.contains(alertType)) { |
| 786 | + alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId); |
| 787 | + } |
| 788 | + return alert; |
| 789 | + } |
| 790 | + |
776 | 791 | protected void sendMessage(SMTPMailProperties mailProps) { |
777 | 792 | _executor.execute(new Runnable() { |
778 | 793 | @Override |
|
0 commit comments