1:修改测试工具类,无法获取域配置中自定义域,业务类型,action等属性报错的问题

2:在添加和取消配置时,单独找一个库为实时统计存储编译配置信息,取消时也取消
This commit is contained in:
RenKaiGe-Office
2018-07-09 11:47:58 +08:00
parent b6f2e08840
commit 5e9966c3b3
5 changed files with 311 additions and 61 deletions

View File

@@ -59,6 +59,9 @@ public class MaatTestController {
String[] configArr = null;
if (configId.contains(",")) {
configArr = configId.split(",");
} else {
configArr = new String[1];
configArr[0] = configId;
}
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
for (String id : configArr) {
@@ -151,30 +154,31 @@ public class MaatTestController {
// + service + "&configId="
// + compileIdList.toString().replace("[", "").replace("]", "");
}
@RequestMapping(value = "/cfg/v1/testSaveMaat", method = RequestMethod.GET)
@ApiOperation(value = "测试批量保存maat配置", httpMethod = "GET", response = String.class, notes = "测试批量保存maat配置,service:需要保存的业务类型,saveCount:保存几条配置")
@ApiParam(value = "测试批量保存maat配置", name = "testSaveMaat", required = true)
public String testSaveMaat(@RequestParam(required = true) Integer service,
@RequestParam(required = true) Integer saveCount) {
long start = System.currentTimeMillis();
SaveRequestLogThread thread = new SaveRequestLogThread();
StringBuffer sb = new StringBuffer();
List<ConfigCompile> configCompileList = new ArrayList<ConfigCompile>();
for (int i = 0; i < saveCount; i++) {
configCompileList.add(getConfigCompile(service));
}
// 保存测试配置
configSourcesService.saveMaatConfig(thread, start, configCompileList, sb);
List<Long> compileIdList = new ArrayList<Long>();
for (ConfigCompile configCompile : configCompileList) {
compileIdList.add(configCompile.getCompileId());
}
FileUtils.addStrToFile(
sdf.format(new Date()) + "\t" + "业务类型" + service + "添加" + saveCount + "条数据成功,配置id是" + compileIdList
+ "\n" + sdf.format(new Date()) + "\t开始验证添加的数据各字段是否正确\n",
Configurations.getStringProperty("maatTestLogPath", ""), true);
// 验证数据是否在正确
maatTestServiceimpl.getKeys(configCompileList);
long start = System.currentTimeMillis();
SaveRequestLogThread thread = new SaveRequestLogThread();
StringBuffer sb = new StringBuffer();
List<ConfigCompile> configCompileList = new ArrayList<ConfigCompile>();
for (int i = 0; i < saveCount; i++) {
configCompileList.add(getConfigCompile(service));
}
// 保存测试配置
configSourcesService.saveMaatConfig(thread, start, configCompileList, sb);
List<Long> compileIdList = new ArrayList<Long>();
for (ConfigCompile configCompile : configCompileList) {
compileIdList.add(configCompile.getCompileId());
}
FileUtils.addStrToFile(
sdf.format(new Date()) + "\t" + "业务类型" + service + "添加" + saveCount + "条数据成功,配置id是" + compileIdList
+ "\n" + sdf.format(new Date()) + "\t开始验证添加的数据各字段是否正确\n",
Configurations.getStringProperty("maatTestLogPath", ""), true);
// 验证数据是否在正确
maatTestServiceimpl.getKeys(configCompileList);
return "http://127.0.0.1:8080/galaxy/service/cfg/v1/testDelMaat?serviceType=" + service + "&configId="
+ compileIdList.toString().replace("[", "").replace("]", "");
}

View File

@@ -67,8 +67,9 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
String maatTableName = ServiceAndRDBIndexReal
.getUnMaatTableName(service);
if (maatTableName == null) {
throw new RuntimeException("后台错误:未从业务类型和表对应关系中,找到非maat配置业务类型:"
+ service + "对应的真实表名");
throw new RuntimeException(
"后台错误:未从业务类型和表对应关系中,找到非maat配置业务类型:" + service
+ "对应的真实表名");
} else {
keyBF.append(maatTableName);
}
@@ -145,7 +146,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
} else {
throw new RuntimeException("后台错误:无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
throw new RuntimeException(
"后台错误:无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
}
}
BaseRedisDao.getIncr(redisDBIndex, "MAAT_VERSION");
@@ -282,6 +284,116 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
/**
* 单独找一个redis-db记录配置信息,方便实时统计程序获取所有配置的分类性质,标签等内容,(为什么实时统计不从配置库redisdb获取呢,
* 因为配置有多分发的情况,会发送到不同的redisdb,每个redisdb的配置条数不一定相同,有的配置所有的redisdb都有,有的只在某一个redisdb中有,实时统计程序不好获取配置这些配置内容,
* 最重要的是,前端机不需要这些属性,所以在配置库有可能不带分类性质,标签等属性,maat.xml如果配置了则有,没有配置则就没有这些属性.所以单独找一个reidsdb存放带分类性质,标签等属性的配置)
* @param configMap
*/
private void addStatisticsReal(Map<Integer, List<MaatConfig>> configMap) {
if (configMap != null && configMap.size() > 0) {
for (Integer redisDBIndex : configMap.keySet()) {
int redisStatisticsRealDBIndex = Configurations.getIntProperty("redisStatisticsRealDBIndex", 14);
if (redisStatisticsRealDBIndex >= 0
&& redisStatisticsRealDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 16)) {
List<MaatConfig> list = configMap.get(redisDBIndex);
if (list != null && list.size() > 0) {
RedisTemplate<String, String> redisTemplate = SpringContextHolder
.getBean("redisTemplate" + redisStatisticsRealDBIndex);
String redisStatisticsReal = Configurations.getStringProperty("redis-statisticsReal",
"[COMPILE_ID];\t;[SERVICE];\t;[ACTION];\t;[CONT_TYPE];\t;[ATTR_TYPE];\t;[CONT_LABEL];\t;[TASK_ID];\t;[AFFAIR_ID];\t;[DO_BLACKLIST];\t;[DO_LOG];\t;[EFFECTIVE_RANGE];\t;[START_TIME];\t;[END_TIME];\t;[USER_REGION];\t;[IS_VALID];\t;[GROUP_NUM];\t;[FATHER_CFG_ID];\t;[OP_TIME]");
String[] redisStatisticsRealArr = redisStatisticsReal.split(";");
String maatVersionStr = BaseRedisDao.getValByKey(redisStatisticsRealDBIndex, "MAAT_VERSION");
if (maatVersionStr == null) {
maatVersionStr = "0";
}
if (maatVersionStr != null) {
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
for (MaatConfig maatConfig : list) {
int service = maatConfig.getService();
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
Map<String, String> compileMap = maatConfig.getCompileMap();
for (MaatXmlExpr maatXmlExpr : maatXmlConfig.getExpressionList()) {
if (10 == maatXmlExpr.getType().intValue()) {
StringBuffer keyBF = new StringBuffer();
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
for (String keyStr : keySplit) {
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
keyStr = keyStr.trim().replace("[", "").replace("]", "");
String keyVal = compileMap.get(keyStr);
if (keyVal != null && !keyVal.equals("")) {
keyBF.append(keyVal);
} else {
throw new RuntimeException(
"后台错误:未从map中获取到" + keyStr + "的值,无法拼接redisKey,请检查数据是否正确");
}
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
keyStr = keyStr.trim().replace("{", "").replace("}", "");
if (keyStr.toLowerCase().contains("table_name")) {
String argTableName = compileMap.get("table_name");
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(
service, 10, argTableName == null ? null : argTableName);
if (maatTableName == null) {
throw new RuntimeException("后台错误:未从业务类型和表对应关系中,找到业务类型:"
+ service + ",配置类型:10,对应的真实表名");
} else {
keyBF.append(maatTableName);
}
}
} else {
keyBF.append(keyStr.trim());
}
}
StringBuffer valBF = new StringBuffer();
for (String valStr : redisStatisticsRealArr) {
if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) {
valStr = valStr.trim().replace("[", "").replace("]", "");
String val = compileMap.get(valStr.toLowerCase());
if (val != null) {
valBF.append(val);
} else {
// 编译配置或分组配置 所有在maat.xml中配置的属性都不可以为空
// if (!valStr.toLowerCase().equals("service")&&!
// valStr.toLowerCase().equals("action")
// &&!valStr.toLowerCase().equals("user_region") &&type==10) {
throw new RuntimeException(
"后台错误:未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据是否正确");
}
} else if (valStr.equals("\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
valBF.append("\t");
} else {
valBF.append(valStr.trim());
}
}
String maatKey = keyBF.toString();
redisTemplate.opsForValue().set(maatKey.toUpperCase(), valBF.toString());
String zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", redisDBIndex,
maatKey.toUpperCase(), valBF.toString());
break;
}
}
}
BaseRedisDao.getIncr(redisStatisticsRealDBIndex, "MAAT_VERSION");
}
} else {
throw new RuntimeException(
"后台错误:向" + redisStatisticsRealDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
}
} else {
throw new RuntimeException("后台错误:redis数据库编号:" + redisStatisticsRealDBIndex + "不正确,请检查数据库编号");
}
break;// configMap中所有的value都是相同的,在记录配置新增或者取消时只记录一次即可
}
}
}
/**
* 封装组id与域id对应关系并添加到对象中
* @param regionMapList
@@ -309,7 +421,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type,
argTableName == null ? null : argTableName);
if (maatTableName == null) {
throw new RuntimeException("后台错误:未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
throw new RuntimeException(
"后台错误:未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
} else {
keyBF.append(maatTableName);
}
@@ -367,7 +480,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
Integer.valueOf(maatVersionStr) + 1);
count++;
} else {
throw new RuntimeException("后台错误:向" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
throw new RuntimeException(
"后台错误:向" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
}
}
@@ -378,6 +492,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
if (count == configMap.size()) {
addMaatRelation(configMap);
addStatisticsReal(configMap);
return true;
}
} else {
@@ -404,7 +519,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
setCommonConfig(maatXmlConfig, compileMap, 10, maatVersion.doubleValue(), service, redisTemplate,
redisDBIndex, null);// 10代表是编译配置
} else {
throw new RuntimeException("后台错误:无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的编译配置信息,请检查配置参数是否正确");
throw new RuntimeException(
"后台错误:无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的编译配置信息,请检查配置参数是否正确");
}
List<Map<String, String>> groupMapList = maatConfig.getGroupMapList();
@@ -414,7 +530,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
compileId);// 11代表是分组配置
}
} else {
throw new RuntimeException("后台错误:无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的分组配置信息,请检查配置参数是否正确");
throw new RuntimeException(
"后台错误:无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的分组配置信息,请检查配置参数是否正确");
}
List<Map<String, String>> ipRegionMapList = maatConfig.getIpRegionMapList();
@@ -509,7 +626,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type,
argTableName == null ? null : argTableName);
if (maatTableName == null) {
throw new RuntimeException("后台错误:未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
throw new RuntimeException(
"后台错误:未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
} else {
keyBF.append(maatTableName);
}
@@ -534,13 +652,15 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|| valStr.toLowerCase().equals("user_region")) {// 域配置中只有这三个可以为空
// 删除前面的\t
} else {// 其他不可以为空
throw new RuntimeException("后台错误:未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据是否正确");
throw new RuntimeException(
"后台错误:未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据是否正确");
}
} else {// 编译配置或分组配置 所有在maat.xml中配置的属性都不可以为空
// if (!valStr.toLowerCase().equals("service")&&!
// valStr.toLowerCase().equals("action")
// &&!valStr.toLowerCase().equals("user_region") &&type==10) {
throw new RuntimeException("后台错误:未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据是否正确");
throw new RuntimeException(
"后台错误:未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据是否正确");
}
}
} else if (valStr.equals("&nbsp")) {
@@ -655,7 +775,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
String maatTableName = ServiceAndRDBIndexReal
.getUnMaatTableName(service);
if (maatTableName == null) {
throw new RuntimeException("后台错误:未从业务类型和表对应关系中,找到非maat配置业务类型:" + service
throw new RuntimeException(
"后台错误:未从业务类型和表对应关系中,找到非maat配置业务类型:" + service
+ "对应的真实表名");
} else {
keyBF.append(maatTableName);
@@ -676,8 +797,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
keyBF.toString().toUpperCase());
break;
} else {
throw new RuntimeException("后台错误:"+redisDBIndex + "号redis库中不存在key=" + oldKey
+ "请检查id映射关系是否正确");
throw new RuntimeException("后台错误:" + redisDBIndex
+ "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
}
}
}
@@ -726,7 +847,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
} else {
throw new RuntimeException("后台错误:无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
throw new RuntimeException(
"后台错误:无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
}
}
BaseRedisDao.getIncr(redisDBIndex, "MAAT_VERSION");
@@ -735,7 +857,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
Integer.valueOf(maatVersionStr) + 1);
count++;
} else {
throw new RuntimeException("后台错误:无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的配置id信息,请检查配置参数是否正确");
throw new RuntimeException("后台错误:无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service
+ "的配置id信息,请检查配置参数是否正确");
}
}
@@ -794,6 +917,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
if (count == idMap.size()) {
delMaatRelation(idMap);
delStatisticsReal(idMap);
return true;
}
} else {
@@ -840,7 +964,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisDBIndex);
}
} else {
throw new RuntimeException("后台错误:从" + idRelaRedisDBIndex + "号redis库中获取" + groupRegionKey
throw new RuntimeException(
"后台错误:从" + idRelaRedisDBIndex + "号redis库中获取" + groupRegionKey
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
}
@@ -893,7 +1018,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
if (keyStr.toLowerCase().contains("table_name")) {
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type, null);
if (maatTableName == null) {
throw new RuntimeException("后台错误:未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
throw new RuntimeException(
"后台错误:未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
} else {
keyBF.append(maatTableName);
}
@@ -914,7 +1040,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
maatKey.toUpperCase());
break;
} else {
throw new RuntimeException("后台错误:"+redisDBIndex + "号redis库中不存在key=" + oldKey
throw new RuntimeException("后台错误:" + redisDBIndex + "号redis库中不存在key=" + oldKey
+ "请检查id映射关系是否正确,或该配置已经被取消,已经被取消的配置不可再次取消,否则将抛出异常");
}
}
@@ -952,6 +1078,15 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
}
/**
* 删除域配置,重名key,记录相关信息MAAT_UPDATE_STATUS,MAAT_RULE_TIMER等
* @param maatXmlConfig
* @param regionArr
* @param maatVersion
* @param service
* @param redisTemplate
* @param redisDBIndex
*/
private void removeRegionConfig(MaatXmlConfig maatXmlConfig, String[] regionArr, Double maatVersion, int service,
RedisTemplate<String, String> redisTemplate, int redisDBIndex) {
if (maatXmlConfig != null && regionArr != null && regionArr.length > 0) {
@@ -964,7 +1099,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisTemplate.rename(oldKey, maatKey.toUpperCase());
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase());
} else {
throw new RuntimeException("后台错误:"+redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
throw new RuntimeException("后台错误:" + redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
}
for (MaatXmlExpr maatXmlExpr : expressionList) {
@@ -1001,6 +1136,75 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
}
/**
* 取消分类性质,标签等信息
*/
private void delStatisticsReal(Map<Integer, Map<Integer, List<Long>>> idMap) {
if (idMap != null && idMap.size() > 0) {
int redisStatisticsRealDBIndex = Configurations.getIntProperty("redisStatisticsRealDBIndex", 14);
RedisTemplate<String, String> redisTemplate = SpringContextHolder
.getBean("redisTemplate" + redisStatisticsRealDBIndex);
String maatVersionStr = BaseRedisDao.getValByKey(redisStatisticsRealDBIndex, "MAAT_VERSION");
if (maatVersionStr == null) {
throw new RuntimeException("后台错误:从" + redisStatisticsRealDBIndex
+ "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
}
double maatVersion = Double.valueOf(maatVersionStr) + 1D;
for (Integer redisDBIndex : idMap.keySet()) {
if (redisStatisticsRealDBIndex >= 0
&& redisStatisticsRealDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 16)) {
Map<Integer, List<Long>> map = idMap.get(redisDBIndex);
if (map != null && map.size() > 0) {
for (Integer service : map.keySet()) {
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, 10, null);
List<Long> idList = map.get(service);
if (idList != null && idList.size() > 0) {
for (Long compileId : idList) {
String effectiveRuleKey = "EFFECTIVE_RULE:" + maatTableName + "," + compileId;
if (BaseRedisDao.keyIsExist(redisStatisticsRealDBIndex,
effectiveRuleKey.toUpperCase())) {
redisTemplate.rename(effectiveRuleKey.toUpperCase(), effectiveRuleKey
.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE"));
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是:{}",
redisStatisticsRealDBIndex, effectiveRuleKey.toUpperCase(), effectiveRuleKey
.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE"));
String zset = effectiveRuleKey.replace("EFFECTIVE_RULE:", "DEL,");
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
redisStatisticsRealDBIndex, zset.toUpperCase(), maatVersion);
} else {
throw new RuntimeException("后台错误:从" + redisStatisticsRealDBIndex + "号redis库中判断"
+ effectiveRuleKey.toUpperCase()
+ "组和域关系时不存在,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
}
}
} else {
throw new RuntimeException("后台错误:删除配置时,配置id不能为空,请联系开发人员检查删除逻辑是否正确");
}
}
BaseRedisDao.getIncr(redisStatisticsRealDBIndex, "MAAT_VERSION");
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisStatisticsRealDBIndex,
Integer.valueOf(maatVersionStr) + 1);
} else {
throw new RuntimeException("后台错误:删除配置时,配置id不能为空,请联系开发人员检查删除逻辑是否正确");
}
} else {
throw new RuntimeException("后台错误:redis数据库编号:" + redisStatisticsRealDBIndex + "不正确,请检查数据库编号");
}
break;// 因为所有的value都是相同的所以只取消一次就可以了
}
}
}
/**
* 删除配置成功后,需要更新编译,组,域等配置id的对应关系
* @param idMap
@@ -1085,8 +1289,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
} else {
throw new RuntimeException("后台错误:从" + idRelaRedisDBIndex + "号redis库中获取" + compileStr
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
throw new RuntimeException("后台错误:从" + idRelaRedisDBIndex + "号redis库中获取"
+ compileStr + "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常");
}
}

View File

@@ -51,53 +51,54 @@ public class MaatTestServiceimpl {
if (maatXmlConfig != null && configCompile != null) {
Long compileId = configCompile.getCompileId();
validData(service, 10, compileId, configCompile.getCompileId(), redisDB, null, maatXmlConfig, redisTemplate,
configCompile);
configCompile,configCompile);
List<ConfigGroupRelation> groupRelationList = configCompile.getGroupRelationList();
for (ConfigGroupRelation configGroupRelation : groupRelationList) {
validData(service, 11, compileId, configGroupRelation.getGroupId(), redisDB, null, maatXmlConfig,
redisTemplate, configGroupRelation);
redisTemplate, configGroupRelation,configCompile);
}
List<IpRegion> ipRegionList = configCompile.getIpRegionList();
for (IpRegion ipRegion : ipRegionList) {
validData(service, 12, compileId, ipRegion.getRegionId(), redisDB, null, maatXmlConfig, redisTemplate,
ipRegion);
ipRegion,configCompile);
}
List<NumRegion> numRegionList = configCompile.getNumRegionList();
for (NumRegion numRegion : numRegionList) {
validData(service, 13, compileId, numRegion.getRegionId(), redisDB, null, maatXmlConfig, redisTemplate,
numRegion);
numRegion,configCompile);
}
List<StrRegion> strRegionList = configCompile.getStrRegionList();
for (StrRegion strRegion : strRegionList) {
if (strRegion.getDistrict() == null || strRegion.getDistrict().trim().equals("")) {
validData(service, 14, compileId, strRegion.getRegionId(), redisDB, null, maatXmlConfig,
redisTemplate, strRegion);
redisTemplate, strRegion,configCompile);
} else {
validData(service, 15, compileId, strRegion.getRegionId(), redisDB, null, maatXmlConfig,
redisTemplate, strRegion);
redisTemplate, strRegion,configCompile);
}
}
List<DigestRegion> digestRegionList = configCompile.getDigestRegionList();
for (DigestRegion digestRegion : digestRegionList) {
validData(service, 16, compileId, digestRegion.getRegionId(), redisDB, null, maatXmlConfig,
redisTemplate, digestRegion);
redisTemplate, digestRegion,configCompile);
}
List<IpRegion> ipClientRangeList = configCompile.getIpClientRangeList();
for (IpRegion ipRegion : ipClientRangeList) {
validData(service, 18, compileId, ipRegion.getRegionId(), redisDB, null, maatXmlConfig, redisTemplate,
ipRegion);
ipRegion,configCompile);
}
}
}
public void validData(Integer service, Integer type, Long compileId, Long id, Integer redisDb, String tableName,
MaatXmlConfig maatXmlConfig, RedisTemplate<String, String> redisTemplate, Object obj) {
MaatXmlConfig maatXmlConfig, RedisTemplate<String, String> redisTemplate, Object obj,
ConfigCompile configCompile) {
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
String[] valArr = null;
String key = null;
@@ -145,26 +146,33 @@ public class MaatTestServiceimpl {
break;
}
}
if (sysoLog(valArr, valList, obj, redisDb, key)) {
if (sysoLog(valArr, valList, obj, redisDb, key, configCompile)) {
FileUtils
.addStrToFile("\t" +
sdf.format(new Date()) + " 编译配置id为" + compileId + "的配置中,在" + redisDb
+ "号redis库中key=" + key + "的值与实际插入的值相符\n",
.addStrToFile(
"\t" + sdf.format(new Date()) + " 编译配置id为" + compileId + "的配置中,在" + redisDb + "号redis库中key="
+ key + "的值与实际插入的值相符\n",
Configurations.getStringProperty("maatTestLogPath", ""), true);
}
}
private boolean sysoLog(String[] valArr, List<String> valList, Object obj, Integer redisDb, String key) {
private boolean sysoLog(String[] valArr, List<String> valList, Object obj, Integer redisDb, String key,
ConfigCompile configCompile) {
boolean bool = true;
for (int i = 0; i < valList.size(); i++) {
String attrName = valList.get(i);
if (!attrName.toLowerCase().equals("op_time")) {
String filedName = CamelUnderlineUtil.underlineToCamel(attrName);
String beanVal = getFieldValueByFieldName(filedName, obj);
String beanVal = null;
if (filedName.toLowerCase().equals("service") || filedName.toLowerCase().equals("action")
|| filedName.toLowerCase().equals("userregion")) {
beanVal=getFieldValueByFieldName(filedName, configCompile);
}else {
beanVal=getFieldValueByFieldName(filedName, obj);
}
String redisVal = valArr[i];
if (!beanVal.trim().equals(redisVal.trim())) {
FileUtils.addStrToFile("\t" +
sdf.format(new Date()) + " error:" + redisDb + "号redis库中key=" + key + "的值第" + i + ""
FileUtils.addStrToFile(
"\t" + sdf.format(new Date()) + " error:" + redisDb + "号redis库中key=" + key + "的值第" + i + ""
+ attrName + "的值:" + redisVal + "与实际传的值不一样,实际值是:{}\n",
Configurations.getStringProperty("maatTestLogPath", ""), true);
bool = false;

View File

@@ -77,6 +77,12 @@
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="10" />
<bean id="connectionFactory14"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="14" />
<bean id="connectionFactory15"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
@@ -84,7 +90,6 @@
<bean id="stringRedisSerializer"
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
@@ -205,6 +210,16 @@
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate14" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory14" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
<!-- 设置开启事务 -->
<property name="enableTransactionSupport" value="true" />
</bean>
<bean id="redisTemplate15" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory15" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
@@ -278,6 +293,12 @@
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="15" />
<bean id="conn14"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
p:database="14" />
<bean id="redisTemplateNoTrans0" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn0" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
@@ -402,8 +423,17 @@
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
<bean id="redisTemplateNoTrans14" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="conn14" />
<!-- 设置key和value的序列化方式,默认使用的是JdkSerializationRedisSerializer,key会被序列化为\xac\xed\x00\x056\x00 -->
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="stringRedisSerializer" />
</bean>
@@ -413,6 +443,4 @@
</beans>

View File

@@ -242,8 +242,14 @@ digest.gen.tool.path=maat-redis/digest_gen
#redis中有多少个数据库(需要加1,代码中用的小于不是小于等于)
maxRedisDBIndex=12
maxRedisDBIndex=16
##存放编译,分组,域配置id关系的redis数据库编号
idRelaRedisDBIndex=15
redisStatisticsReal=[COMPILE_ID];\t;[SERVICE];\t;[ACTION];\t;[CONT_TYPE];\t;[ATTR_TYPE];\t;[CONT_LABEL];\t;[TASK_ID];\t;[AFFAIR_ID];\t;[DO_BLACKLIST];\t;[DO_LOG];\t;[EFFECTIVE_RANGE];\t;[START_TIME];\t;[END_TIME];\t;[USER_REGION];\t;[IS_VALID];\t;[GROUP_NUM];\t;[FATHER_CFG_ID];\t;[OP_TIME]
redisStatisticsRealDBIndex=14
#maat测试程序输出日志的文件目录
maatTestLogPath=c:/maat/mmat.log