fix something

This commit is contained in:
XCXCXCXCX 2019-04-29 20:54:17 +08:00
parent 5fec1098a9
commit 0d436deca0
3 changed files with 18 additions and 27 deletions

View File

@ -25,6 +25,7 @@ import com.alibaba.nacos.naming.core.Cluster;
import com.alibaba.nacos.naming.core.Service;
import com.alibaba.nacos.naming.core.ServiceManager;
import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
import com.alibaba.nacos.naming.misc.Loggers;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import org.apache.commons.lang3.BooleanUtils;
@ -77,23 +78,12 @@ public class ClusterController {
JSONObject healthCheckObj = JSON.parseObject(healthChecker);
AbstractHealthChecker abstractHealthChecker;
switch (healthCheckObj.getString("type")) {
case AbstractHealthChecker.Tcp.TYPE:
abstractHealthChecker = JSON.parseObject(healthChecker, AbstractHealthChecker.Tcp.class);
break;
case AbstractHealthChecker.Http.TYPE:
abstractHealthChecker = JSON.parseObject(healthChecker, AbstractHealthChecker.Http.class);
break;
case AbstractHealthChecker.Mysql.TYPE:
abstractHealthChecker = JSON.parseObject(healthChecker, AbstractHealthChecker.Mysql.class);
break;
case AbstractHealthChecker.None.TYPE:
abstractHealthChecker = JSON.parseObject(healthChecker, AbstractHealthChecker.None.class);
break;
default:
throw new NacosException(NacosException.INVALID_PARAM, "unknown health check type:" + healthChecker);
String type = healthCheckObj.getString("type");
Class<AbstractHealthChecker> healthCheckClass = HealthCheckType.ofHealthCheckerClass(type);
if(healthCheckClass == null){
throw new NacosException(NacosException.INVALID_PARAM, "unknown health check type:" + healthChecker);
}
abstractHealthChecker = JSON.parseObject(healthChecker, healthCheckClass);
cluster.setHealthChecker(abstractHealthChecker);
cluster.setMetadata(UtilsAndCommons.parseMetadata(metadata));
@ -107,4 +97,5 @@ public class ClusterController {
return "ok";
}
}

View File

@ -58,6 +58,12 @@ public enum HealthCheckType {
}
public static Class ofHealthCheckerClass(String type){
return valueOf(type) == null ? EXTEND.get(type) : valueOf(type).healthCheckerClass;
HealthCheckType enumType;
try {
enumType = valueOf(type);
}catch (Exception e){
return EXTEND.get(type);
}
return enumType.healthCheckerClass;
}
}

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.healthcheck.extend;
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
import com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor;
import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@ -33,7 +34,7 @@ import java.util.Set;
* @author XCXCXCXCX
*/
@Component
public class HealthCheckExtendProvider implements BeanFactoryAware{
public class HealthCheckExtendProvider implements BeanFactoryAware {
private ServiceLoader<HealthCheckProcessor> processorLoader
= ServiceLoader.load(HealthCheckProcessor.class);
@ -43,9 +44,6 @@ public class HealthCheckExtendProvider implements BeanFactoryAware{
private SingletonBeanRegistry registry;
private static final char LOWER_A = 'A';
private static final char LOWER_Z = 'Z';
public void init(){
loadExtend();
}
@ -73,14 +71,10 @@ public class HealthCheckExtendProvider implements BeanFactoryAware{
}
private String lowerFirstChar(String simpleName) {
if(simpleName == null || "".equals(simpleName)){
if(StringUtils.isBlank(simpleName)){
throw new IllegalArgumentException("can't find extend processor class name");
}
char[] chars = simpleName.toCharArray();
if(chars[0] >= LOWER_A && chars[0] <= LOWER_Z){
chars[0] = (char)(chars[0] + 32);
}
return String.valueOf(chars);
return String.valueOf(simpleName.charAt(0)).toLowerCase() + simpleName.substring(1);
}
@Override