From 6695805c69c2050b5455d8c22bf040bf532f85d2 Mon Sep 17 00:00:00 2001 From: XCXCXCXCX <1158840657@qq.com> Date: Wed, 8 May 2019 09:14:54 +0800 Subject: [PATCH] Let nacos-server.jar import external jar package --- console/pom.xml | 1 + distribution/bin/startup.cmd | 3 +-- distribution/bin/startup.sh | 2 +- .../extend/HealthCheckExtendProvider.java | 12 +++++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/console/pom.xml b/console/pom.xml index da846322c..84dccd280 100644 --- a/console/pom.xml +++ b/console/pom.xml @@ -104,6 +104,7 @@ 2.1.1.RELEASE com.alibaba.nacos.Nacos + ZIP diff --git a/distribution/bin/startup.cmd b/distribution/bin/startup.cmd index 63bfc2d1a..2f053c8fa 100755 --- a/distribution/bin/startup.cmd +++ b/distribution/bin/startup.cmd @@ -35,9 +35,8 @@ if not "%2" == "cluster" ( set "JAVA_OPT=%JAVA_OPT% -XX:-UseLargePages" ) -set "JAVA_OPT=%JAVA_OPT% -Xbootclasspath/a:%BASE_DIR%\plugins\cmdb" set "JAVA_OPT=%JAVA_OPT% -Dnacos.home=%BASE_DIR%" -set "JAVA_OPT=%JAVA_OPT% -jar %BASE_DIR%\target\nacos-server.jar" +set "JAVA_OPT=%JAVA_OPT% -Dloader.path=%BASE_DIR%/plugins/health/nacos-health-plugin-example-1.0.jar -jar %BASE_DIR%\target\nacos-server.jar" set "JAVA_OPT=%JAVA_OPT% --spring.config.location=%CUSTOM_SEARCH_LOCATIONS%" set "JAVA_OPT=%JAVA_OPT% --logging.config=%BASE_DIR%/conf/nacos-logback.xml" diff --git a/distribution/bin/startup.sh b/distribution/bin/startup.sh index 78eb3a654..480daac8a 100644 --- a/distribution/bin/startup.sh +++ b/distribution/bin/startup.sh @@ -102,7 +102,7 @@ else fi JAVA_OPT="${JAVA_OPT} -Dnacos.home=${BASE_DIR}" -JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/nacos-server.jar" +JAVA_OPT="${JAVA_OPT} -Dloader.path=${BASE_DIR}/plugins/health/nacos-health-plugin-example-1.0.jar -jar ${BASE_DIR}/target/nacos-server.jar" JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}" JAVA_OPT="${JAVA_OPT} --spring.config.location=${CUSTOM_SEARCH_LOCATIONS}" JAVA_OPT="${JAVA_OPT} --logging.config=${BASE_DIR}/conf/nacos-logback.xml" diff --git a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/extend/HealthCheckExtendProvider.java b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/extend/HealthCheckExtendProvider.java index 0912d0ca9..9e18bb4ad 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/extend/HealthCheckExtendProvider.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/healthcheck/extend/HealthCheckExtendProvider.java @@ -19,6 +19,8 @@ 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.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -36,6 +38,8 @@ import java.util.Set; @Component public class HealthCheckExtendProvider implements BeanFactoryAware { + private static final Logger LOGGER = LoggerFactory.getLogger(HealthCheckExtendProvider.class); + private ServiceLoader processorLoader = ServiceLoader.load(HealthCheckProcessor.class); @@ -75,9 +79,7 @@ public class HealthCheckExtendProvider implements BeanFactoryAware { AbstractHealthChecker checker = healthCheckerIt.next(); String type = checker.getType(); if(healthCheckerType.contains(type)){ - if(processorType.contains(type)){ - throw new RuntimeException("More than one healthChecker of the same type was found : [type=\"" + type + "\"]"); - } + throw new RuntimeException("More than one healthChecker of the same type was found : [type=\"" + type + "\"]"); } healthCheckerType.add(type); HealthCheckType.registerHealthChecker(checker.getType(), checker.getClass()); @@ -85,6 +87,10 @@ public class HealthCheckExtendProvider implements BeanFactoryAware { if(!processorType.equals(healthCheckerType)){ throw new RuntimeException("An unmatched processor and healthChecker are detected in the extension package."); } + if(processorType.size() > origin.size()){ + processorType.removeAll(origin); + LOGGER.debug("init health plugin : types=" + processorType); + } } private String lowerFirstChar(String simpleName) {