inflow group 추가
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
package com.eactive.eai.agent.inflow;
|
||||||
|
|
||||||
|
import com.eactive.eai.agent.command.Command;
|
||||||
|
import com.eactive.eai.agent.command.CommandException;
|
||||||
|
import com.eactive.eai.common.inflow.InflowControlManager;
|
||||||
|
import com.eactive.eai.common.util.Logger;
|
||||||
|
|
||||||
|
public class ReloadInflowGroupControlCommand extends Command {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public ReloadInflowGroupControlCommand() {
|
||||||
|
super("ReloadInflowGroupControlCommand");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute() throws CommandException {
|
||||||
|
Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||||
|
if (logger.isInfo())
|
||||||
|
logger.info(this.name + " is executed");
|
||||||
|
|
||||||
|
if (!(args instanceof String)) {
|
||||||
|
String rspErrorCode = "RECEAIMCM001";
|
||||||
|
String msg = makeException(rspErrorCode, null);
|
||||||
|
if (logger.isError())
|
||||||
|
logger.error(msg);
|
||||||
|
throw new CommandException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
String keyName = (String) args;
|
||||||
|
try {
|
||||||
|
InflowControlManager manager = InflowControlManager.getInstance();
|
||||||
|
|
||||||
|
if (keyName != null) {
|
||||||
|
if ("ALL".equals(keyName)) {
|
||||||
|
manager.reloadGroup();
|
||||||
|
if (logger.isWarn())
|
||||||
|
logger.warn(this.name + "] all group rule Reload.");
|
||||||
|
} else {
|
||||||
|
manager.reloadGroup(keyName);
|
||||||
|
if (logger.isWarn())
|
||||||
|
logger.warn(this.name + "] group " + keyName + " Reload.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
String rspErrorCode = "RECEAIMCM002";
|
||||||
|
String msg = makeException(rspErrorCode, e);
|
||||||
|
if (logger.isError())
|
||||||
|
logger.error(msg, e);
|
||||||
|
throw new CommandException(msg);
|
||||||
|
}
|
||||||
|
return "success";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.eactive.eai.agent.inflow;
|
||||||
|
|
||||||
|
import com.eactive.eai.agent.command.Command;
|
||||||
|
import com.eactive.eai.agent.command.CommandException;
|
||||||
|
import com.eactive.eai.common.inflow.InflowControlManager;
|
||||||
|
import com.eactive.eai.common.util.Logger;
|
||||||
|
|
||||||
|
public class RemoveInflowGroupControlCommand extends Command {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public RemoveInflowGroupControlCommand() {
|
||||||
|
super("RemoveInflowGroupControlCommand");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute() throws CommandException {
|
||||||
|
Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||||
|
if (logger.isInfo())
|
||||||
|
logger.info(this.name + " is executed");
|
||||||
|
|
||||||
|
if (!(args instanceof String)) {
|
||||||
|
String rspErrorCode = "RECEAIMCM001";
|
||||||
|
String msg = makeException(rspErrorCode, null);
|
||||||
|
if (logger.isError())
|
||||||
|
logger.error(msg);
|
||||||
|
throw new CommandException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
String key = (String) args;
|
||||||
|
try {
|
||||||
|
InflowControlManager manager = InflowControlManager.getInstance();
|
||||||
|
manager.removeGroup(key);
|
||||||
|
if (logger.isWarn())
|
||||||
|
logger.warn(this.name + "] group " + key + " removed.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
String rspErrorCode = "RECEAIMCM002";
|
||||||
|
String msg = makeException(rspErrorCode, e);
|
||||||
|
if (logger.isError())
|
||||||
|
logger.error(msg, e);
|
||||||
|
throw new CommandException(msg);
|
||||||
|
}
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,4 +6,9 @@ public interface Bucket {
|
|||||||
public InflowTargetVO getAdapterInflowThreashold(String adapter);
|
public InflowTargetVO getAdapterInflowThreashold(String adapter);
|
||||||
public InflowTargetVO getInterfaceInflowThreashold(String inter);
|
public InflowTargetVO getInterfaceInflowThreashold(String inter);
|
||||||
public InflowTargetVO getInflowThreashold(String inter);
|
public InflowTargetVO getInflowThreashold(String inter);
|
||||||
|
|
||||||
|
// 그룹 관련 메서드
|
||||||
|
public boolean isGroupPass(String groupId);
|
||||||
|
public InflowGroupVO getGroupInflowThreshold(String groupId);
|
||||||
|
public String getGroupIdByInterface(String interfaceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,14 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import com.eactive.eai.common.dao.BaseDAO;
|
import com.eactive.eai.common.dao.BaseDAO;
|
||||||
import com.eactive.eai.common.dao.DAOException;
|
import com.eactive.eai.common.dao.DAOException;
|
||||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||||
|
import com.eactive.eai.common.inflow.loader.InflowControlGroupLoader;
|
||||||
|
import com.eactive.eai.common.inflow.loader.InflowControlGroupMappingLoader;
|
||||||
import com.eactive.eai.common.inflow.loader.InflowControlLoader;
|
import com.eactive.eai.common.inflow.loader.InflowControlLoader;
|
||||||
import com.eactive.eai.common.inflow.loader.InflowControlLogLogger;
|
import com.eactive.eai.common.inflow.loader.InflowControlLogLogger;
|
||||||
import com.eactive.eai.common.util.Logger;
|
import com.eactive.eai.common.util.Logger;
|
||||||
import com.eactive.eai.data.entity.onl.inflow.InflowControl;
|
import com.eactive.eai.data.entity.onl.inflow.InflowControl;
|
||||||
|
import com.eactive.eai.data.entity.onl.inflow.InflowControlGroup;
|
||||||
|
import com.eactive.eai.data.entity.onl.inflow.InflowControlGroupMapping;
|
||||||
import com.eactive.eai.data.entity.onl.inflow.InflowControlLog;
|
import com.eactive.eai.data.entity.onl.inflow.InflowControlLog;
|
||||||
import com.eactive.eai.data.entity.onl.inflow.InflowControlLogId;
|
import com.eactive.eai.data.entity.onl.inflow.InflowControlLogId;
|
||||||
|
|
||||||
@@ -30,6 +34,12 @@ public class InflowControlDAO extends BaseDAO {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private InflowControlLogLogger inflowControlLogLogger;
|
private InflowControlLogLogger inflowControlLogLogger;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InflowControlGroupLoader inflowControlGroupLoader;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private InflowControlGroupMappingLoader inflowControlGroupMappingLoader;
|
||||||
|
|
||||||
public List<InflowTargetVO> getInflowAdapterList() throws DAOException {
|
public List<InflowTargetVO> getInflowAdapterList() throws DAOException {
|
||||||
return getInflowList("01");
|
return getInflowList("01");
|
||||||
}
|
}
|
||||||
@@ -132,4 +142,89 @@ public class InflowControlDAO extends BaseDAO {
|
|||||||
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICMM101"));
|
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICMM101"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== 그룹 관련 메서드 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 활성화된 유량제어 그룹 목록 조회
|
||||||
|
*/
|
||||||
|
public List<InflowGroupVO> getInflowGroupList() throws DAOException {
|
||||||
|
try {
|
||||||
|
Iterable<InflowControlGroup> groups = inflowControlGroupLoader.findActiveGroups();
|
||||||
|
List<InflowGroupVO> groupList = new ArrayList<>();
|
||||||
|
logger.info("[ @@ Load InflowControlGroup Configuration - starting >>>>>>>>>>>>>>>>> ]");
|
||||||
|
|
||||||
|
for (InflowControlGroup group : groups) {
|
||||||
|
InflowGroupVO vo = convertToGroupVO(group);
|
||||||
|
// 그룹에 속한 인터페이스 목록 조회
|
||||||
|
Iterable<InflowControlGroupMapping> mappings = inflowControlGroupMappingLoader.findActiveByGroupId(group.getGroupId());
|
||||||
|
for (InflowControlGroupMapping mapping : mappings) {
|
||||||
|
vo.addInterface(mapping.getInterfaceId());
|
||||||
|
}
|
||||||
|
groupList.add(vo);
|
||||||
|
}
|
||||||
|
logger.info("[>>Load InflowControlGroup Configuration - ended. count=" + groupList.size() + " ]");
|
||||||
|
return groupList;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICMM101"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 인터페이스ID → 그룹ID 매핑 조회
|
||||||
|
*/
|
||||||
|
public Map<String, String> getInterfaceToGroupMap() throws DAOException {
|
||||||
|
try {
|
||||||
|
Iterable<InflowControlGroupMapping> mappings = inflowControlGroupMappingLoader.findActiveMappings();
|
||||||
|
Map<String, String> interfaceToGroupMap = new HashMap<>();
|
||||||
|
logger.info("[ @@ Load InterfaceToGroupMap Configuration - starting >>>>>>>>>>>>>>>>> ]");
|
||||||
|
|
||||||
|
for (InflowControlGroupMapping mapping : mappings) {
|
||||||
|
interfaceToGroupMap.put(mapping.getInterfaceId(), mapping.getGroupId());
|
||||||
|
}
|
||||||
|
logger.info("[>>Load InterfaceToGroupMap Configuration - ended. count=" + interfaceToGroupMap.size() + " ]");
|
||||||
|
return interfaceToGroupMap;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICMM101"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 특정 그룹 조회
|
||||||
|
*/
|
||||||
|
public Map<String, InflowGroupVO> getInflowTargetByGroup(String groupId) throws DAOException {
|
||||||
|
try {
|
||||||
|
Iterable<InflowControlGroup> groups = inflowControlGroupLoader.findByConditions(groupId);
|
||||||
|
Map<String, InflowGroupVO> groupMap = new HashMap<>();
|
||||||
|
logger.info("[ @@ Load InflowControlGroup getInflowTargetByGroup Configuration - starting >>>>>>>>>>>>>>>>> ]");
|
||||||
|
|
||||||
|
for (InflowControlGroup group : groups) {
|
||||||
|
InflowGroupVO vo = convertToGroupVO(group);
|
||||||
|
// 그룹에 속한 인터페이스 목록 조회
|
||||||
|
Iterable<InflowControlGroupMapping> mappings = inflowControlGroupMappingLoader.findActiveByGroupId(group.getGroupId());
|
||||||
|
for (InflowControlGroupMapping mapping : mappings) {
|
||||||
|
vo.addInterface(mapping.getInterfaceId());
|
||||||
|
}
|
||||||
|
groupMap.put(vo.getGroupId(), vo);
|
||||||
|
}
|
||||||
|
logger.info("[>>Load InflowControlGroup getInflowTargetByGroup Configuration - ended ]");
|
||||||
|
return groupMap;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICMM101"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity → VO 변환
|
||||||
|
*/
|
||||||
|
private InflowGroupVO convertToGroupVO(InflowControlGroup group) {
|
||||||
|
InflowGroupVO vo = new InflowGroupVO();
|
||||||
|
vo.setGroupId(group.getGroupId());
|
||||||
|
vo.setGroupName(group.getGroupName());
|
||||||
|
vo.setThreshold(group.getThreshold() != null ? group.getThreshold() : 0);
|
||||||
|
vo.setThresholdPerSecond(group.getThresholdPerSecond() != null ? group.getThresholdPerSecond() : 0);
|
||||||
|
vo.setThresholdTimeUnit(group.getThresholdTimeUnit());
|
||||||
|
vo.setActivate(!"0".equals(group.getUseYn()));
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,9 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
|
|
||||||
private Map<String, CustomBucket> adapterBucketList = new HashMap<>();
|
private Map<String, CustomBucket> adapterBucketList = new HashMap<>();
|
||||||
private Map<String, CustomBucket> interfaceBucketList = new HashMap<>();
|
private Map<String, CustomBucket> interfaceBucketList = new HashMap<>();
|
||||||
|
private Map<String, CustomBucket> groupBucketList = new HashMap<>();
|
||||||
|
private Map<String, String> interfaceToGroupMap = new HashMap<>();
|
||||||
|
private Map<String, InflowGroupVO> groupVoMap = new HashMap<>();
|
||||||
private boolean started;
|
private boolean started;
|
||||||
private LifecycleSupport lifecycle = new LifecycleSupport(this);
|
private LifecycleSupport lifecycle = new LifecycleSupport(this);
|
||||||
|
|
||||||
@@ -91,6 +94,7 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
private void init() throws Exception {
|
private void init() throws Exception {
|
||||||
initAdapter();
|
initAdapter();
|
||||||
initInterface();
|
initInterface();
|
||||||
|
initGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAdapter() throws Exception {
|
private void initAdapter() throws Exception {
|
||||||
@@ -121,6 +125,33 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initGroup() throws Exception {
|
||||||
|
groupBucketList = new HashMap<>();
|
||||||
|
interfaceToGroupMap = new HashMap<>();
|
||||||
|
groupVoMap = new HashMap<>();
|
||||||
|
|
||||||
|
List<InflowGroupVO> inflowGroupVoList = inflowControlDAO.getInflowGroupList();
|
||||||
|
|
||||||
|
for (InflowGroupVO groupVo : inflowGroupVoList) {
|
||||||
|
if (isInflowGroupTarget(groupVo)) {
|
||||||
|
CustomBucket bucket = makeBucketUsingGroupVO(groupVo);
|
||||||
|
if (bucket != null) {
|
||||||
|
groupBucketList.put(groupVo.getGroupId(), bucket);
|
||||||
|
groupVoMap.put(groupVo.getGroupId(), groupVo);
|
||||||
|
// 인터페이스 → 그룹 매핑 등록
|
||||||
|
for (String interfaceId : groupVo.getInterfaceList()) {
|
||||||
|
interfaceToGroupMap.put(interfaceId, groupVo.getGroupId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logger.isInfo()) {
|
||||||
|
logger.info("InflowControlManager] initGroup completed. groups=" + groupBucketList.size()
|
||||||
|
+ ", mappings=" + interfaceToGroupMap.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void reloadAdapter() throws Exception {
|
public synchronized void reloadAdapter() throws Exception {
|
||||||
if (logger.isWarn()) {
|
if (logger.isWarn()) {
|
||||||
logger.warn("InflowControlManager] reload all Started ...");
|
logger.warn("InflowControlManager] reload all Started ...");
|
||||||
@@ -200,6 +231,61 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void reloadGroup() throws Exception {
|
||||||
|
if (logger.isWarn()) {
|
||||||
|
logger.warn("InflowControlManager] reloadGroup all Started ...");
|
||||||
|
}
|
||||||
|
initGroup();
|
||||||
|
if (logger.isWarn()) {
|
||||||
|
logger.warn("InflowControlManager] reloadGroup all finished ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void reloadGroup(String groupId) throws Exception {
|
||||||
|
if (logger.isWarn()) {
|
||||||
|
logger.warn("InflowControlManager] reloadGroup Started ... groupId=" + groupId);
|
||||||
|
}
|
||||||
|
Map<String, InflowGroupVO> map = inflowControlDAO.getInflowTargetByGroup(groupId);
|
||||||
|
if (map != null) {
|
||||||
|
// 기존 그룹에 속한 인터페이스 매핑 제거
|
||||||
|
Iterator<Map.Entry<String, String>> mappingIt = interfaceToGroupMap.entrySet().iterator();
|
||||||
|
while (mappingIt.hasNext()) {
|
||||||
|
Map.Entry<String, String> entry = mappingIt.next();
|
||||||
|
if (groupId.equals(entry.getValue())) {
|
||||||
|
mappingIt.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<String> it = map.keySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
String key = it.next();
|
||||||
|
InflowGroupVO groupVo = map.get(key);
|
||||||
|
|
||||||
|
if (isInflowGroupTarget(groupVo)) {
|
||||||
|
CustomBucket bucket = makeBucketUsingGroupVO(groupVo);
|
||||||
|
if (bucket != null) {
|
||||||
|
groupBucketList.put(groupVo.getGroupId(), bucket);
|
||||||
|
groupVoMap.put(groupVo.getGroupId(), groupVo);
|
||||||
|
// 인터페이스 → 그룹 매핑 재등록
|
||||||
|
for (String interfaceId : groupVo.getInterfaceList()) {
|
||||||
|
interfaceToGroupMap.put(interfaceId, groupVo.getGroupId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
groupBucketList.remove(groupVo.getGroupId());
|
||||||
|
groupVoMap.remove(groupVo.getGroupId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
groupBucketList.remove(groupVo.getGroupId());
|
||||||
|
groupVoMap.remove(groupVo.getGroupId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logger.isWarn()) {
|
||||||
|
logger.warn("InflowControlManager] reloadGroup finished ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stop() throws LifecycleException {
|
public void stop() throws LifecycleException {
|
||||||
// Validate and update our current component state
|
// Validate and update our current component state
|
||||||
if (!started)
|
if (!started)
|
||||||
@@ -210,6 +296,9 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
|
|
||||||
adapterBucketList.clear();
|
adapterBucketList.clear();
|
||||||
interfaceBucketList.clear();
|
interfaceBucketList.clear();
|
||||||
|
groupBucketList.clear();
|
||||||
|
interfaceToGroupMap.clear();
|
||||||
|
groupVoMap.clear();
|
||||||
|
|
||||||
started = false;
|
started = false;
|
||||||
// Notify our interested LifecycleListeners
|
// Notify our interested LifecycleListeners
|
||||||
@@ -260,6 +349,29 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
interfaceBucketList.remove(inter);
|
interfaceBucketList.remove(inter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeGroup(String groupId) {
|
||||||
|
groupBucketList.remove(groupId);
|
||||||
|
groupVoMap.remove(groupId);
|
||||||
|
// 해당 그룹에 속한 인터페이스 매핑도 제거
|
||||||
|
Iterator<Map.Entry<String, String>> it = interfaceToGroupMap.entrySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<String, String> entry = it.next();
|
||||||
|
if (groupId.equals(entry.getValue())) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getGroupAllKeys() {
|
||||||
|
Iterator<String> it = this.groupBucketList.keySet().iterator();
|
||||||
|
String[] groupIds = new String[this.groupBucketList.size()];
|
||||||
|
for (int i = 0; it.hasNext(); i++) {
|
||||||
|
groupIds[i] = it.next();
|
||||||
|
}
|
||||||
|
Arrays.sort(groupIds);
|
||||||
|
return groupIds;
|
||||||
|
}
|
||||||
|
|
||||||
private CustomBucket makeBucketUsingInflowVO(InflowTargetVO inflowTarget) {
|
private CustomBucket makeBucketUsingInflowVO(InflowTargetVO inflowTarget) {
|
||||||
if (InflowControlManager.isInflowTarget(inflowTarget)) {
|
if (InflowControlManager.isInflowTarget(inflowTarget)) {
|
||||||
LocalBucketBuilder builder = Bucket4j.builder();
|
LocalBucketBuilder builder = Bucket4j.builder();
|
||||||
@@ -278,6 +390,32 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CustomBucket makeBucketUsingGroupVO(InflowGroupVO groupVo) {
|
||||||
|
if (isInflowGroupTarget(groupVo)) {
|
||||||
|
LocalBucketBuilder builder = Bucket4j.builder();
|
||||||
|
if (groupVo.getThresholdPerSecond() > 0) {
|
||||||
|
builder.addLimit(Bandwidth.simple(groupVo.getThresholdPerSecond(), Duration.ofSeconds(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupVo.getThreshold() > 0 && StringUtils.isNotBlank(groupVo.getThresholdTimeUnit())) {
|
||||||
|
builder.addLimit(Bandwidth.simple(groupVo.getThreshold(),
|
||||||
|
InflowControlManager.getPeriod(groupVo.getThresholdTimeUnit())));
|
||||||
|
}
|
||||||
|
|
||||||
|
// InflowTargetVO로 변환하여 CustomBucket 생성
|
||||||
|
InflowTargetVO targetVo = new InflowTargetVO();
|
||||||
|
targetVo.setName(groupVo.getGroupId());
|
||||||
|
targetVo.setThreshold(groupVo.getThreshold());
|
||||||
|
targetVo.setThresholdPerSecond(groupVo.getThresholdPerSecond());
|
||||||
|
targetVo.setThresholdTimeUnit(groupVo.getThresholdTimeUnit());
|
||||||
|
targetVo.setActivate(groupVo.isActivate());
|
||||||
|
|
||||||
|
return new CustomBucket(builder.build(), targetVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAdapterPass(String adapter) {
|
public boolean isAdapterPass(String adapter) {
|
||||||
CustomBucket b = adapterBucketList.get(adapter);
|
CustomBucket b = adapterBucketList.get(adapter);
|
||||||
@@ -327,6 +465,30 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
return getInterfaceInflowThreashold(inter);
|
return getInterfaceInflowThreashold(inter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGroupPass(String groupId) {
|
||||||
|
CustomBucket b = groupBucketList.get(groupId);
|
||||||
|
|
||||||
|
if (b == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return b.getLocalBucket().tryConsume(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InflowGroupVO getGroupInflowThreshold(String groupId) {
|
||||||
|
return groupVoMap.get(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroupIdByInterface(String interfaceId) {
|
||||||
|
return interfaceToGroupMap.get(interfaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InflowGroupVO getGroupInflow(String groupId) {
|
||||||
|
return getGroupInflowThreshold(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isInflowTarget(InflowTargetVO inflowTarget) {
|
public static boolean isInflowTarget(InflowTargetVO inflowTarget) {
|
||||||
if (inflowTarget == null || !inflowTarget.isActivate()) {
|
if (inflowTarget == null || !inflowTarget.isActivate()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -338,6 +500,16 @@ public class InflowControlManager implements Lifecycle, Bucket {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isInflowGroupTarget(InflowGroupVO groupVo) {
|
||||||
|
if (groupVo == null || !groupVo.isActivate()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return groupVo.getThresholdPerSecond() > 0 || (groupVo.getThreshold() > 0 && StringUtils
|
||||||
|
.equalsAnyIgnoreCase(groupVo.getThresholdTimeUnit(), QUOTA_TIMEUNIT_DAY, QUOTA_TIMEUNIT_SECOND,
|
||||||
|
QUOTA_TIMEUNIT_MINUTE, QUOTA_TIMEUNIT_HOUR, QUOTA_TIMEUNIT_DAY, QUOTA_TIMEUNIT_MONTH));
|
||||||
|
}
|
||||||
|
|
||||||
public static Duration getPeriod(String timeUnit) {
|
public static Duration getPeriod(String timeUnit) {
|
||||||
if (StringUtils.equalsIgnoreCase(timeUnit, QUOTA_TIMEUNIT_SECOND)) {
|
if (StringUtils.equalsIgnoreCase(timeUnit, QUOTA_TIMEUNIT_SECOND)) {
|
||||||
return Duration.ofSeconds(1);
|
return Duration.ofSeconds(1);
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.eactive.eai.common.inflow;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class InflowGroupVO implements Serializable {
|
||||||
|
private String groupId;
|
||||||
|
private String groupName;
|
||||||
|
private long thresholdPerSecond;
|
||||||
|
private long threshold;
|
||||||
|
private String thresholdTimeUnit;
|
||||||
|
private boolean activate;
|
||||||
|
private List<String> interfaceList = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof InflowGroupVO) {
|
||||||
|
return groupId.equals(((InflowGroupVO) obj).getGroupId());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return groupId != null ? groupId.hashCode() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupName() {
|
||||||
|
return groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroupName(String groupName) {
|
||||||
|
this.groupName = groupName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getThresholdPerSecond() {
|
||||||
|
return thresholdPerSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThresholdPerSecond(long thresholdPerSecond) {
|
||||||
|
this.thresholdPerSecond = thresholdPerSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getThreshold() {
|
||||||
|
return threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThreshold(long threshold) {
|
||||||
|
this.threshold = threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThresholdTimeUnit() {
|
||||||
|
return thresholdTimeUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThresholdTimeUnit(String thresholdTimeUnit) {
|
||||||
|
this.thresholdTimeUnit = thresholdTimeUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActivate() {
|
||||||
|
return activate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivate(boolean activate) {
|
||||||
|
this.activate = activate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getInterfaceList() {
|
||||||
|
return interfaceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInterfaceList(List<String> interfaceList) {
|
||||||
|
this.interfaceList = interfaceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addInterface(String interfaceId) {
|
||||||
|
if (this.interfaceList == null) {
|
||||||
|
this.interfaceList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
this.interfaceList.add(interfaceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "InflowGroupVO [groupId=" + groupId + ", groupName=" + groupName
|
||||||
|
+ ", thresholdPerSecond=" + thresholdPerSecond
|
||||||
|
+ ", threshold=" + threshold
|
||||||
|
+ ", thresholdTimeUnit=" + thresholdTimeUnit
|
||||||
|
+ ", activate=" + activate
|
||||||
|
+ ", interfaceCount=" + (interfaceList != null ? interfaceList.size() : 0) + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
//package com.eactive.eai.common.logger.mapper;
|
|
||||||
//
|
|
||||||
//import com.eactive.eai.common.logger.HttpAdapterExtraHeaderVo;
|
|
||||||
//import com.eactive.eai.data.entity.onl.logger.HttpAdapterExtraHeader;
|
|
||||||
//import com.eactive.eai.data.mapper.BaseMapperConfig;
|
|
||||||
//import com.eactive.eai.data.mapper.GenericMapper;
|
|
||||||
//
|
|
||||||
//import org.mapstruct.InheritInverseConfiguration;
|
|
||||||
//import org.mapstruct.Mapper;
|
|
||||||
//import org.mapstruct.Mapping;
|
|
||||||
//
|
|
||||||
//@Mapper(config = BaseMapperConfig.class)
|
|
||||||
//public interface HttpAdapterExtraHeaderMapper extends GenericMapper<HttpAdapterExtraHeaderVo, HttpAdapterExtraHeader> {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// @Mapping(source = "id.name", target = "name")
|
|
||||||
// HttpAdapterExtraHeaderVo toVo(HttpAdapterExtraHeader entity);
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// @InheritInverseConfiguration
|
|
||||||
// HttpAdapterExtraHeader toEntity(HttpAdapterExtraHeaderVo vo);
|
|
||||||
//}
|
|
||||||
@@ -27,6 +27,7 @@ import com.eactive.eai.common.exception.ExceptionUtil;
|
|||||||
import com.eactive.eai.common.inflow.Bucket;
|
import com.eactive.eai.common.inflow.Bucket;
|
||||||
import com.eactive.eai.common.inflow.InflowControlDAO;
|
import com.eactive.eai.common.inflow.InflowControlDAO;
|
||||||
import com.eactive.eai.common.inflow.InflowControlUtil;
|
import com.eactive.eai.common.inflow.InflowControlUtil;
|
||||||
|
import com.eactive.eai.common.inflow.InflowGroupVO;
|
||||||
import com.eactive.eai.common.inflow.InflowTargetVO;
|
import com.eactive.eai.common.inflow.InflowTargetVO;
|
||||||
import com.eactive.eai.common.logger.EAILogSender;
|
import com.eactive.eai.common.logger.EAILogSender;
|
||||||
import com.eactive.eai.common.message.EAIMessage;
|
import com.eactive.eai.common.message.EAIMessage;
|
||||||
@@ -1014,24 +1015,39 @@ public class RequestProcessor extends RequestProcessorSupport {
|
|||||||
Bucket bucket = InflowControlUtil.getBucket();
|
Bucket bucket = InflowControlUtil.getBucket();
|
||||||
|
|
||||||
String blockedType = "";
|
String blockedType = "";
|
||||||
|
// Adapter 유량제어 체크
|
||||||
if (!bucket.isAdapterPass(vo.getAdapterGroupName())) {
|
if (!bucket.isAdapterPass(vo.getAdapterGroupName())) {
|
||||||
blockedType += "A";
|
blockedType += "A";
|
||||||
}
|
}
|
||||||
if (!bucket.isInterfacePass(vo.getEaiSvcCd())) {
|
// 그룹 우선, 없으면 인터페이스 유량제어 체크
|
||||||
blockedType += "I";
|
String groupId = bucket.getGroupIdByInterface(vo.getEaiSvcCd());
|
||||||
|
if (groupId != null) {
|
||||||
|
// 그룹에 속한 인터페이스 → 그룹 유량제어 체크
|
||||||
|
if (!bucket.isGroupPass(groupId)) {
|
||||||
|
blockedType += "G";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 그룹에 속하지 않은 인터페이스 → 인터페이스 유량제어 체크
|
||||||
|
if (!bucket.isInterfacePass(vo.getEaiSvcCd())) {
|
||||||
|
blockedType += "I";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockedType.length() > 0) {
|
if (blockedType.length() > 0) {
|
||||||
InflowTargetVO inflowTargetVO = null;
|
InflowTargetVO inflowTargetVO = null;
|
||||||
|
InflowGroupVO inflowGroupVO = null;
|
||||||
if (blockedType.startsWith("A")) {
|
if (blockedType.startsWith("A")) {
|
||||||
inflowTargetVO = bucket.getAdapterInflowThreashold(vo.getAdapterGroupName());
|
inflowTargetVO = bucket.getAdapterInflowThreashold(vo.getAdapterGroupName());
|
||||||
|
} else if (blockedType.contains("G")) {
|
||||||
|
inflowGroupVO = bucket.getGroupInflowThreshold(groupId);
|
||||||
} else {
|
} else {
|
||||||
inflowTargetVO = bucket.getInterfaceInflowThreashold(vo.getEaiSvcCd());
|
inflowTargetVO = bucket.getInterfaceInflowThreashold(vo.getEaiSvcCd());
|
||||||
}
|
}
|
||||||
// 에러처리
|
// 에러처리
|
||||||
vo.setRspErrorCode(EAIMessageKeys.EAI_INFLOW_BLOCKED_CODE);
|
vo.setRspErrorCode(EAIMessageKeys.EAI_INFLOW_BLOCKED_CODE);
|
||||||
vo.setRspErrorMsg(ExceptionUtil.make(vo.getRspErrorCode(), vo.getEaiSvcCd() ) + ", "
|
String inflowInfo = (inflowGroupVO != null) ? inflowGroupVO.toString() :
|
||||||
+ inflowTargetVO.toString());
|
(inflowTargetVO != null ? inflowTargetVO.toString() : "N/A");
|
||||||
|
vo.setRspErrorMsg(ExceptionUtil.make(vo.getRspErrorCode(), vo.getEaiSvcCd() ) + ", " + inflowInfo);
|
||||||
|
|
||||||
// eaiMsg.setRspErrCd(vo.getRspErrorCode());
|
// eaiMsg.setRspErrCd(vo.getRspErrorCode());
|
||||||
// eaiMsg.setRspErrMsg(vo.getRspErrorMsg());
|
// eaiMsg.setRspErrMsg(vo.getRspErrorMsg());
|
||||||
@@ -1040,16 +1056,21 @@ public class RequestProcessor extends RequestProcessorSupport {
|
|||||||
try {
|
try {
|
||||||
Properties inFlowProp = PropManager.getInstance().getProperties("INFLOW");
|
Properties inFlowProp = PropManager.getInstance().getProperties("INFLOW");
|
||||||
String controlInflowHistory = inFlowProp.getProperty("inflow.control.history.yn", "N");
|
String controlInflowHistory = inFlowProp.getProperty("inflow.control.history.yn", "N");
|
||||||
if (StringUtils.equalsIgnoreCase(controlInflowHistory, "Y") && inflowTargetVO != null) {
|
if (StringUtils.equalsIgnoreCase(controlInflowHistory, "Y") && (inflowTargetVO != null || inflowGroupVO != null)) {
|
||||||
DAOFactory factory = DAOFactory.newInstance();
|
DAOFactory factory = DAOFactory.newInstance();
|
||||||
// InflowControlDAO restrictDao = (InflowControlDAO) factory.create(InflowControlDAO.class);
|
// InflowControlDAO restrictDao = (InflowControlDAO) factory.create(InflowControlDAO.class);
|
||||||
// InflowControlDAO를 서비스로 만들어서 factory.create로 하면 안됨.
|
// InflowControlDAO를 서비스로 만들어서 factory.create로 하면 안됨.
|
||||||
InflowControlDAO restrictDao = (InflowControlDAO) ApplicationContextProvider.getContext().getBean(InflowControlDAO.class);
|
InflowControlDAO restrictDao = (InflowControlDAO) ApplicationContextProvider.getContext().getBean(InflowControlDAO.class);
|
||||||
|
// 그룹 유량제어 정보가 있으면 그룹 정보로, 없으면 기존 inflowTargetVO 정보로 로그
|
||||||
|
long thresholdPerSecond = (inflowGroupVO != null) ? inflowGroupVO.getThresholdPerSecond() : inflowTargetVO.getThresholdPerSecond();
|
||||||
|
long threshold = (inflowGroupVO != null) ? inflowGroupVO.getThreshold() : inflowTargetVO.getThreshold();
|
||||||
|
String thresholdTimeUnit = (inflowGroupVO != null) ? inflowGroupVO.getThresholdTimeUnit() : inflowTargetVO.getThresholdTimeUnit();
|
||||||
|
String logGroupName = (inflowGroupVO != null) ? inflowGroupVO.getGroupId() : vo.getAdapterGroupName();
|
||||||
|
|
||||||
restrictDao.addInflowServicetLog(eaiMsg.getBwkCls(),
|
restrictDao.addInflowServicetLog(eaiMsg.getBwkCls(),
|
||||||
DatetimeUtil.getCurrentTime(eaiMsg.getMsgRcvTm()), eaiMsg.getSvcOgNo(),
|
DatetimeUtil.getCurrentTime(eaiMsg.getMsgRcvTm()), eaiMsg.getSvcOgNo(),
|
||||||
eaiServerManager.getLocalServerName(), eaiMsg.getEAISvcCd(), vo.getAdapterGroupName(),
|
eaiServerManager.getLocalServerName(), eaiMsg.getEAISvcCd(), logGroupName,
|
||||||
inflowTargetVO.getThresholdPerSecond(), inflowTargetVO.getThreshold(),
|
thresholdPerSecond, threshold, thresholdTimeUnit);
|
||||||
inflowTargetVO.getThresholdTimeUnit());
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (logger.isError()) {
|
if (logger.isError()) {
|
||||||
@@ -1060,7 +1081,10 @@ public class RequestProcessor extends RequestProcessorSupport {
|
|||||||
sb.append("EAISevrInstncName [" + eaiServerManager.getLocalServerName() + "]\n");
|
sb.append("EAISevrInstncName [" + eaiServerManager.getLocalServerName() + "]\n");
|
||||||
sb.append("EAISvcName [" + eaiMsg.getEAISvcCd() + "]\n");
|
sb.append("EAISvcName [" + eaiMsg.getEAISvcCd() + "]\n");
|
||||||
sb.append("ADPTRBZWKGROUPNAME[" + vo.getAdapterGroupName() + "]\n");
|
sb.append("ADPTRBZWKGROUPNAME[" + vo.getAdapterGroupName() + "]\n");
|
||||||
sb.append("InflowTargetVO [" + inflowTargetVO.toString() + "]\n");
|
sb.append("InflowInfo [" + inflowInfo + "]\n");
|
||||||
|
if (groupId != null) {
|
||||||
|
sb.append("InflowGroupId [" + groupId + "]\n");
|
||||||
|
}
|
||||||
|
|
||||||
logger.error(guidLogPrefix + " 유량제어 건수 Log 실패 - " + ex.toString() + "\n" + sb.toString());
|
logger.error(guidLogPrefix + " 유량제어 건수 Log 실패 - " + ex.toString() + "\n" + sb.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user