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

@@ -362,7 +362,8 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
RestBusinessCode.missing_args.getValue());
}
// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null
// if ((configCompile.getActiveSys() != null) ||
// (configCompile.getEffectiveRange() != null
// && !configCompile.getEffectiveRange().equals(""))) {
// count++;
// configSourcesService.setCompileInvalid(configCompile);
@@ -394,7 +395,8 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置id不能为空",
RestBusinessCode.missing_args.getValue());
}
// if ((configCompile.getActiveSys() != null) || (configCompile.getEffectiveRange() != null
// if ((configCompile.getActiveSys() != null) ||
// (configCompile.getEffectiveRange() != null
// && !configCompile.getEffectiveRange().equals(""))) {
// try {
// configSourcesService.setCompileValid(configCompile);
@@ -501,17 +503,19 @@ public class ConfigSourcesController extends BaseRestController {
@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);
configSourcesService.updateCommonSources(thread, start, updateStatConfigSource.getUpdateStatCfgList(),
new Date(), sb);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"配置状态修改成功" , Constants.IS_DEBUG ? updateStatConfigSource : null);
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置状态修改成功",
Constants.IS_DEBUG ? updateStatConfigSource : null);
}
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST)
@@ -521,10 +525,12 @@ 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);
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);
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参数",
@@ -533,7 +539,8 @@ public class ConfigSourcesController extends BaseRestController {
}
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
// 验证Md5
String md5 = DigestUtils.md5Hex(file.getBytes());
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值不一致");
@@ -544,7 +551,8 @@ public class ConfigSourcesController extends BaseRestController {
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[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);
@@ -558,17 +566,16 @@ 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);
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);
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
file, null);
// JSONArray fileArray=new JSONArray();
if (file == null) {
thread.setExceptionInfo("请上传获取摘要的文件到file");
@@ -576,11 +583,12 @@ public class ConfigSourcesController extends BaseRestController {
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());
String md5 = DigestUtils.md5Hex(file.getInputStream());
System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
if (!md5.equals(fileDesc.getChecksum())) {
thread.setExceptionInfo("checksum与文件MD5值不一致");
@@ -591,7 +599,8 @@ public class ConfigSourcesController extends BaseRestController {
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[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);
@@ -623,6 +632,7 @@ public class ConfigSourcesController extends BaseRestController {
}
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,7 +40,7 @@ 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";
@@ -98,13 +97,14 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
redisDBIndex, zset.toUpperCase(), maatVersion);
}
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_RULE_TIMER")) {
} 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);
logger.info("向{}号redis数据库更新了MAAT_RULE_TIMER,内容是{},SCORES是{}",
redisDBIndex, maatKey, score);
}
} else if (maatXmlExpr.getKeyExpression().toUpperCase()
@@ -112,10 +112,11 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
Long nowTime = new Date().getTime();
nowTime = nowTime / 1000l;
Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒
redisTemplate.boundZSetOps("MAAT_VERSION_TIMER").add(maatVersion + "", score);
redisTemplate.boundZSetOps("MAAT_VERSION_TIMER").add(maatVersion + "",
score);
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}", redisDBIndex,
maatVersion, score);
logger.info("向{}号redis数据库更新了MAAT_VERSION_TIMER,内容是{},SCORES是{}",
redisDBIndex, maatVersion, score);
}
}
List<MaatXmlSeq> seqList = maatXmlConfig.getSequenceList();
@@ -131,6 +132,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
}
}
} else {
throw new RuntimeException("无法从maat.xml中获取业务类型" + service + "对应的规则,请检查业务类型是否正确");
}
}
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
@@ -138,11 +141,18 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
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);

View File

@@ -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
直接写的代表是固定值,直接拼接即可,
每个属性间用分号分隔,空格用&amp;nbsp表示]]>
</xs:documentation>

View File

@@ -273,7 +273,7 @@
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="104857600"></property>
<property name="maxUploadSize" value="10485760000"></property>
<!--<property name="maxInMemorySize" value="1000"></property> -->
<property name="uploadTempDir" value="/upload"></property>
</bean>

View File

@@ -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,8 +61,7 @@ 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);