Skip to content

Commit

Permalink
Merge pull request #69 from daizhenyu/2.1.x
Browse files Browse the repository at this point in the history
xds router demo
  • Loading branch information
lilai23 authored Oct 14, 2024
2 parents 7ea67d4 + 70784ac commit c6f1a52
Show file tree
Hide file tree
Showing 23 changed files with 903 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,14 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/package/result/sermant-examples-xds-service-discovery-demo-${{ env.version }}.tar.gz
asset_name: sermant-examples-xds-service-discovery-demo-${{ env.version }}.tar.gz
asset_content_type: application/tar
- name: Upload Release xds-router-demo # xds-router-demo release包
id: upload-release-asset-xds-router
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/package/result/sermant-examples-xds-router-demo-${{ env.version }}.tar.gz
asset_name: sermant-examples-xds-router-demo-${{ env.version }}.tar.gz
asset_content_type: application/tar
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>loadbalancer-demo</module>
<module>database-write-prohibition-demo</module>
<module>xds-service-discovery-demo</module>
<module>xds-router-demo</module>
</modules>

<properties>
Expand Down
4 changes: 4 additions & 0 deletions scripts/copy_jar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ mkdir -p package/mq-consume-prohibition-demo
mkdir -p package/database-write-prohibition-demo
mkdir -p package/first-plugin-demo
mkdir -p package/xds-service-discovery-demo
mkdir -p package/xds-router-demo

# 按照文件名模式将对应的jar文件复制到对应目录
# 创建首个插件
find . -type d -name "agent" -exec cp -rv {} package/first-plugin-demo/ \;
# xDS服务发现
find . -type d -name "product" -exec cp -rv {} package/xds-service-discovery-demo/ \;
# xDS路由
find . -type d -name "router-product" -exec cp -rv {} package/xds-router-demo/ \;
# 动态配置
find . -type f -name "spring-provider.jar" -exec cp -v {} package/dynamic-demo/ \;
# 流控
Expand Down Expand Up @@ -76,6 +79,7 @@ find . -type f -name "rest-provider.jar" -exec cp -v {} package/removal-demo/ \;
# 打包
tar -czvf package/result/sermant-examples-first-plugin-demo-$*.tar.gz -C package/first-plugin-demo/ .
tar -czvf package/result/sermant-examples-xds-service-discovery-demo-$*.tar.gz -C package/xds-service-discovery-demo/ .
tar -czvf package/result/sermant-examples-xds-router-demo-$*.tar.gz -C package/xds-router-demo/ .
tar -czvf package/result/sermant-examples-dynamic-demo-$*.tar.gz -C package/dynamic-demo/ .
tar -czvf package/result/sermant-examples-flowcontrol-demo-$*.tar.gz -C package/flowcontrol-demo/ .
tar -czvf package/result/sermant-examples-grace-demo-$*.tar.gz -C package/grace-demo/ .
Expand Down
48 changes: 48 additions & 0 deletions xds-router-demo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sermant-examples</artifactId>
<groupId>com.huaweicloud.sermant.examples</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>xds-router-demo</artifactId>
<packaging>pom</packaging>

<modules>
<module>spring-cloud-client-xds</module>
<module>spring-cloud-server-xds</module>
</modules>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<springboot.version>2.7.17</springboot.version>
<springcloud.version>2021.0.3</springcloud.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${springcloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
46 changes: 46 additions & 0 deletions xds-router-demo/router-product/script/spring-client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-client
spec:
replicas: 1
selector:
matchLabels:
app: spring-client
template:
metadata:
labels:
app: spring-client
spec:
containers:
- name: spring-client
image: spring-client:1.0.0
imagePullPolicy: Never
ports:
- containerPort: 8080
env:
- name: agent_service_dynamic_config_enable
value: "false"
- name: agent_service_xds_service_enable
value: "true"
- name: router_plugin_enabled_xds_route
value: "true"
- name: ZOOKEEPER_ENABLED
value: "false"
- name: JAVA_TOOL_OPTIONS
value: "-javaagent:/home/agent/sermant-agent.jar"
imagePullSecrets:
- name: default-secret
---
apiVersion: v1
kind: Service
metadata:
name: spring-client
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
nodePort: 30110
selector:
app: spring-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: spring-server-destinationrule-robin
spec:
host: spring-server.default.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: spring-server-virtualservice
spec:
hosts:
- spring-server
http:
- name: "v1-routes"
match:
- headers:
version:
exact: v1
uri:
exact: /router
ignoreUriCase: false
route:
- destination:
host: spring-server
subset: v1
port:
number: 8081
73 changes: 73 additions & 0 deletions xds-router-demo/router-product/script/spring-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-server-v1
spec:
replicas: 1
selector:
matchLabels:
app: spring-server
version: v1
template:
metadata:
labels:
app: spring-server
version: v1
spec:
containers:
- name: spring-server
image: spring-server:1.0.0
imagePullPolicy: Never
ports:
- containerPort: 8081
env:
- name: SERVER_VERSION
value: "v1"
- name: ZOOKEEPER_ENABLED
value: "false"
imagePullSecrets:
- name: default-secret
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-server-v2
spec:
replicas: 1
selector:
matchLabels:
app: spring-server
version: v2
template:
metadata:
labels:
app: spring-server
version: v2
spec:
containers:
- name: spring-server
image: spring-server:1.0.0
imagePullPolicy: Never
ports:
- containerPort: 8081
env:
- name: SERVER_VERSION
value: "v2"
- name: ZOOKEEPER_ENABLED
value: "false"
imagePullSecrets:
- name: default-secret
---
apiVersion: v1
kind: Service
metadata:
name: spring-server
spec:
type: ClusterIP
ports:
- port: 8081
targetPort: 8081
protocol: TCP
name: http
selector:
app: spring-server
7 changes: 7 additions & 0 deletions xds-router-demo/router-product/spring-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openjdk:8
WORKDIR /home
COPY agent/ /home/agent
COPY spring-client.jar /home/spring-client.jar
COPY start.sh /home
RUN chmod -R 777 /home
ENTRYPOINT ["sh", "/home/start.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -f Dockerfile -t spring-client:1.0.0 .
1 change: 1 addition & 0 deletions xds-router-demo/router-product/spring-client/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec java -jar /home/spring-client.jar
6 changes: 6 additions & 0 deletions xds-router-demo/router-product/spring-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM openjdk:8
WORKDIR /home
COPY spring-server.jar /home/spring-server.jar
COPY start.sh /home
RUN chmod -R 777 /home
ENTRYPOINT ["sh", "/home/start.sh"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -f Dockerfile -t spring-server:1.0.0 .
1 change: 1 addition & 0 deletions xds-router-demo/router-product/spring-server/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exec java -jar /home/spring-server.jar
99 changes: 99 additions & 0 deletions xds-router-demo/spring-cloud-client-xds/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>xds-router-demo</artifactId>
<groupId>com.huaweicloud.sermant.examples</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-cloud-client-xds</artifactId>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<httpclient.version>4.5.13</httpclient.version>
<okhttp3.version>4.9.3</okhttp3.version>
<httpclient.async.version>4.1.5</httpclient.async.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>${httpclient.async.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
<configuration>
<mainClass>io.sermant.demo.xds.spring.client.SpringCloudClientApplication</mainClass>
<finalName>spring-client</finalName>
<outputDirectory>${pom.basedir}/../product/spring-client</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<inherited>false</inherited>
<executions>
<execution>
<id>agent-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${pom.basedir}/../product/spring-client</directory>
<includes>
<include>spring-client.jar</include>
</includes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit c6f1a52

Please sign in to comment.