修改一个编译下有多个分组时,未完全将分组取消的问题

This commit is contained in:
RenKaiGe-Office
2018-08-31 16:05:18 +08:00
parent 35d2f29a65
commit 4ec5282ebd

View File

@@ -1043,52 +1043,57 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
String compileStr = "COMPILEGROUP:" + id; String compileStr = "COMPILEGROUP:" + id;
// 获取当前编译配置与分组配置的关联关系 // 获取当前编译配置与分组配置的关联关系
String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系 String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系
String groupCompileStrs = getRegionInfo(compileStrVal);// 获取编译对应的分组信息,去除后面的redisdb信息 if (compileStrVal != null && !compileStrVal.trim().equals("")) {
if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) {// 遍历编译和分组的信息 String[] compileGroupStrArr = compileStrVal.split(";");
String[] split = groupCompileStrs.split(";"); for (String compileGroup : compileGroupStrArr) {
for (String groupId : split) {// GROUPCOMPILE:groupid-redisdb String groupCompileStrs = getRegionInfo(compileGroup);// 获取编译对应的分组信息,去除后面的redisdb信息
String groupCompileAndDBStrs = JedisUtils.get(groupId, idRelaRedisDBIndex); if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) {// 遍历编译和分组的信息
String[] compileGroupArr = groupCompileAndDBStrs.split(";");// 获取组对应的编译id String[] split = groupCompileStrs.split(";");
for (String groupAndCompileStr : compileGroupArr) { for (String groupId : split) {// GROUPCOMPILE:groupid-redisdb
String compileId = getRegionInfo(groupAndCompileStr); String groupCompileAndDBStrs = JedisUtils.get(groupId, idRelaRedisDBIndex);
if (compileId != null && !compileId.trim().equals("")) { String[] compileGroupArr = groupCompileAndDBStrs.split(";");// 获取组对应的编译id
// 被分组复用的业务,不能将域置为失效 for (String groupAndCompileStr : compileGroupArr) {
if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效 String compileId = getRegionInfo(groupAndCompileStr);
// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效 if (compileId != null && !compileId.trim().equals("")) {
if (compileId.equals(compileStr)) {// // 被分组复用的业务,不能将域置为失效
String groupRegionKey = groupId.replace("GROUPCOMPILE", "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效
String regionStr = getRegionInfo( // 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效
JedisUtils.get(groupRegionKey, idRelaRedisDBIndex)); if (compileId.equals(compileStr)) {//
if (regionStr != null && !regionStr.trim().equals("")) { String groupRegionKey = groupId.replace("GROUPCOMPILE", "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
String[] regionKeyArr = regionStr.split(";"); String regionStr = getRegionInfo(
if (regionKeyArr != null && regionKeyArr.length > 0) { JedisUtils.get(groupRegionKey, idRelaRedisDBIndex));
// 根据分组与域关联关系找到对应域配置然后删除(重命名) if (regionStr != null && !regionStr.trim().equals("")) {
removeRegionConfig(maatXmlConfig, regionKeyArr, maatVersion, service, String[] regionKeyArr = regionStr.split(";");
transaction, redisDBIndex); if (regionKeyArr != null && regionKeyArr.length > 0) {
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
removeRegionConfig(maatXmlConfig, regionKeyArr, maatVersion,
service, transaction, redisDBIndex);
}
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与域的关联关系key为"
+ groupRegionKey,
RestBusinessCode.KeyNotExistsInRedis.getValue());
}
} }
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与域的关联关系key为"
+ groupRegionKey,
RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
// 根据分组与编译关联关系找到对应分组配置然后删除(重命名)
removeCompileAndGroupConfig(maatXmlConfig, groupId.replace("GROUPCOMPILE:", ""), 11,
maatVersion, service, transaction, redisDBIndex, id + "");// 11代表是分组配置
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为" + groupId,
RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} }
// 根据分组与编译关联关系找到对应分组配置然后删除(重命名)
removeCompileAndGroupConfig(maatXmlConfig, groupId.replace("GROUPCOMPILE:", ""), 11,
maatVersion, service, transaction, redisDBIndex, id + "");// 11代表是分组配置
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为" + groupId,
RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系key为" + compileStr,
RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} }
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系key为" + compileStr,
RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} else { } else {
throw new ServiceRuntimeException( throw new ServiceRuntimeException(
@@ -1279,97 +1284,106 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
// String compileStr = redisDBIndex + ":COMPILEGROUP:" + compileId; // String compileStr = redisDBIndex + ":COMPILEGROUP:" + compileId;
String compileStr = "COMPILEGROUP:" + compileId; String compileStr = "COMPILEGROUP:" + compileId;
String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系 String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系
String groupCompileStr = getRegionInfo(compileStrVal); if (compileStrVal != null && !compileStrVal.trim().equals("")) {
// if (compileStrVal != null && compileStrVal.contains("-")) { String[] split1 = compileStrVal.split(";");
// String[] split = compileStrVal.split("-"); for (String str : split1) {
// groupCompileStr = split[0];// 去除后面的redisdb信息 String groupCompileStr = getRegionInfo(str);
// }
if (groupCompileStr != null && !groupCompileStr.equals("")) { // if (compileStrVal != null && compileStrVal.contains("-")) {
String[] groupCompileStrSplit = groupCompileStr.split(";");// 得到分组关系 // String[] split = compileStrVal.split("-");
for (String groupCompile : groupCompileStrSplit) {// 遍历所有分组关系 // groupCompileStr = split[0];// 去除后面的redisdb信息
String compileGroupStr = getRegionInfo( // }
JedisUtils.get(groupCompile.toUpperCase(), idRelaRedisDBIndex));// 获取当前分组关系对应的编译信息 if (groupCompileStr != null && !groupCompileStr.equals("")) {
if (compileGroupStr != null && !compileGroupStr.equals("")) { String[] groupCompileStrSplit = groupCompileStr.split(";");// 得到分组关系
String[] compileGroupStrSplit = compileGroupStr.split(";"); for (String groupCompile : groupCompileStrSplit) {// 遍历所有分组关系
// 被分组复用的业务,不能将域置为失效,其分组关系也不置为失效 String compileGroupStr = getRegionInfo(
if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效 JedisUtils.get(groupCompile.toUpperCase(), idRelaRedisDBIndex));// 获取当前分组关系对应的编译信息
// if (compileGroupStrSplit != null && compileGroupStrSplit.length if (compileGroupStr != null && !compileGroupStr.equals("")) {
// == 1 String[] compileGroupStrSplit = compileGroupStr.split(";");
// && compileGroupStr.equals(compileStr.toUpperCase())) {// // 被分组复用的业务,不能将域置为失效,其分组关系也不置为失效
// 当前的分组关系只属于当前的compileid,说明没有被分组复用,需要将编译配置,分组关系,域配置,置无 if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失
if (compileGroupStrSplit[0].toUpperCase().equals(compileStr.toUpperCase())) { // if (compileGroupStrSplit != null && compileGroupStrSplit.length
String groupRegion = groupCompile.replace("GROUPCOMPILE", "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION // == 1
// 删除分组与域的关联关系 // && compileGroupStr.equals(compileStr.toUpperCase())) {//
if (JedisUtils.exists(groupRegion, idRelaRedisDBIndex)) { // 当前的分组关系只属于当前的compileid,说明没有被分组复用,需要将编译配置,分组关系,域配置,置无效
transaction.del(groupRegion); if (compileGroupStrSplit[0].toUpperCase()
.equals(compileStr.toUpperCase())) {
String groupRegion = groupCompile.replace("GROUPCOMPILE",
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
// 删除分组与域的关联关系
if (JedisUtils.exists(groupRegion, idRelaRedisDBIndex)) {
transaction.del(groupRegion);
} else {
throw new ServiceRuntimeException("" + idRelaRedisDBIndex
+ "号redis库中无法获取MAAT配置分组与域的关联关系key为" + groupRegion,
RestBusinessCode.KeyNotExistsInRedis.getValue());
}
}
}
String groupCompileStrVal = JedisUtils.get(groupCompile.toUpperCase(),
idRelaRedisDBIndex);
// 删除分组与编译的关联关系
if (groupCompileStrVal != null && !groupCompileStrVal.trim().equals("")) {
StringBuffer sb = new StringBuffer();
String[] split = groupCompileStrVal.split(";");
for (String groupCompileAndDBStr : split) {
if (groupCompileAndDBStr.contains(compileStr.toUpperCase())
&& split.length == 1) {
transaction.del(groupCompile.toUpperCase());// 删除当前组所对应的编译
} else if (!groupCompileAndDBStr
.contains(compileStr.toUpperCase())) {
sb.append(groupCompileAndDBStr + ";");
}
}
if (sb.length() > 0) {
transaction.set(groupCompile.toUpperCase(),
sb.substring(0, sb.length() - 1));// 重新设置分组与编译
}
} else { } else {
throw new ServiceRuntimeException( throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与的关联关系key为" "" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为"
+ groupRegion, + groupCompile.toUpperCase(),
RestBusinessCode.KeyNotExistsInRedis.getValue()); RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为"
+ groupCompile.toUpperCase(),
RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} }
String groupCompileStrVal = JedisUtils.get(groupCompile.toUpperCase(), // String compileGroupStrVal = JedisUtils.get(compileStr.toUpperCase(),
idRelaRedisDBIndex); // idRelaRedisDBIndex);
// 删除分组与编译的关联关系 // if (compileGroupStrVal != null && !compileGroupStrVal.trim().equals("")) {
if (groupCompileStrVal != null && !groupCompileStrVal.trim().equals("")) { // StringBuffer sb = new StringBuffer();
StringBuffer sb = new StringBuffer(); // String[] split = compileGroupStrVal.split(";");
String[] split = groupCompileStrVal.split(";"); // for (String compileGroupAndDBStr : split) {
for (String groupCompileAndDBStr : split) { // if (compileGroupAndDBStr.contains(groupCompile.toUpperCase()) && split.length
if (groupCompileAndDBStr.contains(compileStr.toUpperCase()) // == 1) {
&& split.length == 1) { transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系
transaction.del(groupCompile.toUpperCase());// 删除当前组所对应的编译 // } else {
} else if (!groupCompileAndDBStr.contains(compileStr.toUpperCase())) { // sb.append(compileGroupAndDBStr + ";");
sb.append(groupCompileAndDBStr + ";"); // }
} // }
} // if (sb.length() > 0) {
if (sb.length() > 0) { // transaction.set(compileStr.toUpperCase(), sb.substring(0, sb.length() -
transaction.set(groupCompile.toUpperCase(), // 1));// 重新设置编译与分组的对应
sb.substring(0, sb.length() - 1));// 重新设置分组与编译 // }
} // }
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为"
+ groupCompile.toUpperCase(),
RestBusinessCode.KeyNotExistsInRedis.getValue());
}
} else { } else {
throw new ServiceRuntimeException( throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系key为" "" + idRelaRedisDBIndex + "号redis关联关系库中获取" + compileStr
+ groupCompile.toUpperCase(), + "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
RestBusinessCode.KeyNotExistsInRedis.getValue()); RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} }
// String compileGroupStrVal = JedisUtils.get(compileStr.toUpperCase(),
// idRelaRedisDBIndex);
// if (compileGroupStrVal != null && !compileGroupStrVal.trim().equals("")) {
// StringBuffer sb = new StringBuffer();
// String[] split = compileGroupStrVal.split(";");
// for (String compileGroupAndDBStr : split) {
// if (compileGroupAndDBStr.contains(groupCompile.toUpperCase()) && split.length
// == 1) {
transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系
// } else {
// sb.append(compileGroupAndDBStr + ";");
// }
// }
// if (sb.length() > 0) {
// transaction.set(compileStr.toUpperCase(), sb.substring(0, sb.length() -
// 1));// 重新设置编译与分组的对应
// }
// }
} else {
throw new ServiceRuntimeException(
"" + idRelaRedisDBIndex + "号redis关联关系库中获取" + compileStr
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
RestBusinessCode.KeyNotExistsInRedis.getValue());
} }
} }
} else { } else {