1:将maat类配置取消接口和停启用接口合并为一个接口
2:修改新增maat类配置接口,支持某些组标记为公共组,业务判断是公共组下发到所有的redisdb 3:修改取消或生效配置接口支持对配置停启用,并保留某些不需要删除的组
This commit is contained in:
@@ -575,7 +575,6 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (type == maatXmlExpr.getType().intValue()) {
|
||||
StringBuffer keyBF = new StringBuffer();
|
||||
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||
String groupId = null;
|
||||
for (String keyStr : keySplit) {
|
||||
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||
keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||
@@ -588,7 +587,6 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
if (type == 11 && keyStr.toLowerCase().equals("group_id")) {
|
||||
keyBF.append(compileId);
|
||||
groupId = keyVal;
|
||||
}
|
||||
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
@@ -969,11 +967,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
list.add(i);
|
||||
}
|
||||
serviceConfigMap.put(129, list);
|
||||
delMaatConfig(serviceConfigMap, false, null);
|
||||
updateMaatStatus(serviceConfigMap, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delMaatConfig(Map<Integer, List<Long>> serviceConfigMap, boolean isStart,
|
||||
public boolean updateMaatStatus(Map<Integer, List<Long>> serviceConfigMap, boolean isStart,
|
||||
Map<Long, List<Long>> compileGroupMap) {
|
||||
if (serviceConfigMap != null && serviceConfigMap.size() > 0) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
@@ -1122,51 +1120,49 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) {
|
||||
String compileId = getRegionInfo(groupAndCompileStr);// COMPILEGROUP:24070
|
||||
if (compileId != null && !compileId.trim().equals("")) {
|
||||
if (keepGroupId != null && keepGroupId.size() > 0
|
||||
&& keepGroupId.contains(Long.parseLong(groupIdReal))) {// 包含保留的group,则不将域置为失效,否则将域置为失效,否
|
||||
if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效
|
||||
// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效
|
||||
if (compileId.equals(compileStr)) {//
|
||||
String groupRegionKey = groupId.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
String regionStrs = null;
|
||||
if (!keyMap.containsKey(groupRegionKey)) {
|
||||
regionStrs = JedisUtils.get(groupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
keyMap.put(groupRegionKey, regionStrs);
|
||||
} else {
|
||||
regionStrs = keyMap.get(groupRegionKey);
|
||||
}
|
||||
if (regionStrs != null && !regionStrs.trim().equals("")) {
|
||||
String[] regionStrArr = regionStrs.split(";");
|
||||
for (String str : regionStrArr) {
|
||||
if (str != null && !str.trim().equals("")) {
|
||||
if (isStart || (keepGroupId != null && keepGroupId.size() > 0
|
||||
&& !keepGroupId.contains(Long.parseLong(groupIdReal)))) {// 如果是修改为生效则置为生效,如果是失效如果包含保留的group,则不将域置为失效,否则将域置为失效,否
|
||||
// if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效
|
||||
// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效
|
||||
if (compileId.equals(compileStr)) {//
|
||||
String groupRegionKey = groupId.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
String regionStrs = null;
|
||||
if (!keyMap.containsKey(groupRegionKey)) {
|
||||
regionStrs = JedisUtils.get(groupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
keyMap.put(groupRegionKey, regionStrs);
|
||||
} else {
|
||||
regionStrs = keyMap.get(groupRegionKey);
|
||||
}
|
||||
if (regionStrs != null && !regionStrs.trim().equals("")) {
|
||||
String[] regionStrArr = regionStrs.split(";");
|
||||
for (String str : regionStrArr) {
|
||||
if (str != null && !str.trim().equals("")) {
|
||||
|
||||
String regionStr = getRegionInfo(str);
|
||||
if (regionStr != null
|
||||
&& !regionStr.trim().equals("")) {
|
||||
String[] regionKeyArr = regionStr
|
||||
.split(";");
|
||||
if (regionKeyArr != null
|
||||
&& regionKeyArr.length > 0) {
|
||||
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
|
||||
removeRegionConfig(maatXmlConfig,
|
||||
regionKeyArr, maatVersion,
|
||||
service, transaction,
|
||||
redisDBIndex, isStart);
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与域的关联关系,key为"
|
||||
+ groupRegionKey,
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
String regionStr = getRegionInfo(str);
|
||||
if (regionStr != null
|
||||
&& !regionStr.trim().equals("")) {
|
||||
String[] regionKeyArr = regionStr.split(";");
|
||||
if (regionKeyArr != null
|
||||
&& regionKeyArr.length > 0) {
|
||||
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
|
||||
removeRegionConfig(maatXmlConfig,
|
||||
regionKeyArr, maatVersion, service,
|
||||
transaction, redisDBIndex, isStart);
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与域的关联关系,key为"
|
||||
+ groupRegionKey,
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
// 根据分组与编译关联关系找到对应分组配置然后删除(重命名)
|
||||
@@ -1286,6 +1282,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
*/
|
||||
private void removeRegionConfig(MaatXmlConfig maatXmlConfig, String[] regionArr, Double maatVersion, int service,
|
||||
Transaction transaction, int redisDBIndex, Boolean isStart) {
|
||||
|
||||
transaction.select(redisDBIndex);
|
||||
if (maatXmlConfig != null && regionArr != null && regionArr.length > 0) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
@@ -1428,36 +1425,55 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
String[] compileGroupStrSplit = org.apache.commons.lang.StringUtils
|
||||
.split(compileGroupStr, ";");
|
||||
// 被分组复用的业务,不能将域置为失效,其分组关系也不置为失效
|
||||
if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效
|
||||
// if (compileGroupStrSplit != null &&
|
||||
// compileGroupStrSplit.length
|
||||
// == 1
|
||||
// && compileGroupStr.equals(compileStr.toUpperCase())) {//
|
||||
// 当前的分组关系只属于当前的compileid,说明没有被分组复用,需要将编译配置,分组关系,域配置,置无效
|
||||
// if (compileGroupStrSplit != null
|
||||
// && compileGroupStrSplit.length > 0
|
||||
// && compileGroupStrSplit[0] != null
|
||||
// && !compileGroupStrSplit[0].trim().equals("")
|
||||
// && compileGroupStrSplit[0].toUpperCase()
|
||||
// .equals(compileStr.toUpperCase())) {
|
||||
if (compileGroupStrSplit[0].toUpperCase()
|
||||
.equals(compileStr.toUpperCase())) {
|
||||
String groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
|
||||
String groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
// if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效
|
||||
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除分组与域的关联关系
|
||||
if (isStart) {// 将失效置为生效
|
||||
if (compileGroupStrSplit[0].toUpperCase()
|
||||
.equals(compileStr.toUpperCase())) {
|
||||
String groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
|
||||
String groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除分组与域的关联关系
|
||||
if (isStart) {// 将失效置为生效
|
||||
groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE",
|
||||
"EFFECTIVE_RULE");
|
||||
String[] split = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split.length > 1) {
|
||||
Set<String> set = new HashSet<>();
|
||||
for (String regionKeyStr : split) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim().equals("")) {
|
||||
set.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key
|
||||
} else {
|
||||
transaction.set(groupRegion.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
} else {// 将生效变为失效
|
||||
long groupId = Long.parseLong(
|
||||
groupRegion.replace("GROUPREGION:", ""));
|
||||
|
||||
if (!keepGroupIdList.contains(groupId)) {
|
||||
groupRegionVal = groupRegionVal
|
||||
.replace("OBSOLETE_RULE", "EFFECTIVE_RULE");
|
||||
.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
String[] split = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split.length > 1) {
|
||||
Set<String> set = new HashSet<>();
|
||||
|
||||
for (String regionKeyStr : split) {
|
||||
if (regionKeyStr != null && !regionKeyStr
|
||||
.trim().equals("")) {
|
||||
@@ -1470,54 +1486,23 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key
|
||||
|
||||
} else {
|
||||
transaction.set(groupRegion.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
} else {// 将生效变为失效
|
||||
long groupId = Long.parseLong(
|
||||
groupRegion.replace("GROUPREGION:", ""));
|
||||
|
||||
if (!keepGroupIdList.contains(groupId)) {
|
||||
groupRegionVal = groupRegionVal.replace(
|
||||
"EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
String[] split = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split.length > 1) {
|
||||
Set<String> set = new HashSet<>();
|
||||
|
||||
for (String regionKeyStr : split) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim()
|
||||
.equals("")) {
|
||||
set.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key
|
||||
|
||||
} else {
|
||||
transaction.set(groupRegion.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex + "号redis库中删除"
|
||||
+ groupRegion
|
||||
+ "失败,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从" + idRelaRedisDBIndex
|
||||
+ "号redis库中删除" + groupRegion
|
||||
+ "失败,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
String groupCompileStrVal = JedisUtils
|
||||
.get(groupCompile.toUpperCase(), idRelaRedisDBIndex);
|
||||
|
||||
@@ -75,14 +75,14 @@ public interface ConfigRedisService {
|
||||
public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap, boolean isInvalid);
|
||||
|
||||
/**
|
||||
* 删除maat类配置,key是业务类型,value是配置id集合,并保存某些不需要删除的group(其实是保存region),方便下次下发配置时可以直接使用这些region
|
||||
* 修改maat类配置状态(生效或失效),在删除时可以指定某些group不删除(其实是不删除region,但是删除group和compile),方便下次下发配置时可以直接使用这些region
|
||||
*
|
||||
* @param serviceConfigMap
|
||||
* @param serviceConfigMap key是业务类型,value是配置id集合
|
||||
* @param isStart 是否置为生效,
|
||||
* @param compileGroupMap 在将配置置为失效时,需要保留的groupid,key是compileid,value是groupid集合
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
public boolean delMaatConfig(Map<Integer, List<Long>> serviceConfigMap, boolean isStart,
|
||||
public boolean updateMaatStatus(Map<Integer, List<Long>> serviceConfigMap, boolean isStart,
|
||||
Map<Long, List<Long>> compileGroupMap);
|
||||
|
||||
/**
|
||||
|
||||
@@ -258,7 +258,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
}
|
||||
logger.info("---------------调用Redis maat配置新增接口---------------------");
|
||||
configRedisService.saveMaatConfig(configMap,new ArrayList<>(commonGroupIdSet));
|
||||
configRedisService.saveMaatConfig(configMap, new ArrayList<>(commonGroupIdSet));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,12 +340,23 @@ public class ConfigSourcesService extends BaseService {
|
||||
return dstMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对界面传过来的修改maat类配置状态数据格式进行校验,并转化数据格式传到下一层
|
||||
*
|
||||
* @param thread
|
||||
* @param start
|
||||
* @param compileList
|
||||
* @param opTime
|
||||
* @param sb
|
||||
* @throws Exception
|
||||
*/
|
||||
public void updateConfigSources(AuditLogThread thread, long start, List<ConfigCompile> compileList, Date opTime,
|
||||
StringBuffer sb) throws Exception {
|
||||
// 所有状态更新的配置isValid的值必须相同
|
||||
Map<String, String> validIdMap = new HashMap<String, String>();
|
||||
// 在将配置置为失效时,记录需要保留的groupid(哪些组及组下的域不用置为失效)
|
||||
Map<Long, List<Long>> compileGroupMap = new HashMap<Long, List<Long>>();
|
||||
//需要置失效的配置,key是业务类型,value是配置id集合
|
||||
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
|
||||
if (null != compileList && compileList.size() > 0) {
|
||||
for (ConfigCompile config : compileList) {
|
||||
@@ -386,25 +397,15 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException(RestBusinessCode.IsValidNonUniq.getErrorReason(),
|
||||
RestBusinessCode.IsValidNonUniq.getValue());
|
||||
}
|
||||
|
||||
// if (!isConfigStartStop) {
|
||||
// 所有的都删除成功返回true
|
||||
// if (!configRedisService.delMaatConfig(compileMap,false)) {
|
||||
// throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员",
|
||||
// RestBusinessCode.service_runtime_error.getValue());
|
||||
// }
|
||||
// } else {
|
||||
boolean isStart = true;// 置为生效
|
||||
Integer isValid = compileList.get(0).getIsValid();
|
||||
if (isValid == 0) {
|
||||
isStart = false;// 置为失效
|
||||
}
|
||||
if (!configRedisService.delMaatConfig(compileMap, isStart, compileGroupMap)) {
|
||||
if (!configRedisService.updateMaatStatus(compileMap, isStart, compileGroupMap)) {
|
||||
throw new ServiceRuntimeException("停启用,或取消MAAT配置时出现异常,具体原因不详,请联系管理员",
|
||||
RestBusinessCode.service_runtime_error.getValue());
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
private String convertToTimeStamp16(Date date) {
|
||||
|
||||
Reference in New Issue
Block a user