fix something
This commit is contained in:
parent
5fec1098a9
commit
0d436deca0
@ -25,6 +25,7 @@ import com.alibaba.nacos.naming.core.Cluster;
|
|||||||
import com.alibaba.nacos.naming.core.Service;
|
import com.alibaba.nacos.naming.core.Service;
|
||||||
import com.alibaba.nacos.naming.core.ServiceManager;
|
import com.alibaba.nacos.naming.core.ServiceManager;
|
||||||
import com.alibaba.nacos.naming.exception.NacosException;
|
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.Loggers;
|
||||||
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
@ -77,23 +78,12 @@ public class ClusterController {
|
|||||||
|
|
||||||
JSONObject healthCheckObj = JSON.parseObject(healthChecker);
|
JSONObject healthCheckObj = JSON.parseObject(healthChecker);
|
||||||
AbstractHealthChecker abstractHealthChecker;
|
AbstractHealthChecker abstractHealthChecker;
|
||||||
|
String type = healthCheckObj.getString("type");
|
||||||
switch (healthCheckObj.getString("type")) {
|
Class<AbstractHealthChecker> healthCheckClass = HealthCheckType.ofHealthCheckerClass(type);
|
||||||
case AbstractHealthChecker.Tcp.TYPE:
|
if(healthCheckClass == null){
|
||||||
abstractHealthChecker = JSON.parseObject(healthChecker, AbstractHealthChecker.Tcp.class);
|
throw new NacosException(NacosException.INVALID_PARAM, "unknown health check type:" + healthChecker);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
abstractHealthChecker = JSON.parseObject(healthChecker, healthCheckClass);
|
||||||
|
|
||||||
cluster.setHealthChecker(abstractHealthChecker);
|
cluster.setHealthChecker(abstractHealthChecker);
|
||||||
cluster.setMetadata(UtilsAndCommons.parseMetadata(metadata));
|
cluster.setMetadata(UtilsAndCommons.parseMetadata(metadata));
|
||||||
@ -107,4 +97,5 @@ public class ClusterController {
|
|||||||
|
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,12 @@ public enum HealthCheckType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Class ofHealthCheckerClass(String type){
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package com.alibaba.nacos.naming.healthcheck.extend;
|
|||||||
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
import com.alibaba.nacos.api.naming.pojo.AbstractHealthChecker;
|
||||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor;
|
import com.alibaba.nacos.naming.healthcheck.HealthCheckProcessor;
|
||||||
import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
|
import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.BeanFactoryAware;
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
@ -33,7 +34,7 @@ import java.util.Set;
|
|||||||
* @author XCXCXCXCX
|
* @author XCXCXCXCX
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class HealthCheckExtendProvider implements BeanFactoryAware{
|
public class HealthCheckExtendProvider implements BeanFactoryAware {
|
||||||
|
|
||||||
private ServiceLoader<HealthCheckProcessor> processorLoader
|
private ServiceLoader<HealthCheckProcessor> processorLoader
|
||||||
= ServiceLoader.load(HealthCheckProcessor.class);
|
= ServiceLoader.load(HealthCheckProcessor.class);
|
||||||
@ -43,9 +44,6 @@ public class HealthCheckExtendProvider implements BeanFactoryAware{
|
|||||||
|
|
||||||
private SingletonBeanRegistry registry;
|
private SingletonBeanRegistry registry;
|
||||||
|
|
||||||
private static final char LOWER_A = 'A';
|
|
||||||
private static final char LOWER_Z = 'Z';
|
|
||||||
|
|
||||||
public void init(){
|
public void init(){
|
||||||
loadExtend();
|
loadExtend();
|
||||||
}
|
}
|
||||||
@ -73,14 +71,10 @@ public class HealthCheckExtendProvider implements BeanFactoryAware{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String lowerFirstChar(String simpleName) {
|
private String lowerFirstChar(String simpleName) {
|
||||||
if(simpleName == null || "".equals(simpleName)){
|
if(StringUtils.isBlank(simpleName)){
|
||||||
throw new IllegalArgumentException("can't find extend processor class name");
|
throw new IllegalArgumentException("can't find extend processor class name");
|
||||||
}
|
}
|
||||||
char[] chars = simpleName.toCharArray();
|
return String.valueOf(simpleName.charAt(0)).toLowerCase() + simpleName.substring(1);
|
||||||
if(chars[0] >= LOWER_A && chars[0] <= LOWER_Z){
|
|
||||||
chars[0] = (char)(chars[0] + 32);
|
|
||||||
}
|
|
||||||
return String.valueOf(chars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user