테스트 완료
This commit is contained in:
@@ -28,8 +28,9 @@ public class AlarmService {
|
||||
protected static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
final static String ALARM_GROUP = "Alarm";
|
||||
final static String ALARM_KEY = "Alarm";
|
||||
final static String ALARM_KEY = "{ALARM}";
|
||||
final static String ALARM_RECIVER = "{RECIVER}";
|
||||
final static String ALARM_EABLE = "enable.alarm";
|
||||
|
||||
public Map<AlarmKey, AlarmPolicy> getAlarmPolicy() {
|
||||
|
||||
@@ -40,16 +41,16 @@ public class AlarmService {
|
||||
Properties props = PropManager.getInstance().getProperties(ALARM_GROUP);
|
||||
|
||||
props.forEach((key, value) -> {
|
||||
|
||||
String keyName = (String) key;
|
||||
String configStr = (String) value;
|
||||
|
||||
if (keyName.contains(ALARM_RECIVER)) return;
|
||||
if (keyName.contains(ALARM_KEY)) {
|
||||
|
||||
AlarmPolicy newPolicy = buildAlarmPolicy(keyName, configStr);
|
||||
|
||||
|
||||
policyMap.put(newPolicy.getAlarmKey(), newPolicy);
|
||||
AlarmPolicy newPolicy = buildAlarmPolicy(keyName, configStr);
|
||||
policyMap.put(newPolicy.getAlarmKey(), newPolicy);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -60,29 +61,33 @@ public class AlarmService {
|
||||
return policyMap;
|
||||
}
|
||||
|
||||
public boolean isAlarmEnabled() {
|
||||
return Optional.ofNullable(PropManager.getInstance().getProperty(ALARM_GROUP, ALARM_EABLE))
|
||||
.map(Boolean::valueOf).orElse(false);
|
||||
}
|
||||
|
||||
private AlarmPolicy buildAlarmPolicy(String key, String configJsonStr) {
|
||||
|
||||
JsonObject alarmConfig = Jsons.GSON.fromJson(configJsonStr, JsonObject.class);
|
||||
|
||||
String policyType = alarmConfig.get("type").getAsString();
|
||||
int coolDownSec = Optional.ofNullable(alarmConfig.get("coolDownSec")).map(i -> i.getAsInt()).orElse(60);
|
||||
int thresholdCount = Optional.ofNullable(alarmConfig.get("thresholdCount")).map(i -> i.getAsInt()).orElse(5);
|
||||
int timeWindowSec = Optional.ofNullable(alarmConfig.get("timeWindowSec")).map(i -> i.getAsInt()).orElse(60);
|
||||
|
||||
AlarmPolicy alarmPolicy;
|
||||
|
||||
if ("count".equals(policyType)) {
|
||||
alarmPolicy = CounterPolicy.builder().alarmKey(new DynamicAlarmKey(key)).coolDownMs(coolDownSec * 1000)
|
||||
.thresholdCount(thresholdCount).build();
|
||||
alarmPolicy = CounterPolicy.builder().alarmKey(new DynamicAlarmKey(key)).thresholdCount(thresholdCount)
|
||||
.build();
|
||||
} else {
|
||||
alarmPolicy = TimerPolicy.builder().alarmKey(new DynamicAlarmKey(key)).coolDownMs(coolDownSec * 1000)
|
||||
.timeWindowMs(timeWindowSec * 1000).build();
|
||||
alarmPolicy = TimerPolicy.builder().alarmKey(new DynamicAlarmKey(key)).timeWindowMs(timeWindowSec * 1000)
|
||||
.build();
|
||||
}
|
||||
|
||||
return alarmPolicy;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Map<AlarmKey, SendPolicy> getSendPolicy() {
|
||||
|
||||
Map<AlarmKey, SendPolicy> policyMap = new HashMap<AlarmKey, SendPolicy>();
|
||||
@@ -95,11 +100,11 @@ public class AlarmService {
|
||||
String keyName = (String) key;
|
||||
String configStr = (String) value;
|
||||
|
||||
if (!keyName.contains(ALARM_RECIVER)) return;
|
||||
if (!keyName.contains(ALARM_RECIVER))
|
||||
return;
|
||||
|
||||
SendPolicy newPolicy = buildSendPolicy(keyName, configStr);
|
||||
|
||||
|
||||
|
||||
policyMap.put(newPolicy.getAlarmKey(), newPolicy);
|
||||
|
||||
});
|
||||
@@ -111,12 +116,13 @@ public class AlarmService {
|
||||
|
||||
return policyMap;
|
||||
}
|
||||
|
||||
|
||||
private SendPolicy buildSendPolicy(String key, String configStr) {
|
||||
|
||||
List<String> reciverList = Optional.ofNullable(configStr).map( t -> Arrays.asList(t.split(",")) ).orElse(Collections.EMPTY_LIST);
|
||||
|
||||
key = key.replaceAll(ALARM_RECIVER, "").trim();
|
||||
List<String> reciverList = Optional.ofNullable(configStr).map(t -> Arrays.asList(t.split(",")))
|
||||
.orElse(Collections.EMPTY_LIST);
|
||||
|
||||
key = key.replace(ALARM_RECIVER, "").trim() + "{ALARM}";
|
||||
|
||||
SendPolicy sendPolicy = new SendPolicy(key, reciverList);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user