2017-12-19 14:55:52 +08:00
|
|
|
|
package com.nis.web.service.restful;
|
|
|
|
|
|
|
2018-05-25 19:37:05 +08:00
|
|
|
|
import java.beans.PropertyDescriptor;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
import java.lang.reflect.Method;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.HashMap;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.util.Iterator;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
2018-06-04 15:14:52 +08:00
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
|
|
import com.nis.domain.restful.CommonSourceFieldCfg;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.domain.restful.ConfigCompile;
|
|
|
|
|
|
import com.nis.domain.restful.ConfigGroupRelation;
|
2018-02-28 10:13:39 +08:00
|
|
|
|
import com.nis.domain.restful.DigestRegion;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.domain.restful.IpRegion;
|
2018-05-25 19:37:05 +08:00
|
|
|
|
import com.nis.domain.restful.MaatConfig;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.domain.restful.NumRegion;
|
|
|
|
|
|
import com.nis.domain.restful.StrRegion;
|
|
|
|
|
|
import com.nis.restful.RestBusinessCode;
|
|
|
|
|
|
import com.nis.restful.RestServiceException;
|
2018-08-03 18:08:46 +08:00
|
|
|
|
import com.nis.restful.ServiceRuntimeException;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.nis.util.BasicProvingUtil;
|
2018-05-25 19:37:05 +08:00
|
|
|
|
import com.nis.util.CamelUnderlineUtil;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.util.CompileVal;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
import com.nis.util.Constants;
|
2018-06-28 18:52:23 +08:00
|
|
|
|
import com.nis.util.JsonMapper;
|
2018-05-24 17:22:38 +08:00
|
|
|
|
import com.nis.util.ReadCommSourceXmlUtil;
|
2018-06-01 10:27:03 +08:00
|
|
|
|
import com.nis.util.ServiceAndRDBIndexReal;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.util.StringUtil;
|
2018-08-03 18:08:46 +08:00
|
|
|
|
import com.nis.web.service.AuditLogThread;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @ClassName: ControlService
|
|
|
|
|
|
* @Description: TODO(编译配置持久化)
|
|
|
|
|
|
* @author (zx)
|
|
|
|
|
|
* @date 2016年9月6日 下午1:08:12
|
|
|
|
|
|
* @version V1.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class ConfigSourcesService extends BaseService {
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Integer, Map<String, String>> map;
|
2018-08-10 15:14:12 +08:00
|
|
|
|
|
2018-06-22 10:48:53 +08:00
|
|
|
|
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
ConfigRedisService configRedisService;
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
public static boolean isStrStrongRegion(String tableName,Integer service) throws Exception{
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (null != tableName && !tableName.equals("")) {
|
|
|
|
|
|
List<String> tableList = new ArrayList<String>();
|
2018-07-18 13:15:29 +08:00
|
|
|
|
Map<Integer, List<String>> sercieNameMap = ServiceAndRDBIndexReal.getSercieNameMap().get(service);
|
|
|
|
|
|
if (sercieNameMap != null && sercieNameMap.size() > 0) {
|
|
|
|
|
|
for (Integer type : sercieNameMap.keySet()) {
|
|
|
|
|
|
String typeStr="";
|
|
|
|
|
|
// 12代表是ip类域配置,13代表是数值类配置,14代表是字符串类域配置,15代表是增强字符串类域配置,
|
|
|
|
|
|
if ("15".equals(type.toString())) {
|
|
|
|
|
|
List<String> tableNameList = sercieNameMap.get(type);
|
|
|
|
|
|
if (tableNameList != null && tableNameList.size() > 0) {
|
|
|
|
|
|
for (String table : tableNameList) {
|
|
|
|
|
|
tableList.add(table.toUpperCase());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (tableList.contains(tableName)) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Map<Integer, Map<String, String>> getMap() {
|
|
|
|
|
|
return map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setMap(Map<Integer, Map<String, String>> map) {
|
|
|
|
|
|
this.map = map;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-05-25 19:37:05 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @Description:
|
|
|
|
|
|
* @author (zdx)
|
|
|
|
|
|
* @date 2018年5月25日 下午3:49:46
|
|
|
|
|
|
* @param thread
|
|
|
|
|
|
* @param start
|
|
|
|
|
|
* @param configCompileList
|
|
|
|
|
|
* @param sb
|
|
|
|
|
|
* @return
|
2017-12-19 14:55:52 +08:00
|
|
|
|
*/
|
2018-08-10 15:14:12 +08:00
|
|
|
|
public void saveMaatConfig(AuditLogThread thread, long start,
|
|
|
|
|
|
List<ConfigCompile> configCompileList, StringBuffer sb) throws Exception {
|
2018-07-17 18:16:49 +08:00
|
|
|
|
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
|
2018-07-04 17:03:04 +08:00
|
|
|
|
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
|
2018-05-25 19:37:05 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
for (ConfigCompile configCompile : configCompileList) {
|
|
|
|
|
|
Integer service = Integer.valueOf(configCompile.getService()
|
|
|
|
|
|
.toString());
|
|
|
|
|
|
MaatConfig maatConfig = new MaatConfig();
|
|
|
|
|
|
CompileVal.compileIsOk(configCompile, false, sb);
|
|
|
|
|
|
|
|
|
|
|
|
maatConfig.setService(service);
|
|
|
|
|
|
// 编译
|
|
|
|
|
|
maatConfig.setCompileMap(convertObjectToMap(configCompile,
|
|
|
|
|
|
ConfigCompile.class));
|
|
|
|
|
|
// 分组
|
|
|
|
|
|
List<Map<String, String>> dstMaplList = null;
|
|
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getGroupRelationList())) {
|
|
|
|
|
|
dstMaplList = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
for (ConfigGroupRelation group : configCompile
|
|
|
|
|
|
.getGroupRelationList()) {
|
|
|
|
|
|
dstMaplList.add(convertObjectToMap(group,
|
|
|
|
|
|
ConfigGroupRelation.class));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
maatConfig.setGroupMapList(dstMaplList);
|
|
|
|
|
|
// 字符串域
|
|
|
|
|
|
dstMaplList = null;
|
|
|
|
|
|
List<Map<String, String>> strongMapList = null;
|
|
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getStrRegionList())) {
|
|
|
|
|
|
dstMaplList = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
for (StrRegion region : configCompile.getStrRegionList()) {
|
|
|
|
|
|
if (StringUtil.isEmpty(region.getDistrict())) {
|
|
|
|
|
|
dstMaplList.add(convertObjectToMap(region,
|
|
|
|
|
|
StrRegion.class));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (StringUtil.isEmpty(strongMapList)) {
|
|
|
|
|
|
strongMapList = new ArrayList<Map<String, String>>();
|
2018-07-04 17:03:04 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
strongMapList.add(convertObjectToMap(region,
|
|
|
|
|
|
StrRegion.class));
|
2018-05-25 19:37:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
maatConfig.setStrRegionMapList(dstMaplList);
|
|
|
|
|
|
// 增强字符串域
|
|
|
|
|
|
if (!StringUtil.isEmpty(strongMapList)
|
|
|
|
|
|
&& strongMapList.size() > 0) {
|
|
|
|
|
|
maatConfig.setStrStrRegionMapList((strongMapList));
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
// 数值域
|
|
|
|
|
|
dstMaplList = null;
|
|
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getNumRegionList())) {
|
|
|
|
|
|
dstMaplList = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
for (NumRegion region : configCompile.getNumRegionList()) {
|
|
|
|
|
|
dstMaplList.add(convertObjectToMap(region,
|
|
|
|
|
|
NumRegion.class));
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
maatConfig.setNumRegionMapList(dstMaplList);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
// Ip域
|
|
|
|
|
|
dstMaplList = null;
|
|
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getIpRegionList())) {
|
|
|
|
|
|
dstMaplList = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
for (IpRegion region : configCompile.getIpRegionList()) {
|
|
|
|
|
|
dstMaplList.add(convertObjectToMap(region,
|
|
|
|
|
|
IpRegion.class));
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
maatConfig.setIpRegionMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
// 摘要类域
|
|
|
|
|
|
dstMaplList = null;
|
|
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getDigestRegionList())) {
|
|
|
|
|
|
dstMaplList = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
for (DigestRegion region : configCompile
|
|
|
|
|
|
.getDigestRegionList()) {
|
|
|
|
|
|
dstMaplList.add(convertObjectToMap(region,
|
|
|
|
|
|
DigestRegion.class));
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
maatConfig.setFileDigestRegionMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
// 文本相似性域
|
|
|
|
|
|
// dstMaplList = null;
|
|
|
|
|
|
// maatConfig.setFileLikeRegionMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
// 生效范围IP域
|
|
|
|
|
|
dstMaplList = null;
|
|
|
|
|
|
if (!StringUtil.isEmpty(configCompile.getIpClientRangeList())) {
|
|
|
|
|
|
dstMaplList = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
for (IpRegion region : configCompile.getIpClientRangeList()) {
|
|
|
|
|
|
dstMaplList.add(convertObjectToMap(region,
|
|
|
|
|
|
IpRegion.class));
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
maatConfig.setIpClientRangeMapList(dstMaplList);
|
|
|
|
|
|
|
|
|
|
|
|
if (maatMap.containsKey(service)) {
|
|
|
|
|
|
maatMap.get(service).add(maatConfig);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<MaatConfig> maatCfgList = new ArrayList<MaatConfig>();
|
|
|
|
|
|
maatCfgList.add(maatConfig);
|
|
|
|
|
|
maatMap.put(service, maatCfgList);
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
// 调用接口入redis
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
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 (dbIndex.intValue() == ServiceAndRDBIndexReal
|
|
|
|
|
|
.getValveDBIndex().intValue()) {
|
|
|
|
|
|
Map<Integer, Map<String, String[]>> maatToValueMap = ServiceAndRDBIndexReal
|
|
|
|
|
|
.getMaatToValveMap();
|
|
|
|
|
|
if (maatToValueMap.containsKey(service)) {
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String[]> regionAndFiledMap = maatToValueMap
|
|
|
|
|
|
.get(service);
|
|
|
|
|
|
// for (MaatConfig maatConfig :
|
|
|
|
|
|
// newMaatConfigList) {
|
|
|
|
|
|
for (int i = 0; i < newMaatConfigList.size(); i++) {
|
|
|
|
|
|
MaatConfig maatConfig = newMaatConfigList
|
|
|
|
|
|
.get(i);
|
|
|
|
|
|
MaatConfig newMaatConfig = (MaatConfig) JsonMapper
|
|
|
|
|
|
.fromJsonString(JsonMapper
|
|
|
|
|
|
.toJsonString(maatConfig),
|
|
|
|
|
|
MaatConfig.class);
|
|
|
|
|
|
Iterator iterator = regionAndFiledMap
|
|
|
|
|
|
.keySet().iterator();
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
|
|
String regionName = iterator.next()
|
|
|
|
|
|
.toString();
|
|
|
|
|
|
PropertyDescriptor pd;
|
|
|
|
|
|
try {
|
|
|
|
|
|
pd = new PropertyDescriptor(
|
|
|
|
|
|
regionName + "MapList",
|
|
|
|
|
|
MaatConfig.class);
|
|
|
|
|
|
Method method = pd.getReadMethod();
|
|
|
|
|
|
Object object = method
|
|
|
|
|
|
.invoke(newMaatConfig);
|
|
|
|
|
|
|
|
|
|
|
|
if (object != null) {
|
|
|
|
|
|
|
|
|
|
|
|
List<Map<String, String>> listMaps = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
listMaps.addAll((List<Map<String, String>>) object);
|
|
|
|
|
|
String[] fields = regionAndFiledMap
|
|
|
|
|
|
.get(regionName);
|
|
|
|
|
|
for (String fieldName : fields) {
|
|
|
|
|
|
String value = newMaatConfig
|
|
|
|
|
|
.getCompileMap()
|
|
|
|
|
|
.get(fieldName
|
|
|
|
|
|
.toLowerCase());
|
|
|
|
|
|
if (!StringUtil
|
|
|
|
|
|
.isEmpty(value)) {
|
|
|
|
|
|
for (Map<String, String> map : listMaps) {
|
|
|
|
|
|
map.put(fieldName
|
|
|
|
|
|
.toLowerCase(),
|
|
|
|
|
|
value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
method = pd.getWriteMethod();
|
|
|
|
|
|
method.invoke(newMaatConfig,
|
|
|
|
|
|
listMaps);
|
|
|
|
|
|
}
|
|
|
|
|
|
newMaatConfigList.set(i,
|
|
|
|
|
|
newMaatConfig);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
|
throw new RestServiceException("未找到域列表,请检查配置文件中域类型是否正确!:"+e.getMessage(),RestBusinessCode.service_runtime_error.getValue());
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-02-28 10:13:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
if (configMap.containsKey(dbIndex)) {
|
|
|
|
|
|
configMap.get(dbIndex).addAll(newMaatConfigList);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<MaatConfig> list = new ArrayList<MaatConfig>();
|
|
|
|
|
|
list.addAll(newMaatConfigList);
|
|
|
|
|
|
configMap.put(dbIndex, list);
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
throw new ServiceRuntimeException(RestBusinessCode.ServiceNoFoundDBIndex.getErrorReason(),RestBusinessCode.ServiceNoFoundDBIndex.getValue());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
logger.info("---------------调用Redis maat配置新增接口---------------------");
|
|
|
|
|
|
configRedisService.saveMaatConfig(configMap);
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
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) {
|
|
|
|
|
|
if ("serialVersionUID".equals(field.getName()))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
String dstName = CamelUnderlineUtil.camelToUnderline(field
|
|
|
|
|
|
.getName());
|
|
|
|
|
|
PropertyDescriptor pd;
|
|
|
|
|
|
pd = new PropertyDescriptor(field.getName(), clazz);
|
|
|
|
|
|
Method method = pd.getReadMethod();
|
|
|
|
|
|
Object dstObject = method.invoke(obj);
|
|
|
|
|
|
if (dstObject instanceof Date) {
|
|
|
|
|
|
dstObject = convertToTimeStamp16((Date) dstObject);
|
2018-02-28 10:13:39 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
if (dstObject instanceof ArrayList) {
|
|
|
|
|
|
dstObject = "";
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
dstMap.put(dstName,
|
|
|
|
|
|
StringUtil.isEmpty(dstObject) ? "" : dstObject.toString());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
return dstMap;
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
public void updateConfigSources(AuditLogThread thread, long start,
|
|
|
|
|
|
List<ConfigCompile> compileList, Date opTime, StringBuffer sb) throws Exception {
|
|
|
|
|
|
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (null != compileList && compileList.size() > 0) {
|
|
|
|
|
|
for (ConfigCompile config : compileList) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
checkCompileOptForUpdate(config);
|
2018-07-04 17:03:04 +08:00
|
|
|
|
if (config.getOpTime() == null) {
|
2017-12-22 15:22:11 +08:00
|
|
|
|
config.setOpTime(opTime);
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
// compileAllList.add(config);
|
|
|
|
|
|
if (compileMap.containsKey(config.getService())) {
|
|
|
|
|
|
compileMap.get(config.getService()).add(
|
|
|
|
|
|
config.getCompileId());
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<Long> idList = new ArrayList<Long>();
|
|
|
|
|
|
idList.add(config.getCompileId());
|
|
|
|
|
|
compileMap.put(config.getService(), idList);
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException("编译配置不能为空" + sb.toString(),
|
|
|
|
|
|
RestBusinessCode.CompileIsNull.getValue());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
//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()) {
|
|
|
|
|
|
Integer service = Integer
|
|
|
|
|
|
.valueOf(serviceIterator.next().toString());
|
|
|
|
|
|
List<Integer> dbIndexList = ServiceAndRDBIndexReal
|
|
|
|
|
|
.getRedisDBByService(service);
|
|
|
|
|
|
if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) {
|
|
|
|
|
|
for (Integer dbIndex : dbIndexList) {
|
|
|
|
|
|
if (restMap.containsKey(dbIndex)) {
|
|
|
|
|
|
restMap.get(dbIndex).put(service,
|
|
|
|
|
|
compileMap.get(service));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
|
|
|
|
|
|
map.put(service, compileMap.get(service));
|
|
|
|
|
|
restMap.put(dbIndex, map);
|
|
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
ServiceRuntimeException e = new ServiceRuntimeException("service值为" + service
|
|
|
|
|
|
+ ",与写入数据库序号映射关系不存在",RestBusinessCode.ServiceNoFoundDBIndex.getValue());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
//所有的都删除成功返回true
|
|
|
|
|
|
if (!configRedisService.delMaatConfig(restMap)) {
|
|
|
|
|
|
throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员",RestBusinessCode.service_runtime_error.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String convertToTimeStamp16(Date date) {
|
|
|
|
|
|
// sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
|
|
|
|
return date.getTime() + "000";
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* @Description:验证compileId+isValid
|
|
|
|
|
|
* @author (zdx)
|
|
|
|
|
|
* @date 2017年8月16日 上午11:48:46
|
|
|
|
|
|
* @param config
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-08-10 15:14:12 +08:00
|
|
|
|
private void checkCompileOptForUpdate(ConfigCompile config) throws Exception{
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (StringUtil.isEmpty(config.getCompileId())) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.CompileIdIsNull.getErrorReason(),RestBusinessCode.CompileIdIsNull.getValue());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (StringUtil.isEmpty(config.getService())) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.ServiceIsNull.getErrorReason(),RestBusinessCode.ServiceIsNull.getValue());
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
if (StringUtil.isEmpty(config.getIsValid())) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException("编译配置id为" + config.getCompileId() + "的IsValid字段不能为空",RestBusinessCode.IsValidIsNull.getValue());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (config.getIsValid() != 0) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效",RestBusinessCode.IsValidIsF.getValue());
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
public void saveCommonSources(AuditLogThread thread, long start,
|
|
|
|
|
|
String jsonString) throws Exception{
|
2018-08-03 18:08:46 +08:00
|
|
|
|
JsonArray jsonObjectList = null;
|
|
|
|
|
|
try {
|
|
|
|
|
|
jsonObjectList = new JsonParser().parse(jsonString)
|
2018-07-04 17:03:04 +08:00
|
|
|
|
.getAsJsonArray();
|
2018-08-03 18:08:46 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// TODO: handle exception
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage(),RestBusinessCode.CBParamFormateError.getValue());
|
2018-08-03 18:08:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-04 17:03:04 +08:00
|
|
|
|
Map<Integer, List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String, String>>>();
|
2018-05-24 17:22:38 +08:00
|
|
|
|
for (int i = 0; i < jsonObjectList.size(); i++) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
JsonObject jsonObj = (JsonObject) jsonObjectList.get(i);
|
|
|
|
|
|
Map<String, Object> srcMap = JSONObject.fromObject(JSONObject
|
|
|
|
|
|
.fromObject((jsonObj.toString())));
|
|
|
|
|
|
if (srcMap.containsKey("service")) {
|
|
|
|
|
|
Map<String, String> dstMap = new HashMap<String, String>();
|
|
|
|
|
|
List<CommonSourceFieldCfg> commonSourceFieldCfgList = ReadCommSourceXmlUtil
|
|
|
|
|
|
.getCommonSourceCfgByService(srcMap.get("service")
|
|
|
|
|
|
.toString().trim());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
if (StringUtil.isEmpty(commonSourceFieldCfgList)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.ServiceIsWrong.getErrorReason()+",请检查service配置是否正确",RestBusinessCode.ServiceIsWrong.getValue());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// 获取IP类型
|
2018-06-07 18:37:30 +08:00
|
|
|
|
Integer ipType = null;
|
2018-07-04 17:03:04 +08:00
|
|
|
|
String ipTypeName = "";
|
2018-07-06 18:07:16 +08:00
|
|
|
|
|
|
|
|
|
|
Integer action = null;
|
2018-06-07 18:37:30 +08:00
|
|
|
|
for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) {
|
2018-07-13 12:06:34 +08:00
|
|
|
|
if (commonSourceFieldCfg.getDstName().equals("addr_type")) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
String dstVal = srcMap.get(
|
|
|
|
|
|
commonSourceFieldCfg.getSrcName()).toString();
|
2018-06-07 18:37:30 +08:00
|
|
|
|
ipTypeName = commonSourceFieldCfg.getSrcName();
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// regexp 特殊格式正则验证
|
2018-06-07 18:37:30 +08:00
|
|
|
|
Boolean valFlag = true;
|
2018-07-04 17:03:04 +08:00
|
|
|
|
if (!StringUtil.isEmpty(commonSourceFieldCfg
|
|
|
|
|
|
.getRegexp())) {
|
|
|
|
|
|
Pattern pattern = Pattern
|
|
|
|
|
|
.compile(commonSourceFieldCfg.getRegexp());
|
2018-06-07 18:37:30 +08:00
|
|
|
|
Matcher matcher = pattern.matcher(dstVal);
|
2018-07-04 17:03:04 +08:00
|
|
|
|
valFlag = valFlag & matcher.matches();
|
2018-06-07 18:37:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (!valFlag) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.IpTypeIsWrong
|
|
|
|
|
|
.getErrorReason(),RestBusinessCode.IpTypeIsWrong.getValue());
|
2018-06-07 18:37:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
ipType = Integer.parseInt(dstVal);
|
|
|
|
|
|
}
|
2018-07-06 18:07:16 +08:00
|
|
|
|
//验证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) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.ServiceUnmatchAction
|
2018-07-06 18:07:16 +08:00
|
|
|
|
.getErrorReason(),
|
|
|
|
|
|
RestBusinessCode.ServiceUnmatchAction
|
|
|
|
|
|
.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-07 18:37:30 +08:00
|
|
|
|
}
|
2018-07-13 12:06:34 +08:00
|
|
|
|
if (ipType==null) {
|
|
|
|
|
|
ipType = 4;
|
|
|
|
|
|
}
|
2018-05-24 17:22:38 +08:00
|
|
|
|
for (CommonSourceFieldCfg commonSourceFieldCfg : commonSourceFieldCfgList) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// 是否必填
|
|
|
|
|
|
if (commonSourceFieldCfg.getIsRequired()
|
|
|
|
|
|
&& !srcMap.containsKey(commonSourceFieldCfg
|
|
|
|
|
|
.getSrcName())) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数不能为空",
|
2018-07-04 17:03:04 +08:00
|
|
|
|
RestBusinessCode.FieldIsNull.getValue());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// 字段类型 String Number Date Ip Port
|
|
|
|
|
|
String dstStr = StringUtil.isEmpty(srcMap
|
|
|
|
|
|
.get(commonSourceFieldCfg.getSrcName())) ? commonSourceFieldCfg
|
|
|
|
|
|
.getDefaultVal() : srcMap.get(
|
|
|
|
|
|
commonSourceFieldCfg.getSrcName()).toString();
|
|
|
|
|
|
if (!StringUtil.isEmpty(dstStr) && dstStr.startsWith("[")
|
|
|
|
|
|
&& dstStr.endsWith("]")) {
|
|
|
|
|
|
dstStr = srcMap.get(
|
|
|
|
|
|
dstStr.substring(1, dstStr.length() - 1))
|
|
|
|
|
|
.toString();
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-07-17 14:38:25 +08:00
|
|
|
|
|
|
|
|
|
|
if("dstFile".equals(commonSourceFieldCfg
|
|
|
|
|
|
.getSrcName())){
|
|
|
|
|
|
if ("dst_file".equals(commonSourceFieldCfg
|
|
|
|
|
|
.getDstName())) {
|
|
|
|
|
|
String maatTableName = ServiceAndRDBIndexReal
|
|
|
|
|
|
.getUnMaatTableName(Integer.valueOf(srcMap.get("service")
|
|
|
|
|
|
.toString().trim()));
|
2018-07-17 17:59:07 +08:00
|
|
|
|
String dstPath = Constants.MM_SAMPLE_DST_PATH.replace("{tableType}", maatTableName.substring(maatTableName.lastIndexOf("_")+1));
|
2018-07-17 18:33:01 +08:00
|
|
|
|
dstStr=dstPath.replace("{fileName}", dstStr.substring(dstStr.lastIndexOf("/")+1));
|
2018-07-17 14:38:25 +08:00
|
|
|
|
}else if ("file_id".equals(commonSourceFieldCfg
|
|
|
|
|
|
.getDstName())) {
|
2018-07-18 09:53:17 +08:00
|
|
|
|
dstStr= dstStr.substring(dstStr.indexOf("group"));
|
2018-07-17 14:38:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-05-24 17:22:38 +08:00
|
|
|
|
switch (commonSourceFieldCfg.getFieldType()) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
case "Number":
|
|
|
|
|
|
if (!StringUtil.isNumeric(dstStr)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(commonSourceFieldCfg.getSrcName()
|
2018-07-04 17:03:04 +08:00
|
|
|
|
+ "参数不能格式不正确,必需是数值型",
|
|
|
|
|
|
RestBusinessCode.MastNumberic.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Date":
|
|
|
|
|
|
try {
|
|
|
|
|
|
// sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
2018-08-10 15:14:12 +08:00
|
|
|
|
// System.out.println("--------------------TimeZone:"
|
|
|
|
|
|
// + sdf.getTimeZone());
|
|
|
|
|
|
sdf.setLenient(false);
|
2018-07-04 17:03:04 +08:00
|
|
|
|
Date date = sdf.parse(dstStr);
|
|
|
|
|
|
dstStr = date.getTime() + "000";
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
// TODO Auto-generated catch block
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(commonSourceFieldCfg.getSrcName()
|
|
|
|
|
|
+ "参数格式不正确或不是规范的日期串",
|
2018-07-04 17:03:04 +08:00
|
|
|
|
RestBusinessCode.MastDate.getValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2018-07-13 12:06:34 +08:00
|
|
|
|
case "IP":
|
2018-07-20 17:56:31 +08:00
|
|
|
|
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 (!BasicProvingUtil.isIpOrIpMask(dstStr, valAddrType)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(commonSourceFieldCfg.getSrcName()
|
|
|
|
|
|
+ "参数格式不正确或与" + ipTypeName + "不一致",RestBusinessCode.IpIsUnMatchType.getValue());
|
2018-07-04 17:03:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "Port":
|
|
|
|
|
|
if (!BasicProvingUtil.isPortOrPortMask(dstStr)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(commonSourceFieldCfg.getSrcName()
|
|
|
|
|
|
+ "参数不能格式不正确,不是合法的Port", RestBusinessCode.PortIsNotVal.getValue());
|
2018-07-04 17:03:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// range取值范围验证
|
|
|
|
|
|
if (!StringUtil.isEmpty(commonSourceFieldCfg.getRange())) {
|
|
|
|
|
|
String[] range = commonSourceFieldCfg.getRange().split(
|
|
|
|
|
|
"-");
|
2018-06-22 10:48:53 +08:00
|
|
|
|
Boolean flag = false;
|
2018-07-04 17:03:04 +08:00
|
|
|
|
if (range.length == 2) {
|
|
|
|
|
|
if (!(Long.valueOf(range[0]).compareTo(
|
|
|
|
|
|
Long.valueOf(dstStr)) <= 0 && Long.valueOf(
|
|
|
|
|
|
range[1]).compareTo(Long.valueOf(dstStr)) >= 0)) {
|
2018-06-22 10:48:53 +08:00
|
|
|
|
flag = true;
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
|
|
|
|
|
} else if (commonSourceFieldCfg.getRange().startsWith(
|
|
|
|
|
|
"-")) {// 只有最大值限制
|
|
|
|
|
|
if (Long.valueOf(range[0]).compareTo(
|
|
|
|
|
|
Long.valueOf(dstStr)) <= 0) {
|
2018-06-22 10:48:53 +08:00
|
|
|
|
flag = true;
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else if (commonSourceFieldCfg.getRange()
|
|
|
|
|
|
.endsWith("-")) {// 只有最小值限制
|
|
|
|
|
|
if (Long.valueOf(range[0]).compareTo(
|
|
|
|
|
|
Long.valueOf(dstStr)) >= 0) {
|
2018-06-22 10:48:53 +08:00
|
|
|
|
flag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (flag) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException( commonSourceFieldCfg.getSrcName()
|
|
|
|
|
|
+ "参数不在有效范围("+ commonSourceFieldCfg.getRange()
|
|
|
|
|
|
+ ")",RestBusinessCode.ValueInWrongRange.getValue());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// regexp 特殊格式正则验证
|
2018-05-24 17:22:38 +08:00
|
|
|
|
Boolean valFlag = true;
|
2018-07-04 17:03:04 +08:00
|
|
|
|
if (!StringUtil.isEmpty(commonSourceFieldCfg.getRegexp())) {
|
|
|
|
|
|
Pattern pattern = Pattern.compile(commonSourceFieldCfg
|
|
|
|
|
|
.getRegexp());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
Matcher matcher = pattern.matcher(dstStr);
|
2018-07-04 17:03:04 +08:00
|
|
|
|
valFlag = valFlag & matcher.matches();
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (valFlag) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
dstMap.put(commonSourceFieldCfg.getDstName(), dstStr);
|
|
|
|
|
|
} else {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(commonSourceFieldCfg.getSrcName() + "参数格式与正则("
|
|
|
|
|
|
+ commonSourceFieldCfg.getRegexp()+ ")不匹配",RestBusinessCode.ValueInWrongRegexp.getValue());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
if (StringUtil.isEmpty(dstMaps.get(Integer.valueOf(srcMap.get(
|
|
|
|
|
|
"service").toString())))) {
|
|
|
|
|
|
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
|
2018-05-24 17:22:38 +08:00
|
|
|
|
list.add(dstMap);
|
2018-07-04 17:03:04 +08:00
|
|
|
|
dstMaps.put(
|
|
|
|
|
|
Integer.valueOf(srcMap.get("service").toString()),
|
|
|
|
|
|
list);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<Map<String, String>> list = dstMaps.get(Integer
|
|
|
|
|
|
.valueOf(srcMap.get("service").toString()));
|
2018-05-24 17:22:38 +08:00
|
|
|
|
list.add(dstMap);
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException("service参数不能为空",RestBusinessCode.ServiceIsNull.getValue());
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-17 18:16:49 +08:00
|
|
|
|
logger.info("------------------调用非maat配置新增接口-------------------");
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// 按service分库
|
2018-06-01 10:27:03 +08:00
|
|
|
|
Map<Integer, List<Map<String, String>>> configMap = new HashMap<Integer, List<Map<String, String>>>();
|
|
|
|
|
|
Iterator serviceIterator = dstMaps.keySet().iterator();
|
|
|
|
|
|
while (serviceIterator.hasNext()) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
Integer service = Integer
|
|
|
|
|
|
.valueOf(serviceIterator.next().toString());
|
|
|
|
|
|
List<Integer> dbIndexList = ServiceAndRDBIndexReal
|
|
|
|
|
|
.getRedisDBByService(service);
|
|
|
|
|
|
if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) {
|
2018-06-04 17:52:20 +08:00
|
|
|
|
for (Integer dbIndex : dbIndexList) {
|
|
|
|
|
|
if (configMap.containsKey(dbIndex)) {
|
|
|
|
|
|
configMap.get(dbIndex).addAll(dstMaps.get(service));
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else {
|
2018-06-04 17:52:20 +08:00
|
|
|
|
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
|
|
|
|
|
|
list.addAll(dstMaps.get(service));
|
|
|
|
|
|
configMap.put(dbIndex, list);
|
|
|
|
|
|
}
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new ServiceRuntimeException("service与写入数据库序号映射关系不存在",RestBusinessCode.ServiceNoFoundDBIndex.getValue());
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-08-10 15:14:12 +08:00
|
|
|
|
configRedisService.saveUnMaatConfig(configMap);
|
2018-05-24 17:22:38 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
public void updateCommonSources(AuditLogThread thread, long start,
|
|
|
|
|
|
String jsonString, Date opTime, StringBuffer sb) throws Exception{
|
2018-06-04 15:14:52 +08:00
|
|
|
|
JsonArray jsonObjectList = null;
|
|
|
|
|
|
try {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
jsonObjectList = new JsonParser().parse(jsonString)
|
|
|
|
|
|
.getAsJsonArray();
|
2018-06-04 15:14:52 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// TODO: handle exception
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException (RestBusinessCode.CBParamFormateError.getErrorReason()+","+e.getMessage(),RestBusinessCode.CBParamFormateError.getValue());
|
2018-06-04 15:14:52 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// <service,cfgIdList>
|
2018-06-02 13:01:27 +08:00
|
|
|
|
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();
|
2018-07-17 17:59:07 +08:00
|
|
|
|
//所有状态更新的配置isValid的值必须相同
|
|
|
|
|
|
Map<String, String> validIdMap = new HashMap<String, String>();
|
2018-06-04 15:14:52 +08:00
|
|
|
|
for (int i = 0; i < jsonObjectList.size(); i++) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
JsonObject jsonObj = (JsonObject) jsonObjectList.get(i);
|
|
|
|
|
|
Map<String, Object> srcMap = JSONObject.fromObject(JSONObject
|
|
|
|
|
|
.fromObject((jsonObj.toString())));
|
2018-08-10 15:14:12 +08:00
|
|
|
|
checkOptForUpdate(srcMap);
|
2018-07-17 17:59:07 +08:00
|
|
|
|
validIdMap.put(srcMap.get("isValid").toString(), srcMap.get("isValid").toString());
|
2018-06-04 15:14:52 +08:00
|
|
|
|
Integer service = Integer.valueOf(srcMap.get("service").toString());
|
|
|
|
|
|
Long cfgId = Long.valueOf(srcMap.get("cfgId").toString());
|
|
|
|
|
|
if (cfgMap.containsKey(service)) {
|
|
|
|
|
|
cfgMap.get(service).add(cfgId);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
List<Long> idList = new ArrayList<Long>();
|
|
|
|
|
|
idList.add(cfgId);
|
|
|
|
|
|
cfgMap.put(service, idList);
|
2018-06-02 13:01:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-07-17 17:59:07 +08:00
|
|
|
|
if (validIdMap.size()>1) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.IsValidNonUniq.getErrorReason(), RestBusinessCode.IsValidNonUniq.getValue());
|
2018-07-17 17:59:07 +08:00
|
|
|
|
}
|
2018-06-02 13:01:27 +08:00
|
|
|
|
Map<Integer, Map<Integer, List<Long>>> restMap = new HashMap<Integer, Map<Integer, List<Long>>>();
|
|
|
|
|
|
Iterator serviceIterator = cfgMap.keySet().iterator();
|
|
|
|
|
|
while (serviceIterator.hasNext()) {
|
2018-07-04 17:03:04 +08:00
|
|
|
|
Integer service = Integer
|
|
|
|
|
|
.valueOf(serviceIterator.next().toString());
|
|
|
|
|
|
List<Integer> dbIndexList = ServiceAndRDBIndexReal
|
|
|
|
|
|
.getRedisDBByService(service);
|
|
|
|
|
|
if (!StringUtil.isEmpty(dbIndexList) && dbIndexList.size() > 0) {
|
2018-06-04 17:52:20 +08:00
|
|
|
|
for (Integer dbIndex : dbIndexList) {
|
|
|
|
|
|
if (restMap.containsKey(dbIndex)) {
|
|
|
|
|
|
restMap.get(dbIndex).put(service, cfgMap.get(service));
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else {
|
2018-06-04 17:52:20 +08:00
|
|
|
|
Map<Integer, List<Long>> map = new HashMap<Integer, List<Long>>();
|
|
|
|
|
|
map.put(service, cfgMap.get(service));
|
|
|
|
|
|
restMap.put(dbIndex, map);
|
|
|
|
|
|
}
|
2018-06-02 13:01:27 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new ServiceRuntimeException("service与写入数据库序号映射关系不存在",RestBusinessCode.ServiceNoFoundDBIndex.getValue());
|
2018-06-02 13:01:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-11 15:06:47 +08:00
|
|
|
|
try {
|
2018-07-17 17:59:07 +08:00
|
|
|
|
configRedisService.delUnMaatConfig(restMap,validIdMap.containsKey("0")?true:false);
|
2018-06-11 15:06:47 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// TODO: handle exception
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new ServiceRuntimeException(RestBusinessCode.service_runtime_error.getErrorReason(),RestBusinessCode.service_runtime_error.getValue());
|
2018-06-11 15:06:47 +08:00
|
|
|
|
}
|
2018-06-02 13:01:27 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-08-10 15:14:12 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* @Description:对回调类配置状态更新操作数据进行格式验证
|
|
|
|
|
|
* @author (zdx)
|
|
|
|
|
|
* @date 2018年8月10日 下午3:00:13
|
|
|
|
|
|
* @param srcMap
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void checkOptForUpdate(Map<String, Object> srcMap) throws Exception{
|
2018-06-04 15:14:52 +08:00
|
|
|
|
String cfgId = srcMap.get("cfgId").toString();
|
|
|
|
|
|
String service = srcMap.get("service").toString();
|
|
|
|
|
|
String isValid = srcMap.get("isValid").toString();
|
|
|
|
|
|
if (StringUtil.isEmpty(cfgId)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.CfgIdIsNull.getErrorReason(),RestBusinessCode.CfgIdIsNull.getValue());
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else if (!StringUtil.isNumeric(cfgId)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException("cfgId字段格式不正确,"+RestBusinessCode.MastNumberic.getErrorReason(),RestBusinessCode.MastNumberic.getValue());
|
2018-06-02 13:01:27 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-06-04 15:14:52 +08:00
|
|
|
|
if (StringUtil.isEmpty(service)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.ServiceIsNull.getErrorReason(),RestBusinessCode.ServiceIsNull.getValue());
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else if (!StringUtil.isNumeric(service)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException("service字段格式不正确,"+RestBusinessCode.MastNumberic.getErrorReason(),RestBusinessCode.MastNumberic.getValue());
|
2018-06-02 13:01:27 +08:00
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2018-06-04 15:14:52 +08:00
|
|
|
|
if (StringUtil.isEmpty(isValid)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException("配置id为" + srcMap.get("cfgId") + "的isValid字段不能为空",RestBusinessCode.IsValidIsNull.getValue());
|
2018-07-04 17:03:04 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
if (!StringUtil.isNumeric(service)) {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
throw new RestServiceException(RestBusinessCode.IsValidInWrongRange.getErrorReason(),RestBusinessCode.IsValidInWrongRange.getValue());
|
2018-06-04 15:14:52 +08:00
|
|
|
|
}
|
2018-07-17 17:59:07 +08:00
|
|
|
|
//配置取消改为状态更新(停/启用)
|
|
|
|
|
|
// else if (!isValid.equals("0")) {
|
|
|
|
|
|
// CompileVal.setBusinessCode(RestBusinessCode.IsValidIsF.getValue());
|
|
|
|
|
|
// return RestBusinessCode.IsValidIsF.getErrorReason();
|
|
|
|
|
|
// }
|
2018-06-02 13:01:27 +08:00
|
|
|
|
}
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-04 17:03:04 +08:00
|
|
|
|
public String getDigestGen(String realPath, String filePath)
|
|
|
|
|
|
throws Exception {
|
2018-08-10 15:14:12 +08:00
|
|
|
|
logger.info("----------------开始获取摘要:getDigestGen");
|
2018-07-04 17:03:04 +08:00
|
|
|
|
String content = "";
|
|
|
|
|
|
String digestGenToolPath = Constants.DIGEST_GEN_TOOL_PATH;
|
|
|
|
|
|
String chmodCommond = "chmod +x " + realPath + digestGenToolPath;// 执行权限命令
|
|
|
|
|
|
// System.out.println("----------------chmodCommod:"+chmodCommond);
|
|
|
|
|
|
String commondStr = realPath + digestGenToolPath + " -f " + filePath; // 执行
|
|
|
|
|
|
// 执行摘要获取命令 digest -f /home/aa.txt
|
|
|
|
|
|
// System.out.println("------------commondStr:"+commondStr);
|
2018-06-01 10:27:03 +08:00
|
|
|
|
Runtime.getRuntime().exec(chmodCommond);
|
2018-07-04 17:03:04 +08:00
|
|
|
|
Process p = Runtime.getRuntime().exec(commondStr);
|
|
|
|
|
|
byte[] b = new byte[1024];
|
|
|
|
|
|
StringBuffer sb = new StringBuffer();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
while (p.getInputStream().read(b) != -1) {
|
|
|
|
|
|
sb.append(new String(b, "UTF-8"));
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
content = sb.toString();
|
2018-06-01 10:27:03 +08:00
|
|
|
|
if (!StringUtil.isBlank(content)) {
|
|
|
|
|
|
content = StringUtil.stripAll(content);
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
// System.out.println("-------------------->>"+content);
|
|
|
|
|
|
String[] digestGenReslt = content.split(" ");
|
|
|
|
|
|
if (digestGenReslt.length >= 4
|
|
|
|
|
|
&& !StringUtil.isEmpty(digestGenReslt[3])) {
|
|
|
|
|
|
return digestGenReslt[3];
|
2018-06-01 10:27:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2018-07-04 17:03:04 +08:00
|
|
|
|
|
2017-12-19 14:55:52 +08:00
|
|
|
|
}
|