域清空时取消obj-group-list maat配置

This commit is contained in:
wangxin
2019-06-14 11:29:03 +08:00
parent 1c4308e536
commit f232a5b90a
5 changed files with 93 additions and 11 deletions

View File

@@ -46,7 +46,7 @@ public interface CommonPolicyDao {
List<CfgIndexInfo> getObjGroupListByGroupIds(@Param("groupIds")String groupIds,@Param("functionId")Integer functionId,@Param("isValid") Integer isValid);
void updateCfgIndexCommonGroupIds(List<CfgIndexInfo> cfgIndexInfos);
void updateCfgIndexCommonGroupIds(CfgIndexInfo cfgIndexInfo);
List<ObjGroupCfg> getObjGroupList(@Param("ids")String ids);

View File

@@ -779,6 +779,12 @@
<if test="commonGroupIds != null">
common_group_ids= #{commonGroupIds,jdbcType=VARCHAR},
</if>
<if test="isValid != null">
is_valid= #{isValid,jdbcType=INTEGER},
</if>
<if test="isAudit != null">
is_audit= #{isAudit,jdbcType=INTEGER},
</if>
</trim>
</set>
where cfg_id = #{cfgId,jdbcType=BIGINT}

View File

@@ -3362,6 +3362,7 @@ public abstract class BaseService {
realGroupIds.deleteCharAt(realGroupIds.toString().length()-1);
}
List<CfgIndexInfo> toUpdateCfgIndexInfos=new ArrayList<>();
List<CfgIndexInfo> toCancelCfgIndexInfos=new ArrayList<>();
//查询cfg_index_info表获取所有用到了这个group_id的非删除配置
List<CfgIndexInfo> cfgIndexInfos=commonPolicyDao.getObjGroupListByGroupIds(realGroupIds.toString(),null,null);
@@ -3373,6 +3374,7 @@ public abstract class BaseService {
List compileIds=new ArrayList();
//组织一个大的json
ToMaatBean maatBean = new ToMaatBean();
ToMaatBean cancelMaatBean = new ToMaatBean();
ServiceConfigTemplateUtil templateUtil=new ServiceConfigTemplateUtil();
Map<String,Object> interceptUserRegionMap=new HashMap<>();
for(CfgIndexInfo cfgIndexInfo:cfgIndexInfos){
@@ -3381,6 +3383,7 @@ public abstract class BaseService {
MaatCfg maatCfg = new MaatCfg();
Set<Integer> groupIdSet=new HashSet<>();
List<MaatCfg> configCompileList = new ArrayList();
List<MaatCfg> cancelConfigCompileList = new ArrayList();
List<GroupCfg> groupRelationList = new ArrayList();
List<IpCfg> ipRegionList = new ArrayList();
List<StringCfg> strRegionList = new ArrayList();
@@ -3398,17 +3401,27 @@ public abstract class BaseService {
//需要更新的组
cfgIndexInfo.setCommonGroupIds(gsonToJson(userRgionMap));
if(!oldCommonGroupIds.equals(cfgIndexInfo.getCommonGroupIds())){
if(CollectionUtils.isEmpty(cfgIndexInfo.getIpCommGroupCfgList())&&
CollectionUtils.isEmpty(cfgIndexInfo.getUrlCommGroupList())&&CollectionUtils.isEmpty(cfgIndexInfo.getScriberIdCommGroupList())&&
CollectionUtils.isEmpty(cfgIndexInfo.getDomainCommGroupList())){
cfgIndexInfo.setIsValid(Constants.VALID_NO);
cfgIndexInfo.setIsAudit(Constants.AUDIT_NOT_YES);
cfgIndexInfo.setCommonGroupIds("");
toCancelCfgIndexInfos.add(cfgIndexInfo);
}else if(!oldCommonGroupIds.equals(cfgIndexInfo.getCommonGroupIds())){
toUpdateCfgIndexInfos.add(cfgIndexInfo);
//commonPolicyDao.updateCfgIndexCommonGroupIds(cfgIndexInfo);
}
if(cfgIndexInfo.getIsValid().equals(Constants.VALID_YES)){
//没组了,取消配置
if(userRgionMap.isEmpty()){
//没组了,取消配置,没域了,取消配置
if(userRgionMap.isEmpty()||(CollectionUtils.isEmpty(cfgIndexInfo.getIpCommGroupCfgList())&&
CollectionUtils.isEmpty(cfgIndexInfo.getUrlCommGroupList())&&CollectionUtils.isEmpty(cfgIndexInfo.getScriberIdCommGroupList())&&
CollectionUtils.isEmpty(cfgIndexInfo.getDomainCommGroupList()))){
maatCfg.setCompileId(cfgIndexInfo.getCompileId());
maatCfg.setServiceId(cfgIndexInfo.getServiceId());
maatCfg.setIsValid(0);//无效
configCompileList.add(maatCfg);
cancelConfigCompileList.add(maatCfg);
}else{//有组,重新下发配置
//保存区域IP信息
List<AreaIpCfg> areaIpCfgList=areaIpCfgDao.getByCompileId(cfgIndexInfo.getCompileId());
@@ -3519,22 +3532,49 @@ public abstract class BaseService {
configCompileList.add(maatCfg);
}
if(CollectionUtils.isEmpty(maatBean.getConfigCompileList())){
if(configCompileList.size()>0&&CollectionUtils.isEmpty(maatBean.getConfigCompileList())){
maatBean.setConfigCompileList(configCompileList);
maatBean.setAuditTime(cfgIndexInfo.getAuditTime());
maatBean.setCreatorName(cfgIndexInfo.getCurrentUser().getName());
maatBean.setVersion(Constants.MAAT_VERSION);
maatBean.setOpAction(Constants.UPDATE_ACTION);
}
}else if(cfgIndexInfo.getIsValid().equals(Constants.VALID_NO)){//生效的配置置为了失效
maatCfg.setCompileId(cfgIndexInfo.getCompileId());
maatCfg.setServiceId(cfgIndexInfo.getServiceId());
maatCfg.setIsValid(0);//无效
cancelConfigCompileList.add(maatCfg);
}
if(cancelConfigCompileList.size()>0&&CollectionUtils.isEmpty(cancelMaatBean.getConfigCompileList())){
cancelMaatBean.setConfigCompileList(cancelConfigCompileList);
cancelMaatBean.setAuditTime(cfgIndexInfo.getAuditTime());
cancelMaatBean.setCreatorName(cfgIndexInfo.getCurrentUser().getName());
cancelMaatBean.setVersion(Constants.MAAT_VERSION);
cancelMaatBean.setOpAction(Constants.UPDATE_ACTION);
}
//下发maat配置
//auditPolicy(cfgIndexInfo,cfgIndexInfo.getIsAudit(),Constants.UPDATE_ACTION);
}
}
//需要更新的cfg_index_info数据库更新
if(toCancelCfgIndexInfos.size()>0){
for(CfgIndexInfo info:toCancelCfgIndexInfos){
commonPolicyDao.updateCfgIndexCommonGroupIds(info);
}
}
if(toUpdateCfgIndexInfos.size()>0){
commonPolicyDao.updateCfgIndexCommonGroupIds(toUpdateCfgIndexInfos);
for(CfgIndexInfo info:toUpdateCfgIndexInfos){
commonPolicyDao.updateCfgIndexCommonGroupIds(info);
}
}
//向maat发送配置
if(CollectionUtils.isNotEmpty(cancelMaatBean.getConfigCompileList())){
//调用服务接口下发配置数据
String json=gsonToJson(cancelMaatBean);
logger.info("策略对象组取消配置参数:"+json);
//调用服务接口下发配置
ToMaatResult result = ConfigServiceUtil.put(json,1);
logger.info("策略对象组取消响应信息:"+result.getMsg());
}
//向maat发送配置
if(CollectionUtils.isNotEmpty(maatBean.getConfigCompileList())){

View File

@@ -152,7 +152,7 @@ public class CommonGroupManageService extends BaseService{
if(size > 0 && info.getUdFlag().equals(0)) {
update=true;
udFlag = 1;
}else if(size == 0 && !info.getUdFlag().equals(2)){
}else if(size == 0 /*&& !info.getUdFlag().equals(2)*/){
update=true;
}
if(update){