合并dev 修改controller 冲突

This commit is contained in:
doufenghu
2018-11-26 15:22:20 +08:00
8 changed files with 323 additions and 165 deletions

View File

@@ -677,7 +677,10 @@ public enum RestBusinessCode {
/** /**
* 状态更新操作中更新内容Map不能为空 * 状态更新操作中更新内容Map不能为空
*/ */
ConfigInfoMapIsNull(5004005,"状态更新操作中更新内容Map不能为空"), ConfigInfoMapIsNull(5004006,"状态更新操作中更新内容Map不能为空"),
existBatchTask(5005001,"有其他任务正在执行批量导入,请稍后再试")
; ;

View File

@@ -211,12 +211,22 @@ public final class Constants {
*是否使用Minio *是否使用Minio
*/ */
public static final Boolean IS_USE_MINIO = Configurations.getBooleanProperty("isUseMinio", true); public static final Boolean IS_USE_MINIO = Configurations.getBooleanProperty("isUseMinio", true);
public static final int MAXTHREADNUM = Configurations.getIntProperty("maxThreadNum", 10);
public static final int EVERTHREADNUM = Configurations.getIntProperty("everThreadNum", 10000);
/** /**
* 保存请求内容时最大的资源列表size * 保存请求内容时最大的资源列表size
*/ */
public static final int MAX_LIST_SIZE = Configurations.getIntProperty("maxListSize", 10); public static final int MAX_LIST_SIZE = Configurations.getIntProperty("maxListSize", 10);
/**
* redis分布式锁超时时间,默认五分钟,3000秒
*/
public static final Long REDISLOCKTIME=Configurations.getLongProperty("redisLockTime", 3000);
/**
* 获取redis分布式锁失败后的尝试获取锁的次数,每次失败暂停一秒钟后再次尝试
*/
public static final Long REDISRETRYNUM=Configurations.getLongProperty("redisRetryNum", 5);
} }

View File

@@ -1,5 +1,6 @@
package com.nis.util; package com.nis.util;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -16,7 +17,8 @@ import com.nis.web.service.SpringContextHolder;
public class JedisUtils { public class JedisUtils {
private static Logger logger = LoggerFactory.getLogger(JedisUtils.class); private static Logger logger = LoggerFactory.getLogger(JedisUtils.class);
private static JedisPool jedisPool = SpringContextHolder.getBean(JedisPool.class); private static final JedisPool jedisPool = SpringContextHolder.getBean(JedisPool.class);
/** /**
* 获取缓存 * 获取缓存
* *
@@ -232,7 +234,7 @@ public class JedisUtils {
jedis.select(redisDb); jedis.select(redisDb);
} catch (JedisException e) { } catch (JedisException e) {
returnBrokenResource(jedis); returnBrokenResource(jedis);
logger.error("获取redis连接失败,异常信息:{}" ,ExceptionUtil.getExceptionMsg(e)); logger.error("获取redis连接失败,异常信息:{}", ExceptionUtil.getExceptionMsg(e));
throw new ServiceRuntimeException("获取redis连接失败,请联系管理员检查程序", throw new ServiceRuntimeException("获取redis连接失败,请联系管理员检查程序",
RestBusinessCode.CannotConnectionRedis.getValue()); RestBusinessCode.CannotConnectionRedis.getValue());
} }
@@ -298,4 +300,72 @@ public class JedisUtils {
return ObjectUtils.unserialize(bytes); return ObjectUtils.unserialize(bytes);
} }
// 设置成功返回的结果OK
private static final String LOCK_SUCCESS = "OK";
// NX -- Only set the key if it does not already exist. XX -- Only set the key
// if it already exist
private static final String SET_IF_NOT_EXIST = "NX";
// 失效单位秒(EX)还是毫秒(PX)
private static final String SET_WITH_EXPIRE_TIME = "EX";
private static final Long UNLOCK_SUCCESS = 1L;
/**
* 尝试获取分布式锁,如果没有key就set,有key就不操作
*
* @param requestId
* 请求标识(UUID.randomUUID().toString()),正常情况下是谁加的锁,谁去解锁不能a加的锁,b去解锁
* @return 是否获取成功
*/
public static Boolean lock(String requestId) {
String key = "redisDistributedLock";
String var1 = getResource(0).set(key, requestId, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME,
Constants.REDISLOCKTIME);
if (LOCK_SUCCESS.equals(var1)) {
return true;
}
return false;
}
/**
* 解锁操作
*
* @param value
* 客户端标识(requestId)
* @return
*/
public static Boolean unLock(String value) {
String key = "redisDistributedLock";
// 这个字符串是个lua脚本代表的意思是如果根据key拿到的value跟传入的value相同就执行del否则就返回0【保证安全性】
String luaScript = "if redis.call(\"get\",KEYS[1]) == ARGV[1] then return redis.call(\"del\",KEYS[1]) else return 0 end";
// 这个命令就是去执行lua脚本KEYS的集合就是第二个参数ARGV的集合就是第三参数【保证解锁的原子操作】
Object var2 = getResource(0).eval(luaScript, Collections.singletonList(key), Collections.singletonList(value));
if (UNLOCK_SUCCESS == var2) {
return true;
}
return false;
}
/**
* 重试机制
*
* @param value
* 客户端标识
* @return
*/
public static Boolean lockRetry(String value) {
Boolean flag = false;
try {
for (int i = 0; i < Constants.REDISRETRYNUM; i++) {
flag = lock(value);
if (flag) {
break;
}
Thread.sleep(1000);
}
} catch (Exception e) {
logger.error("尝试获取redis分布式锁失败,失败原因:{}", ExceptionUtil.getExceptionMsg(e));
}
return flag;
}
} }

