Merge remote-tracking branch 'upstream/master'

pull/389/head
mercyblitz 6 years ago
commit f98b74ad45

@ -81,13 +81,14 @@
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
<jacoco.version>0.7.9</jacoco.version>
<jacoco.version>0.8.3</jacoco.version>
</properties>
<modules>
<module>spring-cloud-alibaba-dependencies</module>
<module>spring-cloud-alibaba-sentinel</module>
<module>spring-cloud-alibaba-sentinel-datasource</module>
<module>spring-cloud-alibaba-sentinel-zuul</module>
<module>spring-cloud-alibaba-nacos-config</module>
<module>spring-cloud-alibaba-nacos-discovery</module>
<module>spring-cloud-alibaba-fescar</module>
@ -105,6 +106,7 @@
<module>spring-cloud-alicloud-ans</module>
<module>spring-cloud-alicloud-schedulerx</module>
<module>spring-cloud-alicloud-sms</module>
<module>spring-cloud-alibaba-coverage</module>
</modules>
<dependencyManagement>
@ -169,6 +171,15 @@
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -191,30 +202,6 @@
<reuseForks>false</reuseForks>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<destFile>target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-cloud-alibaba</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>0.2.2.BUILD-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-alibaba-coverage</artifactId>
<name>Spring Cloud Alibaba Coverage</name>
<properties>
<spring.cloud.alibaba.version>0.2.2.BUILD-SNAPSHOT</spring.cloud.alibaba.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-dubbo</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-config-server</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-datasource</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alicloud-acm</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alicloud-ans</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alicloud-context</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alicloud-oss</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alicloud-schedulerx</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alicloud-sms</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rocketmq</artifactId>
<version>${spring.cloud.alibaba.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>report-aggregate</id>
<phase>test</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/../target/site/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -20,7 +20,7 @@
<sentinel.version>1.4.2</sentinel.version>
<oss.version>3.1.0</oss.version>
<fescar.version>0.1.3</fescar.version>
<nacos.client.version>0.8.1</nacos.client.version>
<nacos.client.version>0.8.2</nacos.client.version>
<nacos.config.version>0.8.0</nacos.config.version>
<acm.version>1.0.8</acm.version>
<ans.version>1.0.1</ans.version>
@ -148,6 +148,11 @@
<artifactId>sentinel-web-servlet</artifactId>
<version>${sentinel.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-zuul-adapter</artifactId>
<version>${sentinel.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
@ -256,6 +261,11 @@
<artifactId>spring-cloud-alibaba-sentinel-datasource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-zuul</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alicloud-oss</artifactId>

@ -6,7 +6,7 @@ Spring Cloud AliCloud ACM 是 Config Server 和 Client 的替代方案,客户
=== 如何引入 Spring Cloud AliCloud ACM
Spring Cloud Alibaba 已经发布了 0.2.2.BUILD-SNAPSHOT 版本需要首先导入依赖管理POM。
Spring Cloud Alibaba 已经发布了 0.2.2.BUILD-SNAPSHOT 版本,需要首先导入依赖管理 POM。
[source,xml]
----
@ -23,7 +23,7 @@ Spring Cloud Alibaba 已经发布了 0.2.2.BUILD-SNAPSHOT 版本,需要首先
</dependencyManagement>
----
接下来引入 Spring Cloud AliCloud ACM Starter 即可
并引入 Spring Cloud AliCloud ACM Starter 依赖
[source,xml]
----
@ -53,7 +53,7 @@ public class ProviderApplication {
}
----
既然需要从配置中心服务端获取配置信息,那么肯定需要配置服务端的地址,在 bootstrap.properties 中,还需要配置以下信息。
在从配置中心服务端获取配置信息之前,还需要配置服务端的地址,在 bootstrap.properties 中,还需要配置以下信息。
[source,properties]
----
@ -68,18 +68,18 @@ spring.cloud.alicloud.acm.server-port=8080
NOTE: 此时没有启动配置中心,启动应用会报错,因此在应用启动之前,应当首先启动配置中心。
=== 启动配置中心
==== 启动配置中心
ACM 使用的配置中心有两种,一种是完全免费的轻量版配置中心,主要用于开发和本地调试,一种是云上配置中心ACM。通常情况下可以使用轻量版配置中心作为开发和测试环境使用云上的 ACM 作为灰度和生产环境。
ACM 使用的配置中心有两种,一种是本地运行的轻量版配置中心,主要用于开发和本地调试,一种是阿里云产品 ACM。通常情况下可以使用轻量版配置中心作为开发和测试环境使用云上的 ACM 作为灰度和生产环境。
==== 启动轻量版配置中心
===== 使用轻量版配置中心
轻量版配置中心的下载和启动方式可参考 https://help.aliyun.com/document_detail/44163.html?spm=a2c4g.11186623.6.677.5f206b82Z2mTCF[这里]
轻量版配置中心的下载和启动方式可参考 https://help.aliyun.com/document_detail/44163.html[这里]
NOTE: 只需要进行第1步下载轻量配置中心和第2步启动轻量配置中心即可第3步配置hosts在与 ACM 结合使用时,不需要操作
NOTE: 只需要执行文档中的第1步 (下载轻量配置中心) 和第2步 (启动轻量配置中心)
==== 使用云配置中心
===== 使用阿里云配置中心
使用云上 ACM ,可以省去服务端的维护工作,同时稳定性也会更有保障。当使用云上配置中心时,代码部分和使用轻量配置中心并没有区别,但是配置上会有一些区别。
@ -88,7 +88,7 @@ NOTE: 只需要进行第1步下载轻量配置中心和第2步启动轻
[source,properties]
----
# 应用名会被作为从服务端获取配置 key 的关键词组成部分,因此是必选
spring.application.name=ans-provider
spring.application.name=acm-config
# 端口配置自由配置即可
server.port=18081
# 以下就是配置中心的IP和端口配置
@ -99,9 +99,9 @@ spring.cloud.alicloud.acm.endpoint=acm.aliyun.com
spring.cloud.alicloud.acm.namespace=你的 ACM namespace需要在 ACM 控制台查询
----
NOTE: EDAS 提供应用托管服务,如果你将应用托管到 EDAS那么 EDAS 将会自动为你填充所有配置。
NOTE: EDAS 提供应用托管服务,如果你将应用托管到 EDAS那么 EDAS 将会自动为你填充所有与业务无关的配置。
=== 在配置中心添加配置
==== 在配置中心添加配置
1. 启动好轻量版配置中心之后,在控制台中添加如下的配置。
@ -115,9 +115,9 @@ Content: user.name=james
user.age=18
----
NOTE: DataId 的格式为 `{prefix}. {file-extension}`,prefix 默认从配置 spring.application.name 中取值file-extension 默认的值为 "properties"。
NOTE: DataId 的格式为 `{prefix}.{file-extension}`,prefix 默认从配置 spring.application.name 中取值file-extension 默认的值为 "properties"。
=== 启动应用验证
==== 启动应用验证
启动这个Example可以在控制台看到打印出的值正是我们在轻量版配置中心上预先配置的值。
@ -133,16 +133,16 @@ spring-cloud-starter-alicloud-acm 中 DataId 默认的文件扩展名是 propert
NOTE: 修改文件扩展名后,在配置中心中的 DataID 以及 Content 的格式都必须做相应的修改。
=== 支持配置的动态更新
=== 动态更新
spring-cloud-starter-alicloud-acm 默认支持配置的动态更新,当您在配置中心修改配置的内容时,会触发 Spring 中的 Context Refresh 动作
spring-cloud-starter-alicloud-acm 默认支持配置的动态更新,当您在配置中心修改配置的内容时,会发布 Spring 中的 RefreshEvent 事件
带有 @RefreshScope 和 @ConfigurationProperties 注解的类会自动刷新。
NOTE: 你可以通过配置 spring.cloud.alicloud.acm.refresh.enabled=false 来关闭动态刷新
NOTE: 你可以通过配置 spring.cloud.alicloud.acm.refresh.enabled=false 来关闭动态刷新
=== profile 粒度的配置
=== Profile 粒度的配置
spring-cloud-starter-alicloud-acm 在加载配置的时候,首先会尝试去加载 dataid 为{spring.application.name}.{file-extension}的配置,当设置了 spring.profiles.active 中配置有内容时,还会尝试依次去加载 spring.profile 对应的内容, dataid 的格式为{spring.application.name}-{profile}.{file-extension}的配置,且后者的优先级高于前者。
spring-cloud-starter-alicloud-acm 在加载配置的时候,首先会加载 DataId 为{spring.application.name}.{file-extension}的配置,当 spring.profiles.active 中配置有内容时,还会依次去加载 spring.profile 对应的内容, DataId 的格式为{spring.application.name}-{profile}.{file-extension}的配置,且后者的优先级高于前者。
spring.profiles.active 属于配置的元数据,所以也必须配置在 bootstrap.properties 或 bootstrap.yaml 中。比如可以在 bootstrap.properties 中增加如下内容。
@ -154,8 +154,11 @@ spring.profiles.active={profile-name}
Note: 也可以通过 JVM 参数 -Dspring.profiles.active=develop 或者 --spring.profiles.active=develop 这类优先级更高的方式来配置,只需遵循 Spring Boot 规范即可。
=== 自定义配置中心超时时间
ACM Client 与 Server 通信的超时时间默认是 3000ms可以通过 `spring.cloud.alicloud.acm.timeout` 来修改超时时间,单位为 ms 。
=== 支持自定义 Group 的配置
=== 自定义 Group 的配置
在没有明确指定 `{spring.cloud.alicloud.acm.group}` 配置的情况下, 默认使用的是 DEFAULT_GROUP 。如果需要自定义自己的 Group可以通过以下配置来实现
@ -164,9 +167,9 @@ Note: 也可以通过 JVM 参数 -Dspring.profiles.active=develop 或者 --sprin
spring.cloud.alicloud.acm.group=DEVELOP_GROUP
----
NOTE: 该配置必须放在 bootstrap.properties 文件中。并且在添加配置时 Group 的值一定要和 `spring.cloud.alicloud.acm.group` 的配置值一致。
NOTE: 该配置必须放在 bootstrap.properties 文件中。并且在添加配置时 Group 的值要和 `spring.cloud.alicloud.acm.group` 的配置值一致。
==== 支持共享配置
=== 共享配置
ACM 提供了一种多个应用之间共享配置中心的同一个配置的推荐方式,供多个应用共享一些配置时使用,您在使用的时候需要添加在 bootstrap 中添加一个配置项 `spring.application.group`。
@ -175,11 +178,14 @@ ACM 提供了一种多个应用之间共享配置中心的同一个配置的推
spring.application.group=company.department.team
----
这时你的应用在获取之前提到的自身所独有的配置之前,会先依次从这些 DataId 去获取,分别是 company:application.properties, company.department:application.properties, company.department.team:application.properties。
然后,还会从 {spring.application.group}:{spring.application.name}.{file-extension} 中获取
越往后优先级越高,最高的仍然是应用自身所独有的配置。
这时应用在获取上文提到的自身所独有的配置之前,会先依次从这些 DataId 去获取,分别是 company:application.properties, company.department:application.properties, company.department.team:application.properties。
然后,还会从 {spring.application.group}:{spring.application.name}.{file-extension} 中获取,越往后优先级越高,最高的仍然是应用自身所独有的配置。
NOTE: 共享配置中 DataId 默认后缀为 properties可以通过 spring.cloud.alicloud.acm.file-extension 配置. `{spring.application.group}:{spring.application.name}.{file-extension}` 。
NOTE: 如果设置了 `spring.profiles.active` DataId 的格式还支持 `{spring.application.group}:{spring.application.name}-{spring.profiles.active}.{file-extension}`。优先级高于 `{spring.application.group}:{spring.application.name}.{file-extension}`
=== Actuator 监控
ACM 对应的 Actuator 监控地址为 `/acm`,其中 config 代表了 ACM 元数据配置的信息,`runtime.sources` 对应的是从 ACM 服务端获取的配置的信息及最后刷新时间, `runtime.refreshHistory` 对应的是动态刷新的历史记录。

@ -6,7 +6,7 @@ Spring Cloud Alibaba Cloud ACM is an alternative solution for Config Server and
=== How to Introduce Spring Cloud Alibaba Cloud ACM
Weve released Spring Cloud Alibaba version 0.2.1. You will need to add dependency management POM first.
Weve released Spring Cloud Alibaba version 0.2.2.BUILD-SNAPSHOT. You will need to add dependency management POM first.
[source,xml]
----
@ -68,18 +68,18 @@ spring.cloud.alicloud.acm.server-port=8080
NOTE: By now the configuration center is not started yet, so you will get an error message if your application is started. Therefore, start the configuration center before you start your application.
=== Start Configuration Center
==== Start Configuration Center
ACM uses two types of configuration centers. One is a lightweight configuration center which is totally free, the other is ACM which is used on Alibaba Cloud. Generally, you can use the lightweight version for application development and local testing, and use ACM for canary deployment or production.
ACM uses two types of configuration centers. One is lightweight configuration center, the other is ACM which is used on Alibaba Cloud. Generally, you can use the lightweight version for application development and local testing, and use ACM for canary deployment or production.
==== Start Lightweight Configuration Center
===== Use Lightweight Configuration Center
Refer to the https://help.aliyun.com/document_detail/44163.html[Configure Lightweight Configuration Center] for details about how to download and install lightweight configuration center.
NOTE: You only need to perform step 1(Download lightweight configuration center) and step 2(Start lightweight configuration center). Step 3(Configure hosts) is not required if you use ACM at the same time.
NOTE: You only need to perform step 1(Download lightweight configuration center) and step 2(Start lightweight configuration center).
==== Use ACM on the Cloud
===== Use ACM on the Alibaba Cloud
Using ACM on the cloud saves you from the tedious work of server maintenance while at the same time provides a better stability. There is no difference at the code level between using ACM on cloud and lightweight configuration center, but there are some differences in configurations.
@ -88,7 +88,7 @@ The following is a simple sample of using ACM. You can view configuration detail
[source,properties]
----
# The application name will be used as part of the keyword to obtain configuration key from the server, and is mandatory.
spring.application.name=ans-provider
spring.application.name=acm-config
# Configure your own port number
server.port=18081
# The following is the IP and port number of the configuration center.
@ -99,9 +99,9 @@ spring.cloud.alicloud.acm.endpoint=acm.aliyun.com
spring.cloud.alicloud.acm.namespace=Your ACM namespace(You can find the namespace on the ACM console)
----
NOTE: EDAS provides application hosting service and will fill in all configurations automatically for the hosted applications.
NOTE: EDAS provides application hosting service and will fill in all configurations about ACM automatically for the hosted applications.
=== Add Configuration in the Configuration Center
==== Add Configuration in the Configuration Center
1. After you start the lightweight configuration center, add the following configuration on the console.
@ -117,7 +117,7 @@ Content: user.name=james
NOTE: The format of dataId is `{prefix}. {file-extension}`. “prefix” is obtained from spring.application.name by default, and the value of “file-extension” is "properties” by default.
=== Start Application Verification
==== Start Application Verification
Start the following example and you can see that the value printed on the console is the value we configured in the lightweight configuration center.
@ -133,16 +133,16 @@ You can set the file extension using spring.cloud.alicloud.acm.file-extension. J
NOTE: After you change the file extension, you need to make corresponding format changes in the DataID and content of the configuration center.
=== Dynamic Configuration Updates
=== Dynamic Configuration Refresh
spring-cloud-starter-alicloud-acm supports dynamic configuration updates. Context Refresh in Spring is triggered when you update configuration in the configuration center.
All classes with @RefreshScope and @ConfigurationProperties annotations will be refershed automatically.
spring-cloud-starter-alicloud-acm supports dynamic configuration updates. RefreshEvent in Spring is published when you update configuration in the configuration center.
All classes with @RefreshScope and @ConfigurationProperties annotations will be refreshed automatically.
NOTE: You can disable automatic refresh by this setting: spring.cloud.alicloud.acm.refresh.enabled=false
=== Configure Profile Granularity
When configuration is loaded by spring-cloud-starter-alicloud-acm, configuration with dataid {spring.application.name}. {file-extension} will be loaded first. If there is content in spring.profiles.active, the content of spring.profile, and configuration with the dataid format of{spring.application.name}-{profile}. {file-extension} will also be loaded in turn, and the latter has higher priority.
When configuration is loaded by spring-cloud-starter-alicloud-acm, configuration with DataId {spring.application.name}. {file-extension} will be loaded first. If there is content in spring.profiles.active, the content of spring.profile, and configuration with the dataid format of{spring.application.name}-{profile}. {file-extension} will also be loaded in turn, and the latter has higher priority.
spring.profiles.active is the configuration metadata, and should also be configured in bootstrap.properties or bootstrap.yaml. For example, you can add the following content in bootstrap.properties.
@ -154,6 +154,10 @@ spring.profiles.active={profile-name}
Note: You can also configure the granularity through JVM parameters such as -Dspring.profiles.active=develop or --spring.profiles.active=develop, which have higher priority. Just follow the specifications of Spring Boot.
=== Support Custom ACM Timeout
the default timeout of ACM client get config from sever is 3000 ms . If you need to define a timeout, set configuration `spring.cloud.alicloud.acm.timeout`,the unit is millisecond.
=== Support Custom Group Configurations
@ -183,3 +187,7 @@ The later in order, the higer the priority, and the unique configuration of the
NOTE: The default suffix of DataId is properties, and you can change it using spring.cloud.alicloud.acm.file-extension. `{spring.application.group}: {spring.application.name}. {file-extension}` 。
NOTE: If you configured `spring.profiles.active` , then the DataId format of `{spring.application.group}: {spring.application.name}-{spring.profiles.active}. {file-extension}` is also supported, and has higher priority than `{spring.application.group}: {spring.application.name}. {file-extension}`
=== Actuator Endpoint
the Actuator endpoint of ACM is `/acm`, `config` represents the ACM metadata configuration information, `runtime.sources` corresponds to the configuration information obtained from the ACM server and the last refresh time, `runtime.refreshHistory` corresponds to the dynamic refresh history.

@ -214,4 +214,29 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -34,30 +34,4 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<skip>true</skip>
<check/>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -38,25 +38,4 @@
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<skip>true</skip>
<check/>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -39,30 +39,4 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<skip>true</skip>
<check/>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -44,6 +44,7 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
</dependencies>
<build>

@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @author xiaojing
*/
@EnableDiscoveryClient
@SpringBootApplication
public class ProviderApplication {

@ -0,0 +1,35 @@
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.springframework.cloud.alibaba.cloud.examples;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author xiaolongzuo
*/
@RestController
public class HelloController {
@RequestMapping("/")
@ResponseBody
public String hello() {
return "OK";
}
}

@ -16,25 +16,25 @@
package org.springframework.cloud.alibaba.cloud.examples;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.edas.schedulerx.ProcessResult;
import com.alibaba.edas.schedulerx.ScxSimpleJobContext;
import com.alibaba.edas.schedulerx.ScxSimpleJobProcessor;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author xiaolongzuo
*/
public class SimpleTask implements ScxSimpleJobProcessor {
@Autowired
private TestService testService;
@Autowired
private TestService testService;
@Override
public ProcessResult process(ScxSimpleJobContext context) {
System.out.println("-----------Hello world---------------");
testService.test();
ProcessResult processResult = new ProcessResult(true);
return processResult;
}
@Override
public ProcessResult process(ScxSimpleJobContext context) {
testService.test();
ProcessResult processResult = new ProcessResult(true);
return processResult;
}
}

@ -0,0 +1,39 @@
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.springframework.cloud.alibaba.cloud.examples;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author xiaolongzuo
*/
@RestController
public class TestController {
static AtomicInteger atomicInteger = new AtomicInteger(0);
@RequestMapping("/test")
@ResponseBody
public String test() {
return String.valueOf(atomicInteger.get());
}
}

@ -24,7 +24,7 @@ import org.springframework.stereotype.Service;
@Service
public class TestService {
public void test() {
System.out.println("---------IOC Success--------");
}
public void test() {
TestController.atomicInteger.incrementAndGet();
}
}

@ -114,4 +114,28 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -61,4 +61,28 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -96,4 +96,28 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -80,6 +80,30 @@
<artifactId>spring-cloud-test-support</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -98,4 +98,29 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,141 @@
# Sentinel Spring Cloud Zuul Adapter
Zuul does not provide rateLimit function, If use default `SentinelRibbonFilter` route filter. it wrapped by Hystrix Command. so only provide Service level
circuit protect.
Sentinel can provide `ServiceId` level and `API Path` level flow control for spring cloud zuul gateway service.
*Note*: this project is for zuul 1.
## How to use
1. Add maven dependency
```xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-zuul</artifactId>
<version>x.y.z</version>
</dependency>
```
2. Set application.property
```
// default value is false
spring.cloud.sentinel.zuul.enabled=true
```
## How it works
As Zuul run as per thread per connection block model, we add filters around `route Filter` to trace sentinel statistics.
- `SentinelPreFilter`: Get an entry of resource,the first order is **ServiceId**, then **API Path**.
- `SentinelPostFilter`: When success response,exit entry.
- `SentinelErrorFilter`: When get an `Exception`, trace the exception and exit context.
the order of Filter can be changed by configuration:
```
spring.cloud.sentinel.zuul.order.post=0
spring.cloud.sentinel.zuul.order.pre=10000
spring.cloud.sentinel.zuul.order.error=-1
```
Filters create structure like:
```bash
EntranceNode: machine-root(t:3 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
-EntranceNode: coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
--coke(t:2 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
---/coke/uri(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
-EntranceNode: sentinel_default_context(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
-EntranceNode: book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
--book(t:1 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
---/book/uri(t:0 pq:0 bq:0 tq:0 rt:0 prq:0 1mp:0 1mb:0 1mt:0)
```
`book` and `coke` are serviceId.
`---/book/uri` is api path, the real uri is `/uri`.
## Integration with Sentinel DashBord
Start [Sentinel DashBord](https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0).
## Rule config with dataSource
Sentinel has full rule config features. see [Dynamic-Rule-Configuration](https://github.com/alibaba/Sentinel/wiki/Dynamic-Rule-Configuration)
## Custom Fallbacks
Implements `SentinelFallbackProvider` to define your own Fallback Provider when Sentinel Block Exception throwing for different rout. the default
Fallback Provider is `DefaultBlockFallbackProvider`.
By default Fallback route is `ServiveId + URI PATH`, example `/book/coke`, first `book` is serviceId, `/uri` is URI PATH, so both
can be needed.
Here is an example:
```java
// custom provider
public class MyCokeServiceBlockFallbackProvider implements SentinelFallbackProvider {
private Logger logger = LoggerFactory.getLogger(DefaultBlockFallbackProvider.class);
// you can define root as service level
@Override
public String getRoute() {
return "/coke/uri";
}
@Override
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
if (cause instanceof BlockException) {
logger.info("get in fallback block exception:{}", cause);
return response(HttpStatus.TOO_MANY_REQUESTS, route);
} else {
return response(HttpStatus.INTERNAL_SERVER_ERROR, route);
}
}
}
```
## Custom Request Origin Parser
By default this adapter use `DefaultRequestOriginParser` to parse sentinel origin.
```java
public class CustomRequestOriginParser implements RequestOriginParser {
@Override
public String parseOrigin(HttpServletRequest request) {
// do custom logic.
return "";
}
}
```
## Custom UrlCleaner
By default this adapter use `DefaultUrlCleaner` to define uri resource.
```java
public class CustomUrlCleaner implements UrlCleaner {
@Override
public String clean(String originUrl) {
// do custom logic.
return originUrl;
}
}
```

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-cloud-alibaba</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>0.2.2.BUILD-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-zuul</artifactId>
<name>Spring Cloud Alibaba Sentinel Zuul</name>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-zuul-adapter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,110 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.springframework.cloud.alibaba.sentinel.zuul;
import com.alibaba.csp.sentinel.adapter.zuul.fallback.DefaultRequestOriginParser;
import com.alibaba.csp.sentinel.adapter.zuul.fallback.DefaultUrlCleaner;
import com.alibaba.csp.sentinel.adapter.zuul.fallback.RequestOriginParser;
import com.alibaba.csp.sentinel.adapter.zuul.fallback.UrlCleaner;
import com.alibaba.csp.sentinel.adapter.zuul.filters.SentinelErrorFilter;
import com.alibaba.csp.sentinel.adapter.zuul.filters.SentinelPostFilter;
import com.alibaba.csp.sentinel.adapter.zuul.filters.SentinelPreFilter;
import com.alibaba.csp.sentinel.adapter.zuul.properties.SentinelZuulProperties;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.netflix.zuul.ZuulFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.alibaba.sentinel.zuul.listener.FallBackProviderListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import static org.springframework.cloud.alibaba.sentinel.zuul.SentinelZuulAutoConfiguration.PREFIX;
/**
* Sentinel Spring Cloud Zuul AutoConfiguration
*
* @author tiger
*/
@Configuration
@ConditionalOnProperty(prefix = PREFIX, name = "enabled", havingValue = "true")
public class SentinelZuulAutoConfiguration {
@Autowired
private Environment environment;
public static final String PREFIX = "spring.cloud.alibaba.sentinel.zuul";
@Bean
public SentinelZuulProperties sentinelZuulProperties() {
SentinelZuulProperties properties = new SentinelZuulProperties();
String enabledStr = environment.getProperty(PREFIX + "." + "enabled");
String preOrderStr = environment.getProperty(PREFIX + "." + "order.pre");
String postOrderStr = environment.getProperty(PREFIX + "." + "order.post");
String errorOrderStr = environment.getProperty(PREFIX + "." + "order.error");
if (StringUtil.isNotEmpty(enabledStr)) {
Boolean enabled = Boolean.valueOf(enabledStr);
properties.setEnabled(enabled);
}
if (StringUtil.isNotEmpty(preOrderStr)) {
properties.getOrder().setPre(Integer.parseInt(preOrderStr));
}
if (StringUtil.isNotEmpty(postOrderStr)) {
properties.getOrder().setPost(Integer.parseInt(postOrderStr));
}
if (StringUtil.isNotEmpty(errorOrderStr)) {
properties.getOrder().setError(Integer.parseInt(errorOrderStr));
}
return properties;
}
@Bean
@ConditionalOnMissingBean(UrlCleaner.class)
public UrlCleaner urlCleaner(){
return new DefaultUrlCleaner();
}
@Bean
@ConditionalOnMissingBean(RequestOriginParser.class)
public RequestOriginParser requestOriginParser(){
return new DefaultRequestOriginParser();
}
@Bean
public ZuulFilter preFilter(SentinelZuulProperties sentinelZuulProperties,UrlCleaner urlCleaner,
RequestOriginParser requestOriginParser) {
return new SentinelPreFilter(sentinelZuulProperties,urlCleaner,requestOriginParser);
}
@Bean
public ZuulFilter postFilter(SentinelZuulProperties sentinelZuulProperties) {
return new SentinelPostFilter(sentinelZuulProperties);
}
@Bean
public ZuulFilter errorFilter(SentinelZuulProperties sentinelZuulProperties) {
return new SentinelErrorFilter(sentinelZuulProperties);
}
@Bean
public FallBackProviderListener fallBackProviderListener(DefaultListableBeanFactory beanFactory) {
return new FallBackProviderListener(beanFactory);
}
}

@ -0,0 +1,43 @@
package org.springframework.cloud.alibaba.sentinel.zuul.listener;
import com.alibaba.csp.sentinel.adapter.zuul.fallback.DefaultBlockFallbackProvider;
import com.alibaba.csp.sentinel.adapter.zuul.fallback.ZuulBlockFallbackManager;
import com.alibaba.csp.sentinel.adapter.zuul.fallback.ZuulBlockFallbackProvider;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
import java.util.Map;
/**
* @author tiger
*/
public class FallBackProviderListener implements SmartInitializingSingleton {
private static final Logger logger = LoggerFactory.getLogger(FallBackProviderListener.class);
private final DefaultListableBeanFactory beanFactory;
public FallBackProviderListener(DefaultListableBeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
@Override
public void afterSingletonsInstantiated() {
Map<String, ZuulBlockFallbackProvider> providerMap = beanFactory.getBeansOfType(ZuulBlockFallbackProvider.class);
if (MapUtils.isNotEmpty(providerMap)) {
providerMap.forEach((k, v) -> {
logger.info("[Sentinel] Register provider name:{}, instance: {}", k, v);
ZuulBlockFallbackManager.registerProvider(v);
});
} else {
logger.info("[Sentinel] Register default fallback provider. ");
ZuulBlockFallbackManager.registerProvider(new DefaultBlockFallbackProvider());
}
}
}

@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.sentinel.zuul.SentinelZuulAutoConfiguration

@ -137,4 +137,28 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -69,5 +69,29 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -118,4 +118,28 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -128,5 +128,28 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -15,15 +15,15 @@
*/
package org.springframework.cloud.alicloud.context.nacos;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
import java.util.Properties;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
/**
* @author pbting
@ -54,7 +54,7 @@ public class NacosDiscoveryParameterInitListener
}
// initialize nacos configuration
Properties properties = System.getProperties();
properties.setProperty("spring.cloud.nacos.discovery.server-mode", "EDAS");
// step 1: set some properties for spring cloud alibaba nacos discovery
properties.setProperty("spring.cloud.nacos.discovery.server-addr", "");
properties.setProperty("spring.cloud.nacos.discovery.endpoint",
@ -67,7 +67,7 @@ public class NacosDiscoveryParameterInitListener
edasChangeOrderConfiguration.getDauthSecretKey());
// step 2: set these properties for nacos client
properties.setProperty("webContext", "/vipserver");
properties.setProperty("serverPort", "80");
properties.setProperty("nacos.naming.web.context", "/vipserver");
properties.setProperty("nacos.naming.exposed.port", "80");
}
}

@ -31,13 +31,33 @@ import com.aliyun.oss.ClientBuilderConfiguration;
@ConfigurationProperties("spring.cloud.alicloud.oss")
public class OssProperties {
/**
* Authorization Mode, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
@Value("${spring.cloud.alicloud.oss.authorization-mode:AK_SK}")
private AliCloudAuthorizationMode authorizationMode;
/**
* Endpoint, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
private String endpoint;
/**
* Sts token, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
private StsToken sts;
/**
* Client Configuration, please see <a href=
* "https://help.aliyun.com/document_detail/32010.html?spm=a2c4g.11186623.6.659.29f145dc3KOwTh">oss
* docs</a>.
*/
private ClientBuilderConfiguration config;
public AliCloudAuthorizationMode getAuthorizationMode() {

@ -26,8 +26,18 @@ import com.alibaba.cloud.context.scx.ScxConfiguration;
@ConfigurationProperties("spring.cloud.alicloud.scx")
public class ScxProperties implements ScxConfiguration {
/**
* Group id, please see <a href=
* "https://help.aliyun.com/document_detail/35359.html?spm=a2c4g.11186623.6.721.69ca5763p9IJly">scx
* docs</a>.
*/
private String groupId;
/**
* Domain name, please see <a href=
* "https://help.aliyun.com/document_detail/35359.html?spm=a2c4g.11186623.6.721.69ca5763p9IJly">scx
* docs</a>.
*/
private String domainName;
@Override

@ -48,7 +48,9 @@ public class StatisticsTaskStarter implements InitializingBean {
private static final String NACOS_CONFIG_SERVER_MODE_KEY = "spring.cloud.nacos.config.server-mode";
private static final String NACOS_CONFIG_SERVER_MODE_VALUE = "EDAS";
private static final String NACOS_DISCOVERY_SERVER_MODE_KEY = "spring.cloud.nacos.discovery.server-mode";
private static final String NACOS_SERVER_MODE_VALUE = "EDAS";
@Autowired(required = false)
private AliCloudEdasSdk aliCloudEdasSdk;
@ -106,10 +108,14 @@ public class StatisticsTaskStarter implements InitializingBean {
if (acmContextBootstrapConfiguration != null && acmEnableEdas) {
components.add("SC-ACM");
}
if (NACOS_CONFIG_SERVER_MODE_VALUE
if (NACOS_SERVER_MODE_VALUE
.equals(System.getProperty(NACOS_CONFIG_SERVER_MODE_KEY))) {
components.add("SC-NACOS-CONFIG");
}
if (NACOS_SERVER_MODE_VALUE
.equals(System.getProperty(NACOS_DISCOVERY_SERVER_MODE_KEY))) {
components.add("SC-NACOS-DISCOVERY");
}
return components;
}

@ -0,0 +1,23 @@
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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 org.springframework.cloud.alibaba.nacos;
/**
* @author xiaolongzuo
*/
public class NacosDiscoveryAutoConfiguration {
}

@ -16,8 +16,7 @@
package org.springframework.cloud.alicloud.context.nacos;
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import org.junit.BeforeClass;
import org.junit.Test;
@ -25,35 +24,39 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication;
import org.springframework.cloud.alicloud.utils.ChangeOrderUtils;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
/**
* @author xiaolongzuo
*/
@PrepareForTest({EdasChangeOrderConfigurationFactory.class,
NacosConfigParameterInitListener.class, AliCloudAnsInitializer.class})
public class NacosDiscoveryParameterInitListenerTests extends BaseAliCloudSpringApplication {
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
NacosDiscoveryParameterInitListener.class, AliCloudAnsInitializer.class })
public class NacosDiscoveryParameterInitListenerTests
extends BaseAliCloudSpringApplication {
@BeforeClass
public static void setUp() {
ChangeOrderUtils.mockChangeOrder();
System.getProperties().setProperty("webContext", "/vipserver");
System.getProperties().setProperty("serverPort", "80");
}
@BeforeClass
public static void setUp() {
ChangeOrderUtils.mockChangeOrder();
}
@Test
public void testNacosParameterInitListener() {
assertThat(System.getProperty("spring.cloud.nacos.config.server-addr"))
.isEqualTo("");
assertThat(System.getProperty("spring.cloud.nacos.config.endpoint"))
.isEqualTo("testDomain");
assertThat(System.getProperty("spring.cloud.nacos.config.namespace"))
.isEqualTo("testTenantId");
assertThat(System.getProperty("spring.cloud.nacos.config.access-key"))
.isEqualTo("testAK");
assertThat(System.getProperty("spring.cloud.nacos.config.secret-key"))
.isEqualTo("testSK");
assertThat(System.getProperties().getProperty("webContext")).isEqualTo("/vipserver");
assertThat(System.getProperties().getProperty("serverPort")).isEqualTo("80");
}
@Test
public void testNacosParameterInitListener() {
assertThat(System.getProperty("spring.cloud.nacos.discovery.server-mode"))
.isEqualTo("EDAS");
assertThat(System.getProperty("spring.cloud.nacos.discovery.server-addr"))
.isEqualTo("");
assertThat(System.getProperty("spring.cloud.nacos.discovery.endpoint"))
.isEqualTo("testDomain");
assertThat(System.getProperty("spring.cloud.nacos.discovery.namespace"))
.isEqualTo("testTenantId");
assertThat(System.getProperty("spring.cloud.nacos.discovery.access-key"))
.isEqualTo("testAK");
assertThat(System.getProperty("spring.cloud.nacos.discovery.secret-key"))
.isEqualTo("testSK");
assertThat(System.getProperties().getProperty("nacos.naming.web.context"))
.isEqualTo("/vipserver");
assertThat(System.getProperties().getProperty("nacos.naming.exposed.port"))
.isEqualTo("80");
}
}

@ -61,4 +61,28 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -50,5 +50,28 @@
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -79,5 +79,29 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -77,5 +77,29 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Loading…
Cancel
Save