forked from Tencent/spring-cloud-tencent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:add Tencent Cloud TSF support. (Tencent#1349
)
- Loading branch information
1 parent
57b5f67
commit dda2aac
Showing
95 changed files
with
5,565 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...n/java/com/tencent/cloud/polaris/config/tsf/PolarisAdaptorTsfConfigAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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.ConditionalOnTsfEnabled; | ||
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); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...a/com/tencent/cloud/polaris/config/tsf/PolarisAdaptorTsfConfigBootstrapConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.polaris.config.ConditionalOnPolarisConfigEnabled; | ||
import com.tencent.cloud.polaris.context.tsf.ConditionalOnTsfEnabled; | ||
|
||
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 { | ||
|
||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...s-config/src/main/java/com/tencent/cloud/polaris/config/tsf/TsfConfigurationModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.