mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge remote-tracking branch 'upstream/1.x' into 1.x
This commit is contained in:
commit
fa1c5f614f
@ -56,9 +56,8 @@ public class NacosConfigAutoConfiguration {
|
|||||||
public NacosContextRefresher nacosContextRefresher(
|
public NacosContextRefresher nacosContextRefresher(
|
||||||
NacosConfigProperties nacosConfigProperties,
|
NacosConfigProperties nacosConfigProperties,
|
||||||
NacosRefreshProperties nacosRefreshProperties,
|
NacosRefreshProperties nacosRefreshProperties,
|
||||||
NacosRefreshHistory refreshHistory,
|
NacosRefreshHistory refreshHistory) {
|
||||||
NacosPropertySourceRepository propertySourceRepository) {
|
|
||||||
return new NacosContextRefresher(nacosRefreshProperties, refreshHistory,
|
return new NacosContextRefresher(nacosRefreshProperties, refreshHistory,
|
||||||
propertySourceRepository, nacosConfigProperties.configServiceInstance());
|
nacosConfigProperties.configServiceInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,4 @@ public class NacosConfigBootstrapConfiguration {
|
|||||||
return new NacosConfigProperties();
|
return new NacosConfigProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
public NacosPropertySourceRepository nacosPropertySourceRepository() {
|
|
||||||
return new NacosPropertySourceRepository();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,24 +16,21 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.alibaba.nacos;
|
package org.springframework.cloud.alibaba.nacos;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.PropertyKeyConst.*;
|
import com.alibaba.nacos.api.NacosFactory;
|
||||||
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import static com.alibaba.nacos.api.PropertyKeyConst.*;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
import com.alibaba.nacos.api.NacosFactory;
|
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nacos properties
|
* nacos properties
|
||||||
@ -110,7 +107,6 @@ public class NacosConfigProperties {
|
|||||||
*/
|
*/
|
||||||
private String clusterName;
|
private String clusterName;
|
||||||
|
|
||||||
@Value("${spring.application.name}")
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String[] activeProfiles;
|
private String[] activeProfiles;
|
||||||
@ -141,6 +137,10 @@ public class NacosConfigProperties {
|
|||||||
this.activeProfiles = environment.getActiveProfiles();
|
this.activeProfiles = environment.getActiveProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setActiveProfiles(String[] activeProfiles) {
|
||||||
|
this.activeProfiles = activeProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
// todo sts support
|
// todo sts support
|
||||||
|
|
||||||
public String getServerAddr() {
|
public String getServerAddr() {
|
||||||
|
@ -24,22 +24,29 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
|
* @author pbting
|
||||||
*/
|
*/
|
||||||
public class NacosPropertySourceRepository {
|
public class NacosPropertySourceRepository {
|
||||||
|
|
||||||
private ConcurrentHashMap<String, NacosPropertySource> nacosPropertySourceRepository = new ConcurrentHashMap<>();
|
private final static ConcurrentHashMap<String, NacosPropertySource> nacosPropertySourceRepository = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all nacos properties from application context
|
* @return all nacos properties from application context
|
||||||
*/
|
*/
|
||||||
public List<NacosPropertySource> getAll() {
|
public static List<NacosPropertySource> getAll() {
|
||||||
List<NacosPropertySource> result = new ArrayList<>();
|
List<NacosPropertySource> result = new ArrayList<>();
|
||||||
result.addAll(nacosPropertySourceRepository.values());
|
result.addAll(nacosPropertySourceRepository.values());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collectNacosPropertySources(NacosPropertySource nacosPropertySource) {
|
public static void collectNacosPropertySources(
|
||||||
|
NacosPropertySource nacosPropertySource) {
|
||||||
nacosPropertySourceRepository.putIfAbsent(nacosPropertySource.getDataId(),
|
nacosPropertySourceRepository.putIfAbsent(nacosPropertySource.getDataId(),
|
||||||
nacosPropertySource);
|
nacosPropertySource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NacosPropertySource getNacosPropertySource(String dataId) {
|
||||||
|
|
||||||
|
return nacosPropertySourceRepository.get(dataId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ public class NacosPropertySourceBuilder {
|
|||||||
.getLogger(NacosPropertySourceBuilder.class);
|
.getLogger(NacosPropertySourceBuilder.class);
|
||||||
private static final Properties EMPTY_PROPERTIES = new Properties();
|
private static final Properties EMPTY_PROPERTIES = new Properties();
|
||||||
|
|
||||||
private NacosPropertySourceRepository nacosPropertySourceRepository;
|
|
||||||
private ConfigService configService;
|
private ConfigService configService;
|
||||||
private long timeout;
|
private long timeout;
|
||||||
|
|
||||||
@ -74,7 +73,7 @@ public class NacosPropertySourceBuilder {
|
|||||||
}
|
}
|
||||||
NacosPropertySource nacosPropertySource = new NacosPropertySource(group, dataId,
|
NacosPropertySource nacosPropertySource = new NacosPropertySource(group, dataId,
|
||||||
propertiesToMap(p), new Date(), isRefreshable);
|
propertiesToMap(p), new Date(), isRefreshable);
|
||||||
nacosPropertySourceRepository.collectNacosPropertySources(nacosPropertySource);
|
NacosPropertySourceRepository.collectNacosPropertySources(nacosPropertySource);
|
||||||
return nacosPropertySource;
|
return nacosPropertySource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,9 +113,9 @@ public class NacosPropertySourceBuilder {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Map<String, Object> propertiesToMap(Properties properties) {
|
private Map<String, Object> propertiesToMap(Properties properties) {
|
||||||
Map<String, Object> result = new HashMap<>(16);
|
Map<String, Object> result = new HashMap<>(16);
|
||||||
Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
|
Enumeration<String> tmpKeys = (Enumeration<String>) properties.propertyNames();
|
||||||
while (keys.hasMoreElements()) {
|
while (tmpKeys.hasMoreElements()) {
|
||||||
String key = keys.nextElement();
|
String key = tmpKeys.nextElement();
|
||||||
Object value = properties.getProperty(key);
|
Object value = properties.getProperty(key);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
result.put(key, ((String) value).trim());
|
result.put(key, ((String) value).trim());
|
||||||
@ -127,13 +126,4 @@ public class NacosPropertySourceBuilder {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NacosPropertySourceRepository getNacosPropertySourceRepository() {
|
|
||||||
return nacosPropertySourceRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNacosPropertySourceRepository(
|
|
||||||
NacosPropertySourceRepository nacosPropertySourceRepository) {
|
|
||||||
this.nacosPropertySourceRepository = nacosPropertySourceRepository;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
|
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
|
||||||
|
import org.springframework.cloud.alibaba.nacos.refresh.NacosContextRefresher;
|
||||||
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
|
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.core.env.CompositePropertySource;
|
import org.springframework.core.env.CompositePropertySource;
|
||||||
@ -51,9 +52,6 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private NacosConfigProperties nacosConfigProperties;
|
private NacosConfigProperties nacosConfigProperties;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosPropertySourceRepository nacosPropertySourceRepository;
|
|
||||||
|
|
||||||
public NacosPropertySourceLocator() {
|
public NacosPropertySourceLocator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +70,6 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
|||||||
long timeout = nacosConfigProperties.getTimeout();
|
long timeout = nacosConfigProperties.getTimeout();
|
||||||
nacosPropertySourceBuilder = new NacosPropertySourceBuilder(configService,
|
nacosPropertySourceBuilder = new NacosPropertySourceBuilder(configService,
|
||||||
timeout);
|
timeout);
|
||||||
nacosPropertySourceBuilder
|
|
||||||
.setNacosPropertySourceRepository(nacosPropertySourceRepository);
|
|
||||||
String name = nacosConfigProperties.getName();
|
String name = nacosConfigProperties.getName();
|
||||||
|
|
||||||
String nacosGroup = nacosConfigProperties.getGroup();
|
String nacosGroup = nacosConfigProperties.getGroup();
|
||||||
@ -82,6 +78,13 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
|||||||
dataIdPrefix = name;
|
dataIdPrefix = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(dataIdPrefix)) {
|
||||||
|
dataIdPrefix = env.getProperty("spring.application.name");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> profiles = Arrays.asList(env.getActiveProfiles());
|
||||||
|
nacosConfigProperties.setActiveProfiles(profiles.toArray(new String[0]));
|
||||||
|
|
||||||
String fileExtension = nacosConfigProperties.getFileExtension();
|
String fileExtension = nacosConfigProperties.getFileExtension();
|
||||||
|
|
||||||
CompositePropertySource composite = new CompositePropertySource(
|
CompositePropertySource composite = new CompositePropertySource(
|
||||||
@ -164,11 +167,24 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
|||||||
private void loadNacosDataIfPresent(final CompositePropertySource composite,
|
private void loadNacosDataIfPresent(final CompositePropertySource composite,
|
||||||
final String dataId, final String group, String fileExtension,
|
final String dataId, final String group, String fileExtension,
|
||||||
boolean isRefreshable) {
|
boolean isRefreshable) {
|
||||||
NacosPropertySource ps = nacosPropertySourceBuilder.build(dataId, group,
|
|
||||||
fileExtension, isRefreshable);
|
if (NacosContextRefresher.loadCount.get() != 0) {
|
||||||
if (ps != null) {
|
NacosPropertySource ps;
|
||||||
|
if (!isRefreshable) {
|
||||||
|
ps = NacosPropertySourceRepository.getNacosPropertySource(dataId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ps = nacosPropertySourceBuilder.build(dataId, group, fileExtension, true);
|
||||||
|
}
|
||||||
|
|
||||||
composite.addFirstPropertySource(ps);
|
composite.addFirstPropertySource(ps);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
NacosPropertySource ps = nacosPropertySourceBuilder.build(dataId, group,
|
||||||
|
fileExtension, isRefreshable);
|
||||||
|
composite.addFirstPropertySource(ps);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkDataIdFileExtension(String[] sharedDataIdArry) {
|
private static void checkDataIdFileExtension(String[] sharedDataIdArry) {
|
||||||
|
@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.alibaba.nacos.endpoint;
|
package org.springframework.cloud.alibaba.nacos.endpoint;
|
||||||
|
|
||||||
|
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||||
|
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
||||||
|
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
|
||||||
|
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySource;
|
||||||
|
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -23,12 +29,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
|
|
||||||
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySource;
|
|
||||||
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Endpoint for Nacos, contains config data and refresh history
|
* Endpoint for Nacos, contains config data and refresh history
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
@ -40,16 +40,13 @@ public class NacosConfigEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
|||||||
|
|
||||||
private final NacosRefreshHistory refreshHistory;
|
private final NacosRefreshHistory refreshHistory;
|
||||||
|
|
||||||
private final NacosPropertySourceRepository propertySourceRepository;
|
|
||||||
|
|
||||||
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
public NacosConfigEndpoint(NacosConfigProperties properties, NacosRefreshHistory refreshHistory,
|
public NacosConfigEndpoint(NacosConfigProperties properties,
|
||||||
NacosPropertySourceRepository propertySourceRepository) {
|
NacosRefreshHistory refreshHistory) {
|
||||||
super("nacos_config", false);
|
super("nacos_config", false);
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.refreshHistory = refreshHistory;
|
this.refreshHistory = refreshHistory;
|
||||||
this.propertySourceRepository = propertySourceRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,7 +54,7 @@ public class NacosConfigEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
|||||||
Map<String, Object> result = new HashMap<>(16);
|
Map<String, Object> result = new HashMap<>(16);
|
||||||
result.put("NacosConfigProperties", properties);
|
result.put("NacosConfigProperties", properties);
|
||||||
|
|
||||||
List<NacosPropertySource> all = propertySourceRepository.getAll();
|
List<NacosPropertySource> all = NacosPropertySourceRepository.getAll();
|
||||||
|
|
||||||
List<Map<String, Object>> sources = new ArrayList<>();
|
List<Map<String, Object>> sources = new ArrayList<>();
|
||||||
for (NacosPropertySource ps : all) {
|
for (NacosPropertySource ps : all) {
|
||||||
|
@ -16,15 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.alibaba.nacos.endpoint;
|
package org.springframework.cloud.alibaba.nacos.endpoint;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
|
|
||||||
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
@ -41,21 +37,15 @@ public class NacosConfigEndpointAutoConfiguration {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private NacosRefreshHistory nacosRefreshHistory;
|
private NacosRefreshHistory nacosRefreshHistory;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private NacosPropertySourceRepository nacosPropertySourceRepository;
|
|
||||||
|
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@Bean
|
@Bean
|
||||||
public NacosConfigEndpoint nacosConfigEndpoint() {
|
public NacosConfigEndpoint nacosConfigEndpoint() {
|
||||||
return new NacosConfigEndpoint(nacosConfigProperties, nacosRefreshHistory,
|
return new NacosConfigEndpoint(nacosConfigProperties, nacosRefreshHistory);
|
||||||
nacosPropertySourceRepository);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public NacosConfigHealthIndicator nacosConfigHealthIndicator(
|
public NacosConfigHealthIndicator nacosConfigHealthIndicator() {
|
||||||
NacosPropertySourceRepository nacosPropertySourceRepository) {
|
|
||||||
return new NacosConfigHealthIndicator(nacosConfigProperties,
|
return new NacosConfigHealthIndicator(nacosConfigProperties,
|
||||||
nacosPropertySourceRepository,
|
|
||||||
nacosConfigProperties.configServiceInstance());
|
nacosConfigProperties.configServiceInstance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.alibaba.nacos.endpoint;
|
package org.springframework.cloud.alibaba.nacos.endpoint;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||||
import org.springframework.boot.actuate.health.Health;
|
import org.springframework.boot.actuate.health.Health;
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
|
||||||
@ -28,6 +24,9 @@ import org.springframework.cloud.alibaba.nacos.NacosPropertySourceRepository;
|
|||||||
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySource;
|
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySource;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author xiaojing
|
* @author xiaojing
|
||||||
*/
|
*/
|
||||||
@ -35,21 +34,17 @@ public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
|
|||||||
|
|
||||||
private final NacosConfigProperties nacosConfigProperties;
|
private final NacosConfigProperties nacosConfigProperties;
|
||||||
|
|
||||||
private final NacosPropertySourceRepository nacosPropertySourceRepository;
|
|
||||||
|
|
||||||
private final List<String> dataIds;
|
private final List<String> dataIds;
|
||||||
|
|
||||||
private final ConfigService configService;
|
private final ConfigService configService;
|
||||||
|
|
||||||
public NacosConfigHealthIndicator(NacosConfigProperties nacosConfigProperties,
|
public NacosConfigHealthIndicator(NacosConfigProperties nacosConfigProperties,
|
||||||
NacosPropertySourceRepository nacosPropertySourceRepository,
|
|
||||||
ConfigService configService) {
|
ConfigService configService) {
|
||||||
this.nacosConfigProperties = nacosConfigProperties;
|
this.nacosConfigProperties = nacosConfigProperties;
|
||||||
this.nacosPropertySourceRepository = nacosPropertySourceRepository;
|
|
||||||
this.configService = configService;
|
this.configService = configService;
|
||||||
|
|
||||||
this.dataIds = new ArrayList<>();
|
this.dataIds = new ArrayList<>();
|
||||||
for (NacosPropertySource nacosPropertySource : this.nacosPropertySourceRepository
|
for (NacosPropertySource nacosPropertySource : NacosPropertySourceRepository
|
||||||
.getAll()) {
|
.getAll()) {
|
||||||
this.dataIds.add(nacosPropertySource.getDataId());
|
this.dataIds.add(nacosPropertySource.getDataId());
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,9 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.alibaba.nacos.refresh;
|
package org.springframework.cloud.alibaba.nacos.refresh;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
import java.math.BigInteger;
|
import com.alibaba.nacos.api.config.listener.Listener;
|
||||||
import java.security.MessageDigest;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
@ -36,9 +30,15 @@ import org.springframework.context.ApplicationContextAware;
|
|||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
import java.io.UnsupportedEncodingException;
|
||||||
import com.alibaba.nacos.api.config.listener.Listener;
|
import java.math.BigInteger;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On application start up, NacosContextRefresher add nacos listeners to all application
|
* On application start up, NacosContextRefresher add nacos listeners to all application
|
||||||
@ -54,36 +54,32 @@ public class NacosContextRefresher
|
|||||||
private final static Logger LOGGER = LoggerFactory
|
private final static Logger LOGGER = LoggerFactory
|
||||||
.getLogger(NacosContextRefresher.class);
|
.getLogger(NacosContextRefresher.class);
|
||||||
|
|
||||||
|
public static final AtomicLong loadCount = new AtomicLong(0);
|
||||||
|
|
||||||
private final NacosRefreshProperties refreshProperties;
|
private final NacosRefreshProperties refreshProperties;
|
||||||
|
|
||||||
private final NacosRefreshHistory refreshHistory;
|
private final NacosRefreshHistory refreshHistory;
|
||||||
|
|
||||||
private final NacosPropertySourceRepository nacosPropertySourceRepository;
|
|
||||||
|
|
||||||
private final ConfigService configService;
|
private final ConfigService configService;
|
||||||
|
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
private AtomicBoolean ready = new AtomicBoolean(true);
|
private AtomicBoolean ready = new AtomicBoolean(false);
|
||||||
|
|
||||||
private Map<String, Listener> listenerMap = new ConcurrentHashMap<>(16);
|
private Map<String, Listener> listenerMap = new ConcurrentHashMap<>(16);
|
||||||
|
|
||||||
public NacosContextRefresher(NacosRefreshProperties refreshProperties,
|
public NacosContextRefresher(NacosRefreshProperties refreshProperties,
|
||||||
NacosRefreshHistory refreshHistory,
|
NacosRefreshHistory refreshHistory, ConfigService configService) {
|
||||||
NacosPropertySourceRepository nacosPropertySourceRepository,
|
|
||||||
ConfigService configService) {
|
|
||||||
this.refreshProperties = refreshProperties;
|
this.refreshProperties = refreshProperties;
|
||||||
this.refreshHistory = refreshHistory;
|
this.refreshHistory = refreshHistory;
|
||||||
this.nacosPropertySourceRepository = nacosPropertySourceRepository;
|
|
||||||
this.configService = configService;
|
this.configService = configService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationReadyEvent event) {
|
public void onApplicationEvent(ApplicationReadyEvent event) {
|
||||||
// many Spring context
|
// many Spring context
|
||||||
if (this.ready.get()) {
|
if (this.ready.compareAndSet(false, true)) {
|
||||||
this.registerNacosListenersForApplications();
|
this.registerNacosListenersForApplications();
|
||||||
this.ready.compareAndSet(true, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +90,7 @@ public class NacosContextRefresher
|
|||||||
|
|
||||||
private void registerNacosListenersForApplications() {
|
private void registerNacosListenersForApplications() {
|
||||||
if (refreshProperties.isEnabled()) {
|
if (refreshProperties.isEnabled()) {
|
||||||
for (NacosPropertySource nacosPropertySource : nacosPropertySourceRepository
|
for (NacosPropertySource nacosPropertySource : NacosPropertySourceRepository
|
||||||
.getAll()) {
|
.getAll()) {
|
||||||
|
|
||||||
if (!nacosPropertySource.isRefreshable()) {
|
if (!nacosPropertySource.isRefreshable()) {
|
||||||
@ -114,6 +110,7 @@ public class NacosContextRefresher
|
|||||||
listener = new Listener() {
|
listener = new Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void receiveConfigInfo(String configInfo) {
|
public void receiveConfigInfo(String configInfo) {
|
||||||
|
loadCount.incrementAndGet();
|
||||||
String md5 = "";
|
String md5 = "";
|
||||||
if (!StringUtils.isEmpty(configInfo)) {
|
if (!StringUtils.isEmpty(configInfo)) {
|
||||||
try {
|
try {
|
||||||
|
@ -3,31 +3,33 @@ package org.springframework.cloud.alicloud.context.nacos;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
|
||||||
|
|
||||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||||
|
|
||||||
/**
|
|
||||||
* A listener that prepare initialize the nacos configuration for aliyun acm
|
|
||||||
*
|
|
||||||
* @author pbting
|
|
||||||
*/
|
|
||||||
public class NacosParameterInitListener
|
public class NacosParameterInitListener
|
||||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
extends AbstractOnceApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
||||||
private static final Logger log = LoggerFactory
|
private static final Logger log = LoggerFactory
|
||||||
.getLogger(NacosParameterInitListener.class);
|
.getLogger(NacosParameterInitListener.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
protected String conditionalOnClass() {
|
||||||
|
return "org.springframework.cloud.alibaba.nacos.NacosConfigAutoConfiguration";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||||
preparedNacosConfiguration();
|
preparedNacosConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preparedNacosConfiguration() {
|
private void preparedNacosConfiguration() {
|
||||||
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
|
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
|
||||||
.getEdasChangeOrderConfiguration();
|
.getEdasChangeOrderConfiguration();
|
||||||
|
|
||||||
log.info("Initialize Nacos Parameter from edas change order,is edas managed {}.",
|
log.info("Initialize Nacos Parameter from edas change order,is edas managed {}.",
|
||||||
edasChangeOrderConfiguration.isEdasManaged());
|
edasChangeOrderConfiguration.isEdasManaged());
|
||||||
|
|
||||||
if (!edasChangeOrderConfiguration.isEdasManaged()) {
|
if (!edasChangeOrderConfiguration.isEdasManaged()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user