appip全量下发逻辑:

1、全量下发
(1)、批量下发已下发过的app的app IP配置(走maat配置下发接口)

appip批量审核逻辑:
1、审核通过
(1)、批量下发已下发过的app的app IP配置(走ip复用接口)
		 批量修改app ip配置状态为已下发
(2)、批量下发未下发过的app的app ip配置(走maat下发接口)
		批量修改group_info为已下发
		批量修改app ip为已下发
2、取消审核通过
(1)、批量失效已下发过的app的app IP配置(走ip复用接口)
		 批量修改app ip配置状态为失效
(2)、未下发过的app不存在已下发的配置,无需处理取消。
This commit is contained in:
DuanDongmei
2018-12-07 10:07:53 +08:00
parent 1c3dc455e3
commit 95dbe2a123
9 changed files with 389 additions and 141 deletions

View File

@@ -169,6 +169,7 @@ import com.nis.web.service.configuration.UserManageService;
import com.nis.web.service.configuration.WebsiteCfgService;
import com.nis.web.service.configuration.XmppCfgService;
import com.nis.web.service.configuration.statistics.ConfigureStatisticsService;
import com.nis.web.service.specific.ConfigGroupInfoService;
import com.nis.web.service.specific.SpecificServiceCfgService;
import com.nis.web.service.specific.SpecificServiceHostCfgService;
import com.nis.web.service.systemService.ServiceConfigInfoService;
@@ -298,6 +299,8 @@ public class BaseController {
protected IpReuseIpCfgService ipReuseIpCfgService;
@Autowired
protected IpAddrPoolCfgService ipAddrPoolCfgService;// 地址池管理service
@Autowired
protected ConfigGroupInfoService configGroupInfoService;// 分组复用
/**
* 管理基础路径
*/
@@ -2000,7 +2003,7 @@ public class BaseController {
BeanUtils.copyProperties(entity, auditBatchCfg);
BeanUtils.copyProperties(entity, searchTrustedCaCrlCfg);
}
if(entity != null && (entity instanceof CfgIndexInfo)) {
if(entity != null && (entity instanceof DnsResStrategy)) {
BeanUtils.copyProperties(entity, auditBatchCfg);
BeanUtils.copyProperties(entity, searchDnsResStrategy);
}
@@ -2008,7 +2011,7 @@ public class BaseController {
BeanUtils.copyProperties(entity, auditBatchCfg);
BeanUtils.copyProperties(entity, searchDnsIpCfg);
}
if(entity != null && (entity instanceof CfgIndexInfo)) {
if(entity != null && (entity instanceof IpPortCfg)) {
BeanUtils.copyProperties(entity, auditBatchCfg);
BeanUtils.copyProperties(entity, searchIpPortCfg);
}
@@ -2021,7 +2024,7 @@ public class BaseController {
BeanUtils.copyProperties(entity, auditBatchCfg);
BeanUtils.copyProperties(entity, searchDdosIpCfg);
}
if(entity != null && (entity instanceof CfgIndexInfo)) {
if(entity != null && (entity instanceof AppIpCfg)) {
BeanUtils.copyProperties(entity, auditBatchCfg);
BeanUtils.copyProperties(entity, searchAppIpCfg);
}
@@ -2331,58 +2334,131 @@ public class BaseController {
}
}
}else{
boolean hasData = true;
while(hasData){
List list = Lists.newArrayList();
/*
1026 app_domain_cfg
1028 app_ip_cfg
1029 app_ssl_cert_cfg
1152 app_topic_domain_cfg
1024 app_http_cfg
1026 app_domain_cfg
*/
if(auditBatchCfg.getServiceId().equals(1026)) {
list=appCfgService.findAppDomainList(page, searchAppDomainCfg).getList();
}
if(auditBatchCfg.getServiceId().equals(1028)) {
list=appCfgService.findAppIpList(page, searchAppIpCfg).getList();
}
if(auditBatchCfg.getServiceId().equals(1029)) {
list=appCfgService.findAppSslList(page, searchAppSslCertCfg).getList();
}
if(auditBatchCfg.getServiceId().equals(1152)) {
list=appCfgService.findAppTopicDomainList(page, searchAppTopicCfg).getList();
}
if(auditBatchCfg.getServiceId().equals(1024)) {
list=appCfgService.findAppHttpList(page, searchAppHttpCfg).getList();
}
if(!StringUtil.isEmpty(list)){
if(auditBatchCfg.getIsValid().equals(1)) {
if(auditBatchCfg.getServiceId().equals(1028)){
hasData=configSynchronizationService.auditAppIpData(userRegionList,
page,auditBatchCfg,list,hasData,true);
}else{
hasData=configSynchronizationService.auditSingleMaatData(cfgType,userRegionList,
page,auditBatchCfg,list,hasData,true);
}
}else {
List<BaseCfg> newList=new ArrayList<>();
if(!StringUtil.isEmpty(list)) {
for (Object obj : list) {
BaseCfg cfg=(BaseCfg)obj;
newList.add(cfg);
//批量下发时未下发过的app需要下发正常配置;已下发过的app需要下发ip复用配置为保证事物分两种方式下发
//1028 app_ip_cfg
if(auditBatchCfg.getServiceId().equals(1028)) {
if(true) {
boolean hasData = true;
while(hasData){
/************预先获取已下发的groupid和compileid且每批次重新获取避免上一批次有新的compileId下发*************/
Map<Integer, Integer> isIssuedCompileIds=new HashMap<>();
//分组复用组信息1:app ip2内容3区域 ,4 asn
ConfigGroupInfo groupInfo=new ConfigGroupInfo();
groupInfo.setIsIssued(1);
groupInfo.setGroupType(1);
List<ConfigGroupInfo> groupInfos=configGroupInfoService.findAllList(groupInfo);//每一批次下发都取一次最新的group_info信息
Map<Integer, Integer> compileGroups=new HashMap<>();
if(!StringUtil.isEmpty(groupInfos)) {
for (ConfigGroupInfo configGroupInfo : groupInfos) {
isIssuedCompileIds.put(configGroupInfo.getCompileId(), configGroupInfo.getGroupId());
}
}
hasData=commonPolicyService.auditNtcMaatData(cfgList, page, auditBatchCfg,newList, hasData);
if(!StringUtil.isEmpty(isIssuedCompileIds)) {
auditBatchCfg.setCompileGroupMap(isIssuedCompileIds);
auditBatchCfg.setCompileIsIssued(1);
List list = Lists.newArrayList();
searchAppIpCfg.setCompileGroupMap(isIssuedCompileIds);
list=appCfgService.findAppIpList(page, searchAppIpCfg).getList();
if(!StringUtil.isEmpty(list)){
//APP IP配置生效/失效
hasData=configSynchronizationService.auditAppIpData(userRegionList,
page,auditBatchCfg,list,hasData,true);
if(hasData) {
page.setPageNo(1);
}
}else{
hasData = false;
}
}else {
hasData = false;
}
}
if(hasData) {
page.setPageNo(1);
}
if(auditBatchCfg.getIsValid().equals(1)) {
boolean hasData = true;
while(hasData){
/************预先获取未下发的groupid和compileid********************/
//获取已下发的appcompileid
Map<Integer, Integer> notIssuedCompileIds=new HashMap<>();
//分组复用组信息1:app ip2内容3区域 ,4 asn
ConfigGroupInfo groupInfo=new ConfigGroupInfo();
groupInfo.setIsIssued(0);
groupInfo.setGroupType(1);
List<ConfigGroupInfo> groupInfos=configGroupInfoService.findAllList(groupInfo);//每一批次下发都取一次最新的group_info信息
Map<Integer, Integer> compileGroups=new HashMap<>();
if(!StringUtil.isEmpty(groupInfos)) {
for (ConfigGroupInfo configGroupInfo : groupInfos) {
notIssuedCompileIds.put(configGroupInfo.getCompileId(), configGroupInfo.getGroupId());
}
}
if(!StringUtil.isEmpty(notIssuedCompileIds)) {
auditBatchCfg.setCompileGroupMap(notIssuedCompileIds);
searchAppIpCfg.setCompileGroupMap(notIssuedCompileIds);
auditBatchCfg.setCompileIsIssued(0);
List list = Lists.newArrayList();
list=appCfgService.findAppIpList(page, searchAppIpCfg).getList();
if(!StringUtil.isEmpty(list)){
//APP IP配置生效/失效
hasData=configSynchronizationService.auditAppIpData(userRegionList,
page,auditBatchCfg,list,hasData,true);
if(hasData) {
page.setPageNo(1);
}
}else{
hasData = false;
}
}else {
hasData = false;
}
}
}
}else {
boolean hasData = true;
while(hasData){
List list = Lists.newArrayList();
/*
1026 app_domain_cfg
1028 app_ip_cfg
1029 app_ssl_cert_cfg
1152 app_topic_domain_cfg
1024 app_http_cfg
1026 app_domain_cfg
*/
if(auditBatchCfg.getServiceId().equals(1026)) {
list=appCfgService.findAppDomainList(page, searchAppDomainCfg).getList();
}
if(auditBatchCfg.getServiceId().equals(1029)) {
list=appCfgService.findAppSslList(page, searchAppSslCertCfg).getList();
}
if(auditBatchCfg.getServiceId().equals(1152)) {
list=appCfgService.findAppTopicDomainList(page, searchAppTopicCfg).getList();
}
if(auditBatchCfg.getServiceId().equals(1024)) {
list=appCfgService.findAppHttpList(page, searchAppHttpCfg).getList();
}
if(!StringUtil.isEmpty(list)){
if(auditBatchCfg.getIsValid().equals(1)) {
hasData=configSynchronizationService.auditSingleMaatData(cfgType,userRegionList,
page,auditBatchCfg,list,hasData,true);
}else {
List<BaseCfg> newList=new ArrayList<>();
if(!StringUtil.isEmpty(list)) {
for (Object obj : list) {
BaseCfg cfg=(BaseCfg)obj;
newList.add(cfg);
}
}
hasData=commonPolicyService.auditNtcMaatData(cfgList, page, auditBatchCfg,newList, hasData);
}
if(hasData) {
page.setPageNo(1);
}
}else{
hasData = false;
}
}else{
hasData = false;
}
}
}
}
}else if("2".equals(serviceTypeXml)){

View File

@@ -373,39 +373,66 @@ public class AppCfgController extends BaseController {
*/
@RequestMapping(value = {"auditAppIpCfg"})
@RequiresPermissions(value={"app:ip:confirm"})
public String auditAppIpCfg(Integer isAudit,Integer isValid,String ids,Integer functionId, RedirectAttributes redirectAttributes) {
AppIpCfg entity = new AppIpCfg();
String[] idArray = ids.split(",");
//同一编译IP的分组
Map<Integer,List<AppIpCfg>> dataMap=new HashMap<>();
for(String id :idArray){
entity = appCfgService.getAppIpCfg(Long.parseLong(id));
entity.setIsAudit(isAudit);
entity.setIsValid(isValid);
entity.setAuditorId(UserUtils.getUser().getId());
entity.setAuditTime(new Date());
entity.setFunctionId(functionId);
entity.setTableName(AppIpCfg.getTablename());
if(dataMap.containsKey(entity.getCompileId())) {
dataMap.get(entity.getCompileId()).add(entity);
}else {
List<AppIpCfg> ipList=new ArrayList<>();
ipList.add(entity);
dataMap.put(entity.getCompileId(), ipList);
}
}
for(List<AppIpCfg> entitys:dataMap.values()) {
try {
appCfgService.auditAppIpCfg(entitys,isAudit);
} catch (Exception e) {
e.printStackTrace();
logger.error("app协议IP配置下发失败",e);
if(e instanceof MaatConvertException) {
addMessage(redirectAttributes,"error","request_service_failed");
public String auditAppIpCfg(Model model,@ModelAttribute("cfg")AppIpCfg cfg,
Integer isValid,
Integer isAudit,
String ids,
Integer functionId,
RedirectAttributes redirectAttributes,
HttpServletResponse response,
HttpServletRequest request) {
if(!StringUtil.isEmpty(ids)) {
AppIpCfg entity = new AppIpCfg();
String[] idArray = ids.split(",");
//同一编译IP的分组
Map<Integer,List<AppIpCfg>> dataMap=new HashMap<>();
for(String id :idArray){
entity = appCfgService.getAppIpCfg(Long.parseLong(id));
entity.setIsAudit(isAudit);
entity.setIsValid(isValid);
entity.setAuditorId(UserUtils.getUser().getId());
entity.setAuditTime(new Date());
entity.setFunctionId(functionId);
entity.setTableName(AppIpCfg.getTablename());
if(dataMap.containsKey(entity.getCompileId())) {
dataMap.get(entity.getCompileId()).add(entity);
}else {
addMessage(redirectAttributes,"error","audit_failed");
List<AppIpCfg> ipList=new ArrayList<>();
ipList.add(entity);
dataMap.put(entity.getCompileId(), ipList);
}
}
for(List<AppIpCfg> entitys:dataMap.values()) {
try {
appCfgService.auditAppIpCfg(entitys,isAudit);
} catch (Exception e) {
e.printStackTrace();
logger.error("app协议IP配置下发失败",e);
if(e instanceof MaatConvertException) {
addMessage(redirectAttributes,"error","request_service_failed");
}else {
addMessage(redirectAttributes,"error","audit_failed");
}
}
}
}else {
Page<AppIpCfg> searchPage=new Page<AppIpCfg>(request,response,"r");
Page<AppIpCfg> auditPage=new Page<AppIpCfg>(request,response,"r");
BeanUtils.copyProperties(searchPage, auditPage);
try {
auditAll(auditPage,isValid , cfg);
} catch (Exception e) {
logger.error("配置下发失败:",e);
if(e instanceof MaatConvertException) {
addMessage(redirectAttributes,"error", "request_service_failed");
}else {
addMessage(redirectAttributes,"error", "audit_failed");
}
}
return ipCfgList(model, cfg, request, response);
}
return "redirect:" + adminPath +"/app/ipCfgList?functionId="+functionId;