1:修改证书类配置的表达式删除最后面的\n
2:修改redis连接池信息 3:修改获取配置id的方式,改为从程序中遍历,从redis中太耗时了 4:添加单独添加域,删除域使用多线程的方法
This commit is contained in:
@@ -211,4 +211,6 @@ public final class Constants {
|
|||||||
*是否使用Minio
|
*是否使用Minio
|
||||||
*/
|
*/
|
||||||
public static final Boolean IS_USE_MINIO = Configurations.getBooleanProperty("isUseMinio", true);
|
public static final Boolean IS_USE_MINIO = Configurations.getBooleanProperty("isUseMinio", true);
|
||||||
|
public static final int MAXTHREADNUM = Configurations.getIntProperty("maxThreadNum", 10);
|
||||||
|
public static final int EVERTHREADNUM = Configurations.getIntProperty("everThreadNum", 10000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ import com.nis.web.service.SpringContextHolder;
|
|||||||
public class JedisUtils {
|
public class JedisUtils {
|
||||||
private static Logger logger = LoggerFactory.getLogger(JedisUtils.class);
|
private static Logger logger = LoggerFactory.getLogger(JedisUtils.class);
|
||||||
private static JedisPool jedisPool = SpringContextHolder.getBean(JedisPool.class);
|
private static JedisPool jedisPool = SpringContextHolder.getBean(JedisPool.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存
|
* 获取缓存
|
||||||
* @param key 键
|
*
|
||||||
|
* @param key
|
||||||
|
* 键
|
||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
public static String get(String key, int redisDb) {
|
public static String get(String key, int redisDb) {
|
||||||
@@ -34,7 +35,8 @@ public class JedisUtils {
|
|||||||
logger.debug("get {} = {}", key, value);
|
logger.debug("get {} = {}", key, value);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
|
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败",
|
||||||
|
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||||
} finally {
|
} finally {
|
||||||
returnResource(jedis);
|
returnResource(jedis);
|
||||||
}
|
}
|
||||||
@@ -43,7 +45,9 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取缓存
|
* 获取缓存
|
||||||
* @param key 键
|
*
|
||||||
|
* @param key
|
||||||
|
* 键
|
||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
public static Object getObject(String key, int redisDb) {
|
public static Object getObject(String key, int redisDb) {
|
||||||
@@ -56,7 +60,8 @@ public class JedisUtils {
|
|||||||
logger.debug("getObject {} = {}", key, value);
|
logger.debug("getObject {} = {}", key, value);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
|
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败",
|
||||||
|
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||||
} finally {
|
} finally {
|
||||||
returnResource(jedis);
|
returnResource(jedis);
|
||||||
}
|
}
|
||||||
@@ -69,9 +74,10 @@ public class JedisUtils {
|
|||||||
*
|
*
|
||||||
* @param String
|
* @param String
|
||||||
* key
|
* key
|
||||||
* @param long number 要减去的值
|
* @param long
|
||||||
|
* number 要减去的值
|
||||||
* @return long 相加后的值
|
* @return long 相加后的值
|
||||||
* */
|
*/
|
||||||
public static long incrBy(String key, long number, int redisDb) {
|
public static long incrBy(String key, long number, int redisDb) {
|
||||||
Jedis jedis = getResource(redisDb);
|
Jedis jedis = getResource(redisDb);
|
||||||
long len = jedis.incrBy(key, number);
|
long len = jedis.incrBy(key, number);
|
||||||
@@ -81,9 +87,13 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置缓存
|
* 设置缓存
|
||||||
* @param key 键
|
*
|
||||||
* @param value 值
|
* @param key
|
||||||
* @param cacheSeconds 超时时间,0为不超时
|
* 键
|
||||||
|
* @param value
|
||||||
|
* 值
|
||||||
|
* @param cacheSeconds
|
||||||
|
* 超时时间,0为不超时
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String set(String key, String value, int cacheSeconds, int redisDb) {
|
public static String set(String key, String value, int cacheSeconds, int redisDb) {
|
||||||
@@ -97,7 +107,8 @@ public class JedisUtils {
|
|||||||
}
|
}
|
||||||
logger.debug("set {} = {}", key, value);
|
logger.debug("set {} = {}", key, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceRuntimeException("向" + redisDb + "号redisDB中设置zset失败,key=" + key + ",value=" + value, RestBusinessCode.ZsetFailed.getValue());
|
throw new ServiceRuntimeException("向" + redisDb + "号redisDB中设置zset失败,key=" + key + ",value=" + value,
|
||||||
|
RestBusinessCode.ZsetFailed.getValue());
|
||||||
} finally {
|
} finally {
|
||||||
returnResource(jedis);
|
returnResource(jedis);
|
||||||
}
|
}
|
||||||
@@ -106,7 +117,9 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取List缓存
|
* 获取List缓存
|
||||||
* @param key 键
|
*
|
||||||
|
* @param key
|
||||||
|
* 键
|
||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
public static List<String> getList(String key, int redisDb) {
|
public static List<String> getList(String key, int redisDb) {
|
||||||
@@ -119,7 +132,8 @@ public class JedisUtils {
|
|||||||
logger.debug("getList {} = {}", key, value);
|
logger.debug("getList {} = {}", key, value);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
|
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败",
|
||||||
|
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||||
} finally {
|
} finally {
|
||||||
returnResource(jedis);
|
returnResource(jedis);
|
||||||
}
|
}
|
||||||
@@ -128,7 +142,9 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取List缓存
|
* 获取List缓存
|
||||||
* @param key 键
|
*
|
||||||
|
* @param key
|
||||||
|
* 键
|
||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
public static List<Object> getObjectList(String key, int redisDb) {
|
public static List<Object> getObjectList(String key, int redisDb) {
|
||||||
@@ -145,7 +161,8 @@ public class JedisUtils {
|
|||||||
logger.debug("getObjectList {} = {}", key, value);
|
logger.debug("getObjectList {} = {}", key, value);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败", RestBusinessCode.KeyNotExistsInRedis.getValue());
|
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中获取" + key + "对应的值失败",
|
||||||
|
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||||
} finally {
|
} finally {
|
||||||
returnResource(jedis);
|
returnResource(jedis);
|
||||||
}
|
}
|
||||||
@@ -154,7 +171,9 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存是否存在
|
* 缓存是否存在
|
||||||
* @param key 键
|
*
|
||||||
|
* @param key
|
||||||
|
* 键
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean exists(String key, int redisDb) {
|
public static boolean exists(String key, int redisDb) {
|
||||||
@@ -165,7 +184,8 @@ public class JedisUtils {
|
|||||||
result = jedis.exists(key);
|
result = jedis.exists(key);
|
||||||
logger.debug("exists {}", key);
|
logger.debug("exists {}", key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中判断" + key + "是否存在失败", RestBusinessCode.ExistsKeyFailed.getValue());
|
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中判断" + key + "是否存在失败",
|
||||||
|
RestBusinessCode.ExistsKeyFailed.getValue());
|
||||||
} finally {
|
} finally {
|
||||||
returnResource(jedis);
|
returnResource(jedis);
|
||||||
}
|
}
|
||||||
@@ -174,7 +194,9 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存是否存在
|
* 缓存是否存在
|
||||||
* @param key 键
|
*
|
||||||
|
* @param key
|
||||||
|
* 键
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean existsObject(String key, int redisDb) {
|
public static boolean existsObject(String key, int redisDb) {
|
||||||
@@ -185,7 +207,8 @@ public class JedisUtils {
|
|||||||
result = jedis.exists(getBytesKey(key));
|
result = jedis.exists(getBytesKey(key));
|
||||||
logger.debug("existsObject {}", key);
|
logger.debug("existsObject {}", key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中判断" + key + "是否存在失败", RestBusinessCode.ExistsKeyFailed.getValue());
|
throw new ServiceRuntimeException("从" + redisDb + "号redisDB中判断" + key + "是否存在失败",
|
||||||
|
RestBusinessCode.ExistsKeyFailed.getValue());
|
||||||
} finally {
|
} finally {
|
||||||
returnResource(jedis);
|
returnResource(jedis);
|
||||||
}
|
}
|
||||||
@@ -194,20 +217,24 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取资源
|
* 获取资源
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
* @throws JedisException
|
* @throws JedisException
|
||||||
*/
|
*/
|
||||||
public static Jedis getResource(int redisDb) throws JedisException {
|
public static Jedis getResource(int redisDb) throws JedisException {
|
||||||
Jedis jedis = null;
|
Jedis jedis = null;
|
||||||
if (jedisPool == null) {
|
if (jedisPool == null) {
|
||||||
throw new ServiceRuntimeException("redis连接池为空,请联系管理员检查程序",RestBusinessCode.CannotConnectionRedis.getValue());
|
throw new ServiceRuntimeException("redis连接池为空,请联系管理员检查程序",
|
||||||
|
RestBusinessCode.CannotConnectionRedis.getValue());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
jedis = jedisPool.getResource();
|
jedis = jedisPool.getResource();
|
||||||
jedis.select(redisDb);
|
jedis.select(redisDb);
|
||||||
} catch (JedisException e) {
|
} catch (JedisException e) {
|
||||||
returnBrokenResource(jedis);
|
returnBrokenResource(jedis);
|
||||||
throw new ServiceRuntimeException("获取redis连接失败,请联系管理员检查程序", RestBusinessCode.CannotConnectionRedis.getValue());
|
logger.error("获取redis连接失败,异常信息:{}" ,ExceptionUtil.getExceptionMsg(e));
|
||||||
|
throw new ServiceRuntimeException("获取redis连接失败,请联系管理员检查程序",
|
||||||
|
RestBusinessCode.CannotConnectionRedis.getValue());
|
||||||
}
|
}
|
||||||
return jedis;
|
return jedis;
|
||||||
|
|
||||||
@@ -215,6 +242,7 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 归还资源
|
* 归还资源
|
||||||
|
*
|
||||||
* @param jedis
|
* @param jedis
|
||||||
* @param isBroken
|
* @param isBroken
|
||||||
*/
|
*/
|
||||||
@@ -226,6 +254,7 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 释放资源
|
* 释放资源
|
||||||
|
*
|
||||||
* @param jedis
|
* @param jedis
|
||||||
* @param isBroken
|
* @param isBroken
|
||||||
*/
|
*/
|
||||||
@@ -237,6 +266,7 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取byte[]类型Key
|
* 获取byte[]类型Key
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -250,6 +280,7 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Object转换byte[]类型
|
* Object转换byte[]类型
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -259,6 +290,7 @@ public class JedisUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* byte[]型转换Object
|
* byte[]型转换Object
|
||||||
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.nis.web.service.restful;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.nis.domain.MaatXmlExpr;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
import redis.clients.jedis.Transaction;
|
||||||
|
|
||||||
|
public class CommRegionThreadMethod {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(CommRegionThreadMethod.class);
|
||||||
|
|
||||||
|
protected void updateMaatInfoByPipelined(List<MaatXmlExpr> list, String maatKey, Pipeline pipelined,
|
||||||
|
Double maatVersion, 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) {
|
||||||
|
zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||||
|
} else {
|
||||||
|
zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
|
||||||
|
}
|
||||||
|
pipelined.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")) {
|
||||||
|
if (maatKey != null) {
|
||||||
|
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
|
||||||
|
pipelined.zadd("MAAT_RULE_TIMER", score, maatKey);
|
||||||
|
logger.info("向{}号redis数据库更新了MAAT_RULE_TIMER,内容是{},SCORES是{}", redisDBIndex, maatKey, score);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_VERSION_TIMER")) {
|
||||||
|
Long nowTime = new Date().getTime();
|
||||||
|
nowTime = nowTime / 1000l;
|
||||||
|
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
|
||||||
|
pipelined.zadd("MAAT_VERSION_TIMER", score, maatVersion + "");
|
||||||
|
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex, maatVersion, score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateMaatInfo(List<MaatXmlExpr> list, String maatKey, Transaction transaction, Double maatVersion,
|
||||||
|
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) {
|
||||||
|
zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||||
|
} else {
|
||||||
|
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")) {
|
||||||
|
if (maatKey != null) {
|
||||||
|
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
|
||||||
|
transaction.zadd("MAAT_RULE_TIMER", score, maatKey);
|
||||||
|
logger.info("向{}号redis数据库更新了MAAT_RULE_TIMER,内容是{},SCORES是{}", redisDBIndex, maatKey, score);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_VERSION_TIMER")) {
|
||||||
|
Long nowTime = new Date().getTime();
|
||||||
|
nowTime = nowTime / 1000l;
|
||||||
|
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
|
||||||
|
transaction.zadd("MAAT_VERSION_TIMER", score, maatVersion + "");
|
||||||
|
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex, maatVersion, score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,10 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -21,12 +25,15 @@ import com.nis.domain.restful.MaatConfig;
|
|||||||
import com.nis.restful.RestBusinessCode;
|
import com.nis.restful.RestBusinessCode;
|
||||||
import com.nis.restful.ServiceRuntimeException;
|
import com.nis.restful.ServiceRuntimeException;
|
||||||
import com.nis.util.Configurations;
|
import com.nis.util.Configurations;
|
||||||
|
import com.nis.util.Constants;
|
||||||
import com.nis.util.File2Redis;
|
import com.nis.util.File2Redis;
|
||||||
import com.nis.util.JedisUtils;
|
import com.nis.util.JedisUtils;
|
||||||
import com.nis.util.ReadMaatXmlUtil;
|
import com.nis.util.ReadMaatXmlUtil;
|
||||||
import com.nis.util.ServiceAndRDBIndexReal;
|
import com.nis.util.ServiceAndRDBIndexReal;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
import redis.clients.jedis.Response;
|
||||||
import redis.clients.jedis.Transaction;
|
import redis.clients.jedis.Transaction;
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
|
||||||
@@ -763,6 +770,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getIncrById(String key, int num) {
|
||||||
|
Long id = JedisUtils.incrBy(key, num, 0);
|
||||||
|
logger.info("从0号redis数据库获取{}成功,自增后的值是{}", key, id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap, boolean isInvalid) {
|
public boolean delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap, boolean isInvalid) {
|
||||||
if (idMap != null && idMap.size() > 0) {
|
if (idMap != null && idMap.size() > 0) {
|
||||||
@@ -1445,7 +1458,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addTmpReion(List<Map<String, String>> regionMapList, MaatXmlConfig maatXmlConfig,
|
private void addTmpReion(List<Map<String, String>> regionMapList, MaatXmlConfig maatXmlConfig,
|
||||||
Transaction transaction, int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex, Integer service1) {
|
Transaction transaction, int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex ) throws Exception {
|
||||||
|
|
||||||
if (regionMapList != null && regionMapList.size() > 0) {
|
if (regionMapList != null && regionMapList.size() > 0) {
|
||||||
for (Map<String, String> map : regionMapList) {
|
for (Map<String, String> map : regionMapList) {
|
||||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||||
@@ -1569,6 +1583,51 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addTmpReionByPipeLine(List<Map<String, String>> regionMapList, MaatXmlConfig maatXmlConfig,
|
||||||
|
Pipeline pipelined, int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) throws Exception {
|
||||||
|
if (regionMapList != null && regionMapList.size() > 0) {
|
||||||
|
int execNum = Constants.MAXTHREADNUM;
|
||||||
|
// 每10000条数据开启一条线程
|
||||||
|
int threadSize = Constants.EVERTHREADNUM;
|
||||||
|
// 总数据条数
|
||||||
|
int dataSize = regionMapList.size();
|
||||||
|
// 线程数
|
||||||
|
int countSize = dataSize / threadSize ;
|
||||||
|
// 定义标记,过滤threadNum为整数
|
||||||
|
boolean special = dataSize % threadSize == 0;
|
||||||
|
if (!special && dataSize > threadSize) {
|
||||||
|
countSize++;
|
||||||
|
}
|
||||||
|
if (countSize < execNum) {
|
||||||
|
execNum = countSize;
|
||||||
|
}
|
||||||
|
// 创建一个线程池
|
||||||
|
ExecutorService exec = Executors.newFixedThreadPool(execNum);
|
||||||
|
// 定义一个任务集合
|
||||||
|
List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
|
||||||
|
Callable<Integer> task = null;
|
||||||
|
List<Map<String, String>> cutList = null;
|
||||||
|
// 确定每条线程的数据
|
||||||
|
for (int i = 0; i < countSize; i++) {
|
||||||
|
cutList = regionMapList.subList(threadSize * i,
|
||||||
|
threadSize * (i + 1) > dataSize ? dataSize : threadSize * (i + 1));
|
||||||
|
final List<Map<String, String>> listStr = cutList;
|
||||||
|
task = new SaveRegionThreadByPipeline(listStr, maatXmlConfig, pipelined, type, tmpStorageReuseRegionDB,
|
||||||
|
idRelaRedisDBIndex);
|
||||||
|
// 这里提交的任务容器列表和返回的Future列表存在顺序对应的关系
|
||||||
|
tasks.add(task);
|
||||||
|
}
|
||||||
|
List<Future<Integer>> results;
|
||||||
|
results = exec.invokeAll(tasks);
|
||||||
|
// for (Future<Integer> future : results) {
|
||||||
|
// logger.info("SaveRegionThread添加分组复用域配置线程执行结果:" + future.get());
|
||||||
|
// }
|
||||||
|
// 关闭线程池
|
||||||
|
exec.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1587,11 +1646,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
for (MaatConfig maatConfig : configList) {
|
for (MaatConfig maatConfig : configList) {
|
||||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个
|
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个
|
||||||
addTmpReion(maatConfig.getIpRegionMapList(), maatXmlConfig, transaction, 12,
|
addTmpReion(maatConfig.getIpRegionMapList(), maatXmlConfig, transaction, 12,
|
||||||
tmpStorageReuseRegionDB, idRelaRedisDBIndex, maatConfig.getService());
|
tmpStorageReuseRegionDB, idRelaRedisDBIndex );
|
||||||
addTmpReion(maatConfig.getNumRegionMapList(), maatXmlConfig, transaction, 13,
|
addTmpReion(maatConfig.getNumRegionMapList(), maatXmlConfig, transaction, 13,
|
||||||
tmpStorageReuseRegionDB, idRelaRedisDBIndex, maatConfig.getService());
|
tmpStorageReuseRegionDB, idRelaRedisDBIndex );
|
||||||
addTmpReion(maatConfig.getStrRegionMapList(), maatXmlConfig, transaction, 14,
|
addTmpReion(maatConfig.getStrRegionMapList(), maatXmlConfig, transaction, 14,
|
||||||
tmpStorageReuseRegionDB, idRelaRedisDBIndex, maatConfig.getService());
|
tmpStorageReuseRegionDB, idRelaRedisDBIndex );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new ServiceRuntimeException("添加分组复用域配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
throw new ServiceRuntimeException("添加分组复用域配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
||||||
@@ -1614,6 +1673,56 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean saveGroupReuseConfigByPipeLine(List<MaatConfig> configList) {
|
||||||
|
Jedis resource = JedisUtils.getResource(0);
|
||||||
|
Pipeline pipelined = resource.pipelined();
|
||||||
|
try {
|
||||||
|
if (configList != null && configList.size() > 0) {
|
||||||
|
int tmpStorageReuseRegionDB = Configurations.getIntProperty("tmpStorageReuseRegionDB", 15);
|
||||||
|
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||||
|
pipelined.select(tmpStorageReuseRegionDB);
|
||||||
|
pipelined.multi();
|
||||||
|
for (MaatConfig maatConfig : configList) {
|
||||||
|
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个
|
||||||
|
addTmpReionByPipeLine(maatConfig.getIpRegionMapList(), maatXmlConfig, pipelined, 12,
|
||||||
|
tmpStorageReuseRegionDB, idRelaRedisDBIndex);
|
||||||
|
addTmpReionByPipeLine(maatConfig.getNumRegionMapList(), maatXmlConfig, pipelined, 13,
|
||||||
|
tmpStorageReuseRegionDB, idRelaRedisDBIndex);
|
||||||
|
addTmpReionByPipeLine(maatConfig.getStrRegionMapList(), maatXmlConfig, pipelined, 14,
|
||||||
|
tmpStorageReuseRegionDB, idRelaRedisDBIndex);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException("添加分组复用域配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
||||||
|
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||||
|
}
|
||||||
|
Response<List<Object>> exec = pipelined.exec();
|
||||||
|
pipelined.sync();// 关闭pipeline
|
||||||
|
// 结束pipeline,并开始从相应中获得数据
|
||||||
|
// List<Object> responses = exec.get();
|
||||||
|
// if (responses == null || responses.isEmpty()) {
|
||||||
|
// throw new RuntimeException("Pipeline error: no response...");
|
||||||
|
// }
|
||||||
|
// for (Object resp : responses) {
|
||||||
|
// System.out.println("Response:" + resp.toString());// 注意,此处resp的类型为Long
|
||||||
|
// }
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (JedisConnectionException e) {
|
||||||
|
String error = "连接redis异常,保存分组复用maat类域配置失败" + e.getMessage();
|
||||||
|
logger.error(error);
|
||||||
|
throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
String error = "保存分组复用maat类域配置发生了异常" + e.getMessage();
|
||||||
|
logger.error(error);
|
||||||
|
// pipelined.discard();
|
||||||
|
throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
|
||||||
|
} finally {
|
||||||
|
// 释放连接到连接池
|
||||||
|
JedisUtils.returnResource(resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加分组和域的关联关系
|
* 添加分组和域的关联关系
|
||||||
*
|
*
|
||||||
@@ -1836,6 +1945,52 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeReuseReionByPipelined(long groupId, List<String> regionList, Pipeline pipelined,
|
||||||
|
MaatXmlConfig maatXmlConfig, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) throws Exception {
|
||||||
|
if (regionList != null && regionList.size() > 0) {
|
||||||
|
int execNum = Constants.MAXTHREADNUM;
|
||||||
|
// 每10000条数据开启一条线程
|
||||||
|
int threadSize = Constants.EVERTHREADNUM;
|
||||||
|
// 总数据条数
|
||||||
|
int dataSize = regionList.size();
|
||||||
|
// 线程数
|
||||||
|
int countSize = dataSize / threadSize + 1;
|
||||||
|
// 定义标记,过滤threadNum为整数
|
||||||
|
boolean special = dataSize % threadSize == 0;
|
||||||
|
if (!special && dataSize > threadSize) {
|
||||||
|
countSize++;
|
||||||
|
}
|
||||||
|
if (countSize < execNum) {
|
||||||
|
execNum = countSize;
|
||||||
|
}
|
||||||
|
// 创建一个线程池
|
||||||
|
ExecutorService exec = Executors.newFixedThreadPool(execNum);
|
||||||
|
// 定义一个任务集合
|
||||||
|
List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
|
||||||
|
Callable<Integer> task = null;
|
||||||
|
List<String> cutList = null;
|
||||||
|
// 确定每条线程的数据
|
||||||
|
for (int i = 0; i < countSize; i++) {
|
||||||
|
cutList = regionList.subList(threadSize * i,
|
||||||
|
threadSize * (i + 1) > dataSize ? dataSize : threadSize * (i + 1));
|
||||||
|
final List<String> listStr = cutList;
|
||||||
|
task = new DelRegionThreadByPipeline(groupId, listStr, pipelined, maatXmlConfig, tmpStorageReuseRegionDB,
|
||||||
|
idRelaRedisDBIndex);
|
||||||
|
// 这里提交的任务容器列表和返回的Future列表存在顺序对应的关系
|
||||||
|
tasks.add(task);
|
||||||
|
}
|
||||||
|
List<Future<Integer>> results;
|
||||||
|
results = exec.invokeAll(tasks);
|
||||||
|
for (Future<Integer> future : results) {
|
||||||
|
logger.info("DelRegionThread删除分组复用域配置线程执行结果:" + future.get());
|
||||||
|
}
|
||||||
|
// 关闭线程池
|
||||||
|
exec.shutdown();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delGroupReuseConfig(Map<Long, List<String>> groupAndRegionMap) {
|
public boolean delGroupReuseConfig(Map<Long, List<String>> groupAndRegionMap) {
|
||||||
Jedis resource = JedisUtils.getResource(0);
|
Jedis resource = JedisUtils.getResource(0);
|
||||||
@@ -1876,6 +2031,52 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean delGroupReuseConfigByPipeline(Map<Long, List<String>> groupAndRegionMap) {
|
||||||
|
Jedis resource = JedisUtils.getResource(0);
|
||||||
|
Pipeline pipelined = resource.pipelined();
|
||||||
|
// Transaction transaction = resource.multi();
|
||||||
|
try {
|
||||||
|
if (groupAndRegionMap != null && groupAndRegionMap.size() > 0) {
|
||||||
|
int tmpStorageReuseRegionDB = Configurations.getIntProperty("tmpStorageReuseRegionDB", 15);
|
||||||
|
int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
|
||||||
|
pipelined.select(tmpStorageReuseRegionDB);
|
||||||
|
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个
|
||||||
|
for (Long groupId : groupAndRegionMap.keySet()) {
|
||||||
|
List<String> regionList = groupAndRegionMap.get(groupId);
|
||||||
|
if (regionList != null && regionList.size() > 0) {
|
||||||
|
removeReuseReionByPipelined(groupId, regionList, pipelined, maatXmlConfig,
|
||||||
|
tmpStorageReuseRegionDB, idRelaRedisDBIndex);
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException("删除分组复用域配置时,参数都为空,请检查配置参数是否正确",
|
||||||
|
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Response<List<Object>> exec = pipelined.exec();
|
||||||
|
pipelined.sync();// 关闭pipeline
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException("单独删除分组复用配置的域配置时,参数为空,请检查",
|
||||||
|
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JedisConnectionException e) {
|
||||||
|
String error = "连接redis异常,删除分组复用maat类域配置失败" + e.getMessage();
|
||||||
|
logger.error(error);
|
||||||
|
// pipelined.discard();
|
||||||
|
throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
|
||||||
|
} catch (Exception e) {
|
||||||
|
String error = "删除分组复用maat类域配置发生了异常" + e.getMessage();
|
||||||
|
logger.error(error);
|
||||||
|
// pipelined.discard();
|
||||||
|
throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
// 释放连接到连接池
|
||||||
|
JedisUtils.returnResource(resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加和删除时更新MAAT_*状态信息
|
* 添加和删除时更新MAAT_*状态信息
|
||||||
*
|
*
|
||||||
@@ -1917,9 +2118,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
|||||||
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex, maatVersion, score);
|
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex, maatVersion, score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package com.nis.web.service.restful;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -13,9 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.nis.domain.restful.ConfigPzIdSource;
|
import com.nis.domain.restful.ConfigPzIdSource;
|
||||||
import com.zdjizhi.utils.StringUtil;
|
|
||||||
import com.nis.web.dao.ConfigPzIdDao;
|
import com.nis.web.dao.ConfigPzIdDao;
|
||||||
import com.nis.web.service.BaseLogService;
|
import com.nis.web.service.BaseLogService;
|
||||||
|
import com.zdjizhi.utils.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName:ConfigPzIdService
|
* @ClassName:ConfigPzIdService
|
||||||
@@ -44,15 +45,34 @@ public class ConfigPzIdService extends BaseLogService {
|
|||||||
sourceNameMap.put("CONFIG_REGION", "SEQ_REGIONID");
|
sourceNameMap.put("CONFIG_REGION", "SEQ_REGIONID");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigPzIdSource getConfigPzIdList(ConfigPzIdSource entity){
|
public ConfigPzIdSource getConfigPzIdListOld(ConfigPzIdSource entity) {
|
||||||
List<Long> pzIdList = new ArrayList<Long>();
|
List<Long> pzIdList = new ArrayList<Long>();
|
||||||
entity.setSourceName(entity.getSourceName().toUpperCase());
|
entity.setSourceName(entity.getSourceName().toUpperCase());
|
||||||
String seqName= StringUtil.isEmpty(sourceNameMap.get(entity.getSourceName()))?"SEQ_COMPILEID":sourceNameMap.get(entity.getSourceName());
|
String seqName = StringUtil.isEmpty(sourceNameMap.get(entity.getSourceName())) ? "SEQ_COMPILEID"
|
||||||
|
: sourceNameMap.get(entity.getSourceName());
|
||||||
for (int i = 0; i < entity.getNum(); i++) {
|
for (int i = 0; i < entity.getNum(); i++) {
|
||||||
// pzIdList.add(dao.getConfigPzIdList(entity)); //直接从数据库序列号获取
|
// pzIdList.add(dao.getConfigPzIdList(entity)); //直接从数据库序列号获取
|
||||||
pzIdList.add(configRedisService.getIncrId(seqName));
|
pzIdList.add(configRedisService.getIncrId(seqName));
|
||||||
}
|
}
|
||||||
entity.setPzIdList(pzIdList);
|
entity.setPzIdList(pzIdList);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigPzIdSource getConfigPzIdList(ConfigPzIdSource entity) {
|
||||||
|
List<Long> pzIdList = new LinkedList<Long>();
|
||||||
|
entity.setSourceName(entity.getSourceName().toUpperCase());
|
||||||
|
String seqName = StringUtil.isEmpty(sourceNameMap.get(entity.getSourceName())) ? "SEQ_COMPILEID"
|
||||||
|
: sourceNameMap.get(entity.getSourceName());
|
||||||
|
long endNum = configRedisService.getIncrById(seqName, entity.getNum());
|
||||||
|
|
||||||
|
long startNum=endNum-entity.getNum();
|
||||||
|
|
||||||
|
for (long i = endNum; i > startNum; i--) {
|
||||||
|
// pzIdList.add(dao.getConfigPzIdList(entity)); //直接从数据库序列号获取
|
||||||
|
pzIdList.add(i);
|
||||||
|
}
|
||||||
|
entity.setPzIdList(pzIdList);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ public interface ConfigRedisService {
|
|||||||
* @return 成功返回true,失败返回false或抛出异常
|
* @return 成功返回true,失败返回false或抛出异常
|
||||||
*/
|
*/
|
||||||
public boolean saveGroupReuseConfig( List<MaatConfig> configList);
|
public boolean saveGroupReuseConfig( List<MaatConfig> configList);
|
||||||
|
/**
|
||||||
|
* 使用pipeline方式,分组复用域配置新增接口,value是配置集合
|
||||||
|
* @param configList
|
||||||
|
* @return 成功返回true,失败返回false或抛出异常
|
||||||
|
*/
|
||||||
|
public boolean saveGroupReuseConfigByPipeLine( List<MaatConfig> configList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定key的自增长值
|
* 获取指定key的自增长值
|
||||||
@@ -42,6 +48,13 @@ public interface ConfigRedisService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Long getIncrId(String key);
|
public Long getIncrId(String key);
|
||||||
|
/**
|
||||||
|
* 批量获取接口,利用java进行遍历,比从redis中自增要快很多
|
||||||
|
* @param key
|
||||||
|
* @param num
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Long getIncrById(String key,int num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合
|
* 删除非maat类配置,第一个key是redisDBIndex,第二个key是业务类型,value是配置id集合
|
||||||
@@ -64,5 +77,11 @@ public interface ConfigRedisService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean delGroupReuseConfig( Map<Long, List<String>> reuseMap);
|
public boolean delGroupReuseConfig( Map<Long, List<String>> reuseMap);
|
||||||
|
/**
|
||||||
|
* 使用pipeline方式删除分组复用的域配置
|
||||||
|
* @param reuseMap key是groupId,value是"tableName,regionId"
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean delGroupReuseConfigByPipeline( Map<Long, List<String>> reuseMap);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,13 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
|
import redis.clients.jedis.JedisPool;
|
||||||
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -871,6 +874,7 @@ public class ConfigSourcesService extends BaseService {
|
|||||||
// 调用接口入redis
|
// 调用接口入redis
|
||||||
logger.info("---------------调用Redis 分组复用配置新增接口---------------------");
|
logger.info("---------------调用Redis 分组复用配置新增接口---------------------");
|
||||||
configRedisService.saveGroupReuseConfig(list);
|
configRedisService.saveGroupReuseConfig(list);
|
||||||
|
// configRedisService.saveGroupReuseConfigByPipeLine(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -936,6 +940,7 @@ public class ConfigSourcesService extends BaseService {
|
|||||||
logger.info("调用接口删除Redis中分组复用的域配置接口");
|
logger.info("调用接口删除Redis中分组复用的域配置接口");
|
||||||
// 所有的都删除成功返回true
|
// 所有的都删除成功返回true
|
||||||
if (!configRedisService.delGroupReuseConfig(reuseMap)) {
|
if (!configRedisService.delGroupReuseConfig(reuseMap)) {
|
||||||
|
// if (!configRedisService.delGroupReuseConfigByPipeline(reuseMap)) {
|
||||||
throw new ServiceRuntimeException("删除分组利用域配置时出现异常,具体原因不详,请联系管理员",
|
throw new ServiceRuntimeException("删除分组利用域配置时出现异常,具体原因不详,请联系管理员",
|
||||||
RestBusinessCode.service_runtime_error.getValue());
|
RestBusinessCode.service_runtime_error.getValue());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package com.nis.web.service.restful;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.nis.domain.MaatXmlConfig;
|
||||||
|
import com.nis.restful.RestBusinessCode;
|
||||||
|
import com.nis.restful.ServiceRuntimeException;
|
||||||
|
import com.nis.util.JedisUtils;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class DelRegionThreadByPipeline extends CommRegionThreadMethod implements Callable<Integer> {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DelRegionThreadByPipeline.class);
|
||||||
|
|
||||||
|
long groupId;
|
||||||
|
List<String> regionList;
|
||||||
|
Pipeline pipelined;
|
||||||
|
MaatXmlConfig maatXmlConfig;
|
||||||
|
int tmpStorageReuseRegionDB;
|
||||||
|
int idRelaRedisDBIndex;
|
||||||
|
|
||||||
|
public DelRegionThreadByPipeline(long groupId, List<String> regionList, Pipeline pipelined, MaatXmlConfig maatXmlConfig,
|
||||||
|
int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) {
|
||||||
|
super();
|
||||||
|
this.groupId = groupId;
|
||||||
|
this.regionList = regionList;
|
||||||
|
this.pipelined = pipelined;
|
||||||
|
this.maatXmlConfig = maatXmlConfig;
|
||||||
|
this.tmpStorageReuseRegionDB = tmpStorageReuseRegionDB;
|
||||||
|
this.idRelaRedisDBIndex = idRelaRedisDBIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeReuseReionByPipelined(long groupId, List<String> regionList, Pipeline pipelined,
|
||||||
|
MaatXmlConfig maatXmlConfig, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) {
|
||||||
|
if (regionList != null && regionList.size() > 0) {
|
||||||
|
pipelined.select(tmpStorageReuseRegionDB);
|
||||||
|
for (String tableAndId : regionList) {
|
||||||
|
String regionKey = "EFFECTIVE_RULE:" + tableAndId;
|
||||||
|
if (JedisUtils.exists(regionKey, tmpStorageReuseRegionDB)) {
|
||||||
|
pipelined.del(regionKey);
|
||||||
|
String groupStr = "GROUPREGION:" + groupId;
|
||||||
|
String groupCompileVal = JedisUtils.get(groupStr, idRelaRedisDBIndex);
|
||||||
|
StringBuffer newGroupRegion = new StringBuffer();
|
||||||
|
|
||||||
|
if (groupCompileVal != null && !groupCompileVal.trim().equals("")) {
|
||||||
|
Set<Integer> redisDBSet = new HashSet<Integer>();
|
||||||
|
String[] split = groupCompileVal.split(";");
|
||||||
|
if (split != null && split.length > 0) {
|
||||||
|
for (String compileStr : split) {
|
||||||
|
if (compileStr.split("-")[0].equals(regionKey)) {
|
||||||
|
String[] dbArr = compileStr.split("-")[1].split(",");
|
||||||
|
for (String db : dbArr) {
|
||||||
|
if (db != null && !db.trim().equals("")) {
|
||||||
|
redisDBSet.add(Integer.parseInt(db.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (split.length == 1) {
|
||||||
|
pipelined.select(idRelaRedisDBIndex);
|
||||||
|
pipelined.del(groupStr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newGroupRegion.append(compileStr + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newGroupRegion.length() > 0) {
|
||||||
|
pipelined.select(idRelaRedisDBIndex);
|
||||||
|
pipelined.set(groupStr, newGroupRegion.substring(0, newGroupRegion.length() - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
for (Integer redisDb : redisDBSet) {
|
||||||
|
if (JedisUtils.exists(regionKey, redisDb)) {
|
||||||
|
pipelined.select(redisDb);
|
||||||
|
|
||||||
|
String isValidKey = regionKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||||
|
pipelined.rename(regionKey, isValidKey);
|
||||||
|
|
||||||
|
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb);
|
||||||
|
if (maatVersionStr == null) {
|
||||||
|
maatVersionStr = "0";
|
||||||
|
}
|
||||||
|
if (maatVersionStr != null) {
|
||||||
|
Double maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||||
|
updateMaatInfoByPipelined(maatXmlConfig.getExpressionList(), isValidKey, pipelined,
|
||||||
|
maatVersion, redisDb, true);
|
||||||
|
pipelined.incrBy("MAAT_VERSION", 1l);
|
||||||
|
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb,
|
||||||
|
Integer.valueOf(maatVersionStr) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException(
|
||||||
|
"从" + tmpStorageReuseRegionDB + "号redis库中删除分组复用域配置时,regionKey=" + regionKey
|
||||||
|
+ "不存在,请检查配置参数是否正确,或redis数据是否正确",
|
||||||
|
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException("临时存放region的" + tmpStorageReuseRegionDB + "号redis库中regionKey="
|
||||||
|
+ regionKey + "不存在,请检查配置参数是否正确", RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException("删除分组复用域配置时,参数都为空,请检查配置参数是否正确",
|
||||||
|
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer call() throws Exception {
|
||||||
|
removeReuseReionByPipelined(groupId, regionList, pipelined, maatXmlConfig, tmpStorageReuseRegionDB,
|
||||||
|
idRelaRedisDBIndex);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
187
src/main/java/com/nis/web/service/restful/SaveRegionThread.java
Normal file
187
src/main/java/com/nis/web/service/restful/SaveRegionThread.java
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
package com.nis.web.service.restful;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.nis.domain.MaatXmlConfig;
|
||||||
|
import com.nis.domain.MaatXmlExpr;
|
||||||
|
import com.nis.restful.RestBusinessCode;
|
||||||
|
import com.nis.restful.ServiceRuntimeException;
|
||||||
|
import com.nis.util.JedisUtils;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Transaction;
|
||||||
|
|
||||||
|
public class SaveRegionThread extends CommRegionThreadMethod implements Callable<Integer> {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(SaveRegionThread.class);
|
||||||
|
|
||||||
|
List<Map<String, String>> regionMapList;
|
||||||
|
MaatXmlConfig maatXmlConfig;
|
||||||
|
Transaction transaction;
|
||||||
|
int type;
|
||||||
|
int tmpStorageReuseRegionDB;
|
||||||
|
int idRelaRedisDBIndex;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public SaveRegionThread(List<Map<String, String>> regionMapList, MaatXmlConfig maatXmlConfig,
|
||||||
|
Transaction transaction, int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) {
|
||||||
|
super();
|
||||||
|
this.regionMapList = regionMapList;
|
||||||
|
this.maatXmlConfig = maatXmlConfig;
|
||||||
|
this.transaction = transaction;
|
||||||
|
this.type = type;
|
||||||
|
this.tmpStorageReuseRegionDB = tmpStorageReuseRegionDB;
|
||||||
|
this.idRelaRedisDBIndex = idRelaRedisDBIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addTmpReion(List<Map<String, String>> regionMapList, MaatXmlConfig maatXmlConfig,
|
||||||
|
Transaction transaction, int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) {
|
||||||
|
if (regionMapList != null && regionMapList.size() > 0) {
|
||||||
|
for (Map<String, String> map : regionMapList) {
|
||||||
|
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||||
|
String maatKey = null;
|
||||||
|
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||||
|
if (type == maatXmlExpr.getType().intValue()) {
|
||||||
|
StringBuffer keyBF = new StringBuffer();
|
||||||
|
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||||
|
for (String keyStr : keySplit) {
|
||||||
|
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||||
|
keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||||
|
String keyVal = map.get(keyStr);
|
||||||
|
if (keyVal != null && !keyVal.equals("")) {
|
||||||
|
keyBF.append(keyVal);
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException("未从map中获取到" + keyStr + "的值,请检查数据或配置文件是否正确",
|
||||||
|
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||||
|
}
|
||||||
|
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||||
|
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||||
|
if (keyStr.toLowerCase().contains("table_name")) {
|
||||||
|
String argTableName = map.get("table_name");
|
||||||
|
if (argTableName == null) {
|
||||||
|
throw new ServiceRuntimeException(
|
||||||
|
"添加分组复用域配置时,必须要传入表名,请检查参数,配置类型:" + type + ",对应的真实表名",
|
||||||
|
RestBusinessCode.NotFoundTableName.getValue());
|
||||||
|
} else {
|
||||||
|
keyBF.append(argTableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
keyBF.append(keyStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String groupId = null;
|
||||||
|
StringBuffer valBF = new StringBuffer();
|
||||||
|
String[] valSplit = maatXmlExpr.getValueExpression().split(";");
|
||||||
|
for (String valStr : valSplit) {
|
||||||
|
if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) {
|
||||||
|
valStr = valStr.trim().replace("[", "").replace("]", "");
|
||||||
|
// if (service != null && service.intValue() == 1028
|
||||||
|
// && valStr.toLowerCase().equals("op_time") && type == 12) {
|
||||||
|
if (valStr.toLowerCase().equals("op_time") && type == 12) {
|
||||||
|
String user_region = map.get("user_region");
|
||||||
|
valBF.append(user_region + "\t");
|
||||||
|
}
|
||||||
|
String val = map.get(valStr);
|
||||||
|
if (val != null) {
|
||||||
|
valBF.append(val);
|
||||||
|
if (valStr.equals("group_id")) {
|
||||||
|
groupId = val;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 所有在maat.xml中配置的属性都不可以为空
|
||||||
|
throw new ServiceRuntimeException(
|
||||||
|
"未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据或配置文件是否正确",
|
||||||
|
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (valStr.equals(" ")) {
|
||||||
|
valBF.append(" ");
|
||||||
|
} else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
|
||||||
|
valBF.append("\t");
|
||||||
|
} else if (valStr.equals("\\n")) {
|
||||||
|
valBF.append("\n");
|
||||||
|
} else {
|
||||||
|
valBF.append(valStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transaction.select(tmpStorageReuseRegionDB);
|
||||||
|
maatKey = keyBF.toString();
|
||||||
|
transaction.set(maatKey.toUpperCase(), valBF.toString());
|
||||||
|
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", tmpStorageReuseRegionDB,
|
||||||
|
maatKey.toUpperCase(), valBF.toString());
|
||||||
|
|
||||||
|
String groupIdStr = "GROUPCOMPILE:" + groupId;
|
||||||
|
String groupCompileVal = JedisUtils.get(groupIdStr, idRelaRedisDBIndex);
|
||||||
|
if (groupCompileVal != null && !groupCompileVal.trim().equals("")) {
|
||||||
|
Set<Integer> redisDBSet = new HashSet<Integer>();
|
||||||
|
String[] split = groupCompileVal.split(";");
|
||||||
|
if (split != null && split.length > 0) {
|
||||||
|
for (String compileStr : split) {
|
||||||
|
String[] dbArr = compileStr.split("-")[1].split(",");
|
||||||
|
for (String db : dbArr) {
|
||||||
|
if (db != null && !db.trim().equals("")) {
|
||||||
|
redisDBSet.add(Integer.parseInt(db.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String groupRegionStr = "GROUPREGION:" + groupId;
|
||||||
|
String regionVal = JedisUtils.get(groupIdStr, idRelaRedisDBIndex);
|
||||||
|
if (regionVal != null && !regionVal.trim().equals("")) {
|
||||||
|
transaction.append(groupRegionStr, ";" + maatKey.toUpperCase() + "-"
|
||||||
|
+ redisDBSet.toString().replace("[", "").replace("]", ""));
|
||||||
|
} else {
|
||||||
|
transaction.set(groupRegionStr, maatKey.toUpperCase() + "-"
|
||||||
|
+ redisDBSet.toString().replace("[", "").replace("]", ""));
|
||||||
|
}
|
||||||
|
for (Integer redisDb : redisDBSet) {
|
||||||
|
transaction.select(redisDb);
|
||||||
|
transaction.set(maatKey.toUpperCase(), valBF.toString());
|
||||||
|
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", redisDb, maatKey.toUpperCase(),
|
||||||
|
valBF.toString());
|
||||||
|
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb);
|
||||||
|
if (maatVersionStr == null) {
|
||||||
|
maatVersionStr = "0";
|
||||||
|
}
|
||||||
|
if (maatVersionStr != null) {
|
||||||
|
Double maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||||
|
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDb, false);
|
||||||
|
transaction.incrBy("MAAT_VERSION", 1l);
|
||||||
|
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb,
|
||||||
|
Integer.valueOf(maatVersionStr) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// addTmpReionByPipeLine(regionMapList, maatXmlConfig, pipelined, type,
|
||||||
|
// tmpStorageReuseRegionDB,
|
||||||
|
// idRelaRedisDBIndex);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer call() throws Exception {
|
||||||
|
addTmpReion( regionMapList, maatXmlConfig,
|
||||||
|
transaction, type, tmpStorageReuseRegionDB, idRelaRedisDBIndex);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
package com.nis.web.service.restful;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import com.nis.domain.MaatXmlConfig;
|
||||||
|
import com.nis.domain.MaatXmlExpr;
|
||||||
|
import com.nis.restful.RestBusinessCode;
|
||||||
|
import com.nis.restful.ServiceRuntimeException;
|
||||||
|
import com.nis.util.JedisUtils;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Pipeline;
|
||||||
|
|
||||||
|
public class SaveRegionThreadByPipeline extends CommRegionThreadMethod implements Callable<Integer>{
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(SaveRegionThreadByPipeline.class);
|
||||||
|
|
||||||
|
List<Map<String, String>> regionMapList;
|
||||||
|
MaatXmlConfig maatXmlConfig;
|
||||||
|
Pipeline pipelined;
|
||||||
|
int type;
|
||||||
|
int tmpStorageReuseRegionDB;
|
||||||
|
int idRelaRedisDBIndex;
|
||||||
|
|
||||||
|
public SaveRegionThreadByPipeline(List<Map<String, String>> regionMapList, MaatXmlConfig maatXmlConfig,
|
||||||
|
Pipeline pipelined, int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) {
|
||||||
|
super();
|
||||||
|
this.regionMapList = regionMapList;
|
||||||
|
this.maatXmlConfig = maatXmlConfig;
|
||||||
|
this.pipelined = pipelined;
|
||||||
|
this.type = type;
|
||||||
|
this.tmpStorageReuseRegionDB = tmpStorageReuseRegionDB;
|
||||||
|
this.idRelaRedisDBIndex = idRelaRedisDBIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addTmpReionByPipeLine(List<Map<String, String>> regionMapList, MaatXmlConfig maatXmlConfig,
|
||||||
|
Pipeline pipelined, int type, int tmpStorageReuseRegionDB, int idRelaRedisDBIndex) {
|
||||||
|
if (regionMapList != null && regionMapList.size() > 0) {
|
||||||
|
for (Map<String, String> map : regionMapList) {
|
||||||
|
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||||
|
String maatKey = null;
|
||||||
|
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||||
|
if (type == maatXmlExpr.getType().intValue()) {
|
||||||
|
StringBuffer keyBF = new StringBuffer();
|
||||||
|
String[] keySplit = maatXmlExpr.getKeyExpression().split(";");
|
||||||
|
for (String keyStr : keySplit) {
|
||||||
|
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||||
|
keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||||
|
String keyVal = map.get(keyStr);
|
||||||
|
if (keyVal != null && !keyVal.equals("")) {
|
||||||
|
keyBF.append(keyVal);
|
||||||
|
} else {
|
||||||
|
throw new ServiceRuntimeException("未从map中获取到" + keyStr + "的值,请检查数据或配置文件是否正确",
|
||||||
|
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||||
|
}
|
||||||
|
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||||
|
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||||
|
if (keyStr.toLowerCase().contains("table_name")) {
|
||||||
|
String argTableName = map.get("table_name");
|
||||||
|
if (argTableName == null) {
|
||||||
|
throw new ServiceRuntimeException(
|
||||||
|
"添加分组复用域配置时,必须要传入表名,请检查参数,配置类型:" + type + ",对应的真实表名",
|
||||||
|
RestBusinessCode.NotFoundTableName.getValue());
|
||||||
|
} else {
|
||||||
|
keyBF.append(argTableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
keyBF.append(keyStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String groupId = null;
|
||||||
|
StringBuffer valBF = new StringBuffer();
|
||||||
|
String[] valSplit = maatXmlExpr.getValueExpression().split(";");
|
||||||
|
for (String valStr : valSplit) {
|
||||||
|
if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) {
|
||||||
|
valStr = valStr.trim().replace("[", "").replace("]", "");
|
||||||
|
// if (service != null && service.intValue() == 1028
|
||||||
|
// && valStr.toLowerCase().equals("op_time") && type == 12) {
|
||||||
|
if (valStr.toLowerCase().equals("op_time") && type == 12) {
|
||||||
|
String user_region = map.get("user_region");
|
||||||
|
valBF.append(user_region + "\t");
|
||||||
|
}
|
||||||
|
String val = map.get(valStr);
|
||||||
|
if (val != null) {
|
||||||
|
valBF.append(val);
|
||||||
|
if (valStr.equals("group_id")) {
|
||||||
|
groupId = val;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 所有在maat.xml中配置的属性都不可以为空
|
||||||
|
throw new ServiceRuntimeException(
|
||||||
|
"未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据或配置文件是否正确",
|
||||||
|
RestBusinessCode.NotFoundValueByKey.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (valStr.equals(" ")) {
|
||||||
|
valBF.append(" ");
|
||||||
|
} else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
|
||||||
|
valBF.append("\t");
|
||||||
|
} else if (valStr.equals("\\n")) {
|
||||||
|
valBF.append("\n");
|
||||||
|
} else {
|
||||||
|
valBF.append(valStr.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pipelined.select(tmpStorageReuseRegionDB);
|
||||||
|
maatKey = keyBF.toString();
|
||||||
|
pipelined.set(maatKey.toUpperCase(), valBF.toString());
|
||||||
|
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", tmpStorageReuseRegionDB,
|
||||||
|
maatKey.toUpperCase(), valBF.toString());
|
||||||
|
|
||||||
|
String groupIdStr = "GROUPCOMPILE:" + groupId;
|
||||||
|
String groupCompileVal = JedisUtils.get(groupIdStr, idRelaRedisDBIndex);
|
||||||
|
if (groupCompileVal != null && !groupCompileVal.trim().equals("")) {
|
||||||
|
Set<Integer> redisDBSet = new HashSet<Integer>();
|
||||||
|
String[] split = groupCompileVal.split(";");
|
||||||
|
if (split != null && split.length > 0) {
|
||||||
|
for (String compileStr : split) {
|
||||||
|
String[] dbArr = compileStr.split("-")[1].split(",");
|
||||||
|
for (String db : dbArr) {
|
||||||
|
if (db != null && !db.trim().equals("")) {
|
||||||
|
redisDBSet.add(Integer.parseInt(db.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String groupRegionStr = "GROUPREGION:" + groupId;
|
||||||
|
String regionVal = JedisUtils.get(groupIdStr, idRelaRedisDBIndex);
|
||||||
|
if (regionVal != null && !regionVal.trim().equals("")) {
|
||||||
|
pipelined.append(groupRegionStr, ";" + maatKey.toUpperCase() + "-"
|
||||||
|
+ redisDBSet.toString().replace("[", "").replace("]", ""));
|
||||||
|
} else {
|
||||||
|
pipelined.set(groupRegionStr, maatKey.toUpperCase() + "-"
|
||||||
|
+ redisDBSet.toString().replace("[", "").replace("]", ""));
|
||||||
|
}
|
||||||
|
for (Integer redisDb : redisDBSet) {
|
||||||
|
pipelined.select(redisDb);
|
||||||
|
pipelined.set(maatKey.toUpperCase(), valBF.toString());
|
||||||
|
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", redisDb, maatKey.toUpperCase(),
|
||||||
|
valBF.toString());
|
||||||
|
String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb);
|
||||||
|
if (maatVersionStr == null) {
|
||||||
|
maatVersionStr = "0";
|
||||||
|
}
|
||||||
|
if (maatVersionStr != null) {
|
||||||
|
Double maatVersion = Double.valueOf(maatVersionStr) + 1D;
|
||||||
|
updateMaatInfoByPipelined(expressionList, maatKey, pipelined, maatVersion, redisDb,
|
||||||
|
false);
|
||||||
|
pipelined.incrBy("MAAT_VERSION", 1l);
|
||||||
|
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb,
|
||||||
|
Integer.valueOf(maatVersionStr) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void run() {
|
||||||
|
// addTmpReionByPipeLine(regionMapList, maatXmlConfig, pipelined, type, tmpStorageReuseRegionDB,
|
||||||
|
// idRelaRedisDBIndex);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer call() throws Exception {
|
||||||
|
addTmpReionByPipeLine(regionMapList, maatXmlConfig, pipelined, type, tmpStorageReuseRegionDB,
|
||||||
|
idRelaRedisDBIndex);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
|
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
|
||||||
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
|
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
|
||||||
<property name="testOnReturn" value="${redis.testOnReturn}" />
|
<property name="testOnReturn" value="${redis.testOnReturn}" />
|
||||||
|
<!-- <property name="timeOut" value="${redis.timeout}" /> -->
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
|
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
|
||||||
@@ -31,6 +32,10 @@
|
|||||||
<constructor-arg name="host" value="${redis.host}" />
|
<constructor-arg name="host" value="${redis.host}" />
|
||||||
<constructor-arg name="port" value="${redis.port}"
|
<constructor-arg name="port" value="${redis.port}"
|
||||||
type="int" />
|
type="int" />
|
||||||
|
<constructor-arg name="timeout" value="${redis.timeout}"
|
||||||
|
type="int" />
|
||||||
|
<!-- <constructor-arg name="password" value="${redis.pass}"/> -->
|
||||||
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ jdbc.log.driver=com.mysql.jdbc.Driver
|
|||||||
#华严
|
#华严
|
||||||
#jdbc.log.url=jdbc:mysql://192.168.11.242:3306/galaxy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
#jdbc.log.url=jdbc:mysql://192.168.11.242:3306/galaxy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
||||||
#元辰鑫外网-开发环境
|
#元辰鑫外网-开发环境
|
||||||
jdbc.log.url=jdbc:mysql://192.168.10.204:3306/galaxy-dev?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
#jdbc.log.url=jdbc:mysql://192.168.10.204:3306/galaxy-dev?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
||||||
#元辰鑫外网
|
#元辰鑫外网
|
||||||
#jdbc.log.url=jdbc:mysql://192.168.10.204:3306/galaxy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
jdbc.log.url=jdbc:mysql://192.168.10.204:3306/galaxy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
||||||
#亦庄演示环境
|
#亦庄演示环境
|
||||||
#jdbc.log.url=jdbc:mysql://10.3.48.5:3306/galaxy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
#jdbc.log.url=jdbc:mysql://10.3.48.5:3306/galaxy?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
|
||||||
jdbc.log.username=root
|
jdbc.log.username=root
|
||||||
@@ -145,6 +145,8 @@ druid.log.filters=stat
|
|||||||
#########################################################################
|
#########################################################################
|
||||||
##minio地址
|
##minio地址
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
##亦庄测试地址,注意前面的http://不要忘记写
|
||||||
|
#minio_url=http://10.3.48.2:9001
|
||||||
##华严minio的地址,注意前面的http://不要忘记写
|
##华严minio的地址,注意前面的http://不要忘记写
|
||||||
#minio_url=http://192.168.10.61:9000
|
#minio_url=http://192.168.10.61:9000
|
||||||
##元辰鑫外网minio的地址,注意前面的http://不要忘记写
|
##元辰鑫外网minio的地址,注意前面的http://不要忘记写
|
||||||
@@ -175,10 +177,15 @@ redis.host=192.168.10.12
|
|||||||
#redis.host=10.3.34.1
|
#redis.host=10.3.34.1
|
||||||
redis.port=6379
|
redis.port=6379
|
||||||
redis.pass=
|
redis.pass=
|
||||||
redis.maxIdle=5
|
#最大空闲连接数
|
||||||
|
redis.maxIdle=50
|
||||||
|
#最大连接数
|
||||||
redis.maxTotal=250
|
redis.maxTotal=250
|
||||||
|
#获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
|
||||||
redis.maxWaitMillis=100000
|
redis.maxWaitMillis=100000
|
||||||
|
#在获取连接的时候检查有效性
|
||||||
redis.testOnBorrow=true
|
redis.testOnBorrow=true
|
||||||
|
#在归还连接的时候检查有效性
|
||||||
redis.testOnReturn=true
|
redis.testOnReturn=true
|
||||||
#客户端超时时间单位是毫秒
|
#客户端超时时间单位是毫秒
|
||||||
redis.timeout=100000
|
redis.timeout=100000
|
||||||
|
|||||||
@@ -161,7 +161,7 @@
|
|||||||
<p:maatType service="520">
|
<p:maatType service="520">
|
||||||
<p:expressions>
|
<p:expressions>
|
||||||
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
||||||
<p:valueExpression>[cfg_id];\t;[service];\t;[keyring_name];\t;[keyring_type];\t;[private_key_file];\t;[public_key_file];\t;[expire_after];\t;[public_key_algo];\t;[crl];\t;[is_valid];\t;[redisFile_private_key_file];\t;[redisFile_public_key_file];\t;[op_time];&nbsp;0;\n</p:valueExpression>
|
<p:valueExpression>[cfg_id];\t;[service];\t;[keyring_name];\t;[keyring_type];\t;[private_key_file];\t;[public_key_file];\t;[expire_after];\t;[public_key_algo];\t;[crl];\t;[is_valid];\t;[redisFile_private_key_file];\t;[redisFile_public_key_file];\t;[op_time];&nbsp;0</p:valueExpression>
|
||||||
</p:expressions>
|
</p:expressions>
|
||||||
<p:sequences>
|
<p:sequences>
|
||||||
<p:operation>1</p:operation>
|
<p:operation>1</p:operation>
|
||||||
@@ -181,7 +181,7 @@
|
|||||||
<p:maatType service="608">
|
<p:maatType service="608">
|
||||||
<p:expressions>
|
<p:expressions>
|
||||||
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
||||||
<p:valueExpression>[cfg_id];\t;[service];\t;[file_desc];\t;[content_type];\t;[content_length];\t;[file_path];\t;[is_valid];\t;[redisFile_file_path];\t;[op_time];&nbsp;0;\n</p:valueExpression>
|
<p:valueExpression>[cfg_id];\t;[service];\t;[file_desc];\t;[content_type];\t;[content_length];\t;[file_path];\t;[is_valid];\t;[redisFile_file_path];\t;[op_time];&nbsp;0</p:valueExpression>
|
||||||
</p:expressions>
|
</p:expressions>
|
||||||
<p:sequences>
|
<p:sequences>
|
||||||
<p:operation>1</p:operation>
|
<p:operation>1</p:operation>
|
||||||
@@ -203,7 +203,7 @@
|
|||||||
<p:maatType service="640">
|
<p:maatType service="640">
|
||||||
<p:expressions>
|
<p:expressions>
|
||||||
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
||||||
<p:valueExpression>[cfg_id];\t;[cert_name];\t;[cert_file];\t;[is_valid];\t;[redisFile_private_cert_file];\t;[service];\t;[op_time];&nbsp;0;\n</p:valueExpression>
|
<p:valueExpression>[cfg_id];\t;[cert_name];\t;[redisFile_private_cert_file];\t;[is_valid];\t;[service];\t;[op_time];&nbsp;0</p:valueExpression>
|
||||||
</p:expressions>
|
</p:expressions>
|
||||||
<p:sequences>
|
<p:sequences>
|
||||||
<p:operation>1</p:operation>
|
<p:operation>1</p:operation>
|
||||||
@@ -224,7 +224,7 @@
|
|||||||
<p:maatType service="641">
|
<p:maatType service="641">
|
||||||
<p:expressions>
|
<p:expressions>
|
||||||
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
<p:keyExpression>EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id]</p:keyExpression>
|
||||||
<p:valueExpression>[cfg_id];\t;[cert_id];\t;[crl_file];\t;[is_valid];\t;[redisFile_private_crl_file];\t;[service];\t;[op_time];&nbsp;0;\n</p:valueExpression>
|
<p:valueExpression>[cfg_id];\t;[cert_id];\t;[redisFile_private_crl_file];\t;[is_valid];\t;[service];\t;[op_time];&nbsp;0</p:valueExpression>
|
||||||
</p:expressions>
|
</p:expressions>
|
||||||
<p:sequences>
|
<p:sequences>
|
||||||
<p:operation>1</p:operation>
|
<p:operation>1</p:operation>
|
||||||
|
|||||||
@@ -213,3 +213,8 @@ fileProtocol=redis://
|
|||||||
#是否开启日志查询count和last功能
|
#是否开启日志查询count和last功能
|
||||||
isOpenLogCountAndLast=true
|
isOpenLogCountAndLast=true
|
||||||
|
|
||||||
|
#定义单独添加域与删除域开启的最大线程数
|
||||||
|
maxThreadNum=20
|
||||||
|
#每个线程处理多少条数据
|
||||||
|
everThreadNum=500
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user