1:为实时统计配置中jediscluster改为每次使用都获取一个新的
2:添加根据配置id获取编译,组,域等信息的接口 3:修改获取或释放redis分布式锁后,将redis连接释放 4:解决冲突
This commit is contained in:
@@ -30,6 +30,8 @@ import com.nis.util.ReadMaatXmlUtil;
|
||||
import com.nis.util.ServiceAndRDBIndexReal;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
|
||||
@@ -568,8 +570,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
* @param redisTemplate
|
||||
* @param redisDBIndex
|
||||
* @param compileId
|
||||
* @param isReuse
|
||||
* 是否是分组复用
|
||||
* @param isReuse 是否是分组复用
|
||||
*/
|
||||
private void setCommonConfig(MaatXmlConfig maatXmlConfig, Map<String, String> map, int type, Double maatVersion,
|
||||
int service, Transaction transaction, Integer redisDBIndex, String compileId, boolean isReuse) {
|
||||
@@ -1028,17 +1029,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
/**
|
||||
* 删除maat类配置
|
||||
*
|
||||
* @param id
|
||||
* 配置id
|
||||
* @param maatXmlConfig
|
||||
* maat.xml中关于当前业务类型的key和value写法的对象
|
||||
* @param maatVersion
|
||||
* 版本号
|
||||
* @param service
|
||||
* 业务类型
|
||||
* @param id 配置id
|
||||
* @param maatXmlConfig maat.xml中关于当前业务类型的key和value写法的对象
|
||||
* @param maatVersion 版本号
|
||||
* @param service 业务类型
|
||||
* @param redisTemplate
|
||||
* @param maatRelation
|
||||
* id对应关系对象
|
||||
* @param maatRelation id对应关系对象
|
||||
*/
|
||||
private void removeConfig(Long id, MaatXmlConfig maatXmlConfig, Double maatVersion, int service,
|
||||
Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex) {
|
||||
@@ -1700,20 +1696,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
/**
|
||||
* 保存域配置信息,供分组复用单独添加域和普通maat配置添加域
|
||||
*
|
||||
* @param maatConfig
|
||||
* 配置信息
|
||||
* @param maatXmlConfig
|
||||
* 配置的表达式
|
||||
* @param maatVersion
|
||||
* 版本号
|
||||
* @param service
|
||||
* 业务类型
|
||||
* @param transaction
|
||||
* redis连接
|
||||
* @param redisDBIndex
|
||||
* redis编号
|
||||
* @param isReuseSaveRegion
|
||||
* 是否是分组复用单独添加域配置
|
||||
* @param maatConfig 配置信息
|
||||
* @param maatXmlConfig 配置的表达式
|
||||
* @param maatVersion 版本号
|
||||
* @param service 业务类型
|
||||
* @param transaction redis连接
|
||||
* @param redisDBIndex redis编号
|
||||
* @param isReuseSaveRegion 是否是分组复用单独添加域配置
|
||||
*/
|
||||
private Integer addRegion(MaatConfig maatConfig, MaatXmlConfig maatXmlConfig, Double maatVersion, int service,
|
||||
Transaction transaction, Integer redisDBIndex, boolean isReuseSaveRegion) {
|
||||
@@ -1957,6 +1946,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
JedisUtils.returnResource(resource);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMaatInfo(List<MaatXmlExpr> list, String maatKey, Transaction transaction, Double maatVersion,
|
||||
int redisDBIndex, boolean idDel) {
|
||||
if (list != null && list.size() > 0) {
|
||||
@@ -1991,4 +1981,78 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Integer, Map<String, String>> getAllKVByCompileId(Long id) {
|
||||
Jedis resource = JedisUtils.getResource(1);
|
||||
try {
|
||||
Map<Integer, Map<String, String>> map = new HashMap<>();
|
||||
String pattern = "*," + id;
|
||||
|
||||
for (int index = 2; index < 6; index++) {
|
||||
resource.select(index);
|
||||
List<String> keyByScan = getKeyByScan(pattern, resource);
|
||||
for (String redisKey : keyByScan) {
|
||||
if (resource.exists(redisKey)) {
|
||||
|
||||
String statusMebmer = null;
|
||||
if (redisKey.startsWith("EFFECTIVE_RULE:")) {
|
||||
statusMebmer = redisKey.replace("EFFECTIVE_RULE:", "ADD,");
|
||||
} else if (redisKey.startsWith("OBSOLETE_RULE:")) {
|
||||
statusMebmer = redisKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||
}
|
||||
if (statusMebmer != null) {
|
||||
Double zscore = resource.zscore("MAAT_UPDATE_STATUS", statusMebmer);
|
||||
if (zscore != null) {
|
||||
Set<String> zrangeByScore = resource.zrangeByScore("MAAT_UPDATE_STATUS", zscore,
|
||||
zscore);
|
||||
for (String statusKey : zrangeByScore) {
|
||||
String replaceKey = null;
|
||||
if (statusKey.startsWith("ADD,")) {
|
||||
replaceKey = statusKey.replace("ADD,", "EFFECTIVE_RULE:");
|
||||
|
||||
} else if (statusKey.startsWith("DEL,")) {
|
||||
replaceKey = statusKey.replace("DEL,", "OBSOLETE_RULE:");
|
||||
}
|
||||
if (replaceKey != null) {
|
||||
String val = resource.get(replaceKey);
|
||||
if (val != null) {
|
||||
if (map.containsKey(index)) {
|
||||
Map<String, String> map2 = map.get(index);
|
||||
map2.put(replaceKey, val);
|
||||
} else {
|
||||
Map<String, String> map2 = new HashMap<>();
|
||||
map2.put(replaceKey, val);
|
||||
map.put(index, map2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return map;
|
||||
} finally {
|
||||
resource.close();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getKeyByScan(String pattern, Jedis resource) {
|
||||
List<String> list = new ArrayList<>();
|
||||
int count = 1000;
|
||||
String cursor = ScanParams.SCAN_POINTER_START;
|
||||
ScanParams scanParams = new ScanParams();
|
||||
scanParams.count(count);
|
||||
scanParams.match(pattern);
|
||||
do {
|
||||
ScanResult<String> scanResult = resource.scan(cursor, scanParams);
|
||||
list.addAll(scanResult.getResult());
|
||||
cursor = scanResult.getStringCursor();
|
||||
} while ("!0".equals(cursor));
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,16 +7,24 @@ import com.nis.domain.restful.MaatConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>Title: ConfigRedisService</p>
|
||||
* <p>Description: 保存配置到redis中</p>
|
||||
* <p>Company: IIE</p>
|
||||
* <p>
|
||||
* Title: ConfigRedisService
|
||||
* </p>
|
||||
* <p>
|
||||
* Description: 保存配置到redis中
|
||||
* </p>
|
||||
* <p>
|
||||
* Company: IIE
|
||||
* </p>
|
||||
*
|
||||
* @author rkg
|
||||
* @date 2018年5月17日
|
||||
* @date 2018年5月17日
|
||||
*
|
||||
*/
|
||||
public interface ConfigRedisService {
|
||||
/**
|
||||
* 下发非maat配置接口,key是redisDBIndex,value是配置集合
|
||||
*
|
||||
* @param configMap
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
@@ -24,6 +32,7 @@ public interface ConfigRedisService {
|
||||
|
||||
/**
|
||||
* 保存 maat配置接口,key是redisDBIndex,value是配置集合
|
||||
*
|
||||
* @param configMap
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
@@ -31,27 +40,32 @@ public interface ConfigRedisService {
|
||||
|
||||
/**
|
||||
* 分组复用域配置新增接口,value是配置集合
|
||||
*
|
||||
* @param configList
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
public boolean saveGroupReuseConfig( List<MaatConfig> configList);
|
||||
public boolean saveGroupReuseConfig(List<MaatConfig> configList);
|
||||
|
||||
/**
|
||||
* 获取指定key的自增长值
|
||||
*
|
||||
* @param key 需要自增的key
|
||||
* @return
|
||||
*/
|
||||
public Long getIncrId(String key);
|
||||
|
||||
/**
|
||||
* 批量获取接口,利用java进行遍历,比从redis中自增要快很多
|
||||
*
|
||||
* @param key
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public Long getIncrById(String key,int num);
|
||||
public Long getIncrById(String key, int num);
|
||||
|
||||
/**
|
||||
* 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合
|
||||
*
|
||||
* @param idMap
|
||||
* @param isInvalid 是否将配置置为无效
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
@@ -60,6 +74,7 @@ public interface ConfigRedisService {
|
||||
|
||||
/**
|
||||
* 删除maat类配置,key是业务类型,value是配置id集合
|
||||
*
|
||||
* @param serviceConfigMap
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
@@ -67,9 +82,17 @@ public interface ConfigRedisService {
|
||||
|
||||
/**
|
||||
* 删除分组复用的域配置
|
||||
*
|
||||
* @param reuseMap key是groupId,value是"tableName,regionId"
|
||||
* @return
|
||||
*/
|
||||
public boolean delGroupReuseConfig( Map<Long, List<String>> reuseMap);
|
||||
public boolean delGroupReuseConfig(Map<Long, List<String>> reuseMap);
|
||||
|
||||
/**
|
||||
* 根据配置id获取对应的编译,组,域等信息
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Map<Integer, Map<String, String>> getAllKVByCompileId(Long id);
|
||||
}
|
||||
|
||||
@@ -306,12 +306,12 @@ public class DashboardService extends BaseService{
|
||||
* 协议统计报表
|
||||
* @return
|
||||
*/
|
||||
public List<Map> getProtocolList(){
|
||||
public List<Map> getProtocolList(String startTime,String endTime){
|
||||
TrafficProtocolStatistic maxStatTime = trafficProtocolStatisticDao.getMaxStatTime();
|
||||
List<Map> list=new ArrayList<Map>();
|
||||
if(maxStatTime!=null&&maxStatTime.getStatTime()!=null) {
|
||||
Date statTime = maxStatTime.getStatTime();
|
||||
list = trafficProtocolStatisticDao.getProtocolList(statTime);
|
||||
list = trafficProtocolStatisticDao.getProtocolList(statTime,startTime,endTime);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -339,12 +339,12 @@ public class DashboardService extends BaseService{
|
||||
* App统计报表
|
||||
* @return
|
||||
*/
|
||||
public List<Map> getAppList(){
|
||||
public List<Map> getAppList(String startTime,String endTime){
|
||||
TrafficAppStatistic maxStatTime = trafficAppStatisticDao.getMaxStatTime();
|
||||
List<Map> list=new ArrayList<Map>();
|
||||
if(maxStatTime!=null&&maxStatTime.getStatTime()!=null) {
|
||||
Date statTime = maxStatTime.getStatTime();
|
||||
list = trafficAppStatisticDao.getAppList(statTime);
|
||||
list = trafficAppStatisticDao.getAppList(statTime,startTime,endTime);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user