Skip to content

Commit 3959dbd

Browse files
authored
refactor create duplicate alert check (#10544)
1 parent bcd23eb commit 3959dbd

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

server/src/main/java/com/cloud/alert/AlertManagerImpl.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.UnsupportedEncodingException;
2020
import java.text.DecimalFormat;
2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.Date;
2324
import java.util.HashMap;
2425
import java.util.HashSet;
@@ -82,8 +83,21 @@
8283
import com.cloud.utils.component.ManagerBase;
8384
import com.cloud.utils.concurrency.NamedThreadFactory;
8485
import com.cloud.utils.db.SearchCriteria;
86+
import org.jetbrains.annotations.Nullable;
8587

8688
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);
87101
protected Logger logger = Logger.getLogger(AlertManagerImpl.class.getName());
88102

89103
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) {
723737
public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content)
724738
throws MessagingException, UnsupportedEncodingException {
725739
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);
735741

736742
if (alert == null) {
737743
AlertVO newAlert = new AlertVO();
@@ -773,6 +779,15 @@ public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long c
773779

774780
}
775781

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+
776791
protected void sendMessage(SMTPMailProperties mailProps) {
777792
_executor.execute(new Runnable() {
778793
@Override

0 commit comments

Comments
 (0)