Merge branch 'develop' of http://10.0.6.99/common/maat_service.git into develop
This commit is contained in:
@@ -14,17 +14,17 @@ public class GroupAndRegionRelations implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Long groupId;
|
||||
private Long regionId;
|
||||
private String regionId;
|
||||
public Long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
public void setGroupId(Long groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
public Long getRegionId() {
|
||||
public String getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
public void setRegionId(Long regionId) {
|
||||
public void setRegionId(String regionId) {
|
||||
this.regionId = regionId;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MaatRelation implements Serializable {
|
||||
/**
|
||||
* groupid与regionid的对应关系,key是groupid,value使用set不允许重复
|
||||
*/
|
||||
private Map<Long, Set<Long>> groupAndRegionMap;
|
||||
private Map<Long, Set<String>> groupAndRegionMap;
|
||||
|
||||
public Map<Long, Set<Long>> getCompileAndGroupMap() {
|
||||
return compileAndGroupMap;
|
||||
@@ -49,11 +49,11 @@ public class MaatRelation implements Serializable {
|
||||
this.groupAndCompileMap = groupAndCompileMap;
|
||||
}
|
||||
|
||||
public Map<Long, Set<Long>> getGroupAndRegionMap() {
|
||||
public Map<Long, Set<String>> getGroupAndRegionMap() {
|
||||
return groupAndRegionMap;
|
||||
}
|
||||
|
||||
public void setGroupAndRegionMap(Map<Long, Set<Long>> groupAndRegionMap) {
|
||||
public void setGroupAndRegionMap(Map<Long, Set<String>> groupAndRegionMap) {
|
||||
this.groupAndRegionMap = groupAndRegionMap;
|
||||
}
|
||||
|
||||
@@ -120,10 +120,10 @@ public class MaatRelation implements Serializable {
|
||||
System.out.println("组:" + group + "编译:" + compile);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
Map<Long, Set<String>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
for (Long group : getGroupAndRegionMap.keySet()) {
|
||||
Set<Long> regionList = getGroupAndRegionMap.get(group);
|
||||
for (Long region : regionList) {
|
||||
Set<String> regionList = getGroupAndRegionMap.get(group);
|
||||
for (String region : regionList) {
|
||||
System.out.println("组:" + group + "域:" + region);
|
||||
}
|
||||
}
|
||||
@@ -162,12 +162,12 @@ public class MaatRelation implements Serializable {
|
||||
List<GroupAndRegionRelations> groupIdList = new ArrayList<GroupAndRegionRelations>();
|
||||
GroupAndRegionRelations gRR = new GroupAndRegionRelations();
|
||||
gRR.setGroupId(100L);
|
||||
gRR.setRegionId(200L);
|
||||
gRR.setRegionId("200");
|
||||
groupIdList.add(gRR);
|
||||
|
||||
gRR = new GroupAndRegionRelations();
|
||||
gRR.setGroupId(100L);
|
||||
gRR.setRegionId(300L);
|
||||
gRR.setRegionId("300");
|
||||
groupIdList.add(gRR);
|
||||
cGR.setGroupIdList(groupIdList);
|
||||
return cGR;
|
||||
@@ -200,10 +200,10 @@ public class MaatRelation implements Serializable {
|
||||
groupAndCompileMap2.get(gRR.getGroupId()).add(compileId);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||
Map<Long, Set<String>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap2 != null && groupAndRegionMap2.size() > 0) {
|
||||
if (!groupAndRegionMap2.containsKey(gRR.getGroupId())) {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
Set<String> set = new HashSet<String>();
|
||||
set.add(gRR.getRegionId());
|
||||
groupAndRegionMap2.put(gRR.getGroupId(), set);
|
||||
} else {
|
||||
@@ -230,11 +230,11 @@ public class MaatRelation implements Serializable {
|
||||
list.add(2l);
|
||||
groupAndCompileMap.put(1l, list);
|
||||
// Map<Long, List<Long>> regionAndGroupMap = new HashMap<Long, List<Long>>();
|
||||
list = new HashSet<Long>();
|
||||
list.add(1l);
|
||||
Set<String> list2 = new HashSet<String>();
|
||||
list2.add("1");
|
||||
// regionAndGroupMap.put(1l, list);
|
||||
Map<Long, Set<Long>> groupAndRegionMap = new HashMap<Long, Set<Long>>();
|
||||
groupAndRegionMap.put(1l, list);
|
||||
Map<Long, Set<String>> groupAndRegionMap = new HashMap<Long, Set<String>>();
|
||||
groupAndRegionMap.put(1l, list2);
|
||||
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
|
||||
private void getAllId(RedisTemplate<String, String> redisTemplate, int redisDBIndex) {
|
||||
Map<Long, Set<Long>> groupCompileIdMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Map<Long, Set<Long>> groupRegionIdMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Map<Long, Set<String>> groupRegionIdMap = new ConcurrentHashMap<Long, Set<String>>();
|
||||
Set<String> keySet = redisTemplate.keys("EFFECTIVE_RULE:*");
|
||||
if (keySet != null && keySet.size() > 0) {
|
||||
for (String keys : keySet) {
|
||||
@@ -66,14 +66,24 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
}
|
||||
|
||||
} else {
|
||||
// String[] split = value.split("\t");
|
||||
// String regionIdStr = split[0];
|
||||
// String groupIdStr = split[1];
|
||||
// if (groupRegionIdMap.containsKey(Long.valueOf(groupIdStr))) {
|
||||
// groupRegionIdMap.get(Long.valueOf(groupIdStr)).add(Long.valueOf(regionIdStr));
|
||||
// } else {
|
||||
// Set<Long> list = new HashSet<Long>();
|
||||
// list.add(Long.valueOf(regionIdStr));
|
||||
// groupRegionIdMap.put(Long.valueOf(groupIdStr), list);
|
||||
// }
|
||||
String[] split = value.split("\t");
|
||||
String regionIdStr = split[0];
|
||||
//String regionIdStr = split[0];
|
||||
String groupIdStr = split[1];
|
||||
if (groupRegionIdMap.containsKey(Long.valueOf(groupIdStr))) {
|
||||
groupRegionIdMap.get(Long.valueOf(groupIdStr)).add(Long.valueOf(regionIdStr));
|
||||
groupRegionIdMap.get(Long.valueOf(groupIdStr)).add(keys);
|
||||
} else {
|
||||
Set<Long> list = new HashSet<Long>();
|
||||
list.add(Long.valueOf(regionIdStr));
|
||||
Set<String> list = new HashSet<String>();
|
||||
list.add(keys);
|
||||
groupRegionIdMap.put(Long.valueOf(groupIdStr), list);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +116,7 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
}
|
||||
|
||||
Map<Long, Set<Long>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
Map<Long, Set<String>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap.containsKey(groupId)) {
|
||||
groupAndRegionMap.get(groupId).addAll(groupRegionIdMap.get(groupId));
|
||||
} else {
|
||||
@@ -133,7 +143,7 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||
|
||||
Map<Long, Set<Long>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Map<Long, Set<String>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<String>>();
|
||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||
idRelationMap.put(redisDBIndex, maatRelation);
|
||||
@@ -263,18 +273,18 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
|
||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||
}
|
||||
Map<Long, Set<Long>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||
Map<Long, Set<String>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap2 != null && groupAndRegionMap2.size() > 0) {
|
||||
if (!groupAndRegionMap2.containsKey(gRR.getGroupId())) {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
Set<String> set = new HashSet<String>();
|
||||
set.add(gRR.getRegionId());
|
||||
groupAndRegionMap2.put(gRR.getGroupId(), set);
|
||||
} else {
|
||||
groupAndRegionMap2.get(gRR.getGroupId()).add(gRR.getRegionId());
|
||||
}
|
||||
} else {
|
||||
Map<Long, Set<Long>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
Map<Long, Set<String>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<String>>();
|
||||
Set<String> set = new HashSet<String>();
|
||||
set.add(gRR.getRegionId());
|
||||
groupAndRegionMap.put(gRR.getGroupId(), set);
|
||||
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||
@@ -306,10 +316,10 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
System.out.println("组:" + group + "编译:" + compile);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
Map<Long, Set<String>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
for (Long group : getGroupAndRegionMap.keySet()) {
|
||||
Set<Long> regionList = getGroupAndRegionMap.get(group);
|
||||
for (Long region : regionList) {
|
||||
Set<String> regionList = getGroupAndRegionMap.get(group);
|
||||
for (String region : regionList) {
|
||||
System.out.println("组:" + group + "域:" + region);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class ReadMaatXmlUtil {
|
||||
static {
|
||||
readXml();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// validateXmlByXSD();
|
||||
@@ -54,13 +55,13 @@ public class ReadMaatXmlUtil {
|
||||
MaatXmlConfig maatXmlConfig = map.get(key);
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
System.out.println("service=" + key + " key="
|
||||
+ maatXmlExpr.getKeyExpression() + " value=" + maatXmlExpr.getValueExpression());
|
||||
System.out.println("service=" + key + " key=" + maatXmlExpr.getKeyExpression() + " value="
|
||||
+ maatXmlExpr.getValueExpression());
|
||||
}
|
||||
List<MaatXmlSeq> sequenceList = maatXmlConfig.getSequenceList();
|
||||
for (MaatXmlSeq maatXmlSeq : sequenceList) {
|
||||
System.out.println("service=" + key + " key="
|
||||
+ maatXmlSeq.getSequenceKey() + " operation=" + maatXmlSeq.getOperation());
|
||||
System.out.println("service=" + key + " key=" + maatXmlSeq.getSequenceKey() + " operation="
|
||||
+ maatXmlSeq.getOperation());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +95,9 @@ public class ReadMaatXmlUtil {
|
||||
if (ele.getName().toLowerCase().equals("operation")) {
|
||||
maatXmlSeq.setOperation(Integer.parseInt(ele.getTextTrim()));
|
||||
}
|
||||
// if (ele.getName().toLowerCase().equals("redisdb")) {
|
||||
// maatXmlSeq.setRedisDB(Integer.parseInt(ele.getTextTrim()));
|
||||
// }
|
||||
// if (ele.getName().toLowerCase().equals("redisdb")) {
|
||||
// maatXmlSeq.setRedisDB(Integer.parseInt(ele.getTextTrim()));
|
||||
// }
|
||||
if (ele.getName().toLowerCase().equals("sequencekey")) {
|
||||
maatXmlSeq.setSequenceKey(ele.getTextTrim());
|
||||
}
|
||||
@@ -129,16 +130,16 @@ public class ReadMaatXmlUtil {
|
||||
maatXmlExpr.setType(17);
|
||||
} else if (ele.getTextTrim().contains("ip_client_range_table_name")) {
|
||||
maatXmlExpr.setType(18);
|
||||
} else {
|
||||
} else if (ele.getTextTrim().contains("un_maat_table_name")) {
|
||||
maatXmlExpr.setType(0);
|
||||
}
|
||||
}
|
||||
if (ele.getName().toLowerCase().equals("valueexpression")) {
|
||||
maatXmlExpr.setValueExpression(ele.getTextTrim());
|
||||
}
|
||||
// if (ele.getName().toLowerCase().equals("redisdb")) {
|
||||
// maatXmlExpr.setRedisDB(Integer.parseInt(ele.getTextTrim()));
|
||||
// }
|
||||
// if (ele.getName().toLowerCase().equals("redisdb")) {
|
||||
// maatXmlExpr.setRedisDB(Integer.parseInt(ele.getTextTrim()));
|
||||
// }
|
||||
|
||||
}
|
||||
exprList.add(maatXmlExpr);
|
||||
|
||||
@@ -5,6 +5,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.nis.web.service.restful.ConfigRedisServiceimpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>Title: ServiceAndRDBIndexReal</p>
|
||||
@@ -15,7 +20,7 @@ import java.util.Map;
|
||||
*
|
||||
*/
|
||||
public class ServiceAndRDBIndexReal {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ServiceAndRDBIndexReal.class);
|
||||
/**
|
||||
* 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名
|
||||
*/
|
||||
@@ -42,7 +47,7 @@ public class ServiceAndRDBIndexReal {
|
||||
for (String str : split) {
|
||||
String[] serviceAction = str.split(":");
|
||||
serviceActionMap.put(Integer.valueOf(serviceAction[0]), Integer.valueOf(serviceAction[1]));
|
||||
|
||||
|
||||
String serviceType = Configurations.getStringProperty(serviceAction[0], "");
|
||||
if (serviceType != null && !serviceType.trim().equals("")) {
|
||||
String[] typeArrs = serviceType.split(";");
|
||||
@@ -108,19 +113,45 @@ public class ServiceAndRDBIndexReal {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务类型和具体的type获取对应的表名
|
||||
* 根据业务类型和具体的type获取maat类型对应的表名
|
||||
* @param service 业务类型
|
||||
* @param type 10代表是编译配置,11代表是分组配置,12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置
|
||||
* @return
|
||||
*/
|
||||
public static String getTableName(int service, int type) {
|
||||
public static String getMaatTableName(int service, int type, String tableName) {
|
||||
Map<Integer, String> typeMap = sercieNameMap.get(service);
|
||||
if (typeMap != null && typeMap.size() > 0) {
|
||||
return typeMap.get(type);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
if (tableName == null || tableName.trim().equals("")) {
|
||||
return typeMap.get(type);
|
||||
} else {
|
||||
String tableNames = typeMap.get(type);
|
||||
String[] split = tableNames.split(",");
|
||||
for (String str : split) {
|
||||
if (str.toLowerCase().contains(tableName.toLowerCase())) {
|
||||
return str;
|
||||
} else {
|
||||
logger.error(
|
||||
"未从业务类型和表对应关系中,找到业务类型:{},配置类型:{}表名:{}对应的真实表名",service,type,tableName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务类型获取unmaat配置表名
|
||||
* @param service
|
||||
* @return
|
||||
*/
|
||||
public static String getUnMaatTableName(int service) {
|
||||
if (unMaatSercieNameMap != null && unMaatSercieNameMap.size() > 0) {
|
||||
return unMaatSercieNameMap.get(service);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getActionByService(Integer service) {
|
||||
|
||||
@@ -62,6 +62,19 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) {
|
||||
keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||
keyBF.append(map.get(keyStr));
|
||||
} else if (!StringUtils.isEmpty(keyStr)
|
||||
&& keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
String maatTableName = ServiceAndRDBIndexReal
|
||||
.getUnMaatTableName(service);
|
||||
if (maatTableName == null) {
|
||||
throw new RuntimeException("未从业务类型和表对应关系中,找到非maat配置业务类型:"
|
||||
+ service + "对应的真实表名");
|
||||
} else {
|
||||
keyBF.append(maatTableName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
@@ -164,8 +177,6 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
if (configMap != null && configMap.size() > 0) {
|
||||
for (Integer redisDBIndex : configMap.keySet()) {
|
||||
if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) {
|
||||
// MaatRelation maatRelation =
|
||||
// CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex);
|
||||
List<MaatConfig> maatConfigList = configMap.get(redisDBIndex);
|
||||
if (maatConfigList != null && maatConfigList.size() > 0) {
|
||||
for (MaatConfig maatConfig : maatConfigList) {
|
||||
@@ -175,13 +186,22 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
compileAndGroupRelations.setCompileId(Long.valueOf(cfgIdStr));
|
||||
compileAndGroupRelations.setGroupIdList(new ArrayList<GroupAndRegionRelations>());
|
||||
|
||||
addGroupAndRegionRelations(maatConfig.getIpRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getNumRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getStrRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getStrStrRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getFileDigestRegionMapList(),
|
||||
int service = maatConfig.getService();
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 12, maatConfig.getIpRegionMapList(),
|
||||
compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 13, maatConfig.getNumRegionMapList(),
|
||||
compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 14, maatConfig.getStrRegionMapList(),
|
||||
compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 15, maatConfig.getStrStrRegionMapList(),
|
||||
compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 16,
|
||||
maatConfig.getFileDigestRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 17,
|
||||
maatConfig.getFileLikeRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatXmlConfig, service, 18, maatConfig.getIpClientRangeMapList(),
|
||||
compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getFileLikeRegionMapList(), compileAndGroupRelations);
|
||||
|
||||
CompileGroupRegionRela.addIdRelation(redisDBIndex, compileAndGroupRelations);
|
||||
}
|
||||
@@ -201,15 +221,46 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
* @param regionMapList
|
||||
* @param compileAndGroupRelations
|
||||
*/
|
||||
private void addGroupAndRegionRelations(List<Map<String, String>> regionMapList,
|
||||
CompileAndGroupRelations compileAndGroupRelations) {
|
||||
private void addGroupAndRegionRelations(MaatXmlConfig maatXmlConfig, int service, int type,
|
||||
List<Map<String, String>> regionMapList, CompileAndGroupRelations compileAndGroupRelations) {
|
||||
if (regionMapList != null && regionMapList.size() > 0 && compileAndGroupRelations != null) {
|
||||
for (Map<String, String> map : regionMapList) {
|
||||
String regionIdStr = map.get("region_id");
|
||||
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("]", "");
|
||||
keyBF.append(map.get(keyStr));
|
||||
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
String argTableName = map.get("tableName");
|
||||
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type,
|
||||
argTableName == null ? null : argTableName);
|
||||
if (maatTableName == null) {
|
||||
throw new RuntimeException(
|
||||
"未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
|
||||
} else {
|
||||
keyBF.append(maatTableName);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
maatKey = keyBF.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
String groupIdStr = map.get("group_id");
|
||||
GroupAndRegionRelations groupAndRegionRelations = new GroupAndRegionRelations();
|
||||
groupAndRegionRelations.setGroupId(Long.valueOf(groupIdStr));
|
||||
groupAndRegionRelations.setRegionId(Long.valueOf(regionIdStr));
|
||||
groupAndRegionRelations.setRegionId(maatKey);
|
||||
compileAndGroupRelations.getGroupIdList().add(groupAndRegionRelations);
|
||||
}
|
||||
}
|
||||
@@ -371,7 +422,16 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
keyBF.append(ServiceAndRDBIndexReal.getTableName(service, type));
|
||||
String argTableName = map.get("tableName");
|
||||
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type,
|
||||
argTableName == null ? null : argTableName);
|
||||
if (maatTableName == null) {
|
||||
throw new RuntimeException(
|
||||
"未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
|
||||
} else {
|
||||
keyBF.append(maatTableName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -487,13 +547,27 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
&& keyStr.trim().startsWith("[")) {
|
||||
// keyStr = keyStr.trim().replace("[", "").replace("]", "");
|
||||
keyBF.append(id);
|
||||
} else if (!StringUtils.isEmpty(keyStr)
|
||||
&& keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
String maatTableName = ServiceAndRDBIndexReal
|
||||
.getUnMaatTableName(service);
|
||||
if (maatTableName == null) {
|
||||
throw new RuntimeException(
|
||||
"未从业务类型和表对应关系中,找到非maat配置业务类型:" + service
|
||||
+ "对应的真实表名");
|
||||
} else {
|
||||
keyBF.append(maatTableName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
maatKey = keyBF.toString();
|
||||
String oldKey = maatKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE");
|
||||
if (redisTemplate.hasKey( oldKey.toString().toUpperCase())) {
|
||||
if (redisTemplate.hasKey(oldKey.toString().toUpperCase())) {
|
||||
redisTemplate.rename(oldKey.toString().toUpperCase(),
|
||||
keyBF.toString().toUpperCase());
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex,
|
||||
@@ -501,7 +575,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
keyBF.toString().toUpperCase());
|
||||
break;
|
||||
} else {
|
||||
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
|
||||
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey
|
||||
+ "请检查id映射关系是否正确");
|
||||
}
|
||||
}
|
||||
// redisTemplate.boundValueOps(keyBF.toString().toUpperCase()).set(valBF.toString());
|
||||
@@ -635,32 +710,37 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
RedisTemplate<String, String> redisTemplate, MaatRelation maatRelation, int redisDBIndex) {
|
||||
if (maatRelation != null && idList != null && idList.size() > 0 && maatXmlConfig != null) {
|
||||
for (Long id : idList) {
|
||||
Set<Long> compileIdList = new HashSet<Long>();
|
||||
compileIdList.add(id);
|
||||
removeCommonConfig(maatXmlConfig, compileIdList, 10, maatVersion.doubleValue(), service, redisTemplate,
|
||||
removeCompileAndGroupConfig(maatXmlConfig, id, 10, maatVersion.doubleValue(), service, redisTemplate,
|
||||
redisDBIndex);// 10代表是编译配置
|
||||
Set<Long> groupSet = maatRelation.getCompileAndGroupMap().get(id);
|
||||
if (groupSet != null && groupSet.size() > 0) {
|
||||
removeCommonConfig(maatXmlConfig, groupSet, 11, maatVersion.doubleValue(), service, redisTemplate,
|
||||
redisDBIndex);// 11代表是分组配置
|
||||
for (Long groupId : groupSet) {
|
||||
Set<Long> regionIdSet = maatRelation.getGroupAndRegionMap().get(groupId);
|
||||
if (regionIdSet != null && regionIdSet.size() > 0) {
|
||||
removeCommonConfig(maatXmlConfig, regionIdSet, 12, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 12代表是ip类域配置
|
||||
removeCommonConfig(maatXmlConfig, regionIdSet, 13, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 13代表是数值类配置
|
||||
removeCommonConfig(maatXmlConfig, regionIdSet, 14, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 14代表是字符串类域配置
|
||||
removeCommonConfig(maatXmlConfig, regionIdSet, 15, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 15代表是增强字符串类域配置
|
||||
removeCommonConfig(maatXmlConfig, regionIdSet, 16, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 16代表是文件摘要类域配置
|
||||
removeCommonConfig(maatXmlConfig, regionIdSet, 17, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 17代表是文本相似性域配置
|
||||
removeCommonConfig(maatXmlConfig, regionIdSet, 18, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 18代表是区域ip域配置
|
||||
Set<Long> set = maatRelation.getGroupAndCompileMap().get(groupId);// 获取组对应的编译id
|
||||
if (set != null && set.size() == 0) {// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效
|
||||
for (Long compileId : set) {
|
||||
if (compileId == id) {//
|
||||
Set<String> regionIdSet = maatRelation.getGroupAndRegionMap().get(groupId);
|
||||
if (regionIdSet != null && regionIdSet.size() > 0) {
|
||||
removeRegionConfig(maatXmlConfig, regionIdSet, 12, maatVersion.doubleValue(),
|
||||
service, redisTemplate, redisDBIndex);// 12代表是ip类域配置
|
||||
removeRegionConfig(maatXmlConfig, regionIdSet, 13, maatVersion.doubleValue(),
|
||||
service, redisTemplate, redisDBIndex);// 13代表是数值类配置
|
||||
removeRegionConfig(maatXmlConfig, regionIdSet, 14, maatVersion.doubleValue(),
|
||||
service, redisTemplate, redisDBIndex);// 14代表是字符串类域配置
|
||||
removeRegionConfig(maatXmlConfig, regionIdSet, 15, maatVersion.doubleValue(),
|
||||
service, redisTemplate, redisDBIndex);// 15代表是增强字符串类域配置
|
||||
removeRegionConfig(maatXmlConfig, regionIdSet, 16, maatVersion.doubleValue(),
|
||||
service, redisTemplate, redisDBIndex);// 16代表是文件摘要类域配置
|
||||
removeRegionConfig(maatXmlConfig, regionIdSet, 17, maatVersion.doubleValue(),
|
||||
service, redisTemplate, redisDBIndex);// 17代表是文本相似性域配置
|
||||
removeRegionConfig(maatXmlConfig, regionIdSet, 18, maatVersion.doubleValue(),
|
||||
service, redisTemplate, redisDBIndex);// 18代表是区域ip域配置
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
removeCompileAndGroupConfig(maatXmlConfig, groupId, 11, maatVersion.doubleValue(), service,
|
||||
redisTemplate, redisDBIndex);// 11代表是分组配置
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -678,42 +758,94 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
* @param service
|
||||
* @param redisTemplate
|
||||
*/
|
||||
private void removeCommonConfig(MaatXmlConfig maatXmlConfig, Set<Long> idList, int type, Double maatVersion,
|
||||
private void removeCompileAndGroupConfig(MaatXmlConfig maatXmlConfig, long id, int type, Double maatVersion,
|
||||
int service, RedisTemplate<String, String> redisTemplate, int redisDBIndex) {
|
||||
if (maatXmlConfig != null) {
|
||||
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("]", "");
|
||||
keyBF.append(id);
|
||||
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
String maatTableName = ServiceAndRDBIndexReal.getMaatTableName(service, type, null);
|
||||
if (maatTableName == null) {
|
||||
throw new RuntimeException(
|
||||
"未从业务类型和表对应关系中,找到业务类型:" + service + ",配置类型:" + type + ",对应的真实表名");
|
||||
} else {
|
||||
keyBF.append(maatTableName);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
String oldKey = keyBF.toString().toUpperCase();
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
if (redisTemplate.hasKey(oldKey)) {
|
||||
redisTemplate.rename(oldKey, maatKey.toUpperCase());
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey,
|
||||
maatKey.toUpperCase());
|
||||
break;
|
||||
} else {
|
||||
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
|
||||
if (maatKey != null) {
|
||||
String zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
|
||||
|
||||
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
|
||||
redisTemplate.boundZSetOps("MAAT_RULE_TIMER").add(maatKey, score);
|
||||
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,得到当前时间的秒
|
||||
redisTemplate.boundZSetOps("MAAT_VERSION_TIMER").add(maatVersion + "", score);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex, maatVersion, score);
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("无法获取业务类型" + service + "对应的maat规则,请检查!");
|
||||
}
|
||||
}
|
||||
|
||||
private void removeRegionConfig(MaatXmlConfig maatXmlConfig, Set<String> idList, int type, Double maatVersion,
|
||||
int service, RedisTemplate<String, String> redisTemplate, int redisDBIndex) {
|
||||
if (maatXmlConfig != null && idList != null && idList.size() > 0) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
String maatKey = null;
|
||||
for (Long id : idList) {
|
||||
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("]", "");
|
||||
keyBF.append(id);
|
||||
} else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) {
|
||||
keyStr = keyStr.trim().replace("{", "").replace("}", "");
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
keyBF.append(ServiceAndRDBIndexReal.getTableName(service, type));
|
||||
}
|
||||
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
String oldKey = keyBF.toString().toUpperCase();
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
if (redisTemplate.hasKey(oldKey)) {
|
||||
redisTemplate.rename(oldKey, maatKey.toUpperCase());
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey,
|
||||
maatKey.toUpperCase());
|
||||
break;
|
||||
} else {
|
||||
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
|
||||
}
|
||||
}
|
||||
for (String oldKey : idList) {
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
if (redisTemplate.hasKey(oldKey)) {
|
||||
redisTemplate.rename(oldKey, maatKey.toUpperCase());
|
||||
logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase());
|
||||
} else {
|
||||
throw new RuntimeException(redisDBIndex + "号redis库中不存在key=" + oldKey + "请检查id映射关系是否正确");
|
||||
}
|
||||
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
|
||||
if (maatKey != null) {
|
||||
@@ -727,7 +859,6 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
|
||||
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_RULE_TIMER")) {
|
||||
if (maatKey != null) {
|
||||
|
||||
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
|
||||
redisTemplate.boundZSetOps("MAAT_RULE_TIMER").add(maatKey, score);
|
||||
logger.info("向{}号redis数据库更新了MAAT_RULE_TIMER,内容是{},SCORES是{}", redisDBIndex, maatKey, score);
|
||||
|
||||
Reference in New Issue
Block a user