diff --git a/pom.xml b/pom.xml
index 94a523859..1bf958f4a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,6 +47,10 @@
fangjian
fangjian0423@gmail.com
+
+ xiaolongzuo
+ 150349407@qq.com
+
hengyunabc
hengyunabc@gmail.com
@@ -82,6 +86,9 @@
spring-cloud-starter-alibaba
spring-cloud-starter-alicloud
spring-cloud-alicloud-oss
+ spring-cloud-alicloud-context
+ spring-cloud-alicloud-acm
+ spring-cloud-alicloud-ans
diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml
index 4680ca710..e08a9dc28 100644
--- a/spring-cloud-alibaba-dependencies/pom.xml
+++ b/spring-cloud-alibaba-dependencies/pom.xml
@@ -19,11 +19,47 @@
0.2.0
3.1.0
0.3.0-RC1
+ 1.0.8
+ 0.1.1
+ 4.0.1
+ 1.0.0
+ 2.16.0
-
+
+
+ com.alibaba.cloud
+ alicloud-context
+ ${alicloud.context.version}
+
+
+ com.aliyun
+ aliyun-java-sdk-edas
+ ${aliyun.sdk.edas.version}
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+
+
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+ ${aliyun.sdk.version}
+
+
+ com.alibaba.ans
+ ans-sdk
+ ${ans.version}
+
+
+ com.alibaba.edas.acm
+ acm-sdk
+ ${acm.version}
+
com.alibaba.nacos
nacos-client
@@ -115,6 +151,21 @@
spring-cloud-alibaba-nacos-config
${project.version}
+
+ org.springframework.cloud
+ spring-cloud-alicloud-acm
+ ${project.version}
+
+
+ org.springframework.cloud
+ spring-cloud-alicloud-ans
+ ${project.version}
+
+
+ org.springframework.cloud
+ spring-cloud-alicloud-context
+ ${project.version}
+
@@ -140,9 +191,17 @@
${project.version}
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+ ${project.version}
+
-
-
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-acm
+ ${project.version}
+
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/pom.xml b/spring-cloud-alibaba-examples/acm-example/acm-local-example/pom.xml
new file mode 100644
index 000000000..f83e5da34
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/pom.xml
@@ -0,0 +1,27 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.0.BUILD-SNAPSHOT
+
+ 4.0.0
+ acm-local-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-acm
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AcmApplication.java b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AcmApplication.java
new file mode 100644
index 000000000..5d48c381d
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/AcmApplication.java
@@ -0,0 +1,34 @@
+/*
+ * 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.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+public class AcmApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(AcmApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
new file mode 100644
index 000000000..b7c874610
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
@@ -0,0 +1,41 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class EchoController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EchoController.class);
+
+ @Value("${user.id}")
+ private String userId;
+
+ @RequestMapping(value = "/")
+ public String echo() {
+ LOGGER.info("User id is " + userId);
+ return userId;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties
new file mode 100644
index 000000000..dceeba95a
--- /dev/null
+++ b/spring-cloud-alibaba-examples/acm-example/acm-local-example/src/main/resources/bootstrap.properties
@@ -0,0 +1,6 @@
+spring.application.group=com.alibaba.acm
+spring.application.name=acm-local
+server.port=18089
+spring.cloud.alicloud.acm.server-list=127.0.0.1
+spring.cloud.alicloud.acm.server-port=8080
+
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/pom.xml b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/pom.xml
new file mode 100644
index 000000000..e0966d4f7
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/pom.xml
@@ -0,0 +1,23 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.0.BUILD-SNAPSHOT
+
+ 4.0.0
+ ans-consumer-feign-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
new file mode 100644
index 000000000..e95b2e9cf
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
@@ -0,0 +1,34 @@
+/*
+ * 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.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableFeignClients(basePackages = {"org.springframework.cloud.alibaba.cloud.examples"})
+public class ConsumerApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ConsumerApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java
new file mode 100644
index 000000000..78b3c486a
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * @author xiaolongzuo
+ */
+@FeignClient(value = "ans-provider")
+public interface EchoService {
+
+ @RequestMapping(path = "echo/{str}")
+ String echo(@RequestParam("str") String param);
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
new file mode 100644
index 000000000..8f2a3e8c2
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
@@ -0,0 +1,46 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class HomeController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);
+
+ @Autowired
+ private EchoService echoService;
+
+ @RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")
+ public String home() {
+ LOGGER.info("-----------------consumer调用开始-----------------");
+ String param = "Nice to meet you.";
+ LOGGER.info("消费者传递参数:" + param);
+ String result = echoService.echo(param);
+ LOGGER.info("收到提供者响应:" + result);
+ return param + "
" + result;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties
new file mode 100644
index 000000000..1b25ea1e7
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-feign-example/src/main/resources/application.properties
@@ -0,0 +1,4 @@
+server.port=18083
+# The following configuration can be omitted.
+spring.cloud.ans.server.list=127.0.0.1
+spring.cloud.ans.server.port=8080
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/pom.xml b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/pom.xml
new file mode 100644
index 000000000..238ea7f4c
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/pom.xml
@@ -0,0 +1,19 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.0.BUILD-SNAPSHOT
+
+ 4.0.0
+ ans-consumer-ribbon-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
new file mode 100644
index 000000000..223a2d891
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ConsumerApplication.java
@@ -0,0 +1,43 @@
+/*
+ * 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.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+public class ConsumerApplication {
+
+ @Bean
+ @LoadBalanced
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+
+ public static void main(String[] args) {
+ SpringApplication.run(ConsumerApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
new file mode 100644
index 000000000..e3853fdd3
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/HomeController.java
@@ -0,0 +1,47 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class HomeController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HomeController.class);
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @RequestMapping(value = "/", method = RequestMethod.GET, produces = "application/json")
+ public String home() {
+ LOGGER.info("-----------------consumer调用开始-----------------");
+ String param = "Nice to meet you.";
+ LOGGER.info("消费者传递参数:" + param);
+ String result = restTemplate.getForObject("http://ans-provider/echo/" + param, String.class);
+ LOGGER.info("收到提供者响应:" + result);
+ return param + "
" + result;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties
new file mode 100644
index 000000000..c7bf8206f
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-consumer-ribbon-example/src/main/resources/application.properties
@@ -0,0 +1,4 @@
+server.port=18082
+# The following configuration can be omitted.
+spring.cloud.ans.server.list=127.0.0.1
+spring.cloud.ans.server.port=8080
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/pom.xml b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/pom.xml
new file mode 100644
index 000000000..d79e46f14
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/pom.xml
@@ -0,0 +1,19 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.0.BUILD-SNAPSHOT
+
+ 4.0.0
+ ans-provider-example
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alicloud-ans
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
new file mode 100644
index 000000000..a9c031ead
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/EchoController.java
@@ -0,0 +1,42 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author xiaolongzuo
+ */
+@RestController
+public class EchoController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(EchoController.class);
+
+ @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET, produces = "application/json")
+ public String echo(@PathVariable String str) {
+ LOGGER.info("-----------收到消费者请求-----------");
+ LOGGER.info("收到消费者传递的参数:" + str);
+ String result = "Nice to meet you, too.";
+ LOGGER.info("提供者返回结果:" + result);
+ return result;
+ }
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java
new file mode 100644
index 000000000..03436dcb4
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ProviderApplication.java
@@ -0,0 +1,34 @@
+/*
+ * 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.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+/**
+ * @author xiaolongzuo
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+public class ProviderApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ProviderApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties
new file mode 100644
index 000000000..76862f6b7
--- /dev/null
+++ b/spring-cloud-alibaba-examples/ans-example/ans-provider-example/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+spring.application.name=ans-provider
+server.port=18081
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSApplication.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSApplication.java
index 0e4546fac..f9265800d 100644
--- a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSApplication.java
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSApplication.java
@@ -1,7 +1,6 @@
package org.springframework.cloud.alibaba.cloud.examples;
-import java.net.URISyntaxException;
-
+import com.aliyun.oss.OSS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
@@ -9,7 +8,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
-import com.aliyun.oss.OSS;
+import java.net.URISyntaxException;
/**
* OSS Application
@@ -17,35 +16,34 @@ import com.aliyun.oss.OSS;
* @author Jim
*/
@SpringBootApplication
-public class OSSApplication {
-
- public static final String BUCKET_NAME = "spring-cloud-alibaba";
-
- public static void main(String[] args) throws URISyntaxException {
- SpringApplication.run(OSSApplication.class, args);
- }
-
- @Bean
- public AppRunner appRunner() {
- return new AppRunner();
- }
-
- class AppRunner implements ApplicationRunner {
- @Autowired
- private OSS ossClient;
-
- @Override
- public void run(ApplicationArguments args) throws Exception {
- try {
- if (!ossClient.doesBucketExist(BUCKET_NAME)) {
- ossClient.createBucket(BUCKET_NAME);
- }
- }
- catch (Exception e) {
- System.err.println("oss handle bucket error: " + e.getMessage());
- System.exit(-1);
- }
- }
- }
+public class OssApplication {
+
+ public static final String BUCKET_NAME = "spring-cloud-alibaba-test";
+
+ public static void main(String[] args) throws URISyntaxException {
+ SpringApplication.run(OssApplication.class, args);
+ }
+
+ @Bean
+ public AppRunner appRunner() {
+ return new AppRunner();
+ }
+
+ class AppRunner implements ApplicationRunner {
+ @Autowired
+ private OSS ossClient;
+
+ @Override
+ public void run(ApplicationArguments args) throws Exception {
+ try {
+ if (!ossClient.doesBucketExist(BUCKET_NAME)) {
+ ossClient.createBucket(BUCKET_NAME);
+ }
+ } catch (Exception e) {
+ System.err.println("oss handle bucket error: " + e.getMessage());
+ System.exit(-1);
+ }
+ }
+ }
}
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSController.java b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSController.java
index 1f3aac896..7c6e427a9 100644
--- a/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSController.java
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/OSSController.java
@@ -1,7 +1,8 @@
package org.springframework.cloud.alibaba.cloud.examples;
-import java.nio.charset.Charset;
-
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.common.utils.IOUtils;
+import com.aliyun.oss.model.OSSObject;
import org.apache.commons.codec.CharEncoding;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -10,9 +11,7 @@ import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
-import com.aliyun.oss.OSS;
-import com.aliyun.oss.common.utils.IOUtils;
-import com.aliyun.oss.model.OSSObject;
+import java.nio.charset.Charset;
/**
* OSS Controller
@@ -20,53 +19,47 @@ import com.aliyun.oss.model.OSSObject;
* @author Jim
*/
@RestController
-public class OSSController {
-
- @Autowired
- private OSS ossClient;
+public class OssController {
- @Value("oss://" + OSSApplication.BUCKET_NAME + "/oss-test")
- private Resource file;
+ @Autowired
+ private OSS ossClient;
- private String dir = "custom-dir/";
+ @Value("oss://" + OssApplication.BUCKET_NAME + "/oss-test.json")
+ private Resource file;
- @GetMapping("/upload")
- public String upload() {
- try {
- ossClient.putObject(OSSApplication.BUCKET_NAME, dir + "oss-test", this
- .getClass().getClassLoader().getResourceAsStream("oss-test.json"));
- }
- catch (Exception e) {
- e.printStackTrace();
- return "upload fail: " + e.getMessage();
- }
- return "upload success";
- }
+ @GetMapping("/upload")
+ public String upload() {
+ try {
+ ossClient.putObject(OssApplication.BUCKET_NAME, "oss-test.json", this
+ .getClass().getClassLoader().getResourceAsStream("oss-test.json"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "upload fail: " + e.getMessage();
+ }
+ return "upload success";
+ }
- @GetMapping("/file-resource")
- public String fileResource() {
- try {
- return "get file resource success. content: " + StreamUtils.copyToString(
- file.getInputStream(), Charset.forName(CharEncoding.UTF_8));
- }
- catch (Exception e) {
- e.printStackTrace();
- return "get resource fail: " + e.getMessage();
- }
- }
+ @GetMapping("/file-resource")
+ public String fileResource() {
+ try {
+ return "get file resource success. content: " + StreamUtils.copyToString(
+ file.getInputStream(), Charset.forName(CharEncoding.UTF_8));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "get resource fail: " + e.getMessage();
+ }
+ }
- @GetMapping("/download")
- public String download() {
- try {
- OSSObject ossObject = ossClient.getObject(OSSApplication.BUCKET_NAME,
- dir + "oss-test");
- return "download success, content: " + IOUtils
- .readStreamAsString(ossObject.getObjectContent(), CharEncoding.UTF_8);
- }
- catch (Exception e) {
- e.printStackTrace();
- return "download fail: " + e.getMessage();
- }
- }
+ @GetMapping("/download")
+ public String download() {
+ try {
+ OSSObject ossObject = ossClient.getObject(OssApplication.BUCKET_NAME, "oss-test.json");
+ return "download success, content: " + IOUtils
+ .readStreamAsString(ossObject.getObjectContent(), CharEncoding.UTF_8);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "download fail: " + e.getMessage();
+ }
+ }
}
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties
index 4b269483e..59c650d3d 100644
--- a/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/resources/application.properties
@@ -1,8 +1,6 @@
spring.application.name=oss-example
server.port=18084
-
-spring.cloud.alibaba.oss.accessKeyId=[your-ak]
-spring.cloud.alibaba.oss.secretAccessKey=[your-sk]
-spring.cloud.alibaba.oss.region=[your-region]
-
-management.endpoints.web.exposure.include=*
\ No newline at end of file
+spring.cloud.alicloud.access-key=AK
+spring.cloud.alicloud.secret-key=SK
+spring.cloud.alicloud.oss.endpoint=***.aliyuncs.com
+management.endpoints.web.exposure.include=*
diff --git a/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json b/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json
index eb0fe5f89..f1683e94f 100644
--- a/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json
+++ b/spring-cloud-alibaba-examples/oss-example/src/main/resources/oss-test.json
@@ -1,6 +1,3 @@
{
- "name": "spring-cloud-alibaba",
- "github": "https://github.com/spring-cloud-incubator/spring-cloud-alibaba",
- "authors": ["Jim", "flystar32"],
- "emails": ["fangjian0423@gmail.com", "flystar32@163.com"]
+ "name": "chenzhu-test"
}
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/pom.xml b/spring-cloud-alibaba-examples/pom.xml
index ed4acb014..eef97298b 100644
--- a/spring-cloud-alibaba-examples/pom.xml
+++ b/spring-cloud-alibaba-examples/pom.xml
@@ -23,6 +23,10 @@
nacos-example/nacos-discovery-example
nacos-example/nacos-config-example
oss-example
+ ans-example/ans-consumer-feign-example
+ ans-example/ans-consumer-ribbon-example
+ ans-example/ans-provider-example
+ acm-example/acm-local-example
diff --git a/spring-cloud-alicloud-acm/pom.xml b/spring-cloud-alicloud-acm/pom.xml
new file mode 100644
index 000000000..971d33827
--- /dev/null
+++ b/spring-cloud-alicloud-acm/pom.xml
@@ -0,0 +1,71 @@
+
+
+ 4.0.0
+
+
+
+ org.springframework.cloud
+ spring-cloud-alibaba
+ 0.2.0.BUILD-SNAPSHOT
+
+
+ spring-cloud-alicloud-acm
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-alicloud-context
+
+
+
+ com.aliyun
+ aliyun-java-sdk-core
+
+
+
+ com.aliyun
+ aliyun-java-sdk-edas
+
+
+
+ com.alibaba.edas.acm
+ acm-sdk
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ provided
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+ true
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-context
+
+
+ org.springframework.cloud
+ spring-cloud-commons
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java
new file mode 100644
index 000000000..5930568a9
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java
@@ -0,0 +1,73 @@
+/*
+ * 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.alicloud.acm;
+
+import com.taobao.diamond.client.Diamond;
+import org.springframework.beans.BeansException;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.alicloud.acm.endpoint.AcmHealthIndicator;
+import org.springframework.cloud.alicloud.acm.refresh.AcmContextRefresher;
+import org.springframework.cloud.alicloud.acm.refresh.AcmRefreshHistory;
+import org.springframework.cloud.alicloud.context.acm.AcmProperties;
+import org.springframework.cloud.context.refresh.ContextRefresher;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Created on 01/10/2017.
+ *
+ * @author juven.xuxb
+ */
+@Configuration
+@ConditionalOnClass({Diamond.class})
+@EnableConfigurationProperties(AcmProperties.class)
+public class AcmAutoConfiguration implements ApplicationContextAware {
+
+ private ApplicationContext applicationContext;
+
+ @Bean
+ public AcmPropertySourceRepository acmPropertySourceRepository() {
+ return new AcmPropertySourceRepository(applicationContext);
+ }
+
+ @Bean
+ public AcmHealthIndicator acmHealthIndicator(AcmProperties acmProperties,
+ AcmPropertySourceRepository acmPropertySourceRepository) {
+ return new AcmHealthIndicator(acmProperties, acmPropertySourceRepository);
+ }
+
+ @Bean
+ public AcmRefreshHistory acmRefreshHistory() {
+ return new AcmRefreshHistory();
+ }
+
+ @Bean
+ public AcmContextRefresher acmContextRefresher(AcmProperties acmProperties, ContextRefresher contextRefresher,
+ AcmRefreshHistory refreshHistory,
+ AcmPropertySourceRepository propertySourceRepository) {
+ return new AcmContextRefresher(contextRefresher, acmProperties, refreshHistory, propertySourceRepository);
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmPropertySourceRepository.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmPropertySourceRepository.java
new file mode 100644
index 000000000..42b84c89f
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/AcmPropertySourceRepository.java
@@ -0,0 +1,68 @@
+/*
+ * 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.alicloud.acm;
+
+import org.springframework.cloud.alicloud.acm.bootstrap.AcmPropertySource;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.CompositePropertySource;
+import org.springframework.core.env.PropertySource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author juven.xuxb, 5/17/16.
+ */
+public class AcmPropertySourceRepository {
+
+ private final ApplicationContext applicationContext;
+
+ public AcmPropertySourceRepository(ApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ /**
+ * get all acm properties from application context
+ * @return
+ */
+ public List getAll() {
+ List result = new ArrayList<>();
+ ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) applicationContext;
+ for (PropertySource p : ctx.getEnvironment().getPropertySources()) {
+ if (p instanceof AcmPropertySource) {
+ result.add((AcmPropertySource) p);
+ }
+ else if (p instanceof CompositePropertySource) {
+ collectAcmPropertySources((CompositePropertySource) p, result);
+ }
+ }
+ return result;
+ }
+
+ private void collectAcmPropertySources(CompositePropertySource composite,
+ List result) {
+ for (PropertySource p : composite.getPropertySources()) {
+ if (p instanceof AcmPropertySource) {
+ result.add((AcmPropertySource) p);
+ }
+ else if (p instanceof CompositePropertySource) {
+ collectAcmPropertySources((CompositePropertySource) p, result);
+ }
+ }
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySource.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySource.java
new file mode 100644
index 000000000..3ebae2773
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySource.java
@@ -0,0 +1,55 @@
+/*
+ * 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.alicloud.acm.bootstrap;
+
+import org.springframework.core.env.MapPropertySource;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author juven.xuxb
+ * @author xiaolongzuo
+ */
+public class AcmPropertySource extends MapPropertySource {
+
+ private final String dataId;
+
+ private final Date timestamp;
+
+ private final boolean groupLevel;
+
+ AcmPropertySource(String dataId, Map source, Date timestamp,
+ boolean groupLevel) {
+ super(dataId, source);
+ this.dataId = dataId;
+ this.timestamp = timestamp;
+ this.groupLevel = groupLevel;
+ }
+
+ public String getDataId() {
+ return dataId;
+ }
+
+ public Date getTimestamp() {
+ return timestamp;
+ }
+
+ public boolean isGroupLevel() {
+ return groupLevel;
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java
new file mode 100644
index 000000000..2bf9cbba3
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceBuilder.java
@@ -0,0 +1,96 @@
+/*
+ * 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.alicloud.acm.bootstrap;
+
+import com.alibaba.edas.acm.ConfigService;
+import com.alibaba.edas.acm.exception.ConfigException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.util.StringUtils;
+
+import java.io.StringReader;
+import java.util.*;
+
+/**
+ * @author juven.xuxb
+ * @author xiaolongzuo
+ */
+class AcmPropertySourceBuilder {
+
+ private Logger logger = LoggerFactory.getLogger(AcmPropertySourceBuilder.class);
+
+ /**
+ * 传入 ACM 的 DataId 和 groupID,获取到解析后的 AcmProperty 对象
+ *
+ * @param dataId
+ * @param diamondGroup
+ * @param groupLevel
+ * @return
+ */
+ AcmPropertySource build(String dataId, String diamondGroup, boolean groupLevel) {
+ Properties properties = loadDiamondData(dataId, diamondGroup);
+ if (properties == null) {
+ return null;
+ }
+ return new AcmPropertySource(dataId, toMap(properties), new Date(), groupLevel);
+ }
+
+ private Properties loadDiamondData(String dataId, String diamondGroup) {
+ try {
+ String data = ConfigService.getConfig(dataId, diamondGroup, 3000L);
+ if (StringUtils.isEmpty(data)) {
+ return null;
+ }
+ if (dataId.endsWith(".properties")) {
+ Properties properties = new Properties();
+ logger.info(String.format("Loading acm data, dataId: '%s', group: '%s'",
+ dataId, diamondGroup));
+ properties.load(new StringReader(data));
+ return properties;
+ } else if (dataId.endsWith(".yaml") || dataId.endsWith(".yml")) {
+ YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
+ yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
+ return yamlFactory.getObject();
+ }
+ } catch (Exception e) {
+ if (e instanceof ConfigException) {
+ logger.error("DIAMOND-100500:" + dataId + ", " + e.toString(), e);
+ } else {
+ logger.error("DIAMOND-100500:" + dataId, e);
+ }
+ }
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map toMap(Properties properties) {
+ Map result = new HashMap<>();
+ Enumeration keys = (Enumeration)properties.propertyNames();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ Object value = properties.getProperty(key);
+ if (value != null) {
+ result.put(key, ((String)value).trim());
+ } else {
+ result.put(key, null);
+ }
+ }
+ return result;
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceLocator.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceLocator.java
new file mode 100644
index 000000000..8c08e1baf
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/bootstrap/AcmPropertySourceLocator.java
@@ -0,0 +1,142 @@
+/*
+ * 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.alicloud.acm.bootstrap;
+
+import com.taobao.diamond.maintenance.DiamondHealth;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.alicloud.acm.diagnostics.analyzer.DiamondConnectionFailureException;
+import org.springframework.cloud.alicloud.context.acm.AcmProperties;
+import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
+import org.springframework.core.env.CompositePropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.PropertySource;
+import org.springframework.util.StringUtils;
+
+import static com.taobao.diamond.client.impl.ServerHttpAgent.addressPort;
+import static com.taobao.diamond.client.impl.ServerHttpAgent.domainName;
+
+/**
+ * @author juven.xuxb
+ * @author xiaolongzuo
+ */
+public class AcmPropertySourceLocator implements PropertySourceLocator {
+
+ private final Logger logger = LoggerFactory.getLogger(AcmPropertySourceLocator.class);
+
+ private static final String DIAMOND_PROPERTY_SOURCE_NAME = "diamond";
+
+ private static String defaultDiamondGroup = "DEFAULT_GROUP";
+
+ private AcmPropertySourceBuilder acmPropertySourceBuilder = new AcmPropertySourceBuilder();
+
+ @Autowired
+ private AcmProperties acmProperties;
+
+ @Override
+ public PropertySource> locate(Environment environment) {
+ checkDiamondHealth();
+
+ String applicationName = environment.getProperty("spring.application.name");
+ logger.info("Initialize spring.application.name '" + applicationName + "'.");
+ String applicationGroup = environment.getProperty("spring.application.group");
+
+ if (StringUtils.isEmpty(applicationName)) {
+ throw new IllegalStateException(
+ "'spring.application.name' must be configured.");
+ }
+
+ CompositePropertySource compositePropertySource = new CompositePropertySource(
+ DIAMOND_PROPERTY_SOURCE_NAME);
+
+ loadGroupConfigurationRecursively(compositePropertySource, applicationGroup);
+
+ loadApplicationConfiguration(compositePropertySource, environment,
+ applicationGroup, applicationName);
+
+ return compositePropertySource;
+ }
+
+ private void checkDiamondHealth() {
+ logger.info("Checking ACM health");
+ try {
+ if (!"UP".equals(DiamondHealth.getHealth())) {
+ throw new DiamondConnectionFailureException(domainName, addressPort,
+ DiamondHealth.getHealth());
+ }
+ }
+ catch (Throwable t) {
+ throw new DiamondConnectionFailureException(domainName, addressPort,
+ "ACM Health error", t);
+ }
+ }
+
+ private void loadGroupConfigurationRecursively(
+ CompositePropertySource compositePropertySource, String applicationGroup) {
+ if (StringUtils.isEmpty(applicationGroup)) {
+ return;
+ }
+ String[] parts = applicationGroup.split("\\.");
+ for (int i = 1; i < parts.length; i++) {
+ String subGroup = parts[0];
+ for (int j = 1; j <= i; j++) {
+ subGroup = subGroup + "." + parts[j];
+ }
+ String dataId = subGroup + ":application." + acmProperties.getFileExtension();
+ loadDiamondDataIfPresent(compositePropertySource, dataId, defaultDiamondGroup,
+ true);
+ }
+ }
+
+ private void loadApplicationConfiguration(
+ CompositePropertySource compositePropertySource, Environment environment,
+ String applicationGroup, String applicationName) {
+
+ if (!StringUtils.isEmpty(applicationGroup)) {
+ String dataId = applicationGroup + ":" + applicationName + "."
+ + acmProperties.getFileExtension();
+ loadDiamondDataIfPresent(compositePropertySource, dataId, defaultDiamondGroup,
+ false);
+ for (String profile : environment.getActiveProfiles()) {
+ dataId = applicationGroup + ":" + applicationName + "-" + profile + "."
+ + acmProperties.getFileExtension();
+ loadDiamondDataIfPresent(compositePropertySource, dataId,
+ defaultDiamondGroup, false);
+ }
+
+ }
+ String dataId = applicationName + "." + acmProperties.getFileExtension();
+ loadDiamondDataIfPresent(compositePropertySource, dataId, defaultDiamondGroup,
+ false);
+ for (String profile : environment.getActiveProfiles()) {
+ dataId = applicationName + "-" + profile + "."
+ + acmProperties.getFileExtension();
+ loadDiamondDataIfPresent(compositePropertySource, dataId, defaultDiamondGroup,
+ false);
+ }
+ }
+
+ private void loadDiamondDataIfPresent(final CompositePropertySource composite,
+ final String dataId, final String diamondGroup, final boolean groupLevel) {
+ AcmPropertySource ps = acmPropertySourceBuilder.build(dataId, diamondGroup,
+ groupLevel);
+ if (ps != null) {
+ composite.addFirstPropertySource(ps);
+ }
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureAnalyzer.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureAnalyzer.java
new file mode 100644
index 000000000..64d56be39
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureAnalyzer.java
@@ -0,0 +1,40 @@
+/*
+ * 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.alicloud.acm.diagnostics.analyzer;
+
+import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
+import org.springframework.boot.diagnostics.FailureAnalysis;
+
+/**
+ * A {@code FailureAnalyzer} that performs analysis of failures caused by a
+ * {@code DiamondConnectionFailureException}.
+ *
+ * @author juven.xuxb, 07/11/2016.
+ */
+public class DiamondConnectionFailureAnalyzer
+ extends AbstractFailureAnalyzer {
+
+ @Override
+ protected FailureAnalysis analyze(Throwable rootFailure,
+ DiamondConnectionFailureException cause) {
+ return new FailureAnalysis(
+ "Application failed to connect to Diamond, unable to access http://"
+ + cause.getDomain() + ":" + cause.getPort()
+ + "/diamond-server/diamond",
+ "config the right endpoint", cause);
+ }
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureException.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureException.java
new file mode 100644
index 000000000..a1b10abf6
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/diagnostics/analyzer/DiamondConnectionFailureException.java
@@ -0,0 +1,52 @@
+/*
+ * 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.alicloud.acm.diagnostics.analyzer;
+
+/**
+ * A {@code DiamondConnectionFailureException} is thrown when the application fails to
+ * connect to Diamond Server.
+ *
+ * @author juven.xuxb, 07/11/2016.
+ */
+public class DiamondConnectionFailureException extends RuntimeException {
+
+ private final String domain;
+
+ private final String port;
+
+ public DiamondConnectionFailureException(String domain, String port, String message) {
+ super(message);
+ this.domain = domain;
+ this.port = port;
+ }
+
+ public DiamondConnectionFailureException(String domain, String port, String message,
+ Throwable cause) {
+ super(message, cause);
+ this.domain = domain;
+ this.port = port;
+ }
+
+ String getDomain() {
+ return domain;
+ }
+
+ String getPort() {
+ return port;
+ }
+
+}
diff --git a/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/endpoint/AcmEndpoint.java b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/endpoint/AcmEndpoint.java
new file mode 100644
index 000000000..6c5518d76
--- /dev/null
+++ b/spring-cloud-alicloud-acm/src/main/java/org/springframework/cloud/alicloud/acm/endpoint/AcmEndpoint.java
@@ -0,0 +1,77 @@
+/*
+ * 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.alicloud.acm.endpoint;
+
+import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+import org.springframework.cloud.alicloud.acm.AcmPropertySourceRepository;
+import org.springframework.cloud.alicloud.acm.bootstrap.AcmPropertySource;
+import org.springframework.cloud.alicloud.acm.refresh.AcmRefreshHistory;
+import org.springframework.cloud.alicloud.context.acm.AcmProperties;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created on 01/10/2017.
+ *
+ * @author juven.xuxb
+ */
+@Endpoint(id = "acm")
+public class AcmEndpoint {
+
+ private final AcmProperties properties;
+
+ private final AcmRefreshHistory refreshHistory;
+
+ private final AcmPropertySourceRepository propertySourceRepository;
+
+ private DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ public AcmEndpoint(AcmProperties properties, AcmRefreshHistory refreshHistory,
+ AcmPropertySourceRepository propertySourceRepository) {
+ this.properties = properties;
+ this.refreshHistory = refreshHistory;
+ this.propertySourceRepository = propertySourceRepository;
+ }
+
+ @ReadOperation
+ public Map invoke() {
+ Map result = new HashMap<>();
+ result.put("config", properties);
+
+ Map runtime = new HashMap<>();
+ List all = propertySourceRepository.getAll();
+
+ List