diff --git a/linkis-commons/linkis-rpc/pom.xml b/linkis-commons/linkis-rpc/pom.xml index 9447c6f554..a3354e0e0e 100644 --- a/linkis-commons/linkis-rpc/pom.xml +++ b/linkis-commons/linkis-rpc/pom.xml @@ -49,7 +49,7 @@ org.springframework.cloud spring-cloud-loadbalancer - ${spring-netflix.version} + ${spring-cloud-common.version} org.springframework.cloud diff --git a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/CacheManualRefresher.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/CacheManualRefresher.java new file mode 100644 index 0000000000..214d6fb854 --- /dev/null +++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/CacheManualRefresher.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.linkis.rpc.conf; + +import org.springframework.stereotype.Component; + +@Component +public interface CacheManualRefresher { + void refresh(); +} diff --git a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java index 2fad4432ea..870693a91c 100644 --- a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java +++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java @@ -21,6 +21,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; import org.springframework.util.ReflectionUtils; @@ -36,7 +37,8 @@ import org.slf4j.LoggerFactory; @Component -public class EurekaClientCacheManualRefresher { +@ConditionalOnProperty(name = "discovery", havingValue = "eureka") +public class EurekaClientCacheManualRefresher implements CacheManualRefresher { private static final Logger logger = LoggerFactory.getLogger(EurekaClientCacheManualRefresher.class); private final AtomicBoolean isRefreshing = new AtomicBoolean(false); diff --git a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/NacosClientCacheManualRefresher.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/NacosClientCacheManualRefresher.java new file mode 100644 index 0000000000..af5df373cf --- /dev/null +++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/NacosClientCacheManualRefresher.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.linkis.rpc.conf; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component +@ConditionalOnProperty(name = "discovery", havingValue = "nacos") +public class NacosClientCacheManualRefresher implements CacheManualRefresher { + private static final Logger logger = + LoggerFactory.getLogger(NacosClientCacheManualRefresher.class); + + public void refresh() { + try { + logger.warn("Failed to obtain nacos metadata. Wait 3 seconds"); + Thread.sleep(3000L); + } catch (InterruptedException e) { + + } + } +} diff --git a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/loadbalancer/ServiceInstancePriorityLoadBalancer.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/loadbalancer/ServiceInstancePriorityLoadBalancer.java index f9511fcf52..2f81ba84d5 100644 --- a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/loadbalancer/ServiceInstancePriorityLoadBalancer.java +++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/loadbalancer/ServiceInstancePriorityLoadBalancer.java @@ -17,7 +17,7 @@ package org.apache.linkis.rpc.loadbalancer; -import org.apache.linkis.rpc.conf.EurekaClientCacheManualRefresher; +import org.apache.linkis.rpc.conf.CacheManualRefresher; import org.apache.linkis.rpc.constant.RpcConstant; import org.apache.linkis.rpc.errorcode.LinkisRpcErrorCodeSummary; import org.apache.linkis.rpc.exception.NoInstanceExistsException; @@ -49,7 +49,7 @@ public class ServiceInstancePriorityLoadBalancer implements ReactorServiceInstan private static final Log log = LogFactory.getLog(ServiceInstancePriorityLoadBalancer.class); - @Autowired private EurekaClientCacheManualRefresher eurekaClientCacheManualRefresher; + @Autowired private CacheManualRefresher cacheManualRefresher; private final String serviceId; @@ -112,7 +112,7 @@ private Response processInstanceResponse( && StringUtils.isNoneBlank(clientIp) && isRPC(linkisLoadBalancerType) && System.currentTimeMillis() < endTtime) { - eurekaClientCacheManualRefresher.refresh(); + cacheManualRefresher.refresh(); List instances = SpringCloudFeignConfigurationCache$.MODULE$.discoveryClient().getInstances(serviceId); serviceInstanceResponse = getInstanceResponse(instances, clientIp); diff --git a/linkis-dist/package/conf/application-engineconn.yml b/linkis-dist/package/conf/application-engineconn.yml index 25b75c9a80..ee8e5d150b 100644 --- a/linkis-dist/package/conf/application-engineconn.yml +++ b/linkis-dist/package/conf/application-engineconn.yml @@ -53,3 +53,6 @@ management: logging: config: classpath:log4j2.xml + +#The default value is eureka, Optional value: eureka,nacos +discovery: eureka \ No newline at end of file diff --git a/linkis-dist/package/conf/application-linkis.yml b/linkis-dist/package/conf/application-linkis.yml index 82fb281211..fbf2fae3f1 100644 --- a/linkis-dist/package/conf/application-linkis.yml +++ b/linkis-dist/package/conf/application-linkis.yml @@ -63,4 +63,7 @@ spring: ##disable kinif4j.production when you want to use apidoc during development knife4j: enable: true - production: true \ No newline at end of file + production: true + +#The default value is eureka, Optional value: eureka,nacos +discovery: eureka \ No newline at end of file diff --git a/pom.xml b/pom.xml index 88259e399c..05691218ef 100644 --- a/pom.xml +++ b/pom.xml @@ -225,6 +225,7 @@ 3.1.7 2021.0.8 2021.0.6.0 + 3.1.7 UTF-8