1:删除一下业务0x421,0x422
action:1057:64;1058:64; #0x421 IP限流 20180824虎哥群里面发的需要删除这个业务 1057=10:LIMIT_COMPILE;11:LIMIT_GROUP;12:LIMIT_IP;14:APP_SUBSCRIBE_ID;18:NTC_IP_RANGE #0x422 域名限流20180824虎哥群里面发的需要删除这个业务 1058=10:LIMIT_COMPILE;11:LIMIT_GROUP;14:LIMIT_DOMAIN,APP_SUBSCRIBE_ID;18:NTC_IP_RANGE 1057:ipRegion@ACTION&SERVICE&USER_REGION;1058:strRegion@ACTION&SERVICE&USER_REGION; 2:扩展编译,分组,域等对应关系,以支持分组复用业务的下发和取消 3:修改#0x208(520)表PXY_OBJ_KEYRING中crl字段为字符串类型
This commit is contained in:
103
src/main/java/com/nis/domain/restful/GroupReuse.java
Normal file
103
src/main/java/com/nis/domain/restful/GroupReuse.java
Normal file
@@ -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<StrRegion> strRegionList;
|
||||
|
||||
@ApiModelProperty(value = "IP域分组列表", required = true)
|
||||
private List<IpRegion> ipRegionList;
|
||||
|
||||
@ApiModelProperty(value = "数值域分组列表", required = true)
|
||||
private List<NumRegion> numRegionList;
|
||||
|
||||
/**
|
||||
* @return service
|
||||
*/
|
||||
public Integer getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param service
|
||||
* 要设置的 service
|
||||
*/
|
||||
public void setService(Integer service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return strRegionList
|
||||
*/
|
||||
public List<StrRegion> getStrRegionList() {
|
||||
return strRegionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strRegionList
|
||||
* 要设置的 strRegionList
|
||||
*/
|
||||
public void setStrRegionList(List<StrRegion> strRegionList) {
|
||||
this.strRegionList = strRegionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ipRegionList
|
||||
*/
|
||||
public List<IpRegion> getIpRegionList() {
|
||||
return ipRegionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ipRegionList
|
||||
* 要设置的 ipRegionList
|
||||
*/
|
||||
public void setIpRegionList(List<IpRegion> ipRegionList) {
|
||||
this.ipRegionList = ipRegionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return numRegionList
|
||||
*/
|
||||
@ApiModelProperty(value = "数值域分组列表", required = true)
|
||||
public List<NumRegion> getNumRegionList() {
|
||||
return numRegionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numRegionList
|
||||
* 要设置的 numRegionList
|
||||
*/
|
||||
public void setNumRegionList(List<NumRegion> numRegionList) {
|
||||
this.numRegionList = numRegionList;
|
||||
}
|
||||
|
||||
}
|
||||
119
src/main/java/com/nis/domain/restful/GroupReuseSource.java
Normal file
119
src/main/java/com/nis/domain/restful/GroupReuseSource.java
Normal file
@@ -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<GroupReuse> 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<GroupReuse> getGroupReuseList() {
|
||||
return groupReuseList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groupReuseList the groupReuseList to set
|
||||
*/
|
||||
public void setGroupReuseList(List<GroupReuse> groupReuseList) {
|
||||
this.groupReuseList = groupReuseList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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中缺少编译配置信息
|
||||
|
||||
@@ -132,7 +132,8 @@ public class CompileVal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//只有分组复用的业务类型,域可以不埴写,其他的maat配置至少填写一个域配置
|
||||
Boolean hasRegionFlag = false;
|
||||
List<Long> regionGroupIdList = new ArrayList<Long>();// 所有域配置中groupId的集合,不重复
|
||||
List<NumRegion> 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<IpRegion> 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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
551
src/main/java/com/nis/util/GroupReuseVal.java
Normal file
551
src/main/java/com/nis/util/GroupReuseVal.java
Normal file
@@ -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<GroupReuse> 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<String, List<String>> regTabNameMap = ServiceAndRDBIndexReal
|
||||
.getServiceGroupReuseMap(service);
|
||||
// 验证各类型域配置
|
||||
Boolean hasRegionFlag = false;
|
||||
if (regTabNameMap.containsKey("numRegion")
|
||||
&& !StringUtil.isEmpty(groupReuse.getNumRegionList())
|
||||
&& groupReuse.getNumRegionList().size() > 0) {
|
||||
hasRegionFlag = true;
|
||||
List<NumRegion> 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<StrRegion> 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<IpRegion> 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,8 +26,9 @@ public class ServiceAndRDBIndexReal {
|
||||
private static Logger logger = LoggerFactory.getLogger(ServiceAndRDBIndexReal.class);
|
||||
/**
|
||||
* 记录哪些service可以被分组复用(只有maat类配置可以被分组复用)
|
||||
* Map<Service,Map<regionName,List<tableName>>
|
||||
*/
|
||||
private static Set<Integer> serviceRepeatedRealSet = new HashSet<Integer>();
|
||||
private static Map<Integer,Map<String, List<String>>> serviceGroupReuseMap = new HashMap<Integer, Map<String,List<String>>>();
|
||||
|
||||
/**
|
||||
* 第一个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<String,List<String>> regTabMap = new HashMap<String, List<String>>();
|
||||
List<String> tabList = new ArrayList<String>();
|
||||
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<Integer, String> unMaatSercieNameMap) {
|
||||
ServiceAndRDBIndexReal.unMaatSercieNameMap = unMaatSercieNameMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the serviceGroupReuseMap
|
||||
*/
|
||||
public static Map<String, List<String>> getServiceGroupReuseMap(Integer service) {
|
||||
return serviceGroupReuseMap.get(service);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<GroupReuse> 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Integer> redisDBSet = configMap.keySet();// 所有的redisdb
|
||||
String redisDBSetStr = "-" + redisDBSet.toString().replace("[", "").replace("]", "");
|
||||
for (Integer redisDBIndex : redisDBSet) {
|
||||
if (redisDBIndex >= 0 && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) {
|
||||
List<MaatConfig> maatConfigList = configMap.get(redisDBIndex);
|
||||
@@ -218,25 +217,28 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
List<Map<String, String>> groupMapList = maatConfig.getGroupMapList();
|
||||
if (groupMapList != null && groupMapList.size() > 0) {
|
||||
for (Map<String, String> 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<String> list = new ArrayList<String>();
|
||||
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<String> list = new ArrayList<String>();
|
||||
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<String> list = map.get(groupIdStr);
|
||||
@@ -439,7 +442,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService {
|
||||
*/
|
||||
private Map<String, List<String>> addGroupAndRegionRelations(MaatXmlConfig maatXmlConfig, int service, int type,
|
||||
List<Map<String, String>> regionMapList, Map<String, List<String>> groupAndRegionMap, int redisDBIndex,
|
||||
String compileId) {
|
||||
String compileId, String redisDBSetStr) {
|
||||
if (regionMapList != null && regionMapList.size() > 0) {
|
||||
for (Map<String, String> map : regionMapList) {
|
||||
List<MaatXmlExpr> 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<String> list = new ArrayList<String>();
|
||||
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<Integer, Map<Integer, List<Long>>> 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<Integer, List<Long>> 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<Long> 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<Long> 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<MaatXmlExpr> 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<Integer, Map<Integer, List<Long>>> idMap, Transaction transaction) {
|
||||
private boolean delStatisticsReal(Map<Integer, Map<Integer, List<Long>>> 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<Integer, Map<Integer, List<Long>>> idMap, Transaction transaction) {
|
||||
private boolean delMaatRelation(Map<Integer, Map<Integer, List<Long>>> 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<Integer, List<Long>> map = idMap.get(redisDBIndex);
|
||||
Map<Integer, List<Long>> map = idMap.get(redisDBIndex);// 获取service和配置id的对应关系
|
||||
if (map != null && map.size() > 0) {
|
||||
for (Integer service : map.keySet()) {
|
||||
List<Long> 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<String> groupCompileSet = new HashSet<String>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Integer, Map<String, String>> 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<String> tableList = new ArrayList<String>();
|
||||
Map<Integer, List<String>> sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(service);
|
||||
Map<Integer, List<String>> 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<String> 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<ConfigCompile> configCompileList, StringBuffer sb) throws Exception {
|
||||
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
List<ConfigCompile> configCompileList, StringBuffer sb)
|
||||
throws Exception {
|
||||
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
|
||||
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<Map<String, String>>();
|
||||
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<Map<String, String>>();
|
||||
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<Map<String, String>>();
|
||||
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<Map<String, String>>();
|
||||
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<Integer> 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<String, String> 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<String, String> convertObjectToMap(Object obj, Class clazz) throws Exception {
|
||||
private Map<String, String> convertObjectToMap(Object obj, Class clazz)
|
||||
throws Exception {
|
||||
Map<String, String> dstMap = new HashMap<String, String>();
|
||||
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<ConfigCompile> compileList, Date opTime, StringBuffer sb) throws Exception {
|
||||
List<ConfigCompile> compileList, Date opTime, StringBuffer sb)
|
||||
throws Exception {
|
||||
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
|
||||
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<DBIndex,Map<Service,List<CompileId>>
|
||||
// Map<DBIndex,Map<Service,List<CompileId>>
|
||||
Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
|
||||
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<Integer, List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String, String>>>();
|
||||
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());
|
||||
}
|
||||
// <service,cfgIdList>
|
||||
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();
|
||||
//所有状态更新的配置isValid的值必须相同
|
||||
// 所有状态更新的配置isValid的值必须相同
|
||||
Map<String, String> validIdMap = new HashMap<String, String>();
|
||||
for (int i = 0; i < jsonObjectList.size(); i++) {
|
||||
JsonObject jsonObj = (JsonObject) jsonObjectList.get(i);
|
||||
Map<String, Object> 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<CommonSourceFieldCfg> list = ReadCommSourceXmlUtil.getCommonSourceCfgByService(service+"");
|
||||
String srcName="cfgId";
|
||||
|
||||
List<CommonSourceFieldCfg> 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<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
|
||||
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<String, Object> srcMap) throws Exception{
|
||||
private void checkOptForUpdate(Map<String, Object> 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<CommonSourceFieldCfg> list = ReadCommSourceXmlUtil.getCommonSourceCfgByService(service+"");
|
||||
String srcName="cfgId";
|
||||
List<CommonSourceFieldCfg> 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<GroupReuse> groupReuseList, StringBuffer sb) throws Exception {
|
||||
// Map<service,List<maat配置>> 存放解析后输入数据
|
||||
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
// Map<service,List<maat配置>> 存放多分发的数据
|
||||
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
//验证
|
||||
GroupReuseVal.valGroupReuse(groupReuseList, false);
|
||||
|
||||
for (GroupReuse groupReuse : groupReuseList) {
|
||||
Integer service = groupReuse.getService();
|
||||
MaatConfig maatConfig = new MaatConfig();
|
||||
maatConfig.setService(service);
|
||||
List<Map<String, String>> dstMaplList = null;
|
||||
// 字符串域
|
||||
List<Map<String, String>> strongMapList = null;
|
||||
if (!StringUtil.isEmpty(groupReuse.getStrRegionList())) {
|
||||
dstMaplList = new ArrayList<Map<String, String>>();
|
||||
for (StrRegion region : groupReuse.getStrRegionList()) {
|
||||
if (StringUtil.isEmpty(region.getDistrict())) {
|
||||
dstMaplList.add(convertObjectToMap(region,
|
||||
StrRegion.class));
|
||||
} else {
|
||||
if (StringUtil.isEmpty(strongMapList)) {
|
||||
strongMapList = new ArrayList<Map<String, String>>();
|
||||
}
|
||||
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<Map<String, String>>();
|
||||
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<Map<String, String>>();
|
||||
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<MaatConfig> maatCfgList = new ArrayList<MaatConfig>();
|
||||
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<Integer> dbIndexList = ServiceAndRDBIndexReal
|
||||
.getRedisDBByService(service);
|
||||
if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) {
|
||||
for (Integer dbIndex : dbIndexList) {
|
||||
List<MaatConfig> newMaatConfigList = new ArrayList<MaatConfig>();
|
||||
newMaatConfigList.addAll(maatMap.get(service));
|
||||
if (configMap.containsKey(dbIndex)) {
|
||||
configMap.get(dbIndex).addAll(newMaatConfigList);
|
||||
} else {
|
||||
List<MaatConfig> list = new ArrayList<MaatConfig>();
|
||||
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<GroupReuse> groupReuseList, Date opTime, StringBuffer sb)
|
||||
throws Exception {
|
||||
//按service分类
|
||||
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
||||
|
||||
GroupReuseVal.valGroupReuse(groupReuseList, false);
|
||||
for (GroupReuse groupReuse : groupReuseList) {
|
||||
//验证格式
|
||||
checkGroupReuseForUpdate(groupReuse);
|
||||
|
||||
Integer service = groupReuse.getService();
|
||||
MaatConfig maatConfig = new MaatConfig();
|
||||
maatConfig.setService(service);
|
||||
List<Map<String, String>> dstMaplList = null;
|
||||
// 字符串域
|
||||
List<Map<String, String>> strongMapList = null;
|
||||
if (!StringUtil.isEmpty(groupReuse.getStrRegionList())) {
|
||||
dstMaplList = new ArrayList<Map<String, String>>();
|
||||
for (StrRegion region : groupReuse.getStrRegionList()) {
|
||||
if (StringUtil.isEmpty(region.getDistrict())) {
|
||||
dstMaplList.add(convertObjectToMap(region,
|
||||
StrRegion.class));
|
||||
} else {
|
||||
if (StringUtil.isEmpty(strongMapList)) {
|
||||
strongMapList = new ArrayList<Map<String, String>>();
|
||||
}
|
||||
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<Map<String, String>>();
|
||||
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<Map<String, String>>();
|
||||
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<MaatConfig> maatCfgList = new ArrayList<MaatConfig>();
|
||||
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<String, List<String>> regTabNameMap = ServiceAndRDBIndexReal
|
||||
.getServiceGroupReuseMap(config.getService());
|
||||
if (regTabNameMap.containsKey("numRegion")
|
||||
&& !StringUtil.isEmpty(config.getNumRegionList())
|
||||
&& config.getNumRegionList().size() > 0) {
|
||||
hasRegionFlag = true;
|
||||
List<NumRegion> 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<StrRegion> 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<IpRegion> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user