diff --git a/src/main/java/com/nis/domain/restful/GroupReuse.java b/src/main/java/com/nis/domain/restful/GroupReuse.java new file mode 100644 index 0000000..6257932 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/GroupReuse.java @@ -0,0 +1,103 @@ +/** +* @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 java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.wordnik.swagger.annotations.ApiModelProperty; + +/** + * + * @ClassName:RegionRepeat + * @Description:TODO(这里用一句话描述这个类的作用) + * @author (zdx) + * @date 2018年8月22日 下午6:57:42 + * @version V1.0 + */ +public class GroupReuse implements Serializable { + private static final long serialVersionUID = 5803814776173252917L; + + @ApiModelProperty(value = "业务ID", required = true) + private Integer service; + + @ApiModelProperty(value = "字符串域分组列表", access = "", required = true) + private List strRegionList; + + @ApiModelProperty(value = "IP域分组列表", required = true) + private List ipRegionList; + + @ApiModelProperty(value = "数值域分组列表", required = true) + private List numRegionList; + + /** + * @return service + */ + public Integer getService() { + return service; + } + + /** + * @param service + * 要设置的 service + */ + public void setService(Integer service) { + this.service = service; + } + + + /** + * @return strRegionList + */ + public List getStrRegionList() { + return strRegionList; + } + + /** + * @param strRegionList + * 要设置的 strRegionList + */ + public void setStrRegionList(List strRegionList) { + this.strRegionList = strRegionList; + } + + /** + * @return ipRegionList + */ + public List getIpRegionList() { + return ipRegionList; + } + + /** + * @param ipRegionList + * 要设置的 ipRegionList + */ + public void setIpRegionList(List ipRegionList) { + this.ipRegionList = ipRegionList; + } + + /** + * @return numRegionList + */ + @ApiModelProperty(value = "数值域分组列表", required = true) + public List getNumRegionList() { + return numRegionList; + } + + /** + * @param numRegionList + * 要设置的 numRegionList + */ + public void setNumRegionList(List numRegionList) { + this.numRegionList = numRegionList; + } + +} diff --git a/src/main/java/com/nis/domain/restful/GroupReuseSource.java b/src/main/java/com/nis/domain/restful/GroupReuseSource.java new file mode 100644 index 0000000..4764a84 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/GroupReuseSource.java @@ -0,0 +1,119 @@ +/** +* @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:RegionRepeatSource + * @Description:TODO(这里用一句话描述这个类的作用) + * @author (zdx) + * @date 2018年8月22日 下午7:03:36 + * @version V1.0 + */ +public class GroupReuseSource extends ConfigCommonSource{ + + private static final long serialVersionUID = -7543263486915343526L; + private static final String DEFAULT_VERSION = "1.0"; + private List groupReuseList; //分组复用域配置列表 + /** + * @Title: + * @Description: TODO + * @param + */ + public GroupReuseSource() { + this.version = DEFAULT_VERSION; + } + + public GroupReuseSource(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; + } + + /** + * @return the groupReuseList + */ + public List getGroupReuseList() { + return groupReuseList; + } + + /** + * @param groupReuseList the groupReuseList to set + */ + public void setGroupReuseList(List groupReuseList) { + this.groupReuseList = groupReuseList; + } + +} diff --git a/src/main/java/com/nis/restful/RestBusinessCode.java b/src/main/java/com/nis/restful/RestBusinessCode.java index c4bf1e4..671b996 100644 --- a/src/main/java/com/nis/restful/RestBusinessCode.java +++ b/src/main/java/com/nis/restful/RestBusinessCode.java @@ -113,6 +113,11 @@ public enum RestBusinessCode { */ IsValidIsNull(4001013, "配置isValid属性不能为空"), + /** + * MAAT配置的域配置信息不能全为空 + */ + RegionListIsNull(4001014, "MAAT配置的域配置信息不能全为空"), + /** * 编译配置的groupNum不能为空 */ @@ -414,7 +419,14 @@ public enum RestBusinessCode { */ CfdsLevelIsWrongRange(4002500,"摘要域-cfdsLevel的值只能是1到10"), - + /** + * service不能为空并且必须是分组复用的业务类型 + */ + ServiceIsNullOrNotReuse(4002501, "service不能为空并且必须是分组复用的业务类型"), + /** + * 分组复用配置中域不能全为空 + */ + ReuseRegionIsNull(4002501, "分组复用配置中域不能全为空"), //回调类 /** * 回调类service配置不正确 @@ -544,6 +556,10 @@ public enum RestBusinessCode { * Redis数据库中MAAT配置的对应关系不存在 */ RelationNotExistsInRedis(5003004,"Redis数据库中MAAT配置的对应关系不存在"), + /** + * Redis关联关系库中未找到配置对应的redisdb信息 + */ + RedisDBRelationNotExistsInRedis(5003005,"Redis关联关系库中未找到配置对应的redisdb信息"), /** * Map中缺少编译配置信息 diff --git a/src/main/java/com/nis/util/CompileVal.java b/src/main/java/com/nis/util/CompileVal.java index 3f40da9..54a93e3 100644 --- a/src/main/java/com/nis/util/CompileVal.java +++ b/src/main/java/com/nis/util/CompileVal.java @@ -132,7 +132,8 @@ public class CompileVal { } } } - + //只有分组复用的业务类型,域可以不埴写,其他的maat配置至少填写一个域配置 + Boolean hasRegionFlag = false; List regionGroupIdList = new ArrayList();// 所有域配置中groupId的集合,不重复 List numRegionList = configCompile.getNumRegionList(); if (numRegionList == null) { @@ -142,6 +143,7 @@ public class CompileVal { RestBusinessCode.NumRegionIsNull.getValue()); } if (numRegionList.size() > 0) { + hasRegionFlag = true; for (NumRegion numRegion : numRegionList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(numRegion.getGroupId())) { @@ -194,6 +196,7 @@ public class CompileVal { RestBusinessCode.StrRegionIsNull.getValue()); } if (strRegionList != null && strRegionList.size() > 0) { + hasRegionFlag = true; for (StrRegion strRegion : strRegionList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(strRegion.getGroupId())) { @@ -248,6 +251,7 @@ public class CompileVal { RestBusinessCode.IpRegionIsNull.getValue()); } if (ipRegionList != null && ipRegionList.size() > 0) { + hasRegionFlag = true; for (IpRegion ipRegion : ipRegionList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(ipRegion.getGroupId())) { @@ -295,6 +299,7 @@ public class CompileVal { // 验证 if (digestRegionList != null && digestRegionList.size() > 0) { + hasRegionFlag = true; for (DigestRegion digestRegion : digestRegionList) { // 不验证表名和业务类型是否对应 @@ -335,6 +340,7 @@ public class CompileVal { List ipClientRangeList = configCompile.getIpClientRangeList(); if (ipClientRangeList != null && ipClientRangeList.size() > 0) { + hasRegionFlag = true; for (IpRegion ipRegion : ipClientRangeList) { // if (configCompile.getIsValid() != 0 && // !regionGroupIdList.contains(ipRegion.getGroupId())) { @@ -376,6 +382,10 @@ public class CompileVal { } } } + + if (!hasRegionFlag&&!ServiceAndRDBIndexReal.serviceIsReuse(configCompile.getService())) { + throw new RestServiceException("配置id为" + configCompile.getCompileId() + "的业务类型属于分组复用,域配置信息不能全为空",RestBusinessCode.RegionListIsNull.getValue()); + } } /** diff --git a/src/main/java/com/nis/util/GroupReuseVal.java b/src/main/java/com/nis/util/GroupReuseVal.java new file mode 100644 index 0000000..817a460 --- /dev/null +++ b/src/main/java/com/nis/util/GroupReuseVal.java @@ -0,0 +1,551 @@ +package com.nis.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.nis.domain.restful.GroupReuse; +import com.nis.domain.restful.IpRegion; +import com.nis.domain.restful.NumRegion; +import com.nis.domain.restful.StrRegion; +import com.nis.restful.RestBusinessCode; +import com.nis.restful.RestServiceException; +import com.nis.restful.ServiceRuntimeException; +import com.nis.web.service.restful.ConfigSourcesService; + +public class GroupReuseVal { + + public static void valGroupReuse(List groupReuseList, + Boolean isUpdate) throws Exception { + for (GroupReuse groupReuse : groupReuseList) { + Integer service = groupReuse.getService(); + if (StringUtil.isEmpty(service) + || !ServiceAndRDBIndexReal.serviceIsReuse(service)) { + throw new RestServiceException("server为空或" + service + + "或不属于分组复用的业务类型", + RestBusinessCode.ServiceIsNullOrNotReuse.getValue()); + } + Map> regTabNameMap = ServiceAndRDBIndexReal + .getServiceGroupReuseMap(service); + // 验证各类型域配置 + Boolean hasRegionFlag = false; + if (regTabNameMap.containsKey("numRegion") + && !StringUtil.isEmpty(groupReuse.getNumRegionList()) + && groupReuse.getNumRegionList().size() > 0) { + hasRegionFlag = true; + List numRegionList = groupReuse.getNumRegionList(); + for (NumRegion numRegion : numRegionList) { + if (!StringUtil.isEmpty(numRegion.getTableName()) + && !CompileVal.type2TableNameIsOk(service, + numRegion.getTableName())) { + throw new RestServiceException("service为" + service + + "的配置中numRegionList中的regionId为" + + numRegion.getRegionId() + + "的域配置tableName与业务类型不一致", + RestBusinessCode.TableNameUnmatchService + .getValue()); + } + if (!isUpdate && numRegion.getIsValid() != 1) { + throw new RestServiceException("service为" + service + + "的配置中numRegionList中的regionId为" + + numRegion.getRegionId() + "的域配置在添加时不能为无效", + RestBusinessCode.IsValidIsT.getValue()); + } + if (isUpdate && numRegion.getIsValid() != 0) { + throw new RestServiceException("service为" + service + + "的配置中numRegionList中的regionId为" + + numRegion.getRegionId() + "的域配置在修改时不能为有效", + RestBusinessCode.IsValidIsF.getValue()); + } + + if (!isUpdate && Constants.BASE_VALIDATE) { + valNumRegion(numRegion, service); + } + if (!isUpdate && Constants.SERVICE_VALIDATE) { + serviceNumRegionVal(numRegion, service); + } + } + } else if (regTabNameMap.containsKey("strRegion") + && !StringUtil.isEmpty(groupReuse.getStrRegionList()) + && groupReuse.getStrRegionList().size() > 0) { + hasRegionFlag = true; + List strRegionList = groupReuse.getStrRegionList(); + for (StrRegion strRegion : strRegionList) { + // if (groupReuse.getIsValid() != 0 && + // !regionGroupIdList.contains(strRegion.getGroupId())) + // { + if (!StringUtil.isEmpty(strRegion.getTableName()) + && !CompileVal.type2TableNameIsOk(service, + strRegion.getTableName())) { + throw new RestServiceException("配置id为" + service + + "的配置中strRegionList中的regionId为" + + strRegion.getRegionId() + + "的域配置tableName与业务类型不一致", + RestBusinessCode.TableNameUnmatchService + .getValue()); + } + if (!isUpdate && strRegion.getIsValid() != 1) { + throw new RestServiceException("配置id为" + service + + "的配置中strRegionList中的regionId为" + + strRegion.getRegionId() + "的域配置在添加时不能为无效", + RestBusinessCode.IsValidIsT.getValue()); + } + if (isUpdate && strRegion.getIsValid() != 0) { + throw new RestServiceException("配置id为" + service + + "的配置中strRegionList中的regionId为" + + strRegion.getRegionId() + "的域配置在修改时不能为有效", + RestBusinessCode.IsValidIsF.getValue()); + } + + if (!isUpdate && Constants.BASE_VALIDATE) { + valStrRegion(strRegion, service, + ConfigSourcesService.isStrStrongRegion( + strRegion.getTableName(), service)); + } + if (!isUpdate && Constants.SERVICE_VALIDATE) { + serviceStrRegionVal(strRegion, service, + ConfigSourcesService.isStrStrongRegion( + strRegion.getTableName(), service)); + } + } + } else if (regTabNameMap.containsKey("ipRegion") + && !StringUtil.isEmpty(groupReuse.getIpRegionList()) + && groupReuse.getIpRegionList().size() > 0) { + hasRegionFlag = true; + List ipRegionList = groupReuse.getIpRegionList(); + for (IpRegion ipRegion : ipRegionList) { + // if (groupReuse.getIsValid() != 0 && + // !regionGroupIdList.contains(ipRegion.getGroupId())) { + if (!StringUtil.isEmpty(ipRegion.getTableName()) + && !CompileVal.type2TableNameIsOk(service, + ipRegion.getTableName())) { + throw new RestServiceException("配置id为" + service + + "的配置中ipRegionList中的regionId为" + + ipRegion.getRegionId() + + "的域配置tableName与业务类型不一致", + RestBusinessCode.TableNameUnmatchService + .getValue()); + } + + if (!isUpdate + && (null == ipRegion.getIsValid() || ipRegion + .getIsValid() != 1)) { + throw new RestServiceException("配置id为" + service + + "的配置中ipRegionList中的regionId为" + + ipRegion.getRegionId() + "的域配置在添加时不能为无效", + RestBusinessCode.IsValidIsT.getValue()); + } + if (isUpdate + && (null == ipRegion.getIsValid() || ipRegion + .getIsValid() != 0)) { + throw new RestServiceException("service为" + service + + "的配置中ipRegionList中的regionId为" + + ipRegion.getRegionId() + "的域配置在修改时不能为有效", + RestBusinessCode.IsValidIsF.getValue()); + } + + if (!isUpdate && Constants.BASE_VALIDATE) { + valIpRegion(ipRegion, service); + } + + if (!isUpdate && Constants.SERVICE_VALIDATE) { + serviceIpRegionVal(ipRegion, service, "ipRegionList"); + } + } + } + if (hasRegionFlag) { + // 所有的域类型都不包括,可能是配置文件配错了 + throw new ServiceRuntimeException("service为" + service + "的" + + RestBusinessCode.ReuseRegionIsNull.getErrorReason(), + RestBusinessCode.ReuseRegionIsNull.getValue()); + } + } + } + + public static void valIpRegion(IpRegion ipRegion, Integer service) { + Long regionId = ipRegion.getRegionId(); + if (null == regionId) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置的regionId不能为空", + RestBusinessCode.RegionIdIsNull.getValue()); + } + if (null == ipRegion.getGroupId()) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置groupId不能为空", + RestBusinessCode.RegionsGroupIdIsNull.getValue()); + } + if (null == ipRegion.getAddrType()) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置addrType不能为空", + RestBusinessCode.AddrTypeIsNull.getValue()); + } + if (null == ipRegion.getSrcIp() || ipRegion.getSrcIp().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置srcIp不能为空", + RestBusinessCode.SrcIpIsNull.getValue()); + } + + if (null == ipRegion.getMaskSrcIp() + || ipRegion.getMaskSrcIp().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置maskSrcIp不能为空", + RestBusinessCode.MaskSrcIpIsNull.getValue()); + } + if (null == ipRegion.getSrcPort() || ipRegion.getSrcPort().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置srcPort不能为空", + RestBusinessCode.SrcPortIsNull.getValue()); + } + if (null == ipRegion.getMaskSrcPort() + || ipRegion.getMaskSrcPort().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置maskSrcPort不能为空", + RestBusinessCode.MaskSrcPortIsNull.getValue()); + } + if (null == ipRegion.getDstIp() || ipRegion.getDstIp().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置dstIp不能为空", + RestBusinessCode.DstIpIsNull.getValue()); + } + if (null == ipRegion.getMaskDstIp() + || ipRegion.getMaskDstIp().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置maskDstIp不能为空", + RestBusinessCode.MaskDstIpIsNull.getValue()); + } + if (null == ipRegion.getDstPort() || ipRegion.getDstPort().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置dstPort不能为空", + RestBusinessCode.DstPortIsNull.getValue()); + } + if (null == ipRegion.getMaskDstPort() + || ipRegion.getMaskDstPort().equals("")) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置maskDstPort不能为空", + RestBusinessCode.MaskDstPortIsNull.getValue()); + } + if (null == ipRegion.getProtocol()) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置protocol不能为空", + RestBusinessCode.ProtocolIsNull.getValue()); + } + if (null == ipRegion.getDirection()) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置direction不能为空", + RestBusinessCode.DirectionIsNull.getValue()); + } + if (null == ipRegion.getIsValid()) { + throw new RestServiceException("service为" + service + + "的中的ip类域配置id为" + regionId + "的配置isValid不能为空", + RestBusinessCode.IsValidIsNull.getValue()); + } + } + + public static void valNumRegion(NumRegion numRegion, Integer service) + throws Exception { + Long regionId = numRegion.getRegionId(); + if (null == regionId) { + throw new RestServiceException("service为" + service + + "的中的数值类域配置的regionId不能为空", + RestBusinessCode.RegionIdIsNull.getValue()); + } + if (null == numRegion.getGroupId()) { + throw new RestServiceException("service为" + service + + "的中的数值类域配置id为" + regionId + "的配置groupId不能为空", + RestBusinessCode.RegionsGroupIdIsNull.getValue()); + } + if (null == numRegion.getLowBoundary()) { + throw new RestServiceException("service为" + service + + "的中的数值类域配置id为" + regionId + "的配置lowBoundary不能为空", + RestBusinessCode.LowBoundaryIsNull.getValue()); + } + if (null == numRegion.getUpBoundary()) { + throw new RestServiceException("service为" + service + + "的中的数值类域配置id为" + regionId + "的配置upBoundary不能为空", + RestBusinessCode.UpBoundaryIsNull.getValue()); + } + } + + public static void valStrRegion(StrRegion strRegion, Integer service, + boolean isDirtrict) throws Exception { + Long regionId = strRegion.getRegionId(); + if (null == regionId) { + throw new RestServiceException("service为" + service + + "的中的字符串类域配置的regionId不能为空", + RestBusinessCode.RegionIdIsNull.getValue()); + } + if (null == strRegion.getGroupId()) { + throw new RestServiceException("service为" + service + + "的中的字符串类域配置id为" + regionId + "的配置groupId不能为空", + RestBusinessCode.RegionsGroupIdIsNull.getValue()); + } + if (isDirtrict + && (null == strRegion.getDistrict() || strRegion.getDistrict() + .equals(""))) { + throw new RestServiceException("service为" + service + + "的中的字符串类域配置id为" + regionId + "的配置district不能为空", + RestBusinessCode.DistrictIsNull.getValue()); + } + + if (null == strRegion.getKeywords() + || strRegion.getKeywords().equals("")) { + throw new RestServiceException("service为" + service + + "的中的字符串类域配置id为" + regionId + "的配置keywords不能为空", + RestBusinessCode.KeywordsIsNull.getValue()); + } + + if (null == strRegion.getExprType()) { + throw new RestServiceException("service为" + service + + "的中的字符串类域配置id为" + regionId + "的配置exprType不能为空", + RestBusinessCode.ExprTypeIsNull.getValue()); + } + + if (null == strRegion.getMatchMethod()) { + throw new RestServiceException("service为" + service + + "的中的字符串类域配置id为" + regionId + "的配置matchMethod不能为空", + RestBusinessCode.MatchMethodIsNull.getValue()); + } + if (null == strRegion.getIsHexbin()) { + throw new RestServiceException("service为" + service + + "的中的字符串类域配置id为" + regionId + "的配置isHexbin不能为空", + RestBusinessCode.MatchMethodIsNull.getValue()); + } + } + + + private static void validateIpAndMask(IpRegion ipRegion, Integer service, + String listName) throws Exception { + // 源IP信息和目的IP信息格式s为IPV4或IPV6 + if (ipRegion.getAddrType().intValue() == 4 + || ipRegion.getAddrType().intValue() == 6) { + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getSrcIp(), + ipRegion.getAddrType())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置srcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskSrcIp(), + ipRegion.getAddrType())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskSrcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getDstIp(), + ipRegion.getAddrType())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置dstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskDstIp(), + ipRegion.getAddrType())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskDstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + } else if (ipRegion.getAddrType().intValue() == 46) {// 4OVER6:源IP信息格式为IPV4、目的IP信息格式IPV6 + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getSrcIp(), 4)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置srcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskSrcIp(), 4)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskSrcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getDstIp(), 6)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置dstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskDstIp(), 6)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskDstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + } else if (ipRegion.getAddrType().intValue() == 64) {// 6OVER4:源IP信息格式为IPV6、目的IP信息格式IPV4 + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getSrcIp(), 6)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置srcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskSrcIp(), 6)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskSrcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getDstIp(), 4)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置dstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskDstIp(), 4)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskDstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + } else if (ipRegion.getAddrType().intValue() == 10) {// all:符合IP格式即可 + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getSrcIp(), null)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置srcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskSrcIp(), null)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskSrcIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getDstIp(), null)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置dstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + if (!BasicProvingUtil.isIpOrIpMask(ipRegion.getMaskDstIp(), null)) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskDstIp的格式不正确或与addrType不一致", + RestBusinessCode.IPUnMatchAddrType.getValue()); + } + } + + } + + public static void serviceIpRegionVal(IpRegion ipRegion, Integer service, + String listName) throws Exception { + + validateIpAndMask(ipRegion, service, listName); + + if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getSrcPort())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置srcPort的格式不正确", + RestBusinessCode.PortIsNotVal.getValue()); + } + + if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskSrcPort())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskSrcPort的格式不正确", + RestBusinessCode.PortIsNotVal.getValue()); + } + if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getDstPort())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置dstPort的格式不正确", + RestBusinessCode.PortIsNotVal.getValue()); + } + + if (!BasicProvingUtil.isPortOrPortMask(ipRegion.getMaskDstPort())) { + // if (!BasicProvingUtil.isIntType(ipRegion.getMaskDstPort())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置maskDstPort的格式不正确", + RestBusinessCode.PortIsNotVal.getValue()); + } + + if (ipRegion.getSrcIp().equals(ipRegion.getDstIp())) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置srcIp和dstIp不能相同", + RestBusinessCode.SrcIpEQDstIp.getValue()); + } + if (ipRegion.getDirection() != 1 && ipRegion.getDirection() != 0) { + throw new RestServiceException("service为" + service + "的配置中" + + listName + "中regionId为" + ipRegion.getRegionId() + + "的域配置direction的值不正确,只能是0或1", + RestBusinessCode.DirectionIsWrongRange.getValue()); + } + + // zdx protocol验证? + // if (ipRegion.getTableName().toLowerCase().equals("dj_ip_port")) { + // if (ipRegion.getProtocol() < 0 || ipRegion.getProtocol() > 255) { + // return "service为" + service + "的配置中"+listName+"中regionId为" + + // ipRegion.getRegionId() + // + "的域配置tableName为dj_ip_port时,protocol的取值范围只能是0-255"; + // } + // } else { + // if (ipRegion.getProtocol() != 0) { + // return "service为" + service + "的配置中"+listName+"中regionId为" + + // ipRegion.getRegionId() + "的域配置tableName为" + // + ipRegion.getTableName() + "时,protocol的值只能是0"; + // } + // + // } + } + + public static void serviceNumRegionVal(NumRegion numRegion, Integer service) + throws Exception { + Long lowBoundary = numRegion.getLowBoundary(); + Long upBoundary = numRegion.getUpBoundary(); + if (lowBoundary <= upBoundary) { + if (lowBoundary > 4294967295l || lowBoundary < 0l) { + throw new RestServiceException("service为" + service + + "的配置中numRegionList中regionId为" + + numRegion.getRegionId() + + "的域配置lowBoundary的值不能大于2的32次方减一(4294967295)或者小于0", + RestBusinessCode.LowBoundaryIsWrongRange.getValue()); + } + if (upBoundary > 4294967295l || upBoundary < 0l) { + throw new RestServiceException("service为" + service + + "的配置中numRegionList中regionId为" + + numRegion.getRegionId() + + "的域配置upBoundary的值不能大于2的32次方减一(4294967295)或者小于0", + RestBusinessCode.UpBoundaryIsWrongRange.getValue()); + } + } else { + throw new RestServiceException("service为" + service + + "的配置中numRegionList中regionId为" + numRegion.getRegionId() + + "的域配置lowBoundary的值大于upBoundary,应该是小于或等于", + RestBusinessCode.LowBoundaryGTUpBoundary.getValue()); + } + } + + public static void serviceStrRegionVal(StrRegion strRegion, + Integer service, boolean isDirtrict) throws Exception { + + Integer exprType = strRegion.getExprType(); + Integer matchMethod = strRegion.getMatchMethod(); + Integer isHexbin = strRegion.getIsHexbin(); + if (exprType != 0 && exprType != 1) { + throw new RestServiceException("service为" + service + + "的配置中strRegionList中regionId为" + strRegion.getRegionId() + + "的域配置exprType的值只能是0(无表达式)或者1(与表达式)", + RestBusinessCode.ExprTypeIsWrongRange.getValue()); + } + if (matchMethod != 0 && matchMethod != 1 && matchMethod != 2 + && matchMethod != 3) { + throw new RestServiceException("service为" + service + + "的配置中strRegionList中regionId为" + strRegion.getRegionId() + + "的域配置matchMethod的值只能是0(子串匹配),1(右匹配),2(左匹配),3(完全匹配)", + RestBusinessCode.MatchMethodIsWrongRange.getValue()); + } + + if (isHexbin != 0 && isHexbin != 1 && isHexbin != 2) { + throw new RestServiceException( + "service为" + + service + + "的配置中strRegionList中regionId为" + + strRegion.getRegionId() + + "的域配置isHexbin的值只能是0(大小写不敏感,且非HEX)或者1(HEX)或者2(大小写敏感,且非HEX)", + RestBusinessCode.IsHexbinIsWrongRange.getValue()); + } + // strRegProhibitConfigWord(strRegion,service); + + } + +} diff --git a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java index 025934c..3b3d867 100644 --- a/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java +++ b/src/main/java/com/nis/util/ServiceAndRDBIndexReal.java @@ -26,8 +26,9 @@ public class ServiceAndRDBIndexReal { private static Logger logger = LoggerFactory.getLogger(ServiceAndRDBIndexReal.class); /** * 记录哪些service可以被分组复用(只有maat类配置可以被分组复用) + * Map> */ - private static Set serviceRepeatedRealSet = new HashSet(); + private static Map>> serviceGroupReuseMap = new HashMap>>(); /** * 第一个key是业务类型,第二个key是type(编译配置,分组配置,域配置)value是表名 @@ -64,35 +65,26 @@ public class ServiceAndRDBIndexReal { if (unMaatService != null && !unMaatService.trim().equals("")) { String[] split = unMaatService.split(";"); for (String str : split) { - // 回调类删除action zdx20180821 - // String[] serviceAction = str.split(":"); - // serviceActionMap.put(Integer.valueOf(serviceAction[0]), - // Integer.valueOf(serviceAction[1])); - // - // String serviceType = Configurations.getStringProperty(serviceAction[0], ""); - // if (serviceType != null && !serviceType.trim().equals("")) { - // String[] typeArrs = serviceType.split(";"); - // for (String typeStr : typeArrs) { - // String[] typeArr = typeStr.split(":"); - // String tableNameArr[] = typeArr[1].split(","); - // for (String tableName : tableNameArr) { - // unMaatSercieNameMap.put(Integer.parseInt(serviceAction[0]), - // tableName.toUpperCase()); - // } - // } - // } - - String serviceType = Configurations.getStringProperty(str, ""); - if (serviceType != null && !serviceType.trim().equals("")) { - String[] typeArrs = serviceType.split(";"); - for (String typeStr : typeArrs) { - String[] typeArr = typeStr.split(":"); - String tableNameArr[] = typeArr[1].split(","); - for (String tableName : tableNameArr) { - unMaatSercieNameMap.put(Integer.parseInt(str), tableName.toUpperCase()); - } - } - } + String[] serviceAction = str.split(":"); + if (serviceAction.length==2) { + serviceActionMap.put(Integer.valueOf(serviceAction[0]), + Integer.valueOf(serviceAction[1])); + }else{ + serviceActionMap.put(Integer.valueOf(serviceAction[0]), + null); + } + String serviceType = Configurations.getStringProperty(serviceAction[0], ""); + if (serviceType != null && !serviceType.trim().equals("")) { + String[] typeArrs = serviceType.split(";"); + for (String typeStr : typeArrs) { + String[] typeArr = typeStr.split(":"); + String tableNameArr[] = typeArr[1].split(","); + for (String tableName : tableNameArr) { + unMaatSercieNameMap.put(Integer.parseInt(serviceAction[0]), + tableName.toUpperCase()); + } + } + } } } @@ -165,13 +157,27 @@ public class ServiceAndRDBIndexReal { } String serviceRepeatedReal = Configurations.getStringProperty("serviceRepeatedReal", ""); - if (serviceRepeatedReal != null && !serviceRepeatedReal.trim().equals("")) { - String[] serviceRepeatedRealArr = serviceRepeatedReal.split(","); - for (String ser : serviceRepeatedRealArr) { - if (ser != null && !ser.trim().equals("")) { - serviceRepeatedRealSet.add(Integer.parseInt(ser)); + if (!StringUtil.isEmpty(serviceRepeatedReal)) { + String[] serviceRepeatedRealArr = serviceRepeatedReal.split(";"); + for (String serviceRepeated : serviceRepeatedRealArr) { + String [] serInfos = serviceRepeated.split(":"); + String [] regionInfos = serInfos[1].split("[|]"); + for (String regionInfo : regionInfos) { + String [] regionTabName = regionInfo.split("@"); + String [] tableNames = regionTabName[1].split(","); + for (String tableName : tableNames) { + Integer ser = Integer.valueOf(serInfos[0]); + if(serviceGroupReuseMap.containsKey(ser)){ + serviceGroupReuseMap.get(ser).get(regionTabName[0]).add(tableName); + }else{ + Map> regTabMap = new HashMap>(); + List tabList = new ArrayList(); + tabList.add(tableName); + regTabMap.put(regionTabName[0], tabList); + serviceGroupReuseMap.put(ser, regTabMap); + } + } } - } } } @@ -325,12 +331,12 @@ public class ServiceAndRDBIndexReal { * @param service * @return */ - public static Boolean serviceIsRepeated(Integer service) { + public static Boolean serviceIsReuse(Integer service) { if (service != null) { - return serviceRepeatedRealSet.contains(service); + return serviceGroupReuseMap.containsKey(service); } else { - } throw new ServiceRuntimeException("判断service是否是分组复用时发生了异常,异常原因:service=null", RestBusinessCode.ServiceIsNull.getValue()); - + throw new ServiceRuntimeException("判断service是否是分组复用时发生了异常,异常原因:service=null", RestBusinessCode.ServiceIsNull.getValue()); + } } /** @@ -394,5 +400,12 @@ public class ServiceAndRDBIndexReal { public static void setUnMaatSercieNameMap(Map unMaatSercieNameMap) { ServiceAndRDBIndexReal.unMaatSercieNameMap = unMaatSercieNameMap; } - + + /** + * @return the serviceGroupReuseMap + */ + public static Map> getServiceGroupReuseMap(Integer service) { + return serviceGroupReuseMap.get(service); + } + } 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 145a3f5..cb1c4bb 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -2,7 +2,6 @@ package com.nis.web.controller.restful; import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; @@ -10,7 +9,8 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.nis.web.service.AuditLogThread; +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; @@ -22,16 +22,17 @@ import org.springframework.web.multipart.MultipartFile; import com.nis.domain.restful.ConfigCompile; import com.nis.domain.restful.ConfigSource; import com.nis.domain.restful.FileDesc; +import com.nis.domain.restful.GroupReuse; +import com.nis.domain.restful.GroupReuseSource; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; import com.nis.restful.ServiceRuntimeException; -import com.nis.util.CompileVal; import com.nis.util.Constants; import com.nis.util.FileUtils; -import com.nis.util.OracleErrorCodeUtil; import com.nis.util.StringUtil; 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.fdfs.FastDFSFile; import com.nis.web.service.fdfs.FileManager; @@ -41,8 +42,6 @@ import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; import com.wordnik.swagger.annotations.ApiParam; -import net.sf.json.JSONObject; - /** * @ClassName: ConfigSourcesController * @Description: 配置存储服务 @@ -177,7 +176,7 @@ 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, @@ -208,7 +207,6 @@ public class ConfigSourcesController extends BaseRestController { 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, @@ -376,6 +374,119 @@ public class ConfigSourcesController extends BaseRestController { return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "摘要获取成功", resultObject); } + @RequestMapping(value = "/cfg/v1/groupReuseSources", method = RequestMethod.POST) + @ApiOperation(value = "分组复用域配置新增接口", httpMethod = "POST", response = Map.class, notes = "接收分组复用域配置,增加到对应的分组中") + @ApiParam(value = "分组复用域配置对象", name = "configSource", 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(); + 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()); + } + } catch (Exception e) { + // TODO: handle exception + thread.setExceptionInfo("Maat 分组复用规则存储异常:" + e.getMessage()); + 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) { + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + "Maat 分组复用规则存储异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); + }else{ + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + "Maat 分组复用规则存储异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + } + + } + + 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 = "configSource", required = true) + public Map delGroupReuseSources(@RequestBody GroupReuseSource groupReuseSource, HttpServletRequest request, + HttpServletResponse response) { + long start = System.currentTimeMillis(); + AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, + groupReuseSource); + StringBuffer sb = new StringBuffer(); + 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()); + } + } catch (Exception e) { + // TODO: handle exception + thread.setExceptionInfo("MAAT规则状态更新时出现异常:" + e.getMessage()); + 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) { + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + "删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); + }else{ + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + "删除MAAT规则分组复用域配置时出现异常:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + } + } + + return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, + "MAAT规则分组复用域配置删除成功" + sb.toString(), Constants.IS_DEBUG ?groupReuseSource : null); + } + + private void validateGroupReuseSource(AuditLogThread thread, long start, GroupReuseSource groupReuseSource) { + String errorInfo = ""; + + List groupReuseSourceList = groupReuseSource.getGroupReuseList(); + + if (StringUtils.isEmpty(groupReuseSource.getOperator())) { + errorInfo = "get operator is Empty"; + } + if (StringUtils.isEmpty(groupReuseSource.getVersion())) { + errorInfo = "get version is Empty"; + } + + if (!isBlank(groupReuseSource.getOpTime())) { + errorInfo = "get OpTime is Empty"; + } + + if (groupReuseSourceList.size() <= 0) { + errorInfo = "分组复用的域配置列表不能为空"; + } + if (!errorInfo.equals("")) { + thread.setExceptionInfo(errorInfo); + throw new RestServiceException(thread, System.currentTimeMillis() - start, errorInfo, + RestBusinessCode.missing_args.getValue()); + } + + } private boolean isBlank(Date datetime) { if (null != datetime) { return true; diff --git a/src/main/java/com/nis/web/controller/restful/MaatTestController.java b/src/main/java/com/nis/web/controller/restful/MaatTestController.java index 7f9f5fa..87ddbe3 100644 --- a/src/main/java/com/nis/web/controller/restful/MaatTestController.java +++ b/src/main/java/com/nis/web/controller/restful/MaatTestController.java @@ -188,7 +188,9 @@ public class MaatTestController { maatTestServiceimpl.getMaatKeys(configCompileList); map.put(service, "http://127.0.0.1:8080/galaxy/service/test/cfg/v1/testDelMaat?serviceType=" + service + "&configId=" + compileIdList.toString().replace("[", "").replace("]", "")); - testDelMaat(compileIdList.toString().replace("[", "").replace("]", ""), service); + if(!testDelMaat(compileIdList.toString().replace("[", "").replace("]", ""), service).equals("ok")) { + map.put(-4, "del config error"); + } } else { map.put(-2, "is not maat service"); @@ -592,7 +594,9 @@ public class MaatTestController { // 验证数据是否在正确 maatTestServiceimpl.getUnMaatKeys(jsonStr, service); // 删除配置 - testDelUnMaat(compileIdList.toString().replace("[", "").replace("]", ""), service); + if(!testDelUnMaat(compileIdList.toString().replace("[", "").replace("]", ""), service).equals("ok")){ + map.put(-4, "del unmaat error"); + } } } catch (Exception e) { String exceptionMsg = ExceptionUtil.getExceptionMsg(e); 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 b2c7c34..03bebd2 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java @@ -4,7 +4,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -14,10 +13,6 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.Transaction; -import redis.clients.jedis.exceptions.JedisConnectionException; - import com.nis.domain.MaatXmlConfig; import com.nis.domain.MaatXmlExpr; import com.nis.domain.MaatXmlSeq; @@ -29,6 +24,10 @@ import com.nis.util.JedisUtils; import com.nis.util.ReadMaatXmlUtil; import com.nis.util.ServiceAndRDBIndexReal; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Transaction; +import redis.clients.jedis.exceptions.JedisConnectionException; + @Service() public class ConfigJedisServiceimpl implements ConfigRedisService { private static Logger logger = LoggerFactory.getLogger(ConfigJedisServiceimpl.class); @@ -186,7 +185,6 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } catch (Exception e) { transaction.discard(); String error = "保存非maat类配置发生了异常," + e.getMessage(); - // logger.error(error); throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue()); } finally { // 释放连接到连接池 @@ -207,6 +205,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); transaction.select(idRelaRedisDBIndex); Set redisDBSet = configMap.keySet();// 所有的redisdb + String redisDBSetStr = "-" + redisDBSet.toString().replace("[", "").replace("]", ""); for (Integer redisDBIndex : redisDBSet) { if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { List maatConfigList = configMap.get(redisDBIndex); @@ -218,25 +217,28 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { List> groupMapList = maatConfig.getGroupMapList(); if (groupMapList != null && groupMapList.size() > 0) { for (Map map : groupMapList) { - String cfgIdStr = redisDBSet.toString() + ":COMPILEGROUP:" + map.get("compile_id"); - String groupIdStr = redisDBIndex + ":GROUPCOMPILE:" + map.get("group_id"); + // String cfgIdStr = redisDBSet.toString() + ":COMPILEGROUP:" + + // map.get("compile_id"); + String cfgIdStr = "COMPILEGROUP:" + map.get("compile_id"); + // String groupIdStr = redisDBIndex + ":GROUPCOMPILE:" + map.get("group_id"); + String groupIdStr = "GROUPCOMPILE:" + map.get("group_id"); // + map.get("compile_id"); if (cfgIdStr != null && groupIdStr != null && !cfgIdStr.equals("") && !groupIdStr.equals("")) { if (compileAndGroupMap.containsKey(cfgIdStr.toUpperCase())) { compileAndGroupMap.get(cfgIdStr.toUpperCase()) - .add(groupIdStr.toUpperCase()); + .add(groupIdStr.toUpperCase() + redisDBSetStr); } else { List list = new ArrayList(); - list.add(groupIdStr.toUpperCase()); + list.add(groupIdStr.toUpperCase() + redisDBSetStr); compileAndGroupMap.put(cfgIdStr.toUpperCase(), list); } if (groupAndCompileMap.containsKey(groupIdStr.toUpperCase())) { groupAndCompileMap.get(groupIdStr.toUpperCase()) - .add(cfgIdStr.toUpperCase()); + .add(cfgIdStr.toUpperCase() + redisDBSetStr); } else { List list = new ArrayList(); - list.add(cfgIdStr.toUpperCase()); + list.add(cfgIdStr.toUpperCase() + redisDBSetStr); groupAndCompileMap.put(groupIdStr.toUpperCase(), list); } } @@ -246,19 +248,20 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { int service = maatConfig.getService(); MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); addGroupAndRegionRelations(maatXmlConfig, service, 12, maatConfig.getIpRegionMapList(), map, - redisDBIndex, compileId); + redisDBIndex, compileId, redisDBSetStr); addGroupAndRegionRelations(maatXmlConfig, service, 13, maatConfig.getNumRegionMapList(), - map, redisDBIndex, compileId); + map, redisDBIndex, compileId, redisDBSetStr); addGroupAndRegionRelations(maatXmlConfig, service, 14, maatConfig.getStrRegionMapList(), - map, redisDBIndex, compileId); + map, redisDBIndex, compileId, redisDBSetStr); addGroupAndRegionRelations(maatXmlConfig, service, 15, maatConfig.getStrStrRegionMapList(), - map, redisDBIndex, compileId); + map, redisDBIndex, compileId, redisDBSetStr); addGroupAndRegionRelations(maatXmlConfig, service, 16, - maatConfig.getFileDigestRegionMapList(), map, redisDBIndex, compileId); + maatConfig.getFileDigestRegionMapList(), map, redisDBIndex, compileId, + redisDBSetStr); addGroupAndRegionRelations(maatXmlConfig, service, 17, - maatConfig.getFileLikeRegionMapList(), map, redisDBIndex, compileId); + maatConfig.getFileLikeRegionMapList(), map, redisDBIndex, compileId, redisDBSetStr); addGroupAndRegionRelations(maatXmlConfig, service, 18, maatConfig.getIpClientRangeMapList(), - map, redisDBIndex, compileId); + map, redisDBIndex, compileId, redisDBSetStr); for (String groupIdStr : map.keySet()) { List list = map.get(groupIdStr); @@ -439,7 +442,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { */ private Map> addGroupAndRegionRelations(MaatXmlConfig maatXmlConfig, int service, int type, List> regionMapList, Map> groupAndRegionMap, int redisDBIndex, - String compileId) { + String compileId, String redisDBSetStr) { if (regionMapList != null && regionMapList.size() > 0) { for (Map map : regionMapList) { List expressionList = maatXmlConfig.getExpressionList(); @@ -478,12 +481,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } // String groupIdStr = redisDBIndex + ":GROUPREGION:" + map.get("group_id") + // compileId; - String groupIdStr = redisDBIndex + ":GROUPREGION:" + map.get("group_id"); + // String groupIdStr = redisDBIndex + ":GROUPREGION:" + map.get("group_id"); + String groupIdStr = "GROUPREGION:" + map.get("group_id");// groupregion里面value是region的信息,key是group的信息 if (groupAndRegionMap.containsKey(groupIdStr.toUpperCase())) { - groupAndRegionMap.get(groupIdStr.toUpperCase()).add(redisDBIndex + ":" + maatKey.toUpperCase()); + groupAndRegionMap.get(groupIdStr.toUpperCase()).add(maatKey.toUpperCase() + redisDBSetStr); } else { List list = new ArrayList(); - list.add(redisDBIndex + ":" + maatKey.toUpperCase()); + list.add(maatKey.toUpperCase() + redisDBSetStr); groupAndRegionMap.put(groupIdStr.toUpperCase(), list); } } @@ -982,7 +986,6 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } catch (Exception e) { transaction.discard(); String error = "删除非maat类配置发生了异常," + e.getMessage(); - // logger.error(error); throw new ServiceRuntimeException(error, RestBusinessCode.DeleteDataInError.getValue()); } finally { // 释放连接到连接池 @@ -998,14 +1001,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { @Override public boolean delMaatConfig(Map>> idMap) { if (idMap != null && idMap.size() > 0) { - int count = 0; Jedis resource = JedisUtils.getResource(0); Transaction transaction = resource.multi(); try { int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); for (Integer redisDBIndex : idMap.keySet()) { - // 按序号选择Redis数据库 - transaction.select(redisDBIndex); Map> serviceConfigMap = idMap.get(redisDBIndex); if (serviceConfigMap != null && serviceConfigMap.size() > 0) { String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDBIndex); @@ -1013,14 +1013,46 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { Long maatVersion = Long.valueOf(maatVersionStr) + 1; for (Integer service : serviceConfigMap.keySet()) { MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); - removeConfig(serviceConfigMap.get(service), maatXmlConfig, maatVersion, service, - transaction, redisDBIndex, idRelaRedisDBIndex); + List list = serviceConfigMap.get(service); + if (list != null && list.size() > 0) { + for (Long id : list) { + String compileStrVal = JedisUtils.get("COMPILEGROUP:" + id, idRelaRedisDBIndex);/// 从编译,分组,域的关系中获取当前编译id对应的的分组关系,及redisdb信息 + if (compileStrVal != null && compileStrVal.contains("-")) { + String[] split = compileStrVal.split("-"); + String redisDBStr = split[1];// 获取redisdb信息 + if (redisDBStr != null && !redisDBStr.equals("")) { + String[] redisDBArr = redisDBStr.split(","); + for (String dbStr : redisDBArr) { + int dbIndex = Integer.parseInt(dbStr.trim()); + // 按序号选择Redis数据库 + transaction.select(dbIndex); + removeConfig(id, maatXmlConfig, maatVersion, service, transaction, + dbIndex, idRelaRedisDBIndex); + transaction.incrBy("MAAT_VERSION", 1l); + logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, + Integer.valueOf(maatVersionStr) + 1); + } + } else { + throw new ServiceRuntimeException( + "未从" + idRelaRedisDBIndex + "号redis库(编译,分组,域关系)中获取配置id=" + id + + ",对应的redisdb信息,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常", + RestBusinessCode.RedisDBRelationNotExistsInRedis.getValue()); + } + } else { + throw new ServiceRuntimeException( + "未从" + idRelaRedisDBIndex + "号redis库(编译,分组,域关系)中获取配置id=" + id + + ",对应的redisdb信息,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常", + RestBusinessCode.RedisDBRelationNotExistsInRedis.getValue()); + } + + } + } else { + throw new ServiceRuntimeException("删除配置时,未发现对应的配置id信息,请检查配置参数是否正确", + RestBusinessCode.ConfigSourceIsNull.getValue()); + } } - transaction.incrBy("MAAT_VERSION", 1l); - logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex, - Integer.valueOf(maatVersionStr) + 1); - count++; + } else { throw new ServiceRuntimeException("从" + redisDBIndex + "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常", @@ -1030,10 +1062,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { throw new ServiceRuntimeException("从" + redisDBIndex + "号redis库删除配置时,未发现对应的配置信息,请检查配置参数是否正确", RestBusinessCode.ConfigSourceIsNull.getValue()); } + break; } - if (count == idMap.size()) { - delMaatRelation(idMap, transaction); - delStatisticsReal(idMap, transaction); + if (delMaatRelation(idMap, transaction) && delStatisticsReal(idMap, transaction)) { transaction.exec(); return true; } else { @@ -1042,13 +1073,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } catch (JedisConnectionException e) { String error = "连接redis异常,删除maat配置失败," + e.getMessage(); - // logger.error(error); throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue()); } catch (Exception e) { + e.printStackTrace(); transaction.discard(); - - // logger.error(error); int businessCode = RestBusinessCode.service_runtime_error.getValue(); if (e instanceof ServiceRuntimeException) { businessCode = ((ServiceRuntimeException) e).getErrorCode(); @@ -1058,85 +1087,96 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { // 释放连接到连接池 JedisUtils.returnResource(resource); } - } else { + } else + + { throw new ServiceRuntimeException("Map参数信息不能为空,请检查!", RestBusinessCode.ConfigInfoMapIsNull.getValue()); } return false; } + private String getRealInfo(String compileStrVal) { + if (compileStrVal != null && compileStrVal.contains("-")) { + String[] split = compileStrVal.split("-"); + return split[0];// 去除后面的redisdb信息 + } + return null; + } + /** * 删除maat类配置 - * @param idList 配置id集合 + * @param id 配置id * @param maatXmlConfig maat.xml中关于当前业务类型的key和value写法的对象 * @param maatVersion 版本号 * @param service 业务类型 * @param redisTemplate * @param maatRelation id对应关系对象 */ - private void removeConfig(List idList, MaatXmlConfig maatXmlConfig, Long maatVersion, int service, + private void removeConfig(Long id, MaatXmlConfig maatXmlConfig, Long maatVersion, int service, Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex) { + if (maatXmlConfig != null) { + // 删除(重命名)编译配置 + removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion.doubleValue(), service, transaction, + redisDBIndex, null);// 10代表是编译配置 + // 拼接编译与分组关系的Redis Key + // String compileStr = redisDBIndex + ":COMPILEGROUP:" + id; + String compileStr = "COMPILEGROUP:" + id; + // 获取当前编译配置与分组配置的关联关系 + String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系 + String groupCompileStrs = getRealInfo(compileStrVal); + // if (compileStrVal != null && compileStrVal.contains("-")) { + // String[] split = compileStrVal.split("-"); + // groupCompileStrs = split[0];// 去除后面的redisdb信息 + // } + if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) { + String[] split = groupCompileStrs.split(";"); + for (String groupId : split) { + String compileGroupStr = getRealInfo(JedisUtils.get(groupId, idRelaRedisDBIndex)); + if (compileGroupStr != null && !compileGroupStr.trim().equals("")) { + String[] compileGroupArr = compileGroupStr.split(";");// 获取组对应的编译id - if (idList != null && idList.size() > 0 && maatXmlConfig != null) { - for (Long id : idList) { - // 删除(重命名)编译配置 - removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion.doubleValue(), service, transaction, - redisDBIndex, null);// 10代表是编译配置 - // 拼接编译与分组关系的Redis Key - String compileStr = redisDBIndex + ":COMPILEGROUP:" + id; - // 获取当前编译配置与分组配置的关联关系 - String groupCompileStrs = JedisUtils.get(compileStr, idRelaRedisDBIndex); - if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) { - String[] split = groupCompileStrs.split(";"); - for (String groupId : split) { - String compileGroupStr = JedisUtils.get(groupId, idRelaRedisDBIndex); - if (compileGroupStr != null && !compileGroupStr.trim().equals("")) { - String[] compileGroupArr = compileGroupStr.split(";");// 获取组对应的编译id - if (compileGroupArr != null && compileGroupArr.length == 1) {// 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效 - for (String compileId : compileGroupArr) { - if (compileId.equals(compileStr)) {// - String groupRegionKey = groupId.replace("GROUPCOMPILE", "GROUPREGION"); - String regionStr = JedisUtils.get(groupRegionKey, idRelaRedisDBIndex); - if (regionStr != null && !regionStr.trim().equals("")) { - String[] regionKeyArr = regionStr.split(";"); - if (regionKeyArr != null && regionKeyArr.length > 0) { - // 根据分组与域关联关系找到对应域配置然后删除(重命名) - removeRegionConfig(maatXmlConfig, regionKeyArr, - maatVersion.doubleValue(), service, transaction, redisDBIndex); - } - } else { - throw new ServiceRuntimeException( - "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与域的关联关系,key为" - + groupRegionKey, - RestBusinessCode.KeyNotExistsInRedis.getValue()); + // 被分组复用的业务,不能将域置为失效 + if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效 + // if (compileGroupArr != null && compileGroupArr.length == 1) {// + // 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效 + for (String compileId : compileGroupArr) { + if (compileId.equals(compileStr)) {// + String groupRegionKey = groupId.replace("GROUPCOMPILE", "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION + String regionStr = getRealInfo(JedisUtils.get(groupRegionKey, idRelaRedisDBIndex)); + if (regionStr != null && !regionStr.trim().equals("")) { + String[] regionKeyArr = regionStr.split(";"); + if (regionKeyArr != null && regionKeyArr.length > 0) { + // 根据分组与域关联关系找到对应域配置然后删除(重命名) + removeRegionConfig(maatXmlConfig, regionKeyArr, maatVersion.doubleValue(), + service, transaction, redisDBIndex); } + } else { + throw new ServiceRuntimeException( + "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与域的关联关系,key为" + + groupRegionKey, + RestBusinessCode.KeyNotExistsInRedis.getValue()); } } } - // 根据分组与域关联关系找到对应域配置然后删除(重命名) - removeCompileAndGroupConfig(maatXmlConfig, - groupId.replace(redisDBIndex + ":GROUPCOMPILE:", ""), 11, maatVersion.doubleValue(), - service, transaction, redisDBIndex, id + "");// 11代表是分组配置 - } else { - throw new ServiceRuntimeException( - "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为" + groupId, - RestBusinessCode.KeyNotExistsInRedis.getValue()); } + // 根据分组与编译关联关系找到对应分组配置然后删除(重命名) + removeCompileAndGroupConfig(maatXmlConfig, groupId.replace("GROUPCOMPILE:", ""), 11, + maatVersion.doubleValue(), service, transaction, redisDBIndex, id + "");// 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( + "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系,key为" + compileStr, + RestBusinessCode.KeyNotExistsInRedis.getValue()); } } else { - if (StringUtils.isEmpty(maatXmlConfig)) { - throw new ServiceRuntimeException( - "无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确", - RestBusinessCode.NotFoundRedisRule.getValue()); - } else { - throw new ServiceRuntimeException("删除redis库中配置时,未发现对应的配置信息,请检查配置参数是否正确", - RestBusinessCode.ConfigSourceIsNull.getValue()); - } + throw new ServiceRuntimeException( + "无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确", + RestBusinessCode.NotFoundRedisRule.getValue()); } } @@ -1248,7 +1288,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { List expressionList = maatXmlConfig.getExpressionList(); String maatKey = null; for (String oldKey : regionArr) { - oldKey = oldKey.replace(redisDBIndex + ":", ""); + // oldKey = oldKey.replace(redisDBIndex + ":", ""); maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); if (JedisUtils.exists(oldKey, redisDBIndex)) { transaction.rename(oldKey, maatKey.toUpperCase()); @@ -1300,7 +1340,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { * 编译配置用于实时统计 * 取消分类性质,标签等信息 */ - private void delStatisticsReal(Map>> idMap, Transaction transaction) { + private boolean delStatisticsReal(Map>> idMap, Transaction transaction) { if (idMap != null && idMap.size() > 0) { int redisStatisticsRealDBIndex = Configurations.getIntProperty("redisStatisticsRealDBIndex", 14); transaction.select(redisStatisticsRealDBIndex); @@ -1362,7 +1402,10 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } break;// 因为所有的value都是相同的所以只取消一次就可以了 } - + return true; + } else { + throw new ServiceRuntimeException("状态更新操作Map参数信息不能为空,请检查配置参数是否正确", + RestBusinessCode.ConfigInfoMapIsNull.getValue()); } } @@ -1371,37 +1414,43 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { * 删除配置成功后,需要更新编译,组,域等配置id的对应关系 * @param idMap */ - private String delMaatRelation(Map>> idMap, Transaction transaction) { + private boolean delMaatRelation(Map>> idMap, Transaction transaction) { if (idMap != null && idMap.size() > 0) { int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); transaction.select(idRelaRedisDBIndex); for (Integer redisDBIndex : idMap.keySet()) { if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) { - Map> map = idMap.get(redisDBIndex); + Map> map = idMap.get(redisDBIndex);// 获取service和配置id的对应关系 if (map != null && map.size() > 0) { for (Integer service : map.keySet()) { List idList = map.get(service); if (idList != null && idList.size() > 0) { for (Long compileId : idList) { - String compileStr = redisDBIndex + ":COMPILEGROUP:" + compileId; - String groupCompileStr = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系 + // String compileStr = redisDBIndex + ":COMPILEGROUP:" + compileId; + String compileStr = "COMPILEGROUP:" + compileId; + String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系 + String groupCompileStr = getRealInfo(compileStrVal); + // if (compileStrVal != null && compileStrVal.contains("-")) { + // String[] split = compileStrVal.split("-"); + // groupCompileStr = split[0];// 去除后面的redisdb信息 + // } if (groupCompileStr != null && !groupCompileStr.equals("")) { String[] groupCompileStrSplit = groupCompileStr.split(";");// 得到分组关系 for (String groupCompile : groupCompileStrSplit) {// 遍历所有分组关系 - // String compileGroupStr = redisTemplate.opsForValue() - // .get(groupCompile.toUpperCase());// 获取当前分组关系对应的编译信息 - - String compileGroupStr = JedisUtils.get(groupCompile.toUpperCase(), - idRelaRedisDBIndex);// 获取当前分组关系对应的编译信息 - + String compileGroupStr = getRealInfo( + JedisUtils.get(groupCompile.toUpperCase(), idRelaRedisDBIndex));// 获取当前分组关系对应的编译信息 if (compileGroupStr != null && !compileGroupStr.equals("")) { String[] compileGroupStrSplit = compileGroupStr.split(";"); - if (compileGroupStrSplit != null && compileGroupStrSplit.length == 1 - && compileGroupStr.equals(compileStr.toUpperCase())) {// 当前的分组关系只属于当前的compileid,说明没有被分组复用,需要将编译配置,分组关系,域配置,置无效 + // 被分组复用的业务,不能将域置为失效,其分组关系也不置为失效 + if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效 + // if (compileGroupStrSplit != null && compileGroupStrSplit.length + // == 1 + // && compileGroupStr.equals(compileStr.toUpperCase())) {// + // 当前的分组关系只属于当前的compileid,说明没有被分组复用,需要将编译配置,分组关系,域配置,置无效 if (compileGroupStrSplit[0].toUpperCase() .equals(compileStr.toUpperCase())) { - String groupRegion = groupCompile.replaceAll("GROUPCOMPILE", - "GROUPREGION"); + String groupRegion = groupCompile.replace("GROUPCOMPILE", + "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION // 删除分组与域的关联关系 if (JedisUtils.exists(groupRegion, idRelaRedisDBIndex)) { transaction.del(groupRegion); @@ -1410,34 +1459,20 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { + "号redis库中无法获取MAAT配置分组与域的关联关系,key为" + groupRegion, RestBusinessCode.KeyNotExistsInRedis.getValue()); } - // 删除分组与编译的关联关系 - if (JedisUtils.exists(groupCompile.toUpperCase(), - idRelaRedisDBIndex)) { - transaction.del(groupCompile.toUpperCase());// 删除当前组所对应的编译 - } else { - throw new ServiceRuntimeException( - "从" + idRelaRedisDBIndex - + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为" - + groupCompile.toUpperCase(), - RestBusinessCode.KeyNotExistsInRedis.getValue()); - } } - } else {// 当前的分组被复用了,属于多个编译,需要将当前的分组关系置为无效 - Set groupCompileSet = new HashSet(); - for (String compileGroup : compileGroupStrSplit) { - if (!compileGroup.equals(compileStr.toUpperCase())) { - groupCompileSet.add(compileGroup); - } - } - StringBuffer sb = new StringBuffer(); - // 更新组对应的编译 - for (String str : groupCompileSet) { - sb.append(str); - sb.append(";"); - } - transaction.set(groupCompile, sb.substring(0, sb.length() - 1)); } + // 删除分组与编译的关联关系 + if (JedisUtils.exists(groupCompile.toUpperCase(), idRelaRedisDBIndex)) { + transaction.del(groupCompile.toUpperCase());// 删除当前组所对应的编译 + } else { + throw new ServiceRuntimeException( + "从" + idRelaRedisDBIndex + + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为" + + groupCompile.toUpperCase(), + RestBusinessCode.KeyNotExistsInRedis.getValue()); + } + } else { throw new ServiceRuntimeException( "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为" @@ -1456,19 +1491,29 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { RestBusinessCode.KeyNotExistsInRedis.getValue()); } } + } else { + throw new ServiceRuntimeException( + "未从redisdb与配置id的对应关系中找到redisdb=" + redisDBIndex + "service=" + service + + "对应的配置id,请联系开发人员检查redisdb与配置id的对应关系", + RestBusinessCode.ConfigSourceIsNull.getValue()); } } + } else { + throw new ServiceRuntimeException( + "未从redisdb与配置id的对应关系中找到redisdb=" + redisDBIndex + "对应的配置id,请联系开发人员检查redisdb与配置id的对应关系", + RestBusinessCode.ConfigSourceIsNull.getValue()); } } else { throw new ServiceRuntimeException("redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号", RestBusinessCode.DbIndexNotInRange.getValue()); } - break;// map中的每个value都是一样的,而且关联关系里面只存储了一个信息, + break;// map中的每个value都是一样的,而且关联关系里面只存储了一份信息,所以不需要再遍历了 + } + return true; } else { throw new ServiceRuntimeException("状态更新操作Map参数信息不能为空,请检查配置参数是否正确", RestBusinessCode.ConfigInfoMapIsNull.getValue()); } - return null; } } 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 ffbd431..420dce2 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -26,6 +26,7 @@ import com.nis.domain.restful.CommonSourceFieldCfg; import com.nis.domain.restful.ConfigCompile; import com.nis.domain.restful.ConfigGroupRelation; import com.nis.domain.restful.DigestRegion; +import com.nis.domain.restful.GroupReuse; import com.nis.domain.restful.IpRegion; import com.nis.domain.restful.MaatConfig; import com.nis.domain.restful.NumRegion; @@ -37,6 +38,7 @@ import com.nis.util.BasicProvingUtil; import com.nis.util.CamelUnderlineUtil; import com.nis.util.CompileVal; import com.nis.util.Constants; +import com.nis.util.GroupReuseVal; import com.nis.util.JsonMapper; import com.nis.util.ReadCommSourceXmlUtil; import com.nis.util.ServiceAndRDBIndexReal; @@ -55,7 +57,7 @@ import com.nis.web.service.BaseService; public class ConfigSourcesService extends BaseService { private Map> map; - + private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Autowired @@ -70,13 +72,15 @@ public class ConfigSourcesService extends BaseService { * @return * @throws Exception */ - public static boolean isStrStrongRegion(String tableName,Integer service) throws Exception{ + public static boolean isStrStrongRegion(String tableName, Integer service) + throws Exception { if (null != tableName && !tableName.equals("")) { List tableList = new ArrayList(); - Map> sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(service); + Map> sercieNameMap = ServiceAndRDBIndexReal + .getSercieNameMap().get(service); if (sercieNameMap != null && sercieNameMap.size() > 0) { for (Integer type : sercieNameMap.keySet()) { - // 12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置, + // 12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置, if ("15".equals(type.toString())) { List tableNameList = sercieNameMap.get(type); if (tableNameList != null && tableNameList.size() > 0) { @@ -118,8 +122,9 @@ public class ConfigSourcesService extends BaseService { * @return */ public void saveMaatConfig(AuditLogThread thread, long start, - List configCompileList, StringBuffer sb) throws Exception { - Map> maatMap = new HashMap>(); + List configCompileList, StringBuffer sb) + throws Exception { + Map> maatMap = new HashMap>(); Map> configMap = new HashMap>(); for (ConfigCompile configCompile : configCompileList) { @@ -163,8 +168,7 @@ public class ConfigSourcesService extends BaseService { } maatConfig.setStrRegionMapList(dstMaplList); // 增强字符串域 - if (!StringUtil.isEmpty(strongMapList) - && strongMapList.size() > 0) { + if (!StringUtil.isEmpty(strongMapList) && strongMapList.size() > 0) { maatConfig.setStrStrRegionMapList((strongMapList)); } // 数值域 @@ -172,8 +176,8 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getNumRegionList())) { dstMaplList = new ArrayList>(); for (NumRegion region : configCompile.getNumRegionList()) { - dstMaplList.add(convertObjectToMap(region, - NumRegion.class)); + dstMaplList + .add(convertObjectToMap(region, NumRegion.class)); } } maatConfig.setNumRegionMapList(dstMaplList); @@ -183,8 +187,7 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getIpRegionList())) { dstMaplList = new ArrayList>(); for (IpRegion region : configCompile.getIpRegionList()) { - dstMaplList.add(convertObjectToMap(region, - IpRegion.class)); + dstMaplList.add(convertObjectToMap(region, IpRegion.class)); } } maatConfig.setIpRegionMapList(dstMaplList); @@ -193,8 +196,7 @@ public class ConfigSourcesService extends BaseService { dstMaplList = null; if (!StringUtil.isEmpty(configCompile.getDigestRegionList())) { dstMaplList = new ArrayList>(); - for (DigestRegion region : configCompile - .getDigestRegionList()) { + for (DigestRegion region : configCompile.getDigestRegionList()) { dstMaplList.add(convertObjectToMap(region, DigestRegion.class)); } @@ -211,8 +213,7 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getIpClientRangeList())) { dstMaplList = new ArrayList>(); for (IpRegion region : configCompile.getIpClientRangeList()) { - dstMaplList.add(convertObjectToMap(region, - IpRegion.class)); + dstMaplList.add(convertObjectToMap(region, IpRegion.class)); } } maatConfig.setIpClientRangeMapList(dstMaplList); @@ -231,8 +232,8 @@ public class ConfigSourcesService extends BaseService { Iterator serviceIterator = maatMap.keySet().iterator(); while (serviceIterator.hasNext()) { - Integer service = Integer.valueOf(serviceIterator.next() - .toString()); + Integer service = Integer + .valueOf(serviceIterator.next().toString()); List dbIndexList = ServiceAndRDBIndexReal .getRedisDBByService(service); if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) { @@ -255,16 +256,15 @@ public class ConfigSourcesService extends BaseService { .fromJsonString(JsonMapper .toJsonString(maatConfig), MaatConfig.class); - Iterator iterator = regionAndFiledMap - .keySet().iterator(); + Iterator iterator = regionAndFiledMap.keySet() + .iterator(); while (iterator.hasNext()) { String regionName = iterator.next() .toString(); PropertyDescriptor pd; try { - pd = new PropertyDescriptor( - regionName + "MapList", - MaatConfig.class); + pd = new PropertyDescriptor(regionName + + "MapList", MaatConfig.class); Method method = pd.getReadMethod(); Object object = method .invoke(newMaatConfig); @@ -280,8 +280,7 @@ public class ConfigSourcesService extends BaseService { .getCompileMap() .get(fieldName .toLowerCase()); - if (!StringUtil - .isEmpty(value)) { + if (!StringUtil.isEmpty(value)) { for (Map map : listMaps) { map.put(fieldName .toLowerCase(), @@ -293,11 +292,14 @@ public class ConfigSourcesService extends BaseService { method.invoke(newMaatConfig, listMaps); } - newMaatConfigList.set(i, - newMaatConfig); + newMaatConfigList.set(i, newMaatConfig); } catch (Exception e) { // TODO Auto-generated catch block - throw new RestServiceException("未找到域列表,请检查配置文件中域类型是否正确!:"+e.getMessage(),RestBusinessCode.service_runtime_error.getValue()); + throw new RestServiceException( + "未找到域列表,请检查配置文件中域类型是否正确!:" + + e.getMessage(), + RestBusinessCode.service_runtime_error + .getValue()); } } @@ -315,14 +317,17 @@ public class ConfigSourcesService extends BaseService { } } else { - throw new ServiceRuntimeException(RestBusinessCode.ServiceNoFoundDBIndex.getErrorReason(),RestBusinessCode.ServiceNoFoundDBIndex.getValue()); + throw new ServiceRuntimeException( + RestBusinessCode.ServiceNoFoundDBIndex.getErrorReason(), + RestBusinessCode.ServiceNoFoundDBIndex.getValue()); } } logger.info("---------------调用Redis maat配置新增接口---------------------"); configRedisService.saveMaatConfig(configMap); } - private Map convertObjectToMap(Object obj, Class clazz) throws Exception { + private Map convertObjectToMap(Object obj, Class clazz) + throws Exception { Map dstMap = new HashMap(); Field[] fields = obj.getClass().getDeclaredFields(); for (Field field : fields) { @@ -347,7 +352,8 @@ public class ConfigSourcesService extends BaseService { } public void updateConfigSources(AuditLogThread thread, long start, - List compileList, Date opTime, StringBuffer sb) throws Exception { + List compileList, Date opTime, StringBuffer sb) + throws Exception { Map> compileMap = new HashMap>(); if (null != compileList && compileList.size() > 0) { for (ConfigCompile config : compileList) { @@ -371,7 +377,7 @@ public class ConfigSourcesService extends BaseService { throw new RestServiceException("编译配置不能为空" + sb.toString(), RestBusinessCode.CompileIsNull.getValue()); } - //Map> + // Map> Map>> restMap = new HashMap>>(); Iterator serviceIterator = compileMap.keySet().iterator(); while (serviceIterator.hasNext()) { @@ -391,13 +397,15 @@ public class ConfigSourcesService extends BaseService { } } } else { - ServiceRuntimeException e = new ServiceRuntimeException("service值为" + service - + ",与写入数据库序号映射关系不存在",RestBusinessCode.ServiceNoFoundDBIndex.getValue()); + ServiceRuntimeException e = new ServiceRuntimeException( + "service值为" + service + ",与写入数据库序号映射关系不存在", + RestBusinessCode.ServiceNoFoundDBIndex.getValue()); } } - //所有的都删除成功返回true + // 所有的都删除成功返回true if (!configRedisService.delMaatConfig(restMap)) { - throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员",RestBusinessCode.service_runtime_error.getValue()); + throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员", + RestBusinessCode.service_runtime_error.getValue()); } } @@ -414,33 +422,44 @@ public class ConfigSourcesService extends BaseService { * @param config * @return */ - private void checkCompileOptForUpdate(ConfigCompile config) throws Exception{ - + private void checkCompileOptForUpdate(ConfigCompile config) + throws Exception { + if (StringUtil.isEmpty(config.getCompileId())) { - throw new RestServiceException(RestBusinessCode.CompileIdIsNull.getErrorReason(),RestBusinessCode.CompileIdIsNull.getValue()); + throw new RestServiceException( + RestBusinessCode.CompileIdIsNull.getErrorReason(), + RestBusinessCode.CompileIdIsNull.getValue()); } if (StringUtil.isEmpty(config.getService())) { - throw new RestServiceException(RestBusinessCode.ServiceIsNull.getErrorReason(),RestBusinessCode.ServiceIsNull.getValue()); + throw new RestServiceException( + RestBusinessCode.ServiceIsNull.getErrorReason(), + RestBusinessCode.ServiceIsNull.getValue()); } if (StringUtil.isEmpty(config.getIsValid())) { - throw new RestServiceException("编译配置id为" + config.getCompileId() + "的IsValid字段不能为空",RestBusinessCode.IsValidIsNull.getValue()); + throw new RestServiceException("编译配置id为" + config.getCompileId() + + "的IsValid字段不能为空", + RestBusinessCode.IsValidIsNull.getValue()); } if (config.getIsValid() != 0) { - throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效",RestBusinessCode.IsValidIsF.getValue()); + throw new RestServiceException("编译配置id为" + config.getCompileId() + + "的配置在修改时不能为有效", RestBusinessCode.IsValidIsF.getValue()); } } public void saveCommonSources(AuditLogThread thread, long start, - String jsonString) throws Exception{ + String jsonString) throws Exception { JsonArray jsonObjectList = null; try { jsonObjectList = new JsonParser().parse(jsonString) - .getAsJsonArray(); + .getAsJsonArray(); } catch (Exception e) { // TODO: handle exception - throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage(),RestBusinessCode.CBParamFormateError.getValue()); + throw new RestServiceException( + RestBusinessCode.CBParamFormateError.getErrorReason() + "," + + e.getMessage(), + RestBusinessCode.CBParamFormateError.getValue()); } - + Map>> dstMaps = new HashMap>>(); for (int i = 0; i < jsonObjectList.size(); i++) { JsonObject jsonObj = (JsonObject) jsonObjectList.get(i); @@ -452,12 +471,15 @@ public class ConfigSourcesService extends BaseService { .getCommonSourceCfgByService(srcMap.get("service") .toString().trim()); if (StringUtil.isEmpty(commonSourceFieldCfgList)) { - throw new RestServiceException(RestBusinessCode.ServiceIsWrong.getErrorReason()+",请检查service配置是否正确",RestBusinessCode.ServiceIsWrong.getValue()); + throw new RestServiceException( + RestBusinessCode.ServiceIsWrong.getErrorReason() + + ",请检查service配置是否正确", + RestBusinessCode.ServiceIsWrong.getValue()); } // 获取IP类型 Integer ipType = null; String ipTypeName = ""; - + for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { if (commonSourceFieldCfg.getDstName().equals("addr_type")) { String dstVal = srcMap.get( @@ -473,25 +495,32 @@ public class ConfigSourcesService extends BaseService { valFlag = valFlag & matcher.matches(); } if (!valFlag) { - throw new RestServiceException(RestBusinessCode.IpTypeIsWrong - .getErrorReason(),RestBusinessCode.IpTypeIsWrong.getValue()); + throw new RestServiceException( + RestBusinessCode.IpTypeIsWrong + .getErrorReason(), + RestBusinessCode.IpTypeIsWrong.getValue()); } ipType = Integer.parseInt(dstVal); } - //验证service与action是否匹配 + // 验证service与action是否匹配 if (commonSourceFieldCfg.getDstName().equals("action")) { - String dstVal = srcMap.get( - commonSourceFieldCfg.getSrcName()).toString().trim(); - if (Integer.valueOf(dstVal).compareTo(ServiceAndRDBIndexReal.getActionByService(Integer.valueOf(srcMap.get("service") - .toString().trim())))!=0) { - throw new RestServiceException(RestBusinessCode.ServiceUnmatchAction + String dstVal = srcMap + .get(commonSourceFieldCfg.getSrcName()) + .toString().trim(); + if (Integer.valueOf(dstVal).compareTo( + ServiceAndRDBIndexReal + .getActionByService(Integer + .valueOf(srcMap.get("service") + .toString().trim()))) != 0) { + throw new RestServiceException( + RestBusinessCode.ServiceUnmatchAction .getErrorReason(), RestBusinessCode.ServiceUnmatchAction .getValue()); } } } - if (ipType==null) { + if (ipType == null) { ipType = 4; } for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) { @@ -499,7 +528,8 @@ public class ConfigSourcesService extends BaseService { if (commonSourceFieldCfg.getIsRequired() && !srcMap.containsKey(commonSourceFieldCfg .getSrcName())) { - throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数不能为空", + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + "参数不能为空", RestBusinessCode.FieldIsNull.getValue()); } // 字段类型 String Number Date Ip Port @@ -513,25 +543,29 @@ public class ConfigSourcesService extends BaseService { dstStr.substring(1, dstStr.length() - 1)) .toString(); } - - if("dstFile".equals(commonSourceFieldCfg - .getSrcName())){ - if ("dst_file".equals(commonSourceFieldCfg - .getDstName())) { + + if ("dstFile".equals(commonSourceFieldCfg.getSrcName())) { + if ("dst_file" + .equals(commonSourceFieldCfg.getDstName())) { String maatTableName = ServiceAndRDBIndexReal - .getUnMaatTableName(Integer.valueOf(srcMap.get("service") - .toString().trim())); - String dstPath = Constants.MM_SAMPLE_DST_PATH.replace("{tableType}", 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")); + .getUnMaatTableName(Integer.valueOf(srcMap + .get("service").toString().trim())); + String dstPath = Constants.MM_SAMPLE_DST_PATH + .replace("{tableType}", 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")); } } switch (commonSourceFieldCfg.getFieldType()) { case "Number": if (!StringUtil.isNumeric(dstStr)) { - throw new RestServiceException(commonSourceFieldCfg.getSrcName() + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + "参数不能格式不正确,必需是数值型", RestBusinessCode.MastNumberic.getValue()); } @@ -539,37 +573,42 @@ public class ConfigSourcesService extends BaseService { case "Date": try { // sdf.setTimeZone(TimeZone.getTimeZone("UTC")); -// System.out.println("--------------------TimeZone:" -// + sdf.getTimeZone()); + // System.out.println("--------------------TimeZone:" + // + sdf.getTimeZone()); sdf.setLenient(false); Date date = sdf.parse(dstStr); dstStr = date.getTime() + "000"; } catch (ParseException e) { // TODO Auto-generated catch block - throw new RestServiceException(commonSourceFieldCfg.getSrcName() + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + "参数格式不正确或不是规范的日期串", - RestBusinessCode.MastDate.getValue()); + RestBusinessCode.MastDate.getValue()); } break; case "IP": Boolean isSrcInfo = commonSourceFieldCfg.getIsSrcInfo(); Integer valAddrType = ipType; - if (ipType.intValue()==46) { - valAddrType=isSrcInfo?4:6; - }else if (ipType.intValue()==64) { - valAddrType=isSrcInfo?6:4; - }else if (ipType.intValue()==10) { - valAddrType=null; + if (ipType.intValue() == 46) { + valAddrType = isSrcInfo ? 4 : 6; + } else if (ipType.intValue() == 64) { + valAddrType = isSrcInfo ? 6 : 4; + } else if (ipType.intValue() == 10) { + valAddrType = null; } if (!BasicProvingUtil.isIpOrIpMask(dstStr, valAddrType)) { - throw new RestServiceException(commonSourceFieldCfg.getSrcName() - + "参数格式不正确或与" + ipTypeName + "不一致",RestBusinessCode.IpIsUnMatchType.getValue()); + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + + "参数格式不正确或与" + ipTypeName + "不一致", + RestBusinessCode.IpIsUnMatchType.getValue()); } break; case "Port": if (!BasicProvingUtil.isPortOrPortMask(dstStr)) { - throw new RestServiceException(commonSourceFieldCfg.getSrcName() - + "参数不能格式不正确,不是合法的Port", RestBusinessCode.PortIsNotVal.getValue()); + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + + "参数不能格式不正确,不是合法的Port", + RestBusinessCode.PortIsNotVal.getValue()); } break; @@ -600,9 +639,13 @@ public class ConfigSourcesService extends BaseService { } } if (flag) { - throw new RestServiceException( commonSourceFieldCfg.getSrcName() - + "参数不在有效范围("+ commonSourceFieldCfg.getRange() - + ")",RestBusinessCode.ValueInWrongRange.getValue()); + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + + "参数不在有效范围(" + + commonSourceFieldCfg.getRange() + + ")", + RestBusinessCode.ValueInWrongRange + .getValue()); } } // regexp 特殊格式正则验证 @@ -616,8 +659,11 @@ public class ConfigSourcesService extends BaseService { if (valFlag) { dstMap.put(commonSourceFieldCfg.getDstName(), dstStr); } else { - throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数格式与正则(" - + commonSourceFieldCfg.getRegexp()+ ")不匹配",RestBusinessCode.ValueInWrongRegexp.getValue()); + throw new RestServiceException( + commonSourceFieldCfg.getSrcName() + "参数格式与正则(" + + commonSourceFieldCfg.getRegexp() + + ")不匹配", + RestBusinessCode.ValueInWrongRegexp.getValue()); } } if (StringUtil.isEmpty(dstMaps.get(Integer.valueOf(srcMap.get( @@ -634,7 +680,8 @@ public class ConfigSourcesService extends BaseService { } } else { - throw new RestServiceException("service参数不能为空",RestBusinessCode.ServiceIsNull.getValue()); + throw new RestServiceException("service参数不能为空", + RestBusinessCode.ServiceIsNull.getValue()); } } logger.info("------------------调用非maat配置新增接口-------------------"); @@ -657,7 +704,8 @@ public class ConfigSourcesService extends BaseService { } } } else { - throw new ServiceRuntimeException("service与写入数据库序号映射关系不存在",RestBusinessCode.ServiceNoFoundDBIndex.getValue()); + throw new ServiceRuntimeException("service与写入数据库序号映射关系不存在", + RestBusinessCode.ServiceNoFoundDBIndex.getValue()); } } @@ -677,29 +725,34 @@ public class ConfigSourcesService extends BaseService { * @throws Exception */ public void updateCommonSources(AuditLogThread thread, long start, - String jsonString, Date opTime, StringBuffer sb) throws Exception{ + String jsonString, Date opTime, StringBuffer sb) throws Exception { JsonArray jsonObjectList = null; try { jsonObjectList = new JsonParser().parse(jsonString) .getAsJsonArray(); } catch (Exception e) { // TODO: handle exception - throw new RestServiceException (RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage(),RestBusinessCode.CBParamFormateError.getValue()); + throw new RestServiceException( + RestBusinessCode.CBParamFormateError.getErrorReason() + "," + + e.getMessage(), + RestBusinessCode.CBParamFormateError.getValue()); } // Map> cfgMap = new HashMap>(); - //所有状态更新的配置isValid的值必须相同 + // 所有状态更新的配置isValid的值必须相同 Map validIdMap = new HashMap(); for (int i = 0; i < jsonObjectList.size(); i++) { JsonObject jsonObj = (JsonObject) jsonObjectList.get(i); Map srcMap = JSONObject.fromObject(JSONObject .fromObject((jsonObj.toString()))); checkOptForUpdate(srcMap); - validIdMap.put(srcMap.get("isValid").toString(), srcMap.get("isValid").toString()); + validIdMap.put(srcMap.get("isValid").toString(), + srcMap.get("isValid").toString()); Integer service = Integer.valueOf(srcMap.get("service").toString()); - - List list = ReadCommSourceXmlUtil.getCommonSourceCfgByService(service+""); - String srcName="cfgId"; + + List list = ReadCommSourceXmlUtil + .getCommonSourceCfgByService(service + ""); + String srcName = "cfgId"; for (CommonSourceFieldCfg commonSourceFieldCfg : list) { if (commonSourceFieldCfg.getIsCfgId()) { srcName = commonSourceFieldCfg.getSrcName(); @@ -715,8 +768,10 @@ public class ConfigSourcesService extends BaseService { } } - if (validIdMap.size()>1) { - throw new RestServiceException(RestBusinessCode.IsValidNonUniq.getErrorReason(), RestBusinessCode.IsValidNonUniq.getValue()); + if (validIdMap.size() > 1) { + throw new RestServiceException( + RestBusinessCode.IsValidNonUniq.getErrorReason(), + RestBusinessCode.IsValidNonUniq.getValue()); } Map>> restMap = new HashMap>>(); Iterator serviceIterator = cfgMap.keySet().iterator(); @@ -736,16 +791,19 @@ public class ConfigSourcesService extends BaseService { } } } else { - throw new ServiceRuntimeException("service与写入数据库序号映射关系不存在",RestBusinessCode.ServiceNoFoundDBIndex.getValue()); + throw new ServiceRuntimeException("service与写入数据库序号映射关系不存在", + RestBusinessCode.ServiceNoFoundDBIndex.getValue()); } } try { - //停用时isInvalid=true,启用时isInvalid = false - configRedisService.delUnMaatConfig(restMap,validIdMap.containsKey("0")?true:false); + // 停用时isInvalid=true,启用时isInvalid = false + configRedisService.delUnMaatConfig(restMap, + validIdMap.containsKey("0") ? true : false); } catch (Exception e) { // TODO: handle exception throw e; - //throw new ServiceRuntimeException(RestBusinessCode.service_runtime_error.getErrorReason(),RestBusinessCode.service_runtime_error.getValue()); + // throw new + // ServiceRuntimeException(RestBusinessCode.service_runtime_error.getErrorReason(),RestBusinessCode.service_runtime_error.getValue()); } } @@ -757,17 +815,22 @@ public class ConfigSourcesService extends BaseService { * @param srcMap * @throws Exception */ - private void checkOptForUpdate(Map srcMap) throws Exception{ + private void checkOptForUpdate(Map srcMap) throws Exception { Object service = srcMap.get("service"); Object isValid = srcMap.get("isValid"); if (StringUtil.isEmpty(service)) { - throw new RestServiceException(RestBusinessCode.ServiceIsNull.getErrorReason(),RestBusinessCode.ServiceIsNull.getValue()); + throw new RestServiceException( + RestBusinessCode.ServiceIsNull.getErrorReason(), + RestBusinessCode.ServiceIsNull.getValue()); } else if (!StringUtil.isNumeric(service.toString())) { - throw new RestServiceException("service字段格式不正确,"+RestBusinessCode.MastNumberic.getErrorReason(),RestBusinessCode.MastNumberic.getValue()); + throw new RestServiceException("service字段格式不正确," + + RestBusinessCode.MastNumberic.getErrorReason(), + RestBusinessCode.MastNumberic.getValue()); } - List list = ReadCommSourceXmlUtil.getCommonSourceCfgByService(service+""); - String srcName="cfgId"; + List list = ReadCommSourceXmlUtil + .getCommonSourceCfgByService(service + ""); + String srcName = "cfgId"; for (CommonSourceFieldCfg commonSourceFieldCfg : list) { if (commonSourceFieldCfg.getIsCfgId()) { srcName = commonSourceFieldCfg.getSrcName(); @@ -775,21 +838,29 @@ public class ConfigSourcesService extends BaseService { } Object cfgId = srcMap.get(srcName); if (StringUtil.isEmpty(cfgId)) { - throw new RestServiceException(RestBusinessCode.CfgIdIsNull.getErrorReason(),RestBusinessCode.CfgIdIsNull.getValue()); + throw new RestServiceException( + RestBusinessCode.CfgIdIsNull.getErrorReason(), + RestBusinessCode.CfgIdIsNull.getValue()); } else if (!StringUtil.isNumeric(cfgId.toString())) { - throw new RestServiceException("cfgId字段格式不正确,"+RestBusinessCode.MastNumberic.getErrorReason(),RestBusinessCode.MastNumberic.getValue()); + throw new RestServiceException("cfgId字段格式不正确," + + RestBusinessCode.MastNumberic.getErrorReason(), + RestBusinessCode.MastNumberic.getValue()); } if (StringUtil.isEmpty(isValid)) { - throw new RestServiceException("配置id为" + srcMap.get("cfgId") + "的isValid字段不能为空",RestBusinessCode.IsValidIsNull.getValue()); + throw new RestServiceException("配置id为" + srcMap.get("cfgId") + + "的isValid字段不能为空", + RestBusinessCode.IsValidIsNull.getValue()); } else { if (!StringUtil.isNumeric(service.toString())) { - throw new RestServiceException(RestBusinessCode.IsValidInWrongRange.getErrorReason(),RestBusinessCode.IsValidInWrongRange.getValue()); + throw new RestServiceException( + RestBusinessCode.IsValidInWrongRange.getErrorReason(), + RestBusinessCode.IsValidInWrongRange.getValue()); } - //配置取消改为状态更新(停/启用) -// else if (!isValid.equals("0")) { -// CompileVal.setBusinessCode(RestBusinessCode.IsValidIsF.getValue()); -// return RestBusinessCode.IsValidIsF.getErrorReason(); -// } + // 配置取消改为状态更新(停/启用) + // else if (!isValid.equals("0")) { + // CompileVal.setBusinessCode(RestBusinessCode.IsValidIsF.getValue()); + // return RestBusinessCode.IsValidIsF.getErrorReason(); + // } } } @@ -833,4 +904,307 @@ public class ConfigSourcesService extends BaseService { return null; } + /** + * + * @Description:增加分组复用域配置 + * @author (zdx) + * @date 2018年5月25日 下午3:49:46 + * @param thread + * @param start + * @param configCompileList + * @param sb + * @return + */ + public void addGroupReuseSources(AuditLogThread thread, long start, + List groupReuseList, StringBuffer sb) throws Exception { + // Map> 存放解析后输入数据 + Map> maatMap = new HashMap>(); + // Map> 存放多分发的数据 + Map> configMap = new HashMap>(); + //验证 + GroupReuseVal.valGroupReuse(groupReuseList, false); + + for (GroupReuse groupReuse : groupReuseList) { + Integer service = groupReuse.getService(); + MaatConfig maatConfig = new MaatConfig(); + maatConfig.setService(service); + List> dstMaplList = null; + // 字符串域 + List> strongMapList = null; + if (!StringUtil.isEmpty(groupReuse.getStrRegionList())) { + dstMaplList = new ArrayList>(); + for (StrRegion region : groupReuse.getStrRegionList()) { + if (StringUtil.isEmpty(region.getDistrict())) { + dstMaplList.add(convertObjectToMap(region, + StrRegion.class)); + } else { + if (StringUtil.isEmpty(strongMapList)) { + strongMapList = new ArrayList>(); + } + strongMapList.add(convertObjectToMap(region, + StrRegion.class)); + } + } + } + maatConfig.setStrRegionMapList(dstMaplList); + // 增强字符串域 + if (!StringUtil.isEmpty(strongMapList) && strongMapList.size() > 0) { + maatConfig.setStrStrRegionMapList((strongMapList)); + } + // 数值域 + dstMaplList = null; + if (!StringUtil.isEmpty(groupReuse.getNumRegionList())) { + dstMaplList = new ArrayList>(); + for (NumRegion region : groupReuse.getNumRegionList()) { + dstMaplList + .add(convertObjectToMap(region, NumRegion.class)); + } + } + maatConfig.setNumRegionMapList(dstMaplList); + + // Ip域 + dstMaplList = null; + if (!StringUtil.isEmpty(groupReuse.getIpRegionList())) { + dstMaplList = new ArrayList>(); + for (IpRegion region : groupReuse.getIpRegionList()) { + dstMaplList.add(convertObjectToMap(region, IpRegion.class)); + } + } + maatConfig.setIpRegionMapList(dstMaplList); + + if (maatMap.containsKey(service)) { + maatMap.get(service).add(maatConfig); + } else { + List maatCfgList = new ArrayList(); + maatCfgList.add(maatConfig); + maatMap.put(service, maatCfgList); + + } + } + // 调用接口入redis + // 根据service分发到各系统 + Iterator serviceIterator = maatMap.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) { + List newMaatConfigList = new ArrayList(); + newMaatConfigList.addAll(maatMap.get(service)); + if (configMap.containsKey(dbIndex)) { + configMap.get(dbIndex).addAll(newMaatConfigList); + } else { + List list = new ArrayList(); + list.addAll(newMaatConfigList); + configMap.put(dbIndex, list); + } + + } + } else { + throw new ServiceRuntimeException( + RestBusinessCode.ServiceNoFoundDBIndex.getErrorReason(), + RestBusinessCode.ServiceNoFoundDBIndex.getValue()); + } + } + logger.info("---------------调用Redis 分组复用配置新增接口---------------------"); + // configRedisService.addGroupReuseConfig(configMap); + } + + /** + * + * @Description:删除分组复用域配置 + * @author (zdx) + * @date 2018年8月23日 下午7:37:14 + * @param thread + * @param start + * @param groupReuseList + * @param opTime + * @param sb + * @throws Exception + */ + public void deleteGroupReuseSources(AuditLogThread thread, long start, + List groupReuseList, Date opTime, StringBuffer sb) + throws Exception { + //按service分类 + Map> maatMap = new HashMap>(); + + GroupReuseVal.valGroupReuse(groupReuseList, false); + for (GroupReuse groupReuse : groupReuseList) { + //验证格式 + checkGroupReuseForUpdate(groupReuse); + + Integer service = groupReuse.getService(); + MaatConfig maatConfig = new MaatConfig(); + maatConfig.setService(service); + List> dstMaplList = null; + // 字符串域 + List> strongMapList = null; + if (!StringUtil.isEmpty(groupReuse.getStrRegionList())) { + dstMaplList = new ArrayList>(); + for (StrRegion region : groupReuse.getStrRegionList()) { + if (StringUtil.isEmpty(region.getDistrict())) { + dstMaplList.add(convertObjectToMap(region, + StrRegion.class)); + } else { + if (StringUtil.isEmpty(strongMapList)) { + strongMapList = new ArrayList>(); + } + strongMapList.add(convertObjectToMap(region, + StrRegion.class)); + } + } + } + maatConfig.setStrRegionMapList(dstMaplList); + // 增强字符串域 + if (!StringUtil.isEmpty(strongMapList) && strongMapList.size() > 0) { + maatConfig.setStrStrRegionMapList((strongMapList)); + } + // 数值域 + dstMaplList = null; + if (!StringUtil.isEmpty(groupReuse.getNumRegionList())) { + dstMaplList = new ArrayList>(); + for (NumRegion region : groupReuse.getNumRegionList()) { + dstMaplList + .add(convertObjectToMap(region, NumRegion.class)); + } + } + maatConfig.setNumRegionMapList(dstMaplList); + + // Ip域 + dstMaplList = null; + if (!StringUtil.isEmpty(groupReuse.getIpRegionList())) { + dstMaplList = new ArrayList>(); + for (IpRegion region : groupReuse.getIpRegionList()) { + dstMaplList.add(convertObjectToMap(region, IpRegion.class)); + } + } + maatConfig.setIpRegionMapList(dstMaplList); + + if (maatMap.containsKey(service)) { + maatMap.get(service).add(maatConfig); + } else { + List maatCfgList = new ArrayList(); + maatCfgList.add(maatConfig); + maatMap.put(service, maatCfgList); + } + } + logger.info("调用接口删除Redis中分组复用的域配置接口"); + // 所有的都删除成功返回true +// if (!configRedisService.delMaatConfig(maatMap)) { +// throw new ServiceRuntimeException("删除分组利用域配置时出现异常,具体原因不详,请联系管理员", +// RestBusinessCode.service_runtime_error.getValue()); +// } + } + + /** + * + * @Description:验证service+regionId+isValid+tableName + * @author (zdx) + * @date 2017年8月16日 上午11:48:46 + * @param config + * @return + */ + private void checkGroupReuseForUpdate(GroupReuse config) + throws Exception { + + if (StringUtil.isEmpty(config.getService())) { + throw new RestServiceException( + RestBusinessCode.ServiceIsNull.getErrorReason(), + RestBusinessCode.ServiceIsNull.getValue()); + } + + if (!ServiceAndRDBIndexReal.serviceIsReuse(config.getService())) { + throw new RestServiceException("server为空或" + config.getService() + + "或不属于分组复用的业务类型", + RestBusinessCode.ServiceIsNullOrNotReuse.getValue()); + } + Boolean hasRegionFlag = false; + Map> regTabNameMap = ServiceAndRDBIndexReal + .getServiceGroupReuseMap(config.getService()); + if (regTabNameMap.containsKey("numRegion") + && !StringUtil.isEmpty(config.getNumRegionList()) + && config.getNumRegionList().size() > 0) { + hasRegionFlag = true; + List numRegionList = config.getNumRegionList(); + for (NumRegion numRegion : numRegionList) { + if (!StringUtil.isEmpty(numRegion.getTableName()) + && !CompileVal.type2TableNameIsOk(config.getService(), + numRegion.getTableName())) { + throw new RestServiceException("service为" + config.getService() + + "的配置中numRegionList中的regionId为" + + numRegion.getRegionId() + + "的域配置tableName与业务类型不一致", + RestBusinessCode.TableNameUnmatchService + .getValue()); + } + if (numRegion.getIsValid() != 0) { + throw new RestServiceException("service为" + config.getService() + + "的配置中numRegionList中的regionId为" + + numRegion.getRegionId() + "的域配置在修改时不能为有效", + RestBusinessCode.IsValidIsF.getValue()); + } + } + } else if (regTabNameMap.containsKey("strRegion") + && !StringUtil.isEmpty(config.getStrRegionList()) + && config.getStrRegionList().size() > 0) { + hasRegionFlag = true; + List strRegionList = config.getStrRegionList(); + for (StrRegion strRegion : strRegionList) { + // if (groupReuse.getIsValid() != 0 && + // !regionGroupIdList.contains(strRegion.getGroupId())) + // { + if (!StringUtil.isEmpty(strRegion.getTableName()) + && !CompileVal.type2TableNameIsOk(config.getService(), + strRegion.getTableName())) { + throw new RestServiceException("配置id为" + config.getService() + + "的配置中strRegionList中的regionId为" + + strRegion.getRegionId() + + "的域配置tableName与业务类型不一致", + RestBusinessCode.TableNameUnmatchService + .getValue()); + } + if (strRegion.getIsValid() != 0) { + throw new RestServiceException("配置id为" + config.getService() + + "的配置中strRegionList中的regionId为" + + strRegion.getRegionId() + "的域配置在修改时不能为有效", + RestBusinessCode.IsValidIsF.getValue()); + } + + } + } else if (regTabNameMap.containsKey("ipRegion") + && !StringUtil.isEmpty(config.getIpRegionList()) + && config.getIpRegionList().size() > 0) { + hasRegionFlag = true; + List ipRegionList = config.getIpRegionList(); + for (IpRegion ipRegion : ipRegionList) { + if (!StringUtil.isEmpty(ipRegion.getTableName()) + && !CompileVal.type2TableNameIsOk(config.getService(), + ipRegion.getTableName())) { + throw new RestServiceException("配置id为" + config.getService() + + "的配置中ipRegionList中的regionId为" + + ipRegion.getRegionId() + + "的域配置tableName与业务类型不一致", + RestBusinessCode.TableNameUnmatchService + .getValue()); + } + + if (null == ipRegion.getIsValid() || ipRegion + .getIsValid() != 0) { + throw new RestServiceException("service为" + config.getService() + + "的配置中ipRegionList中的regionId为" + + ipRegion.getRegionId() + "的域配置在修改时不能为有效", + RestBusinessCode.IsValidIsF.getValue()); + } + } + } + + if (hasRegionFlag) { + // 所有的域类型都不包括,可能是配置文件配错了 + throw new ServiceRuntimeException("service为" + config.getService() + "的" + + RestBusinessCode.ReuseRegionIsNull.getErrorReason(), + RestBusinessCode.ReuseRegionIsNull.getValue()); + } + } } diff --git a/src/main/resources/applicationConfig-rule.properties b/src/main/resources/applicationConfig-rule.properties index 9b048d0..af9085e 100644 --- a/src/main/resources/applicationConfig-rule.properties +++ b/src/main/resources/applicationConfig-rule.properties @@ -20,7 +20,7 @@ ##回流 0x60 96 loop ##白名单 0x80 128 whitelist -service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16;27:16;30:16;31:16;32:16;33:16;34:16;35:16;36:16;128:1;129:1;130:1;131:1;132:1;133:1;134:1;135:1;136:1;137:1;138:1;139:1;140:1;141:1;142:1;143:1;144:1;145:1;147:1;148:1;256:16;257:16;258:16;259:16;260:16;267:16;384:1;385:1;386:1;387:1;388:1;395:1;512:1;513:1;514:64;515:64;517:80;521:128;528:48;544:2;560:80;576:16;592:1;750:128;768:96;1024:1;1026:1;1027:1;1028:1;1029:1;1030:1;1031:1;1040:32;1041:32;1042:32;1056:64;1057:64;1058:64;1059:64;1060:64;1152:1 +service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16;27:16;30:16;31:16;32:16;33:16;34:16;35:16;36:16;37:16;128:1;129:1;130:1;131:1;132:1;133:1;134:1;135:1;136:1;137:1;138:1;139:1;140:1;141:1;142:1;143:1;144:1;145:1;147:1;148:1;149:1;256:16;257:16;258:16;259:16;260:16;267:16;384:1;385:1;386:1;387:1;388:1;395:1;512:1;513:1;514:64;515:64;517:80;521:128;528:48;544:2;560:80;576:16;592:1;750:128;768:96;1024:1;1026:1;1027:1;1028:1;1029:1;1030:1;1031:1;1040:32;1041:32;1042:32;1056:64;1059:64;1060:64;1152:1 #0x1E 0x8E 有问题:14:NTC_XMPP_REGION,NTC_XMPP_CONT 无表结构 不确定表是不是字符串类 @@ -65,6 +65,8 @@ service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16; 35=10:APP_COMPILE;11:APP_GROUP;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE #0x24 隧道行为阻断 36=10:APP_COMPILE;11:APP_GROUP;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE +#0x25 ASN IP阻断 +37=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_ASN_IP;14:APP_SUBSCRIBE_ID;18:NTC_IP_RANGE #0x80 IP地址监测 128=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_IP;14:NTC_SUBSCRIBE_ID;18:NTC_IP_RANGE @@ -104,6 +106,8 @@ service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16; 147=10:APP_COMPILE;11:APP_GROUP;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE #0x94 隧道行为监测 148=10:APP_COMPILE;11:APP_GROUP;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE +#0x95 ASN IP监测 +149=10:NTC_COMPILE;11:NTC_GROUP;12:NTC_ASN_IP;14:APP_SUBSCRIBE_ID;18:NTC_IP_RANGE #0xA0 通联关系监测 monit 无配置 #0xA1 邮件泛收 monit 无配置 @@ -190,10 +194,7 @@ service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16; #0x420 APP限流 1056=10:APP_COMPILE;11:APP_GROUP;12:NTC_UNIVERSAL_IP;13:NTC_UNIVERSAL_PROTO_TYPE;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE -#0x421 IP限流 -1057=10:LIMIT_COMPILE;11:LIMIT_GROUP;12:LIMIT_IP;14:APP_SUBSCRIBE_ID;18:NTC_IP_RANGE -#0x422 域名限流 -1058=10:LIMIT_COMPILE;11:LIMIT_GROUP;14:LIMIT_DOMAIN,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE + #0x423 基础协议限流 1059=10:APP_COMPILE;11:APP_GROUP;14:APP_POLICY,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE #0x424 隧道行为限流 @@ -201,9 +202,8 @@ service=1:128;2:128;16:16;17:16;18:16;19:16;20:16;21:16;22:16;23:16;24:16;26:16; #0x480 APP 主题网站配置 1152=10:APP_COMPILE;11:APP_GROUP;14:APP_TOPIC_DOMAIN,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE -#格式:业务类型1:动作;业务类型2:动作 ( 用于验证回调类service与action对应关系) 删除所有回调类的action属性 zdx20180821 -#unMaatService=3:32;4:96;5:32;25:32;28:32;64:16;65:16;261:16;262:16;263:16;264:16;265:16;266:16;389:1;390:1;391:1;392:1;393:1;394:1;832:96;1025:1 -unMaatService=3;4;5;25;28;64;65;261;262;263;264;265;266;389;390;391;392;393;394;520;608;832;1025 +#格式:业务类型1:动作;业务类型2:动作 ( 用于验证回调类service与action对应关系 +unMaatService=3:32;4:96;5:32;25:32;28:32;64;65;261:16;262:16;263:16;264:16;265:16;266:16;389:1;390:1;391:1;392:1;393:1;394:1;520;608;832;1025:1 #0x03 IP地址丢弃 3=0:INLINE_IP_CB #0x04 IP地址回流 @@ -282,8 +282,6 @@ unMaatService=3;4;5;25;28;64;65;261;262;263;264;265;266;389;390;391;392;393;394; #0x411 基础协议丢弃 1041:2,6,7; #0x412 隧道行为丢弃 1042:2,6,7; #0x420 APP限流 1056:2,6,7; -#0x421 IP限流 1057:6,7; -#0x422 域名限流 1058:6,2,7; #0x423 基础协议限流 1059:2,6,7; #0x424 隧道行为限流 1060:2,6,7; #0x405 SSL证书特征 1029:2,6,7; @@ -297,7 +295,7 @@ unMaatService=3;4;5;25;28;64;65;261;262;263;264;265;266;389;390;391;392;393;394; #0x19 IPSec丢弃 25:7; #0x340 IP复用地址池配置(回调)832:2,4,5,7 ########## -serviceDBIndex=1:2,3,4,6,7;2:2,3,4,6,7;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,6,7;34:2;35:2,6,7;36:2,6,7;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;141:2;142:2;143:2;144:2;145:2,6,7;147:2,6,7;148:2,6,7;256:3;257:3;258:3;259:3;260:3;267:3;384:3;385:3;386:3;387:3;388:3;395:3;512:4,7;513:4,2,7;514:4;515:4;517:4;520:4;521:4;528:4;544:4;560:4;576:4;592:4;608:4;750:4;768:5;1024:2,6,7;1024:2;1025:2;1026:2,6,7;1027:2,6,7;1028:2,6,7;1029:2,6,7;1030:2,6,7;1031:2,6,7;1040:2,6,7;1041:2,6,7;1042:2,6,7;1056:2,6,7;1057:6,7;1058:6,2,7;1059:2,6,7;1060:2,6,7;1152:2,6;3:7;4:7;5:2;25:7;28:7;64:2;65:2;261:8;262:9;263:10;264:11;265:3;266:3;389:8;390:9;391:10;392:11;393:3;394:3;832:2,4,5,7 +serviceDBIndex=1:2,3,4,6,7;2:2,3,4,6,7;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,6,7;34:2;35:2,6,7;36:2,6,7;37: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;141:2;142:2;143:2;144:2;145:2,6,7;147:2,6,7;148:2,6,7;149:2;256:3;257:3;258:3;259:3;260:3;267:3;384:3;385:3;386:3;387:3;388:3;395:3;512:4,7;513:4,2,7;514:4;515:4;517:4;520:4;521:4;528:4;544:4;560:4;576:4;592:4;608:4;750:4;768:5;1024:2,6,7;1024:2;1025:2;1026:2,6,7;1027:2,6,7;1028:2,6,7;1029:2,6,7;1030:2,6,7;1031:2,6,7;1040:2,6,7;1041:2,6,7;1042:2,6,7;1056:2,6,7;1059:2,6,7;1060:2,6,7;1152:2,6;3:7;4:7;5:2;25:7;28:7;64:2;65:2;261:8;262:9;263:10;264:11;265:3;266:3;389:8;390:9;391:10;392:11;393:3;394:3;832:2,4,5,7 ##maat配置入阀门需要将编译中的部分参数写到域配置中,目前最多包含ACTION,SERVICE,USER_REGION三个属性 @@ -314,13 +312,12 @@ serviceDBIndex=1:2,3,4,6,7;2:2,3,4,6,7;16:2;17:2;18:2;19:2;20:2;21:2;22:2;23:2;2 #0x404 APP IP特征 1028 #0x410 APP丢弃 1040 #0x420 APP限流 1056 -#0x421 IP限流 1057 -#0x422 域名限流 1058 -maat2Valve=33:strRegion@ACTION&SERVICE&USER_REGION;35:strRegion@ACTION&SERVICE&USER_REGION;36:strRegion@ACTION&SERVICE&USER_REGION;145:strRegion@ACTION&SERVICE&USER_REGION;147:strRegion@ACTION&SERVICE&USER_REGION;148:strRegion@ACTION&SERVICE&USER_REGION;512:ipRegion@ACTION&SERVICE;513:strRegion@ACTION&SERVICE&USER_REGION;1024:strRegion|strStrRegion@USER_REGION;1026:strRegion|strStrRegion@USER_REGION;1027:strRegion|strStrRegion@USER_REGION;1028:ipRegion@USER_REGION;1029:strStrRegion@USER_REGION;1030:numRegion@USER_REGION;1031:strStrRegion@USER_REGION;1040:strRegion@ACTION&SERVICE&USER_REGION;1041:strRegion@ACTION&SERVICE&USER_REGION;1042:strRegion@ACTION&SERVICE&USER_REGION;1056:strRegion@ACTION&SERVICE&USER_REGION;1057:ipRegion@ACTION&SERVICE&USER_REGION;1058:strRegion@ACTION&SERVICE&USER_REGION;1059:strRegion@ACTION&SERVICE&USER_REGION;1060:strRegion@ACTION&SERVICE&USER_REGION +maat2Valve=33:strRegion@ACTION&SERVICE&USER_REGION;35:strRegion@ACTION&SERVICE&USER_REGION;36:strRegion@ACTION&SERVICE&USER_REGION;145:strRegion@ACTION&SERVICE&USER_REGION;147:strRegion@ACTION&SERVICE&USER_REGION;148:strRegion@ACTION&SERVICE&USER_REGION;512:ipRegion@ACTION&SERVICE;513:strRegion@ACTION&SERVICE&USER_REGION;1024:strRegion|strStrRegion@USER_REGION;1026:strRegion|strStrRegion@USER_REGION;1027:strRegion|strStrRegion@USER_REGION;1028:ipRegion@USER_REGION;1029:strStrRegion@USER_REGION;1030:numRegion@USER_REGION;1031:strStrRegion@USER_REGION;1040:strRegion@ACTION&SERVICE&USER_REGION;1041:strRegion@ACTION&SERVICE&USER_REGION;1042:strRegion@ACTION&SERVICE&USER_REGION;1056:strRegion@ACTION&SERVICE&USER_REGION;1059:strRegion@ACTION&SERVICE&USER_REGION;1060:strRegion@ACTION&SERVICE&USER_REGION ##记录哪些service可以被分组复用(只有maat类配置可以被分组复用) -serviceRepeatedReal=256,257,258,259,260,267,384,385,386,387,388,395,512,513,521,528,544,560,576,592,750,768 - +#业务ID:域类型1@表名,表名|域类型2@表名;业务ID:域类型1@表名,表名|域类型2@表名 +##域类型:IP域 =ipRegion 字符串域=strRegion 数值域=numRegion +serviceRepeatedReal=37:ipRegion@NTC_ASN_IP;149:ipRegion@NTC_ASN_IP;1028:ipRegion@APP_STATIC_SER_IP diff --git a/src/main/resources/commonSources/applicationConfig-parser.xml b/src/main/resources/commonSources/applicationConfig-parser.xml index cd675ea..24eb9b5 100644 --- a/src/main/resources/commonSources/applicationConfig-parser.xml +++ b/src/main/resources/commonSources/applicationConfig-parser.xml @@ -13,7 +13,7 @@ --> - + @@ -41,7 +41,7 @@ --> - + @@ -58,7 +58,7 @@ --> - + @@ -139,9 +139,9 @@ - + - + @@ -153,7 +153,7 @@ - + diff --git a/src/main/resources/maatXml/applicationConfig-maatRedis.xml b/src/main/resources/maatXml/applicationConfig-maatRedis.xml index f4d233c..b3ffa0c 100644 --- a/src/main/resources/maatXml/applicationConfig-maatRedis.xml +++ b/src/main/resources/maatXml/applicationConfig-maatRedis.xml @@ -11,7 +11,7 @@ EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id] - [cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[op_time];&nbsp;[service];\t;0;\t;[file_id];\n + [cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[op_time];&nbsp;[service];\t;[action];\t;0;\t;[file_id];\n @@ -34,7 +34,7 @@ EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id] - [cfg_id];\t;[service];\t;[level];\t;[description];\t;[is_valid];\t;[op_time];&nbsp;0;\n + [cfg_id];\t;[service];\t;[action];\t; [level];\t;[description];\t;[is_valid];\t;[op_time];&nbsp;0;\n 1 @@ -56,7 +56,7 @@ EFFECTIVE_RULE;:;{un_maat_table_name};,;[cfg_id] - [cfg_id];\t;0;\t;[addr_type];\t;[src_ip];\t;[mask_src_ip];\t;[src_port];\t;[mask_src_port];\t;[dst_ip];\t;[mask_dst_ip];\t;[dst_port];\t;[mask_dst_port];\t;[protocol];\t;[direction];\t;[is_valid];\t;[service];\t;[op_time];&nbsp;0;\n + [cfg_id];\t;0;\t;[addr_type];\t;[src_ip];\t;[mask_src_ip];\t;[src_port];\t;[mask_src_port];\t;[dst_ip];\t;[mask_dst_ip];\t;[dst_port];\t;[mask_dst_port];\t;[protocol];\t;[direction];\t;[is_valid];\t;[action];\t;[service];\t;[op_time];&nbsp;0;\n 1 @@ -177,7 +177,7 @@ + service="1;2;16;17;18;19;20;21;22;23;24;26;27;30;31;32;33;34;35;36;37;128;129;130;131;132;133;134;135;136;137;138;139;140;141;142;143;144;145;147;148;149;256;257;258;259;260;267;384;385;386;387;388;395;512;513;514;515;517;521;528;544;560;576;592;750;768;848;1024;1026;1027;1028;1029;1030;1031;1040;1041;1042;1056;1057;1058;1059;1060;1152"> EFFECTIVE_RULE;:;{compile_table_name};,;[compile_id] [compile_id];\t;[service];\t;[action];\t;[do_blacklist];\t;[do_log];\t;[effective_range];\t;[user_region];\t;[is_valid];\t;[group_num];\t;[father_cfg_id];\t;[op_time];&nbsp;0;\n