Skip to content

Commit f6d8bca

Browse files
committed
Merge branch 'liushi/master'
merge #120
2 parents b2fb8c1 + 705a29e commit f6d8bca

38 files changed

+726
-90
lines changed

mse-simple-demo/A/Dockerfile

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1.3-labs
22

3-
FROM maven:3-eclipse-temurin-8-alpine
3+
FROM maven:3-eclipse-temurin-8-alpine as build
44

55
# copy arthas
66
COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas
@@ -15,14 +15,9 @@ COPY <<EOF /root/.m2/settings.xml
1515
<mirror>
1616
<id>alimaven</id>
1717
<name>aliyun maven</name>
18-
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
18+
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
1919
<mirrorOf>central</mirrorOf>
2020
</mirror>
21-
<mirror>
22-
<id>maven-default-http-blocker</id>
23-
<mirrorOf>!*</mirrorOf>
24-
<url>http://0.0.0.0/</url>
25-
</mirror>
2621
</mirrors>
2722
</settings>
2823
EOF
@@ -34,6 +29,14 @@ COPY ./ ./
3429
RUN --mount=type=cache,target=/root/.m2/repository/ \
3530
mvn clean package --batch-mode
3631

32+
33+
FROM dragonwell-registry.cn-hangzhou.cr.aliyuncs.com/dragonwell/dragonwell:8-extended-ga-centos
34+
35+
# copy arthas
36+
COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas
37+
38+
COPY --from=build /app/target/A.jar /app/target/A.jar
39+
3740
EXPOSE 20001
3841
ENTRYPOINT ["sh", "-c"]
3942
CMD ["java -jar /app/target/A.jar"]

mse-simple-demo/A/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ set -e
33

44
cd "$(dirname "$0")"
55

6-
docker build . -t ${REGISTRY}spring-cloud-a:1.1.0
6+
docker build . -t ${REGISTRY}spring-cloud-a:1.2.0
77

88
if [ -n "${REGISTRY}" ]; then
9-
docker push ${REGISTRY}spring-cloud-a:1.1.0
9+
docker push ${REGISTRY}spring-cloud-a:1.2.0
1010
fi

mse-simple-demo/A/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.alibabacloud.mse.demo</groupId>
77
<artifactId>A</artifactId>
8-
<version>1.1.0</version>
8+
<version>1.2.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>A</name>

mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/AController.java

+99-1
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515
import org.springframework.beans.factory.annotation.Qualifier;
1616
import org.springframework.beans.factory.annotation.Value;
1717
import org.springframework.cloud.commons.util.InetUtils;
18+
import org.springframework.http.HttpStatus;
19+
import org.springframework.http.ResponseEntity;
1820
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
1921
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.PathVariable;
2023
import org.springframework.web.bind.annotation.RestController;
2124
import org.springframework.web.client.RestTemplate;
2225

2326
import javax.annotation.PostConstruct;
2427
import javax.servlet.http.HttpServletRequest;
2528
import java.util.Enumeration;
2629
import java.util.List;
30+
import java.util.Random;
2731
import java.util.concurrent.ExecutionException;
32+
import java.util.concurrent.TimeUnit;
2833

