1:新增webFocusDb业务

2:修改编译配置对doblacklist,exprType的校验值
3:新增从clickhouse查询流量统计的controller,service,dao等
4:新增对maat类配置支持停启用
This commit is contained in:
renkaige
2018-12-24 10:34:06 +06:00
parent 829be054fb
commit c50d92d265
23 changed files with 2361 additions and 169 deletions

View File

@@ -10,9 +10,6 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zdjizhi.utils.StringUtil;
import net.sf.json.JSONObject;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
@@ -23,7 +20,9 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.nis.domain.restful.ConfigCompile;
import com.nis.domain.restful.ConfigCompileStartStop;
import com.nis.domain.restful.ConfigSource;
import com.nis.domain.restful.ConfigSourceStartStop;
import com.nis.domain.restful.FileDesc;
import com.nis.domain.restful.GroupReuse;
import com.nis.domain.restful.GroupReuseSource;
@@ -45,6 +44,9 @@ import com.nis.web.service.restful.ConfigSourcesService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import com.zdjizhi.utils.StringUtil;
import net.sf.json.JSONObject;
/**
* @ClassName: ConfigSourcesController
@@ -121,6 +123,50 @@ public class ConfigSourcesController extends BaseRestController {
"Maat规则下发成功" + sb.toString(), Constants.IS_DEBUG ? configSource : null);
}
@RequestMapping(value = "/cfg/v2/configStartStop", method = RequestMethod.PUT)
@ApiOperation(value = "MAAT规则停用启用接口", httpMethod = "PUT", response = Map.class, notes = "接收MAAT类配置,对配置停用还是启用")
@ApiParam(value = "MAAT规则停用启用接口", name = "configStartStop", required = true)
public Map configStartStop(@RequestBody ConfigSourceStartStop configSourceStartStop, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
configSourceStartStop);
// 分布式锁的标识,谁加锁,谁解锁,如果中间发生了异常则根据失效时间自动失效,默认五分钟失效
StringBuffer sb = new StringBuffer();
String requestId = UUID.randomUUID().toString();
try {
if (getLock(requestId)) {
checkOpAction(thread, System.currentTimeMillis() - start, configSourceStartStop.getOpAction(),
Constants.OPACTION_PUT);
configSourcesService.updateConfigSources(thread, start, configSourceStartStop.getConfigCompileStartStopList(),
configSourceStartStop.getOpTime(), sb,true);
}
} catch (Exception e) {
thread.setExceptionInfo("Maat 规则停启用异常:" + ExceptionUtil.getExceptionMsg(e));
logger.error("Maat 规则停启用异常:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(thread, System.currentTimeMillis() - start,
"Maat 规则停启用异常:" + ExceptionUtil.getExceptionMsg(e), ((RestServiceException) e).getErrorCode());
} else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"Maat 规则停启用异常:" + ExceptionUtil.getExceptionMsg(e),
((ServiceRuntimeException) e).getErrorCode());
} else {
throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start,
"Maat 规则停启用异常:" + ExceptionUtil.getExceptionMsg(e),
RestBusinessCode.service_runtime_error.getValue());
}
} finally {
deblocking(requestId);
}
return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response,
"Maat规则停启用成功" + sb.toString(), Constants.IS_DEBUG ? configSourceStartStop : null);
}
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.PUT)
@ApiOperation(value = "MAAT规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收Maat规则,对其状态置为失效")
@ApiParam(value = "MAAT规则对象", name = "configSource", required = true)
@@ -145,7 +191,7 @@ public class ConfigSourcesController extends BaseRestController {
}
checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(),
configSource.getOpTime(), sb);
configSource.getOpTime(), sb,false);
} else {
throw new RestServiceException("Maat规则不能为空" + sb.toString(),

View File

@@ -0,0 +1,205 @@
package com.nis.web.controller.restful;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.nis.domain.Page;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Constants;
import com.nis.util.DateUtils;
import com.nis.util.ExceptionUtil;
import com.nis.util.StringUtils;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.restful.TrafficReportService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.zdjizhi.utils.StringUtil;
/**
*
* <p>
* Title: SingleDimensionReport
* </p>
* <p>
* Description:首页流量统计查询controller,改为从clickhouse中获取
* </p>
* <p>
* Company: IIE
* </p>
*
* @author rkg
* @date 2018年12月20日
*
*/
@RestController
@RequestMapping("${servicePath}/ckLog/v1")
@Api(value = "TrafficeReportController", description = "流量统计查询报表controller")
public class TrafficeReportController extends BaseRestController {
@Autowired
protected ServicesRequestLogService servicesRequestLogService;
@Autowired
protected TrafficReportService trafficReportService;
@RequestMapping(value = "/ntcRadiusReport", method = RequestMethod.GET)
@ApiOperation(value = "用户行为统计查询服务", httpMethod = "GET", notes = "用户行为统计查询服务基于用户名或接入IP维度聚合")
public Map<String, ?> ntcRadiusReport(Page page, NtcRadiusReport ntcRadiusReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
try {
resetReportTime(ntcRadiusReport, true);
trafficReportService.checkNtcRadiusReportCondition(saveLogThread, start, ntcRadiusReport);
trafficReportService.findNtcRadiusReport(page, ntcRadiusReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo("用户行为统计查询失败:" + e.getMessage());
logger.error("用户行为统计查询失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(saveLogThread, System.currentTimeMillis() - start,
"用户行为统计查询失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
} else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"用户行为统计查询失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
} else {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"用户行为统计查询失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "用户行为统计查询成功", page, 0);
}
/**
* 根据ip46,协议tcpudp查询带宽
*/
@RequestMapping(value = "trafficBandwidthTransThree", method = RequestMethod.GET)
@ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
public Map<String, ?> trafficBandwidthTransThree(@RequestParam String beginDate, @RequestParam String endDate,
Model model, HttpServletRequest request, HttpServletResponse response) {
String[] addrTypes = { "4", "6" };// ipv4,ipv6是固定的不会变
String[] transTypes = { "6", "17" };// 传输层协议,tcp,udp
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
Map<String, List<HashMap>> resultMap = new HashMap<String, List<HashMap>>();
try {
if (StringUtils.isEmpty(beginDate) && StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());// 获取到完整的时间
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
beginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
}
String addrType = null;
Integer transType = null;
if (addrTypes != null) {
for (int i = 0; i < addrTypes.length; i++) {
addrType = addrTypes[i];
List<HashMap> resultList = trafficReportService.getBandwidthTrans(addrType, transType, beginDate,
endDate);
if (resultList != null && resultList.size() > 0) {
resultMap.put("ipv" + addrType + "Type1", resultList);
}
resultList = trafficReportService.getBandwidthTrans2(addrType, transType, beginDate, endDate);
if (resultList != null && resultList.size() > 0) {
resultMap.put("ipv" + addrType + "Type2", resultList);
}
addrType = null;
}
}
if (transTypes != null) {
for (int i = 0; i < transTypes.length; i++) {
transType = Integer.valueOf(transTypes[i]);
List<HashMap> resultList = trafficReportService.getBandwidthTrans(addrType, transType, beginDate,
endDate);
if (resultList != null && resultList.size() > 0) {
resultMap.put("trans" + transType + "Type1", resultList);
}
resultList = trafficReportService.getBandwidthTrans2(addrType, transType, beginDate, endDate);
if (resultList != null && resultList.size() > 0) {
resultMap.put("trans" + transType + "Type2", resultList);
}
transType = null;
}
}
} catch (Exception e) {
auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:" + e.getMessage());
logger.error("带宽实时统计数据检索失败:" + ExceptionUtil.getExceptionMsg(e));
if (e instanceof RestServiceException) {
throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start,
"带宽实时统计数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode());
} else if (e instanceof ServiceRuntimeException) {
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"带宽实时统计数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode());
} else {
throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",
resultMap, 0);
}
/**
* @Description:
* @author (zdx)
* @date 2018年7月12日 上午11:01:30
* @param entity
* @throws Exception
*/
public void resetReportTime(NtcRadiusReport entity, Boolean isTotal) throws Exception {
// 日志总量统计查询全部
// if ("1".equals(entity.getSearchBusinessType()) && isTotal) {
// return;
// }
if (StringUtil.isEmpty(entity.getSearchReportStartTime())
&& StringUtil.isEmpty(entity.getSearchReportEndTime())) {
String dateType = "hour"; // 默认为分钟
if (!isTotal) {
if (entity.getSearchBusinessType().equals("2")) {
dateType = "hour";
} else if (entity.getSearchBusinessType().equals("3")) {
dateType = "daily";
} else if (entity.getSearchBusinessType().equals("4")) {
dateType = "month";
}
} else {
if (entity.getSearchBusinessType().equals("3")) {
dateType = "hour";
} else if (entity.getSearchBusinessType().equals("4")) {
dateType = "daily";
} else if (entity.getSearchBusinessType().equals("5")) {
dateType = "month";
}
}
Map<String, String> map = DateUtils.getLocalTime(entity.getSearchReportStartTime(),
entity.getSearchReportEndTime(), Constants.PZ_REPORT_TIME, dateType);
entity.setSearchReportStartTime(map.get("startTime"));
entity.setSearchReportEndTime(map.get("endTime"));
}
}
}