Upgrade spring boot version with 2.6.7 and spring cloud version with 3.1.x .

pull/214/head
misselvexu 2 years ago committed by Haotian Zhang
parent 3a66330a9d
commit 4b5ad54f40

@ -5,9 +5,9 @@ name: Test with Junit
on:
push:
branches: [ 2020.0 ]
branches: [ 2021.0 ]
pull_request:
branches: [ 2020.0 ]
branches: [ 2021.0 ]
jobs:
build:

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>3.0.5</version>
<version>3.1.2</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -86,13 +86,13 @@
<properties>
<!-- Project revision -->
<revision>1.4.3-2020.0.5</revision>
<revision>1.4.3-2021.0.2-SNAPSHOT</revision>
<!-- Spring Cloud -->
<spring.cloud.version>2020.0.5</spring.cloud.version>
<spring.cloud.version>2021.0.2</spring.cloud.version>
<!-- Dependencies -->
<logback.version>1.2.7</logback.version>
<logback.version>1.2.11</logback.version>
<!-- Maven Plugin Versions -->
<jacoco.version>0.8.3</jacoco.version>

@ -50,20 +50,6 @@
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<scope>test</scope>
</dependency>
<!-- powermock-module-junit4 -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<!-- powermock-api-mockito -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -19,6 +19,7 @@
package com.tencent.cloud.metadata.core;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;
@ -60,9 +61,20 @@ public class EncodeTransferMedataFeignInterceptor implements RequestInterceptor,
if (!CollectionUtils.isEmpty(requestTemplate.headers())
&& !CollectionUtils.isEmpty(requestTemplate.headers().get(CUSTOM_METADATA))) {
for (String headerMetadataStr : requestTemplate.headers().get(CUSTOM_METADATA)) {
Map<String, String> headerMetadataMap = JacksonUtils.deserialize2Map(headerMetadataStr);
for (String key : headerMetadataMap.keySet()) {
metadataContext.putTransitiveCustomMetadata(key, headerMetadataMap.get(key));
try {
// Since feign-core 11.1, RequestTemplate Adapted to RFC6570, See: https://tools.ietf.org/html/rfc6570#section-2.2
// Feign ISSUES : https://github.com/OpenFeign/feign/pull/1203
// Feign ISSUES : https://github.com/OpenFeign/feign/issues/1305
// Fixed : If you used RequestTemplate#header(name,value) method , the value needs to be encoded using URLEncoder .
headerMetadataStr = URLDecoder.decode(headerMetadataStr, "UTF-8");
Map<String, String> headerMetadataMap = JacksonUtils.deserialize2Map(headerMetadataStr);
for (String key : headerMetadataMap.keySet()) {
metadataContext.putTransitiveCustomMetadata(key, headerMetadataMap.get(key));
}
}
catch (UnsupportedEncodingException e) {
LOG.error("Set header failed.", e);
throw new RuntimeException(e);
}
}
}

@ -20,6 +20,7 @@ package com.tencent.cloud.metadata.core.intercepter;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.stream.Collectors;
import com.tencent.cloud.common.constant.MetadataConstant;
@ -121,8 +122,17 @@ public class EncodeTransferMedataFeignInterceptorTest {
@Override
public void apply(RequestTemplate template) {
template.header(MetadataConstant.HeaderName.CUSTOM_METADATA,
"{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}");
try {
// Since feign-core 11.1, RequestTemplate Adapted to RFC6570, See: https://tools.ietf.org/html/rfc6570#section-2.2
// Feign ISSUES : https://github.com/OpenFeign/feign/pull/1203
// Feign ISSUES : https://github.com/OpenFeign/feign/issues/1305
// Fixed : If you used RequestTemplate#header(name,value) method , the value needs to be encoded using URLEncoder .
template.header(MetadataConstant.HeaderName.CUSTOM_METADATA,
URLEncoder.encode("{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}", "UTF-8"));
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}

@ -99,17 +99,5 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -24,8 +24,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.client.ServiceInstance;
@ -41,8 +40,7 @@ import static org.mockito.Mockito.when;
*
* @author Haotian Zhang
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*")
@RunWith(MockitoJUnitRunner.class)
public class PolarisDiscoveryClientTest {
@Mock

@ -25,8 +25,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.mockito.junit.MockitoJUnitRunner;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
@ -41,8 +40,7 @@ import static org.mockito.Mockito.when;
*
* @author Haotian Zhang
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*")
@RunWith(MockitoJUnitRunner.class)
public class PolarisReactiveDiscoveryClientTest {
@Mock

@ -87,17 +87,5 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -32,6 +32,9 @@ public final class ReflectionUtils {
public static Object getFieldValue(Object instance, String fieldName) {
Field field = org.springframework.util.ReflectionUtils.findField(instance.getClass(), fieldName);
if (field == null) {
return null;
}
field.setAccessible(true);
try {

@ -27,7 +27,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Test for {@link MetadataLocalProperties}
* Test for {@link MetadataLocalProperties} .
*
* @author Haotian Zhang
*/

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<version>3.0.5</version>
<version>3.1.2</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -70,9 +70,9 @@
</developers>
<properties>
<revision>1.4.3-2020.0.5</revision>
<revision>1.4.3-2021.0.2-SNAPSHOT</revision>
<polaris.version>1.5.2</polaris.version>
<powermock.version>2.0.0</powermock.version>
<guava.version>31.1-jre</guava.version>
<!-- Maven Plugin Versions -->
<maven-source-plugin.version>3.2.0</maven-source-plugin.version>
@ -145,18 +145,10 @@
<version>${revision}</version>
</dependency>
<!-- powermock-module-junit4 -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
</dependency>
<!-- powermock-api-mockito -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

@ -4,7 +4,7 @@
本样例将介绍如何在Spring Cloud项目中使用```spring-cloud-tencent-polaris-gateway```以使用其各项功能。
本样例包括```gateway-zuul-service```、```gateway-scg-service```和```gateway-callee-service```。```gateway-zuul-service```和```gateway-scg-service```调用```gateway-callee-service```。
本样例包括 ```gateway-scg-service```和```gateway-callee-service```。```gateway-scg-service```调用```gateway-callee-service```。
## 使用说明
@ -31,7 +31,7 @@ spring:
- IDEA启动
分别启动```spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service```的```GatewayZuulService```、```spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service```的```GatewayScgService```和```spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service```的```GatewayCalleeService```
分别启动```spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service```的```GatewayScgService```和```spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service```的```GatewayCalleeService```
- Maven打包启动
@ -41,7 +41,7 @@ spring:
mvn clean package
```
然后在```gateway-zuul-service```、```gateway-scg-service```和```gateway-callee-service```下找到生成的jar包运行
然后在 ```gateway-scg-service```和```gateway-callee-service```下找到生成的jar包运行
```
java -jar ${app.jar}
@ -51,18 +51,6 @@ java -jar ${app.jar}
### 验证
#### Zuul调用
```shell
curl -L -X GET 'http://localhost:48082/GatewayCalleeService/gateway/example/callee/echo' -H 'SCT-CUSTOM-METADATA: {"b": 2}'
```
预期返回值
```
{"a":"1","b":2}
```
#### Spring-Cloud-Gateway调用
```shell

@ -2,9 +2,9 @@
## Example Introduction
This example shows how to use ```spring-cloud-tencent-polaris-gateway`` in Spring Cloud project for its features.
This example shows how to use ```spring-cloud-tencent-polaris-gateway``` in Spring Cloud project for its features.
This example contains ```gateway-zuul-service```, ```gateway-scg-service``` and ```gateway-callee-service```. ```gateway-zuul-service``` and ```gateway-scg-service``` invoke ```gateway-callee-service```.
This example contains ```gateway-scg-service``` and ```gateway-callee-service```. ```gateway-scg-service``` invoke ```gateway-callee-service```.
## Instruction
@ -31,7 +31,7 @@ Reference to [Polaris Getting Started](https://github.com/PolarisMesh/polaris#ge
- IDEA Launching
Launching ```spring-cloud-tencent-examples/polaris-gateway-example/gateway-zuul-service```'s ```GatewayZuulService```, ```spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service```'s ```GatewayScgService``` and ```spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service```'s ```GatewayCalleeService```
Launching ```spring-cloud-tencent-examples/polaris-gateway-example/gateway-scg-service```'s ```GatewayScgService``` and ```spring-cloud-tencent-examples/polaris-gateway-example/gateway-callee-service```'s ```GatewayCalleeService```
- Maven Package Launching
@ -41,7 +41,7 @@ Execute under ```spring-cloud-tencent-examples/polaris-gateway-example```
mvn clean package
```
Then find the jars under ```gateway-zuul-service```, ```gateway-scg-service``` and ```gateway-callee-service```, and run it:
Then find the jars under ```gateway-scg-service``` and ```gateway-callee-service```, and run it:
```
java -jar ${app.jar}
@ -51,18 +51,6 @@ Launch application, change ${app.jar} to jar's package name.
### Verify
#### Zuul Invoke
```shell
curl -L -X GET 'http://localhost:48082/GatewayCalleeService/gateway/example/callee/echo' -H 'SCT-CUSTOM-METADATA: {"b": 2}'
```
Expected return rate
```
{"a":"1","b":2}
```
#### Spring-Cloud-Gateway Invoke
```shell

@ -43,10 +43,13 @@
4. 配置限流规则并验证
北极星提供了三个方式进行限流规则的配置控制台、HTTP接口以及本地文件
本示例使用的方式为通过HTTP接口进行配置。通过以下命令来配置
- 使用的方式为通过HTTP接口进行配置。通过以下命令来配置
````
curl -X POST -H "Content-Type:application/json" 127.0.0.1:8090/naming/v1/ratelimits -d @rule.json
````
- 通过控制台进行配置,示例如下:
![](polaris-ratelimit-ui.png)
5. 验证限流效果
继续访问http://127.0.0.1:48081/business/invoke可以看到10次调用后就开始被限流

@ -50,11 +50,15 @@ Examples provided by Polaris all support to run at IDE, or compile and run with
4. Configuration rate limit and verification
Polaris provide three wats to conduct rate limit configuration (control panel, HTTP port and local files)
this example is HTTP configuration. One can figure with the following steps:
- HTTP configuration. One can figure with the following steps:
````
curl -X POST -H "Content-Type:application/json" 127.0.0.1:8090/naming/v1/ratelimits -d @rule.json
````
````
curl -X POST -H "Content-Type:application/json" 127.0.0.1:8090/naming/v1/ratelimits -d @rule.json
````
- Configuration is done through the console, example as follows.
![](polaris-ratelimit-ui.png)
5. Verify rate limit result
continue visit http://127.0.0.1:48081/business/invoke, one can see, after 10 invokes, rate limit will start:

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 KiB

@ -54,7 +54,7 @@ public class RouterCallerController {
*/
@GetMapping("/rest")
public String rest() {
return restTemplate.getForObject("http://DiscoveryCalleeService/discovery/service/callee/info", String.class);
return restTemplate.getForObject("http://RouterCalleeService/router/service/callee/info", String.class);
}
/**

@ -18,12 +18,15 @@
package com.tencent.cloud.polaris.context;
import java.util.List;
import com.tencent.polaris.api.exception.PolarisException;
import com.tencent.polaris.client.api.SDKContext;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
/**
* Autoconfiguration for Polaris {@link SDKContext}.
@ -36,8 +39,10 @@ public class PolarisContextAutoConfiguration {
@Bean(name = "polarisContext", initMethod = "init", destroyMethod = "destroy")
@ConditionalOnMissingBean
public SDKContext polarisContext(PolarisContextProperties properties) throws PolarisException {
return SDKContext.initContextByConfig(properties.configuration());
public SDKContext polarisContext(PolarisContextProperties properties,
Environment environment,
List<PolarisConfigModifier> modifierList) throws PolarisException {
return SDKContext.initContextByConfig(properties.configuration(environment, modifierList));
}
@Bean

@ -29,7 +29,6 @@ import com.tencent.polaris.factory.ConfigAPIFactory;
import com.tencent.polaris.factory.config.ConfigurationImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.util.CollectionUtils;
@ -67,19 +66,17 @@ public class PolarisContextProperties {
*/
private String service;
@Autowired
private Environment environment;
@Autowired
private List<PolarisConfigModifier> modifierList;
protected Configuration configuration() {
protected Configuration configuration(Environment environment, List<PolarisConfigModifier> modifierList) {
// 1. Read user-defined polaris.yml configuration
ConfigurationImpl configuration = (ConfigurationImpl) ConfigAPIFactory
.defaultConfig(ConfigProvider.DEFAULT_CONFIG);
// 2. Override user-defined polaris.yml configuration with SCT configuration
String defaultHost = getHost();
String defaultHost = this.localIpAddress;
if (StringUtils.isBlank(localIpAddress)) {
defaultHost = environment.getProperty("spring.cloud.client.ip-address");
}
configuration.getGlobal().getAPI().setBindIP(defaultHost);
Collection<PolarisConfigModifier> modifiers = modifierList;
@ -94,13 +91,6 @@ public class PolarisContextProperties {
return configuration;
}
private String getHost() {
if (StringUtils.isNotBlank(localIpAddress)) {
return localIpAddress;
}
return environment.getProperty("spring.cloud.client.ip-address");
}
public String getAddress() {
return address;
}

@ -95,7 +95,8 @@ public class PolarisServiceInstanceListSupplier extends DelegatingServiceInstanc
processRoutersRequest.setDstInstances(serviceInstances);
String srcNamespace = MetadataContext.LOCAL_NAMESPACE;
String srcService = MetadataContext.LOCAL_SERVICE;
Map<String, String> transitiveCustomMetadata = MetadataContextHolder.get().getAllTransitiveCustomMetadata();
MetadataContext context = MetadataContextHolder.get();
Map<String, String> transitiveCustomMetadata = context.getAllTransitiveCustomMetadata();
if (StringUtils.isNotBlank(srcNamespace) && StringUtils.isNotBlank(srcService)) {
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setNamespace(srcNamespace);

Loading…
Cancel
Save