2934
@Api(value = "/", tags = {"入口应用"})
3035
@RestController
@@ -41,7 +46,7 @@ class AController {
4146
@Autowired
4247
InetUtils inetUtils;
4348

44-
@Reference(application = "${dubbo.application.id}", version = "1.1.0")
49+
@Reference(application = "${dubbo.application.id}", version = "1.2.0")
4550
private HelloServiceB helloServiceB;
4651

4752
@Autowired
@@ -55,6 +60,7 @@ class AController {
5560

5661
private String currentZone;
5762

63+
5864
@PostConstruct
5965
private void init() {
6066
try {
@@ -96,6 +102,44 @@ public String a(HttpServletRequest request) throws ExecutionException, Interrupt
96102
"[config=" + configValue + "]" + " -> " + result;
97103
}
98104

105+
@ApiOperation(value = "测试防护规则" , tags = {"流量防护"})
106+
@GetMapping("/flow")
107+
public String flow(HttpServletRequest request) throws ExecutionException, InterruptedException {
108+
109+
ResponseEntity<String> responseEntity = loadBalancedRestTemplate.getForEntity("http://sc-B/flow", String.class);
110+
HttpStatus status = responseEntity.getStatusCode();
111+
String result = responseEntity.getBody() + status.value();
112+
113+
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
114+
"[config=" + configValue + "]" + " -> " + result;
115+
}
116+
117+
118+
@ApiOperation(value = "测试热点规则", tags = {"流量防护"})
119+
@GetMapping("/params/{hot}")
120+
public String params(HttpServletRequest request,@PathVariable("hot") String hot) throws ExecutionException, InterruptedException {
121+
ResponseEntity<String> responseEntity = loadBalancedRestTemplate.getForEntity("http://sc-B/params/"+hot, String.class);
122+
123+
HttpStatus status = responseEntity.getStatusCode();
124+
String result = responseEntity.getBody() + status.value();
125+
126+
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
127+
"[config=" + configValue + "]" + " -> " + result;
128+
}
129+
130+
@ApiOperation(value = "测试隔离规则", tags = { "流量防护"})
131+
@GetMapping("/isolate")
132+
public String isolate(HttpServletRequest request) throws ExecutionException, InterruptedException {
133+
ResponseEntity<String> responseEntity = loadBalancedRestTemplate.getForEntity("http://sc-B/isolate", String.class);
134+
135+
HttpStatus status = responseEntity.getStatusCode();
136+
String result = responseEntity.getBody() + status.value();
137+
138+
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
139+
"[config=" + configValue + "]" + " -> " + result;
140+
}
141+
142+
99143
@GetMapping("/spring_boot")
100144
public String spring_boot(HttpServletRequest request) {
101145
String result = restTemplate.getForObject("http://sc-b:20002/spring_boot", String.class);
@@ -138,11 +182,65 @@ public String dubbo(HttpServletRequest request) {
138182
helloServiceB.hello("A");
139183
}
140184

185+
@ApiOperation(value = "Dubbo 全链路灰度入口", tags = {"入口应用"})
186+
@GetMapping("/dubbo-flow")
187+
public String dubbo_flow(HttpServletRequest request) {
188+
StringBuilder headerSb = new StringBuilder();
189+
Enumeration<String> enumeration = request.getHeaderNames();
190+
while (enumeration.hasMoreElements()) {
191+
String headerName = enumeration.nextElement();
192+
Enumeration<String> val = request.getHeaders(headerName);
193+
while (val.hasMoreElements()) {
194+
String headerVal = val.nextElement();
195+
headerSb.append(headerName + ":" + headerVal + ",");
196+
}
197+
}
198+
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
199+
helloServiceB.hello("A");
200+
}
201+
202+
@ApiOperation(value = "Dubbo 全链路灰度入口", tags = {"入口应用"})
203+
@GetMapping("/dubbo-params/{hot}")
204+
public String dubbo_params(HttpServletRequest request, @PathVariable("hot") String hot) {
205+
StringBuilder headerSb = new StringBuilder();
206+
Enumeration<String> enumeration = request.getHeaderNames();
207+
while (enumeration.hasMoreElements()) {
208+
String headerName = enumeration.nextElement();
209+
Enumeration<String> val = request.getHeaders(headerName);
210+
while (val.hasMoreElements()) {
211+
String headerVal = val.nextElement();
212+
headerSb.append(headerName + ":" + headerVal + ",");
213+
}
214+
}
215+
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
216+
helloServiceB.hello(hot);
217+
}
218+
219+
@ApiOperation(value = "Dubbo 全链路灰度入口", tags = {"入口应用"})
220+
@GetMapping("/dubbo-isolate")
221+
public String dubbo_isolate(HttpServletRequest request) {
222+
StringBuilder headerSb = new StringBuilder();
223+
Enumeration<String> enumeration = request.getHeaderNames();
224+
while (enumeration.hasMoreElements()) {
225+
String headerName = enumeration.nextElement();
226+
Enumeration<String> val = request.getHeaders(headerName);
227+
while (val.hasMoreElements()) {
228+
String headerVal = val.nextElement();
229+
headerSb.append(headerName + ":" + headerVal + ",");
230+
}
231+
}
232+
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
233+
helloServiceB.hello("isolate");
234+
}
235+
236+
141237
@GetMapping("swagger-demo")
142238
@ApiOperation(value = "这是一个演示swagger的接口 ", tags = {"首页操作页面"})
143239
public String swagger(@ApiParam(name = "name", value = "我是姓名", required = true) String name,
144240
@ApiParam(name = "age", value = "我是年龄", required = true) int age,
145241
@ApiParam(name = "aliware-products", value = "我是购买阿里云原生产品列表", required = true) List<String> aliwareProducts) {
146242
return "hello swagger";
147243
}
244+
245+
148246
}

mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/service/HelloServiceAImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.cloud.commons.util.InetUtils;
88

9-
@Service(version = "1.1.0")
9+
@Service(version = "1.2.0")
1010
public class HelloServiceAImpl implements HelloServiceA {
1111

1212
@Autowired
1313
InetUtils inetUtils;
1414

15-
@Reference(application = "${dubbo.application.id}", version = "1.1.0")
15+
@Reference(application = "${dubbo.application.id}", version = "1.2.0")
1616
private HelloServiceB helloServiceB;
1717

1818
@Autowired

mse-simple-demo/B/Dockerfile

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@ COPY <<EOF /root/.m2/settings.xml
1515
<mirror>
1616
<id>alimaven</id>
1717
<name>aliyun maven</name>
18-
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
18+
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
1919
<mirrorOf>central</mirrorOf>
2020
</mirror>
21-
<mirror>
22-
<id>maven-default-http-blocker</id>
23-
<mirrorOf>!*</mirrorOf>
24-
<url>http://0.0.0.0/</url>
25-
</mirror>
2621
</mirrors>
2722
</settings>
2823
EOF

mse-simple-demo/B/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
cd "$(dirname "$0")"
44

5-
docker build . -t ${REGISTRY}spring-cloud-b:1.1.0
5+
docker build . -t ${REGISTRY}spring-cloud-b:1.2.0
66

77
if [ -n "${REGISTRY}" ]; then
8-
docker push ${REGISTRY}spring-cloud-b:1.1.0
8+
docker push ${REGISTRY}spring-cloud-b:1.2.0
99
fi

mse-simple-demo/B/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.alibabacloud.mse.demo</groupId>
77
<artifactId>B</artifactId>
8-
<version>1.1.0</version>
8+
<version>1.2.0</version>
99
<packaging>jar</packaging>
1010

1111
<name>B</name>

mse-simple-demo/B/src/main/java/com/alibabacloud/mse/demo/BController.java

+69
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.alibabacloud.mse.demo;
22

3+
import com.alibabacloud.mse.demo.service.HelloServiceC;
4+
import org.apache.dubbo.config.annotation.Reference;
35
import org.apache.http.HttpResponse;
46
import org.apache.http.client.HttpClient;
57
import org.apache.http.client.config.RequestConfig;
@@ -10,11 +12,15 @@
1012
import org.springframework.beans.factory.annotation.Qualifier;
1113
import org.springframework.cloud.commons.util.InetUtils;
1214
import org.springframework.web.bind.annotation.GetMapping;
15+
import org.springframework.web.bind.annotation.PathVariable;
1316
import org.springframework.web.bind.annotation.RestController;
1417
import org.springframework.web.client.RestTemplate;
1518

1619
import javax.annotation.PostConstruct;
1720
import javax.servlet.http.HttpServletRequest;
21+
import java.util.Random;
22+
import java.util.concurrent.ExecutionException;
23+
import java.util.concurrent.TimeUnit;
1824

1925
@RestController
2026
class BController {
@@ -27,6 +33,9 @@ class BController {
2733
@Qualifier("restTemplate")
2834
private RestTemplate restTemplate;
2935

36+
@Reference(application = "${dubbo.application.id}", version = "1.2.0")
37+
private HelloServiceC helloServiceC;
38+
3039
@Autowired
3140
InetUtils inetUtils;
3241

@@ -35,6 +44,8 @@ class BController {
3544

3645
private String currentZone;
3746

47+
private static final Random RANDOM = new Random();
48+
3849
@PostConstruct
3950
private void init() {
4051
try {
@@ -53,6 +64,55 @@ private void init() {
5364
}
5465
}
5566

67+
68+
@GetMapping("/flow")
69+
public String flow(HttpServletRequest request) throws ExecutionException, InterruptedException {
70+
long sleepTime = 5 + RANDOM.nextInt(5);
71+
silentSleep(sleepTime);
72+
73+
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " + sleepTime;
74+
}
75+
76+
@GetMapping("/params/{hot}")
77+
public String params(HttpServletRequest request,@PathVariable("hot") String hot) throws ExecutionException, InterruptedException {
78+
long sleepTime = 5 + RANDOM.nextInt(5);
79+
silentSleep(sleepTime);
80+
helloServiceC.hello(hot);
81+
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " + sleepTime+":"+hot;
82+
}
83+
84+
@GetMapping("/isolate")
85+
public String isolate(HttpServletRequest request) throws ExecutionException, InterruptedException {
86+
long sleepTime = 20 + RANDOM.nextInt(5);
87+
silentSleep(sleepTime);
88+
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " + sleepTime;
89+
}
90+
91+
92+
@GetMapping("/flow-c")
93+
public String flow_c(HttpServletRequest request) throws ExecutionException, InterruptedException {
94+
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
95+
helloServiceC.hello("B");
96+
}
97+
98+
@GetMapping("/params-c/{hot}")
99+
public String params_c(HttpServletRequest request,@PathVariable("hot") String hot) throws ExecutionException, InterruptedException {
100+
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
101+
helloServiceC.hello(hot);
102+
}
103+
104+
@GetMapping("/isolate-c")
105+
public String isolate_c(HttpServletRequest request) throws ExecutionException, InterruptedException {
106+
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
107+
helloServiceC.hello("B");
108+
}
109+
110+
@GetMapping("/rpc-c")
111+
public String rpc_c(HttpServletRequest request) throws ExecutionException, InterruptedException {
112+
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
113+
helloServiceC.world("B");
114+
}
115+
56116
@GetMapping("/b")
57117
public String b(HttpServletRequest request) {
58118
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
@@ -70,4 +130,13 @@ public String spring_boot(HttpServletRequest request) {
70130
return "B" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
71131
restTemplate.getForObject("http://sc-c:20003/spring_boot", String.class);
72132
}
133+
134+
135+
private void silentSleep(long ms) {
136+
try {
137+
TimeUnit.MILLISECONDS.sleep(ms);
138+
} catch (InterruptedException ignored) {
139+
}
140+
}
141+
73142
}

mse-simple-demo/B/src/main/java/com/alibabacloud/mse/demo/service/HelloServiceBImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.cloud.commons.util.InetUtils;
77

8-
@Service(version = "1.1.0")
8+
@Service(version = "1.2.0")
99
public class HelloServiceBImpl implements HelloServiceB {
1010

1111
@Autowired
@@ -14,7 +14,7 @@ public class HelloServiceBImpl implements HelloServiceB {
1414
@Autowired
1515
String serviceTag;
1616

17-
@Reference(application = "${dubbo.application.id}", version = "1.1.0")
17+
@Reference(application = "${dubbo.application.id}", version = "1.2.0")
1818
private HelloServiceC helloServiceC;
1919

2020
@Override

mse-simple-demo/B/src/main/java/com/alibabacloud/mse/demo/service/HelloServiceC.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
public interface HelloServiceC {
44
String hello(String name);
5+
String world(String name);
56
}

0 commit comments

Comments
 (0)