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