修改非maat配置时支持将配置从失效再次置为有效的状态

This commit is contained in:
RenKaiGe-Office
2018-07-17 17:25:11 +08:00
parent 30aaee1e1d
commit bb5fda045e
3 changed files with 39 additions and 17 deletions

View File

@@ -126,7 +126,7 @@ public class ConfigSourcesController extends BaseRestController {
map.put(service, arrayList); map.put(service, arrayList);
Map<Integer, Map<Integer, List<Long>>> idMap = new HashMap<Integer, Map<Integer, List<Long>>>(); Map<Integer, Map<Integer, List<Long>>> idMap = new HashMap<Integer, Map<Integer, List<Long>>>();
idMap.put(redisDB, map); idMap.put(redisDB, map);
configRedisService.delUnMaatConfig(idMap); configRedisService.delUnMaatConfig(idMap,true);
// configRedisService.saveMaatConfig(listMap, service); // configRedisService.saveMaatConfig(listMap, service);
// new ConfigRedisServiceimpl().GETMaatConfig(listMap); // new ConfigRedisServiceimpl().GETMaatConfig(listMap);
return "ok"; return "ok";

View File

@@ -166,12 +166,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.discard(); transaction.discard();
} }
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
//transaction.discard(); // transaction.discard();
logger.error("后台错误:连接redis异常,保存非maat类配置失败,{}",e.getMessage()); logger.error("后台错误:连接redis异常,保存非maat类配置失败,{}", e.getMessage());
throw new RuntimeException("后台错误:连接redis异常,保存非maat类配置失败", e); throw new RuntimeException("后台错误:连接redis异常,保存非maat类配置失败", e);
} catch (Exception e) { } catch (Exception e) {
transaction.discard(); transaction.discard();
logger.error("后台错误:保存非maat类配置发生了异常,{}",e.getMessage()); logger.error("后台错误:保存非maat类配置发生了异常,{}", e.getMessage());
throw new RuntimeException("后台错误:保存非maat类配置发生了异常", e); throw new RuntimeException("后台错误:保存非maat类配置发生了异常", e);
} finally { } finally {
// 释放连接到连接池 // 释放连接到连接池
@@ -510,7 +510,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.exec(); transaction.exec();
} }
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
//transaction.discard(); // transaction.discard();
throw new RuntimeException("后台错误:连接redis异常,保存maat类配置失败", e); throw new RuntimeException("后台错误:连接redis异常,保存maat类配置失败", e);
} catch (Exception e) { } catch (Exception e) {
transaction.discard(); transaction.discard();
@@ -744,7 +744,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
} }
@Override @Override
public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap) { public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap, boolean isInvalid) {
if (idMap != null && idMap.size() > 0) { if (idMap != null && idMap.size() > 0) {
int count = 0; int count = 0;
Jedis resource = JedisUtils.getResource(0); Jedis resource = JedisUtils.getResource(0);
@@ -777,7 +777,14 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
for (String keyStr : keySplit) { for (String keyStr : keySplit) {
if (!StringUtils.isEmpty(keyStr) if (!StringUtils.isEmpty(keyStr)
&& keyStr.toUpperCase().equals("EFFECTIVE_RULE")) { && keyStr.toUpperCase().equals("EFFECTIVE_RULE")) {
if(isInvalid) {
keyStr = "OBSOLETE_RULE"; keyStr = "OBSOLETE_RULE";
}else {
keyStr = "EFFECTIVE_RULE";
}
keyBF.append(keyStr.trim()); keyBF.append(keyStr.trim());
} else if (!StringUtils.isEmpty(keyStr) } else if (!StringUtils.isEmpty(keyStr)
&& keyStr.trim().startsWith("[")) { && keyStr.trim().startsWith("[")) {
@@ -801,15 +808,22 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
keyBF.append(keyStr.trim()); keyBF.append(keyStr.trim());
} }
} }
String oldKey = null;
maatKey = keyBF.toString(); maatKey = keyBF.toString();
String oldKey = maatKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"); if (isInvalid) {
oldKey = maatKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE");
} else {
oldKey = maatKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
}
if (JedisUtils.exists(oldKey.toString().toUpperCase(), if (JedisUtils.exists(oldKey.toString().toUpperCase(),
redisDBIndex)) { redisDBIndex)) {
transaction.rename(oldKey.toString().toUpperCase(), transaction.rename(oldKey.toString().toUpperCase(),
keyBF.toString().toUpperCase()); maatKey.toString().toUpperCase());
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}",
redisDBIndex, oldKey.toString().toUpperCase(), redisDBIndex, oldKey.toString().toUpperCase(),
keyBF.toString().toUpperCase()); maatKey.toString().toUpperCase());
break; break;
} else { } else {
throw new RuntimeException("后台错误:" + redisDBIndex throw new RuntimeException("后台错误:" + redisDBIndex
@@ -821,10 +835,17 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
if (maatXmlExpr.getKeyExpression().toUpperCase() if (maatXmlExpr.getKeyExpression().toUpperCase()
.equals("MAAT_UPDATE_STATUS")) { .equals("MAAT_UPDATE_STATUS")) {
if (maatKey != null) { if (maatKey != null) {
if (isInvalid) {
String zset = maatKey.replace("OBSOLETE_RULE:", "DEL,"); String zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset); transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset);
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}", logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
redisDBIndex, zset.toUpperCase(), maatVersion); redisDBIndex, zset.toUpperCase(), maatVersion);
}else {
String zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset);
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
redisDBIndex, zset.toUpperCase(), maatVersion);
}
} }
} else if (maatXmlExpr.getKeyExpression().toUpperCase() } else if (maatXmlExpr.getKeyExpression().toUpperCase()
.equals("MAAT_RULE_TIMER")) { .equals("MAAT_RULE_TIMER")) {
@@ -887,7 +908,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
transaction.discard(); transaction.discard();
} }
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
//transaction.discard(); // transaction.discard();
throw new RuntimeException("后台错误:连接redis异常,删除非maat类配置失败", e); throw new RuntimeException("后台错误:连接redis异常,删除非maat类配置失败", e);
} catch (Exception e) { } catch (Exception e) {
transaction.discard(); transaction.discard();
@@ -946,7 +967,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
} }
} catch (JedisConnectionException e) { } catch (JedisConnectionException e) {
//transaction.discard(); // transaction.discard();
throw new RuntimeException("后台错误:连接redis异常,删除maat类配置失败", e); throw new RuntimeException("后台错误:连接redis异常,删除maat类配置失败", e);
} catch (Exception e) { } catch (Exception e) {
transaction.discard(); transaction.discard();

View File

@@ -44,9 +44,10 @@ public interface ConfigRedisService {
/** /**
* 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合 * 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合
* @param idMap * @param idMap
* @param isInvalid 是否将配置置为无效
* @return 成功返回true,失败返回false或抛出异常 * @return 成功返回true,失败返回false或抛出异常
*/ */
public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap); public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap,boolean isInvalid);
/** /**
* 删除maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合 * 删除maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合