Skip to content

Commit 4a1fbe6

Browse files
committed
refactor create duplicate alert check
1 parent 919c979 commit 4a1fbe6

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,6 +83,7 @@
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 {
8789
protected Logger logger = Logger.getLogger(AlertManagerImpl.class.getName());
@@ -723,15 +725,7 @@ public void clearAlert(short alertType, long dataCenterId, Long podId) {
723725
public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content)
724726
throws MessagingException, UnsupportedEncodingException {
725727
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-
}
728+
AlertVO alert = createAlertForTrivialAlertType(alertType, dataCenterId, podId, clusterId);
735729

736730
if (alert == null) {
737731
AlertVO newAlert = new AlertVO();
@@ -773,6 +767,27 @@ public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long c
773767

774768
}
775769

770+
@Nullable
771+
private AlertVO createAlertForTrivialAlertType(AlertType alertType, long dataCenterId, Long podId, Long clusterId) {
772+
AlertVO alert = null;
773+
List<AlertType> alerts = Arrays.asList(AlertType.ALERT_TYPE_HOST
774+
, AlertType.ALERT_TYPE_USERVM
775+
, AlertType.ALERT_TYPE_DOMAIN_ROUTER
776+
, AlertType.ALERT_TYPE_CONSOLE_PROXY
777+
, AlertType.ALERT_TYPE_SSVM
778+
, AlertType.ALERT_TYPE_STORAGE_MISC
779+
, AlertType.ALERT_TYPE_MANAGEMENT_NODE
780+
, AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED
781+
, AlertType.ALERT_TYPE_UPLOAD_FAILED
782+
, AlertType.ALERT_TYPE_OOBM_AUTH_ERROR
783+
, AlertType.ALERT_TYPE_HA_ACTION
784+
, AlertType.ALERT_TYPE_CA_CERT);
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)