diff --git a/src/main/java/com/nis/domain/restful/MaatConfig.java b/src/main/java/com/nis/domain/restful/MaatConfig.java index c0dc1b5..f096773 100644 --- a/src/main/java/com/nis/domain/restful/MaatConfig.java +++ b/src/main/java/com/nis/domain/restful/MaatConfig.java @@ -50,7 +50,7 @@ public class MaatConfig implements Serializable { private List> fileLikeRegionMapList; /** - * + * 区域ip域配置 */ private List> ipClientRangeMapList; /** @@ -126,8 +126,7 @@ public class MaatConfig implements Serializable { return ipClientRangeMapList; } - public void setIpClientRangeMapList( - List> ipClientRangeMapList) { + public void setIpClientRangeMapList(List> ipClientRangeMapList) { this.ipClientRangeMapList = ipClientRangeMapList; } diff --git a/src/main/java/com/nis/util/ReadMaatXmlUtil.java b/src/main/java/com/nis/util/ReadMaatXmlUtil.java index cf03b9c..e25766e 100644 --- a/src/main/java/com/nis/util/ReadMaatXmlUtil.java +++ b/src/main/java/com/nis/util/ReadMaatXmlUtil.java @@ -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); } diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java index dc54a28..818c063 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -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 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 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());// 清除上次记录的日志信息 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());// 清除上次记录的日志信息 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; diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java index 705a636..2dcd3e9 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisServiceimpl.java @@ -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 redisTemplate = SpringContextHolder .getBean("redisTemplate" + redisDBIndex); List> 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 map : listMap) { + String serviceStr = map.get("service"); + int service = Integer.parseInt(serviceStr); + MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); + if (maatXmlConfig != null) { + List 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(" ")) { + 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 map : listMap) { - String serviceStr = map.get("service"); - int service = Integer.parseInt(serviceStr); - MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); - if (maatXmlConfig != null) { - List 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 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(" ")) { - 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 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 redisTemplate, Integer redisDBIndex) { Map 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> groupMapList = maatConfig.getGroupMapList(); if (groupMapList != null && groupMapList.size() > 0) { for (Map map : groupMapList) { setCommonConfig(maatXmlConfig, map, 11, maatVersion.doubleValue(), service, redisTemplate, redisDBIndex);// 11代表是分组配置 } + } else { + throw new RuntimeException("无法从参数中获取" + redisDBIndex + "号redis库,业务类型为:" + service + "的分组配置信息,请检查配置参数是否正确"); } List> ipRegionMapList = maatConfig.getIpRegionMapList(); @@ -305,6 +333,15 @@ public class ConfigRedisServiceimpl implements ConfigRedisService { redisDBIndex);// 17代表是文本相似性域配置 } } + + List> ipclientList = maatConfig.getIpClientRangeMapList(); + if (ipclientList != null && ipclientList.size() > 0) { + for (Map 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("参数不能为空"); } } diff --git a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java index e428031..f3d95d2 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -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 compileList, Date opTime, StringBuffer sb) { Map> compileMap = new HashMap>(); - List compileAllList = new ArrayList(); if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { String msg = checkCompileOptForUpdate(config); diff --git a/src/main/resources/maatXml/maat.xsd b/src/main/resources/maatXml/maat.xsd index ec0a4ec..3c30ad2 100644 --- a/src/main/resources/maatXml/maat.xsd +++ b/src/main/resources/maatXml/maat.xsd @@ -74,7 +74,7 @@ 编译表名:compile_table_name,分组表名:group_table_name,ip类域配置表名:ip_region_table_name, 数值类域配置表名:num_region_table_name,字符串类域配置表名:str_region_table_name, 增强字符串域配置表名:str_str_region_table_name,文件摘要类域配置表名:file_digest_table_name, - 文本相似性域配置表名:file_like_table_name。 + 文本相似性域配置表名:file_like_table_name,区域ip配置表名:ip_client_range_table_name。 直接写的代表是固定值,直接拼接即可, 每个属性间用分号分隔,空格用&nbsp表示]]> diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml index 1b4acd1..11d5abc 100644 --- a/src/main/resources/spring-mvc.xml +++ b/src/main/resources/spring-mvc.xml @@ -273,7 +273,7 @@ - + diff --git a/src/test/java/com/nis/test/RestTest.java b/src/test/java/com/nis/test/RestTest.java index d2e7485..04bdcf0 100644 --- a/src/test/java/com/nis/test/RestTest.java +++ b/src/test/java/com/nis/test/RestTest.java @@ -23,6 +23,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.params.CoreConnectionPNames; import org.apache.http.util.EntityUtils; import org.junit.Test; @@ -42,15 +43,17 @@ public class RestTest { public void testFileUpload() { CloseableHttpResponse response = null; try { - File file = new File("C:/Users/dell/Desktop/Lighthouse.jpg"); + File file = new File("F:/git.rar"); // String md5 = DigestUtils.md5Hex(file); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addBinaryBody("file", file); HttpPost request = new HttpPost( - "http://10.0.6.104:8080/galaxy/service/cfg/v1/fileUploadSources"); + "http://10.0.6.120:8080/galaxy/service/cfg/v1/fileUploadSources"); //galaxy/service/cfg/v1/fileUploadSources + request.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 600000); + request.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 600000); JSONObject jsonObject = new JSONObject(); jsonObject.put("filetype", "doc"); jsonObject.put("createTime", "2018-05-21 21:00:00"); @@ -58,13 +61,12 @@ public class RestTest { jsonObject.put("fileName", "1.png"); //jsonObject.put("checksum", "d99f9aa4f3748fa48aa6e350c628c67f"); - jsonObject.put("checksum", "8969288f4245120e7c3870287cce0ff3"); - + jsonObject.put("checksum", "faa364a36cddcbbfd65c0224f35fcfd0"); request.setHeader("File-Desc", jsonObject.toString()); HttpEntity entity = builder.build(); request.setEntity(entity); CloseableHttpClient httpClient = HttpClients.createDefault(); - + response = httpClient.execute(request); System.out.println(EntityUtils.toString(response.getEntity())); System.out.println("aa");