合并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

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