Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit dd8ab40

Browse files
[feat] [*] [v0.2.0] add CLI tool, bug fix and documents update (#11)
* [fix] [v0.2.0] wrong way to add service `PluginManagementServiceImpl` to `NettyServer` - add configuration about management service host * [feat] [cli] [v0.2.0] add functionality code about CLI tool * [fix] [cli] [v0.2.0] fix start.sh for CLI tool * [fix] [cli] [v0.2.0] wrong default port of the server in start.sh * [doc] [*] [v0.2.0] update README.md and CLI tutorials * [feat] [*] [v0.2.0] add management service interface `restartBBC` - Update interface `restartBBC` to CLI - Update CLI tutorials with `restartBBC` - Add function `restartBBC` to `managementserver.proto` - Pass unit test cases * [doc] [*] [v0.2.0] update version to 0.2.0 in pom.xml and README.md * [doc] [*] [v0.2.0] using branch `develop` instead of branches with prefix `dev/` --------- Co-authored-by: zouxyan <[email protected]> Co-authored-by: dawn-to-dusk <[email protected]>
1 parent 78d15f2 commit dd8ab40

File tree

43 files changed

+2705
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2705
-36
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ We recommend that developers following the rules [here](https://jeffkreeftmeijer
1212

1313
## Contributing
1414

15-
- Fork the repository.
15+
- Fork the repository or create branches.
1616
- Checkout your branch like a feature or bugfix.
1717
- Make a pull request to the `develop` branch of this repository.
1818
- Wait for review and PR merged.
1919

2020
---
2121

22-
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://kcd.im/pull-request)
23-
22+
**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://kcd.im/pull-request)

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ AntChain Bridge 插件服务(PluginServer, PS)用于管理异构链插件、
4747
mvn clean package
4848
```
4949

50-
产生的安装包在`ps-bootstrap/target/plugin-server-0.1.2-SNAPSHOT.tar.gz`
50+
产生的安装包在`ps-bootstrap/target/plugin-server-x.x.x.tar.gz`
5151

5252
## 配置
5353

54-
在获得安装包之后,执行解压缩操作,这里以`plugin-server-0.1.2-SNAPSHOT.tar.gz`为例。
54+
在获得安装包之后,执行解压缩操作,这里以`plugin-server-x.x.x.tar.gz`为例。
5555

5656
```
57-
tar -zxf plugin-server-0.1.2-SNAPSHOT.tar.gz
57+
tar -zxf plugin-server-x.x.x.tar.gz
5858
```
5959

6060
进入解压后的目录,可以看到:
@@ -72,7 +72,7 @@ tree .
7272
├── config
7373
│   └── application.yml
7474
└── lib
75-
   └── ps-bootstrap-0.1.2-SNAPSHOT.jar
75+
   └── ps-bootstrap-x.x.x.jar
7676
7777
7878
3 directories, 7 files

pom.xml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,32 @@
1414
<module>ps-service</module>
1515
<module>ps-server</module>
1616
<module>ps-pluginmanager</module>
17+
<module>ps-cli</module>
1718
</modules>
1819

1920
<properties>
2021
<java.version>8</java.version>
21-
<pluginserver.version>0.1.2-SNAPSHOT</pluginserver.version>
22+
<pluginserver.version>0.2.0</pluginserver.version>
2223
<grpc-starter.version>2.13.1.RELEASE</grpc-starter.version>
2324
<netty-tcnative-boringssl-static.version>2.0.59.Final</netty-tcnative-boringssl-static.version>
2425
<protobuf.version>3.19.1</protobuf.version>
2526
<protobuf-plugin.version>0.6.1</protobuf-plugin.version>
2627
<grpc.version>1.42.2</grpc.version>
2728
<jakarta.annotation-api.version>1.3.5</jakarta.annotation-api.version>
2829
<junit.version>4.13.2</junit.version>
29-
<antchain-bridge.sdk.version>0.1-SNAPSHOT</antchain-bridge.sdk.version>
30+
<antchain-bridge.sdk.version>0.1.1</antchain-bridge.sdk.version>
31+
<jline.version>3.3.0</jline.version>
32+
<groovy.version>3.0.17</groovy.version>
33+
<commons-cli.version>1.5.0</commons-cli.version>
34+
<hutool.version>5.8.10</hutool.version>
35+
<fastjson.version>2.0.21</fastjson.version>
36+
<pf4j.version>3.8.0</pf4j.version>
37+
<slf4j.version>1.7.28</slf4j.version>
3038
</properties>
3139

3240
<groupId>com.alipay.antchain.bridge</groupId>
3341
<artifactId>antchain-bridge-pluginserver</artifactId>
34-
<version>0.1.2-SNAPSHOT</version>
42+
<version>0.2.0</version>
3543

3644
<name>antchain-bridge-pluginserver</name>
3745
<description>antchain-bridge-pluginserver</description>
@@ -103,25 +111,48 @@
103111
<dependency>
104112
<groupId>org.pf4j</groupId>
105113
<artifactId>pf4j</artifactId>
106-
<version>3.8.0</version>
114+
<version>${pf4j.version}</version>
107115
</dependency>
108-
109116
<dependency>
110117
<groupId>com.alipay.antchain.bridge</groupId>
111118
<artifactId>antchain-bridge-plugin-lib</artifactId>
112119
<version>${antchain-bridge.sdk.version}</version>
113120
</dependency>
114-
115121
<dependency>
116122
<groupId>org.slf4j</groupId>
117123
<artifactId>slf4j-api</artifactId>
118-
<version>1.7.28</version>
124+
<version>${slf4j.version}</version>
119125
</dependency>
120-
121126
<dependency>
122127
<groupId>org.slf4j</groupId>
123128
<artifactId>slf4j-simple</artifactId>
124-
<version>1.7.28</version>
129+
<version>${slf4j.version}</version>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.jline</groupId>
133+
<artifactId>jline</artifactId>
134+
<version>${jline.version}</version>
135+
</dependency>
136+
<dependency>
137+
<groupId>org.codehaus.groovy</groupId>
138+
<artifactId>groovy-all</artifactId>
139+
<version>${groovy.version}</version>
140+
<type>pom</type>
141+
</dependency>
142+
<dependency>
143+
<groupId>commons-cli</groupId>
144+
<artifactId>commons-cli</artifactId>
145+
<version>${commons-cli.version}</version>
146+
</dependency>
147+
<dependency>
148+
<groupId>cn.hutool</groupId>
149+
<artifactId>hutool-all</artifactId>
150+
<version>${hutool.version}</version>
151+
</dependency>
152+
<dependency>
153+
<groupId>com.alibaba</groupId>
154+
<artifactId>fastjson</artifactId>
155+
<version>${fastjson.version}</version>
125156
</dependency>
126157
</dependencies>
127158
</dependencyManagement>

ps-bootstrap/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alipay.antchain.bridge</groupId>
88
<artifactId>antchain-bridge-pluginserver</artifactId>
9-
<version>0.1.2-SNAPSHOT</version>
9+
<version>0.2.0</version>
1010
</parent>
1111

1212
<artifactId>ps-bootstrap</artifactId>

ps-bootstrap/src/main/java/com/alipay/antchain/bridge/pluginserver/config/PluginManagerConfiguration.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@
1717
package com.alipay.antchain.bridge.pluginserver.config;
1818

1919
import cn.hutool.core.collection.ListUtil;
20+
import cn.hutool.core.util.StrUtil;
2021
import com.alipay.antchain.bridge.pluginserver.pluginmanager.IPluginManagerWrapper;
2122
import com.alipay.antchain.bridge.pluginserver.pluginmanager.PluginManagerWrapperImpl;
2223
import com.alipay.antchain.bridge.pluginserver.server.PluginManagementServiceImpl;
2324
import io.grpc.Server;
2425
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
2526
import lombok.extern.slf4j.Slf4j;
2627
import org.pf4j.ClassLoadingStrategy;
28+
import org.springframework.beans.factory.annotation.Autowired;
2729
import org.springframework.beans.factory.annotation.Value;
2830
import org.springframework.context.annotation.Bean;
2931
import org.springframework.context.annotation.Configuration;
3032

3133
import java.io.IOException;
34+
import java.net.InetAddress;
35+
import java.net.InetSocketAddress;
3236
import java.util.HashMap;
3337
import java.util.HashSet;
3438
import java.util.Map;
@@ -43,6 +47,9 @@ public class PluginManagerConfiguration {
4347
@Value("${pluginserver.plugin.policy.classloader.resource.ban-with-prefix.APPLICATION}")
4448
private String[] resourceBannedPrefixOnAppLevel;
4549

50+
@Value("${pluginserver.managerserver.host}")
51+
private String managementHost;
52+
4653
@Bean
4754
public IPluginManagerWrapper pluginManagerWrapper() {
4855
return new PluginManagerWrapperImpl(
@@ -66,10 +73,14 @@ private Map<ClassLoadingStrategy.Source, Set<String>> convertPathPrefixBannedMap
6673
private String pluginServerMgrPort;
6774

6875
@Bean
69-
public Server pluginMgrServer() throws IOException {
76+
public Server pluginMgrServer(@Autowired PluginManagementServiceImpl pluginManagementService) throws IOException {
7077
log.info("Starting plugin managing server on port " + pluginServerMgrPort);
71-
return NettyServerBuilder.forPort(Integer.parseInt(pluginServerMgrPort))
72-
.addService(new PluginManagementServiceImpl())
78+
return NettyServerBuilder.forAddress(
79+
new InetSocketAddress(
80+
StrUtil.isEmpty(managementHost) ? InetAddress.getLoopbackAddress() : InetAddress.getByName(managementHost),
81+
Integer.parseInt(pluginServerMgrPort)
82+
)
83+
).addService(pluginManagementService)
7384
.build()
7485
.start();
7586
}

ps-bootstrap/src/main/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ pluginserver:
2828
# where to load the hetero-chain plugins
2929
repo: ./plugins
3030
policy:
31+
# limit actions of the plugin classloader
3132
classloader:
3233
resource:
3334
ban-with-prefix:
35+
# the plugin classloader will not read the resource file starting with the prefix below
3436
APPLICATION: "META-INF/services/io.grpc."
3537
managerserver:
38+
host: localhost
3639
port: 9091

ps-bootstrap/src/main/resources/scripts/start.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ print_title
77

88
log_info "start plugin-server now..."
99

10-
java -jar -Dlogging.file.path=${CURR_DIR}/../log ${CURR_DIR}/../lib/ps-bootstrap-0.1.2-SNAPSHOT.jar --spring.config.location=file:${CURR_DIR}/../config/application.yml > /dev/null 2>&1 &
10+
JAR_FILE=`ls ${CURR_DIR}/../lib/ | grep '.jar'`
11+
12+
java -jar -Dlogging.file.path=${CURR_DIR}/../log ${CURR_DIR}/../lib/${JAR_FILE} --spring.config.location=file:${CURR_DIR}/../config/application.yml > /dev/null 2>&1 &
1113
if [ $? -ne 0 ]; then
1214
log_error "failed to start plugin-server"
1315
exit 1

ps-bootstrap/src/test/java/com/alipay/antchain/bridge/pluginserver/AntChainBridgePluginManagementApplicationTests.java

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.alipay.antchain.bridge.pluginserver.server.CrossChainServiceImpl;
2323
import com.alipay.antchain.bridge.pluginserver.server.PluginManagementServiceImpl;
2424
import com.alipay.antchain.bridge.pluginserver.server.ResponseBuilder;
25+
import com.alipay.antchain.bridge.pluginserver.server.exception.ServerErrorCodeEnum;
2526
import com.alipay.antchain.bridge.pluginserver.service.CallBBCRequest;
2627
import com.alipay.antchain.bridge.pluginserver.service.CallBBCResponse;
2728
import com.alipay.antchain.bridge.pluginserver.service.Response;
@@ -83,7 +84,7 @@ public void testManageLoadAndStartPluginsReq() {
8384

8485
@Test
8586
@DirtiesContext
86-
public void testManagePluginReq(){
87+
public void testManagePluginReq() {
8788
PluginManageRequest pluginManageRequest;
8889

8990
// 1. load plugin
@@ -163,7 +164,7 @@ public void testManagePluginReq(){
163164

164165
@Test
165166
@DirtiesContext
166-
public void testPluginQueryReq(){
167+
public void testPluginQueryReq() {
167168
PluginManageRequest pluginManageRequest;
168169

169170
// 1. All plugins in the default path are automatically loaded when the service starts
@@ -174,7 +175,7 @@ public void testPluginQueryReq(){
174175
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
175176
pluginManagementService.hasPlugins(hasPluginsRequest, mngResponseStreamObserver);
176177
Mockito.verify(mngResponseStreamObserver).onNext(ResponseBuilder.buildHasPluginsResp(
177-
HasPluginsResp.newBuilder().putAllResults(new HashMap<String, Boolean>(){{
178+
HasPluginsResp.newBuilder().putAllResults(new HashMap<String, Boolean>() {{
178179
put(DEFAULT_PRODUCT, true);
179180
put(TEST_PRODUCT, false);
180181
}})
@@ -214,13 +215,13 @@ public void testPluginQueryReq(){
214215
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
215216
pluginManagementService.hasDomains(hasDomainsRequest, mngResponseStreamObserver);
216217
Mockito.verify(mngResponseStreamObserver).onNext(ResponseBuilder.buildHasDomainsResp(
217-
HasDomainsResp.newBuilder().putAllResults(new HashMap<String, Boolean>(){{
218+
HasDomainsResp.newBuilder().putAllResults(new HashMap<String, Boolean>() {{
218219
put(TEST_DOMAIN, false);
219220
}})
220221
));
221222
Mockito.verify(mngResponseStreamObserver).onCompleted();
222223

223-
// 6. all doamin
224+
// 6. all domain
224225
AllDomainsRequest allDomainsRequest = AllDomainsRequest.newBuilder().build();
225226
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
226227
pluginManagementService.allDomains(allDomainsRequest, mngResponseStreamObserver);
@@ -229,7 +230,7 @@ public void testPluginQueryReq(){
229230
));
230231
Mockito.verify(mngResponseStreamObserver).onCompleted();
231232

232-
// 7. create service with test doamin
233+
// 7. create service with test domain
233234
AbstractBBCContext mockCtx = AntChainBridgePluginServerApplicationTests.mockInitCtx();
234235
CallBBCRequest callBBCRequest = CallBBCRequest.newBuilder()
235236
.setProduct(DEFAULT_PRODUCT)
@@ -240,7 +241,7 @@ public void testPluginQueryReq(){
240241
Mockito.verify(responseStreamObserver).onNext(ResponseBuilder.buildBBCSuccessResp(CallBBCResponse.newBuilder()));
241242
Mockito.verify(responseStreamObserver).onCompleted();
242243

243-
// 8. all doamin
244+
// 8. all domain
244245
allDomainsRequest = AllDomainsRequest.newBuilder().build();
245246
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
246247
pluginManagementService.allDomains(allDomainsRequest, mngResponseStreamObserver);
@@ -250,4 +251,50 @@ public void testPluginQueryReq(){
250251
Mockito.verify(mngResponseStreamObserver).onCompleted();
251252
}
252253

254+
@Test
255+
@DirtiesContext
256+
public void testRestartBBC() {
257+
// 1. failed to restart a domain or product not exist
258+
RestartBBCRequest request = RestartBBCRequest.newBuilder()
259+
.setDomain("domain")
260+
.setProduct("product")
261+
.build();
262+
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
263+
pluginManagementService.restartBBC(request, mngResponseStreamObserver);
264+
Mockito.verify(mngResponseStreamObserver)
265+
.onNext(ResponseBuilder.buildFailManageResp(ServerErrorCodeEnum.MANAGE_RESTART_BBC_ERROR, "product not found"));
266+
Mockito.verify(mngResponseStreamObserver).onCompleted();
267+
268+
// 2. green case
269+
PluginManageRequest pluginManageRequest = PluginManageRequest.newBuilder()
270+
.setType(PluginManageRequest.Type.LOAD_PLUGIN)
271+
.setPath(TEST_PLUGIN_PATH).build();
272+
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
273+
pluginManagementService.managePlugin(pluginManageRequest, mngResponseStreamObserver);
274+
pluginManageRequest = PluginManageRequest.newBuilder()
275+
.setType(PluginManageRequest.Type.START_PLUGIN)
276+
.setPath(TEST_PLUGIN_PATH).build();
277+
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
278+
pluginManagementService.managePlugin(pluginManageRequest, mngResponseStreamObserver);
279+
280+
responseStreamObserver = Mockito.mock(StreamObserver.class);
281+
crossChainService.bbcCall(
282+
CallBBCRequest.newBuilder()
283+
.setDomain("domain")
284+
.setProduct("testchain")
285+
.setStartUpReq(StartUpRequest.newBuilder().setRawContext(ByteString.copyFromUtf8("{\"raw_conf\": \"\"}")))
286+
.build(),
287+
responseStreamObserver
288+
);
289+
290+
request = RestartBBCRequest.newBuilder()
291+
.setDomain("domain")
292+
.setProduct("testchain")
293+
.build();
294+
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
295+
pluginManagementService.restartBBC(request, mngResponseStreamObserver);
296+
297+
Mockito.verify(mngResponseStreamObserver).onNext(ResponseBuilder.buildRestartBBCResp(RestartBBCResp.newBuilder()));
298+
Mockito.verify(mngResponseStreamObserver).onCompleted();
299+
}
253300
}

ps-bootstrap/src/test/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ pluginserver:
3232
ban-with-prefix:
3333
APPLICATION: "META-INF/services/io.grpc."
3434
managerserver:
35+
host: 0.0.0.0
3536
port: 9091

ps-cli/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

0 commit comments

Comments
 (0)