View File

@@ -31,8 +31,10 @@ import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestConstants; import com.nis.restful.RestConstants;
import com.nis.restful.RestResult; import com.nis.restful.RestResult;
import com.nis.restful.RestServiceException; import com.nis.restful.RestServiceException;
import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Constants; import com.nis.util.Constants;
import com.nis.util.DateUtils; import com.nis.util.DateUtils;
import com.nis.util.JedisUtils;
import com.nis.web.service.AuditLogThread; import com.nis.web.service.AuditLogThread;
import com.nis.web.service.ServicesRequestLogService; import com.nis.web.service.ServicesRequestLogService;
import com.zdjizhi.utils.StringUtil; import com.zdjizhi.utils.StringUtil;
@@ -424,4 +426,35 @@ public class BaseRestController {
entity.setSearchFoundEndTime(map.get("endTime")); entity.setSearchFoundEndTime(map.get("endTime"));
} }
} }
/**
* 获取redis分布式锁的状态
*
* @param requestId
* @return
*/
protected boolean getLock(String requestId) {
boolean lock = false;
if (JedisUtils.lock(requestId)) {
lock = true;
} else {
if (JedisUtils.lockRetry(requestId)) {
lock = true;
} else {
throw new ServiceRuntimeException("有其他任务正在执行批量导入,请稍后再试.如一直提示该信息,请联系管理员检查系统运行状态!",
RestBusinessCode.ConfigSourceIsNull.getValue());
}
}
return lock;
}
/**
* 解除redis分布式锁
* @param requestId
*/
protected void deblocking (String requestId) {
JedisUtils.unLock(requestId);
}
} }

View File

