Skip to content

Commit

Permalink
add nacos refresher
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengJie1053 committed Mar 13, 2024
1 parent f505c25 commit cff6add
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 6 deletions.
2 changes: 1 addition & 1 deletion linkis-commons/linkis-rpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
<version>${spring-netflix.version}</version>
<version>${spring-cloud-common.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -112,7 +112,7 @@ private Response<ServiceInstance> processInstanceResponse(
&& StringUtils.isNoneBlank(clientIp)
&& isRPC(linkisLoadBalancerType)
&& System.currentTimeMillis() < endTtime) {
eurekaClientCacheManualRefresher.refresh();
cacheManualRefresher.refresh();
List<ServiceInstance> instances =
SpringCloudFeignConfigurationCache$.MODULE$.discoveryClient().getInstances(serviceId);
serviceInstanceResponse = getInstanceResponse(instances, clientIp);
Expand Down
3 changes: 3 additions & 0 deletions linkis-dist/package/conf/application-engineconn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ management:

logging:
config: classpath:log4j2.xml

#The default value is eureka, Optional value: eureka,nacos
discovery: eureka
5 changes: 4 additions & 1 deletion linkis-dist/package/conf/application-linkis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ spring:
##disable kinif4j.production when you want to use apidoc during development
knife4j:
enable: true
production: true
production: true

#The default value is eureka, Optional value: eureka,nacos
discovery: eureka
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
<spring-netflix.version>3.1.7</spring-netflix.version>
<spring-cloud.version>2021.0.8</spring-cloud.version>
<spring-cloud-alibaba.version>2021.0.6.0</spring-cloud-alibaba.version>
<spring-cloud-common.version>3.1.7</spring-cloud-common.version>

<!-- platform encoding override -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit cff6add

Please sign in to comment.