mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Extract acm configuration to bootstrap phase.
This commit is contained in:
parent
a95a323bc8
commit
32e55ca78b
@ -16,13 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.alicloud.acm;
|
||||
|
||||
import com.taobao.diamond.client.Diamond;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alicloud.acm.endpoint.AcmHealthIndicator;
|
||||
import org.springframework.cloud.alicloud.acm.refresh.AcmContextRefresher;
|
||||
import org.springframework.cloud.alicloud.acm.refresh.AcmRefreshHistory;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmIntegrationProperties;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmProperties;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@ -30,6 +29,8 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.taobao.diamond.client.Diamond;
|
||||
|
||||
/**
|
||||
* Created on 01/10/2017.
|
||||
*
|
||||
@ -37,7 +38,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Diamond.class })
|
||||
@EnableConfigurationProperties(AcmProperties.class)
|
||||
public class AcmAutoConfiguration implements ApplicationContextAware {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
@ -59,10 +59,12 @@ public class AcmAutoConfiguration implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AcmContextRefresher acmContextRefresher(AcmProperties acmProperties, ContextRefresher contextRefresher,
|
||||
AcmRefreshHistory refreshHistory,
|
||||
public AcmContextRefresher acmContextRefresher(
|
||||
AcmIntegrationProperties acmIntegrationProperties,
|
||||
ContextRefresher contextRefresher, AcmRefreshHistory refreshHistory,
|
||||
AcmPropertySourceRepository propertySourceRepository) {
|
||||
return new AcmContextRefresher(contextRefresher, acmProperties, refreshHistory, propertySourceRepository);
|
||||
return new AcmContextRefresher(contextRefresher, acmIntegrationProperties,
|
||||
refreshHistory, propertySourceRepository);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,20 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.alicloud.acm.refresh;
|
||||
|
||||
import com.alibaba.edas.acm.ConfigService;
|
||||
import com.alibaba.edas.acm.listener.ConfigChangeListener;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
||||
import org.springframework.cloud.alicloud.acm.bootstrap.AcmPropertySource;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmProperties;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
@ -37,6 +23,19 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
|
||||
import org.springframework.cloud.alicloud.acm.bootstrap.AcmPropertySource;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmIntegrationProperties;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.edas.acm.ConfigService;
|
||||
import com.alibaba.edas.acm.listener.ConfigChangeListener;
|
||||
|
||||
/**
|
||||
* On application start up, AcmContextRefresher add diamond listeners to all application
|
||||
* level dataIds, when there is a change in the data, listeners will refresh
|
||||
@ -50,7 +49,7 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
|
||||
private final ContextRefresher contextRefresher;
|
||||
|
||||
private final AcmProperties properties;
|
||||
private final AcmIntegrationProperties acmIntegrationProperties;
|
||||
|
||||
private final AcmRefreshHistory refreshHistory;
|
||||
|
||||
@ -58,14 +57,12 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
|
||||
private Map<String, ConfigChangeListener> listenerMap = new ConcurrentHashMap<>(16);
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
public AcmContextRefresher(ContextRefresher contextRefresher,
|
||||
AcmProperties properties, AcmRefreshHistory refreshHistory,
|
||||
AcmIntegrationProperties acmIntegrationProperties,
|
||||
AcmRefreshHistory refreshHistory,
|
||||
AcmPropertySourceRepository acmPropertySourceRepository) {
|
||||
this.contextRefresher = contextRefresher;
|
||||
this.properties = properties;
|
||||
this.acmIntegrationProperties = acmIntegrationProperties;
|
||||
this.refreshHistory = refreshHistory;
|
||||
this.acmPropertySourceRepository = acmPropertySourceRepository;
|
||||
}
|
||||
@ -76,7 +73,7 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
}
|
||||
|
||||
private void registerDiamondListenersForApplications() {
|
||||
if (properties.isRefreshEnabled()) {
|
||||
if (acmIntegrationProperties.getAcmProperties().isRefreshEnabled()) {
|
||||
for (AcmPropertySource acmPropertySource : acmPropertySourceRepository
|
||||
.getAll()) {
|
||||
if (acmPropertySource.isGroupLevel()) {
|
||||
@ -87,11 +84,8 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
}
|
||||
if (acmPropertySourceRepository.getAll().isEmpty()) {
|
||||
|
||||
String applicationName = environment
|
||||
.getProperty("spring.application.name");
|
||||
String dataId = applicationName + "." + properties.getFileExtension();
|
||||
|
||||
registerDiamondListener(dataId);
|
||||
registerDiamondListener(acmIntegrationProperties
|
||||
.getApplicationConfigurationDataIdWithoutGroup());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,7 +113,8 @@ public class AcmContextRefresher implements ApplicationListener<ApplicationReady
|
||||
contextRefresher.refresh();
|
||||
}
|
||||
});
|
||||
ConfigService.addListener(dataId, properties.getGroup(), listener);
|
||||
ConfigService.addListener(dataId,
|
||||
acmIntegrationProperties.getAcmProperties().getGroup(), listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ public class AcmIntegrationProperties {
|
||||
|
||||
private AcmProperties acmProperties;
|
||||
|
||||
public String getApplicationConfigurationDataIdWithoutGroup() {
|
||||
return applicationName + "." + acmProperties.getFileExtension();
|
||||
}
|
||||
|
||||
public List<String> getGroupConfigurationDataIds() {
|
||||
List<String> groupConfigurationDataIds = new ArrayList<>();
|
||||
if (StringUtils.isEmpty(applicationGroup)) {
|
||||
@ -88,4 +92,7 @@ public class AcmIntegrationProperties {
|
||||
this.acmProperties = acmProperties;
|
||||
}
|
||||
|
||||
public AcmProperties getAcmProperties() {
|
||||
return acmProperties;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user