1:为配置下发添加相关逻辑说明
2:修改配置下发和取消的冗余代码 3:删除分组复用相关内容 4:删除redis-pipeline相关的内容 5:删除项目启动加载maat关联关系的逻辑
This commit is contained in:
@@ -1,246 +0,0 @@
|
||||
package com.nis.domain.restful;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
/**
|
||||
*
|
||||
* <p>Title: MaatRelation</p>
|
||||
* <p>Description: 描述:编译id,分组关系id,域配置id等的对应关系</p>
|
||||
* <p>Company: IIE</p>
|
||||
* @author rkg
|
||||
* @date 2018年6月1日
|
||||
*
|
||||
*/
|
||||
public class MaatRelation implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 编译id与groupid的对应关系,key是编译id,value使用set不允许重复
|
||||
*/
|
||||
private Map<Long, Set<Long>> compileAndGroupMap;
|
||||
/**
|
||||
* groupid与编译id的对应关系,key是groupid,value使用set不允许重复
|
||||
*/
|
||||
private Map<Long, Set<Long>> groupAndCompileMap;
|
||||
// private Map<Long, List<Long>> regionAndGroupMap;
|
||||
/**
|
||||
* groupid与regionid的对应关系,key是groupid,value使用set不允许重复
|
||||
*/
|
||||
private Map<Long, Set<String>> groupAndRegionMap;
|
||||
|
||||
public Map<Long, Set<Long>> getCompileAndGroupMap() {
|
||||
return compileAndGroupMap;
|
||||
}
|
||||
|
||||
public void setCompileAndGroupMap(Map<Long, Set<Long>> compileAndGroupMap) {
|
||||
this.compileAndGroupMap = compileAndGroupMap;
|
||||
}
|
||||
|
||||
public Map<Long, Set<Long>> getGroupAndCompileMap() {
|
||||
return groupAndCompileMap;
|
||||
}
|
||||
|
||||
public void setGroupAndCompileMap(Map<Long, Set<Long>> groupAndCompileMap) {
|
||||
this.groupAndCompileMap = groupAndCompileMap;
|
||||
}
|
||||
|
||||
public Map<Long, Set<String>> getGroupAndRegionMap() {
|
||||
return groupAndRegionMap;
|
||||
}
|
||||
|
||||
public void setGroupAndRegionMap(Map<Long, Set<String>> groupAndRegionMap) {
|
||||
this.groupAndRegionMap = groupAndRegionMap;
|
||||
}
|
||||
|
||||
public static void removKey(MaatRelation maatRelation, long compileId) {
|
||||
if (maatRelation.getCompileAndGroupMap().containsKey(compileId)) {
|
||||
Set<Long> list = maatRelation.getCompileAndGroupMap().get(compileId);
|
||||
if (list != null && list.size() > 0) {
|
||||
for (Long groupId : list) {
|
||||
// }
|
||||
// for (Long groupId: list.size()) {
|
||||
if (maatRelation.getGroupAndCompileMap().containsKey(groupId)) {
|
||||
// && maatRelation.getGroupAndCompileMap().get(groupId).size() == 1
|
||||
// && maatRelation.getGroupAndCompileMap().get(groupId).get(0).longValue() ==
|
||||
// compileId) {
|
||||
Set<Long> compileIdList = maatRelation.getGroupAndCompileMap().get(groupId);
|
||||
if (compileIdList.size() == 1) {// 当前的groupid只属于当前的compileid,没有被分组复用,需要将编译配置,分组关系,域配置,置无效
|
||||
for (Long id : compileIdList) {
|
||||
if (id.longValue() == compileId) {
|
||||
// 这个group没有被分组复用,所以需要将这个组下面的域配置置为无效,组也要置为无效
|
||||
if (maatRelation.getGroupAndRegionMap().containsKey(groupId)) {
|
||||
// 把当前组置为无效,把当前组下的所有域置为无效
|
||||
maatRelation.getGroupAndRegionMap().remove(groupId);// 删除组对应的域
|
||||
maatRelation.getGroupAndCompileMap().remove(groupId);// 删除当前组所对应的编译
|
||||
// maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId);
|
||||
// maatRelation.getCompileAndGroupMap().get(compileId)
|
||||
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||
// 删除编译下面的组
|
||||
list.remove(groupId);// 删除编译下面的组
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 这个组对应了多个编译配置被分组复用了,这时将这个组和编译的关系置为无效,编译置为无效
|
||||
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||
// 删除编译下面的这个组
|
||||
// maatRelation.getGroupAndCompileMap().get(groupId)
|
||||
// .remove(maatRelation.getGroupAndCompileMap().get(groupId).indexOf(compileId));//
|
||||
// 删除分组关系中的组和编译关系
|
||||
|
||||
list.remove(groupId);// 删除编译下面的这个组
|
||||
maatRelation.getGroupAndCompileMap().get(groupId).remove(compileId);
|
||||
}
|
||||
} else {
|
||||
// 当前的groupid属于多个组,被分组复用了,所以不对这个组进行操作,也不对这个组下面的域进行操作
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void syso(MaatRelation maatRelation) {
|
||||
Map<Long, Set<Long>> getCompileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||
for (Long compile : getCompileAndGroupMap.keySet()) {
|
||||
Set<Long> groupList = getCompileAndGroupMap.get(compile);
|
||||
for (Long group : groupList) {
|
||||
System.out.println("编译:" + compile + "组:" + group);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> getGroupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||
for (Long group : getGroupAndCompileMap.keySet()) {
|
||||
Set<Long> compileList = getGroupAndCompileMap.get(group);
|
||||
for (Long compile : compileList) {
|
||||
System.out.println("组:" + group + "编译:" + compile);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<String>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
for (Long group : getGroupAndRegionMap.keySet()) {
|
||||
Set<String> regionList = getGroupAndRegionMap.get(group);
|
||||
for (String region : regionList) {
|
||||
System.out.println("组:" + group + "域:" + region);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
MaatRelation maatRelation = getMaat();
|
||||
syso(maatRelation);
|
||||
|
||||
long compileId = 11;
|
||||
removKey(maatRelation, compileId);
|
||||
syso(maatRelation);
|
||||
|
||||
compileId = 2;
|
||||
removKey(maatRelation, compileId);
|
||||
syso(maatRelation);
|
||||
|
||||
addKey(maatRelation, setCGR());
|
||||
syso(maatRelation);
|
||||
|
||||
|
||||
compileId = 99999L;
|
||||
removKey(maatRelation, compileId);
|
||||
syso(maatRelation);
|
||||
}
|
||||
|
||||
public static CompileAndGroupRelations setCGR() {
|
||||
CompileAndGroupRelations cGR = new CompileAndGroupRelations();
|
||||
cGR.setCompileId(99999L);
|
||||
|
||||
List<GroupAndRegionRelations> groupIdList = new ArrayList<GroupAndRegionRelations>();
|
||||
GroupAndRegionRelations gRR = new GroupAndRegionRelations();
|
||||
gRR.setGroupId(100L);
|
||||
gRR.setRegionId("200");
|
||||
groupIdList.add(gRR);
|
||||
|
||||
gRR = new GroupAndRegionRelations();
|
||||
gRR.setGroupId(100L);
|
||||
gRR.setRegionId("300");
|
||||
groupIdList.add(gRR);
|
||||
cGR.setGroupIdList(groupIdList);
|
||||
return cGR;
|
||||
}
|
||||
|
||||
public static void addKey(MaatRelation maatRelation, CompileAndGroupRelations compileAndGroupRelations) {
|
||||
|
||||
long compileId = compileAndGroupRelations.getCompileId();
|
||||
List<GroupAndRegionRelations> groupIdList = compileAndGroupRelations.getGroupIdList();
|
||||
if (groupIdList != null && groupIdList.size() > 0) {
|
||||
for (GroupAndRegionRelations gRR : groupIdList) {
|
||||
Map<Long, Set<Long>> compileAndGroupMap2 = maatRelation.getCompileAndGroupMap();
|
||||
if (compileAndGroupMap2 != null && compileAndGroupMap2.size() > 0) {
|
||||
if (!compileAndGroupMap2.containsKey(compileId)) {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(gRR.getGroupId());
|
||||
compileAndGroupMap2.put(compileId, set);
|
||||
} else {
|
||||
compileAndGroupMap2.get(compileId).add(gRR.getGroupId());
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, Set<Long>> groupAndCompileMap2 = maatRelation.getGroupAndCompileMap();
|
||||
if (groupAndCompileMap2 != null && groupAndCompileMap2.size() > 0) {
|
||||
if (!groupAndCompileMap2.containsKey(gRR.getGroupId())) {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(compileId);
|
||||
groupAndCompileMap2.put(gRR.getGroupId(), set);
|
||||
} else {
|
||||
groupAndCompileMap2.get(gRR.getGroupId()).add(compileId);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<String>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap2 != null && groupAndRegionMap2.size() > 0) {
|
||||
if (!groupAndRegionMap2.containsKey(gRR.getGroupId())) {
|
||||
Set<String> set = new HashSet<String>();
|
||||
set.add(gRR.getRegionId());
|
||||
groupAndRegionMap2.put(gRR.getGroupId(), set);
|
||||
} else {
|
||||
groupAndRegionMap2.get(gRR.getGroupId()).add(gRR.getRegionId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MaatRelation getMaat() {
|
||||
MaatRelation maatRelation = new MaatRelation();
|
||||
Map<Long, Set<Long>> compileAndGroupMap = new HashMap<Long, Set<Long>>();
|
||||
Set<Long> list = new HashSet<Long>();
|
||||
list.add(1l);
|
||||
compileAndGroupMap.put(1l, list);
|
||||
list = new HashSet<Long>();
|
||||
list.add(1l);
|
||||
compileAndGroupMap.put(2l, list);
|
||||
Map<Long, Set<Long>> groupAndCompileMap = new HashMap<Long, Set<Long>>();
|
||||
list = new HashSet<Long>();
|
||||
list.add(1l);
|
||||
list.add(2l);
|
||||
groupAndCompileMap.put(1l, list);
|
||||
// Map<Long, List<Long>> regionAndGroupMap = new HashMap<Long, List<Long>>();
|
||||
Set<String> list2 = new HashSet<String>();
|
||||
list2.add("1");
|
||||
// regionAndGroupMap.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);
|
||||
// maatRelation.setRegionAndGroupMap(regionAndGroupMap);
|
||||
|
||||
return maatRelation;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,336 +0,0 @@
|
||||
package com.nis.listener;
|
||||
|
||||
import com.nis.domain.restful.CompileAndGroupRelations;
|
||||
import com.nis.domain.restful.GroupAndRegionRelations;
|
||||
import com.nis.domain.restful.MaatRelation;
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.web.service.SpringContextHolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 项目启动时加载数据字典
|
||||
*
|
||||
* @author RenKaiGe-Office
|
||||
* @Date:2018-05-24
|
||||
*/
|
||||
public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
private static Logger logger = LoggerFactory.getLogger(CompileGroupRegionRela.class);
|
||||
/**
|
||||
* 存储redis所有库中,编译分组域等配置关系,key是redis库
|
||||
*/
|
||||
private static Map<Integer, MaatRelation> idRelationMap = new ConcurrentHashMap<Integer, MaatRelation>();
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
try {
|
||||
long begin = System.currentTimeMillis();
|
||||
for (int i = 0; i < Configurations.getIntProperty("maxRedisDBIndex", 6); i++) {
|
||||
RedisTemplate<String, String> redisTemplate = SpringContextHolder.getBean("redisTemplate" + i);
|
||||
getAllId(redisTemplate, i);
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
logger.info("从redis读取数据需要" + ((end - begin) / 1000) + "秒");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void getAllId(RedisTemplate<String, String> redisTemplate, int redisDBIndex) {
|
||||
Map<Long, Set<Long>> groupCompileIdMap = 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) {
|
||||
if (!keys.toLowerCase().contains("compile")) {
|
||||
try {
|
||||
String value = redisTemplate.opsForValue().get(keys).toString();
|
||||
if (keys.toLowerCase().contains("group")) {
|
||||
String[] split = value.split("\t");
|
||||
String groupIdStr = split[0];
|
||||
String compileIdStr = split[1];
|
||||
if (groupCompileIdMap.containsKey(Long.valueOf(groupIdStr))) {
|
||||
groupCompileIdMap.get(Long.valueOf(groupIdStr)).add(Long.valueOf(compileIdStr));
|
||||
} else {
|
||||
Set<Long> list = new HashSet<Long>();
|
||||
list.add(Long.valueOf(compileIdStr));
|
||||
groupCompileIdMap.put(Long.valueOf(groupIdStr), list);
|
||||
}
|
||||
|
||||
} 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 groupIdStr = split[1];
|
||||
if (groupRegionIdMap.containsKey(Long.valueOf(groupIdStr))) {
|
||||
groupRegionIdMap.get(Long.valueOf(groupIdStr)).add(keys);
|
||||
} else {
|
||||
Set<String> list = new HashSet<String>();
|
||||
list.add(keys);
|
||||
groupRegionIdMap.put(Long.valueOf(groupIdStr), list);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("从redis中查询" + keys + "数据失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Long groupId : groupCompileIdMap.keySet()) {
|
||||
if (idRelationMap.containsKey(redisDBIndex)) {
|
||||
Set<String> regionIdSet = groupRegionIdMap.get(groupId);
|
||||
if (regionIdSet != null && regionIdSet.size() > 0) {// 防止出现错误数据,redis里面有域配置但是找不多对应的编译配置,分组配置,或者有分组配置但是找不到域或编译,或者有编译找不到分组和域
|
||||
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||
Map<Long, Set<Long>> compileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||
for (Long compileId : compileIdList) {
|
||||
if (compileAndGroupMap.containsKey(compileId)) {
|
||||
compileAndGroupMap.get(compileId).add(groupId);
|
||||
} else {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(groupId);
|
||||
compileAndGroupMap.put(compileId, set);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> groupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||
if (groupAndCompileMap.containsKey(groupId)) {
|
||||
groupAndCompileMap.get(groupId).addAll(compileIdList);
|
||||
} else {
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
}
|
||||
|
||||
Map<Long, Set<String>> groupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap.containsKey(groupId)) {
|
||||
groupAndRegionMap.get(groupId).addAll(groupRegionIdMap.get(groupId));
|
||||
} else {
|
||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
Set<String> regionIdSet = groupRegionIdMap.get(groupId);
|
||||
if (regionIdSet != null && regionIdSet.size() > 0) {// 防止出现错误数据,redis里面有域配置但是找不多对应的编译配置,分组配置,或者有分组配置但是找不到域或编译,或者有编译找不到分组和域
|
||||
MaatRelation maatRelation = new MaatRelation();
|
||||
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Set<Long> compileIdList = groupCompileIdMap.get(groupId);
|
||||
for (Long compileId : compileIdList) {
|
||||
if (compileAndGroupMap.containsKey(compileId)) {
|
||||
compileAndGroupMap.get(compileId).add(groupId);
|
||||
} else {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(groupId);
|
||||
compileAndGroupMap.put(compileId, set);
|
||||
}
|
||||
}
|
||||
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||
Map<Long, Set<Long>> groupAndCompileMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
groupAndCompileMap.put(groupId, compileIdList);
|
||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||
Map<Long, Set<String>> groupAndRegionMap = new ConcurrentHashMap<Long, Set<String>>();
|
||||
groupAndRegionMap.put(groupId, groupRegionIdMap.get(groupId));
|
||||
maatRelation.setGroupAndRegionMap(groupAndRegionMap);
|
||||
idRelationMap.put(redisDBIndex, maatRelation);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从字典中删除编译id的关系
|
||||
* @param redisDBIndex 哪个redis库
|
||||
* @param compileId
|
||||
*/
|
||||
public static void delIdRelation(int redisDBIndex, long compileId) {
|
||||
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||
if (maatRelation != null) {
|
||||
removKey(maatRelation, compileId);
|
||||
} else {
|
||||
logger.error("redis" + redisDBIndex + "号库中没有id对应关系(没有配置),请检查redisDBIndex是否正确");
|
||||
}
|
||||
// syso(maatRelation);
|
||||
|
||||
}
|
||||
|
||||
private static void removKey(MaatRelation maatRelation, long compileId) {
|
||||
if (maatRelation.getCompileAndGroupMap().containsKey(compileId)) {
|
||||
Set<Long> list = maatRelation.getCompileAndGroupMap().get(compileId);
|
||||
|
||||
if (list != null && list.size() > 0) {
|
||||
Iterator<Long> iterator = list.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Long groupId = iterator.next();
|
||||
if (maatRelation.getGroupAndCompileMap().containsKey(groupId)) {
|
||||
// && maatRelation.getGroupAndCompileMap().get(groupId).size() == 1
|
||||
// && maatRelation.getGroupAndCompileMap().get(groupId).get(0).longValue() ==
|
||||
// compileId) {
|
||||
Set<Long> compileIdList = maatRelation.getGroupAndCompileMap().get(groupId);
|
||||
if (compileIdList.size() == 1) {// 当前的groupid只属于当前的compileid,没有被分组复用,需要将编译配置,分组关系,域配置,置无效
|
||||
for (Long id : compileIdList) {
|
||||
if (id.longValue() == compileId) {
|
||||
// 这个group没有被分组复用,所以需要将这个组下面的域配置置为无效,组也要置为无效
|
||||
if (maatRelation.getGroupAndRegionMap().containsKey(groupId)) {
|
||||
// 把当前组置为无效,把当前组下的所有域置为无效
|
||||
maatRelation.getGroupAndRegionMap().remove(groupId);// 删除组对应的域
|
||||
maatRelation.getGroupAndCompileMap().remove(groupId);// 删除当前组所对应的编译
|
||||
// maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId);
|
||||
// maatRelation.getCompileAndGroupMap().get(compileId)
|
||||
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||
// 删除编译下面的组
|
||||
// list.remove(groupId);// 删除编译下面的组
|
||||
iterator.remove();// 删除编译下面的组
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 这个组对应了多个编译配置被分组复用了,这时将这个组和编译的关系置为无效,编译置为无效
|
||||
// list.remove(maatRelation.getCompileAndGroupMap().get(compileId).indexOf(groupId));//
|
||||
// 删除编译下面的这个组
|
||||
// maatRelation.getGroupAndCompileMap().get(groupId)
|
||||
// .remove(maatRelation.getGroupAndCompileMap().get(groupId).indexOf(compileId));//
|
||||
// 删除分组关系中的组和编译关系
|
||||
// list.remove(groupId);// 删除编译下面的这个组
|
||||
iterator.remove();// 删除编译下面的这个组
|
||||
maatRelation.getGroupAndCompileMap().get(groupId).remove(compileId);
|
||||
}
|
||||
} else {
|
||||
// 当前的groupid属于多个组,被分组复用了,所以不对这个组进行操作,也不对这个组下面的域进行操作
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加配置
|
||||
* @param redisDBIndex 向哪个库添加配置
|
||||
* @param compileAndGroupRelations id映射关系
|
||||
*/
|
||||
public static void addIdRelation(int redisDBIndex, CompileAndGroupRelations compileAndGroupRelations) {
|
||||
MaatRelation maatRelation = idRelationMap.get(redisDBIndex);
|
||||
if (maatRelation != null) {
|
||||
addKey(maatRelation, compileAndGroupRelations);
|
||||
} else {
|
||||
maatRelation = new MaatRelation();
|
||||
addKey(maatRelation, compileAndGroupRelations);
|
||||
idRelationMap.put(redisDBIndex, maatRelation);
|
||||
}
|
||||
// syso(maatRelation);
|
||||
|
||||
}
|
||||
|
||||
private static void addKey(MaatRelation maatRelation, CompileAndGroupRelations compileAndGroupRelations) {
|
||||
long compileId = compileAndGroupRelations.getCompileId();
|
||||
List<GroupAndRegionRelations> groupIdList = compileAndGroupRelations.getGroupIdList();
|
||||
if (groupIdList != null && groupIdList.size() > 0) {
|
||||
for (GroupAndRegionRelations gRR : groupIdList) {
|
||||
Map<Long, Set<Long>> compileAndGroupMap2 = maatRelation.getCompileAndGroupMap();
|
||||
if (compileAndGroupMap2 != null && compileAndGroupMap2.size() > 0) {
|
||||
if (!compileAndGroupMap2.containsKey(compileId)) {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(gRR.getGroupId());
|
||||
compileAndGroupMap2.put(compileId, set);
|
||||
} else {
|
||||
compileAndGroupMap2.get(compileId).add(gRR.getGroupId());
|
||||
}
|
||||
} else {
|
||||
Map<Long, Set<Long>> compileAndGroupMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(gRR.getGroupId());
|
||||
compileAndGroupMap.put(compileId, set);
|
||||
maatRelation.setCompileAndGroupMap(compileAndGroupMap);
|
||||
}
|
||||
|
||||
Map<Long, Set<Long>> groupAndCompileMap2 = maatRelation.getGroupAndCompileMap();
|
||||
if (groupAndCompileMap2 != null && groupAndCompileMap2.size() > 0) {
|
||||
if (!groupAndCompileMap2.containsKey(gRR.getGroupId())) {
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(compileId);
|
||||
groupAndCompileMap2.put(gRR.getGroupId(), set);
|
||||
} else {
|
||||
groupAndCompileMap2.get(gRR.getGroupId()).add(compileId);
|
||||
}
|
||||
} else {
|
||||
Map<Long, Set<Long>> groupAndCompileMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Set<Long> set = new HashSet<Long>();
|
||||
set.add(compileId);
|
||||
groupAndCompileMap.put(gRR.getGroupId(), set);
|
||||
|
||||
maatRelation.setGroupAndCompileMap(groupAndCompileMap);
|
||||
}
|
||||
Map<Long, Set<String>> groupAndRegionMap2 = maatRelation.getGroupAndRegionMap();
|
||||
if (groupAndRegionMap2 != null && groupAndRegionMap2.size() > 0) {
|
||||
if (!groupAndRegionMap2.containsKey(gRR.getGroupId())) {
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<Integer, MaatRelation> getIdRelationMap() {
|
||||
return idRelationMap;
|
||||
}
|
||||
|
||||
public static void setIdRelationMap(Map<Integer, MaatRelation> idRelationMap) {
|
||||
CompileGroupRegionRela.idRelationMap = idRelationMap;
|
||||
}
|
||||
|
||||
private static void syso(MaatRelation maatRelation) {
|
||||
Map<Long, Set<Long>> getCompileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||
for (Long compile : getCompileAndGroupMap.keySet()) {
|
||||
Set<Long> groupList = getCompileAndGroupMap.get(compile);
|
||||
for (Long group : groupList) {
|
||||
System.out.println("编译:" + compile + "组:" + group);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> getGroupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||
for (Long group : getGroupAndCompileMap.keySet()) {
|
||||
Set<Long> compileList = getGroupAndCompileMap.get(group);
|
||||
for (Long compile : compileList) {
|
||||
System.out.println("组:" + group + "编译:" + compile);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<String>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
for (Long group : getGroupAndRegionMap.keySet()) {
|
||||
Set<String> regionList = getGroupAndRegionMap.get(group);
|
||||
for (String region : regionList) {
|
||||
System.out.println("组:" + group + "域:" + region);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -410,20 +410,7 @@ public enum RestBusinessCode {
|
||||
* 当前编译配置service与域配置tableName的关系不存在
|
||||
*/
|
||||
TableNameUnmatchService(4002101, "当前编译配置service与域配置tableName的关系不存在"),
|
||||
/**
|
||||
* 域配置中的tableName不是分组复用的域表
|
||||
*/
|
||||
TableNameUnReuse(4002102, "域配置中tableName不是分组复用的域表"),
|
||||
/**
|
||||
* 分组复用域配置下发到阀门时userRegion不能为空
|
||||
*/
|
||||
ReUseUserRegionIsNull(4002102, "域配置需要下发到阀门,userRegion不能为空"),
|
||||
|
||||
/**
|
||||
* 添加分组复用域配置时,service只能为空或1028
|
||||
*/
|
||||
ReUseServiceRange(4002102, "添加分组复用域配置时,service只能为空或1028"),
|
||||
|
||||
|
||||
/**
|
||||
*数值域配置的lowBoundary值不在有效范围内
|
||||
*/
|
||||
@@ -478,14 +465,6 @@ public enum RestBusinessCode {
|
||||
*/
|
||||
CfdsLevelIsWrongRange(4002500,"摘要域-cfdsLevel的值只能是1到10"),
|
||||
|
||||
/**
|
||||
* service不能为空并且必须是分组复用的业务类型
|
||||
*/
|
||||
ServiceIsNullOrNotReuse(4002501, "service不能为空并且必须是分组复用的业务类型"),
|
||||
/**
|
||||
* 分组复用配置中域不能全为空
|
||||
*/
|
||||
ReuseRegionIsNull(4002502, "分组复用配置中域不能全为空"),
|
||||
//回调类
|
||||
/**
|
||||
* 回调类service配置不正确
|
||||
@@ -601,11 +580,6 @@ public enum RestBusinessCode {
|
||||
* 当前service不允许单独添加域配置
|
||||
*/
|
||||
ServiceNotAllowAddReion(5002009,"当前service不允许单独添加域配置"),
|
||||
/**
|
||||
* 删除分组复用域配置时,无法在关联关系中找到对应的域配置信息,之前该域没有添加过,或者关联关系被损坏请检查
|
||||
*/
|
||||
RegionIsNotExist(5002010,"删除分组复用域配置时,无法在关联关系中找到对应的域配置信息,之前该域没有添加过,或者关联关系被损坏请检查"),
|
||||
|
||||
|
||||
/**
|
||||
*配置文件内容有误
|
||||
|
||||
@@ -384,10 +384,6 @@ public class CompileVal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasRegionFlag&&!ServiceAndRDBIndexReal.serviceIsReuse(configCompile.getService())) {
|
||||
throw new RestServiceException("配置id为" + configCompile.getCompileId() + "的业务类型属于分组复用,域配置信息不能全为空",RestBusinessCode.RegionListIsNull.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,12 +3,10 @@ package com.nis.util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.zdjizhi.utils.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -26,12 +24,7 @@ import com.nis.restful.ServiceRuntimeException;
|
||||
*/
|
||||
public class ServiceAndRDBIndexReal {
|
||||
private static Logger logger = LoggerFactory.getLogger(ServiceAndRDBIndexReal.class);
|
||||
/**
|
||||
* 记录哪些service可以被分组复用(只有maat类配置可以被分组复用)
|
||||
* Map<Service,Map<regionName,List<tableName>>
|
||||
*/
|
||||
private static Map<Integer, Map<String, List<String>>> serviceGroupReuseMap = new HashMap<Integer, Map<String, List<String>>>();
|
||||
|
||||
|
||||
/**
|
||||
* 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名
|
||||
*/
|
||||
@@ -180,33 +173,7 @@ public class ServiceAndRDBIndexReal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String serviceRepeatedReal = Configurations.getStringProperty("serviceRepeatedReal", "");
|
||||
if (!StringUtil.isEmpty(serviceRepeatedReal)) {
|
||||
String[] serviceRepeatedRealArr = serviceRepeatedReal.split(";");
|
||||
for (String serviceRepeated : serviceRepeatedRealArr) {
|
||||
String[] serInfos = serviceRepeated.split(":");
|
||||
String[] regionInfos = serInfos[1].split("[|]");
|
||||
for (String regionInfo : regionInfos) {
|
||||
String[] regionTabName = regionInfo.split("@");
|
||||
String[] tableNames = regionTabName[1].split(",");
|
||||
for (String tableName : tableNames) {
|
||||
Integer ser = Integer.valueOf(serInfos[0]);
|
||||
if (serviceGroupReuseMap.containsKey(ser)) {
|
||||
serviceGroupReuseMap.get(ser).get(regionTabName[0]).add(tableName);
|
||||
} else {
|
||||
Map<String, List<String>> regTabMap = new HashMap<String, List<String>>();
|
||||
List<String> tabList = new ArrayList<String>();
|
||||
tabList.add(tableName);
|
||||
regTabMap.put(regionTabName[0], tabList);
|
||||
serviceGroupReuseMap.put(ser, regTabMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// getUnMaatTable();
|
||||
getMaatTable();
|
||||
@@ -349,20 +316,6 @@ public class ServiceAndRDBIndexReal {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断service是否被分组复用
|
||||
* @param service
|
||||
* @return
|
||||
*/
|
||||
public static Boolean serviceIsReuse(Integer service) {
|
||||
if (service != null) {
|
||||
return serviceGroupReuseMap.containsKey(service);
|
||||
} else {
|
||||
throw new ServiceRuntimeException("判断service是否是分组复用时发生了异常,异常原因:service=null",
|
||||
RestBusinessCode.ServiceIsNull.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证当前service是否是向阀门添加action,service或者userregion等属性
|
||||
* @param service
|
||||
|
||||
@@ -545,7 +545,7 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
commonGroupSource.getCommonGroupList(), sb, false);
|
||||
|
||||
} else {
|
||||
throw new RestServiceException("分组复用信息不能为空" + sb.toString(),
|
||||
throw new RestServiceException("公共组信息不能为空" + sb.toString(),
|
||||
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
}
|
||||
}
|
||||
@@ -594,7 +594,7 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
configSourcesService.delCommonGroup(thread, start, commonGroupSource.getCommonGroupList(), sb);
|
||||
|
||||
} else {
|
||||
throw new RestServiceException("分组复用信息不能为空" + sb.toString(),
|
||||
throw new RestServiceException("公共组信息不能为空" + sb.toString(),
|
||||
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
}
|
||||
}
|
||||
@@ -659,7 +659,7 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
}
|
||||
|
||||
if (groupReuseSourceList.size() <= 0) {
|
||||
errorInfo = "分组复用的域配置列表不能为空";
|
||||
errorInfo = "公共组的域配置列表不能为空";
|
||||
}
|
||||
if (!errorInfo.equals("")) {
|
||||
thread.setExceptionInfo(errorInfo);
|
||||
|
||||
@@ -188,8 +188,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) {
|
||||
List<MaatConfig> maatConfigList = configMap.get(redisDBIndex);
|
||||
if (maatConfigList != null && maatConfigList.size() > 0) {
|
||||
Map<String, List<String>> compileAndGroupMap = new HashMap<String, List<String>>();
|
||||
Map<String, List<String>> groupAndCompileMap = new HashMap<String, List<String>>();
|
||||
Map<String, List<String>> compileAndGroupMap = new HashMap<String, List<String>>();// 记录编译下面有哪些组,在哪些redisdb中
|
||||
Map<String, List<String>> groupAndCompileMap = new HashMap<String, List<String>>();// 记录每个组属于哪些编译,公共组可能会属于很多的编译redisdb中
|
||||
for (MaatConfig maatConfig : maatConfigList) {
|
||||
List<Map<String, String>> groupMapList = maatConfig.getGroupMapList();
|
||||
if (groupMapList != null && groupMapList.size() > 0) {
|
||||
@@ -380,10 +380,16 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 封装组id与域id对应关系并添加到对象中
|
||||
* 封装组id与域id对应关系
|
||||
*
|
||||
* @param maatXmlConfig
|
||||
* @param service
|
||||
* @param type
|
||||
* @param regionMapList
|
||||
* @param compileAndGroupRelations
|
||||
* @param groupAndRegionMap
|
||||
* @param redisDBSetStr 当前配置下发到哪些redisdb中
|
||||
* @param commonGroupIdList 公共组id集合
|
||||
* @return
|
||||
*/
|
||||
private Map<String, Set<String>> addGroupAndRegionRelations(MaatXmlConfig maatXmlConfig, int service, int type,
|
||||
List<Map<String, String>> regionMapList, Map<String, Set<String>> groupAndRegionMap, String redisDBSetStr,
|
||||
@@ -429,7 +435,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
|
||||
String groupIdStr = "GROUPREGION:" + groupId;// groupregion里面value是region的信息,key是group的信息
|
||||
if (commonGroupIdList.contains(groupId)) {
|
||||
groupIdStr = "COMMONGROUPREGION:" + groupId;
|
||||
groupIdStr = "COMMONGROUPREGION:" + groupId;// 公共组以COMMONGROUPREGION开头和普通的组标识开
|
||||
}
|
||||
|
||||
if (groupAndRegionMap.containsKey(groupIdStr.toUpperCase())) {
|
||||
@@ -479,13 +485,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
setConfig(maatConfig, maatXmlConfig, maatVersion, service, transaction,
|
||||
redisDBIndex, commonGroupIdList);
|
||||
}
|
||||
if (commonGroupIdList != null && commonGroupIdList.size() > 0) {
|
||||
if (commonGroupIdList != null && commonGroupIdList.size() > 0) {// 如果有公共组则将每个redisdb的版本都加1
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
transaction.select(Integer.parseInt(db));
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION", Integer.parseInt(db));
|
||||
}
|
||||
} else {
|
||||
} else {// 没有公共组则只更新当前的redisdb
|
||||
transaction.select(redisDBIndex);
|
||||
transaction.incrBy("MAAT_VERSION", 1l);
|
||||
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
|
||||
@@ -571,23 +577,23 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将整理好的数据添加到redis中,如果是分组复用时,则去临时库将对应的域找到复制过来,如果当前库存在则不复制了(在复制就重复了)
|
||||
* 将整理好的数据添加到redis中
|
||||
*
|
||||
* @param maatXmlConfig
|
||||
* @param map
|
||||
* @param type
|
||||
* @param maatVersion
|
||||
* @param service
|
||||
* @param redisTemplate
|
||||
* @param map 数据
|
||||
* @param type 标识是编译,组还是ip域,字符串域,数值域等
|
||||
* @param maatVersion maatversion
|
||||
* @param service 业务类型
|
||||
* @param transaction
|
||||
* @param redisDBIndex
|
||||
* @param compileId
|
||||
* @param isReuse 是否是分组复用
|
||||
*/
|
||||
private void setCommonConfig(MaatXmlConfig maatXmlConfig, Map<String, String> map, int type, Double maatVersion,
|
||||
int service, Transaction transaction, Integer redisDBIndex, String compileId) {
|
||||
if (maatXmlConfig != null && map != null && map.size() > 0) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
String maatKey = null;
|
||||
transaction.select(redisDBIndex);
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (type == maatXmlExpr.getType().intValue()) {
|
||||
StringBuffer keyBF = new StringBuffer();
|
||||
@@ -678,17 +684,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
valBF.append(valStr.trim());
|
||||
}
|
||||
}
|
||||
transaction.select(redisDBIndex);
|
||||
maatKey = keyBF.toString();
|
||||
transaction.set(maatKey.toUpperCase(), valBF.toString());
|
||||
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", redisDBIndex, maatKey.toUpperCase(),
|
||||
valBF.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
transaction.select(redisDBIndex);
|
||||
updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, false);
|
||||
} else {
|
||||
if (maatXmlConfig == null) {
|
||||
@@ -1009,10 +1011,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
for (Long id : list) {
|
||||
// 按序号选择Redis数据库
|
||||
transaction.select(redisDb);
|
||||
if (!isStart && compileGroupMap.size() > 0) {
|
||||
if (!isStart && compileGroupMap.size() > 0) {// 失效并且有需要保留的group则将groupid的集合传到下一个方法中
|
||||
// 如果某一个配置下包含两个组,一个普通组,一个公共组,界面调用该接口时一定会保留公共组,
|
||||
// 该接口不能修改公共组的状态如果想对公共组进行操作,调用公共组的相关方法即可
|
||||
removeConfig(id, maatXmlConfig, maatVersion, service, transaction, redisDb,
|
||||
idRelaRedisDBIndex, isStart, compileGroupMap.get(id));
|
||||
} else {
|
||||
} else {// 将配置置为生效,或者删除时不保留groupid
|
||||
removeConfig(id, maatXmlConfig, maatVersion, service, transaction, redisDb,
|
||||
idRelaRedisDBIndex, isStart, null);
|
||||
}
|
||||
@@ -1085,7 +1089,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除maat类配置
|
||||
* 将配置置为生效或失效
|
||||
*
|
||||
* @param id 配置id
|
||||
* @param maatXmlConfig maat.xml中关于当前业务类型的key和value写法的对象
|
||||
@@ -1099,11 +1103,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
private void removeConfig(Long id, MaatXmlConfig maatXmlConfig, Double maatVersion, int service,
|
||||
Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex, boolean isStart,
|
||||
List<Long> keepGroupId) {
|
||||
|
||||
Map<String, Boolean> groupIsCommonMap = new HashMap<>();
|
||||
|
||||
Map<String, Boolean> groupIsCommonMap = new HashMap<>();// 记录公共组是否存在,避免每次都去redis中查询影响性能,,key是COMMONGROUPREGION:groupid,value是该组是否存在的标志
|
||||
if (maatXmlConfig != null) {
|
||||
Map<String, String> keyMap = new HashMap<>();
|
||||
Map<String, String> keyMap = new HashMap<>();// 记录每个key对应的value,避免每次去redis中查询,影响性能
|
||||
// 删除(重命名)编译配置
|
||||
removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion, service, transaction, redisDBIndex,
|
||||
null, isStart);// 10代表是编译配置
|
||||
@@ -1113,115 +1115,104 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系,示例:
|
||||
// GROUPCOMPILE:25166-2,5;GROUPCOMPILE:25167-2,5;GROUPCOMPILE:25168-2,5
|
||||
if (compileStrVal != null && !compileStrVal.trim().equals("")) {
|
||||
String[] compileGroupStrArr = org.apache.commons.lang.StringUtils.split(compileStrVal, ";");
|
||||
String[] compileGroupStrArr = org.apache.commons.lang.StringUtils.split(compileStrVal, ";");// 获取当前编译下有哪些组
|
||||
for (String compileGroup : compileGroupStrArr) {
|
||||
// compileGroup=GROUPCOMPILE:25166-2, 5
|
||||
// compileGroup=GROUPCOMPILE:编译id-redisdb1,redisdb2
|
||||
if (compileGroup != null && !compileGroup.trim().equals("")) {
|
||||
String groupCompileStrs = getRegionInfo(compileGroup);// 获取编译对应的分组信息,去除后面的redisdb信息,GROUPCOMPILE:25166
|
||||
if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) {// 遍历编译和分组的信息
|
||||
String[] split = org.apache.commons.lang.StringUtils.split(groupCompileStrs, ";");
|
||||
|
||||
for (String groupId : split) {// GROUPCOMPILE:groupid
|
||||
if (groupId != null && !groupId.trim().equals("")) {
|
||||
String groupCompileAndDBStrs = null;
|
||||
if (!keyMap.containsKey(groupId)) {
|
||||
groupCompileAndDBStrs = JedisUtils.get(groupId, idRelaRedisDBIndex);
|
||||
keyMap.put(groupId, groupCompileAndDBStrs);
|
||||
} else {
|
||||
groupCompileAndDBStrs = keyMap.get(groupId);
|
||||
}
|
||||
String groupIdReal = groupId.replace("GROUPCOMPILE:", "");
|
||||
String[] compileGroupArr = org.apache.commons.lang.StringUtils
|
||||
.split(groupCompileAndDBStrs, ";");// 获取组对应的编译id,示例:
|
||||
// ;COMPILEGROUP:24070-2, 5
|
||||
for (String groupAndCompileStr : compileGroupArr) {
|
||||
if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) {
|
||||
String compileId = getRegionInfo(groupAndCompileStr);// COMPILEGROUP:24070
|
||||
if (compileId != null && !compileId.trim().equals("")) {
|
||||
|
||||
if (isStart || (keepGroupId != null && keepGroupId.size() > 0
|
||||
&& !keepGroupId.contains(Long.parseLong(groupIdReal)))) {// 如果是修改为生效则置为生效,如果是失效如果包含保留的group,则不将域置为失效,否则将域置为失效,否
|
||||
if (compileId.equals(compileStr)) {//
|
||||
String groupRegionKey = groupId.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
boolean isCommonGroup = false;
|
||||
if (isStart) {
|
||||
String commonGroupRegionKey = groupId
|
||||
.replace("GROUPCOMPILE", "COMMONGROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
if (!groupIsCommonMap.containsKey(commonGroupRegionKey)) {
|
||||
boolean exist = JedisUtils.exists(commonGroupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
groupIsCommonMap.put(commonGroupRegionKey, exist);
|
||||
if (exist) {
|
||||
isCommonGroup = true;
|
||||
}
|
||||
|
||||
} else {
|
||||
isCommonGroup = groupIsCommonMap
|
||||
.get(commonGroupRegionKey);
|
||||
}
|
||||
String groupId = getRegionInfo(compileGroup);// 获取编译对应的分组信息,去除后面的redisdb信息,GROUPCOMPILE:25166
|
||||
if (groupId != null && !groupId.trim().equals("")) {
|
||||
String groupCompileAndDBStrs = null;
|
||||
if (!keyMap.containsKey(groupId)) {
|
||||
groupCompileAndDBStrs = JedisUtils.get(groupId, idRelaRedisDBIndex);
|
||||
keyMap.put(groupId, groupCompileAndDBStrs);
|
||||
} else {
|
||||
groupCompileAndDBStrs = keyMap.get(groupId);
|
||||
}
|
||||
String groupIdReal = groupId.replace("GROUPCOMPILE:", "");// 获取真实的groupid
|
||||
String[] compileGroupArr = org.apache.commons.lang.StringUtils.split(groupCompileAndDBStrs,
|
||||
";");// 获取组对应的编译id,示例:
|
||||
// ;COMPILEGROUP:24070-2, 5
|
||||
for (String groupAndCompileStr : compileGroupArr) {
|
||||
if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) {
|
||||
String compileId = getRegionInfo(groupAndCompileStr);// COMPILEGROUP:24070
|
||||
if (compileId != null && !compileId.trim().equals("")) {
|
||||
if (isStart || (keepGroupId != null && keepGroupId.size() > 0
|
||||
&& !keepGroupId.contains(Long.parseLong(groupIdReal)))) {
|
||||
// 如果是生效则根据关联关系将组下的域都改为生效
|
||||
// 如果是失效并且当前组不是需要保留的组,则将该组下的域置为失效
|
||||
if (compileId.equals(compileStr)) {// 判断编译id是否一致
|
||||
String groupRegionKey = groupId.replace("GROUPCOMPILE", "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
boolean isCommonGroup = false;
|
||||
if (isStart) {// 如果是生效,判断下是否是公共组
|
||||
String commonGroupRegionKey = groupId.replace("GROUPCOMPILE",
|
||||
"COMMONGROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
if (!groupIsCommonMap.containsKey(commonGroupRegionKey)) {
|
||||
boolean exist = JedisUtils.exists(commonGroupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
groupIsCommonMap.put(commonGroupRegionKey, exist);
|
||||
if (exist) {
|
||||
isCommonGroup = true;
|
||||
}
|
||||
if (!isCommonGroup) {// 如果是公共组则不进行操作,因为公共组本来就是有效的
|
||||
String regionStrs = null;
|
||||
if (!keyMap.containsKey(groupRegionKey)) {
|
||||
regionStrs = JedisUtils.get(groupRegionKey,
|
||||
idRelaRedisDBIndex);
|
||||
keyMap.put(groupRegionKey, regionStrs);
|
||||
} else {
|
||||
regionStrs = keyMap.get(groupRegionKey);
|
||||
}
|
||||
if (regionStrs != null && !regionStrs.trim().equals("")) {
|
||||
String[] regionStrArr = regionStrs.split(";");
|
||||
for (String str : regionStrArr) {
|
||||
if (str != null && !str.trim().equals("")) {
|
||||
|
||||
String regionStr = getRegionInfo(str);
|
||||
if (regionStr != null
|
||||
&& !regionStr.trim().equals("")) {
|
||||
String[] regionKeyArr = regionStr
|
||||
.split(";");
|
||||
if (regionKeyArr != null
|
||||
&& regionKeyArr.length > 0) {
|
||||
// 根据分组与域关联关系找到对应域配置然后删除(重命名)
|
||||
removeRegionConfig(maatXmlConfig,
|
||||
regionKeyArr, maatVersion,
|
||||
service, transaction,
|
||||
redisDBIndex, isStart);
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex
|
||||
} else {
|
||||
isCommonGroup = groupIsCommonMap.get(commonGroupRegionKey);
|
||||
}
|
||||
}
|
||||
if (!isCommonGroup) {
|
||||
// 如果是改为生效状态并且不是公共组,则将其下的域改为生效
|
||||
// 如果是失效(默认不是公共组isCommonGroup=false),则将其下的域改为失效
|
||||
String regionStrs = null;
|
||||
if (!keyMap.containsKey(groupRegionKey)) {
|
||||
regionStrs = JedisUtils.get(groupRegionKey, idRelaRedisDBIndex);// 获取组下面对应的域配置
|
||||
keyMap.put(groupRegionKey, regionStrs);
|
||||
} else {
|
||||
regionStrs = keyMap.get(groupRegionKey);
|
||||
}
|
||||
if (regionStrs != null && !regionStrs.trim().equals("")) {
|
||||
String[] regionStrArr = regionStrs.split(";");
|
||||
for (String str : regionStrArr) {
|
||||
if (str != null && !str.trim().equals("")) {
|
||||
String regionStr = getRegionInfo(str);
|
||||
if (regionStr != null && !regionStr.trim().equals("")) {
|
||||
String[] regionKeyArr = regionStr.split(";");
|
||||
if (regionKeyArr != null
|
||||
&& regionKeyArr.length > 0) {
|
||||
// 根据分组与域关联关系找到对应域配置,将域配置置为生效或失效(重命名)
|
||||
removeRegionConfig(maatXmlConfig, regionKeyArr,
|
||||
maatVersion, service, transaction,
|
||||
redisDBIndex, isStart);
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与域的关联关系,key为"
|
||||
+ groupRegionKey,
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
}
|
||||
}
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 根据分组与编译关联关系找到对应分组配置然后删除(重命名)
|
||||
removeCompileAndGroupConfig(maatXmlConfig,
|
||||
groupId.replace("GROUPCOMPILE:", ""), 11, maatVersion, service,
|
||||
transaction, redisDBIndex, id + "", isStart);// 11代表是分组配置
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为"
|
||||
+ groupId,
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
}
|
||||
// 根据分组与编译关联关系找到对应分组配置然后置为生效或失效(重命名)
|
||||
removeCompileAndGroupConfig(maatXmlConfig, groupId.replace("GROUPCOMPILE:", ""),
|
||||
11, maatVersion, service, transaction, redisDBIndex, id + "", isStart);// 11代表是分组配置
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException("从" + idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与编译的关联关系,key为" + groupId,
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系,key为" + compileStr,
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系,key为" + compileStr,
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1425,7 +1416,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
* @param map redisdb与编译id的对应
|
||||
* @param transaction
|
||||
* @param isStart 是否将配置置为生效
|
||||
* @param compileGroupMap 将配置置为失效时,需要保留哪些组(一般针对分组复用的配置,保留当前组,下次可以重复利用改组及其下的域)
|
||||
* @param compileGroupMap 将配置置为失效时,需要保留哪些组(一般针对公共组的配置,保留当前组,下次可以重复利用改组及其下的域)
|
||||
* @return
|
||||
*/
|
||||
private boolean removeMaatRelation(Map<Integer, List<Long>> map, Transaction transaction, Boolean isStart,
|
||||
@@ -1437,74 +1428,93 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
List<Long> idList = map.get(service);
|
||||
if (idList != null && idList.size() > 0) {
|
||||
for (Long compileId : idList) {
|
||||
|
||||
List<Long> keepGroupIdList = compileGroupMap.get(compileId);
|
||||
|
||||
String compileStr = "COMPILEGROUP:" + compileId;
|
||||
String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系
|
||||
if (compileStrVal != null && !compileStrVal.trim().equals("")) {
|
||||
String[] split1 = org.apache.commons.lang.StringUtils.split(compileStrVal, ";");
|
||||
|
||||
for (String str : split1) {
|
||||
for (String str : split1) {// 遍历编译下的所有组
|
||||
if (str != null && !str.trim().equals("")) {
|
||||
String groupCompileStr = getRegionInfo(str);
|
||||
if (groupCompileStr != null && !groupCompileStr.equals("")) {
|
||||
String[] groupCompileStrSplit =
|
||||
String groupCompile = getRegionInfo(str);// 去除redisdb,获取组的真实groupcompile
|
||||
if (groupCompile != null && !groupCompile.equals("")) {
|
||||
String compileGroupStr = JedisUtils.get(groupCompile.toUpperCase(),
|
||||
idRelaRedisDBIndex); // 获取当前分组关系对应的编译信息
|
||||
if (compileGroupStr != null && !compileGroupStr.equals("")) {
|
||||
String[] compileGroupStrSplit = org.apache.commons.lang.StringUtils
|
||||
.split(compileGroupStr, ";");
|
||||
for (String compileGroup : compileGroupStrSplit) {
|
||||
compileGroup = getRegionInfo(compileGroup);
|
||||
if (compileGroup.toUpperCase().equals(compileStr.toUpperCase())) {// 判断是否是同一个配置
|
||||
// 域
|
||||
String groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
// String commonGroupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
// "COMMONGROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
|
||||
org.apache.commons.lang.StringUtils.split(groupCompileStr, ";");// 得到分组关系
|
||||
for (String groupCompile : groupCompileStrSplit) {// 遍历所有分组关系
|
||||
String groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);// 获取普通group下面的region
|
||||
|
||||
if (groupCompile != null && !groupCompile.trim().equals("")) {
|
||||
if (groupRegionVal == null || groupRegionVal.trim().equals("")) {// 如果从普通的组中无法获,取则尝试下获取公共组
|
||||
|
||||
String compileGroupStr = getRegionInfo(
|
||||
JedisUtils.get(groupCompile.toUpperCase(), idRelaRedisDBIndex));// 获取当前分组关系对应的编译信息
|
||||
if (compileGroupStr != null && !compileGroupStr.equals("")) {
|
||||
String[] compileGroupStrSplit = org.apache.commons.lang.StringUtils
|
||||
.split(compileGroupStr, ";");
|
||||
// 被分组复用的业务,不能将域置为失效,其分组关系也不置为失效
|
||||
groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"COMMONGROUPREGION");
|
||||
|
||||
if (compileGroupStrSplit[0].toUpperCase()
|
||||
.equals(compileStr.toUpperCase())) {
|
||||
String groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
// String commonGroupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
// "COMMONGROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION
|
||||
|
||||
String groupRegionVal = JedisUtils.get(groupRegion,
|
||||
groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
|
||||
if (groupRegionVal == null
|
||||
|| groupRegionVal.trim().equals("")) {// 如果从普通的组中无法获,取则尝试下获取公共组
|
||||
|
||||
groupRegion = groupCompile.replace("GROUPCOMPILE",
|
||||
"COMMONGROUPREGION");
|
||||
|
||||
groupRegionVal = JedisUtils.get(groupRegion,
|
||||
idRelaRedisDBIndex);
|
||||
break;
|
||||
}
|
||||
if (groupRegionVal == null
|
||||
|| groupRegionVal.trim().equals("")) {// 如果普通的组和公共组都无法获取则给出错误提示
|
||||
throw new ServiceRuntimeException("从" + idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取"
|
||||
+ groupCompile.replace("GROUPCOMPILE",
|
||||
"COMMONGROUPREGION")
|
||||
+ "和"
|
||||
+ groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION")
|
||||
+ ",请检查groupid是否正确,或联系开发人员检查删除redis数据是否被人为删除了",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除分组与域的关联关系
|
||||
if (isStart) {// 将失效置为生效
|
||||
groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE",
|
||||
"EFFECTIVE_RULE");
|
||||
}
|
||||
if (groupRegionVal == null || groupRegionVal.trim().equals("")) {// 如果普通的组和公共组都无法获取则给出错误提示
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis库中无法获取"
|
||||
+ groupCompile.replace(
|
||||
"GROUPCOMPILE", "COMMONGROUPREGION")
|
||||
+ "和"
|
||||
+ groupCompile.replace("GROUPCOMPILE",
|
||||
"GROUPREGION")
|
||||
+ ",请检查groupid是否正确,或联系开发人员检查删除redis数据是否被人为删除了",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
try {
|
||||
// 修改分组与域的关联关系
|
||||
if (isStart) {// 将失效置为生效
|
||||
groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE",
|
||||
"EFFECTIVE_RULE");
|
||||
String[] split = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split.length > 1) {
|
||||
Set<String> set = new HashSet<>();
|
||||
for (String regionKeyStr : split) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim().equals("")) {
|
||||
set.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key
|
||||
} else {
|
||||
transaction.set(groupRegion.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
} else {// 将生效变为失效
|
||||
long groupId = -1l;
|
||||
if (groupRegion.contains("COMMONGROUPREGION:")) {
|
||||
groupId = Long.parseLong(
|
||||
groupRegion.replace("COMMONGROUPREGION:", ""));// 获取真实的groupid
|
||||
} else {
|
||||
groupId = Long.parseLong(
|
||||
groupRegion.replace("GROUPREGION:", ""));// 获取真实的groupid
|
||||
}
|
||||
if (!keepGroupIdList.contains(groupId)) {// 如果不是需要保留的groupid则失效(公共组不失效[如需失效使用公共组失效接口],非公共组则失效)
|
||||
groupRegionVal = groupRegionVal
|
||||
.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
String[] split = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split.length > 1) {
|
||||
Set<String> set = new HashSet<>();
|
||||
|
||||
for (String regionKeyStr : split) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim().equals("")) {
|
||||
@@ -1517,208 +1527,111 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key
|
||||
|
||||
} else {
|
||||
transaction.set(groupRegion.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
} else {// 将生效变为失效
|
||||
long groupId = Long.parseLong(
|
||||
groupRegion.replace("GROUPREGION:", ""));
|
||||
|
||||
if (!keepGroupIdList.contains(groupId)) {
|
||||
groupRegionVal = groupRegionVal
|
||||
.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
String[] split = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split.length > 1) {
|
||||
Set<String> set = new HashSet<>();
|
||||
|
||||
for (String regionKeyStr : split) {
|
||||
if (regionKeyStr != null && !regionKeyStr
|
||||
.trim().equals("")) {
|
||||
set.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key
|
||||
|
||||
} else {
|
||||
transaction.set(groupRegion.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从" + idRelaRedisDBIndex
|
||||
+ "号redis库中删除" + groupRegion
|
||||
+ "失败,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
String groupCompileStrVal = JedisUtils
|
||||
.get(groupCompile.toUpperCase(), idRelaRedisDBIndex);
|
||||
// 删除分组与编译的关联关系
|
||||
if (groupCompileStrVal != null
|
||||
&& !groupCompileStrVal.trim().equals("")) {
|
||||
String[] split = org.apache.commons.lang.StringUtils
|
||||
.split(groupCompileStrVal, ";");
|
||||
Set<String> set = new HashSet<>();
|
||||
for (String groupCompileAndDBStr : split) {
|
||||
if (groupCompileAndDBStr != null
|
||||
&& !groupCompileAndDBStr.trim().equals("")) {
|
||||
|
||||
if (groupCompileAndDBStr
|
||||
.contains(compileStr.toUpperCase())
|
||||
&& split.length == 1) {
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除当前组所对应的编译
|
||||
String groupRegionVal = JedisUtils.get(
|
||||
groupCompile.toUpperCase(),
|
||||
idRelaRedisDBIndex);
|
||||
if (isStart == null) {// 删除
|
||||
transaction.del(groupCompile.toUpperCase());// 删除编译与分组的关联关系
|
||||
} else if (isStart) {// 将失效置为生效
|
||||
groupRegionVal = groupRegionVal.replace(
|
||||
"OBSOLETE_RULE", "EFFECTIVE_RULE");
|
||||
String[] split2 = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split2.length > 1) {
|
||||
Set<String> set1 = new HashSet<>();
|
||||
for (String regionKeyStr : split2) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim()
|
||||
.equals("")) {
|
||||
set1.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set1) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(
|
||||
groupCompile.toUpperCase(),
|
||||
sb.toString());
|
||||
|
||||
} else {
|
||||
transaction.set(
|
||||
groupCompile.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
} else {// 将生效变为失效
|
||||
groupRegionVal = groupRegionVal.replace(
|
||||
"EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
|
||||
String[] split2 = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split2.length > 1) {
|
||||
|
||||
Set<String> set2 = new HashSet<>();
|
||||
for (String regionKeyStr : split2) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim()
|
||||
.equals("")) {
|
||||
set2.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set2) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(
|
||||
groupCompile.toUpperCase(),
|
||||
sb.toString());
|
||||
} else {
|
||||
transaction.set(
|
||||
groupCompile.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从"
|
||||
+ idRelaRedisDBIndex + "号redis库中删除"
|
||||
+ groupCompile.toUpperCase()
|
||||
+ "失败,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis
|
||||
.getValue());
|
||||
}
|
||||
|
||||
// } else if (!groupCompileAndDBStr
|
||||
// .contains(compileStr.toUpperCase())) {
|
||||
} else {
|
||||
set.add(groupCompileAndDBStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (set.size() > 0) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupCompile.toUpperCase(), sb.toString());// 重新设置分组与编译
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与编译的关联关系,key为"
|
||||
+ groupCompile.toUpperCase(),
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从" + idRelaRedisDBIndex
|
||||
+ "号redis库中删除" + groupRegion
|
||||
+ "失败,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex
|
||||
+ "号redis库中无法获取MAAT配置分组与编译的关联关系,key为"
|
||||
+ groupCompile.toUpperCase(),
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
Set<String> set = new HashSet<>();
|
||||
if (compileGroup.toUpperCase().equals(compileStr.toUpperCase())
|
||||
&& compileGroupStrSplit.length == 1) {// 判断是否是同一个配置
|
||||
try {
|
||||
// 为了提高效率,不判断了,如果报错直接捕捉异常处理
|
||||
// 删除当前组所对应的编译
|
||||
String groupRegionVal = JedisUtils
|
||||
.get(groupCompile.toUpperCase(), idRelaRedisDBIndex);
|
||||
if (isStart == null) {// 删除
|
||||
transaction.del(groupCompile.toUpperCase());// 删除编译与分组的关联关系
|
||||
} else if (isStart) {// 将失效置为生效
|
||||
groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE",
|
||||
"EFFECTIVE_RULE");
|
||||
String[] split2 = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split2.length > 1) {
|
||||
Set<String> set1 = new HashSet<>();
|
||||
for (String regionKeyStr : split2) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim().equals("")) {
|
||||
set1.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set1) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupCompile.toUpperCase(),
|
||||
sb.toString());
|
||||
|
||||
} else {
|
||||
transaction.set(groupCompile.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
} else {// 将生效变为失效
|
||||
groupRegionVal = groupRegionVal.replace("EFFECTIVE_RULE",
|
||||
"OBSOLETE_RULE");
|
||||
|
||||
String[] split2 = org.apache.commons.lang.StringUtils
|
||||
.split(groupRegionVal, ";");
|
||||
if (split2.length > 1) {
|
||||
|
||||
Set<String> set2 = new HashSet<>();
|
||||
for (String regionKeyStr : split2) {
|
||||
if (regionKeyStr != null
|
||||
&& !regionKeyStr.trim().equals("")) {
|
||||
set2.add(regionKeyStr);
|
||||
}
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String regionKeyStr : set2) {
|
||||
sb.append(";");
|
||||
sb.append(regionKeyStr);
|
||||
}
|
||||
transaction.set(groupCompile.toUpperCase(),
|
||||
sb.toString());
|
||||
} else {
|
||||
transaction.set(groupCompile.toUpperCase(),
|
||||
groupRegionVal);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceRuntimeException("从" + idRelaRedisDBIndex
|
||||
+ "号redis库中删除" + groupCompile.toUpperCase()
|
||||
+ "失败,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
} else {
|
||||
set.add(compileGroup);
|
||||
}
|
||||
|
||||
try {
|
||||
if (isStart == null) {// 删除
|
||||
transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系
|
||||
} else if (isStart) {// 将失效置为生效
|
||||
String groupRegionVal = JedisUtils.get(compileStr.toUpperCase(),
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE",
|
||||
"EFFECTIVE_RULE");
|
||||
transaction.set(compileStr.toUpperCase(), groupRegionVal);
|
||||
} else {// 将生效变为失效
|
||||
String groupRegionVal = JedisUtils.get(compileStr.toUpperCase(),
|
||||
idRelaRedisDBIndex);
|
||||
groupRegionVal = groupRegionVal.replace("EFFECTIVE_RULE",
|
||||
"OBSOLETE_RULE");
|
||||
transaction.set(compileStr.toUpperCase(), groupRegionVal);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis关联关系库中删除" + compileStr
|
||||
+ "失败,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
"从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为"
|
||||
+ groupCompile.toUpperCase(),
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis关联关系库中获取" + compileStr
|
||||
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new ServiceRuntimeException(
|
||||
"从" + idRelaRedisDBIndex + "号redis关联关系库中获取" + compileStr
|
||||
+ "的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
|
||||
RestBusinessCode.KeyNotExistsInRedis.getValue());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1760,7 +1673,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
if (keyStr.toLowerCase().contains("table_name")) {
|
||||
String argTableName = map.get("table_name");
|
||||
if (argTableName == null) {
|
||||
throw new ServiceRuntimeException("添加分组复用域配置时,必须要传入表名,请检查参数,配置类型:" + type + ",对应的真实表名",
|
||||
throw new ServiceRuntimeException("添加公共组域配置时,必须要传入表名,请检查参数,配置类型:" + type + ",对应的真实表名",
|
||||
RestBusinessCode.NotFoundTableName.getValue());
|
||||
} else {
|
||||
keyBF.append(argTableName);
|
||||
@@ -1884,9 +1797,6 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean updateGroupRegion(List<MaatConfig> configList, boolean isAdd) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
@@ -1929,18 +1839,18 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
|
||||
}
|
||||
} else {
|
||||
throw new ServiceRuntimeException("添加分组复用域配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
||||
throw new ServiceRuntimeException("添加公共组域配置时,未发现对应的配置信息,请检查配置参数是否正确",
|
||||
RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
}
|
||||
transaction.exec();
|
||||
return true;
|
||||
} catch (JedisConnectionException e) {
|
||||
String error = "连接redis异常,保存分组复用maat类域配置失败" + e.getMessage();
|
||||
String error = "连接redis异常,保存公共组maat类域配置失败" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
|
||||
} catch (Exception e) {
|
||||
|
||||
String error = "保存分组复用maat类域配置发生了异常" + e.getMessage();
|
||||
String error = "保存公共组maat类域配置发生了异常" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
transaction.discard();
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
|
||||
@@ -1994,29 +1904,41 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param maatConfig
|
||||
* @param maatXmlConfig
|
||||
* @param maatVersion
|
||||
* @param service
|
||||
* @param transaction
|
||||
* @param redisDBIndex
|
||||
* @param isCommonGroup 是否是公共组,如果是公共组则需要向所有的db下发
|
||||
*/
|
||||
|
||||
/**
|
||||
* 保存域配置信息,如果当前域所属的组是公共组则需要向所有的redisdb中下发域配置,否则只向指定的组下发
|
||||
*
|
||||
* @param maatConfig 配置信息
|
||||
* @param maatXmlConfig 配置的表达式
|
||||
* @param maatVersion 版本号
|
||||
* @param service 业务类型
|
||||
* @param transaction redis连接
|
||||
* @param redisDBIndex redis编号
|
||||
* @param isCommonGroup 是否是公共组,如果是公共组则需要向所有的db下发
|
||||
* @param maatConfig 配置信息
|
||||
* @param maatXmlConfig 配置的表达式
|
||||
* @param maatVersion 版本号
|
||||
* @param service 业务类型
|
||||
* @param transaction redis连接
|
||||
* @param redisDBIndex redis编号
|
||||
* @param commonGroupIdList
|
||||
* @return
|
||||
*/
|
||||
private Integer addRegion(MaatConfig maatConfig, MaatXmlConfig maatXmlConfig, Double maatVersion, int service,
|
||||
Transaction transaction, Integer redisDBIndex, List<Long> commonGroupIdList) {
|
||||
// Boolean serviceIsReuse = ServiceAndRDBIndexReal.serviceIsReuse(service);
|
||||
int count = 0;// 计算下所有的域是不是都没有值,如果没有值则给出提示
|
||||
int count = 0;// 计算下所有的域
|
||||
List<Map<String, String>> ipRegionMapList = maatConfig.getIpRegionMapList();
|
||||
|
||||
if (ipRegionMapList != null && ipRegionMapList.size() > 0) {
|
||||
count += ipRegionMapList.size();
|
||||
for (Map<String, String> map : ipRegionMapList) {
|
||||
Long groupId = Long.parseLong(map.get("group_id"));
|
||||
boolean isCommonGroup = commonGroupIdList.contains(groupId);
|
||||
if (isCommonGroup) {
|
||||
boolean isCommonGroup = commonGroupIdList.contains(groupId);// 判断当前域是否属于公共组
|
||||
if (isCommonGroup) {// 如果属于公共组则向所有的数据库下发一份
|
||||
for (String db : Constants.COMMONGROUPDBARR) {
|
||||
setCommonConfig(maatXmlConfig, map, 12, maatVersion, service, transaction, Integer.parseInt(db),
|
||||
null);// 12代表是ip类域配置
|
||||
@@ -2124,15 +2046,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
// if (count == 0 && isReuseSaveRegion) {
|
||||
// throw new ServiceRuntimeException("添加分组复用域配置时,所有的域配置都为空,请检查配置参数是否正确",
|
||||
// throw new ServiceRuntimeException("添加公共组域配置时,所有的域配置都为空,请检查配置参数是否正确",
|
||||
// RestBusinessCode.ConfigSourceIsNull.getValue());
|
||||
// }
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean delCommonGroup(Set<Long> groupIdList) {
|
||||
Jedis resource = JedisUtils.getResource(0);
|
||||
@@ -2173,7 +2092,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
transaction.select(everyDb);
|
||||
for (String regionKey : set) {
|
||||
String obsKey = regionKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
transaction.rename(regionKey,obsKey);
|
||||
transaction.rename(regionKey, obsKey);
|
||||
updateMaatInfo(expressionList, obsKey, transaction, maatVersion, everyDb, true);
|
||||
}
|
||||
}
|
||||
@@ -2191,12 +2110,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
} catch (JedisConnectionException e) {
|
||||
String error = "连接redis异常,删除分组复用maat类域配置失败" + e.getMessage();
|
||||
String error = "连接redis异常,删除公共组maat类域配置失败" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
|
||||
} catch (Exception e) {
|
||||
|
||||
String error = "删除分组复用maat类域配置发生了异常" + e.getMessage();
|
||||
String error = "删除公共组maat类域配置发生了异常" + e.getMessage();
|
||||
logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
|
||||
transaction.discard();
|
||||
throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue());
|
||||
|
||||
@@ -84,7 +84,7 @@ public interface ConfigRedisService {
|
||||
*
|
||||
* @param serviceConfigMap key是业务类型,value是配置id集合
|
||||
* @param isStart 是否置为生效,
|
||||
* @param compileGroupMap 在将配置置为失效时,需要保留的groupid,key是compileid,value是groupid集合
|
||||
* @param compileGroupMap 在将配置置为失效时,需要保留的groupid,key是compileid,value是该compileid下的groupid集合
|
||||
* @return 成功返回true,失败返回false或抛出异常
|
||||
*/
|
||||
public boolean updateMaatStatus(Map<Integer, List<Long>> serviceConfigMap, boolean isStart,
|
||||
|
||||
@@ -124,6 +124,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
StringBuffer sb) throws Exception {
|
||||
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
//公共组的groupid
|
||||
Set<Long> commonGroupIdSet = new HashSet<>();
|
||||
for (ConfigCompile configCompile : configCompileList) {
|
||||
Integer service = Integer.valueOf(configCompile.getService().toString());
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -368,8 +368,3 @@ maat2Valve=1:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;2:strRegion@ACT
|
||||
webFocusDb=7
|
||||
maat2WebFocus=512:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;514:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;
|
||||
|
||||
|
||||
##记录哪些service可以被分组复用(只有maat类配置可以被分组复用)
|
||||
#业务ID:域类型1@表名,表名|域类型2@表名;业务ID:域类型1@表名,表名|域类型2@表名
|
||||
##域类型:IP域 =ipRegion 字符串域=strRegion 数值域=numRegion
|
||||
serviceRepeatedReal=400:ipRegion@ASN_IP_REGION;1028:ipRegion@APP_STATIC_SEV_IP
|
||||
|
||||
@@ -167,14 +167,6 @@
|
||||
</taglib>
|
||||
</jsp-config>
|
||||
|
||||
|
||||
|
||||
<!-- 项目启动时加载编译id,组id,域id之间的关系 -->
|
||||
<!-- <listener> -->
|
||||
<!-- <listener-class> -->
|
||||
<!-- com.nis.listener.CompileGroupRegionRela -->
|
||||
<!-- </listener-class> -->
|
||||
<!-- </listener> -->
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DruidStatView</servlet-name>
|
||||
|
||||
Reference in New Issue
Block a user