Skip to content

Commit

Permalink
feat:add Tencent Cloud TSF support. (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyuwei01 committed Jul 24, 2024
1 parent 57b5f67 commit 2bc8964
Show file tree
Hide file tree
Showing 94 changed files with 5,580 additions and 228 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
- [feat:add zero protection.](https://github.com/Tencent/spring-cloud-tencent/pull/1346)
- [fix:fix no registry when lossless is disabled.](https://github.com/Tencent/spring-cloud-tencent/pull/1347)
- [fix:fix the ratelimit bug for 2022](https://github.com/Tencent/spring-cloud-tencent/pull/1348)
- [feat:add Tencent Cloud TSF support.](https://github.com/Tencent/spring-cloud-tencent/pull/1350)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @author juanyinyang
*/
public interface PolarisConfigCustomExtensionLayer {
boolean isEnabled();

void initRegisterConfig(PolarisConfigPropertyAutoRefresher polarisConfigPropertyAutoRefresher);

void initConfigFiles(Environment environment, CompositePropertySource compositePropertySource, ConfigFileService configFileService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,25 @@
public final class PolarisServiceLoaderUtil {

private static final Logger LOGGER = LoggerFactory.getLogger(PolarisServiceLoaderUtil.class);
private PolarisServiceLoaderUtil() {
}
// this class provides customized logic for some customers to configure special business group files
private static PolarisConfigCustomExtensionLayer polarisConfigCustomExtensionLayer;

static {
ServiceLoader<PolarisConfigCustomExtensionLayer> polarisConfigCustomExtensionLayerLoader = ServiceLoader.load(PolarisConfigCustomExtensionLayer.class);
Iterator<PolarisConfigCustomExtensionLayer> polarisConfigCustomExtensionLayerIterator = polarisConfigCustomExtensionLayerLoader.iterator();
// Generally, there is only one implementation class. If there are multiple, the last one is loaded
while (polarisConfigCustomExtensionLayerIterator.hasNext()) {
polarisConfigCustomExtensionLayer = polarisConfigCustomExtensionLayerIterator.next();
LOGGER.info("[SCT Config] PolarisConfigFileLocator init polarisConfigCustomExtensionLayer:{}", polarisConfigCustomExtensionLayer);
PolarisConfigCustomExtensionLayer temp = polarisConfigCustomExtensionLayerIterator.next();
if (temp.isEnabled()) {
polarisConfigCustomExtensionLayer = temp;
LOGGER.info("[SCT Config] PolarisConfigFileLocator init polarisConfigCustomExtensionLayer:{}", polarisConfigCustomExtensionLayer);
}
}
}

private PolarisServiceLoaderUtil() {
}

public static PolarisConfigCustomExtensionLayer getPolarisConfigCustomExtensionLayer() {
return polarisConfigCustomExtensionLayer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.polaris.config.tsf;

import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
import com.tencent.cloud.polaris.config.ConditionalOnPolarisConfigEnabled;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.config.tsf.controller.PolarisAdaptorTsfConfigController;
import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
import com.tencent.tsf.consul.config.watch.TsfConsulConfigRefreshEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author juanyinyang
* @Date Jul 23, 2023 3:52:48 PM
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnTsfEnabled
@ConditionalOnPolarisConfigEnabled
public class PolarisAdaptorTsfConfigAutoConfiguration {

private static final Logger LOGGER = LoggerFactory.getLogger(PolarisAdaptorTsfConfigAutoConfiguration.class);

{
System.setProperty("spring.cloud.polaris.config.refresh-type", "refresh_context");
LOGGER.info(
"[SCTT Config] PolarisAdaptorTsfConfigAutoConfiguration init set spring.cloud.polaris.config.refresh-type to refresh_context");
}

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "spring.cloud.consul.config.watch.enabled", matchIfMissing = true)
public TsfConsulConfigRefreshEventListener polarisAdaptorTsfConsulRefreshEventListener() {
return new TsfConsulConfigRefreshEventListener();
}

/**
* 初始化本类的条件:
* 1、关闭Spring Cloud Consul Config配置开关(如果开启Consul Config配置开关,那么初始化的是tsf自身的类ConfigController)
* 2、开启北极星配置(本类通过注解@ConditionalOnPolarisConfigEnabled开启)
* 3、tsf.config.instance.released-config.lookup.enabled的开关是打开的(默认不配置就是打开的).
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnExpression("${spring.cloud.consul.config.enabled:true} == false and ${tsf.config.instance.released-config.lookup.enabled:true} == true")
public PolarisAdaptorTsfConfigController polarisAdaptorTsfConfigController() {
return new PolarisAdaptorTsfConfigController();
}

@Bean
@ConditionalOnMissingBean
public TsfConfigurationModifier tsfConfigModifier(TsfCoreProperties tsfCoreProperties, PolarisConfigProperties polarisConfigProperties) {
return new TsfConfigurationModifier(tsfCoreProperties, polarisConfigProperties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.polaris.config.tsf;

import com.tencent.cloud.common.tsf.ConditionalOnTsfEnabled;
import com.tencent.cloud.polaris.config.ConditionalOnPolarisConfigEnabled;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
* @author juanyinyang
* @Date Jul 23, 2023 3:52:48 PM
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty("spring.cloud.polaris.enabled")
@ConditionalOnTsfEnabled
@ConditionalOnPolarisConfigEnabled
@Import(PolarisAdaptorTsfConfigAutoConfiguration.class)
public class PolarisAdaptorTsfConfigBootstrapConfiguration {


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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 com.tencent.cloud.polaris.config.tsf;

import com.tencent.cloud.common.constant.OrderConstant;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.cloud.polaris.context.tsf.config.TsfCoreProperties;
import com.tencent.polaris.factory.config.ConfigurationImpl;

/**
* TSF config modifier.
*
* @author Haotian Zhang
*/
public class TsfConfigurationModifier implements PolarisConfigModifier {


private final TsfCoreProperties tsfCoreProperties;

private final PolarisConfigProperties polarisConfigProperties;

public TsfConfigurationModifier(TsfCoreProperties tsfCoreProperties, PolarisConfigProperties polarisConfigProperties) {
this.tsfCoreProperties = tsfCoreProperties;
this.polarisConfigProperties = polarisConfigProperties;
}

@Override
public void modify(ConfigurationImpl configuration) {
if (polarisConfigProperties != null && tsfCoreProperties != null) {
polarisConfigProperties.setEnabled(tsfCoreProperties.isTsePolarisEnable());
}
}

@Override
public int getOrder() {
return OrderConstant.Modifier.CONFIG_ORDER - 1;
}
}
Loading

0 comments on commit 2bc8964

Please sign in to comment.