1:添加对区域ip管控类域配置的支持

2:优化对数据的判断抛出相应的异常
This commit is contained in:
RenKaiGe-Office
2018-06-04 10:18:31 +08:00
parent 226cab3796
commit 90e96391f8
8 changed files with 265 additions and 190 deletions

View File

@@ -50,7 +50,7 @@ public class MaatConfig implements Serializable {
private List<Map<String, String>> fileLikeRegionMapList;
/**
*
* 区域ip域配置
*/
private List<Map<String, String>> ipClientRangeMapList;
/**
@@ -126,8 +126,7 @@ public class MaatConfig implements Serializable {
return ipClientRangeMapList;
}
public void setIpClientRangeMapList(
List<Map<String, String>> ipClientRangeMapList) {
public void setIpClientRangeMapList(List<Map<String, String>> ipClientRangeMapList) {
this.ipClientRangeMapList = ipClientRangeMapList;
}

View File

@@ -127,6 +127,8 @@ public class ReadMaatXmlUtil {
maatXmlExpr.setType(16);
} else if (ele.getTextTrim().contains("file_like_table_name")) {
maatXmlExpr.setType(17);
} else if (ele.getTextTrim().contains("ip_client_range_table_name")) {
maatXmlExpr.setType(18);
} else {
maatXmlExpr.setType(0);
}

View File

@@ -313,14 +313,14 @@ public class ConfigSourcesController extends BaseRestController {
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
String msg = "";
ConfigCompile compile = configSource.getConfigCompileList().get(0);
//zdx 20180528改为调用rkg接口取消配置
// zdx 20180528改为调用rkg接口取消配置
msg = configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(),
configSource.getOpTime(), sb);
if (msg.equals("error")) {
Exception exception = ConfigSourcesService.getMsgList().get(0);
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"修改编译配置状态时出现异常"+exception.getMessage(), RestBusinessCode.unknow_error.getValue());
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"修改编译配置状态时出现异常" + exception.getMessage(), RestBusinessCode.unknow_error.getValue());
}
// configSourcesService.updateConfigSource(thread, start,
// configSource.getConfigCompileList(),
@@ -362,11 +362,12 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
RestBusinessCode.missing_args.getValue());
}
// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null
// && !configCompile.getEffectiveRange().equals(""))) {
// count++;
// configSourcesService.setCompileInvalid(configCompile);
// }
// if ((configCompile.getActiveSys() != null) ||
// (configCompile.getEffectiveRange() != null
// && !configCompile.getEffectiveRange().equals(""))) {
// count++;
// configSourcesService.setCompileInvalid(configCompile);
// }
}
if (count > 0) {
Thread.sleep(14000);
@@ -394,33 +395,34 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
RestBusinessCode.missing_args.getValue());
}
// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null
// && !configCompile.getEffectiveRange().equals(""))) {
// try {
// configSourcesService.setCompileValid(configCompile);
// } catch (Exception e1) {
// String errorCode = "";
// String message = e.getMessage();
// if (null != message && message.length() > 0) {
// int index = message.toUpperCase().indexOf("ORA-");
// if (index != -1) {
// errorCode = message.substring(index + 4, index + 9);
//
// }
// }
// Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil
// .throwExceptionInfo(errorCode);
// for (int errorNum : throwExceptionInfo.keySet()) {
// if (errorNum == 998) {
// thread.setExceptionInfo(e.toString());
// } else {
// thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
// }
// throw new RestServiceException(thread, System.currentTimeMillis() - start,
// throwExceptionInfo.get(errorNum), errorNum);
// }
// }
// }
// if ((configCompile.getActiveSys() != null) ||
// (configCompile.getEffectiveRange() != null
// && !configCompile.getEffectiveRange().equals(""))) {
// try {
// configSourcesService.setCompileValid(configCompile);
// } catch (Exception e1) {
// String errorCode = "";
// String message = e.getMessage();
// if (null != message && message.length() > 0) {
// int index = message.toUpperCase().indexOf("ORA-");
// if (index != -1) {
// errorCode = message.substring(index + 4, index + 9);
//
// }
// }
// Map<Integer, String> throwExceptionInfo = OracleErrorCodeUtil
// .throwExceptionInfo(errorCode);
// for (int errorNum : throwExceptionInfo.keySet()) {
// if (errorNum == 998) {
// thread.setExceptionInfo(e.toString());
// } else {
// thread.setExceptionInfo(throwExceptionInfo.get(errorNum));
// }
// throw new RestServiceException(thread, System.currentTimeMillis() - start,
// throwExceptionInfo.get(errorNum), errorNum);
// }
// }
// }
}
}
@@ -497,23 +499,25 @@ public class ConfigSourcesController extends BaseRestController {
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置数据插入成功",
Constants.IS_DEBUG ? jsonString : null);
}
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT)
@ApiOperation(value = "回调配置状态修改", httpMethod = "PUT", response = Map.class, notes = "回调配置状态修改服务")
@ApiParam(value = "回调配置状态修改", name = "updateStatConfigSource", required = true)
public Map updateCommonConfigSource(@RequestBody UpdateStatConfigSource updateStatConfigSource, HttpServletRequest request,
HttpServletResponse response) {
public Map updateCommonConfigSource(@RequestBody UpdateStatConfigSource updateStatConfigSource,
HttpServletRequest request, HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,updateStatConfigSource);
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
updateStatConfigSource);
StringBuffer sb = new StringBuffer();
configSourcesService.updateCommonSources(thread, start, updateStatConfigSource.getUpdateStatCfgList(), new Date(),sb);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"配置状态修改成功" , Constants.IS_DEBUG ? updateStatConfigSource : null);
configSourcesService.updateCommonSources(thread, start, updateStatConfigSource.getUpdateStatCfgList(),
new Date(), sb);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置状态修改成功",
Constants.IS_DEBUG ? updateStatConfigSource : null);
}
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST)
@ApiOperation(value = "样例文件上传服务", httpMethod = "POST", response = Map.class, notes = "样例文件上传服务")
@ApiParam(value = "样例文件上传服务", name = "MultipartFile", required = true)
@@ -521,33 +525,37 @@ public class ConfigSourcesController extends BaseRestController {
HttpServletResponse response) {
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null);
String filePath ="";
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
null);
String filePath = "";
try {
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class);
if(null==file){
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),
FileDesc.class);
if (null == file) {
thread.setExceptionInfo("请选择上传文件到file参数");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请选择上传文件到file参数",
RestBusinessCode.missing_args.getValue());
}
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
//验证Md5
String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'"+md5+"'==='"+fileDesc.getChecksum()+"'");
// 验证Md5
String md5 = DigestUtils.md5Hex(file.getInputStream());
//String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
if (!md5.equals(fileDesc.getChecksum())) {
thread.setExceptionInfo("checksum与文件MD5值不一致");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致",
RestBusinessCode.config_integrity_error.getValue());
}
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(),file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
// meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize()));
// meta_list[2] = new NameValuePair("fileExt", ext);
// meta_list[3] = new NameValuePair("fileAuthor", "rkg");
// meta_list[4] = new NameValuePair("fileMd5", md5);
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
// meta_list[1] = new NameValuePair("fileLength",
// String.valueOf(file.getSize()));
// meta_list[2] = new NameValuePair("fileExt", ext);
// meta_list[3] = new NameValuePair("fileAuthor", "rkg");
// meta_list[4] = new NameValuePair("fileMd5", md5);
logger.info("-----------------调用接口上传文件---------------");
filePath = FileManager.upload(fdsfile, null);
}
@@ -557,57 +565,58 @@ public class ConfigSourcesController extends BaseRestController {
}
JSONObject jsonObj = new JSONObject();
jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
// jsonObj.put("accessUrl", "filePath");
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"文件上传成功" ,jsonObj);
// jsonObj.put("accessUrl", "filePath");
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "文件上传成功", jsonObj);
}
@RequestMapping(value = "/cfg/v1/fileDigestSources", method = RequestMethod.POST)
@ApiOperation(value = "文件摘要获取", httpMethod = "POST", response = Map.class, notes = "文件摘要获取")
@ApiParam(value = "摘要文件", name = "MultipartFile", required = true)
public Map fileDigestSources(MultipartFile file,HttpServletRequest request,
HttpServletResponse response){
public Map fileDigestSources(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,file,null);
//JSONArray fileArray=new JSONArray();
if (file==null) {
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
file, null);
// JSONArray fileArray=new JSONArray();
if (file == null) {
thread.setExceptionInfo("请上传获取摘要的文件到file");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请上传获取摘要的文件到file参数",
RestBusinessCode.missing_args.getValue());
}
JSONObject resultObject = new JSONObject();
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),FileDesc.class);
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),
FileDesc.class);
try {
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
//验证Md5
String md5 = DigestUtils.md5Hex(file.getBytes());
System.out.println("----------------------------MD5:'"+md5+"'==='"+fileDesc.getChecksum()+"'");
// 验证Md5
String md5 = DigestUtils.md5Hex(file.getInputStream());
System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
if (!md5.equals(fileDesc.getChecksum())) {
thread.setExceptionInfo("checksum与文件MD5值不一致");
throw new RestServiceException(thread, System.currentTimeMillis() - start, "checksum与文件MD5值不一致",
RestBusinessCode.config_integrity_error.getValue());
}
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(),file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
// meta_list[1] = new NameValuePair("fileLength", String.valueOf(file.getSize()));
// meta_list[2] = new NameValuePair("fileExt", ext);
// meta_list[3] = new NameValuePair("fileAuthor", "rkg");
// meta_list[4] = new NameValuePair("fileMd5", md5);
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
// meta_list[1] = new NameValuePair("fileLength",
// String.valueOf(file.getSize()));
// meta_list[2] = new NameValuePair("fileExt", ext);
// meta_list[3] = new NameValuePair("fileAuthor", "rkg");
// meta_list[4] = new NameValuePair("fileMd5", md5);
logger.info("-----------------调用接口上传文件---------------");
String filePath = FileManager.upload(fdsfile, null);
resultObject.put("path", filePath.substring(filePath.indexOf("group")));
}
CommonsMultipartFile filetemp = (CommonsMultipartFile) file;
String tempFilePath = filetemp.getStorageDescription().toString();
tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[")+1, tempFilePath.indexOf("]"));
String digestStr = configSourcesService.getDigestGen(request.getRealPath(File.separator),tempFilePath);
String tempFilePath = filetemp.getStorageDescription().toString();
tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[") + 1, tempFilePath.indexOf("]"));
String digestStr = configSourcesService.getDigestGen(request.getRealPath(File.separator), tempFilePath);
resultObject.put("digest", digestStr);
resultObject.put("rawLen", file.getSize());
}catch (IOException e) {
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("文件上传过程中出现异常");
thread.setExceptionInfo("文件上传过程中出现异常");
@@ -621,8 +630,9 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "摘要获取过程中出现异常",
RestBusinessCode.unknow_error.getValue());
}
return serviceResponse(thread,System.currentTimeMillis()-start,request, response, "摘要获取成功",resultObject);
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "摘要获取成功", resultObject);
}
private boolean isBlank(Date datetime) {
if (null != datetime) {
return true;

View File

@@ -23,7 +23,6 @@ import com.nis.domain.restful.MaatConfig;
import com.nis.domain.restful.MaatRelation;
import com.nis.listener.CompileGroupRegionRela;
import com.nis.util.Configurations;
import com.nis.util.Exceptions;
import com.nis.util.ReadMaatXmlUtil;
import com.nis.util.ServiceAndRDBIndexReal;
import com.nis.web.service.SpringContextHolder;
@@ -41,108 +40,119 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
RedisTemplate<String, String> redisTemplate = SpringContextHolder
.getBean("redisTemplate" + redisDBIndex);
List<Map<String, String>> listMap = configMap.get(redisDBIndex);
if (listMap != null && listMap.size() > 0) {
String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION");
if (maatVersionStr == null) {
maatVersionStr = "0";
}
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);
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
if (maatXmlConfig != null) {
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
String maatKey = null;
for (MaatXmlExpr maatXmlExpr : expressionList) {
if (0 == 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("&nbsp")) {
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();
redisTemplate.opsForValue().set(keyBF.toString().toUpperCase(),
valBF.toString());
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", redisDBIndex,
keyBF.toString().toUpperCase(), valBF.toString());
break;
}
}
for (MaatXmlExpr maatXmlExpr : expressionList) {
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
if (maatKey != null) {
String zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
redisDBIndex, zset.toUpperCase(), maatVersion);
String maatVersionStr = redisTemplate.opsForValue().get("MAAT_VERSION");
if (maatVersionStr == null) {
maatVersionStr = "0";
}
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);
MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
if (maatXmlConfig != null) {
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
String maatKey = null;
for (MaatXmlExpr maatXmlExpr : expressionList) {
if (0 == 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());
}
} else if (maatXmlExpr.getKeyExpression().toUpperCase()
.equals("MAAT_RULE_TIMER")) {
if (maatKey != null) {
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
redisTemplate.boundZSetOps("MAAT_RULE_TIMER").add(maatKey, score);
logger.info("向{}号redis数据库更新了MAAT_RULE_TIMER,内容是{},SCORES是{}",
redisDBIndex, maatKey, score);
}
} else if (maatXmlExpr.getKeyExpression().toUpperCase()
.equals("MAAT_VERSION_TIMER")) {
Long nowTime = new Date().getTime();
nowTime = nowTime / 1000l;
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
redisTemplate.boundZSetOps("MAAT_VERSION_TIMER").add(maatVersion + "",
score);
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}",
redisDBIndex, maatVersion, score);
}
}
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
for (MaatXmlSeq maatXmlSeq : seqList) {
// 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);
}
}
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("&nbsp")) {
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();
redisTemplate.opsForValue().set(keyBF.toString().toUpperCase(),
valBF.toString());
logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", redisDBIndex,
keyBF.toString().toUpperCase(), valBF.toString());
break;
}
}
for (MaatXmlExpr maatXmlExpr : expressionList) {
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
if (maatKey != null) {
String zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,");
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, maatVersion);
logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}",
redisDBIndex, zset.toUpperCase(), maatVersion);
}
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_RULE_TIMER")) {
if (maatKey != null) {
Double score = 0d;// 界面下发的配置没有超时时间所以这里设置为0
redisTemplate.boundZSetOps("MAAT_RULE_TIMER").add(maatKey, score);
logger.info("向{}号redis数据库更新了MAAT_RULE_TIMER,内容是{},SCORES是{}", redisDBIndex,
maatKey, score);
}
} else if (maatXmlExpr.getKeyExpression().toUpperCase()
.equals("MAAT_VERSION_TIMER")) {
Long nowTime = new Date().getTime();
nowTime = nowTime / 1000l;
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
redisTemplate.boundZSetOps("MAAT_VERSION_TIMER").add(maatVersion + "", score);
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex,
maatVersion, score);
}
}
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
for (MaatXmlSeq maatXmlSeq : seqList) {
// 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);
}
}
} else {
throw new RuntimeException("无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
}
}
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1);
count++;
}
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1);
count++;
} else {
throw new RuntimeException("" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
}
} else {
throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号");
}
}
if (count == configMap.size()) {
return true;
}
} else {
throw new RuntimeException("参数不能为空");
}
return false;
}
@@ -176,8 +186,12 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
CompileGroupRegionRela.addIdRelation(redisDBIndex, compileAndGroupRelations);
}
}
} else {
throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号");
}
}
} else {
throw new RuntimeException("参数不能为空");
}
}
@@ -228,15 +242,21 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1);
count++;
} else {
throw new RuntimeException("" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
}
}
} else {
throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号");
}
}
if (count == configMap.size()) {
return true;
}
} else {
throw new RuntimeException("参数不能为空");
}
return false;
@@ -254,13 +274,21 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
public void setConfig(MaatConfig maatConfig, MaatXmlConfig maatXmlConfig, Long maatVersion, int service,
RedisTemplate<String, String> redisTemplate, Integer redisDBIndex) {
Map<String, String> compileMap = maatConfig.getCompileMap();
setCommonConfig(maatXmlConfig, compileMap, 10, maatVersion.doubleValue(), service, redisTemplate, redisDBIndex);// 10代表是编译配置
if (compileMap != null && compileMap.size() > 0) {
setCommonConfig(maatXmlConfig, compileMap, 10, maatVersion.doubleValue(), service, redisTemplate,
redisDBIndex);// 10代表是编译配置
} else {
throw new RuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的编译配置信息,请检查配置参数是否正确");
}
List<Map<String, String>> groupMapList = maatConfig.getGroupMapList();
if (groupMapList != null && groupMapList.size() > 0) {
for (Map<String, String> map : groupMapList) {
setCommonConfig(maatXmlConfig, map, 11, maatVersion.doubleValue(), service, redisTemplate,
redisDBIndex);// 11代表是分组配置
}
} else {
throw new RuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的分组配置信息,请检查配置参数是否正确");
}
List<Map<String, String>> ipRegionMapList = maatConfig.getIpRegionMapList();
@@ -305,6 +333,15 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisDBIndex);// 17代表是文本相似性域配置
}
}
List<Map<String, String>> ipclientList = maatConfig.getIpClientRangeMapList();
if (ipclientList != null && ipclientList.size() > 0) {
for (Map<String, String> map : ipclientList) {
setCommonConfig(maatXmlConfig, map, 18, maatVersion.doubleValue(), service, redisTemplate,
redisDBIndex);// 18代表是区域ip域配置
}
}
// updateCommonKey(maatXmlConfig);
}
@@ -388,6 +425,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex, maatVersion, score);
}
}
} else {
throw new RuntimeException("无法获取业务类型" + service + "对应的maat规则或传入的配置信息有误,请检查!");
}
}
@@ -506,22 +545,32 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
}
} else {
throw new RuntimeException(
"无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
}
}
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
Integer.valueOf(maatVersionStr) + 1);
count++;
} else {
throw new RuntimeException(
"无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的配置id信息,请检查配置参数是否正确");
}
}
}
} else {
throw new RuntimeException("" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
}
}
if (count == idMap.size()) {
return true;
}
} else {
throw new RuntimeException("参数信息有误,请检查!");
}
return false;
}
@@ -556,11 +605,15 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
count++;
}
}
} else {
throw new RuntimeException("" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确");
}
}
if (count == idMap.size()) {
return true;
}
} else {
throw new RuntimeException("参数信息有误,请检查!");
}
return false;
}
@@ -601,10 +654,14 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisTemplate, redisDBIndex);// 16代表是文件摘要类域配置
removeCommonConfig(maatXmlConfig, regionIdSet, 17, maatVersion.doubleValue(), service,
redisTemplate, redisDBIndex);// 17代表是文本相似性域配置
removeCommonConfig(maatXmlConfig, regionIdSet, 18, maatVersion.doubleValue(), service,
redisTemplate, redisDBIndex);// 18代表是区域ip域配置
}
}
}
}
} else {
throw new RuntimeException("无法获取内存中记录的id映射关系,无法获取业务类型" + service + "对应的maat规则或传入的配置id有误,请检查!");
}
}
@@ -683,6 +740,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
}
}
} else {
throw new RuntimeException("无法获取业务类型" + service + "对应的maat规则或传入的配置信息有误,请检查!");
}
}
@@ -707,8 +766,12 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
}
}
} else {
throw new RuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号");
}
}
} else {
throw new RuntimeException("参数不能为空");
}
}

View File

@@ -18,8 +18,6 @@ import java.util.concurrent.CountDownLatch;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.json.JSONObject;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@@ -63,6 +61,8 @@ import com.nis.web.service.BaseService;
import com.nis.web.service.SaveRequestLogThread;
import com.nis.web.service.SpringContextHolder;
import net.sf.json.JSONObject;
/**
* @ClassName: ControlService
* @Description: TODO(编译配置持久化)
@@ -1328,7 +1328,6 @@ public class ConfigSourcesService extends BaseService {
public String updateConfigSources(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList,
Date opTime, StringBuffer sb) {
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>();
if (null != compileList && compileList.size() > 0) {
for (ConfigCompile config : compileList) {
String msg = checkCompileOptForUpdate(config);