이벤트 성격에 따라 발송정책(SendPolicy)를 두고 그에 따라 UMS연계하여 문자메세지 발송하도록 추가.
UMS playload관련 패키지 이동.
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
package com.eactive.eai.custom.alarm;
|
package com.eactive.eai.custom.alarm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@@ -12,11 +14,12 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.eactive.eai.common.property.PropManager;
|
import com.eactive.eai.common.property.PropManager;
|
||||||
import com.eactive.eai.common.util.Jsons;
|
import com.eactive.eai.common.util.Jsons;
|
||||||
import com.eactive.eai.common.util.Logger;
|
import com.eactive.eai.common.util.Logger;
|
||||||
|
import com.eactive.eai.custom.alarm.key.AlarmKey;
|
||||||
import com.eactive.eai.custom.alarm.key.DynamicAlarmKey;
|
import com.eactive.eai.custom.alarm.key.DynamicAlarmKey;
|
||||||
import com.eactive.eai.custom.alarm.policy.AlarmPolicy;
|
import com.eactive.eai.custom.alarm.policy.AlarmPolicy;
|
||||||
import com.eactive.eai.custom.alarm.policy.CounterPolicy;
|
import com.eactive.eai.custom.alarm.policy.CounterPolicy;
|
||||||
|
import com.eactive.eai.custom.alarm.policy.SendPolicy;
|
||||||
import com.eactive.eai.custom.alarm.policy.TimerPolicy;
|
import com.eactive.eai.custom.alarm.policy.TimerPolicy;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -28,9 +31,9 @@ public class AlarmService {
|
|||||||
final static String ALARM_KEY = "Alarm";
|
final static String ALARM_KEY = "Alarm";
|
||||||
final static String ALARM_RECIVER = "{RECIVER}";
|
final static String ALARM_RECIVER = "{RECIVER}";
|
||||||
|
|
||||||
public List<AlarmPolicy> getAlarmPolicy() {
|
public Map<AlarmKey, AlarmPolicy> getAlarmPolicy() {
|
||||||
|
|
||||||
List<AlarmPolicy> policyList = new ArrayList<AlarmPolicy>();
|
Map<AlarmKey, AlarmPolicy> policyMap = new HashMap<AlarmKey, AlarmPolicy>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -40,22 +43,24 @@ public class AlarmService {
|
|||||||
String keyName = (String) key;
|
String keyName = (String) key;
|
||||||
String configStr = (String) value;
|
String configStr = (String) value;
|
||||||
|
|
||||||
if (keyName.contains(ALARM_RECIVER))
|
if (keyName.contains(ALARM_RECIVER)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
policyList.add(buildAlarmPolicy(keyName, configStr));
|
AlarmPolicy newPolicy = buildAlarmPolicy(keyName, configStr);
|
||||||
|
|
||||||
|
|
||||||
|
policyMap.put(newPolicy.getAlarmKey(), newPolicy);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("getAlarmPolicy fail.", e);
|
logger.warn("getAlarmPolicy fail.", e);
|
||||||
return Collections.EMPTY_LIST;
|
return Collections.EMPTY_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return policyMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
AlarmPolicy buildAlarmPolicy(String key, String configJsonStr) {
|
private AlarmPolicy buildAlarmPolicy(String key, String configJsonStr) {
|
||||||
|
|
||||||
JsonObject alarmConfig = Jsons.GSON.fromJson(configJsonStr, JsonObject.class);
|
JsonObject alarmConfig = Jsons.GSON.fromJson(configJsonStr, JsonObject.class);
|
||||||
|
|
||||||
@@ -77,4 +82,45 @@ public class AlarmService {
|
|||||||
return alarmPolicy;
|
return alarmPolicy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<AlarmKey, SendPolicy> getSendPolicy() {
|
||||||
|
|
||||||
|
Map<AlarmKey, SendPolicy> policyMap = new HashMap<AlarmKey, SendPolicy>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
SendPolicy newPolicy = buildSendPolicy(keyName, configStr);
|
||||||
|
|
||||||
|
|
||||||
|
policyMap.put(newPolicy.getAlarmKey(), newPolicy);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("getSendPolicy fail.", e);
|
||||||
|
return Collections.EMPTY_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
SendPolicy sendPolicy = new SendPolicy(key, reciverList);
|
||||||
|
|
||||||
|
return sendPolicy;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,77 +2,117 @@ package com.eactive.eai.custom.alarm;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.eactive.eai.common.util.Logger;
|
import com.eactive.eai.common.util.Logger;
|
||||||
import com.eactive.eai.custom.alarm.event.AlarmEvent;
|
import com.eactive.eai.custom.alarm.event.AlarmEvent;
|
||||||
|
import com.eactive.eai.custom.alarm.key.AlarmKey;
|
||||||
|
import com.eactive.eai.custom.alarm.policy.AlarmPolicy;
|
||||||
|
import com.eactive.eai.custom.alarm.policy.CounterPolicy;
|
||||||
|
import com.eactive.eai.custom.alarm.policy.SendPolicy;
|
||||||
|
import com.eactive.eai.custom.alarm.ums.UmsService;
|
||||||
|
import com.eactive.eai.custom.alarm.ums.payload.IUmsGsonObject;
|
||||||
|
import com.eactive.eai.custom.alarm.ums.payload.ObpMonitoringUmsTemplate;
|
||||||
|
import com.eactive.eai.custom.alarm.ums.payload.UmsRequestPayload;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AlarmStateManager {
|
public class AlarmStateManager {
|
||||||
|
|
||||||
|
|
||||||
List<AlarmEvent> registerAlarmList = new ArrayList<AlarmEvent>();
|
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
|
||||||
|
|
||||||
protected static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
|
||||||
|
|
||||||
|
|
||||||
public AlarmStateManager() {
|
|
||||||
|
|
||||||
this.scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
|
|
||||||
Thread t = new Thread(r);
|
|
||||||
t.setName("AlarmStateManager-worker");
|
|
||||||
t.setDaemon(false);
|
|
||||||
return t;
|
|
||||||
});
|
|
||||||
|
|
||||||
scheduler.scheduleWithFixedDelay(() -> {
|
|
||||||
|
|
||||||
try {
|
List<AlarmEvent> registerAlarmList = new ArrayList<AlarmEvent>();
|
||||||
// === 여기에 지속 실행할 로직 ===
|
|
||||||
fireAlarm();
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
private final ScheduledExecutorService scheduler;
|
||||||
// 반드시 예외 잡기 (안 잡으면 스케줄 자체가 죽음)
|
|
||||||
logger.error("fireAlarm fail", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}, 0, 5, TimeUnit.SECONDS); // 최초 0초, 이후 5초 간격
|
protected static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AlarmService alarmService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UmsService usmService;
|
||||||
|
|
||||||
|
public AlarmStateManager() {
|
||||||
|
|
||||||
|
this.scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
|
||||||
|
Thread t = new Thread(r);
|
||||||
|
t.setName("AlarmStateManager-worker");
|
||||||
|
t.setDaemon(false);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
|
||||||
|
scheduler.scheduleWithFixedDelay(() -> {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// === 여기에 지속 실행할 로직 ===
|
||||||
|
fireAlarm();
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// 반드시 예외 잡기 (안 잡으면 스케줄 자체가 죽음)
|
||||||
|
logger.error("fireAlarm fail", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 0, 5, TimeUnit.SECONDS); // 최초 0초, 이후 5초 간격
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEvnet(AlarmEvent alaramEvent) {
|
||||||
|
|
||||||
|
Optional<AlarmEvent> existEvent = registerAlarmList.stream().filter(e -> e.equals(alaramEvent)).findFirst();
|
||||||
|
|
||||||
|
if (existEvent.isPresent()) {
|
||||||
|
AlarmEvent event = existEvent.get();
|
||||||
|
event.onOcurr();
|
||||||
|
} else {
|
||||||
|
registerAlarmList.add(alaramEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onEvnet(AlarmEvent alaramEvent) {
|
|
||||||
|
|
||||||
Optional<AlarmEvent> existEvent =
|
|
||||||
registerAlarmList.stream()
|
|
||||||
.filter(e -> e.equals(alaramEvent))
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
if (existEvent.isPresent()) {
|
}
|
||||||
AlarmEvent event = existEvent.get();
|
|
||||||
event.onOcurr();
|
private void fireAlarm() {
|
||||||
} else {
|
|
||||||
registerAlarmList.add(alaramEvent);
|
Map<AlarmKey, AlarmPolicy> alarmPolicyMap = alarmService.getAlarmPolicy();
|
||||||
}
|
Map<AlarmKey, SendPolicy> sendPolicyMap = alarmService.getSendPolicy();
|
||||||
|
|
||||||
|
for (AlarmEvent event : registerAlarmList) {
|
||||||
|
|
||||||
|
AlarmPolicy alarmPolicy = alarmPolicyMap.get(event.getKey());
|
||||||
|
|
||||||
|
if (alarmPolicy.isAlarmTriggered(event)) {
|
||||||
|
|
||||||
|
SendPolicy sendPolicy = sendPolicyMap.get(event.getKey());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireAlarm() {
|
}
|
||||||
|
|
||||||
for(AlarmEvent event : registerAlarmList) {
|
private void send(SendPolicy sendPolicy, AlarmEvent event) {
|
||||||
|
|
||||||
|
UmsRequestPayload payload = null;
|
||||||
|
|
||||||
}
|
try {
|
||||||
|
|
||||||
|
List<String> cellPhoneList = sendPolicy.getCellpohoneList();
|
||||||
|
|
||||||
|
for (String cellPhone : cellPhoneList) {
|
||||||
|
|
||||||
|
payload = UmsRequestPayload.builder()
|
||||||
|
.content(ObpMonitoringUmsTemplate.builder().message(event.getMessage()).build())
|
||||||
|
.cellphone(cellPhone).build();
|
||||||
|
|
||||||
|
usmService.send(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(String.format("Alarm message delivery failed (UMS), payload=%s", payload), e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,9 +6,8 @@ import lombok.Getter;
|
|||||||
@Builder
|
@Builder
|
||||||
@Getter
|
@Getter
|
||||||
public class AlarmCondition {
|
public class AlarmCondition {
|
||||||
AlarmLevel level;
|
final long ocurredAt = System.currentTimeMillis();
|
||||||
final long ocurredAt;
|
long lastOcurredAt; // 일단, 미사용
|
||||||
long lastOcurredAt;
|
|
||||||
long count = 1;
|
long count = 1;
|
||||||
|
|
||||||
public void onOcurr() {
|
public void onOcurr() {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import com.eactive.eai.custom.alarm.condition.AlarmCondition;
|
import com.eactive.eai.custom.alarm.condition.AlarmCondition;
|
||||||
import com.eactive.eai.custom.alarm.key.AlarmKey;
|
import com.eactive.eai.custom.alarm.key.AlarmKey;
|
||||||
|
import com.eactive.eai.custom.alarm.policy.AlarmPolicy;
|
||||||
|
import com.eactive.eai.custom.alarm.policy.CounterPolicy;
|
||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -34,4 +36,6 @@ public class AlarmEvent {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(key);
|
return Objects.hash(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.eactive.eai.custom.alarm.key;
|
package com.eactive.eai.custom.alarm.key;
|
||||||
public enum CoreAlarmKey implements AlarmKey {
|
|
||||||
CircuitBreaker;
|
|
||||||
|
|
||||||
@Override
|
public final class CoreAlarmKey {
|
||||||
public String code() {
|
|
||||||
return name();
|
private CoreAlarmKey() { }
|
||||||
}
|
|
||||||
|
public static final AlarmKey CircuitBreaker = new DynamicAlarmKey("CircuitBreaker");
|
||||||
|
|
||||||
|
public static final AlarmKey Timeout = new DynamicAlarmKey("Timeout");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.eactive.eai.custom.alarm.policy;
|
package com.eactive.eai.custom.alarm.policy;
|
||||||
|
|
||||||
|
import com.eactive.eai.custom.alarm.condition.AlarmCondition;
|
||||||
import com.eactive.eai.custom.alarm.event.AlarmEvent;
|
import com.eactive.eai.custom.alarm.event.AlarmEvent;
|
||||||
import com.eactive.eai.custom.alarm.key.AlarmKey;
|
import com.eactive.eai.custom.alarm.key.AlarmKey;
|
||||||
|
|
||||||
@@ -36,11 +37,12 @@ public abstract class AlarmPolicy {
|
|||||||
return coolDownMs;
|
return coolDownMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract boolean isAlarmTriggered(AlarmEvent event);
|
public abstract boolean isAlarmTriggered(AlarmEvent event);
|
||||||
|
|
||||||
|
|
||||||
public boolean hasElapsed(long baseTimeMs, long currentTimeMs) {
|
public boolean hasElapsed(long baseTimeMs) {
|
||||||
|
|
||||||
return currentTimeMs - baseTimeMs >= timeWindowMs;
|
return System.currentTimeMillis() - baseTimeMs >= timeWindowMs;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class CounterPolicy extends AlarmPolicy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isAlarmTriggered(AlarmEvent event) {
|
public boolean isAlarmTriggered(AlarmEvent event) {
|
||||||
|
|
||||||
if (!event.equals(getAlarmKey())) {
|
if (!event.equals(getAlarmKey())) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.eactive.eai.custom.alarm.policy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.eactive.eai.custom.alarm.key.AlarmKey;
|
||||||
|
import com.eactive.eai.custom.alarm.key.DynamicAlarmKey;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class SendPolicy {
|
||||||
|
|
||||||
|
final AlarmKey alarmKey;
|
||||||
|
|
||||||
|
final List<String> cellpohoneList = new ArrayList<String>();
|
||||||
|
|
||||||
|
public SendPolicy(String alarmKey, List<String> cellPhoneList) {
|
||||||
|
this.alarmKey = new DynamicAlarmKey(alarmKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,16 +11,15 @@ public class TimerPolicy extends AlarmPolicy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isAlarmTriggered(AlarmEvent event) {
|
public boolean isAlarmTriggered(AlarmEvent event) {
|
||||||
|
|
||||||
if (event.equals(getAlarmKey())) {
|
if (event.equals(getAlarmKey())) {
|
||||||
|
|
||||||
AlarmCondition condition = event.getCondition();
|
AlarmCondition condition = event.getCondition();
|
||||||
|
|
||||||
long baseTimeMs = condition.getOcurredAt();
|
long baseTimeMs = condition.getOcurredAt();
|
||||||
long lastTimeMs = condition.getLastOcurredAt();
|
|
||||||
|
|
||||||
if (hasElapsed(baseTimeMs, lastTimeMs)) {
|
if (hasElapsed(baseTimeMs)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.eactive.eai.custom.alarm.ums;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.eactive.eai.common.util.Logger;
|
||||||
|
import com.eactive.eai.custom.alarm.ums.payload.UmsRequestPayload;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class UmsSendManager {
|
||||||
|
|
||||||
|
private final ScheduledExecutorService scheduler;
|
||||||
|
|
||||||
|
protected static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||||
|
|
||||||
|
Queue<UmsRequestPayload> queue = new ConcurrentLinkedQueue<UmsRequestPayload>();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UmsService umsService;
|
||||||
|
|
||||||
|
public UmsSendManager() {
|
||||||
|
this.scheduler = Executors.newSingleThreadScheduledExecutor(r -> {
|
||||||
|
Thread t = new Thread(r);
|
||||||
|
t.setName("AlarmStateManager-worker");
|
||||||
|
t.setDaemon(false);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
|
||||||
|
scheduler.scheduleWithFixedDelay(() -> {
|
||||||
|
|
||||||
|
try {
|
||||||
|
// === 여기에 지속 실행할 로직 ===
|
||||||
|
sendMessage();
|
||||||
|
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// 반드시 예외 잡기 (안 잡으면 스케줄 자체가 죽음)
|
||||||
|
logger.error("fireAlarm fail", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, 0, 5, TimeUnit.SECONDS); // 최초 0초, 이후 5초 간격
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendMessage() throws Exception {
|
||||||
|
UmsRequestPayload payload;
|
||||||
|
while ((payload = queue.poll()) != null) {
|
||||||
|
umsService.send(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enqueue(UmsRequestPayload payload) {
|
||||||
|
queue.offer(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,8 +2,6 @@ package com.eactive.eai.custom.alarm.ums;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -21,8 +19,10 @@ import org.apache.hc.core5.util.Timeout;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.StreamUtils;
|
import org.springframework.util.StreamUtils;
|
||||||
|
|
||||||
|
import com.eactive.eai.common.util.Jsons;
|
||||||
import com.eactive.eai.common.util.Logger;
|
import com.eactive.eai.common.util.Logger;
|
||||||
import com.google.gson.Gson;
|
import com.eactive.eai.custom.alarm.ums.payload.UmsRequestPayload;
|
||||||
|
import com.eactive.eai.custom.alarm.ums.payload.ValidationUtil;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -36,18 +36,16 @@ public class UmsService {
|
|||||||
private final static String CONTENT_TYPE = "application/json; charset=utf-8";
|
private final static String CONTENT_TYPE = "application/json; charset=utf-8";
|
||||||
private final static String AUTHORIZATION_FMT = "Bearer %s";
|
private final static String AUTHORIZATION_FMT = "Bearer %s";
|
||||||
|
|
||||||
Future<UmsCallResult> send(String cpno, String message, UmsBizWorkCode code) throws Exception {
|
public Future<UmsCallResult> send(UmsRequestPayload payload) throws Exception {
|
||||||
|
|
||||||
if (message == null) {
|
if (payload.getContent() == null) {
|
||||||
throw new IllegalArgumentException("content is null");
|
throw new IllegalArgumentException("content is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
String guid = String.format("APM-%s",
|
|
||||||
DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").format(LocalDateTime.now()));
|
|
||||||
|
|
||||||
UmsRequestPayload payload = UmsRequestPayload.builder().messageIdentityNo(guid).msgBizWorkCode(code.getCode())
|
// UmsRequestPayload payload = UmsRequestPayload.builder()
|
||||||
.content(ObpMonitoringUmsTemplate.builder().message(message).build()).cellphone(cpno)
|
// .content(ObpMonitoringUmsTemplate.builder().message(message).build()).cellphone(cpno)
|
||||||
.msgSndChnlCd(UmsRequestPayload.ChannelCode.KM).build();
|
// .build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ValidationUtil.validateOrThrow(payload);
|
ValidationUtil.validateOrThrow(payload);
|
||||||
@@ -66,8 +64,8 @@ public class UmsService {
|
|||||||
private Future<UmsCallResult> call(String url, UmsRequestPayload requestPayload) throws Exception {
|
private Future<UmsCallResult> call(String url, UmsRequestPayload requestPayload) throws Exception {
|
||||||
|
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
Gson gson = new Gson();
|
|
||||||
String json = gson.toJson(requestPayload);
|
String json = Jsons.GSON.toJson(requestPayload);
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost(UMS_URL + url);
|
HttpPost httpPost = new HttpPost(UMS_URL + url);
|
||||||
httpPost.setHeader("Content-Type", CONTENT_TYPE);
|
httpPost.setHeader("Content-Type", CONTENT_TYPE);
|
||||||
@@ -97,7 +95,7 @@ public class UmsService {
|
|||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Response - {}", body);
|
logger.debug("Response - {}", body);
|
||||||
}
|
}
|
||||||
result = gson.fromJson(body, UmsCallResult.class);
|
result = Jsons.GSON.fromJson(body, UmsCallResult.class);
|
||||||
result.setUmsMessageId(requestPayload.getMessageIdentityNo());
|
result.setUmsMessageId(requestPayload.getMessageIdentityNo());
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.eactive.eai.custom.alarm.ums;
|
package com.eactive.eai.custom.alarm.ums.payload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GSON Serialize 용 Object
|
* GSON Serialize 용 Object
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.eactive.eai.custom.alarm.ums;
|
package com.eactive.eai.custom.alarm.ums.payload;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.eactive.eai.custom.alarm.ums;
|
package com.eactive.eai.custom.alarm.ums.payload;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
+5
-3
@@ -1,4 +1,4 @@
|
|||||||
package com.eactive.eai.custom.alarm.ums;
|
package com.eactive.eai.custom.alarm.ums.payload;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -22,13 +22,15 @@ public class UmsRequestPayload {
|
|||||||
@Length(min = 1, max = 50)
|
@Length(min = 1, max = 50)
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
@SerializedName("MSG_IDNT_NO")
|
@SerializedName("MSG_IDNT_NO")
|
||||||
private String messageIdentityNo;
|
@Builder.Default
|
||||||
|
private String messageIdentityNo = String.format("APM-%s",DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").format(LocalDateTime.now()));
|
||||||
|
|
||||||
// MSG_BZWK_CD string 메시지업무코드 30 O UMS에 등록된 메시지업무코드(AS-IS 템플릿ID)
|
// MSG_BZWK_CD string 메시지업무코드 30 O UMS에 등록된 메시지업무코드(AS-IS 템플릿ID)
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
@Length(min = 1, max = 30)
|
@Length(min = 1, max = 30)
|
||||||
@SerializedName("MSG_BZWK_CD")
|
@SerializedName("MSG_BZWK_CD")
|
||||||
private String msgBizWorkCode;
|
@Builder.Default
|
||||||
|
private String msgBizWorkCode = UmsBizWorkCode.MONITORING.getCode();
|
||||||
|
|
||||||
// 메시지업무파라미터내용 / 4000 / JSONObject
|
// 메시지업무파라미터내용 / 4000 / JSONObject
|
||||||
// MSG_BZWK_PARAM_CTNT object 메시지업무파라미터내용 4000 메시지업무코드의 템플릿에서 사용하는 변수와 변수값
|
// MSG_BZWK_PARAM_CTNT object 메시지업무파라미터내용 4000 메시지업무코드의 템플릿에서 사용하는 변수와 변수값
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.eactive.eai.custom.alarm.ums;
|
package com.eactive.eai.custom.alarm.ums.payload;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.eactive.eai.custom.alarm.ums;
|
package com.eactive.eai.custom.alarm.ums.payload;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
Reference in New Issue
Block a user