1:新增webFocusDb业务
2:修改编译配置对doblacklist,exprType的校验值 3:新增从clickhouse查询流量统计的controller,service,dao等 4:新增对maat类配置支持停启用
This commit is contained in:
@@ -23,6 +23,7 @@ import com.nis.domain.restful.MaatConfig;
|
||||
import com.nis.restful.RestBusinessCode;
|
||||
import com.nis.restful.ServiceRuntimeException;
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.ExceptionUtil;
|
||||
import com.nis.util.File2Redis;
|
||||
import com.nis.util.JedisUtils;
|
||||
@@ -38,7 +39,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
@Service()
|
||||
public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
private static Logger logger = LoggerFactory.getLogger(ConfigJedisServiceimpl.class);
|
||||
private static final int TAPREDISDB = Configurations.getIntProperty("tapRedisDb", 5);
|
||||
|
||||
// 用于在实时统计配置后面添加时间,方便读取入库时间
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
|
||||
@@ -459,10 +460,10 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
for (MaatConfig maatConfig : maatConfigList) {
|
||||
int service = maatConfig.getService();
|
||||
if (ServiceAndRDBIndexReal.isAddASU(service)) {
|
||||
if (!keySet.contains(TAPREDISDB)) {
|
||||
if (!keySet.contains(Constants.TAPREDISDB)) {
|
||||
throw new ServiceRuntimeException(
|
||||
"业务类型:" + service + ",需要向阀门" + TAPREDISDB + "号库分发,但是当前只往" + keySet
|
||||
+ "库下发,请检查阀门编号或者当前业务对应的配置文件是否正确",
|
||||
"业务类型:" + service + ",需要向阀门" + Constants.TAPREDISDB + "号库分发,但是当前只往"
|
||||
+ keySet + "库下发,请检查阀门编号或者当前业务对应的配置文件是否正确",
|
||||
RestBusinessCode.PropertiesIsError.getValue());
|
||||
}
|
||||
}
|
||||
@@ -624,8 +625,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
valStr = valStr.trim().replace("[", "").replace("]", "");
|
||||
String val = map.get(valStr);
|
||||
if (val != null) {
|
||||
if (TAPREDISDB == redisDBIndex && type != 10 && type != 11
|
||||
&& valStr.toLowerCase().equals("op_time")) {// 域配置并且是op_time时在op_time前面添加如下内容
|
||||
if ((Constants.TAPREDISDB == redisDBIndex || Constants.WEBFOCUSREDISDB == redisDBIndex)
|
||||
&& type != 10 && type != 11 && valStr.toLowerCase().equals("op_time")) {// 域配置并且是op_time时在op_time前面添加如下内容
|
||||
Map<String, String[]> map2 = ServiceAndRDBIndexReal.getMaatToValveMap()
|
||||
.get(service);
|
||||
if (map2 != null && map2.size() > 0) {
|
||||
@@ -894,10 +895,19 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Map<Integer, List<Long>> getCompileIdAndDBReal(List<Long> idList, int service, int idRelaRedisDBIndex) {
|
||||
/**
|
||||
* 根据配置id从关联关系db中获取各个配置实际所在的db
|
||||
*
|
||||
* @param idList
|
||||
* @param service
|
||||
* @param idRelaRedisDBIndex
|
||||
* @return
|
||||
*/
|
||||
private Map<Integer, Set<Long>> getCompileIdAndDBReal(List<Long> idList, int service, int idRelaRedisDBIndex) {
|
||||
// 记录所有需要删除的配置信息key是相同的redisdb,value是需要删除的id集合
|
||||
Map<Integer, List<Long>> idAndDBMap = new HashMap<Integer, List<Long>>();
|
||||
Map<Integer, Set<Long>> idAndDBMap = new HashMap<Integer, Set<Long>>();
|
||||
for (Long configId : idList) {
|
||||
// if(JedisUtils.exists("COMPILEGROUP:" + configId, idRelaRedisDBIndex)){
|
||||
String compileValStr = JedisUtils.get("COMPILEGROUP:" + configId, idRelaRedisDBIndex);
|
||||
if (compileValStr != null && !compileValStr.trim().equals("")) {
|
||||
String[] keyAndDBArr =
|
||||
@@ -914,7 +924,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (idAndDBMap.containsKey(redisDb)) {
|
||||
idAndDBMap.get(redisDb).add(configId);
|
||||
} else {
|
||||
List<Long> list = new ArrayList<Long>();
|
||||
Set<Long> list = new HashSet<Long>();
|
||||
list.add(configId);
|
||||
idAndDBMap.put(redisDb, list);
|
||||
}
|
||||
@@ -931,12 +941,79 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
+ ",对应的redisdb信息,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
return idAndDBMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编译id,组id,域id
|
||||
*/
|
||||
public void delByCompileGroupRegionId() {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
double version = 3901d;
|
||||
Transaction transaction = resource.multi();
|
||||
transaction.select(2);
|
||||
for (long i = 3143; i <= 13142; i++) {
|
||||
String key = "EFFECTIVE_RULE:NTC_COMPILE," + i;
|
||||
String a = "OBSOLETE_RULE:NTC_COMPILE," + i;
|
||||
transaction.rename(key, a);
|
||||
|
||||
transaction.zadd("MAAT_RULE_TIMER", version, a);
|
||||
transaction.zadd("MAAT_UPDATE_STATUS", version, "DEL,NTC_COMPILE," + i);
|
||||
Long nowTime = new Date().getTime();
|
||||
nowTime = nowTime / 1000l;
|
||||
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
|
||||
transaction.zadd("MAAT_VERSION_TIMER", score, version + "");
|
||||
}
|
||||
for (long i = 5312; i <= 15311; i++) {
|
||||
String key = "EFFECTIVE_RULE:NTC_IP," + i;
|
||||
String a = "OBSOLETE_RULE:NTC_IP," + i;
|
||||
transaction.rename(key, a);
|
||||
|
||||
transaction.zadd("MAAT_RULE_TIMER", version, a);
|
||||
transaction.zadd("MAAT_UPDATE_STATUS", version, "DEL,NTC_IP," + i);
|
||||
Long nowTime = new Date().getTime();
|
||||
nowTime = nowTime / 1000l;
|
||||
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
|
||||
transaction.zadd("MAAT_VERSION_TIMER", score, version + "");
|
||||
}
|
||||
int b = 0;
|
||||
for (long i = 3898; i <= 13897; i++) {
|
||||
int id = 3143 + b;
|
||||
String groupId = i + "" + id;
|
||||
String key = "EFFECTIVE_RULE:NTC_GROUP," + groupId;
|
||||
String c = "OBSOLETE_RULE:NTC_GROUP," + groupId;
|
||||
transaction.rename(key, c);
|
||||
b++;
|
||||
transaction.zadd("MAAT_RULE_TIMER", version, c);
|
||||
transaction.zadd("MAAT_UPDATE_STATUS", version, "DEL,NTC_GROUP," + groupId);
|
||||
Long nowTime = new Date().getTime();
|
||||
nowTime = nowTime / 1000l;
|
||||
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
|
||||
transaction.zadd("MAAT_VERSION_TIMER", score, version + "");
|
||||
|
||||
}
|
||||
|
||||
transaction.set("MAAT_VERSION", "3901");
|
||||
transaction.exec();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置id删除数据
|
||||
*/
|
||||
public void delByCompileId() {
|
||||
Map<Integer, List<Long>> serviceConfigMap = new HashMap<Integer, List<Long>>();
|
||||
List<Long> list = new ArrayList<>();
|
||||
for (long i = 13143; i <= 23142; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
serviceConfigMap.put(129, list);
|
||||
delMaatConfig(serviceConfigMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delMaatConfig(Map<Integer, List<Long>> serviceConfigMap) {
|
||||
if (serviceConfigMap != null && serviceConfigMap.size() > 0) {
|
||||
@@ -946,14 +1023,14 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||
if (serviceConfigMap != null && serviceConfigMap.size() > 0) {
|
||||
for (Integer service : serviceConfigMap.keySet()) {
|
||||
Map<Integer, List<Long>> compileIdAndDBReal = getCompileIdAndDBReal(
|
||||
Map<Integer, Set<Long>> compileIdAndDBReal = getCompileIdAndDBReal(
|
||||
serviceConfigMap.get(service), service, idRelaRedisDBIndex);
|
||||
for (Integer redisDb : compileIdAndDBReal.keySet()) {
|
||||
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb);
|
||||
if (maatVersionStr != null) {
|
||||
Double maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
List<Long> list = compileIdAndDBReal.get(redisDb);
|
||||
Set<Long> list = compileIdAndDBReal.get(redisDb);
|
||||
if (list != null && list.size() > 0) {
|
||||
for (Long id : list) {
|
||||
// 按序号选择Redis数据库
|
||||
@@ -979,8 +1056,83 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
throw new ServiceRuntimeException("删除maat类配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
||||
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
}
|
||||
if (removeMaatRelation(serviceConfigMap, transaction)
|
||||
&& removeStatisticsReal(serviceConfigMap, transaction)) {
|
||||
if (removeMaatRelation(serviceConfigMap, transaction, null)
|
||||
&& removeStatisticsReal(serviceConfigMap, transaction, null)) {
|
||||
transaction.exec();
|
||||
return true;
|
||||
} else {
|
||||
transaction.discard();
|
||||
}
|
||||
|
||||
} catch (JedisConnectionException e) {
|
||||
String error = "连接redis异常,删除maat配置失败," + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
int businessCode = RestBusinessCode.service_runtime_error.getValue();
|
||||
if (e instanceof ServiceRuntimeException) {
|
||||
businessCode = ((ServiceRuntimeException) e).getErrorCode();
|
||||
}
|
||||
logger.error("删除maat配置发生了异常" + ExceptionUtil.getExceptionMsg(e));
|
||||
transaction.discard();
|
||||
throw new ServiceRuntimeException("删除maat配置发生了异常," + e.getMessage(), businessCode);
|
||||
} finally {
|
||||
// 释放连接到连接池
|
||||
JedisUtils.returnResource(resource);
|
||||
}
|
||||
} else
|
||||
|
||||
{
|
||||
throw new ServiceRuntimeException("Map参数信息不能为空,请检查!", RestBusinessCode.ConfigInfoMapIsNull.getValue());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean startStopMaatConfig(Map<Integer, List<Long>> serviceConfigMap, boolean isStart) {
|
||||
if (serviceConfigMap != null && serviceConfigMap.size() > 0) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
Transaction transaction = resource.multi();
|
||||
try {
|
||||
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||
if (serviceConfigMap != null && serviceConfigMap.size() > 0) {
|
||||
for (Integer service : serviceConfigMap.keySet()) {
|
||||
Map<Integer, Set<Long>> compileIdAndDBReal = getCompileIdAndDBReal(
|
||||
serviceConfigMap.get(service), service, idRelaRedisDBIndex);
|
||||
for (Integer redisDb : compileIdAndDBReal.keySet()) {
|
||||
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb);
|
||||
if (maatVersionStr != null) {
|
||||
Double maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
Set<Long> list = compileIdAndDBReal.get(redisDb);
|
||||
if (list != null && list.size() > 0) {
|
||||
for (Long id : list) {
|
||||
// 按序号选择Redis数据库
|
||||
transaction.select(redisDb);
|
||||
startStopConfig(id, maatXmlConfig, maatVersion, service, transaction, redisDb,
|
||||
idRelaRedisDBIndex, isStart);
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("删除配置时,未发现对应的配置id信息,请检查配置参数是否正确",
|
||||
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
}
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb,
|
||||
Integer.valueOf(maatVersionStr) + 1);
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从" + redisDb
|
||||
+ "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.GetMaatVersionFailure.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("删除maat类配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
||||
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
}
|
||||
if (removeMaatRelation(serviceConfigMap, transaction, isStart)
|
||||
&& removeStatisticsReal(serviceConfigMap, transaction, isStart)) {
|
||||
transaction.exec();
|
||||
return true;
|
||||
} else {
|
||||
@@ -1044,7 +1196,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
|
||||
// 删除(重命名)编译配置
|
||||
removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion, service, transaction, redisDBIndex,
|
||||
null);// 10代表是编译配置
|
||||
null, null);// 10代表是编译配置
|
||||
// 拼接编译与分组关系的Redis Key
|
||||
String compileStr = "COMPILEGROUP:" + id;
|
||||
// 获取当前编译配置与分组配置的关联关系
|
||||
@@ -1102,7 +1254,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
|
||||
removeRegionConfig(maatXmlConfig,
|
||||
regionKeyArr, maatVersion, service,
|
||||
transaction, redisDBIndex);
|
||||
transaction, redisDBIndex, null);
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从"
|
||||
@@ -1120,7 +1272,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
// 根据分组与编译关联关系找到对应分组配置然后删除(重命名)
|
||||
removeCompileAndGroupConfig(maatXmlConfig,
|
||||
groupId.replace("GROUPCOMPILE:", ""), 11, maatVersion, service,
|
||||
transaction, redisDBIndex, id + "");// 11代表是分组配置
|
||||
transaction, redisDBIndex, id + "", null);// 11代表是分组配置
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
@@ -1149,6 +1301,115 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
private void startStopConfig(Long id, MaatXmlConfig maatXmlConfig, Double maatVersion, int service,
|
||||
Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex, boolean isStart) {
|
||||
if (maatXmlConfig != null) {
|
||||
Map<String, String> keyMap = new HashMap<>();
|
||||
// 删除(重命名)编译配置
|
||||
removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion, service, transaction, redisDBIndex,
|
||||
null, isStart);// 10代表是编译配置
|
||||
// 拼接编译与分组关系的Redis Key
|
||||
String compileStr = "COMPILEGROUP:" + id;
|
||||
// 获取当前编译配置与分组配置的关联关系
|
||||
String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系
|
||||
if (compileStrVal != null && !compileStrVal.trim().equals("")) {
|
||||
String[] compileGroupStrArr = org.apache.commons.lang.StringUtils.split(compileStrVal, ";");
|
||||
for (String compileGroup : compileGroupStrArr) {
|
||||
if (compileGroup != null && !compileGroup.trim().equals("")) {
|
||||
String groupCompileStrs = getRegionInfo(compileGroup);// 获取编译对应的分组信息,去除后面的redisdb信息
|
||||
if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) {// 遍历编译和分组的信息
|
||||
String[] split = org.apache.commons.lang.StringUtils.split(groupCompileStrs, ";");
|
||||
|
||||
for (String groupId : split) {// GROUPCOMPILE:groupid-redisdb
|
||||
if (groupId != null && !groupId.trim().equals("")) {
|
||||
String groupCompileAndDBStrs = null;
|
||||
if (!keyMap.containsKey(groupId)) {
|
||||
groupCompileAndDBStrs = JedisUtils.get(groupId, idRelaRedisDBIndex);
|
||||
keyMap.put(groupId, groupCompileAndDBStrs);
|
||||
} else {
|
||||
groupCompileAndDBStrs = keyMap.get(groupId);
|
||||
}
|
||||
|
||||
String[] compileGroupArr = org.apache.commons.lang.StringUtils
|
||||
.split(groupCompileAndDBStrs, ";");// 获取组对应的编译id
|
||||
|
||||
for (String groupAndCompileStr : compileGroupArr) {
|
||||
if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) {
|
||||
String compileId = getRegionInfo(groupAndCompileStr);
|
||||
if (compileId != null && !compileId.trim().equals("")) {
|
||||
// 被分组复用的业务,不能将域置为失效
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 根据分组与编译关联关系找到对应分组配置然后删除(重命名)
|
||||
removeCompileAndGroupConfig(maatXmlConfig,
|
||||
groupId.replace("GROUPCOMPILE:", ""), 11, maatVersion, service,
|
||||
transaction, redisDBIndex, id + "", isStart);// 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(
|
||||
"无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确",
|
||||
RestBusinessCode.NotFoundRedisRule.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除maat配置时,对redis进行相关操作,主要是重命名key和记录相关状态
|
||||
*
|
||||
@@ -1160,7 +1421,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
* @param redisTemplate
|
||||
*/
|
||||
private void removeCompileAndGroupConfig(MaatXmlConfig maatXmlConfig, String id, int type, Double maatVersion,
|
||||
int service, Transaction transaction, int redisDBIndex, String compileId) {
|
||||
int service, Transaction transaction, int redisDBIndex, String compileId, Boolean isStart) {
|
||||
if (maatXmlConfig != null) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
String maatKey = null;
|
||||
@@ -1194,14 +1455,29 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (compileId != null) {
|
||||
oldKey += compileId;
|
||||
}
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
if (isStart == null) {// 置为失效
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
} else if (isStart == true) {// 将失效置为生效
|
||||
maatKey = oldKey;
|
||||
oldKey=oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
} else {// 将生效变为失效
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
}
|
||||
|
||||
transaction.rename(oldKey, maatKey.toUpperCase());
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase());
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);
|
||||
|
||||
if (isStart == null) {
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);// 变成无效
|
||||
} else if (isStart) {
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, false);// 变成有效
|
||||
} else {
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);// 变成无效
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确",
|
||||
@@ -1220,17 +1496,29 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
* @param redisDBIndex
|
||||
*/
|
||||
private void removeRegionConfig(MaatXmlConfig maatXmlConfig, String[] regionArr, Double maatVersion, int service,
|
||||
Transaction transaction, int redisDBIndex) {
|
||||
Transaction transaction, int redisDBIndex, Boolean isStart) {
|
||||
transaction.select(redisDBIndex);
|
||||
if (maatXmlConfig != null && regionArr != null && regionArr.length > 0) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
String maatKey = null;
|
||||
for (String oldKey : regionArr) {
|
||||
if (oldKey != null && !oldKey.trim().equals("")) {
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
if (isStart == null) {// 置为失效
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
} else if (isStart == true) {// 将失效置为生效
|
||||
maatKey = oldKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE");
|
||||
} else {// 将生效变为失效
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
}
|
||||
transaction.rename(oldKey, maatKey.toUpperCase());
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase());
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);
|
||||
if (isStart == null) {
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);// 变成无效
|
||||
} else if (isStart) {
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, false);// 变成有效
|
||||
} else {
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1246,7 +1534,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
/**
|
||||
* 编译配置用于实时统计 取消分类性质,标签等信息
|
||||
*/
|
||||
private boolean removeStatisticsReal(Map<Integer, List<Long>> map, Transaction transaction) {
|
||||
private boolean removeStatisticsReal(Map<Integer, List<Long>> map, Transaction transaction, Boolean isStart) {
|
||||
if (map != null && map.size() > 0) {
|
||||
int redisStatisticsRealDBIndex = Configurations.getIntProperty("redisStatisticsRealDBIndex", 14);
|
||||
transaction.select(redisStatisticsRealDBIndex);
|
||||
@@ -1269,8 +1557,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是:{}", redisStatisticsRealDBIndex,
|
||||
effectiveRuleKey.toUpperCase(),
|
||||
effectiveRuleKey.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE"));
|
||||
|
||||
String zset = effectiveRuleKey.replace("EFFECTIVE_RULE:", "DEL,");
|
||||
if (isStart == null || isStart == false) {
|
||||
} else if (isStart == true) {
|
||||
zset = effectiveRuleKey.replace("EFFECTIVE_RULE:", "ADD,");
|
||||
}
|
||||
transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset);
|
||||
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}", redisStatisticsRealDBIndex,
|
||||
zset.toUpperCase(), maatVersion);
|
||||
@@ -1302,7 +1593,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
*
|
||||
* @param idMap
|
||||
*/
|
||||
private boolean removeMaatRelation(Map<Integer, List<Long>> map, Transaction transaction) {
|
||||
private boolean removeMaatRelation(Map<Integer, List<Long>> map, Transaction transaction, Boolean isStart) {
|
||||
if (map != null && map.size() > 0) {
|
||||
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||
transaction.select(idRelaRedisDBIndex);
|
||||
@@ -1352,7 +1643,22 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除分组与域的关联关系
|
||||
transaction.del(groupRegion);
|
||||
if (isStart == null) {// 删除
|
||||
transaction.del(groupRegion);
|
||||
} else if (isStart == true) {// 将失效置为生效
|
||||
String groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal
|
||||
.replace("OBSOLETE_RULE", "EFFECTIVE_RULE");
|
||||
transaction.set(groupRegion, groupRegionVal);
|
||||
} else {// 将生效变为失效
|
||||
String groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal
|
||||
.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
transaction.set(groupRegion, groupRegionVal);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex + "号redis库中删除"
|
||||
@@ -1383,7 +1689,26 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除当前组所对应的编译
|
||||
transaction.del(groupCompile.toUpperCase());
|
||||
|
||||
if (isStart == null) {// 删除
|
||||
transaction.del(groupCompile.toUpperCase());// 删除编译与分组的关联关系
|
||||
} else if (isStart == true) {// 将失效置为生效
|
||||
String groupRegionVal = JedisUtils.get(
|
||||
groupCompile.toUpperCase(),
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal.replace(
|
||||
"OBSOLETE_RULE", "EFFECTIVE_RULE");
|
||||
transaction.set(groupCompile.toUpperCase(),
|
||||
groupRegionVal);
|
||||
} else {// 将生效变为失效
|
||||
String groupRegionVal = JedisUtils.get(
|
||||
groupCompile.toUpperCase(),
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal.replace(
|
||||
"EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
transaction.set(groupCompile.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex + "号redis库中删除"
|
||||
@@ -1423,7 +1748,21 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
try {
|
||||
transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系
|
||||
if (isStart == null) {// 删除
|
||||
transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系
|
||||
} else if (isStart == true) {// 将失效置为生效
|
||||
String groupRegionVal = JedisUtils.get(compileStr.toUpperCase(),
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE",
|
||||
"EFFECTIVE_RULE");
|
||||
transaction.set(compileStr.toUpperCase(), groupRegionVal);
|
||||
} else {// 将生效变为失效
|
||||
String groupRegionVal = JedisUtils.get(compileStr.toUpperCase(),
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal.replace("EFFECTIVE_RULE",
|
||||
"OBSOLETE_RULE");
|
||||
transaction.set(compileStr.toUpperCase(), groupRegionVal);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis关联关系库中删除" + compileStr
|
||||
@@ -1950,13 +2289,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
private void updateMaatInfo(List<MaatXmlExpr> list, String maatKey, Transaction transaction, Double maatVersion,
|
||||
int redisDBIndex, boolean idDel) {
|
||||
int redisDBIndex, Boolean idDel) {
|
||||
if (list != null && list.size() > 0) {
|
||||
for (MaatXmlExpr maatXmlExpr : list) {
|
||||
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
|
||||
if (maatKey != null) {
|
||||
String zset = null;
|
||||
if (idDel) {
|
||||
if (idDel == null || idDel) {
|
||||
zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||
} else {
|
||||
zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
|
||||
|
||||
@@ -79,6 +79,14 @@ public interface ConfigRedisService {
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
public boolean delMaatConfig(Map<Integer, List<Long>> serviceConfigMap);
|
||||
/**
|
||||
* 停启用maat类配置,key是业务类型,value是配置id集合
|
||||
*
|
||||
* @param serviceConfigMap
|
||||
* @param isStart 是否置位生效,
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
public boolean startStopMaatConfig(Map<Integer, List<Long>> serviceConfigMap, boolean isStart);
|
||||
|
||||
/**
|
||||
* 删除分组复用的域配置
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.nis.domain.restful.CommonSourceFieldCfg;
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigCompileStartStop;
|
||||
import com.nis.domain.restful.ConfigGroupRelation;
|
||||
import com.nis.domain.restful.DigestRegion;
|
||||
import com.nis.domain.restful.GroupReuse;
|
||||
@@ -123,7 +124,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
StringBuffer sb) throws Exception {
|
||||
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
|
||||
|
||||
for (ConfigCompile configCompile : configCompileList) {
|
||||
Integer service = Integer.valueOf(configCompile.getService().toString());
|
||||
MaatConfig maatConfig = new MaatConfig();
|
||||
@@ -225,54 +226,17 @@ public class ConfigSourcesService extends BaseService {
|
||||
List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
||||
if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) {
|
||||
for (Integer dbIndex : dbIndexList) {
|
||||
|
||||
// 分发到阀门有些业务需要添加编译属性到域配置
|
||||
List<MaatConfig> newMaatConfigList = new ArrayList<MaatConfig>();
|
||||
newMaatConfigList.addAll(maatMap.get(service));
|
||||
if (dbIndex.intValue() == ServiceAndRDBIndexReal.getValveDBIndex().intValue()) {
|
||||
if (dbIndex.intValue() == Constants.TAPREDISDB) {
|
||||
Map<Integer, Map<String, String[]>> maatToValueMap = ServiceAndRDBIndexReal.getMaatToValveMap();
|
||||
if (maatToValueMap.containsKey(service)) {
|
||||
|
||||
Map<String, String[]> regionAndFiledMap = maatToValueMap.get(service);
|
||||
for (int i = 0; i < newMaatConfigList.size(); i++) {
|
||||
MaatConfig maatConfig = newMaatConfigList.get(i);
|
||||
MaatConfig newMaatConfig = (MaatConfig) JsonMapper
|
||||
.fromJsonString(JsonMapper.toJsonString(maatConfig), MaatConfig.class);
|
||||
Iterator iterator = regionAndFiledMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String regionName = iterator.next().toString();
|
||||
PropertyDescriptor pd;
|
||||
try {
|
||||
pd = new PropertyDescriptor(regionName + "MapList", MaatConfig.class);
|
||||
Method method = pd.getReadMethod();
|
||||
Object object = method.invoke(newMaatConfig);
|
||||
|
||||
if (object != null) {
|
||||
|
||||
List<Map<String, String>> listMaps = new ArrayList<Map<String, String>>();
|
||||
listMaps.addAll((List<Map<String, String>>) object);
|
||||
String[] fields = regionAndFiledMap.get(regionName);
|
||||
for (String fieldName : fields) {
|
||||
String value = newMaatConfig.getCompileMap()
|
||||
.get(fieldName.toLowerCase());
|
||||
if (!StringUtil.isEmpty(value)) {
|
||||
for (Map<String, String> map : listMaps) {
|
||||
map.put(fieldName.toLowerCase(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
method = pd.getWriteMethod();
|
||||
method.invoke(newMaatConfig, listMaps);
|
||||
}
|
||||
newMaatConfigList.set(i, newMaatConfig);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
throw new RestServiceException("未找到域列表,请检查配置文件中域类型是否正确!:" + e.getMessage(),
|
||||
RestBusinessCode.service_runtime_error.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
addFieldToValveOrWebFocus(service, newMaatConfigList, maatToValueMap, false);
|
||||
} else if (dbIndex.intValue() == Constants.WEBFOCUSREDISDB) {
|
||||
Map<Integer, Map<String, String[]>> maatToWebFocusMap = ServiceAndRDBIndexReal
|
||||
.getMaatToWebFocusMap();
|
||||
addFieldToValveOrWebFocus(service, newMaatConfigList, maatToWebFocusMap, true);
|
||||
}
|
||||
|
||||
if (configMap.containsKey(dbIndex)) {
|
||||
@@ -293,6 +257,61 @@ public class ConfigSourcesService extends BaseService {
|
||||
configRedisService.saveMaatConfig(configMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加额外属性到阀门或者webfocus
|
||||
*
|
||||
* @param maatToValueMap
|
||||
*/
|
||||
private void addFieldToValveOrWebFocus(Integer service, List<MaatConfig> newMaatConfigList,
|
||||
Map<Integer, Map<String, String[]>> maatToValueMap, Boolean isWebFocus) {
|
||||
|
||||
if (maatToValueMap.containsKey(service)) {
|
||||
|
||||
Map<String, String[]> regionAndFiledMap = maatToValueMap.get(service);
|
||||
for (int i = 0; i < newMaatConfigList.size(); i++) {
|
||||
MaatConfig maatConfig = newMaatConfigList.get(i);
|
||||
if (isWebFocus && maatConfig.getGroupMapList().size() > 1) {// 如果当前配置需要向webfocus中入,但是groupsize大于1,此时就不入了,只有groupsize=1的时候入
|
||||
continue;
|
||||
}
|
||||
MaatConfig newMaatConfig = (MaatConfig) JsonMapper.fromJsonString(JsonMapper.toJsonString(maatConfig),
|
||||
MaatConfig.class);
|
||||
Iterator iterator = regionAndFiledMap.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String regionName = iterator.next().toString();
|
||||
PropertyDescriptor pd;
|
||||
try {
|
||||
pd = new PropertyDescriptor(regionName + "MapList", MaatConfig.class);
|
||||
Method method = pd.getReadMethod();
|
||||
Object object = method.invoke(newMaatConfig);
|
||||
|
||||
if (object != null) {
|
||||
|
||||
List<Map<String, String>> listMaps = new ArrayList<Map<String, String>>();
|
||||
listMaps.addAll((List<Map<String, String>>) object);
|
||||
String[] fields = regionAndFiledMap.get(regionName);
|
||||
for (String fieldName : fields) {
|
||||
String value = newMaatConfig.getCompileMap().get(fieldName.toLowerCase());
|
||||
if (!StringUtil.isEmpty(value)) {
|
||||
for (Map<String, String> map : listMaps) {
|
||||
map.put(fieldName.toLowerCase(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
method = pd.getWriteMethod();
|
||||
method.invoke(newMaatConfig, listMaps);
|
||||
}
|
||||
newMaatConfigList.set(i, newMaatConfig);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
throw new RestServiceException("未找到域列表,请检查配置文件中域类型是否正确!:" + e.getMessage(),
|
||||
RestBusinessCode.service_runtime_error.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> convertObjectToMap(Object obj, Class clazz) throws Exception {
|
||||
Map<String, String> dstMap = new HashMap<String, String>();
|
||||
Field[] fields = obj.getClass().getDeclaredFields();
|
||||
@@ -318,15 +337,18 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
|
||||
public void updateConfigSources(AuditLogThread thread, long start, List<ConfigCompile> compileList, Date opTime,
|
||||
StringBuffer sb) throws Exception {
|
||||
StringBuffer sb, boolean isConfigStartStop) throws Exception {
|
||||
// 所有状态更新的配置isValid的值必须相同
|
||||
Map<String, String> validIdMap = new HashMap<String, String>();
|
||||
|
||||
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
|
||||
if (null != compileList && compileList.size() > 0) {
|
||||
for (ConfigCompile config : compileList) {
|
||||
checkCompileOptForUpdate(config);
|
||||
checkCompileOptForUpdate(config, isConfigStartStop);
|
||||
validIdMap.put(config.getIsValid().toString(), config.getIsValid().toString());
|
||||
if (config.getOpTime() == null) {
|
||||
config.setOpTime(opTime);
|
||||
}
|
||||
|
||||
// compileAllList.add(config);
|
||||
if (compileMap.containsKey(config.getService())) {
|
||||
compileMap.get(config.getService()).add(config.getCompileId());
|
||||
@@ -340,34 +362,29 @@ public class ConfigSourcesService extends BaseService {
|
||||
} else {
|
||||
throw new RestServiceException("编译配置不能为空" + sb.toString(), RestBusinessCode.CompileIsNull.getValue());
|
||||
}
|
||||
// Map<DBIndex,Map<Service,List<CompileId>>
|
||||
// Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer,
|
||||
// Map<Integer, List<Long>>>();
|
||||
// Iterator serviceIterator = compileMap.keySet().iterator();
|
||||
// while (serviceIterator.hasNext()) {
|
||||
// Integer service = Integer.valueOf(serviceIterator.next().toString());
|
||||
// List<Integer> dbIndexList =
|
||||
// ServiceAndRDBIndexReal.getRedisDBByService(service);
|
||||
// if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) {
|
||||
// for (Integer dbIndex : dbIndexList) {
|
||||
// if (restMap.containsKey(dbIndex)) {
|
||||
// restMap.get(dbIndex).put(service, compileMap.get(service));
|
||||
// } else {
|
||||
// Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
|
||||
// map.put(service, compileMap.get(service));
|
||||
// restMap.put(dbIndex, map);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// ServiceRuntimeException e = new ServiceRuntimeException("service值为" + service
|
||||
// + ",与写入数据库序号映射关系不存在",
|
||||
// RestBusinessCode.ServiceNoFoundDBIndex.getValue());
|
||||
// }
|
||||
// }
|
||||
// 所有的都删除成功返回true
|
||||
if (!configRedisService.delMaatConfig(compileMap)) {
|
||||
throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员",
|
||||
RestBusinessCode.service_runtime_error.getValue());
|
||||
|
||||
if (validIdMap.size() > 1) {
|
||||
throw new RestServiceException(RestBusinessCode.IsValidNonUniq.getErrorReason(),
|
||||
RestBusinessCode.IsValidNonUniq.getValue());
|
||||
}
|
||||
|
||||
if (!isConfigStartStop) {
|
||||
// 所有的都删除成功返回true
|
||||
if (!configRedisService.delMaatConfig(compileMap)) {
|
||||
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.startStopMaatConfig(compileMap, isStart)) {
|
||||
throw new ServiceRuntimeException("停启用MAAT配置时出现异常,具体原因不详,请联系管理员",
|
||||
RestBusinessCode.service_runtime_error.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +401,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
* @param config
|
||||
* @return
|
||||
*/
|
||||
private void checkCompileOptForUpdate(ConfigCompile config) throws Exception {
|
||||
private void checkCompileOptForUpdate(ConfigCompile config, boolean isConfigStartStop) throws Exception {
|
||||
|
||||
if (StringUtil.isEmpty(config.getCompileId())) {
|
||||
throw new RestServiceException(RestBusinessCode.CompileIdIsNull.getErrorReason(),
|
||||
@@ -398,9 +415,12 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException("编译配置id为" + config.getCompileId() + "的IsValid字段不能为空",
|
||||
RestBusinessCode.IsValidIsNull.getValue());
|
||||
}
|
||||
if (config.getIsValid() != 0) {
|
||||
throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效",
|
||||
RestBusinessCode.IsValidIsF.getValue());
|
||||
|
||||
if (!isConfigStartStop) {
|
||||
if (config.getIsValid() != 0) {
|
||||
throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效",
|
||||
RestBusinessCode.IsValidIsF.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,8 +433,8 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(),
|
||||
RestBusinessCode.CBParamFormateError.getValue());
|
||||
}
|
||||
if (jsonObjectList!=null&&jsonObjectList.size()>Constants.MAX_LIST_SIZE) {
|
||||
thread.setContent("批量提交数量超过"+Constants.MAX_LIST_SIZE+"条,不记录请求内容");
|
||||
if (jsonObjectList != null && jsonObjectList.size() > Constants.MAX_LIST_SIZE) {
|
||||
thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容");
|
||||
}
|
||||
Map<Integer, List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String, String>>>();
|
||||
for (int i = 0; i < jsonObjectList.size(); i++) {
|
||||
@@ -486,7 +506,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
maatTableName.substring(maatTableName.lastIndexOf("_") + 1));
|
||||
dstStr = dstPath.replace("{fileName}", dstStr.substring(dstStr.lastIndexOf("/") + 1));
|
||||
} else if ("file_id".equals(commonSourceFieldCfg.getDstName())) {
|
||||
//dstStr = dstStr.substring(dstStr.indexOf("group"));
|
||||
// dstStr = dstStr.substring(dstStr.indexOf("group"));
|
||||
}
|
||||
}
|
||||
switch (commonSourceFieldCfg.getFieldType()) {
|
||||
@@ -635,8 +655,8 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(),
|
||||
RestBusinessCode.CBParamFormateError.getValue());
|
||||
}
|
||||
if (jsonObjectList!=null&&jsonObjectList.size()>Constants.MAX_LIST_SIZE) {
|
||||
thread.setContent("批量提交数量超过"+Constants.MAX_LIST_SIZE+"条,不记录请求内容");
|
||||
if (jsonObjectList != null && jsonObjectList.size() > Constants.MAX_LIST_SIZE) {
|
||||
thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容");
|
||||
}
|
||||
// <service,cfgIdList>
|
||||
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();
|
||||
@@ -869,12 +889,11 @@ public class ConfigSourcesService extends BaseService {
|
||||
} else {
|
||||
maatConfig.getIpRegionMapList().addAll(dstMapList);
|
||||
}
|
||||
|
||||
//maatConfig.setService(groupReuse.getService());
|
||||
|
||||
// maatConfig.setService(groupReuse.getService());
|
||||
list.add(maatConfig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 调用接口入redis
|
||||
logger.info("---------------调用Redis 分组复用配置新增接口---------------------");
|
||||
configRedisService.saveGroupReuseConfig(list);
|
||||
@@ -942,9 +961,9 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
}
|
||||
logger.info("调用接口删除Redis中分组复用的域配置接口");
|
||||
if (reuseMap!=null&&reuseMap.size()>Constants.MAX_LIST_SIZE) {
|
||||
thread.setContent("批量提交数量超过"+Constants.MAX_LIST_SIZE+"条,不记录请求内容");
|
||||
}
|
||||
if (reuseMap != null && reuseMap.size() > Constants.MAX_LIST_SIZE) {
|
||||
thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容");
|
||||
}
|
||||
// 所有的都删除成功返回true
|
||||
if (!configRedisService.delGroupReuseConfig(reuseMap)) {
|
||||
// if (!configRedisService.delGroupReuseConfigByPipeline(reuseMap)) {
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.restful.NtcRadiusReport;
|
||||
import com.nis.domain.restful.dashboard.TrafficTransStatistic;
|
||||
import com.nis.web.dao.TrafficReportDao;
|
||||
import com.nis.web.dao.dashboard.NtcTotalReportDao;
|
||||
import com.nis.web.service.BaseLogService;
|
||||
|
||||
@Service
|
||||
public class TrafficReportService extends BaseLogService {
|
||||
|
||||
@Autowired
|
||||
protected TrafficReportDao trafficReportDao;
|
||||
|
||||
|
||||
public Page<NtcRadiusReport> findNtcRadiusReport(Page page,NtcRadiusReport entity) throws Exception {
|
||||
entity.setPage(page);
|
||||
List resultList = null;
|
||||
if ("1".equals(entity.getSearchBusinessType())) {
|
||||
resultList = new ArrayList<Map>();
|
||||
Map<String, List<NtcRadiusReport>> restMap = new HashMap<String, List<NtcRadiusReport>>();
|
||||
List<NtcRadiusReport> accountList = trafficReportDao.findAccounList(entity);
|
||||
restMap.put("accountList", accountList);
|
||||
List<NtcRadiusReport> nasIpList = trafficReportDao.findNasIpList(entity);
|
||||
restMap.put("nasIpList", nasIpList);
|
||||
resultList.add(restMap);
|
||||
} else {
|
||||
resultList = new ArrayList<NtcRadiusReport>();
|
||||
List<NtcRadiusReport> list = trafficReportDao.findNtcRadiusReport(entity);
|
||||
|
||||
String regionName = "nasIp";
|
||||
if ("3".equals(entity.getSearchBusinessType())) {
|
||||
regionName = "account";
|
||||
}
|
||||
PropertyDescriptor pd = new PropertyDescriptor(regionName, NtcRadiusReport.class);
|
||||
Method method = pd.getReadMethod();
|
||||
NtcRadiusReport temp = null;
|
||||
Object tempVal = null;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (i > 0) {
|
||||
NtcRadiusReport obj = list.get(i);
|
||||
Object objVal = method.invoke(obj);
|
||||
if (objVal != null && tempVal != null && !objVal.toString().equals(tempVal.toString())) {
|
||||
temp = obj;
|
||||
tempVal = method.invoke(temp);
|
||||
resultList.add(obj);
|
||||
}
|
||||
} else {
|
||||
temp = list.get(i);
|
||||
tempVal = method.invoke(temp);
|
||||
resultList.add(list.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
page.setList(resultList);
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据ip46,协议tcp,udp查询带宽
|
||||
*
|
||||
* @param addrType
|
||||
* @param transType
|
||||
* @return
|
||||
*/
|
||||
public List<HashMap> getBandwidthTrans(String addrType, Integer transType, String beginDate, String endDate) {
|
||||
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
|
||||
|
||||
HashMap m1 = getBandwidthTransEntrance(addrType, transType, beginDate, endDate, 1);
|
||||
if (m1 != null && m1.size() > 0) {
|
||||
m1.put("entranceId", 1);// 局点1.2 不同来源
|
||||
listMap.add(m1);
|
||||
}
|
||||
return listMap;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据ip46,协议tcp,udp查询带宽
|
||||
*
|
||||
* @param addrType
|
||||
* @param transType
|
||||
* @return
|
||||
*/
|
||||
public List<HashMap> getBandwidthTrans2(String addrType, Integer transType, String beginDate, String endDate) {
|
||||
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
|
||||
|
||||
HashMap m2 = getBandwidthTransEntrance(addrType, transType, beginDate, endDate, 2);
|
||||
if (m2 != null && m2.size() > 0) {
|
||||
m2.put("entranceId", 2);
|
||||
listMap.add(m2);
|
||||
}
|
||||
return listMap;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询单个局点流量的数据信息
|
||||
*
|
||||
* @param addrType
|
||||
* @param transType
|
||||
* @param beginDate
|
||||
* @param endDate
|
||||
* @param entranceId
|
||||
* @return
|
||||
*/
|
||||
public HashMap getBandwidthTransEntrance(String addrType, Integer transType, String beginDate, String endDate,
|
||||
Integer entranceId) {
|
||||
long start = System.currentTimeMillis();
|
||||
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
|
||||
List<TrafficTransStatistic> bandwidthList = new ArrayList<TrafficTransStatistic>();
|
||||
HashMap resulMap = new HashMap();
|
||||
bandwidthList = trafficReportDao.getBandwidthTrans(entranceId, beginDate, endDate, addrType, transType);
|
||||
List timeList = new ArrayList();
|
||||
List linkList = new ArrayList();
|
||||
List gbpsList = new ArrayList();
|
||||
List ppsList = new ArrayList();
|
||||
if (bandwidthList != null && bandwidthList.size() > 0) {
|
||||
Map<String, Comparable> m = new HashMap<String, Comparable>();
|
||||
int inter = 1000 * 60 * 5;// 间隔时间为五分钟
|
||||
// 开始时间,结束时间 时间戳
|
||||
Long b = dateToStamp(beginDate);
|
||||
Long e = dateToStamp(endDate);
|
||||
int num = 0;
|
||||
Long pointTime = b;
|
||||
while (pointTime < e) {
|
||||
Map rm = new HashMap();
|
||||
Long sumL = 0l;
|
||||
Long sumP = 0l;
|
||||
Long sumG = 0l;
|
||||
if (pointTime >= e) {
|
||||
break; // 停止
|
||||
}
|
||||
for (TrafficTransStatistic tt : bandwidthList) {
|
||||
// 实际时间
|
||||
String time = tt.getTime();
|
||||
Long t = dateToStamp(time);
|
||||
if (t >= pointTime && t < pointTime + inter) {
|
||||
// 范围之内分到此pointTime组
|
||||
sumL = sumL + tt.getLinkNum();
|
||||
sumP = sumP + tt.getPps();
|
||||
sumG = sumG + tt.getGbps();
|
||||
}
|
||||
}
|
||||
// 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会
|
||||
if (pointTime >= e - inter && sumL > 0) {
|
||||
linkList.add(sumL);
|
||||
}
|
||||
if (pointTime >= e - inter && sumP > 0) {
|
||||
ppsList.add(sumP);
|
||||
}
|
||||
if (pointTime >= e - inter && sumG > 0) {
|
||||
gbpsList.add(sumG);
|
||||
}
|
||||
if (pointTime >= e - inter && (sumL > 0 || sumG > 0 || sumP > 0)) {
|
||||
timeList.add(stampToDate(pointTime));
|
||||
}
|
||||
if (pointTime < e - inter) {
|
||||
timeList.add(stampToDate(pointTime));
|
||||
linkList.add(sumL);
|
||||
gbpsList.add(sumG);
|
||||
ppsList.add(sumP);
|
||||
}
|
||||
|
||||
num = num + 1;
|
||||
pointTime = b + inter * num;
|
||||
}
|
||||
resulMap.put("linkNum", linkList);
|
||||
resulMap.put("gbps", gbpsList);
|
||||
resulMap.put("pps", ppsList);
|
||||
resulMap.put("statTime", timeList);
|
||||
}
|
||||
return resulMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 时间戳 换成日期格式字符串转
|
||||
*
|
||||
* @param 时间 1544602212000
|
||||
* @param format 如:yyyy-MM-dd HH:mm:ss
|
||||
* @return
|
||||
*/
|
||||
public static String stampToDate(long timeStamp) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");// 这个是你要转成后的时间的格式
|
||||
String sd = sdf.format(new Date(timeStamp)); // 时间戳转换成时间
|
||||
return sd;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 日期格式字符串转换成时间戳
|
||||
*
|
||||
* @param date 字符串日期
|
||||
* @param format 如:yyyy-MM-dd HH:mm:ss
|
||||
* @return
|
||||
*/
|
||||
public static Long dateToStamp(String date_str) {
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return sdf.parse(date_str).getTime();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0l;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user