This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/web/service/basics/AsnIpCfgService.java

930 lines
39 KiB
Java
Raw Normal View History

package com.nis.web.service.basics;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.beust.jcommander.internal.Lists;
import com.google.common.collect.Maps;
2019-01-23 19:32:47 +06:00
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.Page;
import com.nis.domain.basics.AsnGroupInfo;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
import com.nis.domain.maat.GroupReuseAddBean;
import com.nis.domain.maat.GroupReuseCfg;
import com.nis.domain.maat.MaatCfg;
import com.nis.domain.maat.MaatCfg.DigestCfg;
import com.nis.domain.maat.MaatCfg.GroupCfg;
import com.nis.domain.maat.MaatCfg.IpCfg;
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
import com.nis.domain.maat.MaatCfg.StringCfg;
import com.nis.domain.maat.ToMaatBean;
import com.nis.domain.maat.ToMaatResult;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.exceptions.MaatConvertException;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
import com.nis.util.StringUtil;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.basics.AsnGroupInfoDao;
import com.nis.web.dao.basics.AsnIpCfgDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.dao.specific.ConfigGroupInfoDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.CrudService;
import com.nis.web.service.SpringContextHolder;
@Service
public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
@Autowired
private AsnIpCfgDao asnIpCfgDao;
// @Autowired
// private SpecificServiceCfgDao specificServiceCfgDao;
@Autowired
private ConfigGroupInfoDao configGroupInfoDao;
@Autowired
private AsnGroupInfoDao asnGroupInfoDao;
/**
* @param page
* @param entity
* @return
*/
public Page<AsnIpCfg> findPage(Page<AsnIpCfg> page, AsnIpCfg entity) {
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
entity.setPage(page);
List<AsnIpCfg> list=asnIpCfgDao.findPage(entity);
page.setList(list);
return page;
}
2018-12-26 14:47:23 +08:00
public List<AsnIpCfg> findByPage(String ids) {
List<AsnIpCfg> list=asnIpCfgDao.findByPage(ids);
return list;
}
public boolean hasValidAsnIp(Long asnId) {
return asnIpCfgDao.hasValidAsnIp(asnId)>0;
}
2018-12-26 14:47:23 +08:00
public AsnIpCfg get(Long id ) {
return asnIpCfgDao.get(id);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void save(List<AsnIpCfg> entitys) {
logger.warn("Start to save IP,size:"+entitys.size());
long start=System.currentTimeMillis();
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try{
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
for(AsnIpCfg asnIpCfg:entitys) {
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(asnIpCfg);
}
batchSqlSession.commit();
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
long end=System.currentTimeMillis();
logger.warn("Save IP finish,cost:"+(end-start));
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void update(AsnIpCfg entity){
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
List<AsnIpCfg> auditAsnIpList=new ArrayList<>();
List<AsnGroupInfo> auditAsnGroupList=new ArrayList<>();
Date editTime=new Date();
entity.setEditTime(editTime);
entity.setEditorId(entity.getCurrentUser().getId());
String userRegion1=entity.getUserRegion1();
AsnGroupInfo groupInfo=new AsnGroupInfo();
groupInfo.setAsnId(Long.parseLong(userRegion1));
groupInfo=asnGroupInfoDao.getInfoByAsnNo(groupInfo);
String org=groupInfo.getOrganization().trim();
String country=groupInfo.getCountry().trim();
String detail=groupInfo.getDetail().trim();
entity.setOrganization(org);
entity.setCountry(country);
entity.setDetail(detail);
2019-01-06 11:49:48 +08:00
entity.setCompileId(groupInfo.getCompileId());
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
/**
* isvalid=0 and asnNo=false 直接修改
* isvalid=0 and asnNo=true 需要下发
* isvalid=1 需要下发asnNo下所有的域配置
*/
/*if(groupInfo.getIsUsed().equals(1) && entity.getIsValid().equals(Constants.VALID_NO)){
entity.setAuditTime(editTime);
entity.setAuditorId(entity.getCurrentUser().getId());
entity.setIsValid(Constants.VALID_YES);
entity.setIsAudit(Constants.AUDIT_YES);
auditAsnIpList.add(entity);
}
if(groupInfo.getIsUsed().equals(1) && entity.getIsValid().equals(Constants.VALID_YES)){
entity.setAuditTime(editTime);
entity.setAuditorId(entity.getCurrentUser().getId());
entity.setIsValid(Constants.VALID_YES);
entity.setIsAudit(Constants.AUDIT_YES);
auditAsnGroupList.add(groupInfo);
}*/
if(entity.getIsValid() ==1){
entity.setAuditTime(editTime);
entity.setAuditorId(entity.getCurrentUser().getId());
entity.setEditTime(editTime);
entity.setEditorId(entity.getCurrentUser().getId());
entity.setIsValid(Constants.VALID_YES);
entity.setIsAudit(Constants.AUDIT_YES);
}else{
entity.setEditTime(editTime);
entity.setEditorId(entity.getCurrentUser().getId());
entity.setIsValid(Constants.VALID_NO);
entity.setIsAudit(Constants.VALID_NO);
}
asnIpCfgDao.update(entity);
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
//ASN下发状态时可以更改更改之后直接下发
if(entity.getIsValid() ==1){
auditAsnIpList.add(entity);
asnIPRegionSendToMaat(auditAsnIpList,Constants.VALID_YES,Constants.OPACTION_PUT);
}
//common group 新增下发 ASN IP配置
/*if(!StringUtil.isEmpty(auditAsnIpList)){
asnIPRegionSendToMaat(auditAsnIpList,Constants.VALID_YES,Constants.OPACTION_POST);
}*/
//common group 修改已下发过的配置,全量下发 ASN NO下的所有有效配置
/*if(entity.getIsAudit().equals(Constants.VALID_YES)){
auditAllAsnRegionCfg(entity,auditAsnGroupList,null);
}*/
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIp(List<AsnIpCfg> asnIpCfgs,String asnIds){
2019-01-26 10:47:50 +06:00
logger.warn("Start to only save asn ip size:"+asnIpCfgs.size());
long start=System.currentTimeMillis();
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try{
if(!StringUtil.isEmpty(asnIpCfgs)){
asnIpCfgDao.deleteByAsnId(asnIds);
2019-01-26 10:47:50 +06:00
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
for (AsnIpCfg cfg : asnIpCfgs) {
((AsnIpCfgDao) batchSqlSession.getMapper(AsnIpCfgDao.class)).insert(cfg);
}
batchSqlSession.commit();
}
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
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);
2019-01-23 19:32:47 +06:00
long start=System.currentTimeMillis();
Date date=new Date();
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
Long asno=0l;
2019-01-26 10:47:50 +06:00
List<Long> groupIds=Lists.newArrayList(auditAsnIp.size());
List<AsnIpCfg> auditList=new ArrayList<>();
ToMaatBean maatBean = new ToMaatBean();
List<MaatCfg> configCompileList = new ArrayList();
2019-01-23 19:32:47 +06:00
try{
2019-01-26 10:47:50 +06:00
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);
}
2019-01-23 19:32:47 +06:00
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
2019-01-26 10:47:50 +06:00
logger.warn("Start to audit asn ip ");
long startAudit=System.currentTimeMillis();
if(auditType.equals("maat")){
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(new Date());
2019-01-23 19:32:47 +06:00
maatBean.setCreatorName(UserUtils.getUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
2019-01-26 10:47:50 +06:00
maatBean.setOpAction(Constants.INSERT_ACTION);
//调用服务接口下发配置数据
2019-01-23 19:32:47 +06:00
String json=gsonToJson(maatBean);
2019-01-26 10:47:50 +06:00
//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));
2019-01-23 19:32:47 +06:00
long end=System.currentTimeMillis();
2019-01-26 10:47:50 +06:00
logger.warn("end audit and save asn ip finish,cost:"+(end-start));
2019-01-23 19:32:47 +06:00
}
/**
*
* @param asnNoMaps 所有asn的信息
* @param configGroupInfos asn组织的数据库信息
* @param asnOrgMap asn和组织的关系
* @param isImportAll 是否导入全量
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void processGroup(FunctionServiceDict service,List<Map<Long, AsnGroupInfo>> asnNoMaps,List<Map<String, ConfigGroupInfo>> asnOrgList,String isSend,String isImportAll){
logger.warn("Start to save group");
long start=System.currentTimeMillis();
2019-01-23 19:32:47 +06:00
Map<Long, AsnGroupInfo> deleteAsnCompile=null;
Date createTime=new Date();
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
2019-01-23 19:32:47 +06:00
int index=0;
Integer serviceId=service.getServiceId();
try{
2019-01-23 19:32:47 +06:00
//1、删除所有asn ip
//asnIpCfgDao.deleteAll();
2019-01-23 19:32:47 +06:00
//2、删除所有的asn_group_info
//asnGroupInfoDao.deleteAll();
2019-01-23 19:32:47 +06:00
//3、删除所有的组织信息
//configGroupInfoDao.deleteAllAsnGroup();
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
2019-01-23 19:32:47 +06:00
//4、遍历保存所有的config_group_info
if(!StringUtil.isEmpty(asnOrgList)){
Map<String,ConfigGroupInfo> newOrgMap=asnOrgList.get(0);//【0】 新的config group info
Map<String,ConfigGroupInfo> oldOrgMap=asnOrgList.get(1);//【1】 旧的config group info
//入库旧的asn组织信息
/*if(!StringUtil.isEmpty(oldOrgMap)){
2019-01-23 19:32:47 +06:00
index=0;
for(Entry<String, ConfigGroupInfo> e:oldOrgMap.entrySet()) {
ConfigGroupInfo configGroupInfo=e.getValue();
configGroupInfo.setIsIssued(0);
((ConfigGroupInfoDao) batchSqlSession.getMapper(ConfigGroupInfoDao.class)).insertWithId(configGroupInfo);
if(index != 0 && index%Constants.IMPORT_LIMIT==0) {
batchSqlSession.commit();
}
index++;
}
batchSqlSession.commit();
}*/
2019-01-23 19:32:47 +06:00
//入库新的asn组织信息
if(!StringUtil.isEmpty(newOrgMap)){
index=0;
List<Integer> groupIds=ConfigServiceUtil.getId(2, newOrgMap.size());
for(Entry<String, ConfigGroupInfo> e:newOrgMap.entrySet()) {
ConfigGroupInfo configGroupInfo=e.getValue();
configGroupInfo.setGroupId(groupIds.get(index));
configGroupInfo.setIsIssued(0);
configGroupInfo.setIsUsed(0);
configGroupInfo.setIsAuditAll(0);
configGroupInfo.setGroupType(4);
configGroupInfo.setInsertTime(createTime);
asnOrgList.get(1).put(configGroupInfo.getGroupName(), configGroupInfo);
((ConfigGroupInfoDao) batchSqlSession.getMapper(ConfigGroupInfoDao.class)).insertWithoutId(configGroupInfo);
if(index != 0 && index%Constants.IMPORT_LIMIT==0) {
batchSqlSession.commit();
}
index++;
}
batchSqlSession.commit();
}
}
2019-01-23 19:32:47 +06:00
2019-01-26 10:47:50 +06:00
//5、遍历保存所有的asn_group_info
2019-01-23 19:32:47 +06:00
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
Map<Long, AsnGroupInfo> allAsnGroup =asnNoMaps.get(2); //【2】 所有的asn group info
Map<Long, AsnGroupInfo> auditedAsnNoMap=asnNoMaps.get(3); //【3】已下发的所有asn信息【失效所有的asn 编译】
deleteAsnCompile=auditedAsnNoMap;
//保存新增的asn 信息
if(!newAsnGroup.isEmpty()){
index=0;
List<Integer> compileIds=ConfigServiceUtil.getId(1, newAsnGroup.size());
List<Integer> groupIds=ConfigServiceUtil.getId(2, newAsnGroup.size());
List<Integer> regionIds=ConfigServiceUtil.getId(3, newAsnGroup.size());
int onlyGroupId=0;//用于ip地址中下发配置组号
2019-01-23 19:32:47 +06:00
for(Entry<Long, AsnGroupInfo> e:newAsnGroup.entrySet()) {
AsnGroupInfo asnGroupInfo=e.getValue();
asnGroupInfo.setAsnId(e.getKey());
asnGroupInfo.setIsValid(0);
asnGroupInfo.setIsUsed(0);
asnGroupInfo.setCreatorId(UserUtils.getUser().getId());
asnGroupInfo.setCreateTime(createTime);
asnGroupInfo.setGroupId(groupIds.get(index));
asnGroupInfo.setCompileId(compileIds.get(index));
asnGroupInfo.setRegionId(regionIds.get(index));
asnGroupInfo.setOrgGroupId(asnOrgList.get(1).get(asnGroupInfo.getOrganization()).getGroupId());
//新增组号用于ip地址新增业务
List<Integer> onlyGroupIds= ConfigServiceUtil.getId(2,1);
if(onlyGroupIds.size()>0) {
onlyGroupId=onlyGroupIds.get(0).intValue();
}else {
throw new MaatConvertException("Get asn group id failed");
}
asnGroupInfo.setOnlyGroupId(onlyGroupId);
2019-01-23 19:32:47 +06:00
asnNoMaps.get(0).put(e.getKey(), asnGroupInfo);//设置完各种id后更新map数据
asnNoMaps.get(2).put(e.getKey(), asnGroupInfo);//设置完各种id后更新map数据
((AsnGroupInfoDao) batchSqlSession.getMapper(AsnGroupInfoDao.class)).insertWithId(asnGroupInfo);
if(index != 0 && index%Constants.IMPORT_LIMIT==0) {
batchSqlSession.commit();
}
index++;
}
batchSqlSession.commit();
}
//保存旧的asn信息
/*if(!oldAsnGroup.isEmpty()){
2019-01-23 19:32:47 +06:00
index=0;
for(Entry<Long, AsnGroupInfo> e:oldAsnGroup.entrySet()) {
AsnGroupInfo asnGroupInfo=e.getValue();
asnGroupInfo.setIsValid(0);
asnGroupInfo.setOrgGroupId(asnOrgList.get(1).get(asnGroupInfo.getOrganization()).getGroupId());
((AsnGroupInfoDao) batchSqlSession.getMapper(AsnGroupInfoDao.class)).insertWithoutId(asnGroupInfo);
if(index != 0 && index%Constants.IMPORT_LIMIT==0) {
batchSqlSession.commit();
}
index++;
}
batchSqlSession.commit();
}*/
2019-01-23 19:32:47 +06:00
}
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
2019-01-23 19:32:47 +06:00
//6、配置取消所有编译[编译取消编译下的所有group和region都会取消(已和服务端确认)]
/*if(!StringUtil.isEmpty(deleteAsnCompile)){
2019-01-23 19:32:47 +06:00
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);
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);
maatBean.setCreatorName(UserUtils.getUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.UPDATE_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));
}*/
2019-01-23 19:32:47 +06:00
long end=System.currentTimeMillis();
logger.warn("Save group finish,cost:"+(end-start));
}
public void batchSaveConfigGroupInfo(Set<String> groupSet) {
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
SqlSession batchSqlSession = null;
try{
batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
if(groupSet.size()>0) {
int index=0;
List<Integer> groupIds=ConfigServiceUtil.getId(2, groupSet.size());
for(String org:groupSet) {
ConfigGroupInfo configGroupInfo=new ConfigGroupInfo();
configGroupInfo.setGroupName(org);
configGroupInfo.setIsIssued(0);
2019-01-23 19:32:47 +06:00
configGroupInfo.setIsUsed(0);
configGroupInfo.setIsAuditAll(0);
configGroupInfo.setGroupType(4);
configGroupInfo.setInsertTime(new Date());
configGroupInfo.setGroupId(groupIds.get(index));
((ConfigGroupInfoDao) batchSqlSession.getMapper(ConfigGroupInfoDao.class)).insertConfigGroupInfo(configGroupInfo);
if(index%Constants.IMPORT_LIMIT==0) {
batchSqlSession.commit();
}
index++;
}
batchSqlSession.commit();
}
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
}
// public void deleteIps(Map<Long,AsnGroupInfo> asnNoMap){
// List<AsnIpCfg> toDelAndSendAsnIpCfgs=Lists.newArrayList();
// List<Long> asnIds=Lists.newArrayList(asnNoMap.size());
// for(Entry<Long, AsnGroupInfo> e:asnNoMap.entrySet()) {
// AsnGroupInfo asnGroupInfo=e.getValue();
// if(asnGroupInfo==null) {
// asnGroupInfo=this.getAsnGroupInfoByAsnNo(e.getKey());
// }
// if(asnGroupInfo.getIsValid()==1) {//已下发
// List<AsnIpCfg> _toDelAsnIpCfgs=this.getByAsnNo(asnGroupInfo.getAsnId());
// toDelAndSendAsnIpCfgs.addAll(_toDelAsnIpCfgs);
// }else {
// asnIds.add(e.getKey());
// }
// }
// if(asnIds.size()>0) {
// this.deleteByAsnNo(asnIds);
// }
// if(toDelAndSendAsnIpCfgs.size()>0) {
// int pointsDataLimit = Constants.MAAT_JSON_SEND_SIZE;//限制条数
// Integer size = toDelAndSendAsnIpCfgs.size();
// //判断是否有必要分批
// if(pointsDataLimit<size){
// int part = size/pointsDataLimit;//分批数
// for (int i = 0; i < part; i++) {
// //pointsDataLimit条
// List<AsnIpCfg> listPage = toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit);
// delAndSend(listPage);
// //剔除
// toDelAndSendAsnIpCfgs.subList(0, pointsDataLimit).clear();
// }
// //最后剩下的
// if(!toDelAndSendAsnIpCfgs.isEmpty()){
// delAndSend(toDelAndSendAsnIpCfgs);
//
// }
// }else {
// delAndSend(toDelAndSendAsnIpCfgs);
// }
// }
// }
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delAndSend(List<AsnIpCfg> entities) {
StringBuilder sb=new StringBuilder();
Map<Long,Integer> asnDelCounts=Maps.newHashMap();
for(AsnIpCfg ip:entities) {
sb.append(ip.getCfgId());
sb.append(",");
if(asnDelCounts.containsKey(Long.parseLong(ip.getUserRegion1()))) {
int count=asnDelCounts.get(Long.parseLong(ip.getUserRegion1()))+1;
asnDelCounts.put(Long.parseLong(ip.getUserRegion1()), count);
}else {
asnDelCounts.put(Long.parseLong(ip.getUserRegion1()), 1);
}
}
//跟新asn组的审核通过IP数量
for(Entry<Long,Integer> asnDelCount: asnDelCounts.entrySet()) {
AsnGroupInfo info=new AsnGroupInfo();
info.setAsnId(asnDelCount.getKey());
info.setIssuedIPs(0l-asnDelCount.getValue());
asnGroupInfoDao.modifyIssuedIp(info);
}
sb.deleteCharAt(sb.toString().lastIndexOf(","));
asnIpCfgDao.delete(sb.toString());
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
asnIPRegionSendToMaat(entities,Constants.VALID_NO,Constants.OPACTION_PUT);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveAsnIpCfg(CfgIndexInfo entity) {
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
List<AsnIpCfg> auditAsnIpList=new ArrayList<>();
Date createTime=new Date();
//asn号
String userRegion1=entity.getUserRegion1();
AsnGroupInfo asnGroupInfo=new AsnGroupInfo();
asnGroupInfo.setAsnId(Long.parseLong(userRegion1));
asnGroupInfo=asnGroupInfoDao.getInfoByAsnNo(asnGroupInfo);
//组织去除首尾空格
entity.setOrganization(asnGroupInfo.getOrganization().trim());
entity.setCountry(asnGroupInfo.getCountry().trim());
entity.setDetail(asnGroupInfo.getDetail().trim());
ConfigGroupInfo configGroupInfo=configGroupInfoDao.getAsnGroupByName(entity.getOrganization());
Integer orgGroup=0;
Integer compileId=0;
Integer asnIdGroup=0;
if(configGroupInfo==null) {
configGroupInfo=new ConfigGroupInfo();
configGroupInfo.setGroupName(entity.getOrganization());
configGroupInfo.setGroupType(4);
configGroupInfo.setInsertTime(new Date());
configGroupInfo.setIsIssued(0);
List<Integer> groupIdList=ConfigServiceUtil.getId(2, 2);
orgGroup=groupIdList.get(0);
configGroupInfo.setGroupId(orgGroup);
configGroupInfoDao.insertConfigGroupInfo(configGroupInfo);
}
asnIdGroup=asnGroupInfo.getGroupId();
entity.setAsnIpGroup(asnIdGroup);
entity.setCompileId(asnGroupInfo.getCompileId());
List<Integer> idList=ConfigServiceUtil.getId(3, entity.getAsnIpCfgs().size());
int index=0;
if(entity.getAsnIpCfgs()!=null) {
for(AsnIpCfg cfg:entity.getAsnIpCfgs()) {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setRequestId(0);
cfg.setClassify("0");
cfg.setAttribute("0");
cfg.setLable("0");
cfg.setCreateTime(createTime);
cfg.setCreatorId(entity.getCurrentUser().getId());
cfg.setAsnIpGroup(entity.getAsnIpGroup().intValue());
cfg.setRegionId(idList.get(index));
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
//TODO 注意被策略引用并下发过的ASN NO配置新增后直接下发【此功能暂时不做自动asnip拥有审核功能】
/*if(asnGroupInfo.getIsUsed().equals(1)){
cfg.setIsValid(Constants.VALID_YES);
cfg.setIsAudit(Constants.AUDIT_YES);
cfg.setAuditorId(UserUtils.getUser().getId());
cfg.setAuditTime(createTime);
auditAsnIpList.add(cfg);
}else{*/
cfg.setIsValid(Constants.VALID_NO);
cfg.setIsAudit(Constants.AUDIT_NOT_YET);
/*}*/
index++;
}
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
}
this.save(entity.getAsnIpCfgs());
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
//TODO 注意被策略引用并下发过的ASN NO配置新增后直接下发【此功能暂时不做自动asnip拥有审核功能】
/*if(!StringUtil.isEmpty(auditAsnIpList)){
asnIPRegionSendToMaat(auditAsnIpList,Constants.VALID_YES,Constants.OPACTION_POST);
}*/
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delete(String ids) {
2018-12-13 18:07:15 +08:00
/*for(String id:ids.split(",")) {
Long.parseLong(id);
2018-12-13 18:07:15 +08:00
}*/
List<AsnIpCfg> issuedList=new ArrayList<>();
List<AsnIpCfg> asnIpCfgList= asnIpCfgDao.getByIds(ids);
for(AsnIpCfg asnIpCfg:asnIpCfgList) {
if(asnIpCfg.getIsValid()==Constants.VALID_YES) {//代表下发过了
asnIpCfg.setIsValid(Constants.VALID_DEL);
issuedList.add(asnIpCfg);
// groupId=asnIpCfg.getAsnIpGroup();
//List result=asnIpCfgDao.findOtherIps(groupId, asnIpCfg.getCfgId().intValue());
//if(result==null||result.size()==0) {
// throw new RuntimeException("Cant not delete ip from asn group, there is only one ip left in the group!");
//}
}
}
asnIpCfgDao.delete(ids);
//已经下发过的,调用分组复用配置删除接口
// splitAndSend(issuedList,Constants.VALID_NO);
2018-12-13 18:07:15 +08:00
if(issuedList.size() > 0){
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
asnIPRegionSendToMaat(issuedList,Constants.VALID_NO,Constants.OPACTION_PUT);
2018-12-13 18:07:15 +08:00
}
}
/**
* 选中组中是否含有只剩一个未删除IP的组
* @param serviceGroupIds
* @return
*/
public boolean hasLastIp(String serviceGroupIds,String ids) {
// TODO Auto-generated method stub
for(String groupId:serviceGroupIds.split(",")) {
Long.parseLong(groupId);
}
List<Integer> countList=asnIpCfgDao.countValidIPs(serviceGroupIds,ids);
if(countList.size()==0) {
return true;
}
for(Integer count:countList) {
if(count==0) {
return true;
}
}
return false;
}
public AsnGroupInfo getAsnGroupInfoByAsnNo(Long asnNo) {
AsnGroupInfo configGroupInfo=new AsnGroupInfo();
configGroupInfo.setAsnId(asnNo);
configGroupInfo=asnGroupInfoDao.getInfoByAsnNo(configGroupInfo);
return configGroupInfo;
}
public List<AsnIpCfg> getByAsnNo(Long asnNo) {
if(asnNo==null) {
throw new RuntimeException("groupId or asnNo is null!");
}
return asnIpCfgDao.getByAsnNo(asnNo.longValue());
}
public List<AsnIpCfg> getByIds(String ids) {
if(ids==null) {
throw new RuntimeException("ids is null!");
}
return asnIpCfgDao.getByIds(ids);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void deleteByAsnNo(List<Long> asnNoList) {
// for(Long asnNo:asnNoList) {
// int result=0;
// do {
// result=asnIpCfgDao.deleteByAsnId(String.valueOf(asnNo));
// }while(result>0);
// }
int pointsDataLimit = 1000;//限制条数
Integer size = asnNoList.size();
if(pointsDataLimit<size){
int part = size/pointsDataLimit;//分批数
for (int i = 0; i < part; i++) {
List<Long> listPage = asnNoList.subList(0, pointsDataLimit);
StringBuilder asnNoStr=new StringBuilder();
for(Long asnNo:asnNoList) {
asnNoStr.append(asnNo);
asnNoStr.append(",");
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
//剔除
asnNoList.subList(0, pointsDataLimit).clear();
}
if(!asnNoList.isEmpty()){
StringBuilder asnNoStr=new StringBuilder();
for(Long asnNo:asnNoList) {
asnNoStr.append(asnNo);
asnNoStr.append(",");
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
asnNoList.clear();
}
}else {
StringBuilder asnNoStr=new StringBuilder();
for(Long asnNo:asnNoList) {
asnNoStr.append(asnNo);
asnNoStr.append(",");
}
int result=0;
do {
result=asnIpCfgDao.deleteByAsnId(asnNoStr.toString().substring(0,asnNoStr.toString().length()-1));
}while(result>0);
asnNoList.clear();
}
}
/*public void ajaxDeleteAsnIp(String ids) {
2018-12-13 20:31:59 +08:00
asnIpCfgDao.ajaxDeleteAsnIp(ids);
}*/
/**
*
* auditIpBatch(非IP类配置用审核区域IP)
* (这里描述这个方法适用条件 可选)
* @param data
*void
* @exception
* @since 1.0.0
*/
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
public void auditIpBatch(List<AsnIpCfg> asnIpCfgs,Long asn,Integer isValid) {
List<AsnGroupInfo> auditAsnGroupList=new ArrayList<>();
SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class);
final SqlSession batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
Integer serviceId=0;
try{
if(!StringUtil.isEmpty(asnIpCfgs)){
serviceId=asnIpCfgs.get(0).getServiceId();
int issuedNum=asnIpCfgs.size();
for(int index = 0; index < asnIpCfgs.size();index++){
AsnIpCfg t = asnIpCfgs.get(index);
BaseIpCfg ipCfg=new BaseIpCfg();
BeanUtils.copyProperties(t, ipCfg);
ipCfg.setTableName(AsnIpCfg.getTablename());
((IpCfgDao) batchSqlSession.getMapper(IpCfgDao.class)).audit(ipCfg);
Merge branch 'develop' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop Conflicts: src/main/java/com/nis/domain/configuration/CfgIndexInfo.java src/main/resources/nis.properties src/main/webapp/WEB-INF/tags/sys/delRow.tag asn相关功能更改: IP ADDR:增加asn域 1、新增IP ADDR可选asn,如果asn未下发过(is_used=0),下发时asn的group需要标记为commonGroup(groupId为asn组织的groupId,regionId为asn的regionId)。 2、如果所选的asn组(asn组织的groupId)已经下发过(is_used=1),则下发maat时,asn域不需要下发。 3、策略取消时,如果有需要保留的公共组(commongRroupIds),需要将公共组的组号下发。 ASN GROUP: 1、新增asn,如果此asn的组织groupId已下发过(is_used=1),且此组织的groupId已被策略标记过全选(is_audit_all=1),则需要调用公共组域新增的接口,将新增的asn关键字下发。 2、修改asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域修改的接口,修改已经下发的asn关键字域。 3、删除asn,如果此asn的组织groupId已下发过(is_used=1),则需要调用公共组域删除的接口,删除已经下发的asn关键字域。 ASN IP CFG: 1、新增asn ip,所选asn no的组首次下发(is_valid=0),需要将asn no的groupId标记为公共组;如果asn no非首次下发(is_valid=1),直接调用公共组新增域的接口。 2、修改 生效状态asn ip修改,调用公共组修改域接口直接修改 3、失效 直接调用公共组删除域接口,失效asn ip域
2019-01-16 14:33:29 +06:00
}
batchSqlSession.commit();
AsnGroupInfo asnGroupInfo=new AsnGroupInfo();
asnGroupInfo.setAsnId(asn);
asnGroupInfo=asnGroupInfoDao.getInfoByAsnNo(asnGroupInfo);
Integer groupId=asnGroupInfo.getGroupId();
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();
if(isValid==Constants.VALID_YES) {//审核通过
if(asnGroupInfo.getIsValid()==0) {//ans组未下发过下发编译配置
asnGroupInfo.setIsValid(1);
asnGroupInfo.setEditorId(UserUtils.getUser().getId());
asnGroupInfo.setEditTime(new Date());
asnGroupInfo.setIssuedIPs(issuedNum+0L);
asnGroupInfoDao.updateValid(asnGroupInfo);
maatCfg.initDefaultValue();
ToMaatBean maatBean = new ToMaatBean();
//group
GroupCfg groupCfg=new GroupCfg();
groupCfg.setCompileId(asnGroupInfo.getCompileId());
groupCfg.setGroupId(groupId);
groupCfg.setIsValid(Constants.VALID_YES);
//asnGroupId标记为公共组
groupCfg.setIsCommonGroup(1);
groupCfg.setAuditTime(asnIpCfgs.get(0).getAuditTime());
groupRelationList.add(groupCfg);
BeanUtils.copyProperties(asnIpCfgs.get(0), maatCfg);
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(asnIpCfgs,Constants.VALID_YES,groupId));
maatCfg.setCompileId(asnGroupInfo.getCompileId());
maatCfg.setAction(asnIpCfgs.get(0).getAction());
maatCfg.setAuditTime(asnIpCfgs.get(0).getAuditTime());
maatCfg.setIpRegionList(ipRegionList);
maatCfg.setStrRegionList(strRegionList);
maatCfg.setNumRegionList(numRegionList);
maatCfg.setDigestRegionList(digestRegionList);
maatCfg.setGroupRelationList(groupRelationList);
maatCfg.setGroupNum(groupRelationList.size());
maatCfg.setAreaIpRegionList(areaIpRegionList);
maatCfg.setIsValid(isValid);
// 设置ASN自定义域
2019-01-19 11:07:20 +06:00
String userRegion = Constants.ASN_REGION_KEY+"=" +Constants.ASN_KEY+ asnIpCfgs.get(0).getUserRegion1();
maatCfg.setUserRegion(userRegion);
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(asnIpCfgs.get(0).getAuditTime());
maatBean.setCreatorName(asnIpCfgs.get(0).getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.INSERT_ACTION);
// 调用服务接口下发配置数据
String json = gsonToJson(maatBean);
logger.info("ASN IP配置下发配置参数" + json);
// 调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.postMaatCfg(json);
logger.info("ASN IP配置下发响应信息" + result.getMsg());
}else if(asnGroupInfo.getIsValid()==1){//已经下发过,走分组复用
asnGroupInfo.setIssuedIPs(issuedNum+0l);
asnGroupInfoDao.update(asnGroupInfo);
asnIPRegionSendToMaat(asnIpCfgs,isValid,Constants.OPACTION_POST);
}else {
throw new RuntimeException("asnGroupInfo isValid value is "+asnGroupInfo.getIsValid());
}
}else if(isValid==Constants.VALID_NO) {//取消审核通过
asnGroupInfo.setIssuedIPs(0L-issuedNum);
asnGroupInfoDao.update(asnGroupInfo);
//如果一个asn组下没有IP了修改有效状态,并且删除
if(hasValidAsnIp(asn)) {
//已经下发过的,调用分组复用配置删除接口
GroupReuseAddBean maatBean = new GroupReuseAddBean();
List<GroupReuseCfg> groupReuseList=new ArrayList<>();
GroupReuseCfg groupReuseCfg=new GroupReuseCfg();
ipRegionList.addAll(groupReuseCfgAddRemoveConvert(asnIpCfgs,Constants.VALID_NO,groupId));
groupReuseCfg.setIpRegionList(ipRegionList);
groupReuseCfg.setStrRegionList(strRegionList);
groupReuseCfg.setNumRegionList(numRegionList);
groupReuseList.add(groupReuseCfg);
maatBean.setGroupReuseCfgList(groupReuseList);
maatBean.setAuditTime(asnIpCfgs.get(0).getAuditTime());
maatBean.setCreatorName(asnIpCfgs.get(0).getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.UPDATE_ACTION);
//调用服务接口下发配置数据
String json=gsonToJson(maatBean);
logger.info("ASN IP域删除配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.auditCommonGroupRegionSources(json,3);
logger.info("ASN IP域删除配置响应信息"+result.getMsg());
}else{
asnGroupInfo.setIsValid(0);
asnGroupInfo.setEditorId(UserUtils.getUser().getId());
asnGroupInfo.setEditTime(new Date());
asnGroupInfoDao.updateValid(asnGroupInfo);
//asn group下没有asn ip之后需要失效整个compileId并且不保留公共组信息
ToMaatBean maatBean = new ToMaatBean();
maatCfg.setCompileId(asnGroupInfo.getCompileId());
maatCfg.setServiceId(serviceId);
maatCfg.setIsValid(0);//无效
//configCompileList.add(addKeepGroupList(maatCfg,entity));
configCompileList.add(maatCfg);
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(new Date());
maatBean.setCreatorName(UserUtils.getUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.UPDATE_ACTION);
//调用服务接口取消配置
String json=gsonToJson(maatBean);
logger.info("asn ip配置下发配置参数"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json,1);
logger.info("asn ip配置取消配置响应信息"+result.getMsg());
}
}
}
}finally {
if(batchSqlSession != null){
batchSqlSession.close();
}
}
}
public AsnIpCfg getOne(AsnIpCfg cfg) {
// TODO Auto-generated method stub
return asnIpCfgDao.getOne(cfg);
}
}