ASN IP 导入并下发功能
This commit is contained in:
@@ -172,123 +172,145 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
auditAllAsnRegionCfg(entity,auditAsnGroupList,null);
|
||||
}*/
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param asnNoMaps 所有asn的信息
|
||||
* @param configGroupInfos asn组织的数据库信息
|
||||
* @param asnOrgMap asn和组织的关系
|
||||
* @param isImportAll 是否导入全量
|
||||
*/
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void processAsnIp(FunctionServiceDict service,FunctionRegionDict regionDict,List<BaseIpCfg> ipCfgList,List<Map<Long, AsnGroupInfo>> asnNoMaps,String isSend,String isImportAll,Integer requestId, String attribute, String classify){
|
||||
logger.warn("Start to save asn ip size:"+ipCfgList.size());
|
||||
public void saveAsnIp(List<AsnIpCfg> asnIpCfgs){
|
||||
logger.warn("Start to only save asn ip size:"+asnIpCfgs.size());
|
||||
long start=System.currentTimeMillis();
|
||||
//List<AsnIpCfg> asnIpCfgs=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
|
||||
Date date=new Date();
|
||||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||
SqlSession batchSqlSession = null;
|
||||
int index=0;
|
||||
Map<Long,AsnGroupInfo> auditInfo=new HashMap<>();
|
||||
//存储未下发的asno及asnIP
|
||||
Map<Integer,List<AsnIpCfg>> noAuditGroupIds=new HashMap<>();
|
||||
//存储已下发的asnno
|
||||
Map<Integer,List<AsnIpCfg>> auditGroupIds=new HashMap<>();
|
||||
//本次未下发的组信息
|
||||
List<AsnGroupInfo> noAuditGroupList=new ArrayList<AsnGroupInfo>();
|
||||
Long asno=0l;
|
||||
try{
|
||||
List<Integer> regionIds=ConfigServiceUtil.getId(3, ipCfgList.size());
|
||||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
for (BaseIpCfg cfg : ipCfgList) {
|
||||
AsnIpCfg asnIpCfg=new AsnIpCfg();
|
||||
BeanUtils.copyProperties(cfg, asnIpCfg,new String[] {"cfgId"});
|
||||
asnIpCfg.setTableName(AsnIpCfg.getTablename());
|
||||
asnIpCfg.setAction(service==null?0:service.getAction());
|
||||
asnIpCfg.setCfgRegionCode(regionDict.getConfigRegionCode());
|
||||
asnIpCfg.setCfgType(regionDict.getConfigRegionValue());
|
||||
asnIpCfg.setCreateTime(date);
|
||||
asnIpCfg.setCreatorId(UserUtils.getUser().getId());
|
||||
asnIpCfg.setDoLog(2);
|
||||
asnIpCfg.setFunctionId(regionDict.getFunctionId());
|
||||
if(isSend.equals("1")) {
|
||||
asnIpCfg.setIsAudit(Constants.AUDIT_YES);
|
||||
asnIpCfg.setIsValid(Constants.VALID_YES);
|
||||
asnIpCfg.setAuditorId(UserUtils.getUser().getId());
|
||||
asnIpCfg.setAuditTime(date);
|
||||
|
||||
}else {
|
||||
asnIpCfg.setIsAudit(Constants.AUDIT_NOT_YET);
|
||||
asnIpCfg.setIsValid(Constants.VALID_NO);
|
||||
if(!StringUtil.isEmpty(asnIpCfgs)){
|
||||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
for (AsnIpCfg cfg : asnIpCfgs) {
|
||||
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(cfg);
|
||||
}
|
||||
asnIpCfg.setIsAreaEffective(0);
|
||||
asnIpCfg.setLable("0");
|
||||
asnIpCfg.setRequestId(StringUtil.isEmpty(requestId) ? 0 : requestId);
|
||||
asnIpCfg.setAttribute(attribute);
|
||||
asnIpCfg.setClassify(classify);
|
||||
asnIpCfg.setServiceId(service==null?0:service.getServiceId());
|
||||
asnIpCfg.setRegionId(regionIds.get(index));
|
||||
asno=Long.parseLong(asnIpCfg.getUserRegion1());
|
||||
//设置group id,compileId
|
||||
asnIpCfg.setAsnIpGroup(asnNoMaps.get(2).get(Long.parseLong(asnIpCfg.getUserRegion1())).getGroupId());
|
||||
asnIpCfg.setCompileId(asnNoMaps.get(2).get(Long.parseLong(asnIpCfg.getUserRegion1())).getCompileId());
|
||||
/*if(isSend.equals("1")) {
|
||||
//判断组是否已下发
|
||||
if(asnNoMaps.get(3).keySet().contains(asno)){
|
||||
|
||||
}else{
|
||||
asnNoMaps.get(3).put(asno, asnNoMaps.get(2).get(asno));
|
||||
}
|
||||
}*/
|
||||
|
||||
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(asnIpCfg);
|
||||
index++;
|
||||
}
|
||||
batchSqlSession.commit();
|
||||
batchSqlSession.commit();
|
||||
}
|
||||
|
||||
}finally {
|
||||
if(batchSqlSession != null){
|
||||
batchSqlSession.close();
|
||||
}
|
||||
}
|
||||
//6、配置取消所有编译[编译取消,编译下的所有group和region都会取消(已和服务端确认)]
|
||||
/*if(!StringUtil.isEmpty(deleteAsnCompile)){
|
||||
long startAudit=System.currentTimeMillis();
|
||||
ToMaatBean maatBean = new ToMaatBean();
|
||||
MaatCfg maatCfg = new MaatCfg();
|
||||
List<MaatCfg> configCompileList = new ArrayList();
|
||||
List<GroupCfg> groupRelationList = new ArrayList();
|
||||
List<IpCfg> ipRegionList = new ArrayList();
|
||||
List<StringCfg> strRegionList = new ArrayList();
|
||||
List<NumBoundaryCfg> numRegionList = new ArrayList();
|
||||
List<DigestCfg> digestRegionList = new ArrayList();
|
||||
List<IpCfg> areaIpRegionList = new ArrayList();
|
||||
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(600);
|
||||
Integer serviceId=0;
|
||||
serviceId=serviceList.get(0).getServiceId();
|
||||
for(Entry<Long, AsnGroupInfo> e:deleteAsnCompile.entrySet()) {
|
||||
maatCfg.setCompileId(e.getValue().getCompileId());
|
||||
maatCfg.setServiceId(serviceId);
|
||||
maatCfg.setIsValid(0);//无效
|
||||
configCompileList.add(maatCfg);
|
||||
}
|
||||
maatBean.setConfigCompileList(configCompileList);
|
||||
maatBean.setAuditTime(createTime);
|
||||
long end=System.currentTimeMillis();
|
||||
logger.warn("end only save asn ip finish,cost:"+(end-start));
|
||||
}
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public void auditAsnIp(Map<Long, List<AsnIpCfg>> auditAsnIp,List<Map<Long, AsnGroupInfo>> asnNoMaps,String auditType,int auditSize){
|
||||
logger.warn("Start to audit and save asn ip size:"+auditSize);
|
||||
long start=System.currentTimeMillis();
|
||||
Date date=new Date();
|
||||
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
|
||||
SqlSession batchSqlSession = null;
|
||||
Long asno=0l;
|
||||
List<Long> groupIds=Lists.newArrayList(auditAsnIp.size());
|
||||
List<AsnIpCfg> auditList=new ArrayList<>();
|
||||
ToMaatBean maatBean = new ToMaatBean();
|
||||
List<MaatCfg> configCompileList = new ArrayList();
|
||||
try{
|
||||
if(!auditAsnIp.isEmpty()){
|
||||
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
|
||||
//maat结构配置
|
||||
if(auditType.equals("maat")){
|
||||
//maat参数
|
||||
List<StringCfg> strRegionList = new ArrayList();
|
||||
List<NumBoundaryCfg> numRegionList = new ArrayList();
|
||||
List<DigestCfg> digestRegionList = new ArrayList();
|
||||
List<IpCfg> areaIpRegionList = new ArrayList();
|
||||
|
||||
for (Entry<Long, List<AsnIpCfg>> e:auditAsnIp.entrySet()) {
|
||||
List<GroupCfg> groupRelationList = Lists.newArrayList();
|
||||
List<IpCfg> ipRegionList = new ArrayList();
|
||||
|
||||
//分组信息
|
||||
GroupCfg groupCfg=new GroupCfg();
|
||||
groupCfg.setAuditTime(e.getValue().get(0).getAuditTime());
|
||||
groupCfg.setCompileId(e.getValue().get(0).getCompileId());
|
||||
groupCfg.setGroupId(e.getValue().get(0).getAsnIpGroup());
|
||||
groupCfg.setIsCommonGroup(1);
|
||||
groupCfg.setIsValid(e.getValue().get(0).getIsValid());
|
||||
|
||||
groupRelationList.add(groupCfg);
|
||||
|
||||
//域信息
|
||||
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(e.getValue(),Constants.VALID_YES,Integer.parseInt(e.getKey()+"")));
|
||||
|
||||
MaatCfg maatCfg = new MaatCfg();
|
||||
maatCfg.initDefaultValue();
|
||||
BeanUtils.copyProperties(e.getValue().get(0), maatCfg);
|
||||
maatCfg.setAction(e.getValue().get(0).getAction());
|
||||
maatCfg.setAuditTime(e.getValue().get(0).getAuditTime());
|
||||
maatCfg.setStrRegionList(strRegionList);
|
||||
maatCfg.setNumRegionList(numRegionList);
|
||||
maatCfg.setDigestRegionList(digestRegionList);
|
||||
maatCfg.setGroupRelationList(groupRelationList);
|
||||
maatCfg.setAreaIpRegionList(areaIpRegionList);
|
||||
maatCfg.setIpRegionList(ipRegionList);
|
||||
maatCfg.setIsValid(e.getValue().get(0).getIsValid());
|
||||
maatCfg.setCompileId(e.getValue().get(0).getCompileId());
|
||||
// 设置ASN自定义域
|
||||
String userRegion = Constants.ASN_REGION_KEY+"=" +Constants.ASN_KEY+ e.getValue().get(0).getUserRegion1();
|
||||
maatCfg.setUserRegion(userRegion);
|
||||
maatCfg.setGroupNum(groupRelationList.size());
|
||||
configCompileList.add(maatCfg);
|
||||
|
||||
groupIds.add(e.getKey());
|
||||
for (AsnIpCfg cfg : e.getValue()) {
|
||||
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(cfg);
|
||||
}
|
||||
//组第一次下发,需要更新已下发过的组中
|
||||
asnNoMaps.get(3).put(Long.valueOf(e.getValue().get(0).getUserRegion1()), asnNoMaps.get(2).get(Long.valueOf(e.getValue().get(0).getUserRegion1())));
|
||||
}
|
||||
|
||||
}else{
|
||||
//复用接口
|
||||
for (Entry<Long, List<AsnIpCfg>> e:auditAsnIp.entrySet()) {
|
||||
groupIds.add(e.getKey());
|
||||
for (AsnIpCfg cfg : e.getValue()) {
|
||||
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(cfg);
|
||||
}
|
||||
auditList.addAll(e.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
batchSqlSession.commit();
|
||||
}
|
||||
//第一次走maat配置的下发,需要将asn组修改为有效
|
||||
if(auditType.equals("maat") && !StringUtil.isEmpty(groupIds)){
|
||||
asnGroupInfoDao.updateIsUsedAndIsValid(groupIds, null, 1);
|
||||
}
|
||||
|
||||
}finally {
|
||||
if(batchSqlSession != null){
|
||||
batchSqlSession.close();
|
||||
}
|
||||
}
|
||||
logger.warn("Start to audit asn ip ");
|
||||
long startAudit=System.currentTimeMillis();
|
||||
if(auditType.equals("maat")){
|
||||
maatBean.setConfigCompileList(configCompileList);
|
||||
maatBean.setAuditTime(new Date());
|
||||
maatBean.setCreatorName(UserUtils.getUser().getName());
|
||||
maatBean.setVersion(Constants.MAAT_VERSION);
|
||||
maatBean.setOpAction(Constants.UPDATE_ACTION);
|
||||
//调用服务接口取消配置
|
||||
maatBean.setOpAction(Constants.INSERT_ACTION);
|
||||
//调用服务接口下发配置数据
|
||||
String json=gsonToJson(maatBean);
|
||||
logger.info("ASN IP 业务的编译配置全部失效参数:"+json);
|
||||
long auditEnd=System.currentTimeMillis();
|
||||
logger.warn("Cancle all ASN compile finish,cost:"+(auditEnd-startAudit));
|
||||
ToMaatResult result = ConfigServiceUtil.put(json,1);
|
||||
logger.info("ASN IP所有编译取消返回结果:"+result.getMsg());
|
||||
long resultEnd=System.currentTimeMillis();
|
||||
logger.warn("Cancle all ASN compile finish,cost:"+(resultEnd-auditEnd));
|
||||
}*/
|
||||
//logger.info("asn ip maat结构配置下发配置参数:"+json);
|
||||
logger.info("asn ip maat结构配置下发配置参数:");
|
||||
//调用服务接口下发配置
|
||||
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
|
||||
//logger.info("asn ip maat结构配置下发响应信息:"+result.getMsg());
|
||||
logger.info("asn ip maat结构配置下发响应信息:");
|
||||
}else{
|
||||
if(!StringUtil.isEmpty(auditList)){
|
||||
asnIPRegionSendToMaat(auditList, 1, Constants.OPACTION_POST);
|
||||
}
|
||||
}
|
||||
long endAutit=System.currentTimeMillis();
|
||||
logger.warn("End to audit asn ip finish,cost:"+(endAutit-startAudit));
|
||||
|
||||
long end=System.currentTimeMillis();
|
||||
logger.warn("Save asn ip finish,cost:"+(end-start));
|
||||
logger.warn("end audit and save asn ip finish,cost:"+(end-start));
|
||||
}
|
||||
/**
|
||||
*
|
||||
@@ -358,7 +380,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
}
|
||||
}
|
||||
|
||||
//4、遍历保存所有的asn_group_info
|
||||
//5、遍历保存所有的asn_group_info
|
||||
if(!asnNoMaps.isEmpty()){
|
||||
Map<Long, AsnGroupInfo> newAsnGroup =asnNoMaps.get(0); //【0】 新的asn group info
|
||||
Map<Long, AsnGroupInfo> oldAsnGroup =asnNoMaps.get(1); //【1】 旧的asn group info
|
||||
|
||||
Reference in New Issue
Block a user