1:添加项目启动时从redis中加载配置id关系到idRelationMap
2:下发配置时将id关系添加到idRelationMap中 3:添加配置取消功能,及从idRelationMap中删除id关系
This commit is contained in:
@@ -52,7 +52,6 @@ public class MaatRelation implements Serializable {
|
||||
public static void removKey(MaatRelation maatRelation, long compileId) {
|
||||
if (maatRelation.getCompileAndGroupMap().containsKey(compileId)) {
|
||||
Set<Long> list = maatRelation.getCompileAndGroupMap().get(compileId);
|
||||
|
||||
if (list != null && list.size() > 0) {
|
||||
for (Long groupId : list) {
|
||||
// }
|
||||
|
||||
@@ -10,7 +10,6 @@ import javax.servlet.ServletContextEvent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
|
||||
@@ -27,10 +26,6 @@ import com.nis.web.service.SpringContextHolder;
|
||||
*/
|
||||
public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
private static Logger logger = LoggerFactory.getLogger(CompileGroupRegionRela.class);
|
||||
|
||||
private static RedisTemplate<String, String> redisTemplate = null;
|
||||
private static JedisConnectionFactory connectionFactory = null;
|
||||
|
||||
/**
|
||||
* 存储redis所有库中,编译分组域等配置关系,key是redis库
|
||||
*/
|
||||
@@ -39,28 +34,25 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
try {
|
||||
redisTemplate = SpringContextHolder.getBean("redisTemplate");
|
||||
connectionFactory = SpringContextHolder.getBean("connectionFactory");
|
||||
for (int i = 0; i < 16; i++) {
|
||||
connectionFactory.setDatabase(i);
|
||||
redisTemplate.setConnectionFactory(connectionFactory);
|
||||
getAllId(i);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
RedisTemplate<String, String> redisTemplate = SpringContextHolder.getBean("redisTemplate" + i);
|
||||
getAllId(redisTemplate, i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void getAllId(int redisDBIndex) {
|
||||
private void getAllId(RedisTemplate<String, String> redisTemplate, int redisDBIndex) {
|
||||
Map<Long, Set<Long>> groupCompileIdMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Map<Long, Set<Long>> groupRegionIdMap = new ConcurrentHashMap<Long, Set<Long>>();
|
||||
Set<String> keySet = redisTemplate.keys("EFFECTIVE_RULE:*");
|
||||
if (keySet != null && keySet.size() > 0) {
|
||||
for (String keys : keySet) {
|
||||
if (!keys.toLowerCase().contains("config_compile")) {
|
||||
if (!keys.toLowerCase().contains("compile")) {
|
||||
try {
|
||||
String value = redisTemplate.opsForValue().get(keys).toString();
|
||||
if (keys.toLowerCase().contains("config_group")) {
|
||||
if (keys.toLowerCase().contains("group")) {
|
||||
String[] split = value.split("\t");
|
||||
String groupIdStr = split[0];
|
||||
String compileIdStr = split[1];
|
||||
@@ -160,6 +152,8 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
} else {
|
||||
logger.error("redis" + redisDBIndex + "号库中没有id对应关系(没有配置),请检查redisDBIndex是否正确");
|
||||
}
|
||||
syso(maatRelation);
|
||||
|
||||
}
|
||||
|
||||
private static void removKey(MaatRelation maatRelation, long compileId) {
|
||||
@@ -225,6 +219,7 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
addKey(maatRelation, compileAndGroupRelations);
|
||||
idRelationMap.put(redisDBIndex, maatRelation);
|
||||
}
|
||||
syso(maatRelation);
|
||||
|
||||
}
|
||||
|
||||
@@ -294,4 +289,33 @@ public class CompileGroupRegionRela extends ContextLoaderListener {
|
||||
public static void setIdRelationMap(Map<Integer, MaatRelation> idRelationMap) {
|
||||
CompileGroupRegionRela.idRelationMap = idRelationMap;
|
||||
}
|
||||
|
||||
private static void syso(MaatRelation maatRelation) {
|
||||
Map<Long, Set<Long>> getCompileAndGroupMap = maatRelation.getCompileAndGroupMap();
|
||||
for (Long compile : getCompileAndGroupMap.keySet()) {
|
||||
Set<Long> groupList = getCompileAndGroupMap.get(compile);
|
||||
for (Long group : groupList) {
|
||||
System.out.println("编译:" + compile + "组:" + group);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> getGroupAndCompileMap = maatRelation.getGroupAndCompileMap();
|
||||
for (Long group : getGroupAndCompileMap.keySet()) {
|
||||
Set<Long> compileList = getGroupAndCompileMap.get(group);
|
||||
for (Long compile : compileList) {
|
||||
System.out.println("组:" + group + "编译:" + compile);
|
||||
}
|
||||
}
|
||||
Map<Long, Set<Long>> getGroupAndRegionMap = maatRelation.getGroupAndRegionMap();
|
||||
for (Long group : getGroupAndRegionMap.keySet()) {
|
||||
Set<Long> regionList = getGroupAndRegionMap.get(group);
|
||||
for (Long region : regionList) {
|
||||
System.out.println("组:" + group + "域:" + region);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigSource;
|
||||
@@ -111,6 +112,47 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
return "false";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/delUnMaat", 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 delUnMaat(int redisDB, int service, long id) {
|
||||
try {
|
||||
Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
|
||||
ArrayList<Long> arrayList = new ArrayList<Long>();
|
||||
arrayList.add(id);
|
||||
map.put(service, arrayList);
|
||||
Map<Integer, Map<Integer, List<Long>>> idMap = new HashMap<Integer, Map<Integer, List<Long>>>();
|
||||
idMap.put(redisDB, map);
|
||||
configRedisService.delUnMaatConfig(idMap);
|
||||
// configRedisService.saveMaatConfig(listMap, service);
|
||||
// new ConfigRedisServiceimpl().GETMaatConfig(listMap);
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/delMaat", 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 delMaat(int redisDB, int service, long id) {
|
||||
try {
|
||||
Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
|
||||
ArrayList<Long> arrayList = new ArrayList<Long>();
|
||||
arrayList.add(id);
|
||||
map.put(service, arrayList);
|
||||
Map<Integer, Map<Integer, List<Long>>> idMap = new HashMap<Integer, Map<Integer, List<Long>>>();
|
||||
idMap.put(redisDB, map);
|
||||
|
||||
configRedisService.delMaatConfig(idMap);
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/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)
|
||||
@@ -264,15 +306,9 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
|
||||
String msg = "";
|
||||
ConfigCompile compile = configSource.getConfigCompileList().get(0);
|
||||
if (StringUtil.isEmpty(compile.getGroupRelationList()) && StringUtil.isEmpty(compile.getIpRegionList())
|
||||
&& StringUtil.isEmpty(compile.getStrRegionList())
|
||||
&& StringUtil.isEmpty(compile.getNumRegionList())) {
|
||||
msg = configSourcesService.updateByJDBCThread3(thread, start, configSource.getConfigCompileList(),
|
||||
//zdx 20180528改为调用rkg接口取消配置
|
||||
msg = configSourcesService.cancleConfigSources(thread, start, configSource.getConfigCompileList(),
|
||||
configSource.getOpTime(), sb);
|
||||
} else {
|
||||
msg = configSourcesService.updateByJDBCThread12(thread, start, configSource.getConfigCompileList(),
|
||||
configSource.getOpTime(), sb);
|
||||
}
|
||||
|
||||
if (msg.equals("error")) {
|
||||
String errorCode = "";
|
||||
@@ -337,11 +373,11 @@ 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);
|
||||
@@ -369,33 +405,33 @@ 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +495,6 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation(value = "回调配置存储", httpMethod = "POST", response = Map.class, notes = "回调配置存储服务")
|
||||
// @ApiParam(value = "回调配置数据源", name = "JSONObject", requirerue)
|
||||
public Map createCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
||||
@@ -468,12 +503,27 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
null);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
configSourcesService.savaCommonSources(thread, start, jsonString, sb);
|
||||
configSourcesService.saveCommonSources(thread, start, jsonString, sb);
|
||||
|
||||
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置数据插入成功",
|
||||
Constants.IS_DEBUG ? jsonString : null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT, produces=org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
|
||||
@ApiOperation(value = "回调配置状态修改", httpMethod = "PUT", response = Map.class, notes = "回调配置状态修改服务")
|
||||
public Map updateCommonConfigSource(@RequestBody String jsonString , HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
ConfigSourcesService.setMsgList(new ArrayList<Exception>());// 清除上次记录的日志信息
|
||||
long start = System.currentTimeMillis();
|
||||
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,null);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
configSourcesService.saveCommonSources(thread, start, jsonString, sb);
|
||||
|
||||
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
|
||||
"配置数据插入成功" , Constants.IS_DEBUG ? jsonString : null);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/cfg/v1/fileUploadSources", method = RequestMethod.POST)
|
||||
@ApiOperation(value = "样例文件上传服务", httpMethod = "POST", response = Map.class, notes = "样例文件上传服务")
|
||||
@ApiParam(value = "样例文件上传服务", name = "MultipartFile", required = true)
|
||||
@@ -481,12 +531,16 @@ 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参数",
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
|
||||
}
|
||||
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
|
||||
//验证Md5
|
||||
String md5 = DigestUtils.md5Hex(file.getBytes());
|
||||
@@ -500,11 +554,11 @@ 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);
|
||||
logger.info("-----------------调用接口上传文件---------------");
|
||||
filePath = FileManager.upload(fdsfile, null);
|
||||
}else{
|
||||
thread.setExceptionInfo("请求头信息中缺少checksum参数");
|
||||
@@ -517,9 +571,76 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
}
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
|
||||
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){
|
||||
long start = System.currentTimeMillis();
|
||||
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);
|
||||
try {
|
||||
if (!StringUtil.isEmpty(fileDesc.getChecksum())) {
|
||||
//验证Md5
|
||||
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);
|
||||
logger.info("-----------------调用接口上传文件---------------");
|
||||
String filePath = FileManager.upload(fdsfile, null);
|
||||
resultObject.put("path", filePath.substring(filePath.indexOf("group")));
|
||||
}else{
|
||||
thread.setExceptionInfo("请求头信息中缺少checksum参数");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求头信息中缺少checksum参数",
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
|
||||
CommonsMultipartFile filetemp = (CommonsMultipartFile) file;
|
||||
String tempFilePath = filetemp.getStorageDescription().toString();
|
||||
tempFilePath = tempFilePath.substring(tempFilePath.indexOf("[")+1, tempFilePath.indexOf("]"));
|
||||
|
||||
String digestStr = configSourcesService.getDigestGen(request.getRealPath("/"),tempFilePath);
|
||||
resultObject.put("digest", digestStr);
|
||||
resultObject.put("rawLen", file.getSize());
|
||||
}catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.error("文件上传过程中出现异常");
|
||||
thread.setExceptionInfo("文件上传过程中出现异常");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, "文件上传过程中出现异常",
|
||||
RestBusinessCode.unknow_error.getValue());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.error("摘要获取过程中出现异常");
|
||||
thread.setExceptionInfo("摘要获取过程中出现异常");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, "摘要获取过程中出现异常",
|
||||
RestBusinessCode.unknow_error.getValue());
|
||||
}
|
||||
return serviceResponse(thread,System.currentTimeMillis()-start,request, response, "摘要获取成功",resultObject);
|
||||
}
|
||||
private boolean isBlank(Date datetime) {
|
||||
if (null != datetime) {
|
||||
return true;
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.axis2.databinding.types.soapencoding.Array;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -19,6 +18,8 @@ import org.springframework.util.StringUtils;
|
||||
import com.nis.domain.MaatXmlConfig;
|
||||
import com.nis.domain.MaatXmlExpr;
|
||||
import com.nis.domain.MaatXmlSeq;
|
||||
import com.nis.domain.restful.CompileAndGroupRelations;
|
||||
import com.nis.domain.restful.GroupAndRegionRelations;
|
||||
import com.nis.domain.restful.MaatConfig;
|
||||
import com.nis.domain.restful.MaatRelation;
|
||||
import com.nis.listener.CompileGroupRegionRela;
|
||||
@@ -96,6 +97,8 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
}
|
||||
maatKey = keyBF.toString();
|
||||
System.out.println(keyBF.toString());
|
||||
System.out.println(valBF.toString());
|
||||
redisTemplate.opsForValue().set(keyBF.toString().toUpperCase(),
|
||||
valBF.toString());
|
||||
break;
|
||||
@@ -142,6 +145,53 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
|
||||
@Override
|
||||
public void addMaatRelation(Map<Integer, List<MaatConfig>> configMap) {
|
||||
if (configMap != null && configMap.size() > 0) {
|
||||
for (Integer redisDBIndex : configMap.keySet()) {
|
||||
if (redisDBIndex >= 0 && redisDBIndex <= 15) {
|
||||
// MaatRelation maatRelation =
|
||||
// CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex);
|
||||
List<MaatConfig> maatConfigList = configMap.get(redisDBIndex);
|
||||
if (maatConfigList != null && maatConfigList.size() > 0) {
|
||||
for (MaatConfig maatConfig : maatConfigList) {
|
||||
Map<String, String> compileMap = maatConfig.getCompileMap();
|
||||
String cfgIdStr = compileMap.get("cfg_id");
|
||||
CompileAndGroupRelations compileAndGroupRelations = new CompileAndGroupRelations();
|
||||
compileAndGroupRelations.setCompileId(Long.valueOf(cfgIdStr));
|
||||
compileAndGroupRelations.setGroupIdList(new ArrayList<GroupAndRegionRelations>());
|
||||
|
||||
addGroupAndRegionRelations(maatConfig.getIpRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getNumRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getStrRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getStrStrRegionMapList(), compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getFileDigestRegionMapList(),
|
||||
compileAndGroupRelations);
|
||||
addGroupAndRegionRelations(maatConfig.getFileLikeRegionMapList(), compileAndGroupRelations);
|
||||
|
||||
CompileGroupRegionRela.addIdRelation(redisDBIndex, compileAndGroupRelations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addGroupAndRegionRelations(List<Map<String, String>> regionMapList,
|
||||
CompileAndGroupRelations compileAndGroupRelations) {
|
||||
if (regionMapList != null && regionMapList.size() > 0 && compileAndGroupRelations != null) {
|
||||
for (Map<String, String> map : regionMapList) {
|
||||
String regionIdStr = map.get("region_id");
|
||||
String groupIdStr = map.get("group_id");
|
||||
GroupAndRegionRelations groupAndRegionRelations = new GroupAndRegionRelations();
|
||||
groupAndRegionRelations.setGroupId(Long.valueOf(groupIdStr));
|
||||
groupAndRegionRelations.setRegionId(Long.valueOf(regionIdStr));
|
||||
compileAndGroupRelations.getGroupIdList().add(groupAndRegionRelations);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addMaatRelationOld(Map<Integer, List<MaatConfig>> configMap) {
|
||||
if (configMap != null && configMap.size() > 0) {
|
||||
for (Integer redisDBIndex : configMap.keySet()) {
|
||||
if (redisDBIndex >= 0 && redisDBIndex <= 15) {
|
||||
@@ -274,7 +324,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
redisTemplate.boundValueOps("MAAT_VERSION").increment(1l);
|
||||
}
|
||||
}
|
||||
addMaatRelation(configMap);
|
||||
// addMaatRelation(configMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,6 +461,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delUnMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap) {
|
||||
if (idMap != null && idMap.size() > 0) {
|
||||
for (Integer redisDBIndex : idMap.keySet()) {
|
||||
@@ -506,6 +557,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delMaatConfig(Map<Integer, Map<Integer, List<Long>>> idMap) {
|
||||
if (idMap != null && idMap.size() > 0) {
|
||||
for (Integer redisDBIndex : idMap.keySet()) {
|
||||
@@ -572,7 +624,7 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
int service, RedisTemplate<String, String> redisTemplate) {
|
||||
if (maatXmlConfig != null && idList != null && idList.size() > 0) {
|
||||
List<MaatXmlExpr> expressionList = maatXmlConfig.getExpressionList();
|
||||
String maatKey = "";
|
||||
String maatKey = null;
|
||||
for (Long id : idList) {
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (type == maatXmlExpr.getType().intValue()) {
|
||||
@@ -592,19 +644,25 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
keyBF.append(keyStr.trim());
|
||||
}
|
||||
}
|
||||
String oldKey = maatKey.toUpperCase();
|
||||
String oldKey = keyBF.toString().toUpperCase();
|
||||
maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE");
|
||||
redisTemplate.rename(maatKey.toUpperCase(), maatKey);
|
||||
redisTemplate.rename(oldKey, maatKey.toUpperCase());
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (MaatXmlExpr maatXmlExpr : expressionList) {
|
||||
if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) {
|
||||
if (maatKey != null) {
|
||||
String zset = maatKey.replace("OBSOLETE_RULE:", "DEL,");
|
||||
redisTemplate.boundZSetOps("MAAT_UPDATE_STATUS").add(zset, 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);
|
||||
}
|
||||
} else if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_VERSION_TIMER")) {
|
||||
Long nowTime = new Date().getTime();
|
||||
nowTime = nowTime / 1000l;
|
||||
@@ -618,21 +676,45 @@ public class ConfigRedisServiceimpl implements ConfigRedisService {
|
||||
|
||||
@Override
|
||||
public void delMaatRelation(Map<Integer, Map<Integer, List<Long>>> idMap) {
|
||||
if (idMap != null && idMap.size() > 0) {
|
||||
for (Integer redisDBIndex : idMap.keySet()) {
|
||||
if (redisDBIndex >= 0 && redisDBIndex <= 15) {
|
||||
// MaatRelation maatRelation =
|
||||
// CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex);
|
||||
Map<Integer, List<Long>> map = idMap.get(redisDBIndex);
|
||||
if (map != null && map.size() > 0) {
|
||||
for (Integer service : map.keySet()) {
|
||||
List<Long> idList = map.get(service);
|
||||
if (idList != null && idList.size() > 0) {
|
||||
for (Long compileId : idList) {
|
||||
CompileGroupRegionRela.delIdRelation(redisDBIndex, compileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delMaatRelationOld(Map<Integer, Map<Integer, List<Long>>> idMap) {
|
||||
if (idMap != null && idMap.size() > 0) {
|
||||
for (Integer redisDBIndex : idMap.keySet()) {
|
||||
if (redisDBIndex >= 0 && redisDBIndex <= 15) {
|
||||
MaatRelation maatRelation = CompileGroupRegionRela.getIdRelationMap().get(redisDBIndex);
|
||||
// maatRelation
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Map<Integer, List<Long>> map = idMap.get(redisDBIndex);
|
||||
if (map != null && map.size() > 0) {
|
||||
for (Integer service : map.keySet()) {
|
||||
List<Long> idList = map.get(service);
|
||||
if (idList != null && idList.size() > 0) {
|
||||
for (Long compileId : idList) {
|
||||
// CompileGroupRegionRela.removKey(maatRelation, compileId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,8 +50,10 @@ import com.nis.util.BasicProvingUtil;
|
||||
import com.nis.util.CamelUnderlineUtil;
|
||||
import com.nis.util.CompileVal;
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.OracleErrorCodeUtil;
|
||||
import com.nis.util.ReadCommSourceXmlUtil;
|
||||
import com.nis.util.ServiceAndRDBIndexReal;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.dao.ConfigCompileDao;
|
||||
@@ -108,32 +110,32 @@ public class ConfigSourcesService extends BaseService {
|
||||
public static Map<Integer, Map<String, String>> getTableRelation() {
|
||||
Map<Integer, Map<String, String>> tableMap = new HashMap<Integer, Map<String, String>>();
|
||||
Map<String, String> typeMap = new HashMap<String, String>();
|
||||
typeMap.put("AV_CONT_IP_PORT", "ip");
|
||||
typeMap.put("MM_AV_IP", "ip");
|
||||
tableMap.put(80, typeMap);
|
||||
tableMap.put(144, typeMap);
|
||||
|
||||
typeMap = new HashMap<String, String>();
|
||||
typeMap.put("AV_CONT_URL", "str");
|
||||
typeMap.put("MM_AV_URL", "str");
|
||||
tableMap.put(81, typeMap);
|
||||
tableMap.put(145, typeMap);
|
||||
|
||||
typeMap = new HashMap<String, String>();
|
||||
typeMap.put("AV_PIC_IP_PORT", "ip");
|
||||
typeMap.put("MM_PIC_IP", "ip");
|
||||
tableMap.put(82, typeMap);
|
||||
tableMap.put(146, typeMap);
|
||||
|
||||
typeMap = new HashMap<String, String>();
|
||||
typeMap.put("AV_PIC_URL", "str");
|
||||
typeMap.put("MM_PIC_URL", "str");
|
||||
tableMap.put(83, typeMap);
|
||||
tableMap.put(147, typeMap);
|
||||
|
||||
typeMap = new HashMap<String, String>();
|
||||
typeMap.put("AV_VoIP_IP_PORT", "ip");
|
||||
typeMap.put("MM_VOIP_IP", "ip");
|
||||
tableMap.put(84, typeMap);
|
||||
tableMap.put(148, typeMap);
|
||||
|
||||
typeMap = new HashMap<String, String>();
|
||||
typeMap.put("AV_VoIP_ACCOUNT", "str");
|
||||
typeMap.put("MM_VOIP_ACCOUNT", "str");
|
||||
tableMap.put(85, typeMap);
|
||||
tableMap.put(149, typeMap);
|
||||
|
||||
@@ -223,6 +225,8 @@ public class ConfigSourcesService extends BaseService {
|
||||
typeMap.put("UNIVERSAL_IP", "ip");
|
||||
typeMap.put("FX_HTTP_REQ_HDR", "str");
|
||||
typeMap.put("FX_HTTP_URL", "str");
|
||||
|
||||
typeMap.put("WHITE_LIST_IP", "ip");
|
||||
tableMap.put(15, typeMap);
|
||||
|
||||
typeMap = new HashMap<String, String>();
|
||||
@@ -472,7 +476,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
}
|
||||
}
|
||||
config.setLastUpdate(new Date());
|
||||
// config.setLastUpdate(new Date());
|
||||
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
||||
batchSqlSession.getMapper(ConfigCompileDao.class).updateConfigCompile(config);
|
||||
}
|
||||
@@ -625,7 +629,6 @@ public class ConfigSourcesService extends BaseService {
|
||||
num++;
|
||||
configGroupRelation.setIsValid(0);
|
||||
configGroupRelation.setOpTime(opTime);
|
||||
configGroupRelation.setLastUpdate(new Date());
|
||||
if (Configurations.getStringProperty("isCommit", "false").equals("true")) {
|
||||
batchSqlSession.getMapper(ConfigGroupRelationDao.class)
|
||||
.updateConfigGroupRelation(configGroupRelation);
|
||||
@@ -1107,18 +1110,13 @@ public class ConfigSourcesService extends BaseService {
|
||||
*/
|
||||
public String saveMaatConfig(SaveRequestLogThread thread, long start, List<ConfigCompile> configCompileList,
|
||||
StringBuffer sb) {
|
||||
List<MaatConfig> maatConfigList = new ArrayList<MaatConfig>();
|
||||
List<Integer> serviceList = new ArrayList<Integer>();
|
||||
// List<MaatConfig> maatConfigList = new ArrayList<MaatConfig>();
|
||||
// List<Integer> serviceList = new ArrayList<Integer>();
|
||||
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
|
||||
for (ConfigCompile configCompile : configCompileList) {
|
||||
serviceList.add(Integer.valueOf(configCompile.getService().toString()));
|
||||
Integer service = Integer.valueOf(configCompile.getService().toString());
|
||||
MaatConfig maatConfig = new MaatConfig();
|
||||
List<ConfigGroupRelation> groupRelationList = new ArrayList<ConfigGroupRelation>();
|
||||
List<StrRegion> strRegionList = new ArrayList<StrRegion>();
|
||||
List<StrRegion> strStrongRegionList = new ArrayList<StrRegion>();
|
||||
List<IpRegion> ipRegionList =new ArrayList<IpRegion>();
|
||||
List<NumRegion> numRegionList = new ArrayList<NumRegion>();
|
||||
List<DigestRegion> digestRegionList = new ArrayList<DigestRegion>();
|
||||
String msg = CompileVal.compileIsOk(configCompile, false, sb);
|
||||
if (msg != CompileJudgeCode.CompileIsOk.getErrorReason()) {
|
||||
logger1.error(msg);
|
||||
@@ -1128,9 +1126,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
|
||||
|
||||
if (null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0) {
|
||||
groupRelationList.addAll(configCompile.getGroupRelationList());
|
||||
} else {
|
||||
if (!(null != configCompile.getGroupRelationList() && configCompile.getGroupRelationList().size() > 0)) {
|
||||
logger1.error("配置分组数量不能为空" + sb.toString());
|
||||
thread.setExceptionInfo("配置分组数量不能为空" + sb.toString());
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, "配置分组数量不能为空" + sb.toString(),
|
||||
@@ -1138,7 +1134,6 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
if (null != configCompile.getStrRegionList() && configCompile.getStrRegionList().size() > 0) {
|
||||
for (StrRegion strRegion : configCompile.getStrRegionList()) {
|
||||
if (!isStrStrongRegion(strRegion.getTableName())) {
|
||||
if (strRegion.getRegionId() == null) {
|
||||
String errorMsg = "字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString();
|
||||
logger1.error(errorMsg);
|
||||
@@ -1146,26 +1141,11 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
strRegionList.add(strRegion);
|
||||
} else {
|
||||
if (strRegion.getRegionId() == null) {
|
||||
String errorMsg = "增强字符类域配置id不能为空 ,表名---" + strRegion.getTableName() + "" + sb.toString();
|
||||
logger1.error(errorMsg);
|
||||
thread.setExceptionInfo(errorMsg);
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
strStrongRegionList.add(strRegion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (null != configCompile.getIpRegionList() && configCompile.getIpRegionList().size() > 0) {
|
||||
for (IpRegion ipRegion : configCompile.getIpRegionList()) {
|
||||
if (!ipRegion.getTableName().toUpperCase().equals("DJ_IP_PORT")) {
|
||||
ipRegion.setProtocol(0);
|
||||
}
|
||||
|
||||
if (ipRegion.getRegionId() == null) {
|
||||
String errorMsg = "ip类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString();
|
||||
logger1.error(errorMsg);
|
||||
@@ -1173,8 +1153,6 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
|
||||
ipRegionList.add(ipRegion);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1187,7 +1165,6 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
numRegionList.add(numRegion);
|
||||
}
|
||||
}
|
||||
if (null != configCompile.getDigestRegionList() && configCompile.getDigestRegionList().size() > 0) {
|
||||
@@ -1199,46 +1176,56 @@ public class ConfigSourcesService extends BaseService {
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
|
||||
digestRegionList.add(digestRegion);
|
||||
}
|
||||
}
|
||||
|
||||
maatConfig.setService(Integer.valueOf(configCompile.getService().toString()));
|
||||
if (null != configCompile.getIpClientRangeList() && configCompile.getIpClientRangeList().size() > 0) {
|
||||
for (IpRegion ipRegion : configCompile.getIpClientRangeList()) {
|
||||
if (ipRegion.getRegionId() == null) {
|
||||
String errorMsg = "生效范围IP域类域配置id不能为空 ,表名---" + ipRegion.getTableName() + "" + sb.toString();
|
||||
logger1.error(errorMsg);
|
||||
thread.setExceptionInfo(errorMsg);
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maatConfig.setService(service);
|
||||
//编译
|
||||
maatConfig.setCompileMap(convertObjectToMap(configCompile, ConfigCompile.class));
|
||||
//分组
|
||||
List<Map<String, String>> dstMaplList = null;
|
||||
if (!StringUtil.isEmpty(groupRelationList)) {
|
||||
if (!StringUtil.isEmpty(configCompile.getGroupRelationList())) {
|
||||
dstMaplList = new ArrayList<Map<String,String>>();
|
||||
for (ConfigGroupRelation group : groupRelationList) {
|
||||
for (ConfigGroupRelation group : configCompile.getGroupRelationList()) {
|
||||
dstMaplList.add(convertObjectToMap(group, ConfigGroupRelation.class));
|
||||
}
|
||||
}
|
||||
maatConfig.setGroupMapList(dstMaplList);
|
||||
//字符串域
|
||||
dstMaplList = null;
|
||||
if (!StringUtil.isEmpty(strRegionList)) {
|
||||
if (!StringUtil.isEmpty(configCompile.getStrRegionList())) {
|
||||
dstMaplList = new ArrayList<Map<String,String>>();
|
||||
for (StrRegion region : strRegionList) {
|
||||
for (StrRegion region : configCompile.getStrRegionList()) {
|
||||
dstMaplList.add(convertObjectToMap(region, StrRegion.class));
|
||||
}
|
||||
}
|
||||
maatConfig.setStrRegionMapList(dstMaplList);
|
||||
//增强字符串域
|
||||
dstMaplList = null;
|
||||
if (!StringUtil.isEmpty(strStrongRegionList)) {
|
||||
dstMaplList = new ArrayList<Map<String,String>>();
|
||||
for (StrRegion region : strStrongRegionList) {
|
||||
dstMaplList.add(convertObjectToMap(region, StrRegion.class));
|
||||
}
|
||||
}
|
||||
maatConfig.setStrStrRegionMapList((dstMaplList));
|
||||
// //增强字符串域
|
||||
// dstMaplList = null;
|
||||
// if (!StringUtil.isEmpty(strStrongRegionList)) {
|
||||
// dstMaplList = new ArrayList<Map<String,String>>();
|
||||
// for (StrRegion region : strStrongRegionList) {
|
||||
// dstMaplList.add(convertObjectToMap(region, StrRegion.class));
|
||||
// }
|
||||
// }
|
||||
// maatConfig.setStrStrRegionMapList((dstMaplList));
|
||||
//数值域
|
||||
dstMaplList = null;
|
||||
if (!StringUtil.isEmpty(numRegionList)) {
|
||||
if (!StringUtil.isEmpty(configCompile.getNumRegionList())) {
|
||||
dstMaplList = new ArrayList<Map<String,String>>();
|
||||
for (NumRegion region : numRegionList) {
|
||||
for (NumRegion region : configCompile.getNumRegionList()) {
|
||||
dstMaplList.add(convertObjectToMap(region, NumRegion.class));
|
||||
}
|
||||
}
|
||||
@@ -1246,9 +1233,9 @@ public class ConfigSourcesService extends BaseService {
|
||||
|
||||
//Ip域
|
||||
dstMaplList = null;
|
||||
if (!StringUtil.isEmpty(ipRegionList)) {
|
||||
if (!StringUtil.isEmpty(configCompile.getIpRegionList())) {
|
||||
dstMaplList = new ArrayList<Map<String,String>>();
|
||||
for (IpRegion region : ipRegionList) {
|
||||
for (IpRegion region : configCompile.getIpRegionList()) {
|
||||
dstMaplList.add(convertObjectToMap(region, IpRegion.class));
|
||||
}
|
||||
}
|
||||
@@ -1256,29 +1243,57 @@ public class ConfigSourcesService extends BaseService {
|
||||
|
||||
//摘要类域
|
||||
dstMaplList = null;
|
||||
if (!StringUtil.isEmpty(digestRegionList)) {
|
||||
if (!StringUtil.isEmpty(configCompile.getDigestRegionList())) {
|
||||
dstMaplList = new ArrayList<Map<String,String>>();
|
||||
for (DigestRegion region : digestRegionList) {
|
||||
for (DigestRegion region : configCompile.getDigestRegionList()) {
|
||||
dstMaplList.add(convertObjectToMap(region, DigestRegion.class));
|
||||
}
|
||||
}
|
||||
|
||||
maatConfig.setFileDigestRegionMapList(dstMaplList);
|
||||
dstMaplList = null;
|
||||
|
||||
//文本相似性域
|
||||
maatConfig.setFileLikeRegionMapList(dstMaplList);
|
||||
maatConfigList.add(maatConfig);
|
||||
// dstMaplList = null;
|
||||
// maatConfig.setFileLikeRegionMapList(dstMaplList);
|
||||
|
||||
|
||||
//生效范围IP域
|
||||
dstMaplList = null;
|
||||
if (!StringUtil.isEmpty(configCompile.getIpClientRangeList())) {
|
||||
dstMaplList = new ArrayList<Map<String,String>>();
|
||||
for (IpRegion region : configCompile.getIpClientRangeList()) {
|
||||
dstMaplList.add(convertObjectToMap(region, IpRegion.class));
|
||||
}
|
||||
}
|
||||
maatConfig.setIpClientRangeMapList(dstMaplList);
|
||||
|
||||
if (maatMap.containsKey(service)) {
|
||||
maatMap.get(service).add(maatConfig);
|
||||
}else{
|
||||
List<MaatConfig> maatCfgList = new ArrayList<MaatConfig>();
|
||||
maatCfgList.add(maatConfig);
|
||||
maatMap.put(service, maatCfgList);
|
||||
|
||||
}
|
||||
if (!StringUtil.isEmpty(serviceList)&&serviceList.size()!=1) {
|
||||
String errorMsg = "只能添加单一service配置信息列表";
|
||||
logger1.error(errorMsg);
|
||||
thread.setExceptionInfo(errorMsg);
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorMsg,
|
||||
RestBusinessCode.op_action_error.getValue());
|
||||
}
|
||||
|
||||
//调用接口入redis
|
||||
configRedisService.saveMaatConfig(maatConfigList, serviceList.get(0));
|
||||
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
Iterator serviceIterator = maatMap.keySet().iterator();
|
||||
while (serviceIterator.hasNext()) {
|
||||
Integer service =Integer.valueOf(serviceIterator.next().toString());
|
||||
List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
||||
for (Integer dbIndex : dbIndexList) {
|
||||
if (configMap.containsKey(dbIndex)) {
|
||||
configMap.get(dbIndex).addAll(maatMap.get(service));
|
||||
}else{
|
||||
configMap.put(dbIndex, maatMap.get(service));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configRedisService.saveMaatConfig(configMap);
|
||||
logger1.info("---------------调用maat配置新增接口---------------------");
|
||||
|
||||
return "ok";
|
||||
}
|
||||
@@ -1308,6 +1323,32 @@ public class ConfigSourcesService extends BaseService {
|
||||
}
|
||||
return dstMap;
|
||||
}
|
||||
|
||||
public String cancleConfigSources(SaveRequestLogThread thread, long start, List<ConfigCompile> compileList,
|
||||
Date opTime, StringBuffer sb) {
|
||||
List<ConfigCompile> compileAllList = new ArrayList<ConfigCompile>();
|
||||
if (null != compileList && compileList.size() > 0) {
|
||||
for (ConfigCompile config : compileList) {
|
||||
String msg = checkCompileOptForUpdate(config);
|
||||
if (config.getOpTime()==null) {
|
||||
config.setOpTime(opTime);
|
||||
}
|
||||
if (!msg.equals("ok")) {
|
||||
thread.setExceptionInfo(msg + sb.toString());
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, msg + sb.toString(),
|
||||
RestBusinessCode.config_integrity_error.getValue());
|
||||
}
|
||||
|
||||
compileAllList.add(config);
|
||||
}
|
||||
|
||||
} else {
|
||||
thread.setExceptionInfo("编译配置不能为空" + sb.toString());
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, "编译配置不能为空" + sb.toString(),
|
||||
RestBusinessCode.config_integrity_error.getValue());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public String saveByJDBCThread(SaveRequestLogThread thread, long start, List<ConfigCompile> configCompileList,
|
||||
StringBuffer sb) {
|
||||
List<ConfigGroupRelation> groupRelationList = new ArrayList<ConfigGroupRelation>();
|
||||
@@ -1750,7 +1791,6 @@ public class ConfigSourcesService extends BaseService {
|
||||
num++;
|
||||
configGroupRelation.setIsValid(0);
|
||||
|
||||
configGroupRelation.setLastUpdate(new Date());
|
||||
groupRelationAllList.add(configGroupRelation);
|
||||
}
|
||||
}
|
||||
@@ -2172,6 +2212,11 @@ public class ConfigSourcesService extends BaseService {
|
||||
if (StringUtil.isEmpty(config.getCompileId())) {
|
||||
return "compileId字段不能为空";
|
||||
}
|
||||
|
||||
if (StringUtil.isEmpty(config.getService())) {
|
||||
return "service字段不能为空";
|
||||
}
|
||||
|
||||
if (StringUtil.isEmpty(config.getIsValid())) {
|
||||
return "编译配置id为" + config.getCompileId()+"的IsValid字段不能为空";
|
||||
}
|
||||
@@ -2349,7 +2394,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
public String savaCommonSources(SaveRequestLogThread thread, long start,String jsonString,
|
||||
public String saveCommonSources(SaveRequestLogThread thread, long start,String jsonString,
|
||||
StringBuffer sb) {
|
||||
JsonArray jsonObjectList = new JsonParser().parse(jsonString).getAsJsonArray();
|
||||
Map<Integer,List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String,String>>>();
|
||||
@@ -2360,7 +2405,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
Map<String,String> dstMap = new HashMap<String, String>();
|
||||
List<CommonSourceFieldCfg> commonSourceFieldCfgList = ReadCommSourceXmlUtil.getCommonSourceCfgByService(srcMap.get("service").toString().trim());
|
||||
if (StringUtil.isEmpty(commonSourceFieldCfgList)) {
|
||||
logger.error("service请检查service配置是否正确");
|
||||
logger1.error("service请检查service配置是否正确");
|
||||
thread.setExceptionInfo("请检查service配置是否正确");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start,"请检查service配置是否正确",
|
||||
RestBusinessCode.wrong_range.getValue());
|
||||
@@ -2368,7 +2413,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) {
|
||||
//是否必填
|
||||
if(commonSourceFieldCfg.getIsRequired()&&!srcMap.containsKey(commonSourceFieldCfg.getSrcName())){
|
||||
logger.error(commonSourceFieldCfg.getSrcName()+"参数不能为空");
|
||||
logger1.error(commonSourceFieldCfg.getSrcName()+"参数不能为空");
|
||||
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不能为空");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能为空",
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
@@ -2381,7 +2426,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
switch (commonSourceFieldCfg.getFieldType()) {
|
||||
case "Number":
|
||||
if(!StringUtil.isNumeric(dstStr)){
|
||||
logger.error(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型");
|
||||
logger1.error(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型");
|
||||
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必需是数值型");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确",
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
@@ -2390,11 +2435,12 @@ public class ConfigSourcesService extends BaseService {
|
||||
case "Date":
|
||||
try {
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
System.out.println("--------------------TimeZone:"+sdf.getTimeZone());
|
||||
Date date = sdf.parse(dstStr);
|
||||
dstStr = date.getTime()+"000";
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型");
|
||||
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型");
|
||||
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确,必须是日期型");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,必须是日期型",
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
@@ -2402,7 +2448,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
break;
|
||||
case "Ip":
|
||||
if (!isIp(dstStr)) {
|
||||
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的IP地址");
|
||||
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的IP地址");
|
||||
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的IP地址");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,不是合法的IP地址",
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
@@ -2410,7 +2456,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
break;
|
||||
case "Port":
|
||||
if (!BasicProvingUtil.isPortOrPortMask(dstStr)) {
|
||||
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的Port");
|
||||
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的Port");
|
||||
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式不正确,不是合法的Port");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start,commonSourceFieldCfg.getSrcName()+"参数不能格式不正确,不是合法的Port",
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
@@ -2422,7 +2468,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
if(!StringUtil.isEmpty(commonSourceFieldCfg.getRange())){
|
||||
String [] range= commonSourceFieldCfg.getRange().split("-");
|
||||
if(!(Long.valueOf(range[0]).compareTo(Long.valueOf(dstStr))<=0&&Long.valueOf(range[1]).compareTo(Long.valueOf(dstStr))>=0)){
|
||||
logger.error(commonSourceFieldCfg.getSrcName()+"参数不在有效范围");
|
||||
logger1.error(commonSourceFieldCfg.getSrcName()+"参数不在有效范围");
|
||||
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数不在有效范围");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, commonSourceFieldCfg.getSrcName()+"参数不在有效范围",
|
||||
RestBusinessCode.wrong_range.getValue());
|
||||
@@ -2439,7 +2485,7 @@ public class ConfigSourcesService extends BaseService {
|
||||
if (valFlag) {
|
||||
dstMap.put(commonSourceFieldCfg.getDstName(),dstStr);
|
||||
}else{
|
||||
logger.error(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配");
|
||||
logger1.error(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配");
|
||||
thread.setExceptionInfo(commonSourceFieldCfg.getSrcName()+"参数格式与正则不匹配");
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, commonSourceFieldCfg.getSrcName()+"参数格式不正确或数据不在有效范围",
|
||||
RestBusinessCode.param_formate_error.getValue());
|
||||
@@ -2460,13 +2506,22 @@ public class ConfigSourcesService extends BaseService {
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
}
|
||||
Iterator iterator =dstMaps.keySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Integer key = Integer.valueOf(iterator.next().toString());
|
||||
configRedisService.saveUnMaatConfig(dstMaps.get(key),key);
|
||||
// configRedisService.saveConfigYSPDemoCompile(key,);
|
||||
logger1.info("------------------调用非maat配置新增接口-------------------");
|
||||
//按service分库
|
||||
Map<Integer, List<Map<String, String>>> configMap = new HashMap<Integer, List<Map<String, String>>>();
|
||||
Iterator serviceIterator = dstMaps.keySet().iterator();
|
||||
while (serviceIterator.hasNext()) {
|
||||
Integer service =Integer.valueOf(serviceIterator.next().toString());
|
||||
List<Integer> dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service);
|
||||
for (Integer dbIndex : dbIndexList) {
|
||||
if (configMap.containsKey(dbIndex)) {
|
||||
configMap.get(dbIndex).addAll(dstMaps.get(service));
|
||||
}else{
|
||||
configMap.put(dbIndex, dstMaps.get(service));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
configRedisService.saveUnMaatConfig(configMap);
|
||||
|
||||
return "ok";
|
||||
}
|
||||
@@ -2488,4 +2543,32 @@ public class ConfigSourcesService extends BaseService {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
public String getDigestGen(String realPath,String filePath)throws Exception{
|
||||
System.out.println("----------------getDigestGen");
|
||||
String content="";
|
||||
String digestGenToolPath=Constants.DIGEST_GEN_TOOL_PATH;
|
||||
String chmodCommond="chmod +x "+realPath+digestGenToolPath;//执行权限命令
|
||||
System.out.println("----------------chmodCommod:"+chmodCommond);
|
||||
String commondStr=realPath+digestGenToolPath+" -f "+filePath; //执行
|
||||
//执行摘要获取命令 digest -f /home/aa.txt
|
||||
System.out.println("------------commondStr:"+commondStr);
|
||||
Runtime.getRuntime().exec(chmodCommond);
|
||||
Process p=Runtime.getRuntime().exec(commondStr);
|
||||
byte[] b=new byte[1024];
|
||||
StringBuffer sb=new StringBuffer();
|
||||
while (p.getInputStream().read(b) != -1) {
|
||||
sb.append(new String(b, "UTF-8"));
|
||||
}
|
||||
content=sb.toString();
|
||||
if (!StringUtil.isBlank(content)) {
|
||||
content = StringUtil.stripAll(content);
|
||||
}
|
||||
System.out.println("-------------------->>"+content);
|
||||
String[] digestGenReslt=content.split(" ");
|
||||
if(digestGenReslt.length >=4 && !StringUtil.isEmpty(digestGenReslt[3])){
|
||||
return digestGenReslt[3];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -164,11 +164,11 @@
|
||||
|
||||
|
||||
<!-- 项目启动时加载编译id,组id,域id之间的关系 -->
|
||||
<!-- <listener> -->
|
||||
<!-- <listener-class> -->
|
||||
<!-- com.nis.listener.SystemConfigListener -->
|
||||
<!-- </listener-class> -->
|
||||
<!-- </listener> -->
|
||||
<listener>
|
||||
<listener-class>
|
||||
com.nis.listener.CompileGroupRegionRela
|
||||
</listener-class>
|
||||
</listener>
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user