Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java
This commit is contained in:
@@ -24,6 +24,7 @@ import com.nis.util.ServiceAndRDBIndexReal;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
@Service()
|
||||
public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
@@ -164,8 +165,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
} else {
|
||||
transaction.discard();
|
||||
}
|
||||
} catch (JedisConnectionException e) {
|
||||
// transaction.discard();
|
||||
logger.error("后台错误:连接redis异常,保存非maat类配置失败,{}", e.getMessage());
|
||||
throw new RuntimeException("后台错误:连接redis异常,保存非maat类配置失败", e);
|
||||
} catch (Exception e) {
|
||||
transaction.discard();
|
||||
logger.error("后台错误:保存非maat类配置发生了异常,{}", e.getMessage());
|
||||
throw new RuntimeException("后台错误:保存非maat类配置发生了异常", e);
|
||||
} finally {
|
||||
// 释放连接到连接池
|
||||
@@ -500,9 +506,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
addStatisticsReal(configMap, transaction);
|
||||
transaction.exec();
|
||||
return true;
|
||||
}else {
|
||||
} else {
|
||||
transaction.exec();
|
||||
}
|
||||
} catch (JedisConnectionException e) {
|
||||
// transaction.discard();
|
||||
throw new RuntimeException("后台错误:连接redis异常,保存maat类配置失败", e);
|
||||
} catch (Exception e) {
|
||||
transaction.discard();
|
||||
throw new RuntimeException("后台错误:保存maat类配置发生了异常", e);
|
||||
@@ -735,7 +744,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
@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) {
|
||||
int count = 0;
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
@@ -768,7 +777,14 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
for (String keyStr : keySplit) {
|
||||
if (!StringUtils.isEmpty(keyStr)
|
||||
&& keyStr.toUpperCase().equals("EFFECTIVE_RULE")) {
|
||||
keyStr = "OBSOLETE_RULE";
|
||||
|
||||
if(isInvalid) {
|
||||
keyStr = "OBSOLETE_RULE";
|
||||
}else {
|
||||
keyStr = "EFFECTIVE_RULE";
|
||||
}
|
||||
|
||||
|
||||
keyBF.append(keyStr.trim());
|
||||
} else if (!StringUtils.isEmpty(keyStr)
|
||||
&& keyStr.trim().startsWith("[")) {
|
||||
@@ -792,15 +808,22 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
String oldKey = null;
|
||||
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(),
|
||||
redisDBIndex)) {
|
||||
transaction.rename(oldKey.toString().toUpperCase(),
|
||||
keyBF.toString().toUpperCase());
|
||||
maatKey.toString().toUpperCase());
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}",
|
||||
redisDBIndex, oldKey.toString().toUpperCase(),
|
||||
keyBF.toString().toUpperCase());
|
||||
maatKey.toString().toUpperCase());
|
||||
break;
|
||||
} else {
|
||||
throw new RuntimeException("后台错误:" + redisDBIndex
|
||||
@@ -812,10 +835,17 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (maatXmlExpr.getKeyExpression().toUpperCase()
|
||||
.equals("MAAT_UPDATE_STATUS")) {
|
||||
if (maatKey != null) {
|
||||
String zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||
transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset);
|
||||
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
|
||||
redisDBIndex, zset.toUpperCase(), maatVersion);
|
||||
if (isInvalid) {
|
||||
String zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||
transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset);
|
||||
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
|
||||
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()
|
||||
.equals("MAAT_RULE_TIMER")) {
|
||||
@@ -877,6 +907,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
} else {
|
||||
transaction.discard();
|
||||
}
|
||||
} catch (JedisConnectionException e) {
|
||||
// transaction.discard();
|
||||
throw new RuntimeException("后台错误:连接redis异常,删除非maat类配置失败", e);
|
||||
} catch (Exception e) {
|
||||
transaction.discard();
|
||||
throw new RuntimeException("后台错误:删除非maat类配置发生了异常", e);
|
||||
@@ -933,6 +966,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
transaction.discard();
|
||||
}
|
||||
|
||||
} catch (JedisConnectionException e) {
|
||||
// transaction.discard();
|
||||
throw new RuntimeException("后台错误:连接redis异常,删除maat类配置失败", e);
|
||||
} catch (Exception e) {
|
||||
transaction.discard();
|
||||
throw new RuntimeException("后台错误:删除maat类配置发生了异常", e);
|
||||
|
||||
@@ -44,9 +44,10 @@ public interface ConfigRedisService {
|
||||
/**
|
||||
* 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合
|
||||
* @param idMap
|
||||
* @param isInvalid 是否将配置置为无效
|
||||
* @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集合
|
||||
|
||||
@@ -3024,6 +3024,21 @@ public class ConfigSourcesService extends BaseService {
|
||||
dstStr.substring(1, dstStr.length() - 1))
|
||||
.toString();
|
||||
}
|
||||
|
||||
if("dstFile".equals(commonSourceFieldCfg
|
||||
.getSrcName())){
|
||||
if ("dst_file".equals(commonSourceFieldCfg
|
||||
.getDstName())) {
|
||||
String maatTableName = ServiceAndRDBIndexReal
|
||||
.getUnMaatTableName(Integer.valueOf(srcMap.get("service")
|
||||
.toString().trim()));
|
||||
String dstPath = Constants.MM_SAMPLE_DST_PATH.replace("{tableType}", maatTableName.substring(maatTableName.lastIndexOf("_")+1));
|
||||
dstPath=dstPath.replace("{fileName}", dstStr.substring(dstStr.lastIndexOf("/")+1));
|
||||
}else if ("file_id".equals(commonSourceFieldCfg
|
||||
.getDstName())) {
|
||||
dstStr= dstStr.substring(dstStr.indexOf("/group"));
|
||||
}
|
||||
}
|
||||
switch (commonSourceFieldCfg.getFieldType()) {
|
||||
case "Number":
|
||||
if (!StringUtil.isNumeric(dstStr)) {
|
||||
@@ -3238,6 +3253,8 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
// <service,cfgIdList>
|
||||
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();
|
||||
//所有状态更新的配置isValid的值必须相同
|
||||
Map<String, String> validIdMap = new HashMap<String, String>();
|
||||
for (int i = 0; i < jsonObjectList.size(); i++) {
|
||||
JsonObject jsonObj = (JsonObject) jsonObjectList.get(i);
|
||||
Map<String, Object> srcMap = JSONObject.fromObject(JSONObject
|
||||
@@ -3250,6 +3267,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
msg + sb.toString(),
|
||||
CompileVal.getBusinessCode());
|
||||
}
|
||||
validIdMap.put(srcMap.get("isValid").toString(), srcMap.get("isValid").toString());
|
||||
Integer service = Integer.valueOf(srcMap.get("service").toString());
|
||||
Long cfgId = Long.valueOf(srcMap.get("cfgId").toString());
|
||||
if (cfgMap.containsKey(service)) {
|
||||
@@ -3261,6 +3279,13 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
if (validIdMap.size()>1) {
|
||||
thread.setExceptionInfo(RestBusinessCode.IsValidNonUniq.getErrorReason());
|
||||
throw new RestServiceException(thread,
|
||||
System.currentTimeMillis() - start,
|
||||
RestBusinessCode.IsValidNonUniq.getErrorReason(),
|
||||
RestBusinessCode.IsValidNonUniq.getValue());
|
||||
}
|
||||
Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
|
||||
Iterator serviceIterator = cfgMap.keySet().iterator();
|
||||
while (serviceIterator.hasNext()) {
|
||||
@@ -3287,7 +3312,8 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
}
|
||||
try {
|
||||
configRedisService.delUnMaatConfig(restMap);
|
||||
|
||||
configRedisService.delUnMaatConfig(restMap,validIdMap.containsKey("0")?true:false);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
logger.error(e.getMessage());
|
||||
@@ -3328,10 +3354,12 @@ public class ConfigSourcesService extends BaseService {
|
||||
if (!StringUtil.isNumeric(service)) {
|
||||
CompileVal.setBusinessCode(RestBusinessCode.IsValidInWrongRange.getValue());
|
||||
return RestBusinessCode.IsValidInWrongRange.getErrorReason();
|
||||
} else if (!isValid.equals("0")) {
|
||||
CompileVal.setBusinessCode(RestBusinessCode.IsValidIsF.getValue());
|
||||
return RestBusinessCode.IsValidIsF.getErrorReason();
|
||||
}
|
||||
//配置取消改为状态更新(停/启用)
|
||||
// else if (!isValid.equals("0")) {
|
||||
// CompileVal.setBusinessCode(RestBusinessCode.IsValidIsF.getValue());
|
||||
// return RestBusinessCode.IsValidIsF.getErrorReason();
|
||||
// }
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user