@@ -5,6 +5,7 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@@ -63,28 +64,31 @@ public class ConfigSourcesController extends BaseRestController {
@Autowired @Autowired
ConfigRedisService configRedisService; ConfigRedisService configRedisService;
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST) @RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST)
@ApiOperation(value = "MAAT规则存储接口", httpMethod = "POST", response = Map.class, notes = "接收MAAT规则数据存储到流量处理平台配置线中") @ApiOperation(value = "MAAT规则存储接口", httpMethod = "POST", response = Map.class, notes = "接收MAAT规则数据存储到流量处理平台配置线中")
@ApiParam(value = "MAAT规则对象", name = "configSource", required = true) @ApiParam(value = "MAAT规则对象", name = "configSource", required = true)
public Map createMaatConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request, public Map createMaatConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
configSource); configSource);
// 分布式锁的标识,谁加锁,谁解锁,如果中间发生了异常则根据失效时间自动失效,默认五分钟失效
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String requestId = UUID.randomUUID().toString();
try { try {
if (null != configSource && null != configSource.getConfigCompileList() if (getLock(requestId)) {
&& configSource.getConfigCompileList().size() > 0) { if (null != configSource && null != configSource.getConfigCompileList()
checkOpAction(thread, System.currentTimeMillis() - start, configSource.getOpAction(), Constants.OPACTION_POST); && configSource.getConfigCompileList().size() > 0) {
// 验证配置编译数据 checkOpAction(thread, System.currentTimeMillis() - start, configSource.getOpAction(),
validateConfigSource(thread, start, configSource); Constants.OPACTION_POST);
configSourcesService.saveMaatConfig(thread, start, configSource.getConfigCompileList(), sb); // 验证配置编译数据
} else { validateConfigSource(thread, start, configSource);
throw new RestServiceException("Maat规则不能为空", configSourcesService.saveMaatConfig(thread, start, configSource.getConfigCompileList(), sb);
RestBusinessCode.ConfigSourceIsNull.getValue()); } else {
throw new RestServiceException("Maat规则不能为空", RestBusinessCode.ConfigSourceIsNull.getValue());
}
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
@@ -92,15 +96,17 @@ public class ConfigSourcesController extends BaseRestController {
logger.error("Maat 规则存储异常:" + e.getMessage()); logger.error("Maat 规则存储异常:" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"Maat 规则存储异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); "Maat 规则存储异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
}else if(e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"Maat 规则存储异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); "Maat 规则存储异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
}else{ } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"Maat 规则存储异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); "Maat 规则存储异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} }
} finally {
deblocking(requestId);
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
@@ -116,20 +122,23 @@ public class ConfigSourcesController extends BaseRestController {
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
configSource); configSource);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String requestId = UUID.randomUUID().toString();
try { try {
if (null == configSource.getOpTime()) { if (getLock(requestId)) {
configSource.setOpTime(new Date()); if (null == configSource.getOpTime()) {
} configSource.setOpTime(new Date());
if (null != configSource && null != configSource.getConfigCompileList() }
&& configSource.getConfigCompileList().size() > 0) { if (null != configSource && null != configSource.getConfigCompileList()
int opAction = configSource.getOpAction(); && configSource.getConfigCompileList().size() > 0) {
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2); int opAction = configSource.getOpAction();
configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(), checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
configSource.getOpTime(), sb); configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(),
configSource.getOpTime(), sb);
} else {
throw new RestServiceException("Maat规则不能为空" + sb.toString(), } else {
RestBusinessCode.ConfigSourceIsNull.getValue()); throw new RestServiceException("Maat规则不能为空" + sb.toString(),
RestBusinessCode.ConfigSourceIsNull.getValue());
}
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
@@ -137,16 +146,18 @@ public class ConfigSourcesController extends BaseRestController {
logger.error("MAAT规则状态更新时出现异常:" + e.getMessage()); logger.error("MAAT规则状态更新时出现异常:" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"MAAT规则状态更新时出现异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); "MAAT规则状态更新时出现异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
}else if(e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"MAAT规则状态更新时出现异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); "MAAT规则状态更新时出现异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
}else{ } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"MAAT规则状态更新时出现异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); "MAAT规则状态更新时出现异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} }
} finally {
deblocking(requestId);
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"Maat规则状态更新成功" + sb.toString(), Constants.IS_DEBUG ? configSource : null); "Maat规则状态更新成功" + sb.toString(), Constants.IS_DEBUG ? configSource : null);
} }
@@ -177,36 +188,41 @@ public class ConfigSourcesController extends BaseRestController {
} }
} }
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "回调(通用)规则存储接口", httpMethod = "POST", response = Map.class, notes = "接收回调规则数据,格式为结构化行列式JSON,存储到流量处理平台配置线中") @ApiOperation(value = "回调(通用)规则存储接口", httpMethod = "POST", response = Map.class, notes = "接收回调规则数据,格式为结构化行列式JSON,存储到流量处理平台配置线中")
public Map createCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request, public Map createCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, null);
null);
String requestId = UUID.randomUUID().toString();
try { try {
configSourcesService.saveCommonSources(thread, start, jsonString); if (getLock(requestId)) {
configSourcesService.saveCommonSources(thread, start, jsonString);
}
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
thread.setExceptionInfo("回调规则存储异常:" + e.getMessage()); thread.setExceptionInfo("回调规则存储异常:" + e.getMessage());
logger.error("回调规则存储异常:" + e.getMessage()); logger.error("回调规则存储异常:" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start, "回调规则存储异常:" + e.getMessage(),
"回调规则存储异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); ((RestServiceException) e).getErrorCode());
}else if (e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start, "回调规则存储异常:" + e.getMessage(),
"回调规则存储异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); ((ServiceRuntimeException) e).getErrorCode());
}else { } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"回调规则存储异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); "回调规则存储异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} }
} finally {
deblocking(requestId);
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则下发成功", return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则下发成功",
Constants.IS_DEBUG ? jsonString : null); Constants.IS_DEBUG ? jsonString : null);
} }
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PATCH, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PATCH, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "回调(通用)规则内容更新接口", httpMethod = "PATCH", response = Map.class, notes = "接收回调规则数据,格式为结构化行列式JSON,存储到流量处理平台配置线中") @ApiOperation(value = "回调(通用)规则内容更新接口", httpMethod = "PATCH", response = Map.class, notes = "接收回调规则数据,格式为结构化行列式JSON,存储到流量处理平台配置线中")
public Map patchCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request, public Map patchCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
@@ -214,27 +230,33 @@ public class ConfigSourcesController extends BaseRestController {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PATCH, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PATCH, request,
null); null);
String requestId = UUID.randomUUID().toString();
try { try {
configSourcesService.saveCommonSources(thread, start, jsonString); if (getLock(requestId)) {
configSourcesService.saveCommonSources(thread, start, jsonString);
}
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
thread.setExceptionInfo("回调规则内容更新异常:" + e.getMessage()); thread.setExceptionInfo("回调规则内容更新异常:" + e.getMessage());
logger.error("回调规则内容更新异常:" + e.getMessage()); logger.error("回调规则内容更新异常:" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"回调规则内容更新异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); "回调规则内容更新异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
}else if (e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"回调规则内容更新异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); "回调规则内容更新异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
}else { } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"回调规则内容更新异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); "回调规则内容更新异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} }
} finally {
deblocking(requestId);
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则内容更新成功", return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则内容更新成功",
Constants.IS_DEBUG ? jsonString : null); Constants.IS_DEBUG ? jsonString : null);
} }
@RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT) @RequestMapping(value = "/cfg/v1/commonSources", method = RequestMethod.PUT)
@ApiOperation(value = "回调(通用)规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收回调规则,对其状态置为失效") @ApiOperation(value = "回调(通用)规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收回调规则,对其状态置为失效")
public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request, public Map updateCommonConfigSource(@RequestBody String jsonString, HttpServletRequest request,
@@ -243,8 +265,11 @@ public class ConfigSourcesController extends BaseRestController {
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
jsonString); jsonString);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String requestId = UUID.randomUUID().toString();
try { try {
configSourcesService.updateCommonSources(thread, start, jsonString, new Date(), sb); if (getLock(requestId)) {
configSourcesService.updateCommonSources(thread, start, jsonString, new Date(), sb);
}
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
thread.setExceptionInfo("回调规则状态更新异常:" + e.getMessage()); thread.setExceptionInfo("回调规则状态更新异常:" + e.getMessage());
@@ -252,15 +277,17 @@ public class ConfigSourcesController extends BaseRestController {
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"回调规则状态更新异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); "回调规则状态更新异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
}else if (e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"回调规则状态更新异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); "回调规则状态更新异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
}else { } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"回调规则状态更新异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); "回调规则状态更新异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} }
} finally {
deblocking(requestId);
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则状态更新成功", return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "回调规则状态更新成功",
Constants.IS_DEBUG ? jsonString : null); Constants.IS_DEBUG ? jsonString : null);
} }
@@ -271,8 +298,7 @@ public class ConfigSourcesController extends BaseRestController {
public Map fileUploadSource(@RequestBody MultipartFile file, HttpServletRequest request, public Map fileUploadSource(@RequestBody MultipartFile file, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, null);
null);
String filePath = ""; String filePath = "";
try { try {
FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")), FileDesc fileDesc = (FileDesc) JSONObject.toBean(JSONObject.fromObject(request.getHeader("File-Desc")),
@@ -291,9 +317,10 @@ public class ConfigSourcesController extends BaseRestController {
} }
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
logger.info("-----------------调用接口上传文件---------------"); logger.info("-----------------调用接口上传文件---------------");
if(Constants.IS_USE_MINIO){ if (Constants.IS_USE_MINIO) {
filePath = MinioUtil.uploadFile(file.getInputStream(), file.getOriginalFilename(), file.getContentType()); filePath = MinioUtil.uploadFile(file.getInputStream(), file.getOriginalFilename(),
}else{ file.getContentType());
} else {
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext); FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5]; // NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); // meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
@@ -305,27 +332,28 @@ public class ConfigSourcesController extends BaseRestController {
filePath = FileManager.upload(fdsfile, null); filePath = FileManager.upload(fdsfile, null);
} }
} }
}catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.error(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage()); logger.error(RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage());
thread.setExceptionInfo(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage()); thread.setExceptionInfo(RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage());
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue()); RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage(),
}catch (Exception e) { RestBusinessCode.FileUploadFailure.getValue());
} catch (Exception e) {
// TODO: handle exception // TODO: handle exception
logger.error("文件上传异常:" +e.getMessage()); logger.error("文件上传异常:" + e.getMessage());
thread.setExceptionInfo("文件上传异常:" + e.getMessage()); thread.setExceptionInfo("文件上传异常:" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start, e.getMessage(),
e.getMessage(), ((RestServiceException) e).getErrorCode()); ((RestServiceException) e).getErrorCode());
}else if (e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, e.getMessage(),
e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); ((ServiceRuntimeException) e).getErrorCode());
}else { } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, e.getMessage(),
e.getMessage(), RestBusinessCode.FileUploadFailure.getValue()); RestBusinessCode.FileUploadFailure.getValue());
} }
} }
JSONObject jsonObj = new JSONObject(); JSONObject jsonObj = new JSONObject();
// jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group"))); // jsonObj.put("accessUrl", filePath.substring(filePath.indexOf("group")));
@@ -339,10 +367,10 @@ public class ConfigSourcesController extends BaseRestController {
public Map fileDigestSources(@RequestBody MultipartFile file, HttpServletRequest request, public Map fileDigestSources(@RequestBody MultipartFile file, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, file,
file, null); null);
JSONObject resultObject = new JSONObject(); JSONObject resultObject = new JSONObject();
String filePath=""; String filePath = "";
try { try {
if (file == null) { if (file == null) {
throw new RestServiceException("请上传获取摘要的文件到file参数", RestBusinessCode.FileIsNull.getValue()); throw new RestServiceException("请上传获取摘要的文件到file参数", RestBusinessCode.FileIsNull.getValue());
@@ -355,14 +383,14 @@ public class ConfigSourcesController extends BaseRestController {
String md5 = DigestUtils.md5Hex(file.getInputStream()); String md5 = DigestUtils.md5Hex(file.getInputStream());
System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'"); System.out.println("----------------------------MD5:'" + md5 + "'==='" + fileDesc.getChecksum() + "'");
if (!md5.equals(fileDesc.getChecksum())) { if (!md5.equals(fileDesc.getChecksum())) {
throw new RestServiceException("checksum与文件MD5值不一致", throw new RestServiceException("checksum与文件MD5值不一致", RestBusinessCode.CheckSumIsWrong.getValue());
RestBusinessCode.CheckSumIsWrong.getValue());
} }
String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1); String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
logger.info("-----------------调用接口上传文件---------------"); logger.info("-----------------调用接口上传文件---------------");
if(Constants.IS_USE_MINIO){ if (Constants.IS_USE_MINIO) {
filePath = MinioUtil.uploadFile(file.getInputStream(), file.getOriginalFilename(), file.getContentType()); filePath = MinioUtil.uploadFile(file.getInputStream(), file.getOriginalFilename(),
}else{ file.getContentType());
} else {
FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext); FastDFSFile fdsfile = new FastDFSFile(file.getBytes(), file.getOriginalFilename(), ext);
// NameValuePair[] meta_list = new NameValuePair[5]; // NameValuePair[] meta_list = new NameValuePair[5];
// meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename()); // meta_list[0] = new NameValuePair("fileName", file.getOriginalFilename());
@@ -375,44 +403,46 @@ public class ConfigSourcesController extends BaseRestController {
} }
resultObject.put("accessUrl", filePath); resultObject.put("accessUrl", filePath);
} }
}catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
logger.error(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage()); logger.error(RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage());
thread.setExceptionInfo(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage()); thread.setExceptionInfo(RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage());
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage(), RestBusinessCode.FileUploadFailure.getValue()); RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage(),
}catch (Exception e) { RestBusinessCode.FileUploadFailure.getValue());
} catch (Exception e) {
// TODO: handle exception // TODO: handle exception
logger.error(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+e.getMessage()); logger.error(RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage());
thread.setExceptionInfo(RestBusinessCode.FileUploadFailure.getErrorReason()+":"+ e.getMessage()); thread.setExceptionInfo(RestBusinessCode.FileUploadFailure.getErrorReason() + ":" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start, e.getMessage(),
e.getMessage(), ((RestServiceException) e).getErrorCode()); ((RestServiceException) e).getErrorCode());
}else if (e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, e.getMessage(),
e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); ((ServiceRuntimeException) e).getErrorCode());
}else { } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, e.getMessage(),
e.getMessage(), RestBusinessCode.FileUploadFailure.getValue()); RestBusinessCode.FileUploadFailure.getValue());
} }
} }
try { try {
String tempFilePath = request.getRealPath(File.separator) + "upload" + File.separator String tempFilePath = request.getRealPath(File.separator) + "upload" + File.separator
+ (new Date()).getTime() + file.getOriginalFilename(); + (new Date()).getTime() + file.getOriginalFilename();
file.transferTo(new File(tempFilePath)); file.transferTo(new File(tempFilePath));
//System.out.println("------------" + tempFilePath); // System.out.println("------------" + tempFilePath);
logger.info("摘要获取开始:---------------"); logger.info("摘要获取开始:---------------");
String digestStr = configSourcesService.getDigestGen(request.getRealPath(File.separator), tempFilePath); String digestStr = configSourcesService.getDigestGen(request.getRealPath(File.separator), tempFilePath);
logger.info("摘要获取结束:---------------:"+digestStr); logger.info("摘要获取结束:---------------:" + digestStr);
resultObject.put("digest", null==digestStr?"":digestStr); resultObject.put("digest", null == digestStr ? "" : digestStr);
resultObject.put("rawLen", file.getSize()); resultObject.put("rawLen", file.getSize());
FileUtils.deleteFile(tempFilePath); FileUtils.deleteFile(tempFilePath);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
logger.error(RestBusinessCode.GetFileDigestFailure.getValue()+":"+e.getMessage()+",请检查摘要获取工具是否安装成功"); logger.error(RestBusinessCode.GetFileDigestFailure.getValue() + ":" + e.getMessage() + ",请检查摘要获取工具是否安装成功");
thread.setExceptionInfo("摘要获取过程中出现异常:"+e.getMessage()+",请检查摘要获取工具是否安装成功"); thread.setExceptionInfo("摘要获取过程中出现异常:" + e.getMessage() + ",请检查摘要获取工具是否安装成功");
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, RestBusinessCode.GetFileDigestFailure.getErrorReason()+":"+e.getMessage()+",请检查摘要获取工具是否安装成功", throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
RestBusinessCode.GetFileDigestFailure.getErrorReason() + ":" + e.getMessage() + ",请检查摘要获取工具是否安装成功",
RestBusinessCode.GetFileDigestFailure.getValue()); RestBusinessCode.GetFileDigestFailure.getValue());
} }
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "摘要获取成功", resultObject); return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "摘要获取成功", resultObject);
@@ -423,22 +453,25 @@ public class ConfigSourcesController extends BaseRestController {
@ApiParam(value = "分组复用域配置对象", name = "groupReuseSource", required = true) @ApiParam(value = "分组复用域配置对象", name = "groupReuseSource", required = true)
public Map addGroupReuseSources(@RequestBody GroupReuseSource groupReuseSource, HttpServletRequest request, public Map addGroupReuseSources(@RequestBody GroupReuseSource groupReuseSource, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
groupReuseSource); groupReuseSource);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String requestId = UUID.randomUUID().toString();
try { try {
if (null != groupReuseSource && null != groupReuseSource.getGroupReuseList() if (getLock(requestId)) {
&& groupReuseSource.getGroupReuseList().size() > 0) { if (null != groupReuseSource && null != groupReuseSource.getGroupReuseList()
checkOpAction(thread, System.currentTimeMillis() - start, groupReuseSource.getOpAction(), Constants.OPACTION_POST); && groupReuseSource.getGroupReuseList().size() > 0) {
// 验证配置编译数据 checkOpAction(thread, System.currentTimeMillis() - start, groupReuseSource.getOpAction(),
validateGroupReuseSource(thread, start, groupReuseSource); Constants.OPACTION_POST);
configSourcesService.addGroupReuseSources(thread, start, groupReuseSource.getGroupReuseList(), sb); // 验证配置编译数据
} else { validateGroupReuseSource(thread, start, groupReuseSource);
throw new RestServiceException("Maat规则不能为空", configSourcesService.addGroupReuseSources(thread, start, groupReuseSource.getGroupReuseList(), sb);
RestBusinessCode.ConfigSourceIsNull.getValue()); } else {
throw new RestServiceException("Maat规则不能为空", RestBusinessCode.ConfigSourceIsNull.getValue());
}
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
@@ -446,21 +479,23 @@ public class ConfigSourcesController extends BaseRestController {
logger.error("Maat 分组复用规则存储异常:" + e.getMessage()); logger.error("Maat 分组复用规则存储异常:" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"Maat 分组复用规则存储异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); "Maat 分组复用规则存储异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
}else if(e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"Maat 分组复用规则存储异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); "Maat 分组复用规则存储异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
}else{ } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"Maat 分组复用规则存储异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); "Maat 分组复用规则存储异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} }
} finally {
deblocking(requestId);
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"Maat分组复用规则添加成功" + sb.toString(), Constants.IS_DEBUG ? groupReuseSource : null); "Maat分组复用规则添加成功" + sb.toString(), Constants.IS_DEBUG ? groupReuseSource : null);
} }
@RequestMapping(value = "/cfg/v1/groupReuseSources", method = RequestMethod.PUT) @RequestMapping(value = "/cfg/v1/groupReuseSources", method = RequestMethod.PUT)
@ApiOperation(value = "分组复用域配置删除接口", httpMethod = "PUT", response = Map.class, notes = "接收分组复用域配置,并从对应分组中删除") @ApiOperation(value = "分组复用域配置删除接口", httpMethod = "PUT", response = Map.class, notes = "接收分组复用域配置,并从对应分组中删除")
@ApiParam(value = "分组复用域配置对象", name = "groupReuseSource", required = true) @ApiParam(value = "分组复用域配置对象", name = "groupReuseSource", required = true)
@@ -470,20 +505,23 @@ public class ConfigSourcesController extends BaseRestController {
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
groupReuseSource); groupReuseSource);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String requestId = UUID.randomUUID().toString();
try { try {
if (null == groupReuseSource.getOpTime()) { if (getLock(requestId)) {
groupReuseSource.setOpTime(new Date()); if (null == groupReuseSource.getOpTime()) {
} groupReuseSource.setOpTime(new Date());
if (null != groupReuseSource && null != groupReuseSource.getGroupReuseList() }
&& groupReuseSource.getGroupReuseList().size() > 0) { if (null != groupReuseSource && null != groupReuseSource.getGroupReuseList()
int opAction = groupReuseSource.getOpAction(); && groupReuseSource.getGroupReuseList().size() > 0) {
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2); int opAction = groupReuseSource.getOpAction();
configSourcesService.deleteGroupReuseSources(thread, start,groupReuseSource.getGroupReuseList(), checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
groupReuseSource.getOpTime(), sb); configSourcesService.deleteGroupReuseSources(thread, start, groupReuseSource.getGroupReuseList(),
groupReuseSource.getOpTime(), sb);
} else {
throw new RestServiceException("分组复用信息不能为空" + sb.toString(), } else {
RestBusinessCode.ConfigSourceIsNull.getValue()); throw new RestServiceException("分组复用信息不能为空" + sb.toString(),
RestBusinessCode.ConfigSourceIsNull.getValue());
}
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
@@ -491,23 +529,26 @@ public class ConfigSourcesController extends BaseRestController {
logger.error("删除MAAT规则分组复用域配置时出现异常:" + e.getMessage()); logger.error("删除MAAT规则分组复用域配置时出现异常:" + e.getMessage());
if (e instanceof RestServiceException) { if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start, throw new RestServiceException(thread, System.currentTimeMillis() - start,
"删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); "删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
}else if(e instanceof ServiceRuntimeException) { } else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); "删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
}else{ } else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); "删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} }
} finally {
deblocking(requestId);
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"MAAT规则分组复用域配置删除成功" + sb.toString(), Constants.IS_DEBUG ?groupReuseSource : null); "MAAT规则分组复用域配置删除成功" + sb.toString(), Constants.IS_DEBUG ? groupReuseSource : null);
} }
@RequestMapping(value = "/cfg_batch/v1/configSources", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/cfg_batch/v1/configSources", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "全量同步配置接收接口", httpMethod = "POST", response = Map.class, notes = "接收全量同步配置") @ApiOperation(value = "全量同步配置接收接口", httpMethod = "POST", response = Map.class, notes = "接收全量同步配置")
public Map receiveConfigSources(@RequestBody String jsonString, HttpServletRequest request, public Map receiveConfigSources(@RequestBody String jsonString, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
null); null);
@@ -519,19 +560,19 @@ public class ConfigSourcesController extends BaseRestController {
throw new RestServiceException(RestBusinessCode.config_integrity_error.getErrorReason() + "," + e.getMessage(), throw new RestServiceException(RestBusinessCode.config_integrity_error.getErrorReason() + "," + e.getMessage(),
RestBusinessCode.config_integrity_error.getValue()); RestBusinessCode.config_integrity_error.getValue());
} }
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "已接收全量同步配置信息", return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "已接收全量同步配置信息",
Constants.IS_DEBUG ? jsonString : null); Constants.IS_DEBUG ? jsonString : null);
} }
@RequestMapping(value = "/cfg_batch/v1/status", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/cfg_batch/v1/status", method = RequestMethod.POST, produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "配置全量同步指令下发接口", httpMethod = "POST", response = Map.class, notes = "下发配置同步指令") @ApiOperation(value = "配置全量同步指令下发接口", httpMethod = "POST", response = Map.class, notes = "下发配置同步指令")
public Map acceptStatus(@RequestBody String jsonString, HttpServletRequest request, public Map acceptStatus(@RequestBody String jsonString, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST, request,
null); null);
JSONObject obj= JSONObject.fromObject(jsonString); JSONObject obj= JSONObject.fromObject(jsonString);
if (!StringUtil.isEmpty(obj.get("syncStatus"))&&"1".equals(obj.get("syncStatus").toString())) { if (!StringUtil.isEmpty(obj.get("syncStatus"))&&"1".equals(obj.get("syncStatus").toString())) {
logger.info("-----------配置同步指令下发:"+new Date()); logger.info("-----------配置同步指令下发:"+new Date());
}else{ }else{
@@ -539,16 +580,16 @@ public class ConfigSourcesController extends BaseRestController {
thread.setBusinessCode(RestBusinessCode.syncStatusFailed.getValue()); thread.setBusinessCode(RestBusinessCode.syncStatusFailed.getValue());
throw new RestServiceException("未获取到同步状态码", RestBusinessCode.syncStatusFailed.getValue()); throw new RestServiceException("未获取到同步状态码", RestBusinessCode.syncStatusFailed.getValue());
} }
thread.setBusinessCode(RestBusinessCode.syncStatusSuccessed.getValue()); thread.setBusinessCode(RestBusinessCode.syncStatusSuccessed.getValue());
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置同步指令下发成功", return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "配置同步指令下发成功",
Constants.IS_DEBUG ? jsonString : null); Constants.IS_DEBUG ? jsonString : null);
} }
@RequestMapping(value = "/cfg_batch/v1/status", method = RequestMethod.GET) @RequestMapping(value = "/cfg_batch/v1/status", method = RequestMethod.GET)
@ApiOperation(value = "获取全量同步状态服务接口", httpMethod = "GET", response = Map.class, notes = "获取全量同步状态服务") @ApiOperation(value = "获取全量同步状态服务接口", httpMethod = "GET", response = Map.class, notes = "获取全量同步状态服务")
public Map getSyncStatus(HttpServletRequest request, public Map getSyncStatus(HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null); null);
@@ -587,6 +628,7 @@ public class ConfigSourcesController extends BaseRestController {
} }
} }
private boolean isBlank(Date datetime) { private boolean isBlank(Date datetime) {
if (null != datetime) { if (null != datetime) {
return true; return true;

View File

@@ -224,7 +224,7 @@ service=1:128;2:128;5:96;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;2
####删除动作为ratelimit的业务 ####删除动作为ratelimit的业务
#0x420 APP限流 #0x420 APP限流
#1056=10:APP_COMPILE;11:APP_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE 1056=10:APP_COMPILE;11:APP_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE
#0x421 IP限流 #0x421 IP限流
#1057=10:LIMIT_COMPILE;11:LIMIT_GROUP;12:LIMIT_IP;18:NTC_IP_RANGE #1057=10:LIMIT_COMPILE;11:LIMIT_GROUP;12:LIMIT_IP;18:NTC_IP_RANGE
#0x422 域名限流 #0x422 域名限流
@@ -329,7 +329,7 @@ unMaatService=3:32;4:96;25:32;28:32;64;65;261:16;262:16;263:16;264:16;265:16;266
##回调类配置 ##回调类配置
#0x340 IP复用地址池配置回调832:2,4,5 #0x340 IP复用地址池配置回调832:2,4,5
########## ##########
serviceDBIndex=1:2,4,5;2:2,4,5;5:2,5;66:2,4,5;16:2;17:2;18:2;19:2;20:2;21:2;22:2;23:2;24:2;26:2;27:2;30:2;31:2;32:2;33:2,5;34:2;35:2;36:2;37:2;38:2;39:2;40:2;128:2;129:2;130:2;131:2;132:2;133:2;134:2;135:2;136:2;137:2;138:2;139:2;140:2;142:2;143:2;144:2;145:2;146:2;147:2;148:2;149:2;150:2;151:2;152:2;256:2;257:2;258:2;259:2;260:2;267:2;271:2;272:2;273:3;274:5;384:2;385:2;386:2;387:2;388:2;395:2;399:3;512:4,5;513:4,2,5;514:4,5;515:4,5;517:4,5;520:4;521:4;528:4;544:4;560:4;576:4;592:4;608:4;624:4;625:4;640:4;641:4;750:4;768:4;1024:2;1025:2;1026:2,5;1027:2;1028:2,5;1029:2;1030:2;1040:2;1041:2;1042:2;1152:2;3:5;4:5;25:5;28:5;64:2;65:2;261:3;262:3;263:3;264:3;265:3;266:3;268:3;269:3;270:3;389:3;390:3;391:3;392:3;393:3;394:3;396:3;397:3;398:3;832:2,4,5; serviceDBIndex=1:2,4,5;2:2,4,5;5:2,5;66:2,4,5;16:2;17:2;18:2;19:2;20:2;21:2;22:2;23:2;24:2;26:2;27:2;30:2;31:2;32:2;33:2,5;34:2;35:2;36:2;37:2;38:2;39:2;40:2;128:2;129:2;130:2;131:2;132:2;133:2;134:2;135:2;136:2;137:2;138:2;139:2;140:2;142:2;143:2;144:2;145:2;146:2;147:2;148:2;149:2;150:2;151:2;152:2;256:2;257:2;258:2;259:2;260:2;267:2;271:2;272:2;273:3;274:5;384:2;385:2;386:2;387:2;388:2;395:2;399:3;512:4,5;513:4,2,5;514:4,5;515:4,2,5;517:4,5;520:4;521:4;528:4;544:4;560:4;576:4;592:4;608:4;624:4;625:4;640:4;641:4;750:4;768:4;1024:2;1025:2;1026:2,5;1027:2;1028:2,5;1029:2;1030:2;1040:2;1041:2;1042:2;1056:2;1152:2;3:5;4:5;25:5;28:5;64:2;65:2;261:3;262:3;263:3;264:3;265:3;266:3;268:3;269:3;270:3;389:3;390:3;391:3;392:3;393:3;394:3;396:3;397:3;398:3;832:2,4,5;
##阀门配置在redisdb的序号 ##阀门配置在redisdb的序号
tapRedisDb=5 tapRedisDb=5

View File

@@ -95,7 +95,9 @@ jdbc.clickhouse.driver=ru.yandex.clickhouse.ClickHouseDriver
#jdbc.clickhouse.key=qRKvjMvQcZMq9IdJUa2rbw== #jdbc.clickhouse.key=qRKvjMvQcZMq9IdJUa2rbw==
#实际密码k18 #实际密码k18
#jdbc.clickhouse.password=kxBBKsR2qwyEYFJ8vLcKPA== #jdbc.clickhouse.password=kxBBKsR2qwyEYFJ8vLcKPA==
#元辰鑫 #华严账号密码同元辰鑫
#jdbc.clickhouse.url=jdbc:clickhouse://192.168.10.77:8123/k18_ods?socket_timeout=90000
#元辰鑫账号密码同华严
jdbc.clickhouse.url=jdbc:clickhouse://192.168.10.192:8123/k18_ods?socket_timeout=90000 jdbc.clickhouse.url=jdbc:clickhouse://192.168.10.192:8123/k18_ods?socket_timeout=90000
jdbc.clickhouse.username=default jdbc.clickhouse.username=default
jdbc.clickhouse.key=aUkjs+fcwf6p4rDqHiC+ng== jdbc.clickhouse.key=aUkjs+fcwf6p4rDqHiC+ng==

View File

@@ -213,9 +213,7 @@ fileProtocol=redis://
#是否开启日志查询count和last功能 #是否开启日志查询count和last功能
isOpenLogCountAndLast=true isOpenLogCountAndLast=true
#redis分布式锁超时时间,默认五分钟,3000秒
#定义单独添加域与删除域开启的最大线程数 redisLockTime=3000
maxThreadNum=20 #获取redis分布式锁失败后的尝试获取锁的次数,每次失败暂停一秒钟后再次尝试
#每个线程处理多少条数据 redisRetryNum=5
everThreadNum=500