ASN IP导入(全量+数据入库)开发
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.nis.util.excel.thread;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -24,6 +25,7 @@ import com.nis.domain.configuration.BaseIpCfg;
|
||||
import com.nis.domain.configuration.DnsResStrategy;
|
||||
import com.nis.domain.configuration.IpPortCfg;
|
||||
import com.nis.domain.configuration.template.IpRateLimitTemplate;
|
||||
import com.nis.domain.specific.ConfigGroupInfo;
|
||||
//import com.nis.util.AsnCacheUtils;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DictUtils;
|
||||
@@ -36,8 +38,15 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
// private DnsResStrategyService dnsResStrategyService;
|
||||
private FunctionServiceDict serviceDict;
|
||||
private FunctionRegionDict regionDict;
|
||||
private List<Map<Long,AsnGroupInfo>> asnNoMaps;
|
||||
private Map<Long,AsnGroupInfo> asnGroupInfos;
|
||||
//【0】 新的asn group info
|
||||
//【1】 旧的asn group info
|
||||
//【2】 所有的asn group info
|
||||
//【3】 所有已审核通过的asn group info
|
||||
private List<Map<Long,AsnGroupInfo>> asnNoMaps;
|
||||
//组织之间的关系
|
||||
//【0】 新的组织信息
|
||||
//【1】 旧的组织信息
|
||||
private List<Map<String,ConfigGroupInfo>> asnOrgList;
|
||||
// private DnsResStrategyDao dnsResStrategyDao;
|
||||
public CheckIpFormatThread(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,Properties prop,BlockingQueue<? extends Object> srcQueue,BlockingQueue<BaseIpCfg> destQueue) {
|
||||
this.serviceDict=serviceDict;
|
||||
@@ -51,6 +60,7 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
public String call() throws Exception {
|
||||
List<Object> dataList=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
|
||||
StringBuffer msg=new StringBuffer();
|
||||
boolean error = false;
|
||||
while(!srcQueue.isEmpty()) {
|
||||
int size=srcQueue.drainTo(dataList,Constants.MAAT_JSON_SEND_SIZE);
|
||||
if(regionDict.getRegionType().intValue()==1) {
|
||||
@@ -63,10 +73,15 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
// TODO: handle exception
|
||||
//msg.append(e.getMessage());
|
||||
//break;
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
dataList.clear();
|
||||
}
|
||||
if(error) {
|
||||
msg.append("validate_error");
|
||||
}
|
||||
|
||||
return msg.toString();
|
||||
}
|
||||
public List<BaseIpCfg> checkIpCfg(StringBuffer msg,List<Map<Long,AsnGroupInfo>> asnNos, List<Object> list)
|
||||
@@ -252,6 +267,7 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
}
|
||||
}
|
||||
if (regionDict.getFunctionId().equals(600)) {//asn
|
||||
//组织的非空和长度校验
|
||||
String organization=baseIpCfg.getOrganization();
|
||||
if(StringUtils.isBlank(organization)) {
|
||||
errInfo.append(
|
||||
@@ -268,19 +284,16 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
}
|
||||
|
||||
}
|
||||
//国家的非空和长度校验
|
||||
String country=baseIpCfg.getCountry();
|
||||
if(StringUtils.isBlank(country)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("country"))
|
||||
+ ";");
|
||||
|
||||
if(!StringUtils.isBlank(country) && country.length() > 512){
|
||||
errInfo.append(prop.getProperty("country_code")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":512") + ";");
|
||||
}else {
|
||||
if(country.length() > 512){
|
||||
errInfo.append(prop.getProperty("country_code")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":512") + ";");
|
||||
}else {
|
||||
baseIpCfg.setCountry(country.trim().toUpperCase());
|
||||
}
|
||||
baseIpCfg.setCountry(country.trim().toUpperCase());
|
||||
}
|
||||
String detail=baseIpCfg.getDetail();
|
||||
//详情可以为空
|
||||
/*String detail=baseIpCfg.getDetail();
|
||||
if(StringUtils.isBlank(detail)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("detail"))
|
||||
@@ -291,8 +304,8 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
}else {
|
||||
baseIpCfg.setDetail(detail.trim());
|
||||
}
|
||||
}
|
||||
//asn id
|
||||
}*/
|
||||
//asn id 校验
|
||||
String userRegion1 = baseIpCfg.getUserRegion1();
|
||||
if(StringUtils.isBlank(userRegion1)) {
|
||||
errInfo.append(
|
||||
@@ -306,55 +319,74 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
String.format(prop.getProperty("must_between"),"1","4294967295" )
|
||||
+ ";");
|
||||
}else {
|
||||
// ConfigGroupInfo configGroupInfo=asnIpCfgService.getConfigGroupInfoByAsnNo(asnNo);
|
||||
if(asnNos!=null) {
|
||||
AsnGroupInfo configGroupInfo=asnGroupInfos==null?null:asnGroupInfos.get(asnNo);//从缓存中取
|
||||
//缓存中没有
|
||||
if(configGroupInfo==null) {
|
||||
//数据库中是否已经存在
|
||||
AsnGroupInfo asnGroupInfo=asnNos.get(1)==null?null:asnNos.get(1).get(asnNo);
|
||||
if(asnGroupInfo==null) {
|
||||
synchronized (Constants.IMPORT_LOCK) {
|
||||
if(StringUtils.isNotBlank(baseIpCfg.getOrganization())&&StringUtils.isNotBlank(baseIpCfg.getCountry())) {
|
||||
AsnGroupInfo groupInfo=new AsnGroupInfo();
|
||||
groupInfo.setOrganization(baseIpCfg.getOrganization().trim().toUpperCase());
|
||||
groupInfo.setCountry(baseIpCfg.getCountry().trim().toUpperCase());
|
||||
groupInfo.setCountry(baseIpCfg.getCountry());
|
||||
groupInfo.setDetail(baseIpCfg.getDetail().trim());
|
||||
groupInfo.setIsUsed(0);
|
||||
groupInfo.setIsValid(0);
|
||||
groupInfo.setAsnId(asnNo);
|
||||
if(asnNos.get(0).containsKey(asnNo)) {
|
||||
if(!asnNos.get(0).get(asnNo).getOrganization().equals(baseIpCfg.getOrganization().trim().toUpperCase())) {
|
||||
if(asnNos.get(2).containsKey(asnNo)) {
|
||||
if(!asnNos.get(2).get(asnNo).getOrganization().equals(baseIpCfg.getOrganization().trim().toUpperCase())) {
|
||||
//一个asn号不能被两个组织拥有
|
||||
logger.error("ASN "+asnNo+" Found two Organization "+asnNos.get(0).get(asnNo).getOrganization()+" "+baseIpCfg.getOrganization().trim().toUpperCase());
|
||||
errInfo.append(asnNos.get(0).get(asnNo).getOrganization()+" "+baseIpCfg.getOrganization().trim().toUpperCase()+" "+prop.getProperty("asn_no")+" "+asnNo+" "+prop.getProperty("repeat")
|
||||
logger.error("ASN "+asnNo+" Found two Organization "+asnNos.get(2).get(asnNo).getOrganization()+" "+baseIpCfg.getOrganization().trim().toUpperCase());
|
||||
errInfo.append(asnNos.get(2).get(asnNo).getOrganization()+" "+baseIpCfg.getOrganization().trim().toUpperCase()+" "+prop.getProperty("asn_no")+" "+asnNo+" "+prop.getProperty("repeat")
|
||||
+";");
|
||||
}else {
|
||||
asnNos.get(0).put(asnNo,groupInfo);
|
||||
asnNos.get(2).put(asnNo,groupInfo);
|
||||
if(!asnOrgList.get(0).containsKey(groupInfo.getOrganization()) && !asnOrgList.get(1).containsKey(groupInfo.getOrganization())){
|
||||
ConfigGroupInfo configGroupInfo=new ConfigGroupInfo();
|
||||
configGroupInfo.setGroupName(groupInfo.getOrganization());
|
||||
asnOrgList.get(0).put(groupInfo.getOrganization(), configGroupInfo);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
asnNos.get(0).put(asnNo,groupInfo);
|
||||
asnNos.get(2).put(asnNo,groupInfo);
|
||||
if(!asnOrgList.get(0).containsKey(groupInfo.getOrganization()) && !asnOrgList.get(1).containsKey(groupInfo.getOrganization())){
|
||||
ConfigGroupInfo configGroupInfo=new ConfigGroupInfo();
|
||||
configGroupInfo.setGroupName(groupInfo.getOrganization());
|
||||
asnOrgList.get(0).put(groupInfo.getOrganization(), configGroupInfo);
|
||||
}
|
||||
}
|
||||
|
||||
}else {
|
||||
if(StringUtils.isNotBlank(baseIpCfg.getOrganization())) {
|
||||
logger.error("ASN "+asnNo+" Organization is Null");
|
||||
}
|
||||
if(StringUtils.isNotBlank(baseIpCfg.getCountry())) {
|
||||
/*if(StringUtils.isNotBlank(baseIpCfg.getCountry())) {
|
||||
logger.error("ASN "+asnNo+" Country is Null");
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}else {
|
||||
if(!configGroupInfo.getOrganization().equalsIgnoreCase(baseIpCfg.getOrganization().trim())) {
|
||||
if(!asnGroupInfo.getOrganization().equalsIgnoreCase(baseIpCfg.getOrganization().trim())) {
|
||||
errInfo.append(prop.getProperty("organization","Organization")+" "+prop.getProperty("mismatch","Mismatch"));
|
||||
}
|
||||
if(!configGroupInfo.getCountry().equalsIgnoreCase(baseIpCfg.getCountry().trim())) {
|
||||
/*if(!asnGroupInfo.getCountry().equalsIgnoreCase(baseIpCfg.getCountry().trim())) {
|
||||
errInfo.append(prop.getProperty("country","Country")+" "+prop.getProperty("mismatch","Mismatch"));
|
||||
}
|
||||
if(!configGroupInfo.getDetail().equalsIgnoreCase(baseIpCfg.getDetail().trim())) {
|
||||
if(!asnGroupInfo.getDetail().equalsIgnoreCase(baseIpCfg.getDetail().trim())) {
|
||||
errInfo.append(prop.getProperty("detail","Detail")+" "+prop.getProperty("mismatch","Mismatch"));
|
||||
}
|
||||
}*/
|
||||
if(StringUtils.isBlank(errInfo.toString())) {
|
||||
asnNos.get(1).put(asnNo,configGroupInfo);
|
||||
//已下发过的asn no
|
||||
if(asnGroupInfo.getIsValid() ==1){
|
||||
asnNos.get(3).put(asnNo,asnGroupInfo);
|
||||
}
|
||||
asnNos.get(1).put(asnNo,asnGroupInfo);
|
||||
asnGroupInfo.setIsValid(0);
|
||||
asnGroupInfo.setIssuedIPs(0l);
|
||||
asnNos.get(2).put(asnNo,asnGroupInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1384,11 +1416,11 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
public void setAsnNoMaps(List<Map<Long, AsnGroupInfo>> asnNoMaps) {
|
||||
this.asnNoMaps = asnNoMaps;
|
||||
}
|
||||
public Map<Long, AsnGroupInfo> getAsnGroupInfos() {
|
||||
return asnGroupInfos;
|
||||
public List<Map<String, ConfigGroupInfo>> getAsnOrgList() {
|
||||
return asnOrgList;
|
||||
}
|
||||
public void setAsnGroupInfos(Map<Long, AsnGroupInfo> asnGroupInfos) {
|
||||
this.asnGroupInfos = asnGroupInfos;
|
||||
public void setAsnOrgList(List<Map<String, ConfigGroupInfo>> asnOrgList) {
|
||||
this.asnOrgList = asnOrgList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user