diff --git a/pom.xml b/pom.xml index bffa398f..09e95d5e 100644 --- a/pom.xml +++ b/pom.xml @@ -81,13 +81,14 @@ 2.8.2 2.21.0 1.6 - 0.7.9 + 0.8.3 spring-cloud-alibaba-dependencies spring-cloud-alibaba-sentinel spring-cloud-alibaba-sentinel-datasource + spring-cloud-alibaba-sentinel-zuul spring-cloud-alibaba-nacos-config spring-cloud-alibaba-nacos-discovery spring-cloud-alibaba-fescar @@ -105,6 +106,7 @@ spring-cloud-alicloud-ans spring-cloud-alicloud-schedulerx spring-cloud-alicloud-sms + spring-cloud-alibaba-coverage @@ -169,6 +171,15 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + org.apache.maven.plugins @@ -191,30 +202,6 @@ false - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - target/coverage-reports/jacoco-unit.exec - target/coverage-reports/jacoco-unit.exec - - - - jacoco-initialize - - prepare-agent - - - - jacoco-site - test - - report - - - - diff --git a/spring-cloud-alibaba-coverage/pom.xml b/spring-cloud-alibaba-coverage/pom.xml new file mode 100644 index 00000000..d8ef6b21 --- /dev/null +++ b/spring-cloud-alibaba-coverage/pom.xml @@ -0,0 +1,117 @@ + + + + spring-cloud-alibaba + org.springframework.cloud + 0.2.2.BUILD-SNAPSHOT + + 4.0.0 + + spring-cloud-alibaba-coverage + Spring Cloud Alibaba Coverage + + + 0.2.2.BUILD-SNAPSHOT + + + + org.springframework.cloud + spring-cloud-alibaba-dubbo + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alibaba-nacos-config + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alibaba-nacos-config-server + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alibaba-nacos-discovery + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alibaba-sentinel + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alibaba-sentinel-datasource + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alicloud-acm + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alicloud-ans + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alicloud-context + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alicloud-oss + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alicloud-schedulerx + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-alicloud-sms + ${spring.cloud.alibaba.version} + + + org.springframework.cloud + spring-cloud-stream-binder-rocketmq + ${spring.cloud.alibaba.version} + + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + report-aggregate + test + + report-aggregate + + + ${basedir}/../target/site/jacoco + + + + + + org.apache.maven.plugins + maven-deploy-plugin + ${maven-deploy-plugin.version} + + true + + + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 62d47196..f4a78d75 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -20,7 +20,7 @@ 1.4.2 3.1.0 0.1.3 - 0.8.1 + 0.8.2 0.8.0 1.0.8 1.0.1 @@ -148,6 +148,11 @@ sentinel-web-servlet ${sentinel.version} + + com.alibaba.csp + sentinel-zuul-adapter + ${sentinel.version} + com.alibaba.csp sentinel-transport-simple-http @@ -256,6 +261,11 @@ spring-cloud-alibaba-sentinel-datasource ${project.version} + + org.springframework.cloud + spring-cloud-alibaba-sentinel-zuul + ${project.version} + org.springframework.cloud spring-cloud-alicloud-oss diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc index db4f4318..d5cc93a6 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/acm.adoc @@ -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 版本,需要首先 ---- -接下来引入 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 规范即可。 +=== 自定义配置中心超时时间 -=== 支持自定义 Group 的配置 +ACM Client 与 Server 通信的超时时间默认是 3000ms,可以通过 `spring.cloud.alicloud.acm.timeout` 来修改超时时间,单位为 ms 。 + +=== 自定义 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` 对应的是动态刷新的历史记录。 \ No newline at end of file diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc/acm.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc/acm.adoc index 0e823577..41fdef33 100644 --- a/spring-cloud-alibaba-docs/src/main/asciidoc/acm.adoc +++ b/spring-cloud-alibaba-docs/src/main/asciidoc/acm.adoc @@ -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 -We’ve released Spring Cloud Alibaba version 0.2.1. You will need to add dependency management POM first. +We’ve 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. \ No newline at end of file diff --git a/spring-cloud-alibaba-dubbo/pom.xml b/spring-cloud-alibaba-dubbo/pom.xml index 5d51c191..e94404ab 100644 --- a/spring-cloud-alibaba-dubbo/pom.xml +++ b/spring-cloud-alibaba-dubbo/pom.xml @@ -214,4 +214,29 @@ + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/account-service/pom.xml b/spring-cloud-alibaba-examples/fescar-example/account-service/pom.xml index 219187bc..8d93a588 100644 --- a/spring-cloud-alibaba-examples/fescar-example/account-service/pom.xml +++ b/spring-cloud-alibaba-examples/fescar-example/account-service/pom.xml @@ -34,30 +34,4 @@ mysql-connector-java - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.codehaus.mojo - cobertura-maven-plugin - false - - true - - - - - \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/business-service/pom.xml b/spring-cloud-alibaba-examples/fescar-example/business-service/pom.xml index 6d77872a..53340dfb 100644 --- a/spring-cloud-alibaba-examples/fescar-example/business-service/pom.xml +++ b/spring-cloud-alibaba-examples/fescar-example/business-service/pom.xml @@ -38,25 +38,4 @@ - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - - org.codehaus.mojo - cobertura-maven-plugin - false - - true - - - - - \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/fescar-example/storage-service/pom.xml b/spring-cloud-alibaba-examples/fescar-example/storage-service/pom.xml index bcdca22c..fdef4eaf 100644 --- a/spring-cloud-alibaba-examples/fescar-example/storage-service/pom.xml +++ b/spring-cloud-alibaba-examples/fescar-example/storage-service/pom.xml @@ -39,30 +39,4 @@ mysql-connector-java - - - - - - org.codehaus.mojo - cobertura-maven-plugin - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.codehaus.mojo - cobertura-maven-plugin - false - - true - - - - - \ No newline at end of file diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml index b855f9f8..6a3af32b 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-consumer-example/pom.xml @@ -44,6 +44,7 @@ org.springframework.cloud spring-cloud-starter-alibaba-sentinel + diff --git a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java index c8b4a1c2..ae090f6e 100644 --- a/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java +++ b/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/nacos-discovery-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RestController; /** * @author xiaojing */ +@EnableDiscoveryClient @SpringBootApplication public class ProviderApplication { diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HelloController.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HelloController.java new file mode 100644 index 00000000..c11cbf98 --- /dev/null +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HelloController.java @@ -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"; + } + +} diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SimpleTask.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SimpleTask.java index 09055da1..17ced464 100644 --- a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SimpleTask.java +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SimpleTask.java @@ -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; + } } diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestController.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestController.java new file mode 100644 index 00000000..b237b279 --- /dev/null +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestController.java @@ -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()); + } + +} diff --git a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestService.java b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestService.java index 1786d197..3352c05a 100644 --- a/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestService.java +++ b/spring-cloud-alibaba-examples/schedulerx-example/schedulerx-simple-task-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestService.java @@ -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(); + } } diff --git a/spring-cloud-alibaba-fescar/pom.xml b/spring-cloud-alibaba-fescar/pom.xml index 15613f57..dbdf4063 100644 --- a/spring-cloud-alibaba-fescar/pom.xml +++ b/spring-cloud-alibaba-fescar/pom.xml @@ -114,4 +114,28 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alibaba-nacos-config-server/pom.xml b/spring-cloud-alibaba-nacos-config-server/pom.xml index 32b097e2..4ec0478f 100644 --- a/spring-cloud-alibaba-nacos-config-server/pom.xml +++ b/spring-cloud-alibaba-nacos-config-server/pom.xml @@ -61,4 +61,28 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alibaba-nacos-config/pom.xml b/spring-cloud-alibaba-nacos-config/pom.xml index 8096c713..2c85a841 100644 --- a/spring-cloud-alibaba-nacos-config/pom.xml +++ b/spring-cloud-alibaba-nacos-config/pom.xml @@ -96,4 +96,28 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alibaba-nacos-discovery/pom.xml b/spring-cloud-alibaba-nacos-discovery/pom.xml index fd2dbb80..c775c097 100644 --- a/spring-cloud-alibaba-nacos-discovery/pom.xml +++ b/spring-cloud-alibaba-nacos-discovery/pom.xml @@ -80,6 +80,30 @@ spring-cloud-test-support test - + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alibaba-sentinel-datasource/pom.xml b/spring-cloud-alibaba-sentinel-datasource/pom.xml index 47ca7798..e75033f1 100644 --- a/spring-cloud-alibaba-sentinel-datasource/pom.xml +++ b/spring-cloud-alibaba-sentinel-datasource/pom.xml @@ -98,4 +98,29 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + + diff --git a/spring-cloud-alibaba-sentinel-zuul/README.md b/spring-cloud-alibaba-sentinel-zuul/README.md new file mode 100755 index 00000000..2d0d2fd1 --- /dev/null +++ b/spring-cloud-alibaba-sentinel-zuul/README.md @@ -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 + + org.springframework.cloud + spring-cloud-alibaba-sentinel-zuul + x.y.z + + +``` + +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; + } +} +``` \ No newline at end of file diff --git a/spring-cloud-alibaba-sentinel-zuul/pom.xml b/spring-cloud-alibaba-sentinel-zuul/pom.xml new file mode 100644 index 00000000..d8f8fa80 --- /dev/null +++ b/spring-cloud-alibaba-sentinel-zuul/pom.xml @@ -0,0 +1,44 @@ + + + + spring-cloud-alibaba + org.springframework.cloud + 0.2.2.BUILD-SNAPSHOT + + 4.0.0 + + org.springframework.cloud + spring-cloud-alibaba-sentinel-zuul + Spring Cloud Alibaba Sentinel Zuul + + + + org.springframework.cloud + spring-cloud-starter-netflix-zuul + provided + + + com.alibaba.csp + sentinel-zuul-adapter + + + org.springframework.boot + spring-boot-configuration-processor + provided + true + + + junit + junit + test + + + org.mockito + mockito-core + test + + + + \ No newline at end of file diff --git a/spring-cloud-alibaba-sentinel-zuul/src/main/java/org/springframework/cloud/alibaba/sentinel/zuul/SentinelZuulAutoConfiguration.java b/spring-cloud-alibaba-sentinel-zuul/src/main/java/org/springframework/cloud/alibaba/sentinel/zuul/SentinelZuulAutoConfiguration.java new file mode 100644 index 00000000..73d4cf79 --- /dev/null +++ b/spring-cloud-alibaba-sentinel-zuul/src/main/java/org/springframework/cloud/alibaba/sentinel/zuul/SentinelZuulAutoConfiguration.java @@ -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); + } + +} diff --git a/spring-cloud-alibaba-sentinel-zuul/src/main/java/org/springframework/cloud/alibaba/sentinel/zuul/listener/FallBackProviderListener.java b/spring-cloud-alibaba-sentinel-zuul/src/main/java/org/springframework/cloud/alibaba/sentinel/zuul/listener/FallBackProviderListener.java new file mode 100644 index 00000000..d727a0e4 --- /dev/null +++ b/spring-cloud-alibaba-sentinel-zuul/src/main/java/org/springframework/cloud/alibaba/sentinel/zuul/listener/FallBackProviderListener.java @@ -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 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()); + } + } +} diff --git a/spring-cloud-alibaba-sentinel-zuul/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-sentinel-zuul/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..b4ced151 --- /dev/null +++ b/spring-cloud-alibaba-sentinel-zuul/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.alibaba.sentinel.zuul.SentinelZuulAutoConfiguration \ No newline at end of file diff --git a/spring-cloud-alibaba-sentinel/pom.xml b/spring-cloud-alibaba-sentinel/pom.xml index 9410a293..7f4354a8 100644 --- a/spring-cloud-alibaba-sentinel/pom.xml +++ b/spring-cloud-alibaba-sentinel/pom.xml @@ -137,4 +137,28 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alicloud-acm/pom.xml b/spring-cloud-alicloud-acm/pom.xml index 0d9e3f5e..045812b3 100644 --- a/spring-cloud-alicloud-acm/pom.xml +++ b/spring-cloud-alicloud-acm/pom.xml @@ -69,5 +69,29 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alicloud-ans/pom.xml b/spring-cloud-alicloud-ans/pom.xml index 3aa33c0b..ac784829 100644 --- a/spring-cloud-alicloud-ans/pom.xml +++ b/spring-cloud-alicloud-ans/pom.xml @@ -118,4 +118,28 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + \ No newline at end of file diff --git a/spring-cloud-alicloud-context/pom.xml b/spring-cloud-alicloud-context/pom.xml index b87d920d..4b798458 100644 --- a/spring-cloud-alicloud-context/pom.xml +++ b/spring-cloud-alicloud-context/pom.xml @@ -128,5 +128,28 @@ - + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java index 8595f249..1e7b8d8e 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListener.java @@ -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"); } } \ No newline at end of file diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/oss/OssProperties.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/oss/OssProperties.java index 59f64cc3..4897bf5f 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/oss/OssProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/oss/OssProperties.java @@ -31,13 +31,33 @@ import com.aliyun.oss.ClientBuilderConfiguration; @ConfigurationProperties("spring.cloud.alicloud.oss") public class OssProperties { + /** + * Authorization Mode, please see oss + * docs. + */ @Value("${spring.cloud.alicloud.oss.authorization-mode:AK_SK}") private AliCloudAuthorizationMode authorizationMode; + /** + * Endpoint, please see oss + * docs. + */ private String endpoint; + /** + * Sts token, please see oss + * docs. + */ private StsToken sts; + /** + * Client Configuration, please see oss + * docs. + */ private ClientBuilderConfiguration config; public AliCloudAuthorizationMode getAuthorizationMode() { diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/scx/ScxProperties.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/scx/ScxProperties.java index db6a00d6..5ddfb0ab 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/scx/ScxProperties.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/scx/ScxProperties.java @@ -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 scx + * docs. + */ private String groupId; + /** + * Domain name, please see scx + * docs. + */ private String domainName; @Override diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java index 709315d8..e820d4a9 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/statistics/StatisticsTaskStarter.java @@ -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; } diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.java new file mode 100644 index 00000000..74ac28bc --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.java @@ -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 { +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java index b9e0ec2b..73754cf8 100644 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/nacos/NacosDiscoveryParameterInitListenerTests.java @@ -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"); + } } diff --git a/spring-cloud-alicloud-oss/pom.xml b/spring-cloud-alicloud-oss/pom.xml index eb5c5adf..0596e451 100644 --- a/spring-cloud-alicloud-oss/pom.xml +++ b/spring-cloud-alicloud-oss/pom.xml @@ -61,4 +61,28 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-alicloud-schedulerx/pom.xml b/spring-cloud-alicloud-schedulerx/pom.xml index 04b948a5..db58050a 100644 --- a/spring-cloud-alicloud-schedulerx/pom.xml +++ b/spring-cloud-alicloud-schedulerx/pom.xml @@ -50,5 +50,28 @@ true - + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + \ No newline at end of file diff --git a/spring-cloud-alicloud-sms/pom.xml b/spring-cloud-alicloud-sms/pom.xml index 001a46ad..2b9b500e 100644 --- a/spring-cloud-alicloud-sms/pom.xml +++ b/spring-cloud-alicloud-sms/pom.xml @@ -79,5 +79,29 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + diff --git a/spring-cloud-stream-binder-rocketmq/pom.xml b/spring-cloud-stream-binder-rocketmq/pom.xml index 49ae2579..fad85417 100644 --- a/spring-cloud-stream-binder-rocketmq/pom.xml +++ b/spring-cloud-stream-binder-rocketmq/pom.xml @@ -77,5 +77,29 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + +