Merge branch 'develop' into feature_enhance_interface

This commit is contained in:
pbting 2019-09-06 13:27:52 +08:00 committed by GitHub
commit 2431edae4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 29 deletions

View File

@ -62,5 +62,9 @@
<artifactId>spring-test</artifactId> <artifactId>spring-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -23,7 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import com.google.common.base.Objects;
/** /**
* @author nkorange * @author nkorange
@ -138,7 +138,7 @@ public abstract class AbstractHealthChecker implements Cloneable {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(path, headers, expectedResponseCode); return Objects.hashCode(path, headers, expectedResponseCode);
} }
@Override @Override
@ -184,7 +184,7 @@ public abstract class AbstractHealthChecker implements Cloneable {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(TYPE); return Objects.hashCode(TYPE);
} }
@Override @Override
@ -250,7 +250,7 @@ public abstract class AbstractHealthChecker implements Cloneable {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(user, pwd, cmd); return Objects.hashCode(user, pwd, cmd);
} }
@Override @Override

View File

@ -435,7 +435,7 @@ public class ConfigController {
defaultValue = StringUtils.EMPTY) String tenant, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "ids", required = false)List<Long> ids) { @RequestParam(value = "ids", required = false)List<Long> ids) {
ids.removeAll(Collections.singleton(null)); ids.removeAll(Collections.singleton(null));
List<ConfigInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids); List<ConfigAllInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>(); List<ZipUtils.ZipItem> zipItemList = new ArrayList<>();
StringBuilder metaData = null; StringBuilder metaData = null;
for(ConfigInfo ci : dataList){ for(ConfigInfo ci : dataList){
@ -482,7 +482,7 @@ public class ConfigController {
return ResultBuilder.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData); return ResultBuilder.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData);
} }
} }
List<ConfigInfo> configInfoList = null; List<ConfigAllInfo> configInfoList = null;
try { try {
ZipUtils.UnZipResult unziped = ZipUtils.unzip(file.getBytes()); ZipUtils.UnZipResult unziped = ZipUtils.unzip(file.getBytes());
ZipUtils.ZipItem metaDataZipItem = unziped.getMetaDataItem(); ZipUtils.ZipItem metaDataZipItem = unziped.getMetaDataItem();
@ -516,7 +516,7 @@ public class ConfigController {
+ "~" + tempDataId.substring(tempDataId.lastIndexOf(".") + 1); + "~" + tempDataId.substring(tempDataId.lastIndexOf(".") + 1);
} }
String metaDataId = group + "." + tempDataId + ".app"; String metaDataId = group + "." + tempDataId + ".app";
ConfigInfo ci = new ConfigInfo(); ConfigAllInfo ci = new ConfigAllInfo();
ci.setTenant(namespace); ci.setTenant(namespace);
ci.setGroup(group); ci.setGroup(group);
ci.setDataId(dataId); ci.setDataId(dataId);
@ -570,18 +570,19 @@ public class ConfigController {
} }
ids.removeAll(Collections.singleton(null)); ids.removeAll(Collections.singleton(null));
List<ConfigInfo> queryedDataList = persistService.findAllConfigInfo4Export(null,null, null, null, ids); List<ConfigAllInfo> queryedDataList = persistService.findAllConfigInfo4Export(null,null, null, null, ids);
if(queryedDataList == null || queryedDataList.isEmpty()){ if(queryedDataList == null || queryedDataList.isEmpty()){
failedData.put("succCount", 0); failedData.put("succCount", 0);
return ResultBuilder.buildResult(ResultCodeEnum.DATA_EMPTY, failedData); return ResultBuilder.buildResult(ResultCodeEnum.DATA_EMPTY, failedData);
} }
List<ConfigInfo> configInfoList4Clone = new ArrayList<>(queryedDataList.size()); List<ConfigAllInfo> configInfoList4Clone = new ArrayList<>(queryedDataList.size());
for(ConfigInfo ci : queryedDataList){ for(ConfigAllInfo ci : queryedDataList){
ConfigInfo ci4save = new ConfigInfo(); ConfigAllInfo ci4save = new ConfigAllInfo();
ci4save.setTenant(namespace); ci4save.setTenant(namespace);
ci4save.setType(ci.getType());
ci4save.setGroup(ci.getGroup()); ci4save.setGroup(ci.getGroup());
ci4save.setDataId(ci.getDataId()); ci4save.setDataId(ci.getDataId());
ci4save.setContent(ci.getContent()); ci4save.setContent(ci.getContent());

View File

@ -72,7 +72,7 @@ public class PersistService {
private DataSourceService dataSourceService; private DataSourceService dataSourceService;
private static final String SQL_FIND_ALL_CONFIG_INFO = "select data_id,group_id,tenant_id,app_name,content,type from config_info"; private static final String SQL_FIND_ALL_CONFIG_INFO = "select id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,c_schema from config_info";
private static final String SQL_TENANT_INFO_COUNT_BY_TENANT_ID = "select count(1) from tenant_info where tenant_id = ?"; private static final String SQL_TENANT_INFO_COUNT_BY_TENANT_ID = "select count(1) from tenant_info where tenant_id = ?";
@ -3419,7 +3419,7 @@ public class PersistService {
* @param group * @param group
* @return Collection of ConfigInfo objects * @return Collection of ConfigInfo objects
*/ */
public List<ConfigInfo> findAllConfigInfo4Export(final String dataId, final String group, final String tenant, public List<ConfigAllInfo> findAllConfigInfo4Export(final String dataId, final String group, final String tenant,
final String appName, final List<Long> ids) { final String appName, final List<Long> ids) {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant; String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
StringBuilder where = new StringBuilder(" where "); StringBuilder where = new StringBuilder(" where ");
@ -3451,7 +3451,7 @@ public class PersistService {
} }
} }
try { try {
return this.jt.query(SQL_FIND_ALL_CONFIG_INFO + where, paramList.toArray(), CONFIG_INFO_ROW_MAPPER); return this.jt.query(SQL_FIND_ALL_CONFIG_INFO + where, paramList.toArray(), CONFIG_ALL_INFO_ROW_MAPPER);
} catch (CannotGetJdbcConnectionException e) { } catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error] " + e.toString(), e); fatalLog.error("[db-error] " + e.toString(), e);
throw e; throw e;
@ -3466,7 +3466,7 @@ public class PersistService {
* failData: import failed data (only with abort for the same configs) * failData: import failed data (only with abort for the same configs)
* skipData: data skipped at import (only with skip for the same configs) * skipData: data skipped at import (only with skip for the same configs)
*/ */
public Map<String, Object> batchInsertOrUpdate(List<ConfigInfo> configInfoList, String srcUser, String srcIp, public Map<String, Object> batchInsertOrUpdate(List<ConfigAllInfo> configInfoList, String srcUser, String srcIp,
Map<String, Object> configAdvanceInfo, Timestamp time, boolean notify, SameConfigPolicy policy) throws NacosException { Map<String, Object> configAdvanceInfo, Timestamp time, boolean notify, SameConfigPolicy policy) throws NacosException {
int succCount = 0; int succCount = 0;
int skipCount = 0; int skipCount = 0;
@ -3474,7 +3474,7 @@ public class PersistService {
List<Map<String, String>> skipData = null; List<Map<String, String>> skipData = null;
for (int i = 0; i < configInfoList.size(); i++) { for (int i = 0; i < configInfoList.size(); i++) {
ConfigInfo configInfo = configInfoList.get(i); ConfigAllInfo configInfo = configInfoList.get(i);
try { try {
ParamUtils.checkParam(configInfo.getDataId(), configInfo.getGroup(), "datumId", configInfo.getContent()); ParamUtils.checkParam(configInfo.getDataId(), configInfo.getGroup(), "datumId", configInfo.getContent());
} catch (NacosException e) { } catch (NacosException e) {
@ -3484,14 +3484,16 @@ public class PersistService {
ConfigInfo configInfo2Save = new ConfigInfo(configInfo.getDataId(), configInfo.getGroup(), ConfigInfo configInfo2Save = new ConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), configInfo.getAppName(), configInfo.getContent()); configInfo.getTenant(), configInfo.getAppName(), configInfo.getContent());
// simple judgment of file type based on suffix String type = configInfo.getType();
String type = null; if (StringUtils.isBlank(type)) {
if (configInfo.getDataId().contains(SPOT)) { // simple judgment of file type based on suffix
String extName = configInfo.getDataId().substring(configInfo.getDataId().lastIndexOf(SPOT) + 1).toLowerCase(); if (configInfo.getDataId().contains(SPOT)) {
try { String extName = configInfo.getDataId().substring(configInfo.getDataId().lastIndexOf(SPOT) + 1).toUpperCase();
type = FileTypeEnum.valueOf(extName).getFileType(); try {
} catch (Exception ex) { type = FileTypeEnum.valueOf(extName).getFileType();
type = FileTypeEnum.TEXT.getFileType(); } catch (Exception ex) {
type = FileTypeEnum.TEXT.getFileType();
}
} }
} }
if (configAdvanceInfo == null) { if (configAdvanceInfo == null) {

View File

@ -50,7 +50,7 @@ public class HealthCheckProcessorDelegate implements HealthCheckProcessor {
String type = task.getCluster().getHealthChecker().getType(); String type = task.getCluster().getHealthChecker().getType();
HealthCheckProcessor processor = healthCheckProcessorMap.get(type); HealthCheckProcessor processor = healthCheckProcessorMap.get(type);
if(processor == null){ if(processor == null){
processor = healthCheckProcessorMap.get("none"); processor = healthCheckProcessorMap.get(NoneHealthCheckProcessor.TYPE);
} }
processor.process(task); processor.process(task);

View File

@ -47,6 +47,8 @@ import static com.alibaba.nacos.naming.misc.Loggers.SRV_LOG;
@Component @Component
public class HttpHealthCheckProcessor implements HealthCheckProcessor { public class HttpHealthCheckProcessor implements HealthCheckProcessor {
public static final String TYPE = "HTTP";
@Autowired @Autowired
private SwitchDomain switchDomain; private SwitchDomain switchDomain;
@ -79,7 +81,7 @@ public class HttpHealthCheckProcessor implements HealthCheckProcessor {
@Override @Override
public String getType() { public String getType() {
return "HTTP"; return TYPE;
} }
@Override @Override

View File

@ -45,6 +45,8 @@ import static com.alibaba.nacos.naming.misc.Loggers.SRV_LOG;
@Component @Component
public class MysqlHealthCheckProcessor implements HealthCheckProcessor { public class MysqlHealthCheckProcessor implements HealthCheckProcessor {
public static final String TYPE = "MYSQL";
@Autowired @Autowired
private HealthCheckCommon healthCheckCommon; private HealthCheckCommon healthCheckCommon;
@ -83,7 +85,7 @@ public class MysqlHealthCheckProcessor implements HealthCheckProcessor {
@Override @Override
public String getType() { public String getType() {
return "MYSQL"; return TYPE;
} }
@Override @Override

View File

@ -26,12 +26,14 @@ import org.springframework.stereotype.Component;
@Component @Component
public class NoneHealthCheckProcessor implements HealthCheckProcessor { public class NoneHealthCheckProcessor implements HealthCheckProcessor {
public static final String TYPE = "NONE";
@Override @Override
public void process(HealthCheckTask task) { public void process(HealthCheckTask task) {
} }
@Override @Override
public String getType() { public String getType() {
return "NONE"; return TYPE;
} }
} }

View File

@ -43,6 +43,8 @@ import static com.alibaba.nacos.naming.misc.Loggers.SRV_LOG;
@Component @Component
public class TcpSuperSenseProcessor implements HealthCheckProcessor, Runnable { public class TcpSuperSenseProcessor implements HealthCheckProcessor, Runnable {
public static final String TYPE = "TCP";
@Autowired @Autowired
private HealthCheckCommon healthCheckCommon; private HealthCheckCommon healthCheckCommon;
@ -420,6 +422,6 @@ public class TcpSuperSenseProcessor implements HealthCheckProcessor, Runnable {
@Override @Override
public String getType() { public String getType() {
return "TCP"; return TYPE;
} }
} }