针对IP region range情况做出特殊优化,一次获取region ID
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.nis.util;
|
package com.nis.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -588,12 +589,13 @@ public class ConfigConvertUtil {
|
|||||||
*/
|
*/
|
||||||
public static <T> Map<String, List> objGroupCfgConvert(Map<Integer,FunctionServiceDict> dictMap,List dstList, List<T> srcList, Integer cfgType, BaseCfg baseCfg,
|
public static <T> Map<String, List> objGroupCfgConvert(Map<Integer,FunctionServiceDict> dictMap,List dstList, List<T> srcList, Integer cfgType, BaseCfg baseCfg,
|
||||||
List groupRelationList, Map<String,Object> maatTableMap, Set<Integer> groupIdSet) {
|
List groupRelationList, Map<String,Object> maatTableMap, Set<Integer> groupIdSet) {
|
||||||
|
long start=System.currentTimeMillis(),end=0l;
|
||||||
Map<String, List> map = new HashMap();
|
Map<String, List> map = new HashMap();
|
||||||
if (cfgType == 1) {
|
if (cfgType == 1) {
|
||||||
List numRegionList = new ArrayList();
|
List numRegionList = new ArrayList();
|
||||||
|
int pos=0;
|
||||||
Set<Integer> numGroupVals = new HashSet<>();
|
Set<Integer> numGroupVals = new HashSet<>();
|
||||||
List<Integer> regionIdList = new ArrayList<>();//ConfigServiceUtil.getId(3, srcList.size());
|
List<Integer> regionIdList = calRangeIps(srcList);//ConfigServiceUtil.getId(3, srcList.size());
|
||||||
for (int i = 0; i < srcList.size(); i++) {
|
for (int i = 0; i < srcList.size(); i++) {
|
||||||
T srcCfg = srcList.get(i);
|
T srcCfg = srcList.get(i);
|
||||||
BaseIpCfg baseIpCfg = new BaseIpCfg();
|
BaseIpCfg baseIpCfg = new BaseIpCfg();
|
||||||
@@ -622,17 +624,17 @@ public class ConfigConvertUtil {
|
|||||||
}
|
}
|
||||||
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
|
List<IpCfg> cfgs = ipConvert(cfg, baseIpCfg);
|
||||||
if (cfgs.size() > 1) {
|
if (cfgs.size() > 1) {
|
||||||
List<Integer> ids = ConfigServiceUtil.getId(3, cfgs.size() - 1);
|
List<Integer> ids =regionIdList.subList(pos,pos+cfgs.size());
|
||||||
regionIdList.addAll(ids);
|
|
||||||
//支持range????
|
//支持range????
|
||||||
for (int j = 1; j < cfgs.size(); j++) {
|
for (int j = 1; j < cfgs.size(); j++) {
|
||||||
cfgs.get(j).setRegionId(ids.get(j-1));
|
cfgs.get(j).setRegionId(ids.get(j-1));
|
||||||
}
|
}
|
||||||
|
pos+=cfgs.size();
|
||||||
}
|
}
|
||||||
dstList.addAll(cfgs);
|
dstList.addAll(cfgs);
|
||||||
|
|
||||||
// 如果protocolId非空非零,需要构造数值型域配置,多条相同协议的IP只需要一条数值域配置(目前没有不同协议IP&情况)
|
// 如果protocolId非空非零,需要构造数值型域配置,多条相同协议的IP只需要一条数值域配置(目前没有不同协议IP&情况)
|
||||||
//分组复用每个IP组还需要不同的数值域组么?????
|
//分组复用每个IP组还需要不同的数值域组么????? answer:一个就行了
|
||||||
if (baseCfg!=null&&baseCfg.getServiceId()!=null&&baseCfg.getServiceId()>0&&dictMap.containsKey(baseCfg.getServiceId())) {
|
if (baseCfg!=null&&baseCfg.getServiceId()!=null&&baseCfg.getServiceId()>0&&dictMap.containsKey(baseCfg.getServiceId())) {
|
||||||
FunctionServiceDict dict=dictMap.get(baseCfg.getServiceId());
|
FunctionServiceDict dict=dictMap.get(baseCfg.getServiceId());
|
||||||
Integer protocolId=dict.getProtocolId();
|
Integer protocolId=dict.getProtocolId();
|
||||||
@@ -741,43 +743,8 @@ public class ConfigConvertUtil {
|
|||||||
}
|
}
|
||||||
map.put("groupList", groupRelationList);
|
map.put("groupList", groupRelationList);
|
||||||
map.put("dstList", dstList);
|
map.put("dstList", dstList);
|
||||||
return map;
|
end=System.currentTimeMillis();
|
||||||
}
|
logger.info("objGroupCfgConvert cost:"+(end-start));
|
||||||
public static <T> Map<String, List> emptyGroupConvert(Integer cfgType, BaseCfg baseCfg,
|
|
||||||
List groupRelationList, Map<String,Object> maatTableMap, Set<Integer> groupIdSet) {
|
|
||||||
Map<String, List> map = new HashMap();
|
|
||||||
if (cfgType == 1) {
|
|
||||||
if(maatTableMap.containsKey("ipMaatTable")){
|
|
||||||
Map<String,String> groupMap=(Map<String,String>)maatTableMap.get("ipMaatTable");
|
|
||||||
for(Map.Entry<String,String> e:groupMap.entrySet()){
|
|
||||||
if(!groupIdSet.contains(Integer.parseInt(e.getKey()))){
|
|
||||||
GroupCfg group = new GroupCfg();
|
|
||||||
group.setGroupId(Integer.parseInt(e.getKey()));
|
|
||||||
group.setCompileId(baseCfg.getCompileId());
|
|
||||||
group.setAuditTime(baseCfg.getAuditTime());
|
|
||||||
group.setIsValid(baseCfg.getIsValid());
|
|
||||||
groupRelationList.add(group);
|
|
||||||
groupIdSet.add(Integer.parseInt(e.getKey()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (cfgType == 2 || cfgType == 3) {
|
|
||||||
if(maatTableMap.containsKey("stringMaatTable")){
|
|
||||||
Map<String,String> groupMap=(Map<String,String>)maatTableMap.get("stringMaatTable");
|
|
||||||
for(Map.Entry<String,String> e:groupMap.entrySet()){
|
|
||||||
if(!groupIdSet.contains(Integer.parseInt(e.getKey()))){
|
|
||||||
GroupCfg group = new GroupCfg();
|
|
||||||
group.setGroupId(Integer.parseInt(e.getKey()));
|
|
||||||
group.setCompileId(baseCfg.getCompileId());
|
|
||||||
group.setAuditTime(baseCfg.getAuditTime());
|
|
||||||
group.setIsValid(baseCfg.getIsValid());
|
|
||||||
groupRelationList.add(group);
|
|
||||||
groupIdSet.add(Integer.parseInt(e.getKey()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
map.put("groupList", groupRelationList);
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -960,4 +927,59 @@ public class ConfigConvertUtil {
|
|||||||
}
|
}
|
||||||
return dictMap;
|
return dictMap;
|
||||||
}
|
}
|
||||||
|
public static <T>List<Integer> calRangeIps(List<T> srcList ){
|
||||||
|
List<Integer> regionIdsList=new ArrayList<>();
|
||||||
|
int total=0;
|
||||||
|
//通过反射获取IP的src ip地址,目的IP地址
|
||||||
|
Class clazz=null;
|
||||||
|
Field srcIpAddressField=null,destIpAddressField=null,ipTypeFild=null;
|
||||||
|
for(T instance:srcList){
|
||||||
|
if(clazz==null&&srcIpAddressField==null&&destIpAddressField==null){
|
||||||
|
try {
|
||||||
|
clazz=instance.getClass();
|
||||||
|
srcIpAddressField=clazz.getDeclaredField("srcIpAddress");
|
||||||
|
srcIpAddressField.setAccessible(true);
|
||||||
|
destIpAddressField=clazz.getDeclaredField("destIpAddress");
|
||||||
|
destIpAddressField.setAccessible(true);
|
||||||
|
ipTypeFild=clazz.getDeclaredField("ipType");
|
||||||
|
ipTypeFild.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
return regionIdsList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
String srcIpAddressValue=(String)srcIpAddressField.get(instance);
|
||||||
|
String destIpAddressValue=(String)destIpAddressField.get(instance);
|
||||||
|
Integer ipType=(Integer)ipTypeFild.get(instance);
|
||||||
|
if(ipType.equals(4)){
|
||||||
|
long left=1,right=1;
|
||||||
|
if(srcIpAddressValue.indexOf("-")>-1){
|
||||||
|
String[] srcIpAddressValueArray=srcIpAddressValue.split("-");
|
||||||
|
int startPos=0,endPos=0;
|
||||||
|
startPos=Integer.parseInt(srcIpAddressValueArray[0].split("\\.")[3]);
|
||||||
|
endPos=Integer.parseInt(srcIpAddressValueArray[1].split("\\.")[3]);
|
||||||
|
left=endPos-startPos+1;
|
||||||
|
}
|
||||||
|
if(destIpAddressValue.indexOf("-")>-1){
|
||||||
|
String[] destIpAddressValueArray=srcIpAddressValue.split("-");
|
||||||
|
int startPos=0,endPos=0;
|
||||||
|
startPos=Integer.parseInt(destIpAddressValueArray[0].split("\\.")[3]);
|
||||||
|
endPos=Integer.parseInt(destIpAddressValueArray[1].split("\\.")[3]);
|
||||||
|
right=endPos-startPos+1;
|
||||||
|
}
|
||||||
|
total+=left*right;
|
||||||
|
}else{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return regionIdsList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(total>0){
|
||||||
|
regionIdsList=ConfigServiceUtil.getId(3,total);
|
||||||
|
}
|
||||||
|
|
||||||
|
return regionIdsList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user