diff --git a/src/main/java/com/nis/domain/restful/ConfigCompileStartStop.java b/src/main/java/com/nis/domain/restful/ConfigCompileStartStop.java new file mode 100644 index 0000000..453a6f5 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/ConfigCompileStartStop.java @@ -0,0 +1,89 @@ +/** +* @Title: DfConfigCompile.java +* @Package com.nis.domain.restful +* @Description: TODO(用一句话描述该文件做什么) +* @author (darnell) +* @date 2016年8月29日 下午9:36:28 +* @version V1.0 +*/ +package com.nis.domain.restful; + +import java.io.Serializable; +import java.util.Date; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.nis.util.JsonDateDeserializer; +import com.wordnik.swagger.annotations.ApiModelProperty; + +/** + * @ClassName: ConfigCompileStartStop + * @Description: TODO(这里用一句话描述这个类的作用) + * @author (rkg) + * @date 2018年12月22日 下午4:36:28 + * @version V1.0 + */ +public class ConfigCompileStartStop implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 546753235262247839L; + @ApiModelProperty(value = "配置ID", required = true) + private Long compileId; + @ApiModelProperty(value = "有效标志", required = true) + private Integer isValid; + @ApiModelProperty(value = "业务类型", required = true) + private Integer service; + @ApiModelProperty(value = "操作时间", required = true) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date opTime; + + public Long getCompileId() { + return compileId; + } + + public void setCompileId(Long compileId) { + this.compileId = compileId; + } + + /** + * @return isValid + */ + public Integer getIsValid() { + return isValid; + } + + /** + * @param isValid 要设置的 isValid + */ + public void setIsValid(Integer isValid) { + this.isValid = isValid; + } + + + public Integer getService() { + return service; + } + + public void setService(Integer service) { + this.service = service; + } + + /** + * @return opTime + */ + @JsonDeserialize(using = JsonDateDeserializer.class) + public Date getOpTime() { + return opTime; + } + + /** + * @param opTime 要设置的 opTime + */ + @JsonDeserialize(using = JsonDateDeserializer.class) + public void setOpTime(Date opTime) { + this.opTime = opTime; + } + +} diff --git a/src/main/java/com/nis/domain/restful/ConfigSourceStartStop.java b/src/main/java/com/nis/domain/restful/ConfigSourceStartStop.java new file mode 100644 index 0000000..5d47d53 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/ConfigSourceStartStop.java @@ -0,0 +1,114 @@ +/** +* @Title: ConfigSource.java +* @Package com.nis.domain.restful +* @Description: TODO(用一句话描述该文件做什么) +* @author (darnell) +* @date 2016年8月29日 下午9:31:24 +* @version V1.0 +*/ +package com.nis.domain.restful; + +import java.util.Date; +import java.util.List; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.nis.util.JsonDateDeserializer; +import com.nis.util.JsonDateSerializer; + +/** + * @ClassName: ConfigSourceStartStop + * @Description: TODO(这里用一句话描述这个类的作用) + * @author (darnell) + * @date 2016年8月31日 下午8:32:43 + * @version V1.0 + */ +public class ConfigSourceStartStop extends ConfigCommonSource { + + /** + * + */ + private static final long serialVersionUID = 1L; + private static final String DEFAULT_VERSION = "2.0"; + private List configCompileStartStopList; // 编译配置列表 + + /** + * @Title: + * @Description: TODO + * @param + */ + public ConfigSourceStartStop() { + this.version = DEFAULT_VERSION; + } + + public ConfigSourceStartStop(String Version) { + this.version = Version; + } + + /** + * @return version + */ + public String getVersion() { + return version; + } + + /** + * @param version 要设置的 version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * @return operator + */ + public String getOperator() { + return operator; + } + + /** + * @param operator 要设置的 operator + */ + public void setOperator(String operator) { + this.operator = operator; + } + + /** + * @return opTime + */ + @JsonSerialize(using = JsonDateSerializer.class) + public Date getOpTime() { + return opTime; + } + + /** + * @param opTime 要设置的 opTime + */ + @JsonDeserialize(using = JsonDateDeserializer.class) + public void setOpTime(Date opTime) { + this.opTime = opTime; + } + + /** + * @return opAction + */ + public Integer getOpAction() { + return opAction; + } + + /** + * @param opAction 要设置的 opAction + */ + public void setOpAction(Integer opAction) { + this.opAction = opAction; + } + + public List getConfigCompileStartStopList() { + return configCompileStartStopList; + } + + public void setConfigCompileStartStopList(List configCompileStartStopList) { + this.configCompileStartStopList = configCompileStartStopList; + } + +} diff --git a/src/main/java/com/nis/domain/restful/NtcRadiusReport.java b/src/main/java/com/nis/domain/restful/NtcRadiusReport.java index c992d44..72bee7e 100644 --- a/src/main/java/com/nis/domain/restful/NtcRadiusReport.java +++ b/src/main/java/com/nis/domain/restful/NtcRadiusReport.java @@ -3,14 +3,17 @@ package com.nis.domain.restful; import java.io.Serializable; import java.util.Date; +import javax.xml.bind.annotation.XmlTransient; + import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.nis.domain.Page; import com.nis.util.JsonDateSerializer; import com.wordnik.swagger.annotations.ApiModelProperty; -public class NtcRadiusReport implements Serializable{ +public class NtcRadiusReport implements Serializable{ private static final long serialVersionUID = 7635016645942704971L; @JsonInclude(value = Include.NON_NULL) @@ -39,6 +42,9 @@ public class NtcRadiusReport implements Serializable{ protected String searchAccount; protected String groupType; + + protected Page page; + public String getNasIp() { return nasIp; } @@ -135,5 +141,18 @@ public class NtcRadiusReport implements Serializable{ public void setGroupType(String groupType) { this.groupType = groupType; } + + @JsonIgnore + @XmlTransient + public Page getPage() { + if (page == null) { + page = new Page(); + } + return page; + } + public Page setPage(Page page) { + this.page = page; + return page; + } } diff --git a/src/main/java/com/nis/domain/restful/TrafficNetflowPortInfo.java b/src/main/java/com/nis/domain/restful/TrafficNetflowPortInfo.java index 1efbf82..00e7c3a 100644 --- a/src/main/java/com/nis/domain/restful/TrafficNetflowPortInfo.java +++ b/src/main/java/com/nis/domain/restful/TrafficNetflowPortInfo.java @@ -15,6 +15,7 @@ public class TrafficNetflowPortInfo implements Serializable { @JsonIgnore private long stat_id; private long port; + private long entranceId; private String nodeName; private String nodeIp; private String portDesc; @@ -44,6 +45,14 @@ public class TrafficNetflowPortInfo implements Serializable { public void setPort(long port) { this.port = port; } + + public long getEntranceId() { + return entranceId; + } + + public void setEntranceId(long entranceId) { + this.entranceId = entranceId; + } public String getNodeName() { return nodeName; diff --git a/src/main/java/com/nis/interceptor/DataSourceBInterceptor.java b/src/main/java/com/nis/interceptor/DataSourceBInterceptor.java index e5ce979..5370018 100644 --- a/src/main/java/com/nis/interceptor/DataSourceBInterceptor.java +++ b/src/main/java/com/nis/interceptor/DataSourceBInterceptor.java @@ -15,7 +15,7 @@ public class DataSourceBInterceptor implements HandlerInterceptor { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { logger.info("开启数据源配置操作库---"); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B);//开启数据源B + CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B);//开启数据源B(我们自己的clickhouse) logger.info("mysql日志数据源开启成功---"+System.currentTimeMillis()); return true; } diff --git a/src/main/java/com/nis/util/CompileVal.java b/src/main/java/com/nis/util/CompileVal.java index 888703b..5a82ce3 100644 --- a/src/main/java/com/nis/util/CompileVal.java +++ b/src/main/java/com/nis/util/CompileVal.java @@ -901,8 +901,8 @@ public class CompileVal { "编译配置id为" + compileId + "的配置中service的值为" + configCompile.getService() + "时action只能为" + action, RestBusinessCode.ServiceUnmatchAction.getValue()); } - if (configCompile.getDoBlacklist() != 1) { - throw new RestServiceException("编译配置id为" + compileId + "的配置中doBlacklist的值只能是1", + if (configCompile.getDoBlacklist() != 1&&configCompile.getDoBlacklist() != 0) { + throw new RestServiceException("编译配置id为" + compileId + "的配置中doBlacklist的值只能是1或0", RestBusinessCode.DoBlacklistIsWrongRange.getValue()); } @@ -923,12 +923,12 @@ public class CompileVal { public static void serviceStrRegionVal(StrRegion strRegion, Long compileId, boolean isDirtrict) throws Exception { - Integer exprType = strRegion.getExprType(); + Integer exprType= strRegion.getExprType(); Integer matchMethod = strRegion.getMatchMethod(); Integer isHexbin = strRegion.getIsHexbin(); - if (exprType != 0 && exprType != 1) { + if (exprType != 0 && exprType != 1 && exprType != 3) { throw new RestServiceException("编译配置id为" + compileId + "的配置中strRegionList中regionId为" - + strRegion.getRegionId() + "的域配置exprType的值只能是0(无表达式)或者1(与表达式)", + + strRegion.getRegionId() + "的域配置exprType的值只能是0(无表达式)或者1(与表达式)或者3(偏移表达式)", RestBusinessCode.ExprTypeIsWrongRange.getValue()); } if (matchMethod != 0 && matchMethod != 1 && matchMethod != 2 && matchMethod != 3) { diff --git a/src/main/java/com/nis/util/Constants.java b/src/main/java/com/nis/util/Constants.java index a29f6eb..669b17f 100644 --- a/src/main/java/com/nis/util/Constants.java +++ b/src/main/java/com/nis/util/Constants.java @@ -233,4 +233,11 @@ public final class Constants { + //阀门库db + public static final int TAPREDISDB = Configurations.getIntProperty("tapRedisDb", 5); + //webfocus库db + public static final int WEBFOCUSREDISDB = Configurations.getIntProperty("webFocusDb", 7); + + + } diff --git a/src/main/java/com/nis/util/JedisUtils.java b/src/main/java/com/nis/util/JedisUtils.java index 43592ec..86f59fe 100644 --- a/src/main/java/com/nis/util/JedisUtils.java +++ b/src/main/java/com/nis/util/JedisUtils.java @@ -6,19 +6,18 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisSentinelPool; -import redis.clients.jedis.exceptions.JedisException; - import com.google.common.collect.Lists; import com.nis.restful.RestBusinessCode; import com.nis.restful.ServiceRuntimeException; import com.nis.web.service.SpringContextHolder; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisSentinelPool; +import redis.clients.jedis.exceptions.JedisException; + public class JedisUtils { private static Logger logger = LoggerFactory.getLogger(JedisUtils.class); - private static final JedisPool jedisPool = SpringContextHolder.getBean(JedisPool.class); + /** * 获取缓存 * @@ -213,13 +212,15 @@ public class JedisUtils { * @throws JedisException */ public static Jedis getResource(int redisDb) throws JedisException { - Jedis jedis = null; - if (jedisPool == null) { + JedisSentinelPool jedisSentinelPool = SpringContextHolder.getBean(JedisSentinelPool.class); + + if (jedisSentinelPool == null) { throw new ServiceRuntimeException("redis连接池为空,请联系管理员检查程序", RestBusinessCode.CannotConnectionRedis.getValue()); } + Jedis jedis = null; try { - jedis = jedisPool.getResource(); + jedis = jedisSentinelPool.getResource(); jedis.select(redisDb); } catch (JedisException e) { returnBrokenResource(jedis); diff --git a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java index b7427c1..64104ce 100644 --- a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java +++ b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java @@ -56,11 +56,14 @@ public class ServiceAndRDBIndexReal { * Map> */ private static Map> maatToValveMap = new HashMap>(); + /** - * 阀门保存的redis数据库Index,在nis.properties中定义 + * 保存maat分发到webFocus需要添加到域的属性:maat2WebFocus + * Map> */ - private static Integer valveDBIndex = Configurations.getIntProperty("tapRedisDb", 5); + private static Map> maatToWebFocusMap = new HashMap>(); + static { String unMaatService = Configurations.getStringProperty("unMaatService", ""); @@ -130,7 +133,7 @@ public class ServiceAndRDBIndexReal { } } - String maat2Valve = Configurations.getStringProperty("maat2Valve", ""); + String maat2Valve= Configurations.getStringProperty("maat2Valve", ""); if (maat2Valve != null && !maat2Valve.trim().equals("")) { String[] maat2ValveAry = maat2Valve.split(";"); for (String maat2ValveStr : maat2ValveAry) { @@ -154,6 +157,29 @@ public class ServiceAndRDBIndexReal { } } } + String maat2WebFocus = Configurations.getStringProperty("maat2WebFocus", ""); + if (maat2WebFocus != null && !maat2WebFocus.trim().equals("")) { + String[] maat2ValveAry = maat2WebFocus.split(";"); + for (String maat2ValveStr : maat2ValveAry) { + String[] serviceAndRegion = maat2ValveStr.split(":"); + if (serviceAndRegion != null && serviceAndRegion.length == 2) { + String[] regionAndFields = serviceAndRegion[1].split("@"); + Map fieldMap = new HashMap(); + String[] fields = regionAndFields[1].split("&"); + // 同一service有不同的域类型,多个之间用“|”分隔 + if (regionAndFields[0].contains("|")) { + String[] regionTypeAry = regionAndFields[0].split("\\|"); + for (String regionType : regionTypeAry) { + fieldMap.put(regionType, fields); + } + } else { + fieldMap.put(regionAndFields[0], fields); + } + maatToWebFocusMap.put(Integer.parseInt(serviceAndRegion[0]), fieldMap); + + } + } + } String serviceRepeatedReal = Configurations.getStringProperty("serviceRepeatedReal", ""); if (!StringUtil.isEmpty(serviceRepeatedReal)) { @@ -351,6 +377,7 @@ public class ServiceAndRDBIndexReal { return isValve; } + /** * 根据业务类型获取unmaat配置表名 * @param service @@ -391,20 +418,20 @@ public class ServiceAndRDBIndexReal { ServiceAndRDBIndexReal.maatToValveMap = maatToValveMap; } - /** - * @param valveDBIndex the valveDBIndex to set - */ - public static void setValveDBIndex(Integer valveDBIndex) { - ServiceAndRDBIndexReal.valveDBIndex = valveDBIndex; + + + + + public static Map> getMaatToWebFocusMap() { + return maatToWebFocusMap; } - /** - * @return the valveDBIndex - */ - public static Integer getValveDBIndex() { - return valveDBIndex; + public static void setMaatToWebFocusMap(Map> maatToWebFocusMap) { + ServiceAndRDBIndexReal.maatToWebFocusMap = maatToWebFocusMap; } + + public static Map getUnMaatSercieNameMap() { return unMaatSercieNameMap; } diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java index 113117a..83ae455 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -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(), diff --git a/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java b/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java new file mode 100644 index 0000000..1182231 --- /dev/null +++ b/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java @@ -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; + +/** + * + *

+ * Title: SingleDimensionReport + *

+ *

+ * Description:首页流量统计查询controller,改为从clickhouse中获取 + *

+ *

+ * Company: IIE + *

+ * + * @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 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,协议tcp,udp查询带宽 + */ + @RequestMapping(value = "trafficBandwidthTransThree", method = RequestMethod.GET) + @ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示") + public Map 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> resultMap = new 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 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 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 map = DateUtils.getLocalTime(entity.getSearchReportStartTime(), + entity.getSearchReportEndTime(), Constants.PZ_REPORT_TIME, dateType); + entity.setSearchReportStartTime(map.get("startTime")); + entity.setSearchReportEndTime(map.get("endTime")); + } + } +} diff --git a/src/main/java/com/nis/web/dao/TrafficNetflowPortInfoDao.xml b/src/main/java/com/nis/web/dao/TrafficNetflowPortInfoDao.xml index 362b2e9..c3011c2 100644 --- a/src/main/java/com/nis/web/dao/TrafficNetflowPortInfoDao.xml +++ b/src/main/java/com/nis/web/dao/TrafficNetflowPortInfoDao.xml @@ -14,7 +14,8 @@ OUTOCTETS_SPEED , INPKTS_SPEED , OUTPKTS_SPEED , - RECV_TIME + RECV_TIME, + ENTRANCE_ID ) VALUES ( #{port}, #{nodeName}, @@ -27,6 +28,7 @@ #{outoctetsSpeed}, #{inpktsSpeed}, #{outpktsSpeed}, - #{recvTime}) + #{recvTime}, + #{entranceId}) \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/TrafficReportDao.java b/src/main/java/com/nis/web/dao/TrafficReportDao.java new file mode 100644 index 0000000..2e62d79 --- /dev/null +++ b/src/main/java/com/nis/web/dao/TrafficReportDao.java @@ -0,0 +1,79 @@ +package com.nis.web.dao; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.ibatis.annotations.Param; + +import com.nis.domain.restful.NtcAttrTypeReport; +import com.nis.domain.restful.NtcDestipCountryReport; +import com.nis.domain.restful.NtcEntranceReport; +import com.nis.domain.restful.NtcIpRangeReport; +import com.nis.domain.restful.NtcLwhhReport; +import com.nis.domain.restful.NtcPzReport; +import com.nis.domain.restful.NtcRadiusReport; +import com.nis.domain.restful.NtcServiceReport; +import com.nis.domain.restful.NtcSrcipDomesticReport; +import com.nis.domain.restful.NtcTagReport; +import com.nis.domain.restful.NtcURLIpReport; +import com.nis.domain.restful.dashboard.NtcTotalReport; +import com.nis.domain.restful.dashboard.TrafficTransStatistic; + +/** + * + * @ClassName:NtcReportDao + * @Description:TODO(这里用一句话描述这个类的作用) + * @author (zdx) + * @date 2018年7月11日 下午5:47:55 + * @version V1.0 + */ +@MyBatisDao +public interface TrafficReportDao extends CrudDao { + List findNtcPzReport(NtcPzReport pz); + + List findNtcServiceReport(NtcServiceReport pz); + + List findNtcTagReport(NtcTagReport pz); + + List findNtcAttrTypeReport(NtcAttrTypeReport pz); + + List findNtcLwhhReport(NtcLwhhReport pz); + + List findNtcSrcipDomesticReport(NtcSrcipDomesticReport pz); + + List findNtcDestipCountryReport(NtcDestipCountryReport pz); + + List findNtcEntranceReport(NtcEntranceReport pz); + + List findNtcIpURLReport(NtcURLIpReport pz); + + List findAccounList(NtcRadiusReport pz); + + List findNasIpList(NtcRadiusReport pz); + + List findNtcRadiusReport(NtcRadiusReport pz); + + List findNtcIpRangeReport(NtcIpRangeReport pz); + + void insertNtcIpRangeBatch(List list); + + void truncateNtcIpRange(); + + + + + + + + NtcTotalReport getMaxReportTime(); + Map getMaxStatTime(); + List getTotalReportList(@Param("reportTime") Date reportTime); + List getNetFlowPortInfoNew(@Param("statTime") Date statTime); + List getBandwidthTrans(@Param("entranceId") Integer entranceId,@Param("beginDate") String beginDate,@Param("endDate") String endDate,@Param("addrType") String addrType,@Param("transType") Integer transType); + List getBandwidthTrans2(@Param("beginDate") String beginDate,@Param("endDate") String endDate); + Map getEntranceMaxReportTime(); + List getActionTrans(@Param("beginDate") String beginDate,@Param("endDate") String endDate ,@Param("entranceId") Integer entranceId,@Param("serviceSql") String serviceSql); + + +} diff --git a/src/main/java/com/nis/web/dao/TrafficReportDao.xml b/src/main/java/com/nis/web/dao/TrafficReportDao.xml new file mode 100644 index 0000000..b213b69 --- /dev/null +++ b/src/main/java/com/nis/web/dao/TrafficReportDao.xml @@ -0,0 +1,995 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SERVICE,SUM,REPORT_TIME + + + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO traffic_ip_identify + (ip_start,ip_end,ip_start_num,ip_end_num,ip_sub,area_type,country) + VALUES + + (#{ipRange.ipStart}, #{ipRange.ipEnd}, + #{ipRange.ipStartNum}, + #{ipRange.ipEndNum}, + #{ipRange.ipSub}, #{ipRange.areaType}, + #{ipRange.country}) + + + + + truncate table traffic_ip_identify + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java index 1af7b06..9ef7063 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java @@ -23,6 +23,7 @@ import com.nis.domain.restful.MaatConfig; import com.nis.restful.RestBusinessCode; import com.nis.restful.ServiceRuntimeException; import com.nis.util.Configurations; +import com.nis.util.Constants; import com.nis.util.ExceptionUtil; import com.nis.util.File2Redis; import com.nis.util.JedisUtils; @@ -38,7 +39,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException; @Service() public class ConfigJedisServiceimpl implements ConfigRedisService { private static Logger logger = LoggerFactory.getLogger(ConfigJedisServiceimpl.class); - private static final int TAPREDISDB = Configurations.getIntProperty("tapRedisDb", 5); + // 用于在实时统计配置后面添加时间,方便读取入库时间 private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); @@ -459,10 +460,10 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { for (MaatConfig maatConfig : maatConfigList) { int service = maatConfig.getService(); if (ServiceAndRDBIndexReal.isAddASU(service)) { - if (!keySet.contains(TAPREDISDB)) { + if (!keySet.contains(Constants.TAPREDISDB)) { throw new ServiceRuntimeException( - "业务类型:" + service + ",需要向阀门" + TAPREDISDB + "号库分发,但是当前只往" + keySet - + "库下发,请检查阀门编号或者当前业务对应的配置文件是否正确", + "业务类型:" + service + ",需要向阀门" + Constants.TAPREDISDB + "号库分发,但是当前只往" + + keySet + "库下发,请检查阀门编号或者当前业务对应的配置文件是否正确", RestBusinessCode.PropertiesIsError.getValue()); } } @@ -624,8 +625,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { valStr = valStr.trim().replace("[", "").replace("]", ""); String val = map.get(valStr); if (val != null) { - if (TAPREDISDB == redisDBIndex && type != 10 && type != 11 - && valStr.toLowerCase().equals("op_time")) {// 域配置并且是op_time时在op_time前面添加如下内容 + if ((Constants.TAPREDISDB == redisDBIndex || Constants.WEBFOCUSREDISDB == redisDBIndex) + && type != 10 && type != 11 && valStr.toLowerCase().equals("op_time")) {// 域配置并且是op_time时在op_time前面添加如下内容 Map map2 = ServiceAndRDBIndexReal.getMaatToValveMap() .get(service); if (map2 != null && map2.size() > 0) { @@ -894,10 +895,19 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { return false; } - private Map> getCompileIdAndDBReal(List idList, int service, int idRelaRedisDBIndex) { + /** + * 根据配置id从关联关系db中获取各个配置实际所在的db + * + * @param idList + * @param service + * @param idRelaRedisDBIndex + * @return + */ + private Map> getCompileIdAndDBReal(List idList, int service, int idRelaRedisDBIndex) { // 记录所有需要删除的配置信息key是相同的redisdb,value是需要删除的id集合 - Map> idAndDBMap = new HashMap>(); + Map> idAndDBMap = new HashMap>(); for (Long configId : idList) { +// if(JedisUtils.exists("COMPILEGROUP:" + configId, idRelaRedisDBIndex)){ String compileValStr = JedisUtils.get("COMPILEGROUP:" + configId, idRelaRedisDBIndex); if (compileValStr != null && !compileValStr.trim().equals("")) { String[] keyAndDBArr = @@ -914,7 +924,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { if (idAndDBMap.containsKey(redisDb)) { idAndDBMap.get(redisDb).add(configId); } else { - List list = new ArrayList(); + Set list = new HashSet(); list.add(configId); idAndDBMap.put(redisDb, list); } @@ -931,12 +941,79 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { + ",对应的redisdb信息,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常", RestBusinessCode.KeyNotExistsInRedis.getValue()); } - +// } } return idAndDBMap; } + /** + * 根据编译id,组id,域id + */ + public void delByCompileGroupRegionId() { + Jedis resource = JedisUtils.getResource(0); + double version = 3901d; + Transaction transaction = resource.multi(); + transaction.select(2); + for (long i = 3143; i <= 13142; i++) { + String key = "EFFECTIVE_RULE:NTC_COMPILE," + i; + String a = "OBSOLETE_RULE:NTC_COMPILE," + i; + transaction.rename(key, a); + + transaction.zadd("MAAT_RULE_TIMER", version, a); + transaction.zadd("MAAT_UPDATE_STATUS", version, "DEL,NTC_COMPILE," + i); + Long nowTime = new Date().getTime(); + nowTime = nowTime / 1000l; + Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒 + transaction.zadd("MAAT_VERSION_TIMER", score, version + ""); + } + for (long i = 5312; i <= 15311; i++) { + String key = "EFFECTIVE_RULE:NTC_IP," + i; + String a = "OBSOLETE_RULE:NTC_IP," + i; + transaction.rename(key, a); + + transaction.zadd("MAAT_RULE_TIMER", version, a); + transaction.zadd("MAAT_UPDATE_STATUS", version, "DEL,NTC_IP," + i); + Long nowTime = new Date().getTime(); + nowTime = nowTime / 1000l; + Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒 + transaction.zadd("MAAT_VERSION_TIMER", score, version + ""); + } + int b = 0; + for (long i = 3898; i <= 13897; i++) { + int id = 3143 + b; + String groupId = i + "" + id; + String key = "EFFECTIVE_RULE:NTC_GROUP," + groupId; + String c = "OBSOLETE_RULE:NTC_GROUP," + groupId; + transaction.rename(key, c); + b++; + transaction.zadd("MAAT_RULE_TIMER", version, c); + transaction.zadd("MAAT_UPDATE_STATUS", version, "DEL,NTC_GROUP," + groupId); + Long nowTime = new Date().getTime(); + nowTime = nowTime / 1000l; + Double score = nowTime.doubleValue();// 使用redis自带的time,得到当前时间的秒 + transaction.zadd("MAAT_VERSION_TIMER", score, version + ""); + + } + + transaction.set("MAAT_VERSION", "3901"); + transaction.exec(); + + } + + /** + * 根据配置id删除数据 + */ + public void delByCompileId() { + Map> serviceConfigMap = new HashMap>(); + List list = new ArrayList<>(); + for (long i = 13143; i <= 23142; i++) { + list.add(i); + } + serviceConfigMap.put(129, list); + delMaatConfig(serviceConfigMap); + } + @Override public boolean delMaatConfig(Map> serviceConfigMap) { if (serviceConfigMap != null && serviceConfigMap.size() > 0) { @@ -946,14 +1023,14 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); if (serviceConfigMap != null && serviceConfigMap.size() > 0) { for (Integer service : serviceConfigMap.keySet()) { - Map> compileIdAndDBReal = getCompileIdAndDBReal( + Map> compileIdAndDBReal = getCompileIdAndDBReal( serviceConfigMap.get(service), service, idRelaRedisDBIndex); for (Integer redisDb : compileIdAndDBReal.keySet()) { String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb); if (maatVersionStr != null) { Double maatVersion = Double.valueOf(maatVersionStr) + 1D; MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); - List list = compileIdAndDBReal.get(redisDb); + Set list = compileIdAndDBReal.get(redisDb); if (list != null && list.size() > 0) { for (Long id : list) { // 按序号选择Redis数据库 @@ -979,8 +1056,83 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { throw new ServiceRuntimeException("删除maat类配置时,未发现对应的配置信息,请检查配置参数是否正确", RestBusinessCode.ConfigSourceIsNull.getValue()); } - if (removeMaatRelation(serviceConfigMap, transaction) - && removeStatisticsReal(serviceConfigMap, transaction)) { + if (removeMaatRelation(serviceConfigMap, transaction, null) + && removeStatisticsReal(serviceConfigMap, transaction, null)) { + transaction.exec(); + return true; + } else { + transaction.discard(); + } + + } catch (JedisConnectionException e) { + String error = "连接redis异常,删除maat配置失败," + e.getMessage(); + logger.error(error + " " + ExceptionUtil.getExceptionMsg(e)); + throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue()); + + } catch (Exception e) { + + int businessCode = RestBusinessCode.service_runtime_error.getValue(); + if (e instanceof ServiceRuntimeException) { + businessCode = ((ServiceRuntimeException) e).getErrorCode(); + } + logger.error("删除maat配置发生了异常" + ExceptionUtil.getExceptionMsg(e)); + transaction.discard(); + throw new ServiceRuntimeException("删除maat配置发生了异常," + e.getMessage(), businessCode); + } finally { + // 释放连接到连接池 + JedisUtils.returnResource(resource); + } + } else + + { + throw new ServiceRuntimeException("Map参数信息不能为空,请检查!", RestBusinessCode.ConfigInfoMapIsNull.getValue()); + } + return false; + } + + public boolean startStopMaatConfig(Map> serviceConfigMap, boolean isStart) { + if (serviceConfigMap != null && serviceConfigMap.size() > 0) { + Jedis resource = JedisUtils.getResource(0); + Transaction transaction = resource.multi(); + try { + int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); + if (serviceConfigMap != null && serviceConfigMap.size() > 0) { + for (Integer service : serviceConfigMap.keySet()) { + Map> compileIdAndDBReal = getCompileIdAndDBReal( + serviceConfigMap.get(service), service, idRelaRedisDBIndex); + for (Integer redisDb : compileIdAndDBReal.keySet()) { + String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb); + if (maatVersionStr != null) { + Double maatVersion = Double.valueOf(maatVersionStr) + 1D; + MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); + Set list = compileIdAndDBReal.get(redisDb); + if (list != null && list.size() > 0) { + for (Long id : list) { + // 按序号选择Redis数据库 + transaction.select(redisDb); + startStopConfig(id, maatXmlConfig, maatVersion, service, transaction, redisDb, + idRelaRedisDBIndex, isStart); + } + } else { + throw new ServiceRuntimeException("删除配置时,未发现对应的配置id信息,请检查配置参数是否正确", + RestBusinessCode.ConfigSourceIsNull.getValue()); + } + transaction.incrBy("MAAT_VERSION", 1l); + logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb, + Integer.valueOf(maatVersionStr) + 1); + } else { + throw new ServiceRuntimeException("从" + redisDb + + "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常", + RestBusinessCode.GetMaatVersionFailure.getValue()); + } + } + } + } else { + throw new ServiceRuntimeException("删除maat类配置时,未发现对应的配置信息,请检查配置参数是否正确", + RestBusinessCode.ConfigSourceIsNull.getValue()); + } + if (removeMaatRelation(serviceConfigMap, transaction, isStart) + && removeStatisticsReal(serviceConfigMap, transaction, isStart)) { transaction.exec(); return true; } else { @@ -1044,7 +1196,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { // 删除(重命名)编译配置 removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion, service, transaction, redisDBIndex, - null);// 10代表是编译配置 + null, null);// 10代表是编译配置 // 拼接编译与分组关系的Redis Key String compileStr = "COMPILEGROUP:" + id; // 获取当前编译配置与分组配置的关联关系 @@ -1102,7 +1254,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { // 根据分组与域关联关系找到对应域配置然后删除(重命名) removeRegionConfig(maatXmlConfig, regionKeyArr, maatVersion, service, - transaction, redisDBIndex); + transaction, redisDBIndex, null); } } else { throw new ServiceRuntimeException("从" @@ -1120,7 +1272,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { // 根据分组与编译关联关系找到对应分组配置然后删除(重命名) removeCompileAndGroupConfig(maatXmlConfig, groupId.replace("GROUPCOMPILE:", ""), 11, maatVersion, service, - transaction, redisDBIndex, id + "");// 11代表是分组配置 + transaction, redisDBIndex, id + "", null);// 11代表是分组配置 } else { throw new ServiceRuntimeException( @@ -1149,6 +1301,115 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } } + private void startStopConfig(Long id, MaatXmlConfig maatXmlConfig, Double maatVersion, int service, + Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex, boolean isStart) { + if (maatXmlConfig != null) { + Map keyMap = new HashMap<>(); + // 删除(重命名)编译配置 + removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion, service, transaction, redisDBIndex, + null, isStart);// 10代表是编译配置 + // 拼接编译与分组关系的Redis Key + String compileStr = "COMPILEGROUP:" + id; + // 获取当前编译配置与分组配置的关联关系 + String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系 + if (compileStrVal != null && !compileStrVal.trim().equals("")) { + String[] compileGroupStrArr = org.apache.commons.lang.StringUtils.split(compileStrVal, ";"); + for (String compileGroup : compileGroupStrArr) { + if (compileGroup != null && !compileGroup.trim().equals("")) { + String groupCompileStrs = getRegionInfo(compileGroup);// 获取编译对应的分组信息,去除后面的redisdb信息 + if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) {// 遍历编译和分组的信息 + String[] split = org.apache.commons.lang.StringUtils.split(groupCompileStrs, ";"); + + for (String groupId : split) {// GROUPCOMPILE:groupid-redisdb + if (groupId != null && !groupId.trim().equals("")) { + String groupCompileAndDBStrs = null; + if (!keyMap.containsKey(groupId)) { + groupCompileAndDBStrs = JedisUtils.get(groupId, idRelaRedisDBIndex); + keyMap.put(groupId, groupCompileAndDBStrs); + } else { + groupCompileAndDBStrs = keyMap.get(groupId); + } + + String[] compileGroupArr = org.apache.commons.lang.StringUtils + .split(groupCompileAndDBStrs, ";");// 获取组对应的编译id + + for (String groupAndCompileStr : compileGroupArr) { + if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) { + String compileId = getRegionInfo(groupAndCompileStr); + if (compileId != null && !compileId.trim().equals("")) { + // 被分组复用的业务,不能将域置为失效 + if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效 + // 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效 + if (compileId.equals(compileStr)) {// + String groupRegionKey = groupId.replace("GROUPCOMPILE", + "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION + String regionStrs = null; + if (!keyMap.containsKey(groupRegionKey)) { + regionStrs = JedisUtils.get(groupRegionKey, + idRelaRedisDBIndex); + keyMap.put(groupRegionKey, regionStrs); + } else { + regionStrs = keyMap.get(groupRegionKey); + } + if (regionStrs != null && !regionStrs.trim().equals("")) { + String[] regionStrArr = regionStrs.split(";"); + for (String str : regionStrArr) { + if (str != null && !str.trim().equals("")) { + + String regionStr = getRegionInfo(str); + if (regionStr != null + && !regionStr.trim().equals("")) { + String[] regionKeyArr = regionStr.split(";"); + if (regionKeyArr != null + && regionKeyArr.length > 0) { + // 根据分组与域关联关系找到对应域配置然后删除(重命名) + removeRegionConfig(maatXmlConfig, + regionKeyArr, maatVersion, service, + transaction, redisDBIndex, isStart); + } + } else { + throw new ServiceRuntimeException("从" + + idRelaRedisDBIndex + + "号redis库中无法获取MAAT配置分组与域的关联关系,key为" + + groupRegionKey, + RestBusinessCode.KeyNotExistsInRedis + .getValue()); + } + } + } + } + } + } + // 根据分组与编译关联关系找到对应分组配置然后删除(重命名) + removeCompileAndGroupConfig(maatXmlConfig, + groupId.replace("GROUPCOMPILE:", ""), 11, maatVersion, service, + transaction, redisDBIndex, id + "", isStart);// 11代表是分组配置 + + } else { + throw new ServiceRuntimeException( + "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为" + + groupId, + RestBusinessCode.KeyNotExistsInRedis.getValue()); + } + } + } + } + } + } else { + throw new ServiceRuntimeException( + "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系,key为" + compileStr, + RestBusinessCode.KeyNotExistsInRedis.getValue()); + } + } + } + } + } else { + throw new ServiceRuntimeException( + "无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确", + RestBusinessCode.NotFoundRedisRule.getValue()); + } + } + /** * 删除maat配置时,对redis进行相关操作,主要是重命名key和记录相关状态 * @@ -1160,7 +1421,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { * @param redisTemplate */ private void removeCompileAndGroupConfig(MaatXmlConfig maatXmlConfig, String id, int type, Double maatVersion, - int service, Transaction transaction, int redisDBIndex, String compileId) { + int service, Transaction transaction, int redisDBIndex, String compileId, Boolean isStart) { if (maatXmlConfig != null) { List expressionList = maatXmlConfig.getExpressionList(); String maatKey = null; @@ -1194,14 +1455,29 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { if (compileId != null) { oldKey += compileId; } - maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + if (isStart == null) {// 置为失效 + maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + } else if (isStart == true) {// 将失效置为生效 + maatKey = oldKey; + oldKey=oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + } else {// 将生效变为失效 + maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + } + transaction.rename(oldKey, maatKey.toUpperCase()); logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase()); break; } } - updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true); + + if (isStart == null) { + updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);// 变成无效 + } else if (isStart) { + updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, false);// 变成有效 + } else { + updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);// 变成无效 + } } else { throw new ServiceRuntimeException( "无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确", @@ -1220,17 +1496,29 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { * @param redisDBIndex */ private void removeRegionConfig(MaatXmlConfig maatXmlConfig, String[] regionArr, Double maatVersion, int service, - Transaction transaction, int redisDBIndex) { + Transaction transaction, int redisDBIndex, Boolean isStart) { transaction.select(redisDBIndex); if (maatXmlConfig != null && regionArr != null && regionArr.length > 0) { List expressionList = maatXmlConfig.getExpressionList(); String maatKey = null; for (String oldKey : regionArr) { if (oldKey != null && !oldKey.trim().equals("")) { - maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + if (isStart == null) {// 置为失效 + maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + } else if (isStart == true) {// 将失效置为生效 + maatKey = oldKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"); + } else {// 将生效变为失效 + maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + } transaction.rename(oldKey, maatKey.toUpperCase()); logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是{}", redisDBIndex, oldKey, maatKey.toUpperCase()); - updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true); + if (isStart == null) { + updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true);// 变成无效 + } else if (isStart) { + updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, false);// 变成有效 + } else { + updateMaatInfo(expressionList, maatKey, transaction, maatVersion, redisDBIndex, true); + } } } } else { @@ -1246,7 +1534,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { /** * 编译配置用于实时统计 取消分类性质,标签等信息 */ - private boolean removeStatisticsReal(Map> map, Transaction transaction) { + private boolean removeStatisticsReal(Map> map, Transaction transaction, Boolean isStart) { if (map != null && map.size() > 0) { int redisStatisticsRealDBIndex = Configurations.getIntProperty("redisStatisticsRealDBIndex", 14); transaction.select(redisStatisticsRealDBIndex); @@ -1269,8 +1557,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是:{}", redisStatisticsRealDBIndex, effectiveRuleKey.toUpperCase(), effectiveRuleKey.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE")); - String zset = effectiveRuleKey.replace("EFFECTIVE_RULE:", "DEL,"); + if (isStart == null || isStart == false) { + } else if (isStart == true) { + zset = effectiveRuleKey.replace("EFFECTIVE_RULE:", "ADD,"); + } transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset); logger.info("向{}号redis数据库更新了MAAT_UPDATE_STATUS,内容是{},SCORES是{}", redisStatisticsRealDBIndex, zset.toUpperCase(), maatVersion); @@ -1302,7 +1593,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { * * @param idMap */ - private boolean removeMaatRelation(Map> map, Transaction transaction) { + private boolean removeMaatRelation(Map> map, Transaction transaction, Boolean isStart) { if (map != null && map.size() > 0) { int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); transaction.select(idRelaRedisDBIndex); @@ -1352,7 +1643,22 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { try { // 为了提高效率,不判断了,如果报错直接捕捉异常处理 // 删除分组与域的关联关系 - transaction.del(groupRegion); + if (isStart == null) {// 删除 + transaction.del(groupRegion); + } else if (isStart == true) {// 将失效置为生效 + String groupRegionVal = JedisUtils.get(groupRegion, + idRelaRedisDBIndex); + groupRegionVal = groupRegionVal + .replace("OBSOLETE_RULE", "EFFECTIVE_RULE"); + transaction.set(groupRegion, groupRegionVal); + } else {// 将生效变为失效 + String groupRegionVal = JedisUtils.get(groupRegion, + idRelaRedisDBIndex); + groupRegionVal = groupRegionVal + .replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + transaction.set(groupRegion, groupRegionVal); + } + } catch (Exception e) { throw new ServiceRuntimeException("从" + idRelaRedisDBIndex + "号redis库中删除" @@ -1383,7 +1689,26 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { try { // 为了提高效率,不判断了,如果报错直接捕捉异常处理 // 删除当前组所对应的编译 - transaction.del(groupCompile.toUpperCase()); + + if (isStart == null) {// 删除 + transaction.del(groupCompile.toUpperCase());// 删除编译与分组的关联关系 + } else if (isStart == true) {// 将失效置为生效 + String groupRegionVal = JedisUtils.get( + groupCompile.toUpperCase(), + idRelaRedisDBIndex); + groupRegionVal = groupRegionVal.replace( + "OBSOLETE_RULE", "EFFECTIVE_RULE"); + transaction.set(groupCompile.toUpperCase(), + groupRegionVal); + } else {// 将生效变为失效 + String groupRegionVal = JedisUtils.get( + groupCompile.toUpperCase(), + idRelaRedisDBIndex); + groupRegionVal = groupRegionVal.replace( + "EFFECTIVE_RULE", "OBSOLETE_RULE"); + transaction.set(groupCompile.toUpperCase(), + groupRegionVal); + } } catch (Exception e) { throw new ServiceRuntimeException("从" + idRelaRedisDBIndex + "号redis库中删除" @@ -1423,7 +1748,21 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } try { - transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系 + if (isStart == null) {// 删除 + transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系 + } else if (isStart == true) {// 将失效置为生效 + String groupRegionVal = JedisUtils.get(compileStr.toUpperCase(), + idRelaRedisDBIndex); + groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE", + "EFFECTIVE_RULE"); + transaction.set(compileStr.toUpperCase(), groupRegionVal); + } else {// 将生效变为失效 + String groupRegionVal = JedisUtils.get(compileStr.toUpperCase(), + idRelaRedisDBIndex); + groupRegionVal = groupRegionVal.replace("EFFECTIVE_RULE", + "OBSOLETE_RULE"); + transaction.set(compileStr.toUpperCase(), groupRegionVal); + } } catch (Exception e) { throw new ServiceRuntimeException( "从" + idRelaRedisDBIndex + "号redis关联关系库中删除" + compileStr @@ -1950,13 +2289,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } private void updateMaatInfo(List list, String maatKey, Transaction transaction, Double maatVersion, - int redisDBIndex, boolean idDel) { + int redisDBIndex, Boolean idDel) { if (list != null && list.size() > 0) { for (MaatXmlExpr maatXmlExpr : list) { if (maatXmlExpr.getKeyExpression().toUpperCase().equals("MAAT_UPDATE_STATUS")) { if (maatKey != null) { String zset = null; - if (idDel) { + if (idDel == null || idDel) { zset = maatKey.replace("OBSOLETE_RULE:", "DEL,"); } else { zset = maatKey.replace("EFFECTIVE_RULE:", "ADD,"); diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java index 3427baf..7f7ec3e 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java @@ -79,6 +79,14 @@ public interface ConfigRedisService { * @return 成功返回true,失败返回false或抛出异常 */ public boolean delMaatConfig(Map> serviceConfigMap); + /** + * 停启用maat类配置,key是业务类型,value是配置id集合 + * + * @param serviceConfigMap + * @param isStart 是否置位生效, + * @return 成功返回true,失败返回false或抛出异常 + */ + public boolean startStopMaatConfig(Map> serviceConfigMap, boolean isStart); /** * 删除分组复用的域配置 diff --git a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java index 306ef59..1c6357d 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -22,6 +22,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.nis.domain.restful.CommonSourceFieldCfg; import com.nis.domain.restful.ConfigCompile; +import com.nis.domain.restful.ConfigCompileStartStop; import com.nis.domain.restful.ConfigGroupRelation; import com.nis.domain.restful.DigestRegion; import com.nis.domain.restful.GroupReuse; @@ -123,7 +124,7 @@ public class ConfigSourcesService extends BaseService { StringBuffer sb) throws Exception { Map> maatMap = new HashMap>(); Map> configMap = new HashMap>(); - + for (ConfigCompile configCompile : configCompileList) { Integer service = Integer.valueOf(configCompile.getService().toString()); MaatConfig maatConfig = new MaatConfig(); @@ -225,54 +226,17 @@ public class ConfigSourcesService extends BaseService { List dbIndexList = ServiceAndRDBIndexReal.getRedisDBByService(service); if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { for (Integer dbIndex : dbIndexList) { + // 分发到阀门有些业务需要添加编译属性到域配置 List newMaatConfigList = new ArrayList(); newMaatConfigList.addAll(maatMap.get(service)); - if (dbIndex.intValue() == ServiceAndRDBIndexReal.getValveDBIndex().intValue()) { + if (dbIndex.intValue() == Constants.TAPREDISDB) { Map> maatToValueMap = ServiceAndRDBIndexReal.getMaatToValveMap(); - if (maatToValueMap.containsKey(service)) { - - Map regionAndFiledMap = maatToValueMap.get(service); - for (int i = 0; i < newMaatConfigList.size(); i++) { - MaatConfig maatConfig = newMaatConfigList.get(i); - MaatConfig newMaatConfig = (MaatConfig) JsonMapper - .fromJsonString(JsonMapper.toJsonString(maatConfig), MaatConfig.class); - Iterator iterator = regionAndFiledMap.keySet().iterator(); - while (iterator.hasNext()) { - String regionName = iterator.next().toString(); - PropertyDescriptor pd; - try { - pd = new PropertyDescriptor(regionName + "MapList", MaatConfig.class); - Method method = pd.getReadMethod(); - Object object = method.invoke(newMaatConfig); - - if (object != null) { - - List> listMaps = new ArrayList>(); - listMaps.addAll((List>) object); - String[] fields = regionAndFiledMap.get(regionName); - for (String fieldName : fields) { - String value = newMaatConfig.getCompileMap() - .get(fieldName.toLowerCase()); - if (!StringUtil.isEmpty(value)) { - for (Map map : listMaps) { - map.put(fieldName.toLowerCase(), value); - } - } - } - method = pd.getWriteMethod(); - method.invoke(newMaatConfig, listMaps); - } - newMaatConfigList.set(i, newMaatConfig); - } catch (Exception e) { - // TODO Auto-generated catch block - throw new RestServiceException("未找到域列表,请检查配置文件中域类型是否正确!:" + e.getMessage(), - RestBusinessCode.service_runtime_error.getValue()); - } - - } - } - } + addFieldToValveOrWebFocus(service, newMaatConfigList, maatToValueMap, false); + } else if (dbIndex.intValue() == Constants.WEBFOCUSREDISDB) { + Map> maatToWebFocusMap = ServiceAndRDBIndexReal + .getMaatToWebFocusMap(); + addFieldToValveOrWebFocus(service, newMaatConfigList, maatToWebFocusMap, true); } if (configMap.containsKey(dbIndex)) { @@ -293,6 +257,61 @@ public class ConfigSourcesService extends BaseService { configRedisService.saveMaatConfig(configMap); } + /** + * 添加额外属性到阀门或者webfocus + * + * @param maatToValueMap + */ + private void addFieldToValveOrWebFocus(Integer service, List newMaatConfigList, + Map> maatToValueMap, Boolean isWebFocus) { + + if (maatToValueMap.containsKey(service)) { + + Map regionAndFiledMap = maatToValueMap.get(service); + for (int i = 0; i < newMaatConfigList.size(); i++) { + MaatConfig maatConfig = newMaatConfigList.get(i); + if (isWebFocus && maatConfig.getGroupMapList().size() > 1) {// 如果当前配置需要向webfocus中入,但是groupsize大于1,此时就不入了,只有groupsize=1的时候入 + continue; + } + MaatConfig newMaatConfig = (MaatConfig) JsonMapper.fromJsonString(JsonMapper.toJsonString(maatConfig), + MaatConfig.class); + Iterator iterator = regionAndFiledMap.keySet().iterator(); + while (iterator.hasNext()) { + String regionName = iterator.next().toString(); + PropertyDescriptor pd; + try { + pd = new PropertyDescriptor(regionName + "MapList", MaatConfig.class); + Method method = pd.getReadMethod(); + Object object = method.invoke(newMaatConfig); + + if (object != null) { + + List> listMaps = new ArrayList>(); + listMaps.addAll((List>) object); + String[] fields = regionAndFiledMap.get(regionName); + for (String fieldName : fields) { + String value = newMaatConfig.getCompileMap().get(fieldName.toLowerCase()); + if (!StringUtil.isEmpty(value)) { + for (Map map : listMaps) { + map.put(fieldName.toLowerCase(), value); + } + } + } + method = pd.getWriteMethod(); + method.invoke(newMaatConfig, listMaps); + } + newMaatConfigList.set(i, newMaatConfig); + } catch (Exception e) { + // TODO Auto-generated catch block + throw new RestServiceException("未找到域列表,请检查配置文件中域类型是否正确!:" + e.getMessage(), + RestBusinessCode.service_runtime_error.getValue()); + } + + } + } + } + } + private Map convertObjectToMap(Object obj, Class clazz) throws Exception { Map dstMap = new HashMap(); Field[] fields = obj.getClass().getDeclaredFields(); @@ -318,15 +337,18 @@ public class ConfigSourcesService extends BaseService { } public void updateConfigSources(AuditLogThread thread, long start, List compileList, Date opTime, - StringBuffer sb) throws Exception { + StringBuffer sb, boolean isConfigStartStop) throws Exception { + // 所有状态更新的配置isValid的值必须相同 + Map validIdMap = new HashMap(); + Map> compileMap = new HashMap>(); if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { - checkCompileOptForUpdate(config); + checkCompileOptForUpdate(config, isConfigStartStop); + validIdMap.put(config.getIsValid().toString(), config.getIsValid().toString()); if (config.getOpTime() == null) { config.setOpTime(opTime); } - // compileAllList.add(config); if (compileMap.containsKey(config.getService())) { compileMap.get(config.getService()).add(config.getCompileId()); @@ -340,34 +362,29 @@ public class ConfigSourcesService extends BaseService { } else { throw new RestServiceException("编译配置不能为空" + sb.toString(), RestBusinessCode.CompileIsNull.getValue()); } - // Map> - // Map>> restMap = new HashMap>>(); - // Iterator serviceIterator = compileMap.keySet().iterator(); - // while (serviceIterator.hasNext()) { - // Integer service = Integer.valueOf(serviceIterator.next().toString()); - // List dbIndexList = - // ServiceAndRDBIndexReal.getRedisDBByService(service); - // if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { - // for (Integer dbIndex : dbIndexList) { - // if (restMap.containsKey(dbIndex)) { - // restMap.get(dbIndex).put(service, compileMap.get(service)); - // } else { - // Map> map = new HashMap>(); - // map.put(service, compileMap.get(service)); - // restMap.put(dbIndex, map); - // } - // } - // } else { - // ServiceRuntimeException e = new ServiceRuntimeException("service值为" + service - // + ",与写入数据库序号映射关系不存在", - // RestBusinessCode.ServiceNoFoundDBIndex.getValue()); - // } - // } - // 所有的都删除成功返回true - if (!configRedisService.delMaatConfig(compileMap)) { - throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员", - RestBusinessCode.service_runtime_error.getValue()); + + if (validIdMap.size() > 1) { + throw new RestServiceException(RestBusinessCode.IsValidNonUniq.getErrorReason(), + RestBusinessCode.IsValidNonUniq.getValue()); + } + + if (!isConfigStartStop) { + // 所有的都删除成功返回true + if (!configRedisService.delMaatConfig(compileMap)) { + throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员", + RestBusinessCode.service_runtime_error.getValue()); + } + } else { + boolean isStart = true;// 置为生效 + Integer isValid = compileList.get(0).getIsValid(); + if (isValid == 0) { + isStart = false;// 置为失效 + } + if (!configRedisService.startStopMaatConfig(compileMap, isStart)) { + throw new ServiceRuntimeException("停启用MAAT配置时出现异常,具体原因不详,请联系管理员", + RestBusinessCode.service_runtime_error.getValue()); + } + } } @@ -384,7 +401,7 @@ public class ConfigSourcesService extends BaseService { * @param config * @return */ - private void checkCompileOptForUpdate(ConfigCompile config) throws Exception { + private void checkCompileOptForUpdate(ConfigCompile config, boolean isConfigStartStop) throws Exception { if (StringUtil.isEmpty(config.getCompileId())) { throw new RestServiceException(RestBusinessCode.CompileIdIsNull.getErrorReason(), @@ -398,9 +415,12 @@ public class ConfigSourcesService extends BaseService { throw new RestServiceException("编译配置id为" + config.getCompileId() + "的IsValid字段不能为空", RestBusinessCode.IsValidIsNull.getValue()); } - if (config.getIsValid() != 0) { - throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效", - RestBusinessCode.IsValidIsF.getValue()); + + if (!isConfigStartStop) { + if (config.getIsValid() != 0) { + throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效", + RestBusinessCode.IsValidIsF.getValue()); + } } } @@ -413,8 +433,8 @@ public class ConfigSourcesService extends BaseService { throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(), RestBusinessCode.CBParamFormateError.getValue()); } - if (jsonObjectList!=null&&jsonObjectList.size()>Constants.MAX_LIST_SIZE) { - thread.setContent("批量提交数量超过"+Constants.MAX_LIST_SIZE+"条,不记录请求内容"); + if (jsonObjectList != null && jsonObjectList.size() > Constants.MAX_LIST_SIZE) { + thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容"); } Map>> dstMaps = new HashMap>>(); for (int i = 0; i < jsonObjectList.size(); i++) { @@ -486,7 +506,7 @@ public class ConfigSourcesService extends BaseService { maatTableName.substring(maatTableName.lastIndexOf("_") + 1)); dstStr = dstPath.replace("{fileName}", dstStr.substring(dstStr.lastIndexOf("/") + 1)); } else if ("file_id".equals(commonSourceFieldCfg.getDstName())) { - //dstStr = dstStr.substring(dstStr.indexOf("group")); + // dstStr = dstStr.substring(dstStr.indexOf("group")); } } switch (commonSourceFieldCfg.getFieldType()) { @@ -635,8 +655,8 @@ public class ConfigSourcesService extends BaseService { throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(), RestBusinessCode.CBParamFormateError.getValue()); } - if (jsonObjectList!=null&&jsonObjectList.size()>Constants.MAX_LIST_SIZE) { - thread.setContent("批量提交数量超过"+Constants.MAX_LIST_SIZE+"条,不记录请求内容"); + if (jsonObjectList != null && jsonObjectList.size() > Constants.MAX_LIST_SIZE) { + thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容"); } // Map> cfgMap = new HashMap>(); @@ -869,12 +889,11 @@ public class ConfigSourcesService extends BaseService { } else { maatConfig.getIpRegionMapList().addAll(dstMapList); } - - //maatConfig.setService(groupReuse.getService()); + + // maatConfig.setService(groupReuse.getService()); list.add(maatConfig); } - - + // 调用接口入redis logger.info("---------------调用Redis 分组复用配置新增接口---------------------"); configRedisService.saveGroupReuseConfig(list); @@ -942,9 +961,9 @@ public class ConfigSourcesService extends BaseService { } } logger.info("调用接口删除Redis中分组复用的域配置接口"); - if (reuseMap!=null&&reuseMap.size()>Constants.MAX_LIST_SIZE) { - thread.setContent("批量提交数量超过"+Constants.MAX_LIST_SIZE+"条,不记录请求内容"); - } + if (reuseMap != null && reuseMap.size() > Constants.MAX_LIST_SIZE) { + thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容"); + } // 所有的都删除成功返回true if (!configRedisService.delGroupReuseConfig(reuseMap)) { // if (!configRedisService.delGroupReuseConfigByPipeline(reuseMap)) { diff --git a/src/main/java/com/nis/web/service/restful/TrafficReportService.java b/src/main/java/com/nis/web/service/restful/TrafficReportService.java new file mode 100644 index 0000000..fe6295a --- /dev/null +++ b/src/main/java/com/nis/web/service/restful/TrafficReportService.java @@ -0,0 +1,228 @@ +package com.nis.web.service.restful; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nis.domain.Page; +import com.nis.domain.restful.NtcRadiusReport; +import com.nis.domain.restful.dashboard.TrafficTransStatistic; +import com.nis.web.dao.TrafficReportDao; +import com.nis.web.dao.dashboard.NtcTotalReportDao; +import com.nis.web.service.BaseLogService; + +@Service +public class TrafficReportService extends BaseLogService { + + @Autowired + protected TrafficReportDao trafficReportDao; + + + public Page findNtcRadiusReport(Page page,NtcRadiusReport entity) throws Exception { + entity.setPage(page); + List resultList = null; + if ("1".equals(entity.getSearchBusinessType())) { + resultList = new ArrayList(); + Map> restMap = new HashMap>(); + List accountList = trafficReportDao.findAccounList(entity); + restMap.put("accountList", accountList); + List nasIpList = trafficReportDao.findNasIpList(entity); + restMap.put("nasIpList", nasIpList); + resultList.add(restMap); + } else { + resultList = new ArrayList(); + List list = trafficReportDao.findNtcRadiusReport(entity); + + String regionName = "nasIp"; + if ("3".equals(entity.getSearchBusinessType())) { + regionName = "account"; + } + PropertyDescriptor pd = new PropertyDescriptor(regionName, NtcRadiusReport.class); + Method method = pd.getReadMethod(); + NtcRadiusReport temp = null; + Object tempVal = null; + for (int i = 0; i < list.size(); i++) { + if (i > 0) { + NtcRadiusReport obj = list.get(i); + Object objVal = method.invoke(obj); + if (objVal != null && tempVal != null && !objVal.toString().equals(tempVal.toString())) { + temp = obj; + tempVal = method.invoke(temp); + resultList.add(obj); + } + } else { + temp = list.get(i); + tempVal = method.invoke(temp); + resultList.add(list.get(i)); + } + } + } + page.setList(resultList); + return page; + + } + + + + + + /** + * 根据ip46,协议tcp,udp查询带宽 + * + * @param addrType + * @param transType + * @return + */ + public List getBandwidthTrans(String addrType, Integer transType, String beginDate, String endDate) { + ArrayList listMap = new ArrayList(); + + HashMap m1 = getBandwidthTransEntrance(addrType, transType, beginDate, endDate, 1); + if (m1 != null && m1.size() > 0) { + m1.put("entranceId", 1);// 局点1.2 不同来源 + listMap.add(m1); + } + return listMap; + + } + + + /** + * 根据ip46,协议tcp,udp查询带宽 + * + * @param addrType + * @param transType + * @return + */ + public List getBandwidthTrans2(String addrType, Integer transType, String beginDate, String endDate) { + ArrayList listMap = new ArrayList(); + + HashMap m2 = getBandwidthTransEntrance(addrType, transType, beginDate, endDate, 2); + if (m2 != null && m2.size() > 0) { + m2.put("entranceId", 2); + listMap.add(m2); + } + return listMap; + + } + + + /** + * 查询单个局点流量的数据信息 + * + * @param addrType + * @param transType + * @param beginDate + * @param endDate + * @param entranceId + * @return + */ + public HashMap getBandwidthTransEntrance(String addrType, Integer transType, String beginDate, String endDate, + Integer entranceId) { + long start = System.currentTimeMillis(); + ArrayList listMap = new ArrayList(); + List bandwidthList = new ArrayList(); + HashMap resulMap = new HashMap(); + bandwidthList = trafficReportDao.getBandwidthTrans(entranceId, beginDate, endDate, addrType, transType); + List timeList = new ArrayList(); + List linkList = new ArrayList(); + List gbpsList = new ArrayList(); + List ppsList = new ArrayList(); + if (bandwidthList != null && bandwidthList.size() > 0) { + Map m = new HashMap(); + int inter = 1000 * 60 * 5;// 间隔时间为五分钟 + // 开始时间,结束时间 时间戳 + Long b = dateToStamp(beginDate); + Long e = dateToStamp(endDate); + int num = 0; + Long pointTime = b; + while (pointTime < e) { + Map rm = new HashMap(); + Long sumL = 0l; + Long sumP = 0l; + Long sumG = 0l; + if (pointTime >= e) { + break; // 停止 + } + for (TrafficTransStatistic tt : bandwidthList) { + // 实际时间 + String time = tt.getTime(); + Long t = dateToStamp(time); + if (t >= pointTime && t < pointTime + inter) { + // 范围之内分到此pointTime组 + sumL = sumL + tt.getLinkNum(); + sumP = sumP + tt.getPps(); + sumG = sumG + tt.getGbps(); + } + } + // 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会 + if (pointTime >= e - inter && sumL > 0) { + linkList.add(sumL); + } + if (pointTime >= e - inter && sumP > 0) { + ppsList.add(sumP); + } + if (pointTime >= e - inter && sumG > 0) { + gbpsList.add(sumG); + } + if (pointTime >= e - inter && (sumL > 0 || sumG > 0 || sumP > 0)) { + timeList.add(stampToDate(pointTime)); + } + if (pointTime < e - inter) { + timeList.add(stampToDate(pointTime)); + linkList.add(sumL); + gbpsList.add(sumG); + ppsList.add(sumP); + } + + num = num + 1; + pointTime = b + inter * num; + } + resulMap.put("linkNum", linkList); + resulMap.put("gbps", gbpsList); + resulMap.put("pps", ppsList); + resulMap.put("statTime", timeList); + } + return resulMap; + } + + + /** + * 时间戳 换成日期格式字符串转 + * + * @param 时间 1544602212000 + * @param format 如:yyyy-MM-dd HH:mm:ss + * @return + */ + public static String stampToDate(long timeStamp) { + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");// 这个是你要转成后的时间的格式 + String sd = sdf.format(new Date(timeStamp)); // 时间戳转换成时间 + return sd; + } + + + /** + * 日期格式字符串转换成时间戳 + * + * @param date 字符串日期 + * @param format 如:yyyy-MM-dd HH:mm:ss + * @return + */ + public static Long dateToStamp(String date_str) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.parse(date_str).getTime(); + } catch (Exception e) { + e.printStackTrace(); + } + return 0l; + } + +} diff --git a/src/main/java/com/nis/web/task/SyncRedisToCluster.java b/src/main/java/com/nis/web/task/SyncRedisToCluster.java index 033c5ef..7fa4a1d 100644 --- a/src/main/java/com/nis/web/task/SyncRedisToCluster.java +++ b/src/main/java/com/nis/web/task/SyncRedisToCluster.java @@ -72,7 +72,7 @@ public class SyncRedisToCluster { } } - @Scheduled(cron = "${syncRedisToClusterCron}") +// @Scheduled(cron = "${syncRedisToClusterCron}") public void syncRedisToCluster() { JedisCluster jedisCluster = getResource(); String requestId = UUID.randomUUID().toString(); diff --git a/src/main/resources/applicationConfig-rule.properties b/src/main/resources/applicationConfig-rule.properties index a96f55d..4cb06fe 100644 --- a/src/main/resources/applicationConfig-rule.properties +++ b/src/main/resources/applicationConfig-rule.properties @@ -338,11 +338,11 @@ unMaatService=3:32;4:96;25:32;28:32;64;65;261:16;262:16;263:16;264:16;265:16;266 #0x05 DDOS流量丢弃 5:2,5; #0x21 APP阻断 33:2,5; #0x200 PXY拦截IP 512:4,5; -#0x201 PXY拦截域名 513:4,2,5; +#0x201 PXY拦截域名 513:4,2,5,7; #0x402 APP DOMAIN特征发现 1026:2,5; #0x404 APP IP特征 1028:2,5; ########## -serviceDBIndex=1:2,4,5;2:2,4,5;5:2,5;6: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;518: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;642:4;750:4;1024:2;1025:2;1026:2,5;1027:2;1028:2,5;1029:2;1030:2;1040:2,5;1041:2;1042:2;1056:2,5;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;834:6;835:6;836:6 +serviceDBIndex=1:2,4,5;2:2,4,5;5:2,5;6: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,7;514:4,5;515:4,2,5,7;517:4,5;518: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;642:4;750:4;1024:2;1025:2;1026:2,5;1027:2;1028:2,5;1029:2;1030:2;1040:2,5;1041:2;1042:2;1056:2,5;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;834:6;835:6;836:6 ##阀门配置在redisdb的序号 tapRedisDb=5 @@ -360,6 +360,13 @@ tapRedisDb=5 #0x404 APP IP特征 1028 maat2Valve=1:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;2:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;33:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;512:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;513:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;514:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;515:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;517:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;518:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;1026:strRegion|strStrRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;1028:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;1040:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;1056:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;5:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE&COMPILE_ID;6:ipRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE&COMPILE_ID + + +##webfocus配置在redisdb的序号 +webFocusDb=7 +maat2WebFocus=513:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE;515:strRegion@ACTION&SERVICE&USER_REGION&EFFECTIVE_RANGE; + + ##记录哪些service可以被分组复用(只有maat类配置可以被分组复用) #业务ID:域类型1@表名,表名|域类型2@表名;业务ID:域类型1@表名,表名|域类型2@表名 ##域类型:IP域 =ipRegion 字符串域=strRegion 数值域=numRegion diff --git a/src/main/resources/applicationContext-mybatis.xml b/src/main/resources/applicationContext-mybatis.xml index 9c93955..de071b3 100644 --- a/src/main/resources/applicationContext-mybatis.xml +++ b/src/main/resources/applicationContext-mybatis.xml @@ -243,13 +243,12 @@ - - + diff --git a/src/main/resources/nis.properties b/src/main/resources/nis.properties index 05654e3..e986ab2 100644 --- a/src/main/resources/nis.properties +++ b/src/main/resources/nis.properties @@ -219,7 +219,7 @@ isOpenLogCountAndLast=true #redis分布式锁超时时间,默认五分钟,3000秒 redisLockTime=3000 #获取redis分布式锁失败后的尝试获取锁的次数,每次失败暂停一秒钟后再次尝试 -redisRetryNum=5 +redisRetryNum=500 #ip定位库的地址 #ipLocationLibraryPath=/usr/local/ipLocalLibraay/Kazakhstan.mmdb ipLocationLibraryPath=C:\\ipLocation\\Kazakhstan.mmdb diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml index dedcf6b..cf31f60 100644 --- a/src/main/resources/spring-mvc.xml +++ b/src/main/resources/spring-mvc.xml @@ -216,11 +216,10 @@ - - - - - + + + +