2018-11-26 14:34:24 +08:00
package com.nis.web.service.configuration ;
import java.lang.reflect.Field ;
import java.util.ArrayList ;
import java.util.Date ;
2018-11-29 15:04:03 +08:00
import java.util.HashMap ;
2018-11-26 14:34:24 +08:00
import java.util.List ;
import java.util.Map ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import net.sf.json.JSONObject ;
import org.apache.poi.ss.formula.functions.T ;
import org.dom4j.Node ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import antlr.StringUtils ;
2018-11-28 12:00:25 +08:00
import com.google.common.collect.Lists ;
2019-03-15 16:15:11 +08:00
import com.google.gson.Gson ;
import com.google.gson.JsonObject ;
2018-11-26 14:34:24 +08:00
import com.nis.domain.FunctionServiceDict ;
import com.nis.domain.Page ;
2019-03-15 16:15:11 +08:00
import com.nis.domain.basics.AsnGroupInfo ;
2018-11-27 16:57:08 +08:00
import com.nis.domain.basics.AsnIpCfg ;
2018-11-28 19:58:34 +08:00
import com.nis.domain.configuration.AppFeatureIndex ;
2018-11-29 15:04:03 +08:00
import com.nis.domain.configuration.AppIpCfg ;
2018-11-26 14:34:24 +08:00
import com.nis.domain.configuration.AppPolicyCfg ;
import com.nis.domain.configuration.AvFileSampleCfg ;
import com.nis.domain.configuration.BaseCfg ;
import com.nis.domain.configuration.BaseStringCfg ;
import com.nis.domain.configuration.CfgIndexInfo ;
import com.nis.domain.configuration.ComplexkeywordCfg ;
import com.nis.domain.configuration.DdosIpCfg ;
import com.nis.domain.configuration.DnsIpCfg ;
import com.nis.domain.configuration.DnsResStrategy ;
import com.nis.domain.configuration.FileDigestCfg ;
import com.nis.domain.configuration.IpPortCfg ;
import com.nis.domain.configuration.PxyObjKeyring ;
2019-01-03 12:27:21 +08:00
import com.nis.domain.configuration.PxyObjSpoofingIpPool ;
2018-11-26 14:34:24 +08:00
import com.nis.domain.configuration.PxyObjTrustedCaCert ;
import com.nis.domain.configuration.PxyObjTrustedCaCrl ;
2018-12-09 13:50:05 +08:00
import com.nis.domain.configuration.WebsiteDomainTopic ;
2018-12-07 10:07:53 +08:00
import com.nis.domain.maat.GroupReuseAddBean ;
import com.nis.domain.maat.GroupReuseCfg ;
2018-11-26 14:34:24 +08:00
import com.nis.domain.maat.MaatCfg ;
import com.nis.domain.maat.ToMaatBean ;
import com.nis.domain.maat.ToMaatResult ;
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 ;
2018-11-29 15:04:03 +08:00
import com.nis.domain.specific.ConfigGroupInfo ;
import com.nis.domain.specific.SpecificServiceCfg ;
2018-11-26 14:34:24 +08:00
import com.nis.util.ConfigServiceUtil ;
import com.nis.util.Constants ;
2018-11-30 11:26:34 +08:00
import com.nis.util.DateUtil ;
2018-11-26 14:34:24 +08:00
import com.nis.util.DateUtils ;
import com.nis.util.DictUtils ;
2018-11-29 18:46:35 +08:00
import com.nis.util.FileUtils ;
2018-11-26 14:34:24 +08:00
import com.nis.util.ServiceConfigTemplateUtil ;
import com.nis.util.StringUtil ;
2019-03-15 16:15:11 +08:00
import com.nis.web.dao.basics.AsnGroupInfoDao ;
2018-12-09 13:50:05 +08:00
import com.nis.web.dao.configuration.AppCfgDao ;
2018-11-29 10:59:54 +08:00
import com.nis.web.dao.configuration.CommonPolicyDao ;
2018-11-26 14:34:24 +08:00
import com.nis.web.dao.configuration.ConfigSynchronizationDao ;
2018-11-29 15:04:03 +08:00
import com.nis.web.dao.specific.ConfigGroupInfoDao ;
import com.nis.web.dao.specific.SpecificServiceCfgDao ;
2018-11-26 14:34:24 +08:00
import com.nis.web.security.UserUtils ;
import com.nis.web.service.BaseService ;
2019-03-15 16:15:11 +08:00
import com.sun.xml.internal.rngom.util.Utf16 ;
2018-11-26 14:34:24 +08:00
/ * *
* 配置全量同步事务类
* @author zhangwei
*
* /
@Service
public class ConfigSynchronizationService extends BaseService {
@Autowired
protected ConfigSynchronizationDao configSynchronizationDao ;
2018-11-29 10:59:54 +08:00
@Autowired
protected CommonPolicyDao commonPolicyDao ;
2018-11-29 15:04:03 +08:00
@Autowired
protected SpecificServiceCfgDao specificServiceCfgDao ;
@Autowired
protected ConfigGroupInfoDao configGroupInfoDao ;
2018-12-09 13:50:05 +08:00
@Autowired
2019-03-15 16:15:11 +08:00
protected AsnGroupInfoDao asnGroupInfoDao ;
@Autowired
2018-12-09 13:50:05 +08:00
protected AppCfgDao appCfgDao ;
2018-12-03 16:38:25 +08:00
private boolean lastServiceTag = false ; //标识是否是最后一个同步业务
2018-12-05 09:32:16 +08:00
private boolean isFinished = false ;
2018-11-26 14:34:24 +08:00
/ * *
* 配置全量更新下发
2019-03-15 16:15:11 +08:00
* @param serviceIdCondition 界面传入的全量同步某一个业务
2018-11-26 14:34:24 +08:00
* @param request
* @param response
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws SecurityException
* @throws NoSuchFieldException
* @throws ClassNotFoundException
* /
2019-03-15 16:15:11 +08:00
public void send ( Integer serviceIdCondition , HttpServletRequest request , HttpServletResponse response , BaseCfg cfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException , ClassNotFoundException {
2018-11-26 14:34:24 +08:00
long start = System . currentTimeMillis ( ) ;
ServiceConfigTemplateUtil serviceTemplate = new ServiceConfigTemplateUtil ( ) ;
if ( cfg = = null ) {
2019-03-15 16:15:11 +08:00
List < Map < String , Object > > serviceList = new ArrayList < > ( ) ;
if ( StringUtil . isEmpty ( serviceIdCondition ) ) {
serviceList = serviceTemplate . getServiceList ( ) ;
} else {
serviceList = serviceTemplate . getServiceListByServiceId ( serviceIdCondition ) ;
}
2018-12-03 16:38:25 +08:00
int lastService = 0 ;
lastServiceTag = false ;
2018-11-26 14:34:24 +08:00
for ( Map < String , Object > service : serviceList ) {
2018-12-03 16:38:25 +08:00
lastService + + ;
if ( lastService = = serviceList . size ( ) ) {
lastServiceTag = true ;
}
2018-11-26 14:34:24 +08:00
String tableName = service . get ( " tableName " ) . toString ( ) ;
String serviceType = service . get ( " serviceType " ) . toString ( ) ;
String className = service . get ( " className " ) . toString ( ) ;
String serviceId = service . get ( " id " ) . toString ( ) ;
BaseCfg entity = new BaseCfg ( ) ;
entity . setServiceId ( Integer . valueOf ( serviceId ) ) ;
entity . setIsAudit ( 1 ) ;
entity . setIsValid ( 1 ) ;
2018-11-28 19:58:34 +08:00
entity . setTableName ( tableName ) ;
2018-11-26 14:34:24 +08:00
if ( " 1 " . equals ( serviceType ) ) { //maat类配置
List < Map < String , Object > > cfgList = ( List < Map < String , Object > > ) service . get ( " cfgList " ) ;
List < Map < String , Object > > userRegionList = ( List < Map < String , Object > > ) service . get ( " userRegionList " ) ;
2018-11-28 19:58:34 +08:00
if ( cfgList . size ( ) > 0 ) {
Page page = new Page ( request , response , Constants . MAAT_JSON_SEND_SIZE , " a " ) ;
handleNtcMaatData ( cfgList , userRegionList , page , entity , request , response , false , tableName ) ;
} else {
int cfgType = Integer . parseInt ( service . get ( " cfgType " ) . toString ( ) ) ;
if ( " ddos_ip_cfg " . equals ( tableName ) ) {
Page < DdosIpCfg > page = new Page < DdosIpCfg > ( request , response , Constants . MAAT_JSON_SEND_SIZE , " a " ) ;
handleDdosMaatData ( cfgList , userRegionList , page , entity , request , response , false ) ;
} else {
Page < T > page = new Page < T > ( request , response , Constants . MAAT_JSON_SEND_SIZE , " a " ) ;
handleSingleMaatData ( cfgType , userRegionList , page , entity , request , response , false ) ;
}
}
2018-11-26 14:34:24 +08:00
} else if ( " 2 " . equals ( serviceType ) ) { //回调类配置
entity . setTableName ( tableName ) ;
entity . setServiceId ( Integer . valueOf ( serviceId ) ) ;
Page < BaseCfg > page = new Page < BaseCfg > ( request , response , Constants . MAAT_JSON_SEND_SIZE , " a " ) ;
handleCallbackData ( className , page , entity , request , response , false ) ;
}
2019-04-09 09:10:40 +08:00
//最后一个业务,发送一个结束标识
if ( lastServiceTag ) {
2018-12-05 09:28:11 +08:00
String json = " {} " ;
2019-03-21 17:33:55 +06:00
//如果是所有业务全量同步需要发送一个service=-1的请求, 有助于服务端删除分组复用配置
if ( StringUtil . isEmpty ( serviceIdCondition ) ) {
entity . setServiceId ( - 1 ) ;
}
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (finish data).json " , json , false ) ;
2019-03-20 11:32:24 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , Integer . parseInt ( serviceType ) , entity . getServiceId ( ) , entity . getTableName ( ) , " FINISHED " ) ;
2019-03-21 17:33:55 +06:00
logger . info ( " 全量下发响应信息【finish】: " + result . toString ( ) ) ;
2018-12-05 09:32:16 +08:00
}
2018-11-26 14:34:24 +08:00
}
long end = System . currentTimeMillis ( ) ;
logger . info ( " 本次配置全量同步,开始时间: " + start
+ " ,结束时间: " + end
+ " ,共计花费 " + ( ( end - start ) / 1000 + " 秒 " ) ) ;
} else {
}
}
/ * *
* 处理ntc业务maat类配置
* @param serviceId
* @param request
* @param response
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* /
public void handleNtcMaatData ( List < Map < String , Object > > cfgList , List < Map < String , Object > > userRegionList ,
2018-11-28 19:58:34 +08:00
Page < T > page , BaseCfg entity , HttpServletRequest request , HttpServletResponse response ,
boolean isUpdateCfg , String tableName ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
2018-11-26 14:34:24 +08:00
boolean hasData = true ;
2019-03-21 17:33:55 +06:00
int index = 0 ;
2018-11-26 14:34:24 +08:00
while ( hasData ) {
entity . setPage ( page ) ;
2018-11-28 19:58:34 +08:00
List list = Lists . newArrayList ( ) ;
if ( " cfg_index_info " . equals ( tableName ) ) {
list = configSynchronizationDao . getCfgIndexList ( entity ) ;
if ( ! StringUtil . isEmpty ( list ) ) {
hasData = auditNtcMaatData ( cfgList , userRegionList , page , entity , list , hasData , isUpdateCfg ) ;
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
} else {
hasData = false ;
}
2018-11-30 11:26:34 +08:00
} else if ( " file_digest_cfg " . equals ( tableName ) ) {
list = configSynchronizationDao . getFileDigestListByService ( entity ) ;
if ( ! StringUtil . isEmpty ( list ) ) {
hasData = auditFileDigestData ( cfgList , userRegionList , page , entity , list , hasData , isUpdateCfg ) ;
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
} else {
hasData = false ;
}
2018-11-28 19:58:34 +08:00
} else if ( " app_policy_cfg " . equals ( tableName ) ) {
list = configSynchronizationDao . getAppPolicyList ( entity ) ;
if ( ! StringUtil . isEmpty ( list ) ) {
hasData = auditAppPolicyData ( cfgList , userRegionList , page , entity , list , hasData , isUpdateCfg ) ;
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
} else {
hasData = false ;
}
} else if ( " app_feature_index " . equals ( tableName ) ) {
list = configSynchronizationDao . getAppFeatureIndexList ( entity ) ;
if ( ! StringUtil . isEmpty ( list ) ) {
hasData = auditAppFeatureData ( cfgList , userRegionList , page , entity , list , hasData , isUpdateCfg ) ;
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
} else {
hasData = false ;
2018-11-26 14:34:24 +08:00
}
2018-11-27 16:17:51 +08:00
} else {
2018-11-28 19:58:34 +08:00
logger . info ( " 全量同步未知业务 " ) ;
2018-11-27 16:17:51 +08:00
hasData = false ;
}
2018-11-28 19:58:34 +08:00
2019-03-21 17:33:55 +06:00
//此业务无数据需同步,也许向服务端发送一个{}串
if ( index = = 0 & & StringUtil . isEmpty ( list ) & & ! isUpdateCfg ) {
String json = " {} " ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (m nodata).json " , json , false ) ;
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
}
index + + ;
2018-11-27 16:17:51 +08:00
}
}
/ * *
* MAAT配置批量下发
* @param cfgList
* @param userRegionList
* @param page
* @param entity
* @param list
* @param hasData
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* /
public boolean auditNtcMaatData ( List < Map < String , Object > > cfgList ,
List < Map < String , Object > > userRegionList ,
Page page ,
BaseCfg entity ,
List < CfgIndexInfo > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
List < IpPortCfg > ipList = new ArrayList ( ) ;
2018-11-27 16:57:08 +08:00
List < AsnIpCfg > asnIpList = new ArrayList ( ) ;
2018-11-27 16:17:51 +08:00
List < BaseStringCfg > strList = new ArrayList ( ) ;
List < ComplexkeywordCfg > complexStrList = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > numList = new ArrayList ( ) ;
List < FileDigestCfg > fileList = new ArrayList ( ) ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
List < Integer > compileIds = new ArrayList ( ) ;
2018-11-27 16:57:08 +08:00
List < String > asnGroupIds = new ArrayList ( ) ;
2018-11-27 16:17:51 +08:00
for ( CfgIndexInfo cfg : list ) {
compileIds . add ( cfg . getCompileId ( ) ) ;
2019-03-15 16:15:11 +08:00
/ * if ( entity . getServiceId ( ) . equals ( 37 ) | | entity . getServiceId ( ) . equals ( 149 ) ) {
2018-11-27 16:57:08 +08:00
asnGroupIds . add ( cfg . getUserRegion4 ( ) ) ;
2019-03-15 16:15:11 +08:00
} * /
2018-11-27 16:17:51 +08:00
}
2018-11-29 10:59:54 +08:00
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , compileIds , null ) ;
}
}
2019-04-17 17:49:23 +08:00
//用于存储自定义域为关键字的业务, key=compileId, value=keyword.
Map < Integer , BaseStringCfg > keywordMap = new HashMap < > ( ) ;
2018-11-29 10:59:54 +08:00
2018-11-27 16:17:51 +08:00
if ( cfgList ! = null ) {
for ( Map < String , Object > m : cfgList ) {
String tableName = m . get ( " tableName " ) . toString ( ) ;
if ( " 1 " . equals ( m . get ( " cfgType " ) ) ) {
2019-03-15 16:15:11 +08:00
ipList . addAll ( configSynchronizationDao . getIpPortList ( tableName , compileIds ) ) ;
2018-11-27 16:17:51 +08:00
} else if ( " 2 " . equals ( m . get ( " cfgType " ) ) ) {
2019-04-17 17:49:23 +08:00
List < BaseStringCfg > strDataList = configSynchronizationDao . getStrList ( tableName , compileIds ) ;
strList . addAll ( strDataList ) ;
//512/521/514/1026业务的用户自定义域取DOMAIN_STR取自Keyword
if ( entity . getServiceId ( ) = = 512
| | entity . getServiceId ( ) = = 521
| | entity . getServiceId ( ) = = 514
| | entity . getServiceId ( ) = = 1026 ) {
keywordMap = configSynchronizationDao . getCompileIdWithKeyword ( tableName , compileIds ) ;
}
2018-11-27 16:17:51 +08:00
} else if ( " 3 " . equals ( m . get ( " cfgType " ) ) ) {
complexStrList . addAll ( configSynchronizationDao . getComplexStrList ( tableName , compileIds ) ) ;
} else if ( " 4 " . equals ( m . get ( " cfgType " ) ) ) {
} else if ( " 5 " . equals ( m . get ( " cfgType " ) ) ) {
fileList . addAll ( configSynchronizationDao . getFileDigestList ( tableName , compileIds ) ) ;
2018-11-26 14:34:24 +08:00
}
2018-11-29 10:59:54 +08:00
if ( isUpdateCfg ) {
if ( tableName . equals ( " asn_ip_cfg " ) ) {
if ( ! StringUtil . isEmpty ( asnGroupIds ) ) {
commonPolicyDao . auditCfgBatch ( tableName , entity , asnGroupIds , null ) ;
}
} else {
commonPolicyDao . auditCfgBatch ( tableName , entity , compileIds , null ) ;
}
}
2018-11-27 16:17:51 +08:00
}
}
2018-11-28 12:00:25 +08:00
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号) , 分组复用的域配置不需要重新获取regionId,groupId
List < Integer > regionIds = ConfigServiceUtil . getId ( 3 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
2018-11-29 18:46:35 +08:00
List < Integer > groupIds = ConfigServiceUtil . getId ( 2 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
2018-11-27 16:17:51 +08:00
for ( CfgIndexInfo cfg : list ) {
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
2018-11-27 16:57:08 +08:00
List list1 = new ArrayList ( ) ;
2018-11-27 16:17:51 +08:00
List < BaseStringCfg > list2 = new ArrayList ( ) ;
List < ComplexkeywordCfg > list3 = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > list4 = new ArrayList ( ) ;
List < FileDigestCfg > list5 = new ArrayList ( ) ;
String userRegion = " " ;
//处理自定义域
if ( userRegionList ! = null ) {
for ( Map < String , Object > n : userRegionList ) {
Object userRegionPosition = n . get ( " userRegionPosition " ) ;
if ( userRegionPosition ! = null & & ( userRegionPosition . toString ( ) . equals ( " 1 " ) | | userRegionPosition . toString ( ) . equals ( " 0 " ) ) ) {
//通过反射机制获取自定义域字段值
String regionColumn = n . get ( " regionColumn " ) . toString ( ) ;
2019-03-15 16:15:11 +08:00
String regionKey = n . get ( " regionKey " ) . toString ( ) ;
Object value = " " ;
2018-11-27 16:17:51 +08:00
Class aClass = null ;
if ( userRegionPosition . toString ( ) . equals ( ( " 0 " ) ) ) {
aClass = BaseCfg . class ;
} else {
aClass = CfgIndexInfo . class ;
}
if ( entity . getServiceId ( ) . equals ( 517 ) | | entity . getServiceId ( ) . equals ( 560 ) ) { //代理替换策略
String [ ] regionArray = regionColumn . split ( " , " ) ;
for ( int r = 0 ; r < regionArray . length ; r + + ) {
Field field = aClass . getDeclaredField ( regionArray [ r ] ) ;
field . setAccessible ( true ) ;
2018-11-28 12:00:25 +08:00
if ( n . get ( " regionKey " ) . equals ( " substitute " ) ) {
value + = " / " + replaceContentEscape ( field . get ( cfg ) = = null ? " " : field . get ( cfg ) . toString ( ) ) ; //自定义域以/分割时的处理
} else {
value + = replaceContentEscape ( field . get ( cfg ) = = null ? " " : field . get ( cfg ) . toString ( ) ) ;
}
2018-11-27 16:17:51 +08:00
}
userRegion + = n . get ( " regionKey " ) + " = " + value + Constants . USER_REGION_SPLIT ;
} else {
2019-03-15 16:15:11 +08:00
if ( regionKey . equals ( " keyring_id " ) & & StringUtil . isEmpty ( value ) ) {
value = " 0 " ;
} else if ( regionKey . equals ( " DOMAIN_STR " ) ) {
2019-04-17 17:49:23 +08:00
if ( ! StringUtil . isEmpty ( keywordMap ) & & ! StringUtil . isEmpty ( keywordMap . get ( cfg . getCompileId ( ) ) ) ) {
value = keywordMap . get ( cfg . getCompileId ( ) ) . getCfgKeywords ( ) ;
2019-03-15 16:15:11 +08:00
}
2019-04-17 17:49:23 +08:00
} else if ( regionKey . equals ( " DOMAIN_ID " ) ) {
if ( ! StringUtil . isEmpty ( keywordMap ) & & ! StringUtil . isEmpty ( keywordMap . get ( cfg . getCompileId ( ) ) ) ) {
value = cfg . getCompileId ( ) ;
2019-03-15 16:15:11 +08:00
}
2019-04-17 17:49:23 +08:00
} else {
Field field = aClass . getDeclaredField ( regionColumn ) ;
field . setAccessible ( true ) ;
value = field . get ( cfg ) ;
2019-03-15 16:15:11 +08:00
}
2018-11-27 16:17:51 +08:00
if ( ! StringUtil . isEmpty ( value ) ) {
if ( StringUtil . isEmpty ( n . get ( " regionKey " ) ) ) {
userRegion = value . toString ( ) ;
2018-11-26 14:34:24 +08:00
} else {
userRegion + = n . get ( " regionKey " ) + " = " + value + Constants . USER_REGION_SPLIT ;
}
}
}
}
2018-11-27 16:17:51 +08:00
}
if ( userRegion . endsWith ( Constants . USER_REGION_SPLIT ) ) {
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
}
}
2018-11-28 12:00:25 +08:00
for ( AsnIpCfg ip : asnIpList ) { //asn不需要再次获取regionId,groupId
2018-11-27 16:57:08 +08:00
if ( ip . getAsnIpGroup ( ) . toString ( ) . equals ( cfg . getUserRegion4 ( ) ) ) { //根据组号对应
2018-11-28 15:27:49 +08:00
ip . setIsValid ( entity . getIsValid ( ) ) ;
2018-11-29 09:23:31 +08:00
ip . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-27 16:57:08 +08:00
list1 . add ( ip ) ;
}
}
2018-12-01 20:21:30 +08:00
2018-11-30 11:26:34 +08:00
if ( list1 . size ( ) > 0 ) {
GroupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . setCompileId ( cfg . getCompileId ( ) ) ;
groupCfg . setGroupId ( Integer . parseInt ( cfg . getUserRegion4 ( ) ) ) ;
groupCfg . setIsValid ( entity . getIsValid ( ) ) ;
groupCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
groupRelationList . add ( groupCfg ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( list1 , Constants . VALID_YES , null ) ) ;
2018-12-01 20:21:30 +08:00
} else if ( ! StringUtil . isEmpty ( asnGroupIds ) ) {
GroupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . setCompileId ( cfg . getCompileId ( ) ) ;
groupCfg . setGroupId ( Integer . parseInt ( cfg . getUserRegion4 ( ) ) ) ;
groupCfg . setIsValid ( entity . getIsValid ( ) ) ;
groupCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
groupRelationList . add ( groupCfg ) ;
ipRegionList . addAll ( ipRegionList ) ;
2018-11-30 11:26:34 +08:00
}
//配置域转换
2018-12-09 14:00:50 +08:00
userRegion = configCovert ( ipList , strList , complexStrList ,
2018-11-30 11:26:34 +08:00
numList , fileList , regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . 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 ( entity . getIsValid ( ) ) ;
if ( ! StringUtil . isEmpty ( userRegion ) ) {
maatCfg . setUserRegion ( userRegion ) ;
2018-11-27 16:17:51 +08:00
}
2018-11-30 11:26:34 +08:00
configCompileList . add ( maatCfg ) ;
}
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-30 11:26:34 +08:00
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( new Date ( ) ) ;
maatBean . setCreatorName ( UserUtils . getUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
2018-12-18 12:41:58 +06:00
// logger.info("配置批量下发:"+json);
2018-11-30 11:26:34 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
2018-11-26 14:34:24 +08:00
}
2018-11-30 11:26:34 +08:00
} else {
//调用服务接口配置全量更新
2018-12-05 09:32:16 +08:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2018-12-03 16:38:25 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-27 16:17:51 +08:00
}
2018-11-30 11:26:34 +08:00
}
return hasData ;
}
/ * *
* 文件摘要配置批量下发
* @param cfgList
* @param userRegionList
* @param page
* @param entity
* @param list
* @param hasData
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* /
public boolean auditFileDigestData ( List < Map < String , Object > > cfgList ,
List < Map < String , Object > > userRegionList ,
Page page ,
BaseCfg entity ,
List < FileDigestCfg > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
List < IpPortCfg > ipList = new ArrayList ( ) ;
List < BaseStringCfg > strList = new ArrayList ( ) ;
List < ComplexkeywordCfg > complexStrList = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > numList = new ArrayList ( ) ;
List < FileDigestCfg > fileList = new ArrayList ( ) ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
List < Integer > compileIds = new ArrayList ( ) ;
for ( FileDigestCfg cfg : list ) {
compileIds . add ( cfg . getCompileId ( ) ) ;
2018-12-05 09:32:16 +08:00
if ( ! StringUtil . isEmpty ( cfg . getCfdsLevel ( ) ) & & ( cfg . getCfdsLevel ( ) > 10 ) ) {
cfg . setCfdsLevel ( ( int ) ( cfg . getCfdsLevel ( ) / 10 ) ) ; //文件摘要置信度界面显示为70,80,90,100, 下发为7,8,9,10
}
2018-11-30 11:26:34 +08:00
fileList . add ( cfg ) ;
}
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , compileIds , null ) ;
2018-11-27 16:17:51 +08:00
}
2018-11-30 11:26:34 +08:00
}
if ( cfgList ! = null ) {
for ( Map < String , Object > m : cfgList ) {
String tableName = m . get ( " tableName " ) . toString ( ) ;
if ( " 1 " . equals ( m . get ( " cfgType " ) ) ) {
ipList . addAll ( configSynchronizationDao . getIpPortList ( tableName , compileIds ) ) ;
} else if ( " 2 " . equals ( m . get ( " cfgType " ) ) ) {
strList . addAll ( configSynchronizationDao . getStrList ( tableName , compileIds ) ) ;
} else if ( " 3 " . equals ( m . get ( " cfgType " ) ) ) {
complexStrList . addAll ( configSynchronizationDao . getComplexStrList ( tableName , compileIds ) ) ;
} else if ( " 4 " . equals ( m . get ( " cfgType " ) ) ) {
} else if ( " 5 " . equals ( m . get ( " cfgType " ) ) ) {
fileList . addAll ( configSynchronizationDao . getFileDigestList ( tableName , compileIds ) ) ;
}
if ( isUpdateCfg ) {
commonPolicyDao . auditCfgBatch ( tableName , entity , compileIds , null ) ;
2018-11-26 14:34:24 +08:00
}
}
2018-11-30 11:26:34 +08:00
}
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号) , 分组复用的域配置不需要重新获取regionId,groupId
List < Integer > regionIds = ConfigServiceUtil . getId ( 3 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
List < Integer > groupIds = ConfigServiceUtil . getId ( 2 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
for ( FileDigestCfg cfg : list ) {
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
List list1 = new ArrayList ( ) ;
List < BaseStringCfg > list2 = new ArrayList ( ) ;
List < ComplexkeywordCfg > list3 = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > list4 = new ArrayList ( ) ;
List < FileDigestCfg > list5 = new ArrayList ( ) ;
String userRegion = " " ;
//处理自定义域
if ( userRegionList ! = null ) {
for ( Map < String , Object > n : userRegionList ) {
Object userRegionPosition = n . get ( " userRegionPosition " ) ;
if ( userRegionPosition ! = null & & ( userRegionPosition . toString ( ) . equals ( " 1 " ) | | userRegionPosition . toString ( ) . equals ( " 0 " ) ) ) {
//通过反射机制获取自定义域字段值
String regionColumn = n . get ( " regionColumn " ) . toString ( ) ;
Class aClass = null ;
if ( userRegionPosition . toString ( ) . equals ( ( " 0 " ) ) ) {
aClass = BaseCfg . class ;
} else {
aClass = FileDigestCfg . class ;
}
Object value = " " ;
Field field = aClass . getDeclaredField ( regionColumn ) ;
field . setAccessible ( true ) ;
value = field . get ( cfg ) ;
if ( ! StringUtil . isEmpty ( value ) ) {
if ( StringUtil . isEmpty ( n . get ( " regionKey " ) ) ) {
userRegion = value . toString ( ) ;
} else {
userRegion + = n . get ( " regionKey " ) + " = " + value + Constants . USER_REGION_SPLIT ;
}
}
2018-11-27 16:57:08 +08:00
}
2018-11-30 11:26:34 +08:00
// System.out.println("userRegionList:"+n.get("regionKey")+","+n.get("regionColumn")+","+n.get("handleType"));
}
if ( userRegion . endsWith ( Constants . USER_REGION_SPLIT ) ) {
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
2018-11-27 16:17:51 +08:00
}
}
2018-11-30 11:26:34 +08:00
//配置域转换
configCovert ( ipList , strList , complexStrList ,
numList , fileList , regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
2018-11-27 16:17:51 +08:00
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
2018-11-29 09:23:31 +08:00
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-27 16:17:51 +08:00
maatCfg . setIpRegionList ( ipRegionList ) ;
maatCfg . setStrRegionList ( strRegionList ) ;
maatCfg . setNumRegionList ( numRegionList ) ;
maatCfg . setDigestRegionList ( digestRegionList ) ;
maatCfg . setGroupRelationList ( groupRelationList ) ;
maatCfg . setGroupNum ( groupRelationList . size ( ) ) ;
maatCfg . setAreaIpRegionList ( areaIpRegionList ) ;
2018-11-28 15:27:49 +08:00
maatCfg . setIsValid ( entity . getIsValid ( ) ) ;
2018-11-27 16:17:51 +08:00
if ( ! StringUtil . isEmpty ( userRegion ) ) {
maatCfg . setUserRegion ( userRegion ) ;
}
configCompileList . add ( maatCfg ) ;
}
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-27 16:17:51 +08:00
hasData = false ;
2018-11-26 14:34:24 +08:00
}
2018-11-27 16:17:51 +08:00
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
maatBean . setConfigCompileList ( configCompileList ) ;
2018-11-28 15:27:49 +08:00
maatBean . setAuditTime ( new Date ( ) ) ;
2018-11-27 16:17:51 +08:00
maatBean . setCreatorName ( UserUtils . getUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
String json = gsonToJson ( maatBean ) ;
2018-11-28 12:00:25 +08:00
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
2018-12-18 12:41:58 +06:00
// logger.info("配置批量下发:"+json);
2018-11-28 12:00:25 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
//调用服务接口配置全量更新
2018-12-05 09:32:16 +08:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2018-12-03 16:38:25 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-28 12:00:25 +08:00
}
2018-11-27 16:17:51 +08:00
}
return hasData ;
2018-11-26 14:34:24 +08:00
}
/ * *
2018-11-28 19:58:34 +08:00
* APP策略配置批量下发
2018-11-27 16:17:51 +08:00
* @param cfgList
* @param userRegionList
* @param page
* @param entity
* @param list
* @param hasData
2018-11-28 19:58:34 +08:00
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
2018-11-27 16:17:51 +08:00
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* /
2018-11-28 19:58:34 +08:00
public boolean auditAppPolicyData ( List < Map < String , Object > > cfgList ,
List < Map < String , Object > > userRegionList ,
Page page ,
2018-11-27 16:17:51 +08:00
BaseCfg entity ,
2018-11-28 19:58:34 +08:00
List < AppPolicyCfg > list ,
2018-11-27 16:17:51 +08:00
boolean hasData ,
2018-11-28 19:58:34 +08:00
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
2018-11-27 16:17:51 +08:00
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
List < IpPortCfg > ipList = new ArrayList ( ) ;
2018-11-28 19:58:34 +08:00
List < BaseStringCfg > strList = new ArrayList ( ) ;
List < ComplexkeywordCfg > complexStrList = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > numList = new ArrayList ( ) ;
List < FileDigestCfg > fileList = new ArrayList ( ) ;
2018-11-27 16:17:51 +08:00
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
2018-11-28 19:58:34 +08:00
List < Integer > compileIds = new ArrayList ( ) ;
List < String > asnGroupIds = new ArrayList ( ) ;
for ( AppPolicyCfg cfg : list ) {
compileIds . add ( cfg . getCompileId ( ) ) ;
}
2018-12-03 16:38:25 +08:00
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , compileIds , null ) ;
}
}
2018-11-28 19:58:34 +08:00
if ( cfgList ! = null ) {
for ( Map < String , Object > m : cfgList ) {
String tableName = m . get ( " tableName " ) . toString ( ) ;
if ( " 1 " . equals ( m . get ( " cfgType " ) ) ) {
ipList . addAll ( configSynchronizationDao . getIpPortList ( tableName , compileIds ) ) ;
} else if ( " 2 " . equals ( m . get ( " cfgType " ) ) ) {
strList . addAll ( configSynchronizationDao . getStrList ( tableName , compileIds ) ) ;
} else if ( " 3 " . equals ( m . get ( " cfgType " ) ) ) {
complexStrList . addAll ( configSynchronizationDao . getComplexStrList ( tableName , compileIds ) ) ;
} else if ( " 4 " . equals ( m . get ( " cfgType " ) ) ) {
} else if ( " 5 " . equals ( m . get ( " cfgType " ) ) ) {
fileList . addAll ( configSynchronizationDao . getFileDigestList ( tableName , compileIds ) ) ;
}
2018-12-03 16:38:25 +08:00
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
2019-04-12 15:52:13 +08:00
commonPolicyDao . auditCfgBatch ( tableName , entity , compileIds , null ) ;
2018-12-03 16:38:25 +08:00
}
}
2018-11-28 19:58:34 +08:00
}
}
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号) , compileIds.size()表示app策略本身有一个字符串域
List < Integer > regionIds = ConfigServiceUtil . getId ( 3 , ipList . size ( ) + strList . size ( ) + compileIds . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
2018-11-29 18:46:35 +08:00
List < Integer > groupIds = ConfigServiceUtil . getId ( 2 , ipList . size ( ) + strList . size ( ) + compileIds . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
2018-11-28 19:58:34 +08:00
for ( AppPolicyCfg cfg : list ) {
2018-11-27 16:17:51 +08:00
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
2018-11-28 19:58:34 +08:00
List list1 = new ArrayList ( ) ;
List < BaseStringCfg > list2 = new ArrayList ( ) ;
List < ComplexkeywordCfg > list3 = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > list4 = new ArrayList ( ) ;
List < FileDigestCfg > list5 = new ArrayList ( ) ;
2018-11-27 16:17:51 +08:00
String userRegion = " " ;
//处理自定义域
if ( userRegionList ! = null ) {
for ( Map < String , Object > n : userRegionList ) {
Object userRegionPosition = n . get ( " userRegionPosition " ) ;
if ( userRegionPosition ! = null & & ( userRegionPosition . toString ( ) . equals ( " 1 " ) | | userRegionPosition . toString ( ) . equals ( " 0 " ) ) ) {
//通过反射机制获取自定义域字段值
String regionColumn = n . get ( " regionColumn " ) . toString ( ) ;
Class aClass = null ;
if ( userRegionPosition . toString ( ) . equals ( ( " 0 " ) ) ) {
aClass = BaseCfg . class ;
} else {
2018-11-28 19:58:34 +08:00
aClass = AppPolicyCfg . class ;
2018-11-26 14:34:24 +08:00
}
2018-11-27 16:17:51 +08:00
Object value = " " ;
Field field = aClass . getDeclaredField ( regionColumn ) ;
field . setAccessible ( true ) ;
value = field . get ( cfg ) ;
if ( ! StringUtil . isEmpty ( value ) ) {
if ( StringUtil . isEmpty ( n . get ( " regionKey " ) ) ) {
userRegion = value . toString ( ) ;
} else {
userRegion + = n . get ( " regionKey " ) + " = " + value + Constants . USER_REGION_SPLIT ;
}
2018-11-26 14:34:24 +08:00
}
}
}
2018-11-27 16:17:51 +08:00
if ( userRegion . endsWith ( Constants . USER_REGION_SPLIT ) ) {
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
2018-11-26 14:34:24 +08:00
}
2018-11-27 16:17:51 +08:00
}
2018-11-28 19:58:34 +08:00
//将app码与行为码设置为字符串域
StringBuffer cfgKeywords = new StringBuffer ( ) ;
BaseStringCfg strCfg = new BaseStringCfg ( ) ;
if ( cfg . getServiceId ( ) . equals ( 35 ) | | cfg . getServiceId ( ) . equals ( 147 ) | | cfg . getServiceId ( ) . equals ( 1059 ) ) { //基础协议
cfgKeywords . append ( Constants . PROTO_ID_REGION + " = " + cfg . getAppCode ( ) ) ;
} else if ( cfg . getServiceId ( ) . equals ( 33 ) | | cfg . getServiceId ( ) . equals ( 145 ) | | cfg . getServiceId ( ) . equals ( 1056 ) ) {
cfgKeywords . append ( Constants . APP_ID_REGION + " = " + cfg . getAppCode ( ) ) ;
if ( cfg . getBehavCode ( ) ! = null ) {
cfgKeywords . append ( Constants . KEYWORD_EXPR ) ;
cfgKeywords . append ( Constants . BEHAV_ID_REGION + " = " + cfg . getBehavCode ( ) ) ;
}
} else if ( cfg . getServiceId ( ) . equals ( 36 ) | | cfg . getServiceId ( ) . equals ( 148 ) | | cfg . getServiceId ( ) . equals ( 1060 ) ) { //隧道加密协议
cfgKeywords . append ( Constants . PROTO_ID_REGION + " = " + cfg . getAppCode ( ) ) ;
if ( cfg . getBehavCode ( ) ! = null ) {
cfgKeywords . append ( Constants . KEYWORD_EXPR ) ;
cfgKeywords . append ( Constants . BEHAV_ID_REGION + " = " + cfg . getBehavCode ( ) ) ;
}
}
cfg . setCfgKeywords ( cfgKeywords . toString ( ) ) ;
BeanUtils . copyProperties ( cfg , strCfg ) ;
strList . add ( strCfg ) ;
2018-11-30 11:26:34 +08:00
//配置域转换
configCovert ( ipList , strList , complexStrList ,
numList , fileList , regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
2018-11-28 19:58:34 +08:00
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
2018-11-29 09:23:31 +08:00
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-28 19:58:34 +08:00
maatCfg . setIpRegionList ( ipRegionList ) ;
maatCfg . setStrRegionList ( strRegionList ) ;
maatCfg . setNumRegionList ( numRegionList ) ;
maatCfg . setDigestRegionList ( digestRegionList ) ;
maatCfg . setGroupRelationList ( groupRelationList ) ;
maatCfg . setGroupNum ( groupRelationList . size ( ) ) ;
maatCfg . setAreaIpRegionList ( areaIpRegionList ) ;
maatCfg . setIsValid ( entity . getIsValid ( ) ) ;
if ( ! StringUtil . isEmpty ( userRegion ) ) {
maatCfg . setUserRegion ( userRegion ) ;
}
configCompileList . add ( maatCfg ) ;
}
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-28 19:58:34 +08:00
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( new Date ( ) ) ;
maatBean . setCreatorName ( UserUtils . getUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
2018-12-18 12:41:58 +06:00
// logger.info("配置批量下发:"+json);
2018-11-28 19:58:34 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
//调用服务接口配置全量更新
2018-12-05 09:32:16 +08:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2018-12-03 16:38:25 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-28 19:58:34 +08:00
}
}
return hasData ;
}
/ * *
* APP特征批量下发
* @param cfgList
* @param userRegionList
* @param page
* @param entity
* @param list
* @param hasData
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* /
public boolean auditAppFeatureData ( List < Map < String , Object > > cfgList ,
List < Map < String , Object > > userRegionList ,
Page page ,
BaseCfg entity ,
List < AppFeatureIndex > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
List < IpPortCfg > ipList = new ArrayList ( ) ;
List < BaseStringCfg > strList = new ArrayList ( ) ;
List < ComplexkeywordCfg > complexStrList = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > numList = new ArrayList ( ) ;
List < FileDigestCfg > fileList = new ArrayList ( ) ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
List < Integer > compileIds = new ArrayList ( ) ;
List < String > asnGroupIds = new ArrayList ( ) ;
for ( AppFeatureIndex cfg : list ) {
compileIds . add ( cfg . getCompileId ( ) ) ;
if ( entity . getServiceId ( ) . equals ( 37 ) | | entity . getServiceId ( ) . equals ( 149 ) ) {
asnGroupIds . add ( cfg . getUserRegion4 ( ) ) ;
}
}
2018-12-07 14:28:14 +08:00
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , compileIds , null ) ;
}
}
2018-11-28 19:58:34 +08:00
if ( cfgList ! = null ) {
for ( Map < String , Object > m : cfgList ) {
String tableName = m . get ( " tableName " ) . toString ( ) ;
if ( " 1 " . equals ( m . get ( " cfgType " ) ) ) {
ipList . addAll ( configSynchronizationDao . getAppIpPortList ( tableName , compileIds ) ) ;
} else if ( " 2 " . equals ( m . get ( " cfgType " ) ) ) {
strList . addAll ( configSynchronizationDao . getStrList ( tableName , compileIds ) ) ;
} else if ( " 3 " . equals ( m . get ( " cfgType " ) ) ) {
complexStrList . addAll ( configSynchronizationDao . getComplexStrList ( tableName , compileIds ) ) ;
} else if ( " 4 " . equals ( m . get ( " cfgType " ) ) ) {
} else if ( " 5 " . equals ( m . get ( " cfgType " ) ) ) {
fileList . addAll ( configSynchronizationDao . getFileDigestList ( tableName , compileIds ) ) ;
}
2018-12-07 14:28:14 +08:00
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
2019-04-12 15:52:13 +08:00
commonPolicyDao . auditCfgBatch ( tableName , entity , compileIds , null ) ;
2018-12-07 14:28:14 +08:00
}
}
2018-11-28 19:58:34 +08:00
}
}
//批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号) , 分组复用的域配置不需要重新获取regionId,groupId
List < Integer > regionIds = ConfigServiceUtil . getId ( 3 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
2018-11-29 18:46:35 +08:00
List < Integer > groupIds = ConfigServiceUtil . getId ( 2 , ipList . size ( ) + strList . size ( ) + complexStrList . size ( ) + numList . size ( ) + fileList . size ( ) ) ;
2018-11-28 19:58:34 +08:00
for ( AppFeatureIndex cfg : list ) {
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
List list1 = new ArrayList ( ) ;
List < BaseStringCfg > list2 = new ArrayList ( ) ;
List < ComplexkeywordCfg > list3 = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > list4 = new ArrayList ( ) ;
List < FileDigestCfg > list5 = new ArrayList ( ) ;
String userRegion = " " ;
//处理自定义域
if ( userRegionList ! = null ) {
for ( Map < String , Object > n : userRegionList ) {
Object userRegionPosition = n . get ( " userRegionPosition " ) ;
if ( userRegionPosition ! = null & & ( userRegionPosition . toString ( ) . equals ( " 1 " ) | | userRegionPosition . toString ( ) . equals ( " 0 " ) ) ) {
//通过反射机制获取自定义域字段值
String regionColumn = n . get ( " regionColumn " ) . toString ( ) ;
Class aClass = null ;
if ( userRegionPosition . toString ( ) . equals ( ( " 0 " ) ) ) {
aClass = BaseCfg . class ;
} else {
aClass = AppFeatureIndex . class ;
}
Object value = " " ;
Field field = aClass . getDeclaredField ( regionColumn ) ;
field . setAccessible ( true ) ;
value = field . get ( cfg ) ;
if ( ! StringUtil . isEmpty ( value ) ) {
if ( StringUtil . isEmpty ( n . get ( " regionKey " ) ) ) {
userRegion = value . toString ( ) ;
} else {
userRegion + = n . get ( " regionKey " ) + " = " + value + Constants . USER_REGION_SPLIT ;
}
}
}
}
if ( userRegion . endsWith ( Constants . USER_REGION_SPLIT ) ) {
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
}
}
2018-11-30 11:26:34 +08:00
//配置域转换
configCovert ( ipList , strList , complexStrList ,
numList , fileList , regionIds , groupIds , entity , cfg . getCompileId ( ) ,
StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ,
groupRelationList , ipRegionList , strRegionList , numRegionList , digestRegionList , areaIpRegionList , userRegion ) ;
2018-11-28 19:58:34 +08:00
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
2018-11-29 09:23:31 +08:00
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-28 19:58:34 +08:00
maatCfg . setIpRegionList ( ipRegionList ) ;
maatCfg . setStrRegionList ( strRegionList ) ;
maatCfg . setNumRegionList ( numRegionList ) ;
maatCfg . setDigestRegionList ( digestRegionList ) ;
maatCfg . setGroupRelationList ( groupRelationList ) ;
maatCfg . setGroupNum ( groupRelationList . size ( ) ) ;
maatCfg . setAreaIpRegionList ( areaIpRegionList ) ;
maatCfg . setIsValid ( entity . getIsValid ( ) ) ;
if ( ! StringUtil . isEmpty ( userRegion ) ) {
maatCfg . setUserRegion ( userRegion ) ;
}
configCompileList . add ( maatCfg ) ;
}
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-28 19:58:34 +08:00
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( new Date ( ) ) ;
maatBean . setCreatorName ( UserUtils . getUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
2018-12-18 12:41:58 +06:00
// logger.info("配置批量下发:"+json);
2018-11-28 19:58:34 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
//调用服务接口配置全量更新
2018-12-05 09:32:16 +08:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2018-12-03 16:38:25 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-28 19:58:34 +08:00
}
}
return hasData ;
}
/ * *
* 处理ddos配置
* @param serviceId
* @param request
* @param response
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* /
public void handleDdosMaatData ( List < Map < String , Object > > cfgList , List < Map < String , Object > > userRegionList ,
Page < DdosIpCfg > page , BaseCfg entity , HttpServletRequest request , HttpServletResponse response ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
boolean hasData = true ;
2019-03-21 17:33:55 +06:00
int index = 0 ;
2018-11-28 19:58:34 +08:00
while ( hasData ) {
entity . setPage ( page ) ;
List < DdosIpCfg > list = configSynchronizationDao . getDdosIpCfgList ( entity ) ;
if ( ! StringUtil . isEmpty ( list ) ) {
hasData = auditDdosMaatData ( cfgList , userRegionList ,
page , entity , list , hasData , isUpdateCfg ) ;
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
} else {
hasData = false ;
}
2019-03-21 17:33:55 +06:00
//此业务无数据需同步,也许向服务端发送一个{}串
if ( index = = 0 & & StringUtil . isEmpty ( list ) & & ! isUpdateCfg ) {
String json = " {} " ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (d nodata).json " , json , false ) ;
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
}
index + + ;
2018-11-28 19:58:34 +08:00
}
}
/ * *
* 处理单域maat配置
* @param serviceId
* @param request
* @param response
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* /
public void handleSingleMaatData ( int cfgType , List < Map < String , Object > > userRegionList ,
Page < T > page , BaseCfg entity , HttpServletRequest request , HttpServletResponse response ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
boolean hasData = true ;
2019-03-15 16:15:11 +08:00
//APP IP按配置Id批量下发[服务端只支持maat和回调类格式的json串]
List < ConfigGroupInfo > groupInfos = new ArrayList < > ( ) ;
//ASN IP按配置Id全量下发[服务端只支持maat和回调类格式的json串]
List < AsnGroupInfo > asnGroupInfos = new ArrayList < > ( ) ;
if ( entity . getServiceId ( ) . equals ( 1028 ) ) {
ConfigGroupInfo groupInfo = new ConfigGroupInfo ( ) ;
groupInfo . setIsIssued ( 1 ) ; //全量下发只用获取已下发的group信息
groupInfo . setGroupType ( 1 ) ;
groupInfos = configGroupInfoDao . findAllList ( groupInfo ) ; //每一批次下发都取一次最新的group_info信息
if ( StringUtil . isEmpty ( groupInfos ) ) {
hasData = false ;
}
}
if ( entity . getServiceId ( ) . equals ( 400 ) ) {
AsnGroupInfo groupInfo = new AsnGroupInfo ( ) ;
groupInfo . setIsValid ( 1 ) ; //全量下发只用获取已下发的group信息
asnGroupInfos = asnGroupInfoDao . findAsnGroupInfoList ( groupInfo ) ; //每一批次下发都取一次最新的group_info信息
if ( StringUtil . isEmpty ( asnGroupInfos ) ) {
hasData = false ;
2019-03-21 17:33:55 +06:00
2019-03-15 16:15:11 +08:00
}
}
2019-03-21 17:33:55 +06:00
//此业务无数据需同步,也许向服务端发送一个{}串
if ( ! hasData & & ! isUpdateCfg ) {
String json = " {} " ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (s asn or app nodata).json " , json , false ) ;
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
}
int index = 0 ;
List listData = Lists . newArrayList ( ) ;
2018-11-28 19:58:34 +08:00
while ( hasData ) {
entity . setPage ( page ) ;
List list = Lists . newArrayList ( ) ;
if ( cfgType = = 1 ) {
2018-11-29 15:04:03 +08:00
if ( entity . getServiceId ( ) . equals ( 1028 ) ) {
2019-03-15 16:15:11 +08:00
page . setPageSize ( - 1 ) ;
page . setPageNo ( 1 ) ;
page . setLastPage ( true ) ;
entity . setPage ( page ) ;
entity . setCompileId ( groupInfos . get ( 0 ) . getCompileId ( ) ) ;
entity . setGroupId ( groupInfos . get ( 0 ) . getGroupId ( ) ) ;
2018-11-29 15:04:03 +08:00
list = configSynchronizationDao . getAppIpFeatureList ( entity ) ;
2019-03-21 17:33:55 +06:00
listData . addAll ( list ) ;
2019-03-15 16:15:11 +08:00
} else if ( entity . getServiceId ( ) . equals ( 400 ) ) {
page . setPageSize ( - 1 ) ;
page . setPageNo ( 1 ) ;
page . setLastPage ( true ) ;
entity . setPage ( page ) ;
entity . setCompileId ( asnGroupInfos . get ( 0 ) . getCompileId ( ) ) ;
entity . setGroupId ( asnGroupInfos . get ( 0 ) . getGroupId ( ) ) ;
list = configSynchronizationDao . getAsnIpList ( entity ) ;
2019-03-21 17:33:55 +06:00
listData . addAll ( list ) ;
2018-11-29 15:04:03 +08:00
} else {
list = configSynchronizationDao . getIpPortListByService ( entity ) ;
}
2018-11-28 19:58:34 +08:00
} else if ( cfgType = = 2 ) {
list = configSynchronizationDao . getStrListByService ( entity ) ;
} else if ( cfgType = = 3 ) {
list = configSynchronizationDao . getComplexStrListByService ( entity ) ;
}
if ( ! StringUtil . isEmpty ( list ) ) {
2018-11-29 15:04:03 +08:00
if ( entity . getServiceId ( ) . equals ( 1028 ) ) {
hasData = auditAppIpData ( userRegionList ,
page , entity , list , hasData , isUpdateCfg ) ;
2019-03-15 16:15:11 +08:00
} else if ( entity . getServiceId ( ) . equals ( 400 ) ) {
hasData = auditAsnIpData ( userRegionList ,
page , entity , list , hasData , isUpdateCfg ) ;
2018-11-29 15:04:03 +08:00
} else {
hasData = auditSingleMaatData ( cfgType , userRegionList ,
page , entity , list , hasData , isUpdateCfg ) ;
}
2018-11-28 19:58:34 +08:00
if ( hasData ) {
page . setPageNo ( page . getNext ( ) ) ;
}
} else {
hasData = false ;
}
2019-03-15 16:15:11 +08:00
//ASN IP
if ( entity . getServiceId ( ) . equals ( 400 ) ) {
//处理完成一个compile, 删除一个Group
if ( ! StringUtil . isEmpty ( asnGroupInfos ) ) {
asnGroupInfos . remove ( 0 ) ;
}
if ( asnGroupInfos . size ( ) > 0 ) {
hasData = true ;
} else {
hasData = false ;
2019-03-21 17:33:55 +06:00
if ( StringUtil . isEmpty ( listData ) & & ! isUpdateCfg ) {
String json = " {} " ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (asn nodata).json " , json , false ) ;
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
}
2019-03-15 16:15:11 +08:00
}
2019-03-21 17:33:55 +06:00
//TODO 待处理
} else if ( entity . getServiceId ( ) . equals ( 1028 ) ) {
//APP IP
2019-03-15 16:15:11 +08:00
//处理完成一个compile, 删除一个Group
if ( ! StringUtil . isEmpty ( groupInfos ) ) {
groupInfos . remove ( 0 ) ;
}
if ( groupInfos . size ( ) > 0 ) {
hasData = true ;
} else {
hasData = false ;
2019-03-21 17:33:55 +06:00
if ( StringUtil . isEmpty ( listData ) & & ! isUpdateCfg ) {
String json = " {} " ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (app nodata).json " , json , false ) ;
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
}
}
} else {
//此业务无数据需同步,也许向服务端发送一个{}串
if ( index = = 0 & & StringUtil . isEmpty ( list ) & & ! isUpdateCfg ) {
String json = " {} " ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (s nodata).json " , json , false ) ;
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2019-03-15 16:15:11 +08:00
}
}
2019-03-21 17:33:55 +06:00
index + + ;
2018-11-28 19:58:34 +08:00
}
}
/ * *
* ddos配置批量下发
* @param cfgList
* @param userRegionList
* @param page
* @param entity
* @param list
* @param hasData
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* /
public boolean auditDdosMaatData ( List < Map < String , Object > > cfgList ,
List < Map < String , Object > > userRegionList ,
Page < DdosIpCfg > page ,
BaseCfg entity ,
List < DdosIpCfg > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
2018-12-05 09:32:16 +08:00
List < Integer > compileIds = new ArrayList ( ) ;
2018-11-28 19:58:34 +08:00
//批量获取regionId,groupId
2018-12-05 09:32:16 +08:00
List < Integer > regionIds = ConfigServiceUtil . getId ( 3 , list . size ( ) ) ;
2018-11-28 19:58:34 +08:00
List < Integer > groupIds = ConfigServiceUtil . getId ( 2 , list . size ( ) ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
DdosIpCfg cfg = list . get ( i ) ;
cfg . setRegionId ( regionIds . get ( i ) ) ;
cfg . setGroupId ( groupIds . get ( i ) ) ;
cfg . setIsValid ( entity . getIsValid ( ) ) ;
2018-11-29 09:23:31 +08:00
cfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-28 19:58:34 +08:00
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
List < DdosIpCfg > list1 = new ArrayList ( ) ;
String userRegion = " " ;
2019-03-15 16:15:11 +08:00
//处理自定义域【DDOS自定义域组成json结构】
Map ddosUserRegion = new HashMap ( ) ;
2018-11-28 19:58:34 +08:00
if ( userRegionList ! = null ) {
for ( Map < String , Object > n : userRegionList ) {
Object userRegionPosition = n . get ( " userRegionPosition " ) ;
if ( userRegionPosition ! = null & & ( userRegionPosition . toString ( ) . equals ( " 1 " ) | | userRegionPosition . toString ( ) . equals ( " 0 " ) ) ) {
//通过反射机制获取自定义域字段值
String regionColumn = n . get ( " regionColumn " ) . toString ( ) ;
Class aClass = null ;
if ( userRegionPosition . toString ( ) . equals ( ( " 0 " ) ) ) {
aClass = BaseCfg . class ;
} else {
aClass = DdosIpCfg . class ;
}
Object value = " " ;
Field field = aClass . getDeclaredField ( regionColumn ) ;
field . setAccessible ( true ) ;
value = field . get ( cfg ) ;
2019-03-15 16:15:11 +08:00
2018-11-28 19:58:34 +08:00
if ( ! StringUtil . isEmpty ( value ) ) {
if ( StringUtil . isEmpty ( n . get ( " regionKey " ) ) ) {
userRegion = value . toString ( ) ;
} else {
2019-03-15 16:15:11 +08:00
//userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT;
ddosUserRegion . put ( n . get ( " regionKey " ) , value ) ;
2018-11-28 19:58:34 +08:00
}
}
}
}
if ( userRegion . endsWith ( Constants . USER_REGION_SPLIT ) ) {
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
2019-03-15 16:15:11 +08:00
} else if ( ! StringUtil . isEmpty ( ddosUserRegion ) ) {
userRegion = new Gson ( ) . toJson ( ddosUserRegion ) ;
2018-11-28 19:58:34 +08:00
}
}
2018-12-05 09:32:16 +08:00
if ( isUpdateCfg & & ! StringUtil . isEmpty ( cfg ) & & ! StringUtil . isEmpty ( cfg . getCompileId ( ) ) ) {
compileIds . add ( cfg . getCompileId ( ) ) ;
}
2018-11-28 19:58:34 +08:00
list1 . add ( cfg ) ;
if ( list1 . size ( ) > 0 ) {
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
if ( map . get ( " numRegionList " ) ! = null ) {
numRegionList . addAll ( map . get ( " numRegionList " ) ) ;
}
}
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
2018-11-29 09:23:31 +08:00
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-28 19:58:34 +08:00
maatCfg . setIpRegionList ( ipRegionList ) ;
maatCfg . setStrRegionList ( strRegionList ) ;
maatCfg . setNumRegionList ( numRegionList ) ;
maatCfg . setDigestRegionList ( digestRegionList ) ;
maatCfg . setGroupRelationList ( groupRelationList ) ;
maatCfg . setGroupNum ( groupRelationList . size ( ) ) ;
maatCfg . setAreaIpRegionList ( areaIpRegionList ) ;
maatCfg . setIsValid ( entity . getIsValid ( ) ) ;
if ( ! StringUtil . isEmpty ( userRegion ) ) {
maatCfg . setUserRegion ( userRegion ) ;
}
configCompileList . add ( maatCfg ) ;
}
2018-12-05 09:32:16 +08:00
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( compileIds ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , compileIds , null ) ;
}
}
2018-11-28 19:58:34 +08:00
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-28 19:58:34 +08:00
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( new Date ( ) ) ;
maatBean . setCreatorName ( UserUtils . getUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
2018-12-18 12:41:58 +06:00
// logger.info("配置批量下发:"+json);
2018-11-28 19:58:34 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
//调用服务接口配置全量更新
2018-12-05 09:32:16 +08:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2018-12-03 16:38:25 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-28 19:58:34 +08:00
}
}
return hasData ;
}
/ * *
* 单域配置批量下发
* @param cfgList
* @param userRegionList
* @param page
* @param entity
* @param list
* @param hasData
* @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态
* @return
* @throws NoSuchFieldException
* @throws SecurityException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* /
public boolean auditSingleMaatData ( int cfgType ,
List < Map < String , Object > > userRegionList ,
Page < T > page ,
BaseCfg entity ,
List < T > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
2018-12-05 18:03:42 +08:00
List < Integer > ids = new ArrayList ( ) ;
2018-11-28 19:58:34 +08:00
//批量获取regionId,groupId
List < Integer > regionIds = ConfigServiceUtil . getId ( 3 , list . size ( ) ) ;
List < Integer > groupIds = ConfigServiceUtil . getId ( 2 , list . size ( ) ) ;
2018-11-29 10:59:54 +08:00
IpPortCfg ipCfg = new IpPortCfg ( ) ;
BaseStringCfg strCfg = new BaseStringCfg ( ) ;
ComplexkeywordCfg complexStrCfg = new ComplexkeywordCfg ( ) ;
2018-11-28 19:58:34 +08:00
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
BaseCfg cfg = new BaseCfg ( ) ;
2018-11-29 10:59:54 +08:00
if ( cfgType = = 1 ) {
BeanUtils . copyProperties ( list . get ( i ) , ipCfg ) ;
} else if ( cfgType = = 2 ) {
BeanUtils . copyProperties ( list . get ( i ) , strCfg ) ;
} else if ( cfgType = = 3 ) {
BeanUtils . copyProperties ( list . get ( i ) , complexStrCfg ) ;
}
2018-11-28 19:58:34 +08:00
BeanUtils . copyProperties ( list . get ( i ) , cfg ) ;
cfg . setIsValid ( entity . getIsValid ( ) ) ;
2018-11-29 09:23:31 +08:00
cfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-12-05 18:03:42 +08:00
ids . add ( cfg . getCompileId ( ) ) ;
2018-11-28 19:58:34 +08:00
maatCfg = new MaatCfg ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
List list1 = new ArrayList ( ) ;
String userRegion = " " ;
2018-12-09 13:50:05 +08:00
2018-11-28 19:58:34 +08:00
//处理自定义域
if ( userRegionList ! = null ) {
for ( Map < String , Object > n : userRegionList ) {
2018-12-09 13:50:05 +08:00
if ( entity . getTableName ( ) . equals ( " app_topic_domain_cfg " ) ) {
String domain = strCfg . getCfgKeywords ( ) ;
WebsiteDomainTopic websiteDomainTopic = new WebsiteDomainTopic ( ) ;
websiteDomainTopic . setDomain ( domain ) ;
//查询domainId
List < WebsiteDomainTopic > domainDict = appCfgDao . getDomainDict ( websiteDomainTopic ) ;
Long domainId = domainDict . get ( 0 ) . getId ( ) ;
userRegion + = n . get ( " regionKey " ) + " = " + domainId + Constants . USER_REGION_SPLIT ;
} else {
Object userRegionPosition = n . get ( " userRegionPosition " ) ;
if ( userRegionPosition ! = null ) {
//通过反射机制获取自定义域字段值
String regionColumn = n . get ( " regionColumn " ) . toString ( ) ;
Class aClass = null ;
if ( userRegionPosition . toString ( ) . equals ( ( " 0 " ) ) ) {
aClass = BaseCfg . class ;
} else {
if ( cfgType = = 1 ) {
aClass = IpPortCfg . class ;
} else if ( cfgType = = 2 ) {
aClass = BaseStringCfg . class ;
} else if ( cfgType = = 3 ) {
aClass = ComplexkeywordCfg . class ;
}
}
Object value = " " ;
Field field = aClass . getDeclaredField ( regionColumn ) ;
field . setAccessible ( true ) ;
2018-11-28 19:58:34 +08:00
if ( cfgType = = 1 ) {
2018-12-09 13:50:05 +08:00
value = field . get ( ipCfg ) ;
2018-11-28 19:58:34 +08:00
} else if ( cfgType = = 2 ) {
2018-12-09 13:50:05 +08:00
value = field . get ( strCfg ) ;
2018-11-28 19:58:34 +08:00
} else if ( cfgType = = 3 ) {
2018-12-09 13:50:05 +08:00
value = field . get ( complexStrCfg ) ;
2018-11-28 19:58:34 +08:00
}
2018-12-09 13:50:05 +08:00
if ( ! StringUtil . isEmpty ( value ) ) {
if ( StringUtil . isEmpty ( n . get ( " regionKey " ) ) ) {
userRegion = value . toString ( ) ;
} else {
userRegion + = n . get ( " regionKey " ) + " = " + value + Constants . USER_REGION_SPLIT ;
}
2018-11-28 19:58:34 +08:00
}
}
}
}
if ( userRegion . endsWith ( Constants . USER_REGION_SPLIT ) ) {
userRegion = userRegion . substring ( 0 , userRegion . length ( ) - 1 ) ;
}
}
2018-11-29 10:59:54 +08:00
if ( cfgType = = 1 ) {
ipCfg . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
ipCfg . setGroupId ( groupIds . get ( 0 ) ) ;
2018-12-05 17:56:41 +08:00
ipCfg . setIsValid ( entity . getIsValid ( ) ) ;
ipCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-29 10:59:54 +08:00
groupIds . remove ( 0 ) ;
list1 . add ( ipCfg ) ;
} else if ( cfgType = = 2 ) {
strCfg . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
strCfg . setGroupId ( groupIds . get ( 0 ) ) ;
2018-12-05 17:56:41 +08:00
strCfg . setIsValid ( entity . getIsValid ( ) ) ;
strCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-29 10:59:54 +08:00
groupIds . remove ( 0 ) ;
list1 . add ( strCfg ) ;
} else if ( cfgType = = 3 ) {
complexStrCfg . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
complexStrCfg . setGroupId ( groupIds . get ( 0 ) ) ;
2018-12-05 17:56:41 +08:00
complexStrCfg . setIsValid ( entity . getIsValid ( ) ) ;
complexStrCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-29 10:59:54 +08:00
groupIds . remove ( 0 ) ;
list1 . add ( complexStrCfg ) ;
}
2018-11-28 19:58:34 +08:00
if ( list1 . size ( ) > 0 ) {
if ( cfgType = = 1 ) {
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
if ( map . get ( " numRegionList " ) ! = null ) {
numRegionList . addAll ( map . get ( " numRegionList " ) ) ;
}
} else if ( cfgType = = 2 | | cfgType = = 3 ) {
Map < String , List > map = cfgToMaatConvert ( strRegionList , list1 , 2 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
}
2018-11-27 16:17:51 +08:00
BeanUtils . copyProperties ( cfg , maatCfg ) ;
maatCfg . setAction ( cfg . getAction ( ) ) ;
2018-11-29 09:23:31 +08:00
maatCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2018-11-27 16:17:51 +08:00
maatCfg . setIpRegionList ( ipRegionList ) ;
maatCfg . setStrRegionList ( strRegionList ) ;
maatCfg . setNumRegionList ( numRegionList ) ;
maatCfg . setDigestRegionList ( digestRegionList ) ;
maatCfg . setGroupRelationList ( groupRelationList ) ;
maatCfg . setGroupNum ( groupRelationList . size ( ) ) ;
maatCfg . setAreaIpRegionList ( areaIpRegionList ) ;
2018-11-28 15:27:49 +08:00
maatCfg . setIsValid ( entity . getIsValid ( ) ) ;
2018-11-27 16:17:51 +08:00
if ( ! StringUtil . isEmpty ( userRegion ) ) {
maatCfg . setUserRegion ( userRegion ) ;
}
configCompileList . add ( maatCfg ) ;
}
2018-12-05 18:03:42 +08:00
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( ids ) & & ! StringUtil . isEmpty ( entity . getTableName ( ) ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , ids , null ) ;
}
}
2018-11-27 16:17:51 +08:00
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-27 16:17:51 +08:00
hasData = false ;
2018-11-26 14:34:24 +08:00
}
2018-11-27 16:17:51 +08:00
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( new Date ( ) ) ;
maatBean . setCreatorName ( UserUtils . getUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
String json = gsonToJson ( maatBean ) ;
2018-11-28 12:00:25 +08:00
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
2018-12-18 12:41:58 +06:00
// logger.info("配置批量下发:"+json);
2018-11-28 12:00:25 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
//调用服务接口配置全量更新
2018-12-05 09:32:16 +08:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2018-12-03 16:38:25 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-28 12:00:25 +08:00
}
2018-11-27 16:17:51 +08:00
}
return hasData ;
2018-11-26 14:34:24 +08:00
}
/ * *
2018-11-29 15:04:03 +08:00
* 处理app ip特征 ( 分组复用 ) 配置
2019-03-15 16:15:11 +08:00
* 全量下发 ( 全量下发接口只支持maat和回调类的json字符串格式 )
2019-03-18 15:58:15 +08:00
* 批量下发 : 【 按照config group , 每组每批次下发 , 一次之下发一种格式的配置maat / reuse , CompileIsIssued标识 】
2018-11-26 14:34:24 +08:00
* @param serviceId
* @param request
* @param response
* /
2018-11-29 15:04:03 +08:00
public boolean auditAppIpData ( List < Map < String , Object > > userRegionList ,
Page < T > page ,
BaseCfg entity ,
List < T > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
2018-11-26 14:34:24 +08:00
2018-11-29 15:04:03 +08:00
ToMaatBean maatBean ;
2018-12-07 10:07:53 +08:00
GroupReuseAddBean reuseMaatBean ;
2018-11-29 15:04:03 +08:00
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
2018-12-07 10:07:53 +08:00
maatBean = new ToMaatBean ( ) ;
reuseMaatBean = new GroupReuseAddBean ( ) ;
2018-11-29 15:04:03 +08:00
configCompileList = new ArrayList ( ) ;
2018-12-07 10:07:53 +08:00
List < Integer > regionIds = new ArrayList ( ) ; //存储app ip域id
List < Integer > compileIds = new ArrayList ( ) ; //存储app compileId
Integer isIssued = entity . getCompileIsIssued ( ) ; //批量下发时使用,需要用来判断是否走分组复用接口
2018-11-29 15:04:03 +08:00
//同一编译IP的分组
Map < Integer , List < AppIpCfg > > dataMap = new HashMap < > ( ) ;
2019-03-15 16:15:11 +08:00
Integer compileId = entity . getCompileId ( ) ;
Integer groupId = entity . getGroupId ( ) ;
2019-03-18 15:58:15 +08:00
compileIds . add ( compileId ) ;
2019-03-15 16:15:11 +08:00
List < AppIpCfg > ipList = new ArrayList < > ( ) ;
2018-11-29 15:04:03 +08:00
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
AppIpCfg cfg = new AppIpCfg ( ) ;
BeanUtils . copyProperties ( list . get ( i ) , cfg ) ;
cfg . setIsValid ( entity . getIsValid ( ) ) ;
cfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
2019-03-15 16:15:11 +08:00
cfg . setGroupId ( groupId ) ;
ipList . add ( cfg ) ;
2019-03-18 15:58:15 +08:00
regionIds . add ( Integer . parseInt ( cfg . getUserRegion1 ( ) ) ) ;
2018-11-29 15:04:03 +08:00
}
2019-03-15 16:15:11 +08:00
dataMap . put ( compileId , ipList ) ;
2018-11-29 15:04:03 +08:00
for ( List < AppIpCfg > entitys : dataMap . values ( ) ) {
maatCfg = new MaatCfg ( ) ;
2018-12-07 10:07:53 +08:00
reuseMaatBean = new GroupReuseAddBean ( ) ;
2018-11-29 15:04:03 +08:00
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
2018-12-07 10:07:53 +08:00
2019-03-18 15:58:15 +08:00
if ( isUpdateCfg & & isIssued . equals ( 1 ) ) {
2018-12-07 10:07:53 +08:00
List < GroupReuseCfg > groupReuseList = new ArrayList < > ( ) ;
GroupReuseCfg groupReuseCfg = new GroupReuseCfg ( ) ;
/*groupReuseCfg.setUserRegion(userRegion);*/
2019-01-18 16:21:20 +08:00
groupReuseCfg . setServiceId ( entitys . get ( 0 ) . getServiceId ( ) ) ;
2018-12-07 10:07:53 +08:00
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( entitys , entity . getIsValid ( ) , entitys . get ( 0 ) . getGroupId ( ) ) ) ;
groupReuseCfg . setIpRegionList ( ipRegionList ) ;
groupReuseCfg . setStrRegionList ( strRegionList ) ;
groupReuseCfg . setNumRegionList ( numRegionList ) ;
groupReuseList . add ( groupReuseCfg ) ;
reuseMaatBean . setGroupReuseCfgList ( groupReuseList ) ;
reuseMaatBean . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? entitys . get ( 0 ) . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
reuseMaatBean . setCreatorName ( entitys . get ( 0 ) . getCurrentUser ( ) . getName ( ) ) ;
reuseMaatBean . setVersion ( Constants . MAAT_VERSION ) ;
2019-03-18 15:58:15 +08:00
reuseMaatBean . setOpAction ( Constants . INSERT_ACTION ) ;
2018-12-07 10:07:53 +08:00
} else {
GroupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . setCompileId ( entitys . get ( 0 ) . getCompileId ( ) ) ;
groupCfg . setGroupId ( entitys . get ( 0 ) . getGroupId ( ) ) ;
groupCfg . setIsValid ( Constants . VALID_YES ) ;
groupCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? entitys . get ( 0 ) . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
groupRelationList . add ( groupCfg ) ;
BeanUtils . copyProperties ( entitys . get ( 0 ) , maatCfg ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( entitys , Constants . VALID_YES , entitys . get ( 0 ) . getGroupId ( ) ) ) ;
maatCfg . setAction ( entitys . get ( 0 ) . getAction ( ) ) ;
maatCfg . setAuditTime ( entitys . 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 ( entitys . get ( 0 ) . getIsValid ( ) ) ;
// 设置APP自定义域
String userRegion = " APP_ID= " + entitys . get ( 0 ) . getAppCode ( ) /*+Constants.USER_REGION_SPLIT+"ASEV_ID="+businessType*/ ;
maatCfg . setUserRegion ( userRegion ) ;
configCompileList . add ( maatCfg ) ;
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( entitys . get ( 0 ) . getAuditTime ( ) ) ;
maatBean . setCreatorName ( entitys . get ( 0 ) . getCurrentUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
}
}
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( regionIds ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , regionIds , null ) ;
}
2019-03-18 15:58:15 +08:00
if ( isIssued . equals ( 0 ) ) { //group第一次下发需要修改状态为已下发
2018-12-07 10:07:53 +08:00
if ( ! StringUtil . isEmpty ( compileIds ) ) {
commonPolicyDao . auditCfgBatch ( " config_group_info " , entity , compileIds , null ) ;
}
}
2018-11-29 15:04:03 +08:00
}
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-29 15:04:03 +08:00
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
2018-12-07 10:07:53 +08:00
if ( isIssued . equals ( 1 ) ) { //已下发过的compile或配置取消直接走ip复用接口
json = gsonToJson ( reuseMaatBean ) ;
2019-03-18 15:58:15 +08:00
//logger.info("app ip批量生效: "+json);
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postGroupReuseSources ( json ) ;
if ( result ! = null ) {
logger . info ( " app ip批量生效响应信息: " + result . getMsg ( ) ) ;
2018-12-07 10:07:53 +08:00
}
} else { //未下发过的compile直接走正常maat配置接口
2019-03-18 15:58:15 +08:00
//logger.info("配置批量下发:"+json);
2018-12-07 10:07:53 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
2018-11-29 15:04:03 +08:00
}
} else {
//调用服务接口配置全量更新
2018-12-05 09:32:16 +08:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2019-03-15 16:15:11 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + compileId + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2019-03-15 16:15:11 +08:00
}
}
return hasData ;
}
/ * *
* 处理ASN ip配置
* 全量下发 ( 全量下发接口只支持maat和回调类的json字符串格式 )
2019-03-18 15:58:15 +08:00
* 批量下发 : 【 按照asn group , 每组每批次下发 , 一次之下发一种格式的配置maat / reuse , CompileIsIssued标识 】
2019-03-15 16:15:11 +08:00
* @param serviceId
* @param request
* @param response
* /
public boolean auditAsnIpData ( List < Map < String , Object > > userRegionList ,
Page < T > page ,
BaseCfg entity ,
List < T > list ,
boolean hasData ,
boolean isUpdateCfg ) throws NoSuchFieldException , SecurityException , IllegalArgumentException , IllegalAccessException {
ToMaatBean maatBean ;
GroupReuseAddBean reuseMaatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
maatBean = new ToMaatBean ( ) ;
reuseMaatBean = new GroupReuseAddBean ( ) ;
configCompileList = new ArrayList ( ) ;
List < Integer > regionIds = new ArrayList ( ) ; //存储app ip域id
2019-03-18 15:58:15 +08:00
List < Integer > compileIds = new ArrayList ( ) ; //存储app ip域id
2019-03-15 16:15:11 +08:00
Integer isIssued = entity . getCompileIsIssued ( ) ; //批量下发时使用,需要用来判断是否走分组复用接口
//同一编译IP的分组
Map < Integer , List < AsnIpCfg > > dataMap = new HashMap < > ( ) ;
Integer compileId = entity . getCompileId ( ) ;
Integer groupId = entity . getGroupId ( ) ;
2019-03-18 15:58:15 +08:00
compileIds . add ( compileId ) ;
2019-03-15 16:15:11 +08:00
List < AsnIpCfg > ipList = new ArrayList < > ( ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
AsnIpCfg cfg = new AsnIpCfg ( ) ;
BeanUtils . copyProperties ( list . get ( i ) , cfg ) ;
cfg . setIsValid ( entity . getIsValid ( ) ) ;
cfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? cfg . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
cfg . setGroupId ( groupId ) ;
2019-03-18 15:58:15 +08:00
regionIds . add ( cfg . getRegionId ( ) ) ;
2019-03-15 16:15:11 +08:00
ipList . add ( cfg ) ;
}
dataMap . put ( compileId , ipList ) ;
for ( List < AsnIpCfg > entitys : dataMap . values ( ) ) {
maatCfg = new MaatCfg ( ) ;
reuseMaatBean = new GroupReuseAddBean ( ) ;
maatCfg . initDefaultValue ( ) ;
groupRelationList = new ArrayList ( ) ;
ipRegionList = new ArrayList ( ) ;
strRegionList = new ArrayList ( ) ;
numRegionList = new ArrayList ( ) ;
digestRegionList = new ArrayList ( ) ;
areaIpRegionList = new ArrayList ( ) ;
2019-03-18 15:58:15 +08:00
//批量配置生效,当前组已下发过
if ( isUpdateCfg & & isIssued . equals ( 1 ) ) {
2019-03-15 16:15:11 +08:00
List < GroupReuseCfg > groupReuseList = new ArrayList < > ( ) ;
GroupReuseCfg groupReuseCfg = new GroupReuseCfg ( ) ;
/*groupReuseCfg.setUserRegion(userRegion);*/
groupReuseCfg . setServiceId ( entitys . get ( 0 ) . getServiceId ( ) ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( entitys , entity . getIsValid ( ) , entitys . get ( 0 ) . getGroupId ( ) ) ) ;
groupReuseCfg . setIpRegionList ( ipRegionList ) ;
groupReuseCfg . setStrRegionList ( strRegionList ) ;
groupReuseCfg . setNumRegionList ( numRegionList ) ;
groupReuseList . add ( groupReuseCfg ) ;
reuseMaatBean . setGroupReuseCfgList ( groupReuseList ) ;
reuseMaatBean . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? entitys . get ( 0 ) . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
reuseMaatBean . setCreatorName ( entitys . get ( 0 ) . getCurrentUser ( ) . getName ( ) ) ;
reuseMaatBean . setVersion ( Constants . MAAT_VERSION ) ;
2019-03-18 15:58:15 +08:00
reuseMaatBean . setOpAction ( Constants . INSERT_ACTION ) ;
2019-03-15 16:15:11 +08:00
} else {
GroupCfg groupCfg = new GroupCfg ( ) ;
groupCfg . setCompileId ( entitys . get ( 0 ) . getCompileId ( ) ) ;
groupCfg . setGroupId ( entitys . get ( 0 ) . getGroupId ( ) ) ;
groupCfg . setIsValid ( Constants . VALID_YES ) ;
groupCfg . setAuditTime ( StringUtil . isEmpty ( entity . getAuditTime ( ) ) ? entitys . get ( 0 ) . getAuditTime ( ) : entity . getAuditTime ( ) ) ;
groupRelationList . add ( groupCfg ) ;
BeanUtils . copyProperties ( entitys . get ( 0 ) , maatCfg ) ;
ipRegionList . addAll ( groupReuseCfgAddRemoveConvert ( entitys , Constants . VALID_YES , entitys . get ( 0 ) . getGroupId ( ) ) ) ;
maatCfg . setAction ( entitys . get ( 0 ) . getAction ( ) ) ;
maatCfg . setAuditTime ( entitys . 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 ( entitys . get ( 0 ) . getIsValid ( ) ) ;
// 设置asn自定义域
String userRegion = " ASN_ID=AS " + entitys . get ( 0 ) . getUserRegion1 ( ) /*+Constants.USER_REGION_SPLIT+"ASEV_ID="+businessType*/ ;
maatCfg . setUserRegion ( userRegion ) ;
configCompileList . add ( maatCfg ) ;
maatBean . setConfigCompileList ( configCompileList ) ;
maatBean . setAuditTime ( entitys . get ( 0 ) . getAuditTime ( ) ) ;
maatBean . setCreatorName ( entitys . get ( 0 ) . getCurrentUser ( ) . getName ( ) ) ;
maatBean . setVersion ( Constants . MAAT_VERSION ) ;
maatBean . setOpAction ( Constants . INSERT_ACTION ) ;
}
}
if ( isUpdateCfg ) {
if ( ! StringUtil . isEmpty ( regionIds ) ) {
commonPolicyDao . auditCfgBatch ( entity . getTableName ( ) , entity , regionIds , null ) ;
}
2019-03-18 15:58:15 +08:00
if ( isIssued . equals ( 0 ) ) { //group第一次下发需要修改状态为已下发
2019-03-15 16:15:11 +08:00
if ( ! StringUtil . isEmpty ( compileIds ) ) {
2019-03-18 15:58:15 +08:00
commonPolicyDao . auditCfgBatch ( " asn_group_info " , entity , compileIds , null ) ;
2019-03-15 16:15:11 +08:00
}
}
}
page . setList ( list ) ;
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
hasData = false ;
}
if ( ! StringUtil . isEmpty ( configCompileList . size ( ) ) ) {
String json = gsonToJson ( maatBean ) ;
//调用服务接口下发配置数据
if ( isUpdateCfg ) {
if ( isIssued . equals ( 1 ) ) { //已下发过的compile或配置取消直接走ip复用接口
json = gsonToJson ( reuseMaatBean ) ;
2019-03-18 15:58:15 +08:00
//logger.info("app ip批量生效: "+json);
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postGroupReuseSources ( json ) ;
if ( result ! = null ) {
logger . info ( " app ip批量生效响应信息: " + result . getMsg ( ) ) ;
2019-03-15 16:15:11 +08:00
}
} else { //未下发过的compile直接走正常maat配置接口
2019-03-18 15:58:15 +08:00
//logger.info("配置批量下发:"+json);
2019-03-15 16:15:11 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
}
} else {
//调用服务接口配置全量更新
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + compileId + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 1 , entity . getServiceId ( ) , null , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-26 14:34:24 +08:00
}
2018-11-29 15:04:03 +08:00
}
return hasData ;
2018-11-26 14:34:24 +08:00
}
/ * *
* 处理回调类业务配置
* @param serviceId
* @param request
* @param response
* @throws ClassNotFoundException
* /
public void handleCallbackData ( String className ,
Page < BaseCfg > page , BaseCfg entity , HttpServletRequest request , HttpServletResponse response ,
boolean isUpdateCfg ) throws ClassNotFoundException {
boolean hasData = true ;
2019-03-21 17:33:55 +06:00
int index = 0 ;
2018-11-26 14:34:24 +08:00
while ( hasData ) {
entity . setPage ( page ) ;
2018-11-27 16:17:51 +08:00
hasData = auditCallbackData ( className , page , entity , hasData , isUpdateCfg ) ;
if ( hasData ) {
2018-11-26 14:34:24 +08:00
page . setPageNo ( page . getNext ( ) ) ;
}
2019-03-21 17:33:55 +06:00
//此业务无数据需同步,也许向服务端发送一个{}串
if ( index = = 0 & & StringUtil . isEmpty ( page . getList ( ) ) & & ! isUpdateCfg ) {
String json = " {} " ;
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + System . currentTimeMillis ( ) + " (h nodata).json " , json , false ) ;
JSONObject result = ConfigServiceUtil . configSync ( json , 2 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
}
index + + ;
2018-11-26 14:34:24 +08:00
}
}
2018-11-27 16:17:51 +08:00
/ * *
* 回调类配置下发
* @param className
* @param page
* @param entity
* @param hasData
* @param isUpdateCfg
* @throws ClassNotFoundException
* /
public boolean auditCallbackData ( String className ,
Page < BaseCfg > page , BaseCfg entity ,
boolean hasData ,
boolean isUpdateCfg ) throws ClassNotFoundException {
ToMaatBean maatBean ;
MaatCfg maatCfg ;
List < MaatCfg > configCompileList ;
List < GroupCfg > groupRelationList ;
List < IpCfg > ipRegionList ;
List < StringCfg > strRegionList ;
List < NumBoundaryCfg > numRegionList ;
List < DigestCfg > digestRegionList ;
List < IpCfg > areaIpRegionList ;
maatBean = new ToMaatBean ( ) ;
configCompileList = new ArrayList ( ) ;
List list = new ArrayList ( ) ;
List newList = new ArrayList ( ) ;
2018-12-08 17:54:59 +08:00
List ids = new ArrayList ( ) ;
2018-11-29 18:46:35 +08:00
if ( entity . getServiceId ( ) . equals ( 3 ) ) { //ip drop回调类配置用了主表和子表关系
list = configSynchronizationDao . getCfgIndexList ( entity ) ;
2018-12-04 09:13:20 +08:00
if ( ! StringUtil . isEmpty ( list ) ) {
List < Integer > compileIds = Lists . newArrayList ( ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
CfgIndexInfo cfg = ( CfgIndexInfo ) list . get ( i ) ;
compileIds . add ( cfg . getCompileId ( ) ) ;
}
List subList = configSynchronizationDao . getIpDropList ( " ip_port_cfg " , compileIds ) ;
for ( int i = 0 ; i < subList . size ( ) ; i + + ) {
IpPortCfg cfg = ( IpPortCfg ) subList . get ( i ) ;
newList . add ( convertCallBackIp ( cfg , cfg . getGroupId ( ) ) ) ;
}
2018-11-27 16:17:51 +08:00
}
2018-12-04 09:13:20 +08:00
2018-11-29 18:46:35 +08:00
} else {
if ( className . equals ( " AvFileSampleCfg " ) ) {
list = configSynchronizationDao . getAvFileCfgList ( entity ) ;
2018-12-05 09:32:16 +08:00
newList . addAll ( list ) ;
} else if ( className . equals ( " AvSignSampleCfg " ) ) {
list = configSynchronizationDao . getAvSignCfgList ( entity ) ;
newList . addAll ( list ) ;
2018-11-29 18:46:35 +08:00
} else if ( className . equals ( " PxyObjKeyring " ) ) {
list = configSynchronizationDao . getPxyObjKeyringCfgList ( entity ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
PxyObjKeyring cfg = ( PxyObjKeyring ) list . get ( i ) ;
newList . add ( convertCallBackProxyObjKeyring ( cfg ) ) ;
}
} else if ( className . equals ( " PxyObjTrustedCaCert " ) ) {
2018-12-08 17:54:59 +08:00
//下发cert配置时, 需绑定下发crl配置
2018-11-29 18:46:35 +08:00
list = configSynchronizationDao . getPxyObjTrustedCertCfgList ( entity ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
PxyObjTrustedCaCert cfg = ( PxyObjTrustedCaCert ) list . get ( i ) ;
2018-12-05 15:03:46 +08:00
newList . addAll ( convertCallBackProxyObjTrustedCa ( cfg , null ) ) ;
2018-12-08 17:54:59 +08:00
ids . add ( cfg . getCompileId ( ) ) ;
2018-11-29 18:46:35 +08:00
}
2018-12-08 17:54:59 +08:00
if ( ! StringUtil . isEmpty ( ids ) ) {
list = new ArrayList < > ( ) ;
list = configSynchronizationDao . getPxyObjTrustedCrlCfgListByCertId ( ids ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
PxyObjTrustedCaCrl cfg = ( PxyObjTrustedCaCrl ) list . get ( i ) ;
newList . addAll ( convertCallBackProxyObjTrustedCa ( null , cfg ) ) ;
}
}
2018-11-29 18:46:35 +08:00
} else if ( className . equals ( " PxyObjTrustedCaCrl " ) ) {
2018-12-08 17:54:59 +08:00
ids = new ArrayList < > ( ) ;
//只允许单独下发certId为空或0的crl配置
2018-11-29 18:46:35 +08:00
list = configSynchronizationDao . getPxyObjTrustedCrlCfgList ( entity ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
PxyObjTrustedCaCrl cfg = ( PxyObjTrustedCaCrl ) list . get ( i ) ;
2018-12-05 15:03:46 +08:00
newList . addAll ( convertCallBackProxyObjTrustedCa ( null , cfg ) ) ;
2018-11-29 18:46:35 +08:00
}
2018-12-08 17:54:59 +08:00
2018-11-29 18:46:35 +08:00
} else if ( className . equals ( " DnsResStrategy " ) ) {
list = configSynchronizationDao . getDnsStrategyList ( entity ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
DnsResStrategy cfg = ( DnsResStrategy ) list . get ( i ) ;
newList . add ( convertCallBackDnsResStrategy ( cfg ) ) ;
}
} else if ( className . equals ( " DnsIpCfg " ) ) {
list = configSynchronizationDao . getDnsIpCfgList ( entity ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
DnsIpCfg cfg = ( DnsIpCfg ) list . get ( i ) ;
2018-12-07 20:26:12 +08:00
newList . add ( convertCallBackIp ( cfg , cfg . getDnsStrategyId ( ) ) ) ;
2018-11-29 18:46:35 +08:00
}
} else if ( className . equals ( " IpPortCfg " ) ) {
list = configSynchronizationDao . getIpPortListByService ( entity ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
IpPortCfg cfg = ( IpPortCfg ) list . get ( i ) ;
newList . add ( convertCallBackIp ( cfg , cfg . getGroupId ( ) ) ) ;
}
2019-01-03 12:27:21 +08:00
} else if ( className . equals ( " PxyObjSpoofingIpPool " ) ) {
list = configSynchronizationDao . getSpoofingIpPoolList ( entity ) ;
newList . addAll ( list ) ;
2018-11-27 16:17:51 +08:00
}
}
2018-11-29 18:46:35 +08:00
2018-11-27 16:17:51 +08:00
page . setList ( list ) ;
2018-12-18 12:41:58 +06:00
if ( page . getLast ( ) = = page . getPageNo ( ) ) {
2018-11-27 16:17:51 +08:00
hasData = false ;
}
2018-11-29 18:46:35 +08:00
if ( newList . size ( ) > 0 ) {
//调用服务接口下发配置数据
String json = gsonToJson ( newList ) ;
if ( isUpdateCfg ) {
2018-12-18 12:41:58 +06:00
// logger.info("配置批量下发:"+json);
2018-11-29 18:46:35 +08:00
//调用服务接口同步回调类配置
ToMaatResult result = ConfigServiceUtil . postMaatCfg ( json ) ;
if ( result ! = null ) {
logger . info ( " 配置批量下发响应信息: " + result . getMsg ( ) ) ;
}
} else {
2018-12-03 16:38:25 +08:00
FileUtils . writeToFile ( " /home/ceiec/configSync/ " + DateUtils . getDate ( " yyyy-MM-dd " ) + " / " + entity . getServiceId ( ) + " _ " + page . getPageNo ( ) + " _ " + System . currentTimeMillis ( ) + " .json " , json , false ) ;
2018-11-29 18:46:35 +08:00
//调用服务接口同步回调类配置
2019-03-21 17:33:55 +06:00
isFinished = ( ( ! hasData ) & & lastServiceTag ) ? true : false ;
2019-04-09 09:10:40 +08:00
JSONObject result = ConfigServiceUtil . configSync ( json , 2 , entity . getServiceId ( ) , entity . getTableName ( ) , null ) ;
2019-03-20 11:32:24 +08:00
logger . info ( " 全量下发响应信息: " + result . toString ( ) ) ;
2018-11-29 18:46:35 +08:00
}
2018-11-28 12:00:25 +08:00
}
2018-11-27 16:17:51 +08:00
return hasData ;
}
2018-11-30 11:26:34 +08:00
/ * *
* 配置域转换
* @param ipList
* @param strList
* @param complexStrList
* @param numList
* @param fileList
* @param regionIds
* @param groupIds
* @param entity
* @param compileId
* @param auditTime
* @param groupRelationList
* @param ipRegionList
* @param strRegionList
* @param numRegionList
* @param digestRegionList
* @param areaIpRegionList
* @param userRegion
* /
2018-12-09 14:00:50 +08:00
public String configCovert ( List < IpPortCfg > ipList , List < BaseStringCfg > strList , List < ComplexkeywordCfg > complexStrList ,
2018-11-30 11:26:34 +08:00
List < com . nis . domain . configuration . NumBoundaryCfg > numList ,
List < FileDigestCfg > fileList , List < Integer > regionIds , List < Integer > groupIds , BaseCfg entity ,
Integer compileId , Date auditTime , List < GroupCfg > groupRelationList ,
List < IpCfg > ipRegionList ,
List < StringCfg > strRegionList ,
List < NumBoundaryCfg > numRegionList ,
List < DigestCfg > digestRegionList ,
List < IpCfg > areaIpRegionList , String userRegion ) {
List list1 = new ArrayList ( ) ;
List < BaseStringCfg > list2 = new ArrayList ( ) ;
List < ComplexkeywordCfg > list3 = new ArrayList ( ) ;
List < com . nis . domain . configuration . NumBoundaryCfg > list4 = new ArrayList ( ) ;
List < FileDigestCfg > list5 = new ArrayList ( ) ;
if ( ipList . size ( ) > 0 ) {
for ( int index = 0 ; index < ipList . size ( ) ; index + + ) {
IpPortCfg ip = ipList . get ( index ) ;
if ( ip . getCompileId ( ) . equals ( compileId ) ) {
ip . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
ip . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
ip . setIsValid ( entity . getIsValid ( ) ) ;
ip . setAuditTime ( auditTime ) ;
list1 . add ( ip ) ;
}
}
}
for ( int index = 0 ; index < strList . size ( ) ; index + + ) {
BaseStringCfg str = strList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( compileId ) ) {
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( auditTime ) ;
list2 . add ( str ) ;
if ( entity . getServiceId ( ) . equals ( 513 ) | | entity . getServiceId ( ) . equals ( 515 ) ) {
if ( userRegion . equals ( " " ) ) {
userRegion + = Constants . USERREGION_DOMAIN_STR + " = " + str . getCfgKeywords ( ) ;
} else {
userRegion + = Constants . USER_REGION_SPLIT + Constants . USERREGION_DOMAIN_STR + " = " + str . getCfgKeywords ( ) ;
}
}
}
}
for ( int index = 0 ; index < complexStrList . size ( ) ; index + + ) {
ComplexkeywordCfg str = complexStrList . get ( index ) ;
if ( str . getCompileId ( ) . equals ( compileId ) ) {
str . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
str . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
str . setIsValid ( entity . getIsValid ( ) ) ;
str . setAuditTime ( auditTime ) ;
list3 . add ( str ) ;
if ( entity . getServiceId ( ) . equals ( 129 ) & & str . getDistrict ( ) ! = null ) { //http监测
String dictValue = DictUtils . getDictCode ( Constants . HTTP_HEADER_DICT_MODULE , str . getDistrict ( ) ) ;
if ( StringUtil . isEmpty ( dictValue ) | | dictValue . equals ( " 默认 " ) ) {
if ( userRegion . equals ( " " ) ) {
userRegion + = Constants . HTTP_HEADER_USER_REGION_KEY + " = " + str . getDistrict ( ) ;
} else {
userRegion + = Constants . USER_REGION_SPLIT + Constants . HTTP_HEADER_USER_REGION_KEY + " = " + str . getDistrict ( ) ;
}
}
}
}
}
for ( int index = 0 ; index < numList . size ( ) ; index + + ) {
com . nis . domain . configuration . NumBoundaryCfg num = numList . get ( index ) ;
if ( num . getCompileId ( ) . equals ( compileId ) ) {
num . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
num . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
num . setIsValid ( entity . getIsValid ( ) ) ;
num . setAuditTime ( auditTime ) ;
list4 . add ( num ) ;
}
}
for ( int index = 0 ; index < fileList . size ( ) ; index + + ) {
FileDigestCfg file = fileList . get ( index ) ;
if ( file . getCompileId ( ) . equals ( compileId ) ) {
file . setRegionId ( regionIds . get ( 0 ) ) ;
regionIds . remove ( 0 ) ;
file . setGroupId ( groupIds . get ( 0 ) ) ;
groupIds . remove ( 0 ) ;
file . setIsValid ( entity . getIsValid ( ) ) ;
file . setAuditTime ( auditTime ) ;
list5 . add ( file ) ;
}
}
if ( list1 . size ( ) > 0 ) {
ipList . removeAll ( list1 ) ;
Map < String , List > map = cfgToMaatConvert ( ipRegionList , list1 , 1 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
ipRegionList = map . get ( " dstList " ) ;
if ( map . get ( " numRegionList " ) ! = null ) {
numRegionList . addAll ( map . get ( " numRegionList " ) ) ;
}
}
if ( list2 . size ( ) > 0 ) {
strList . removeAll ( list2 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list2 , 2 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list3 . size ( ) > 0 ) {
complexStrList . removeAll ( list3 ) ;
Map < String , List > map = cfgToMaatConvert ( strRegionList , list3 , 3 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
strRegionList = map . get ( " dstList " ) ;
}
if ( list4 . size ( ) > 0 ) {
numList . removeAll ( list4 ) ;
Map < String , List > map = cfgToMaatConvert ( numRegionList , list4 , 4 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
numRegionList = map . get ( " dstList " ) ;
}
if ( list5 . size ( ) > 0 ) {
fileList . removeAll ( list5 ) ;
Map < String , List > map = cfgToMaatConvert ( digestRegionList , list5 , 5 , groupRelationList ) ;
groupRelationList = map . get ( " groupList " ) ;
digestRegionList = map . get ( " dstList " ) ;
}
2018-12-09 14:00:50 +08:00
return userRegion ;
2018-11-30 11:26:34 +08:00
}
2018-11-26 14:34:24 +08:00
}