1:修改非maat结构的配置下发方法
2:提交maat结构下发配置 3:添加业务类型与redisDBIndex的对应关系
This commit is contained in:
@@ -7,6 +7,7 @@ public class MaatXmlExpr implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String keyExpression;
|
||||
private String valueExpression;
|
||||
private Integer type;
|
||||
private Integer redisDB;
|
||||
|
||||
public String getKeyExpression() {
|
||||
@@ -29,6 +30,14 @@ public class MaatXmlExpr implements Serializable {
|
||||
return redisDB;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setRedisDB(Integer redisDB) {
|
||||
this.redisDB = redisDB;
|
||||
}
|
||||
|
||||
104
src/main/java/com/nis/domain/restful/MaatConfig.java
Normal file
104
src/main/java/com/nis/domain/restful/MaatConfig.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package com.nis.domain.restful;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>Title: MaatConfig</p>
|
||||
* <p>Description: 将编译,组,域配置封装bean</p>
|
||||
* <p>Company: IIE</p>
|
||||
* @author rkg
|
||||
* @date 2018年5月22日
|
||||
*
|
||||
*/
|
||||
public class MaatConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 编译配置
|
||||
*/
|
||||
private Map<String, String> compileMap;
|
||||
/**
|
||||
* 分组配置
|
||||
*/
|
||||
private Map<String, String> groupMap;
|
||||
/**
|
||||
* ip域配置
|
||||
*/
|
||||
private Map<String, String> ipRegionMap;
|
||||
/**
|
||||
* 数值域配置
|
||||
*/
|
||||
private Map<String, String> numRegionMap;
|
||||
/**
|
||||
* 字符串域配置
|
||||
*/
|
||||
private Map<String, String> strRegionMap;
|
||||
/**
|
||||
* 增强字符串域配置
|
||||
*/
|
||||
private Map<String, String> strStrRegionMap;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private Integer service;
|
||||
|
||||
public Map<String, String> getCompileMap() {
|
||||
return compileMap;
|
||||
}
|
||||
|
||||
public void setCompileMap(Map<String, String> compileMap) {
|
||||
this.compileMap = compileMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getGroupMap() {
|
||||
return groupMap;
|
||||
}
|
||||
|
||||
public void setGroupMap(Map<String, String> groupMap) {
|
||||
this.groupMap = groupMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getIpRegionMap() {
|
||||
return ipRegionMap;
|
||||
}
|
||||
|
||||
public void setIpRegionMap(Map<String, String> ipRegionMap) {
|
||||
this.ipRegionMap = ipRegionMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getNumRegionMap() {
|
||||
return numRegionMap;
|
||||
}
|
||||
|
||||
public void setNumRegionMap(Map<String, String> numRegionMap) {
|
||||
this.numRegionMap = numRegionMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getStrRegionMap() {
|
||||
return strRegionMap;
|
||||
}
|
||||
|
||||
public void setStrRegionMap(Map<String, String> strRegionMap) {
|
||||
this.strRegionMap = strRegionMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getStrStrRegionMap() {
|
||||
return strStrRegionMap;
|
||||
}
|
||||
|
||||
public void setStrStrRegionMap(Map<String, String> strStrRegionMap) {
|
||||
this.strStrRegionMap = strStrRegionMap;
|
||||
}
|
||||
|
||||
public Integer getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
public void setService(Integer service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public final class Configurations {
|
||||
prop.load(Configurations.class.getResourceAsStream("/nis.properties"));
|
||||
prop.load(Configurations.class.getResourceAsStream("/table.properties"));
|
||||
prop.load(Configurations.class.getResourceAsStream("/matt.properties"));
|
||||
prop.load(Configurations.class.getResourceAsStream("/serviceTable.properties"));
|
||||
|
||||
} catch (Exception e) {
|
||||
prop = null;
|
||||
|
||||
@@ -114,6 +114,21 @@ public class ReadMaatXmlUtil {
|
||||
for (Element ele : eleList) {
|
||||
if (ele.getName().toLowerCase().equals("keyexpression")) {
|
||||
maatXmlExpr.setKeyExpression(ele.getTextTrim());
|
||||
if (ele.getTextTrim().contains("compile_table_name")) {
|
||||
maatXmlExpr.setType(10);
|
||||
} else if (ele.getTextTrim().contains("group_table_name")) {
|
||||
maatXmlExpr.setType(11);
|
||||
} else if (ele.getTextTrim().contains("ip_region_table_name")) {
|
||||
maatXmlExpr.setType(12);
|
||||
} else if (ele.getTextTrim().contains("num_region_table_name")) {
|
||||
maatXmlExpr.setType(13);
|
||||
} else if (ele.getTextTrim().contains("str_region_table_name")) {
|
||||
maatXmlExpr.setType(14);
|
||||
} else if (ele.getTextTrim().contains("str_str_region_table_name")) {
|
||||
maatXmlExpr.setType(15);
|
||||
} else {
|
||||
maatXmlExpr.setType(16);
|
||||
}
|
||||
}
|
||||
if (ele.getName().toLowerCase().equals("valueexpression")) {
|
||||
maatXmlExpr.setValueExpression(ele.getTextTrim());
|
||||
@@ -121,6 +136,7 @@ public class ReadMaatXmlUtil {
|
||||
if (ele.getName().toLowerCase().equals("redisdb")) {
|
||||
maatXmlExpr.setRedisDB(Integer.parseInt(ele.getTextTrim()));
|
||||
}
|
||||
|
||||
}
|
||||
exprList.add(maatXmlExpr);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigSource;
|
||||
import com.nis.domain.restful.MaatConfig;
|
||||
import com.nis.restful.RestBusinessCode;
|
||||
import com.nis.restful.RestServiceException;
|
||||
import com.nis.util.Constants;
|
||||
@@ -28,6 +29,7 @@ import com.nis.web.controller.BaseRestController;
|
||||
import com.nis.web.service.SaveRequestLogThread;
|
||||
import com.nis.web.service.ServicesRequestLogService;
|
||||
import com.nis.web.service.restful.ConfigRedisService;
|
||||
import com.nis.web.service.restful.ConfigRedisServiceimpl;
|
||||
import com.nis.web.service.restful.ConfigSourcesService;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiOperation;
|
||||
@@ -58,28 +60,36 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||
public String testRedis(Integer type) {
|
||||
try {
|
||||
if(type==1) {
|
||||
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
|
||||
if (type == 1) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
long id=configRedisService.getIncrId("seq_compileid");
|
||||
//int id=2;
|
||||
map.put("cfg_id", id+"");
|
||||
Integer service = 98;
|
||||
long id = configRedisService.getIncrId("seq_compileid", service);
|
||||
// int id=2;
|
||||
map.put("cfg_id", id + "");
|
||||
map.put("is_valid", "1");
|
||||
map.put("dst_file", "home");
|
||||
map.put("dst_file_md5", "fasdfdasfsdafdsafadsf");
|
||||
map.put("time_stamp", new Date().getTime() + "");
|
||||
map.put("level", "20");
|
||||
map.put("file_id",id+"");
|
||||
configRedisService.saveConfigYSPDemoCompile(96,map);
|
||||
}else {
|
||||
map.put("file_id", id + "");
|
||||
map.put("service", service + "");
|
||||
listMap.add(map);
|
||||
configRedisService.saveUnMaatConfig(listMap,service);
|
||||
} else {
|
||||
Integer service = 100;
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
long id=configRedisService.getIncrId("seq_compileid");
|
||||
//int id=2;
|
||||
map.put("cfg_id", id+"");
|
||||
long id = configRedisService.getIncrId("seq_compileid", service);
|
||||
// int id=2;
|
||||
map.put("cfg_id", id + "");
|
||||
map.put("is_valid", "1");
|
||||
map.put("service", "100");
|
||||
map.put("description", "123"+id);
|
||||
map.put("description", "123" + id);
|
||||
map.put("level", "20");
|
||||
configRedisService.saveConfigYSPDemoCompile(100,map);
|
||||
listMap.add(map);
|
||||
map.put("service", service + "");
|
||||
configRedisService.saveUnMaatConfig(listMap,service);
|
||||
}
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
@@ -88,6 +98,74 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
return "false";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/saveMaat", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||
public String saveMaat(Integer service) {
|
||||
try {
|
||||
List<MaatConfig> listMap = new ArrayList<MaatConfig>();
|
||||
listMap.add(getMaatConfig(service));
|
||||
listMap.add(getMaatConfig(service));
|
||||
configRedisService.saveMaatConfig(listMap,service);
|
||||
// new ConfigRedisServiceimpl().GETMaatConfig(listMap);
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
public MaatConfig getMaatConfig(Integer service) {
|
||||
String time = new Date().getTime() + "";
|
||||
Map<String, String> configMap = new HashMap<String, String>();
|
||||
long seq_compileid = configRedisService.getIncrId("SEQ_COMPILEID", service);
|
||||
long seq_groupid = configRedisService.getIncrId("SEQ_GROUPID", service);
|
||||
long seq_regionid = configRedisService.getIncrId("SEQ_REGIONID", service);
|
||||
// int id=2;
|
||||
configMap.put("cfg_id", seq_compileid + "");
|
||||
configMap.put("service", service + "");
|
||||
configMap.put("action", "0");
|
||||
configMap.put("do_blacklist", "1");
|
||||
configMap.put("do_log", "1");
|
||||
configMap.put("effective_range", "0");
|
||||
configMap.put("user_region", "0");
|
||||
configMap.put("is_valid", "1");
|
||||
configMap.put("group_num", "1");
|
||||
configMap.put("father_cfg_id", "0");
|
||||
configMap.put("op_time", time);
|
||||
Map<String, String> groupMap = new HashMap<String, String>();
|
||||
groupMap.put("group_id", seq_groupid + "");
|
||||
groupMap.put("cfg_id", seq_compileid + "");
|
||||
groupMap.put("is_valid", "1");
|
||||
groupMap.put("op_time", time);
|
||||
groupMap.put("service", service + "");
|
||||
Map<String, String> strMap = new HashMap<String, String>();
|
||||
|
||||
strMap.put("group_id", seq_groupid + "");
|
||||
strMap.put("region_id", seq_regionid + "");
|
||||
strMap.put("addr_type", "4");
|
||||
strMap.put("src_ip", "0.0.0.0");
|
||||
strMap.put("mask_src_ip", "255.255.255.255");
|
||||
strMap.put("src_port", "0");
|
||||
strMap.put("mask_src_port", "0");
|
||||
strMap.put("dst_ip", "0.0.0.0");
|
||||
strMap.put("mask_dst_ip", "255.255.255.255");
|
||||
strMap.put("dst_port", "0");
|
||||
strMap.put("mask_dst_port", "0");
|
||||
strMap.put("protocol", "0");
|
||||
strMap.put("direction", "0");
|
||||
strMap.put("is_valid", "1");
|
||||
strMap.put("op_time", time);
|
||||
strMap.put("service", service + "");
|
||||
|
||||
MaatConfig maatConfig = new MaatConfig();
|
||||
maatConfig.setCompileMap(configMap);
|
||||
maatConfig.setGroupMap(groupMap);
|
||||
maatConfig.setService(service);
|
||||
maatConfig.setIpRegionMap(strMap);
|
||||
return maatConfig;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST)
|
||||
@ApiOperation(value = "业务配置存储", httpMethod = "POST", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储")
|
||||
@ApiParam(value = "业务配置数据源", name = "configSource", required = true)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.nis.domain.restful.MaatConfig;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>Title: ConfigRedisService</p>
|
||||
@@ -13,23 +16,23 @@ import java.util.Map;
|
||||
*/
|
||||
public interface ConfigRedisService {
|
||||
/**
|
||||
* 保存ysp样例配置接口
|
||||
* 保存非maat配置接口,例如ysp文件样例,ysp标志样例
|
||||
* @param listMap
|
||||
* @param service 业务类型
|
||||
* @param map
|
||||
*/
|
||||
public void saveConfigYSPDemoCompile(int service, Map<String, String> map);
|
||||
public void saveUnMaatConfig(List<Map<String, String>> listMap, int service);
|
||||
|
||||
/**
|
||||
* 保存ysp配置接口
|
||||
* @param service
|
||||
* @param map
|
||||
* 保存maat配置接口,例如ysp配置,文本类配置
|
||||
* @param maatConfigList
|
||||
* @param service 业务类型
|
||||
*/
|
||||
public void saveConfigYSPCompile(int service, Map<String, String> map);
|
||||
public void saveMaatConfig(List<MaatConfig> maatConfigList, int service);
|
||||
|
||||
/**
|
||||
* 获取指定key的自增长值
|
||||
* @param key 需要自增的key
|
||||
* @return
|
||||
*/
|
||||
public Long getIncrId(String key);
|
||||
public Long getIncrId(String key, int service);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -11,65 +14,139 @@ import com.nis.datasource.DynamicJedisDataBase;
|
||||
import com.nis.domain.MaatXmlConfig;
|
||||
import com.nis.domain.MaatXmlExpr;
|
||||
import com.nis.domain.MaatXmlSeq;
|
||||
import com.nis.domain.restful.MaatConfig;
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.util.ReadMaatXmlUtil;
|
||||
import com.nis.web.dao.impl.BaseRedisDao;
|
||||
|
||||
@Service("configRedisServiceimpl")
|
||||
@Service()
|
||||
public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> implements ConfigRedisService {
|
||||
@Transactional
|
||||
public void saveConfigYSPDemoCompile(int service, Map<String, String> map) {
|
||||
if (map != null && map.size() > 0) {
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
if (maatXmlConfig != null) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
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 {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
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("]", "");
|
||||
valBF.append(map.get(valStr));
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), redisTemplate);
|
||||
System.out.println(keyBF.toString());
|
||||
System.out.println(valBF.toString());
|
||||
/**
|
||||
* 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名
|
||||
*/
|
||||
private static Map<Integer, Map<Integer, String>> sercieNameMap = new HashMap<Integer, Map<Integer, String>>();
|
||||
/**
|
||||
* key是业务类型,value是业务类型对应的redisdbIndex
|
||||
*/
|
||||
private static Map<Integer, Integer> serviceDBIndexmap = new HashMap<Integer, Integer>();
|
||||
|
||||
redisTemplate.opsForValue().set(keyBF.toString(), new String(valBF));
|
||||
// redisTemplate.boundValueOps(keyBF.toString()).set(valBF.toString());
|
||||
|
||||
}
|
||||
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
||||
for (MaatXmlSeq maatXmlSeq : seqList) {
|
||||
DynamicJedisDataBase.setRedisDataBase(maatXmlSeq.getRedisDB(), redisTemplate);
|
||||
String seqKey = maatXmlSeq.getSequenceKey();
|
||||
Integer operation = maatXmlSeq.getOperation();
|
||||
if (operation == 1) {
|
||||
redisTemplate.boundValueOps(seqKey).increment(1);
|
||||
static {
|
||||
String service = Configurations.getStringProperty("service", "");
|
||||
if (service != null && !service.trim().equals("")) {
|
||||
String[] split = service.split(";");
|
||||
for (String str : split) {
|
||||
String type = Configurations.getStringProperty(str, "");
|
||||
if (type != null && !type.trim().equals("")) {
|
||||
Map<Integer, String> typeMap = new HashMap<Integer, String>();
|
||||
String[] typeArrs = type.split(";");
|
||||
for (String typeStr : typeArrs) {
|
||||
String[] typeArr = typeStr.split(":");
|
||||
typeMap.put(Integer.parseInt(typeArr[0]), typeArr[1]);
|
||||
}
|
||||
sercieNameMap.put(Integer.parseInt(str), typeMap);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
String serviceDBIndexs = Configurations.getStringProperty("serviceDBIndex", "");
|
||||
if (serviceDBIndexs != null && !serviceDBIndexs.trim().equals("")) {
|
||||
|
||||
String[] serviceDBIndexArr = serviceDBIndexs.split(";");
|
||||
for (String serviceDBIndexStr : serviceDBIndexArr) {
|
||||
String[] serviceDBIndex = serviceDBIndexStr.split(":");
|
||||
|
||||
serviceDBIndexmap.put(Integer.parseInt(serviceDBIndex[0]), Integer.parseInt(serviceDBIndex[1]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("\\t");
|
||||
@Autowired
|
||||
private OperRedisService operRedisService;
|
||||
|
||||
@Transactional
|
||||
public void saveUnMaatConfig(List<Map<String, String>> listMap, int service) {
|
||||
if (listMap != null && listMap.size() > 0) {
|
||||
String maatVersionStr = operRedisService.getMaatVersion(getRedisDBByService(service));
|
||||
if (maatVersionStr != null) {
|
||||
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
||||
|
||||
for (Map<String, String> map : listMap) {
|
||||
// String serviceStr = map.get("service");
|
||||
// int service = Integer.parseInt(serviceStr);
|
||||
DynamicJedisDataBase.setRedisDataBase(getRedisDBByService(service), redisTemplate);
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
if (maatXmlConfig != null) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
String maatKey = "";
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (16 == 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 {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
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("]", "");
|
||||
valBF.append(map.get(valStr));
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
// System.out.println(keyBF.toString());
|
||||
// System.out.println(valBF.toString());
|
||||
maatKey = keyBF.toString();
|
||||
redisTemplate.opsForValue().set(keyBF.toString().toUpperCase(), valBF.toString());
|
||||
break;
|
||||
}
|
||||
// redisTemplate.boundValueOps(keyBF.toString().toUpperCase()).set(valBF.toString());
|
||||
|
||||
}
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
|
||||
String zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
|
||||
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
|
||||
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_RULE_TIMER")) {
|
||||
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
|
||||
redisTemplate.boundZSetOps("MAAT_RULE_TIMER").add(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);
|
||||
}
|
||||
}
|
||||
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
||||
for (MaatXmlSeq maatXmlSeq : seqList) {
|
||||
// DynamicJedisDataBase.setRedisDataBase(maatXmlSeq.getRedisDB(),
|
||||
// redisTemplate);
|
||||
String seqKey = maatXmlSeq.getSequenceKey();
|
||||
if (!seqKey.toUpperCase().equals("MAAT_VERSION")) {
|
||||
Integer operation = maatXmlSeq.getOperation();
|
||||
if (operation == 1) {
|
||||
redisTemplate.boundValueOps(seqKey.toUpperCase()).increment(1l);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
redisTemplate.boundValueOps("MAAT_VERSION").set(maatVersion + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void test() {
|
||||
@@ -98,8 +175,122 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
}
|
||||
}
|
||||
|
||||
public Long getIncrId(String key) {
|
||||
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
||||
@Transactional
|
||||
public void saveMaatConfig(List<MaatConfig> maatConfigList, int service) {
|
||||
if (maatConfigList != null && maatConfigList.size() > 0) {
|
||||
String maatVersionStr = operRedisService.getMaatVersion(getRedisDBByService(service));
|
||||
if (maatVersionStr != null) {
|
||||
Long maatVersion = Long.valueOf(maatVersionStr) + 1;
|
||||
for (MaatConfig maatConfig : maatConfigList) {
|
||||
// Integer service = maatConfig.getService();
|
||||
// if (service != null) {
|
||||
DynamicJedisDataBase.setRedisDataBase(getRedisDBByService(service), redisTemplate);
|
||||
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
|
||||
setConfig(maatConfig, maatXmlConfig, maatVersion, service);
|
||||
// }
|
||||
}
|
||||
redisTemplate.boundValueOps("MAAT_VERSION").set(maatVersion + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setConfig(MaatConfig maatConfig, MaatXmlConfig maatXmlConfig, Long maatVersion, int service) {
|
||||
Map<String, String> compileMap = maatConfig.getCompileMap();
|
||||
setCommonConfig(maatXmlConfig, compileMap, 10, maatVersion.doubleValue(), service);// 10代表是编译配置
|
||||
Map<String, String> groupMap = maatConfig.getGroupMap();
|
||||
setCommonConfig(maatXmlConfig, groupMap, 11, maatVersion.doubleValue(), service);// 11代表是分组配置
|
||||
Map<String, String> ipRegionMap = maatConfig.getIpRegionMap();
|
||||
setCommonConfig(maatXmlConfig, ipRegionMap, 12, maatVersion.doubleValue(), service);// 12代表是ip类域配置
|
||||
Map<String, String> numRegionMap = maatConfig.getNumRegionMap();
|
||||
setCommonConfig(maatXmlConfig, numRegionMap, 13, maatVersion.doubleValue(), service);// 13代表是数值类配置
|
||||
Map<String, String> strRegionMap = maatConfig.getStrRegionMap();
|
||||
setCommonConfig(maatXmlConfig, strRegionMap, 14, maatVersion.doubleValue(), service);// 14代表是字符串类域配置
|
||||
Map<String, String> strStrRegionMap = maatConfig.getStrStrRegionMap();
|
||||
setCommonConfig(maatXmlConfig, strStrRegionMap, 15, maatVersion.doubleValue(), service);// 15代表是增强字符串类域配置
|
||||
updateCommonKey(maatXmlConfig);
|
||||
}
|
||||
|
||||
public void setCommonConfig(MaatXmlConfig maatXmlConfig, Map<String, String> map, int type, Double maatVersion,
|
||||
int service) {
|
||||
if (maatXmlConfig != null && map != null && map.size() > 0) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
String maatKey = "";
|
||||
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")) {
|
||||
keyBF.append(getTableName(service, type));
|
||||
}
|
||||
|
||||
} else {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
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("]", "");
|
||||
valBF.append(map.get(valStr));
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
maatKey = keyBF.toString();
|
||||
// System.out.println(keyBF.toString());
|
||||
// System.out.println(valBF.toString());
|
||||
redisTemplate.opsForValue().set(maatKey.toUpperCase(), valBF.toString());
|
||||
// redisTemplate.boundValueOps(keyBF.toString()).set(valBF.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
|
||||
String zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
|
||||
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
|
||||
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_RULE_TIMER")) {
|
||||
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
|
||||
redisTemplate.boundZSetOps("MAAT_RULE_TIMER").add(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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCommonKey(MaatXmlConfig maatXmlConfig) {
|
||||
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
|
||||
for (MaatXmlSeq maatXmlSeq : seqList) {
|
||||
// DynamicJedisDataBase.setRedisDataBase(maatXmlSeq.getRedisDB(),
|
||||
// redisTemplate);
|
||||
String seqKey = maatXmlSeq.getSequenceKey();
|
||||
if (!seqKey.toUpperCase().equals("MAAT_VERSION")) {
|
||||
Integer operation = maatXmlSeq.getOperation();
|
||||
if (operation == 1) {
|
||||
redisTemplate.boundValueOps(seqKey).increment(1l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Long getIncrId(String key, int service) {
|
||||
DynamicJedisDataBase.setRedisDataBase(getRedisDBByService(service), redisTemplate);
|
||||
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
||||
// redisTemplate.getConnectionFactory());
|
||||
//
|
||||
@@ -108,12 +299,41 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
// atomicLong.expire(liveTime, TimeUnit.SECONDS);
|
||||
// }
|
||||
// return id;
|
||||
return redisTemplate.boundValueOps(key).increment(1l);
|
||||
return redisTemplate.boundValueOps(key.toUpperCase()).increment(1l);
|
||||
// return redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void saveConfigYSPCompile(int service, Map<String, String> map) {
|
||||
public static Integer getRedisDBByService(Integer service) {
|
||||
Integer redisIndex = serviceDBIndexmap.get(service);
|
||||
if (redisIndex == null) {
|
||||
return 0;
|
||||
}
|
||||
return redisIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务类型和具体的type获取对应的表名
|
||||
// * @param service 业务类型
|
||||
* @param type 10代表是编译配置,11代表是分组配置,12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置
|
||||
* @return
|
||||
*/
|
||||
public static String getTableName(int service, int type) {
|
||||
Map<Integer, String> typeMap = sercieNameMap.get(service);
|
||||
if (typeMap != null && typeMap.size() > 0) {
|
||||
return typeMap.get(type);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String filePath = "http://10.0.6.192/group1/M00/00/01/CgAGwFr9LriANfj6AADz3NN2rlY448.jpg";
|
||||
String substr = filePath.substring(filePath.indexOf("group"));
|
||||
String[] split = "maat_update_status".split(";");
|
||||
System.out.println(substr);
|
||||
|
||||
getRedisDBByService(80);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.nis.datasource.DynamicJedisDataBase;
|
||||
import com.nis.web.dao.impl.BaseRedisDao;
|
||||
|
||||
@Service()
|
||||
public class OperRedisService extends BaseRedisDao<String, String> {
|
||||
|
||||
public String getMaatVersion(int redisIndex) {
|
||||
DynamicJedisDataBase.setRedisDataBase(redisIndex, redisTemplate);
|
||||
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
||||
// redisTemplate.getConnectionFactory());
|
||||
//
|
||||
// Long id = atomicLong.getAndIncrement() + 1;
|
||||
// if ((id == null || id.longValue() == 0) && liveTime > 0) {
|
||||
// atomicLong.expire(liveTime, TimeUnit.SECONDS);
|
||||
// }
|
||||
// return id;
|
||||
|
||||
return redisTemplate.opsForValue().get("MAAT_VERSION");
|
||||
|
||||
// return redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||
// return redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user