26号之前的asn ip导入版本,区分ipv4和ipv6,v4和v6互不影响
This commit is contained in:
@@ -27,6 +27,7 @@ import com.nis.domain.configuration.template.IpRateLimitTemplate;
|
||||
//import com.nis.util.AsnCacheUtils;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DictUtils;
|
||||
import com.nis.util.StringUtil;
|
||||
|
||||
public class CheckIpFormatThread implements Callable<String>{
|
||||
private Logger logger=Logger.getLogger(CheckIpFormatThread.class);
|
||||
@@ -259,11 +260,7 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
}
|
||||
if (regionDict.getFunctionId().equals(600)) {//asn
|
||||
String organization=baseIpCfg.getOrganization();
|
||||
if(StringUtils.isBlank(organization)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("organization","Organization"))
|
||||
+ ";");
|
||||
}else {
|
||||
if(!StringUtils.isBlank(organization)) {
|
||||
if(organization.length() > 1024){
|
||||
errInfo.append(prop.getProperty("asn_name")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":1024") + ";");
|
||||
}else {
|
||||
@@ -272,14 +269,9 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
}
|
||||
baseIpCfg.setOrganization(organization.trim().toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
String country=baseIpCfg.getCountry();
|
||||
if(StringUtils.isBlank(country)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("country"))
|
||||
+ ";");
|
||||
}else {
|
||||
if(!StringUtils.isBlank(country)) {
|
||||
if(country.length() > 512){
|
||||
errInfo.append(prop.getProperty("country_code")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("max_length")+":512") + ";");
|
||||
}else {
|
||||
@@ -287,11 +279,7 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
}
|
||||
}
|
||||
String detail=baseIpCfg.getDetail();
|
||||
if(StringUtils.isBlank(detail)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("detail"))
|
||||
+ ";");
|
||||
}else {
|
||||
if(!StringUtils.isBlank(detail)) {
|
||||
if(detail.length() > 1024||detail.length()<4){
|
||||
errInfo.append(prop.getProperty("details")+prop.getProperty("length_error")+" "+String.format(prop.getProperty("min_length")+":4,"+prop.getProperty("max_length")+":1024") + ";");
|
||||
}else {
|
||||
@@ -303,7 +291,7 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
if(StringUtils.isBlank(userRegion1)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("asn_no"))
|
||||
+ ";");
|
||||
+ ";org:"+baseIpCfg.getOrganization()+ ";asn:"+baseIpCfg.getOrganization()+ ";ip:"+baseIpCfg.getDestIpAddress());
|
||||
}else {
|
||||
try {
|
||||
Long asnNo=Long.parseLong(userRegion1);
|
||||
@@ -312,17 +300,21 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
String.format(prop.getProperty("must_between"),"1","4294967295" )
|
||||
+ ";");
|
||||
}else {
|
||||
if(StringUtil.isEmpty(baseIpCfg.getOrganization())){
|
||||
baseIpCfg.setOrganization(asnNo.toString());
|
||||
baseIpCfg.setCfgDesc(asnNo.toString());
|
||||
}
|
||||
// ConfigGroupInfo configGroupInfo=asnIpCfgService.getConfigGroupInfoByAsnNo(asnNo);
|
||||
if(asnNos!=null) {
|
||||
AsnGroupInfo configGroupInfo=asnGroupInfos==null?null:asnGroupInfos.get(asnNo);//从缓存中取
|
||||
//缓存中没有
|
||||
if(configGroupInfo==null) {
|
||||
synchronized (Constants.IMPORT_LOCK) {
|
||||
if(StringUtils.isNotBlank(baseIpCfg.getOrganization())&&StringUtils.isNotBlank(baseIpCfg.getCountry())) {
|
||||
if(StringUtils.isNotBlank(baseIpCfg.getOrganization())) {
|
||||
AsnGroupInfo groupInfo=new AsnGroupInfo();
|
||||
groupInfo.setOrganization(baseIpCfg.getOrganization().trim().toUpperCase());
|
||||
groupInfo.setCountry(baseIpCfg.getCountry().trim().toUpperCase());
|
||||
groupInfo.setDetail(baseIpCfg.getDetail().trim());
|
||||
groupInfo.setCountry(StringUtil.isEmpty(baseIpCfg.getCountry()) ? "":baseIpCfg.getCountry().trim().toUpperCase());
|
||||
groupInfo.setDetail(StringUtil.isEmpty(baseIpCfg.getDetail()) ? "":baseIpCfg.getDetail().trim());
|
||||
groupInfo.setIsValid(0);
|
||||
groupInfo.setAsnId(asnNo);
|
||||
if(asnNos.get(0).containsKey(asnNo)) {
|
||||
@@ -353,12 +345,8 @@ public class CheckIpFormatThread implements Callable<String>{
|
||||
if(!configGroupInfo.getOrganization().equalsIgnoreCase(baseIpCfg.getOrganization().trim())) {
|
||||
errInfo.append(prop.getProperty("organization","Organization")+" "+prop.getProperty("mismatch","Mismatch"));
|
||||
}
|
||||
if(!configGroupInfo.getCountry().equalsIgnoreCase(baseIpCfg.getCountry().trim())) {
|
||||
errInfo.append(prop.getProperty("country","Country")+" "+prop.getProperty("mismatch","Mismatch"));
|
||||
}
|
||||
if(!configGroupInfo.getDetail().equalsIgnoreCase(baseIpCfg.getDetail().trim())) {
|
||||
errInfo.append(prop.getProperty("detail","Detail")+" "+prop.getProperty("mismatch","Mismatch"));
|
||||
}
|
||||
configGroupInfo.setDetail(baseIpCfg.getDetail());
|
||||
configGroupInfo.setCountry(baseIpCfg.getCountry());
|
||||
if(StringUtils.isBlank(errInfo.toString())) {
|
||||
asnNos.get(1).put(asnNo,configGroupInfo);
|
||||
}
|
||||
|
||||
@@ -1650,9 +1650,17 @@ public class BaseController {
|
||||
}
|
||||
//全量下发,删除asnNo对应的已有的IP
|
||||
if(isImportAll.get(0).getItemCode().equals("1")) {
|
||||
Integer ipType=null;
|
||||
if((!ipPortCfgs.isEmpty())){
|
||||
BaseIpCfg baseIpCfg=ipPortCfgs.take();
|
||||
ipPortCfgs.put(baseIpCfg);
|
||||
if(!StringUtil.isEmpty(baseIpCfg)){
|
||||
ipType=baseIpCfg.getIpType();
|
||||
}
|
||||
}
|
||||
logger.warn("Delete and send ip reuse regions start");
|
||||
long _start=System.currentTimeMillis();
|
||||
deleteIps(asnNoMaps.get(1));
|
||||
deleteIps(asnNoMaps.get(1),ipType);
|
||||
long _end=System.currentTimeMillis();
|
||||
logger.warn("Delete and send ip reuse regions end,cost:"+(_end-_start));
|
||||
}
|
||||
@@ -2383,7 +2391,7 @@ public class BaseController {
|
||||
logger.warn("import finish,cost:"+(end-start));
|
||||
}
|
||||
|
||||
public void deleteIps(Map<Long,AsnGroupInfo> asnNoMap){
|
||||
public void deleteIps(Map<Long,AsnGroupInfo> asnNoMap,Integer ipType){
|
||||
List<AsnIpCfg> toDelAndSendAsnIpCfgs=Lists.newArrayList();
|
||||
List<Long> asnIds=Lists.newArrayList(asnNoMap.size());
|
||||
for(Entry<Long, AsnGroupInfo> e:asnNoMap.entrySet()) {
|
||||
@@ -2399,7 +2407,7 @@ public class BaseController {
|
||||
}
|
||||
}
|
||||
if(asnIds.size()>0) {
|
||||
asnIpCfgService.deleteByAsnNo(asnIds);
|
||||
asnIpCfgService.deleteByAsnNo(asnIds,ipType);
|
||||
}
|
||||
if(toDelAndSendAsnIpCfgs.size()>0) {
|
||||
int pointsDataLimit = Constants.MAAT_JSON_SEND_SIZE;//限制条数
|
||||
|
||||
@@ -33,4 +33,5 @@ public interface AsnIpCfgDao extends CrudDao<AsnIpCfg>{
|
||||
public AsnIpCfg getOne(AsnIpCfg cfg);
|
||||
public void updateAsn(@Param("asnId")String asnNo,@Param("organization")String organization,@Param("country")String country,@Param("detail")String detail);
|
||||
public List<Object[]> findAllAsnIpCfgList();
|
||||
public int deleteByAsnIdAndIpType(@Param("asnId")String ids,@Param("ipType")Integer ipType);
|
||||
}
|
||||
|
||||
@@ -637,4 +637,13 @@
|
||||
from asn_ip_cfg r
|
||||
where r.is_valid !=-1
|
||||
</select>
|
||||
<delete id="deleteByAsnIdAndIpType" >
|
||||
delete from asn_ip_cfg
|
||||
<where>
|
||||
and user_region1 in(${asnId})
|
||||
<if test="ipType != null" >
|
||||
and ip_type = #{ipType,jdbcType=INTEGER}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -377,7 +377,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
return asnIpCfgDao.getByIds(ids);
|
||||
}
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void deleteByAsnNo(List<Long> asnNoList) {
|
||||
public void deleteByAsnNo(List<Long> asnNoList,Integer ipType) {
|
||||
// for(Long asnNo:asnNoList) {
|
||||
// int result=0;
|
||||
// do {
|
||||
@@ -397,7 +397,8 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
}
|
||||
int result=0;
|
||||
do {
|
||||
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
||||
//result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
||||
result=asnIpCfgDao.deleteByAsnIdAndIpType(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1),ipType);
|
||||
}while(result>0);
|
||||
//剔除
|
||||
asnNoList.subList(0, pointsDataLimit).clear();
|
||||
@@ -410,7 +411,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
}
|
||||
int result=0;
|
||||
do {
|
||||
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
||||
result=asnIpCfgDao.deleteByAsnIdAndIpType(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1),ipType);
|
||||
}while(result>0);
|
||||
asnNoList.clear();
|
||||
}
|
||||
@@ -422,7 +423,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
}
|
||||
int result=0;
|
||||
do {
|
||||
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
|
||||
result=asnIpCfgDao.deleteByAsnIdAndIpType(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1),ipType);
|
||||
}while(result>0);
|
||||
asnNoList.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user