Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:let the configuration SDK context stand alone. #1275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ closes #

- [ ] Will pull request to branch of 2023.0.
- [ ] Will pull request to branch of 2022.0.
- [ ] Will pull request to branch of 2021.0.
- [ ] Will pull request to branch of 2020.0.
- [ ] Will pull request to branch of hoxton.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
- [feat: add lane router examples](https://github.com/Tencent/spring-cloud-tencent/pull/1270)
- [fix: fix the lossless provider override in multiple registries scenario](https://github.com/Tencent/spring-cloud-tencent/pull/1271)
- [fix:fix nearby router properties loading bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1273)
- [refactor:let the configuration SDK context stand alone.](https://github.com/Tencent/spring-cloud-tencent/pull/1275)
- [fix: fix grammar issues for lane router example & optimize the gateway dependency](https://github.com/Tencent/spring-cloud-tencent/pull/1276)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* 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 com.tencent.cloud.polaris.config;
Expand All @@ -26,7 +25,7 @@
import com.tencent.cloud.common.util.AddressUtils;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.config.PolarisCryptoConfigProperties;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.cloud.polaris.context.PolarisConfigurationConfigModifier;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import com.tencent.polaris.factory.config.configuration.ConfigFilterConfigImpl;
Expand All @@ -42,7 +41,7 @@
*
* @author lepdou 2022-03-10
*/
public class ConfigurationModifier implements PolarisConfigModifier {
public class ConfigurationModifier implements PolarisConfigurationConfigModifier {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationModifier.class);

private static final String DATA_SOURCE_POLARIS = "polaris";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.tencent.cloud.polaris.config.adapter.AffectedConfigurationPropertiesRebinder;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigPropertyRefresher;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshAffectedContextRefresher;
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshEntireContextRefresher;
import com.tencent.cloud.polaris.config.annotation.PolarisConfigAnnotationProcessor;
Expand Down Expand Up @@ -78,9 +77,9 @@ public ConfigurationPropertiesRebinder affectedConfigurationPropertiesRebinder(

@Bean
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
public PolarisConfigPropertyRefresher polarisRefreshContextPropertySourceAutoRefresher(PolarisConfigProperties polarisConfigProperties,
PolarisPropertySourceManager polarisPropertySourceManager, ContextRefresher contextRefresher) {
return new PolarisRefreshEntireContextRefresher(polarisConfigProperties, polarisPropertySourceManager, contextRefresher);
public PolarisConfigPropertyRefresher polarisRefreshContextPropertySourceAutoRefresher(
PolarisConfigProperties polarisConfigProperties, ContextRefresher contextRefresher) {
return new PolarisRefreshEntireContextRefresher(polarisConfigProperties, contextRefresher);
}

@Configuration(proxyBeanMethods = false)
Expand All @@ -104,10 +103,10 @@ public SpringValueProcessor springValueProcessor(PlaceholderHelper placeholderHe
}

@Bean
public PolarisConfigPropertyRefresher polarisReflectPropertySourceAutoRefresher(PolarisConfigProperties polarisConfigProperties,
PolarisPropertySourceManager polarisPropertySourceManager, SpringValueRegistry springValueRegistry,
public PolarisConfigPropertyRefresher polarisReflectPropertySourceAutoRefresher(
PolarisConfigProperties polarisConfigProperties, SpringValueRegistry springValueRegistry,
PlaceholderHelper placeholderHelper) {
return new PolarisRefreshAffectedContextRefresher(polarisConfigProperties, polarisPropertySourceManager,
return new PolarisRefreshAffectedContextRefresher(polarisConfigProperties,
springValueRegistry, placeholderHelper);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.tencent.cloud.polaris.config.adapter.AffectedConfigurationPropertiesRebinder;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigFileLocator;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.config.PolarisCryptoConfigProperties;
Expand Down Expand Up @@ -59,16 +58,10 @@ public PolarisCryptoConfigProperties polarisCryptoConfigProperties() {
return new PolarisCryptoConfigProperties();
}

@Bean
@ConditionalOnMissingBean
public PolarisPropertySourceManager polarisPropertySourceManager() {
return new PolarisPropertySourceManager();
}

@Bean
@ConditionalOnConnectRemoteServerEnabled
public ConfigFileService configFileService(PolarisSDKContextManager polarisSDKContextManager) {
return ConfigFileServiceFactory.createConfigFileService(polarisSDKContextManager.getSDKContext());
return ConfigFileServiceFactory.createConfigFileService(polarisSDKContextManager.getConfigSDKContext());
}

@Bean
Expand All @@ -77,11 +70,9 @@ public PolarisConfigFileLocator polarisConfigFileLocator(
PolarisConfigProperties polarisConfigProperties,
PolarisContextProperties polarisContextProperties,
ConfigFileService configFileService,
PolarisPropertySourceManager polarisPropertySourceManager,
Environment environment) {
return new PolarisConfigFileLocator(polarisConfigProperties,
polarisContextProperties, configFileService,
polarisPropertySourceManager, environment);
polarisContextProperties, configFileService, environment);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
public interface PolarisConfigCustomExtensionLayer {
void initRegisterConfig(PolarisConfigPropertyAutoRefresher polarisConfigPropertyAutoRefresher);

void initConfigFiles(Environment environment, CompositePropertySource compositePropertySource, PolarisPropertySourceManager polarisPropertySourceManager, ConfigFileService configFileService);
void initConfigFiles(Environment environment, CompositePropertySource compositePropertySource, ConfigFileService configFileService);

void executeAfterLocateConfigReturning(CompositePropertySource compositePropertySource);

boolean executeRegisterPublishChangeListener(PolarisPropertySource polarisPropertySource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {

private final ConfigFileService configFileService;

private final PolarisPropertySourceManager polarisPropertySourceManager;

private final Environment environment;
// this class provides customized logic for some customers to configure special business group files
private final PolarisConfigCustomExtensionLayer polarisConfigCustomExtensionLayer = PolarisServiceLoaderUtil.getPolarisConfigCustomExtensionLayer();

public PolarisConfigFileLocator(PolarisConfigProperties polarisConfigProperties, PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, PolarisPropertySourceManager polarisPropertySourceManager, Environment environment) {
public PolarisConfigFileLocator(PolarisConfigProperties polarisConfigProperties,
PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, Environment environment) {
this.polarisConfigProperties = polarisConfigProperties;
this.polarisContextProperties = polarisContextProperties;
this.configFileService = configFileService;
this.polarisPropertySourceManager = polarisPropertySourceManager;
this.environment = environment;
}

Expand Down Expand Up @@ -104,7 +102,7 @@ private void initCustomPolarisConfigExtensionFiles(CompositePropertySource compo
LOGGER.debug("[SCT Config] PolarisConfigCustomExtensionLayer is not init, ignore the following execution steps");
return;
}
polarisConfigCustomExtensionLayer.initConfigFiles(environment, compositePropertySource, polarisPropertySourceManager, configFileService);
polarisConfigCustomExtensionLayer.initConfigFiles(environment, compositePropertySource, configFileService);
}

private void afterLocatePolarisConfigExtension(CompositePropertySource compositePropertySource) {
Expand All @@ -123,7 +121,7 @@ private void initInternalConfigFiles(CompositePropertySource compositePropertySo

compositePropertySource.addPropertySource(polarisPropertySource);

polarisPropertySourceManager.addPropertySource(polarisPropertySource);
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);

LOGGER.info("[SCT Config] Load and inject polaris config file. file = {}", configFile);
}
Expand Down Expand Up @@ -206,7 +204,7 @@ private void initCustomPolarisConfigFiles(CompositePropertySource compositePrope

compositePropertySource.addPropertySource(polarisPropertySource);

polarisPropertySourceManager.addPropertySource(polarisPropertySource);
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);

LOGGER.info("[SCT Config] Load and inject polaris config file success. namespace = {}, group = {}, fileName = {}", namespace, group, fileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public final class PolarisConfigFilePuller {

private ConfigFileService configFileService;

private PolarisPropertySourceManager polarisPropertySourceManager;

private PolarisConfigFilePuller() {
}

Expand All @@ -64,15 +62,12 @@ private PolarisConfigFilePuller() {
*
* @param polarisContextProperties polarisContextProperties
* @param configFileService configFileService
* @param polarisPropertySourceManager polarisPropertySourceManager
* @return PolarisConfigFilePuller instance
*/
public static PolarisConfigFilePuller get(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService,
PolarisPropertySourceManager polarisPropertySourceManager) {
public static PolarisConfigFilePuller get(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService) {
PolarisConfigFilePuller puller = new PolarisConfigFilePuller();
puller.polarisContextProperties = polarisContextProperties;
puller.configFileService = configFileService;
puller.polarisPropertySourceManager = polarisPropertySourceManager;
return puller;
}

Expand All @@ -91,7 +86,7 @@ public void initInternalConfigFiles(CompositePropertySource compositePropertySou
PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(
configFile.getNamespace(), configFile.getFileGroup(), configFile.getFileName());
compositePropertySource.addPropertySource(polarisPropertySource);
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);
LOGGER.info("[SCT Config] Load and inject polaris config file. file = {}", configFile);
}
}
Expand Down Expand Up @@ -129,7 +124,7 @@ public void initCustomPolarisConfigFile(CompositePropertySource compositePropert
for (String fileName : files) {
PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(namespace, group, fileName);
compositePropertySource.addPropertySource(polarisPropertySource);
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);
LOGGER.info(
"[SCT Config] Load and inject polaris config file success. namespace = {}, group = {}, fileName = {}",
namespace, group, fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ public abstract class PolarisConfigPropertyAutoRefresher implements ApplicationL

private final PolarisConfigProperties polarisConfigProperties;

private final PolarisPropertySourceManager polarisPropertySourceManager;

private final AtomicBoolean registered = new AtomicBoolean(false);

// this class provides customized logic for some customers to configure special business group files
private final PolarisConfigCustomExtensionLayer polarisConfigCustomExtensionLayer = PolarisServiceLoaderUtil.getPolarisConfigCustomExtensionLayer();

public PolarisConfigPropertyAutoRefresher(PolarisConfigProperties polarisConfigProperties, PolarisPropertySourceManager polarisPropertySourceManager) {
public PolarisConfigPropertyAutoRefresher(PolarisConfigProperties polarisConfigProperties) {
this.polarisConfigProperties = polarisConfigProperties;
this.polarisPropertySourceManager = polarisPropertySourceManager;
}

@Override
Expand All @@ -68,7 +65,7 @@ private void registerPolarisConfigPublishEvent() {
return;
}

List<PolarisPropertySource> polarisPropertySources = polarisPropertySourceManager.getAllPropertySources();
List<PolarisPropertySource> polarisPropertySources = PolarisPropertySourceManager.getAllPropertySources();
if (CollectionUtils.isEmpty(polarisPropertySources)) {
return;
}
Expand Down Expand Up @@ -144,4 +141,11 @@ private void customRegisterPolarisConfigPublishChangeListener(PolarisPropertySou
}
polarisConfigCustomExtensionLayer.executeRegisterPublishChangeListener(polarisPropertySource);
}

/**
* Just for junit test.
*/
public void setRegistered(boolean registered) {
this.registered.set(registered);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,25 @@
*
* @author lepdou 2022-03-28
*/
public class PolarisPropertySourceManager {
public final class PolarisPropertySourceManager {

private final Map<String, PolarisPropertySource> polarisPropertySources = new ConcurrentHashMap<>();
private static final Map<String, PolarisPropertySource> polarisPropertySources = new ConcurrentHashMap<>();

public void addPropertySource(PolarisPropertySource polarisPropertySource) {
polarisPropertySources.putIfAbsent(polarisPropertySource.getPropertySourceName(), polarisPropertySource);
private PolarisPropertySourceManager() {
}

public List<PolarisPropertySource> getAllPropertySources() {
public static void addPropertySource(PolarisPropertySource polarisPropertySource) {
polarisPropertySources.put(polarisPropertySource.getPropertySourceName(), polarisPropertySource);
}

public static List<PolarisPropertySource> getAllPropertySources() {
return new ArrayList<>(polarisPropertySources.values());
}

/**
* Just for test.
*/
public static void clearPropertySources() {
polarisPropertySources.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ public class PolarisRefreshAffectedContextRefresher extends PolarisConfigPropert
private TypeConverter typeConverter;

public PolarisRefreshAffectedContextRefresher(PolarisConfigProperties polarisConfigProperties,
PolarisPropertySourceManager polarisPropertySourceManager, SpringValueRegistry springValueRegistry,
PlaceholderHelper placeholderHelper) {
super(polarisConfigProperties, polarisPropertySourceManager);
SpringValueRegistry springValueRegistry, PlaceholderHelper placeholderHelper) {
super(polarisConfigProperties);
this.springValueRegistry = springValueRegistry;
this.placeholderHelper = placeholderHelper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ public class PolarisRefreshEntireContextRefresher extends PolarisConfigPropertyA
private final ContextRefresher contextRefresher;

public PolarisRefreshEntireContextRefresher(PolarisConfigProperties polarisConfigProperties,
PolarisPropertySourceManager polarisPropertySourceManager,
ContextRefresher contextRefresher) {
super(polarisConfigProperties, polarisPropertySourceManager);
super(polarisConfigProperties);
this.contextRefresher = contextRefresher;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import java.util.concurrent.atomic.AtomicBoolean;

import com.tencent.cloud.polaris.config.adapter.PolarisConfigFilePuller;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
import com.tencent.cloud.polaris.config.config.ConfigFileGroup;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.polaris.client.api.SDKContext;
import com.tencent.polaris.configuration.api.core.ConfigFileService;
import com.tencent.polaris.configuration.factory.ConfigFileServiceFactory;
Expand Down Expand Up @@ -90,13 +90,12 @@ private CompositePropertySource locate(ConfigurableBootstrapContext bootstrapCon
PolarisConfigDataResource resource) {
CompositePropertySource compositePropertySource = new CompositePropertySource(
POLARIS_CONFIG_PROPERTY_SOURCE_NAME);
SDKContext sdkContext = bootstrapContext.get(SDKContext.class);
SDKContext sdkContext = PolarisSDKContextManager.innerGetConfigSDKContext();
if (null == this.configFileService) {
this.configFileService = ConfigFileServiceFactory.createConfigFileService(sdkContext);
}
if (null == this.puller) {
this.puller = PolarisConfigFilePuller.get(resource.getPolarisContextProperties(),
configFileService, bootstrapContext.get(PolarisPropertySourceManager.class));
this.puller = PolarisConfigFilePuller.get(resource.getPolarisContextProperties(), configFileService);
}
Profiles profiles = resource.getProfiles();
if (INTERNAL_CONFIG_FILES_LOADED.compareAndSet(false, true)) {
Expand Down
Loading
Loading