Skip to content

Commit

Permalink
[feat] [*] [v0.2.0] add CLI tool, bug fix and documents update (#11)
Browse files Browse the repository at this point in the history
* [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 <zouxueyan.zxy@antgroup.com>
Co-authored-by: dawn-to-dusk <37816460+dawn-to-dusk@users.noreply.github.com>
  • Loading branch information
3 people committed May 23, 2023
1 parent 78d15f2 commit dd8ab40
Show file tree
Hide file tree
Showing 43 changed files with 2,705 additions and 36 deletions.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ We recommend that developers following the rules [here](https://jeffkreeftmeijer

## Contributing

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

---

**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)

**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)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ AntChain Bridge 插件服务(PluginServer, PS)用于管理异构链插件、
mvn clean package
```

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

## 配置

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

```
tar -zxf plugin-server-0.1.2-SNAPSHOT.tar.gz
tar -zxf plugin-server-x.x.x.tar.gz
```

进入解压后的目录,可以看到:
Expand All @@ -72,7 +72,7 @@ tree .
├── config
│   └── application.yml
└── lib
   └── ps-bootstrap-0.1.2-SNAPSHOT.jar
   └── ps-bootstrap-x.x.x.jar
3 directories, 7 files
Expand Down
49 changes: 40 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,32 @@
<module>ps-service</module>
<module>ps-server</module>
<module>ps-pluginmanager</module>
<module>ps-cli</module>
</modules>

<properties>
<java.version>8</java.version>
<pluginserver.version>0.1.2-SNAPSHOT</pluginserver.version>
<pluginserver.version>0.2.0</pluginserver.version>
<grpc-starter.version>2.13.1.RELEASE</grpc-starter.version>
<netty-tcnative-boringssl-static.version>2.0.59.Final</netty-tcnative-boringssl-static.version>
<protobuf.version>3.19.1</protobuf.version>
<protobuf-plugin.version>0.6.1</protobuf-plugin.version>
<grpc.version>1.42.2</grpc.version>
<jakarta.annotation-api.version>1.3.5</jakarta.annotation-api.version>
<junit.version>4.13.2</junit.version>
<antchain-bridge.sdk.version>0.1-SNAPSHOT</antchain-bridge.sdk.version>
<antchain-bridge.sdk.version>0.1.1</antchain-bridge.sdk.version>
<jline.version>3.3.0</jline.version>
<groovy.version>3.0.17</groovy.version>
<commons-cli.version>1.5.0</commons-cli.version>
<hutool.version>5.8.10</hutool.version>
<fastjson.version>2.0.21</fastjson.version>
<pf4j.version>3.8.0</pf4j.version>
<slf4j.version>1.7.28</slf4j.version>
</properties>

<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-pluginserver</artifactId>
<version>0.1.2-SNAPSHOT</version>
<version>0.2.0</version>

<name>antchain-bridge-pluginserver</name>
<description>antchain-bridge-pluginserver</description>
Expand Down Expand Up @@ -103,25 +111,48 @@
<dependency>
<groupId>org.pf4j</groupId>
<artifactId>pf4j</artifactId>
<version>3.8.0</version>
<version>${pf4j.version}</version>
</dependency>

<dependency>
<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-plugin-lib</artifactId>
<version>${antchain-bridge.sdk.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.28</version>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>${jline.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons-cli.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion ps-bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.antchain.bridge</groupId>
<artifactId>antchain-bridge-pluginserver</artifactId>
<version>0.1.2-SNAPSHOT</version>
<version>0.2.0</version>
</parent>

<artifactId>ps-bootstrap</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
package com.alipay.antchain.bridge.pluginserver.config;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.alipay.antchain.bridge.pluginserver.pluginmanager.IPluginManagerWrapper;
import com.alipay.antchain.bridge.pluginserver.pluginmanager.PluginManagerWrapperImpl;
import com.alipay.antchain.bridge.pluginserver.server.PluginManagementServiceImpl;
import io.grpc.Server;
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
import lombok.extern.slf4j.Slf4j;
import org.pf4j.ClassLoadingStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

@Value("${pluginserver.managerserver.host}")
private String managementHost;

@Bean
public IPluginManagerWrapper pluginManagerWrapper() {
return new PluginManagerWrapperImpl(
Expand All @@ -66,10 +73,14 @@ private Map<ClassLoadingStrategy.Source, Set<String>> convertPathPrefixBannedMap
private String pluginServerMgrPort;

@Bean
public Server pluginMgrServer() throws IOException {
public Server pluginMgrServer(@Autowired PluginManagementServiceImpl pluginManagementService) throws IOException {
log.info("Starting plugin managing server on port " + pluginServerMgrPort);
return NettyServerBuilder.forPort(Integer.parseInt(pluginServerMgrPort))
.addService(new PluginManagementServiceImpl())
return NettyServerBuilder.forAddress(
new InetSocketAddress(
StrUtil.isEmpty(managementHost) ? InetAddress.getLoopbackAddress() : InetAddress.getByName(managementHost),
Integer.parseInt(pluginServerMgrPort)
)
).addService(pluginManagementService)
.build()
.start();
}
Expand Down
3 changes: 3 additions & 0 deletions ps-bootstrap/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ pluginserver:
# where to load the hetero-chain plugins
repo: ./plugins
policy:
# limit actions of the plugin classloader
classloader:
resource:
ban-with-prefix:
# the plugin classloader will not read the resource file starting with the prefix below
APPLICATION: "META-INF/services/io.grpc."
managerserver:
host: localhost
port: 9091
4 changes: 3 additions & 1 deletion ps-bootstrap/src/main/resources/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ print_title

log_info "start plugin-server now..."

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 &
JAR_FILE=`ls ${CURR_DIR}/../lib/ | grep '.jar'`

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 &
if [ $? -ne 0 ]; then
log_error "failed to start plugin-server"
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.alipay.antchain.bridge.pluginserver.server.CrossChainServiceImpl;
import com.alipay.antchain.bridge.pluginserver.server.PluginManagementServiceImpl;
import com.alipay.antchain.bridge.pluginserver.server.ResponseBuilder;
import com.alipay.antchain.bridge.pluginserver.server.exception.ServerErrorCodeEnum;
import com.alipay.antchain.bridge.pluginserver.service.CallBBCRequest;
import com.alipay.antchain.bridge.pluginserver.service.CallBBCResponse;
import com.alipay.antchain.bridge.pluginserver.service.Response;
Expand Down Expand Up @@ -83,7 +84,7 @@ public void testManageLoadAndStartPluginsReq() {

@Test
@DirtiesContext
public void testManagePluginReq(){
public void testManagePluginReq() {
PluginManageRequest pluginManageRequest;

// 1. load plugin
Expand Down Expand Up @@ -163,7 +164,7 @@ public void testManagePluginReq(){

@Test
@DirtiesContext
public void testPluginQueryReq(){
public void testPluginQueryReq() {
PluginManageRequest pluginManageRequest;

// 1. All plugins in the default path are automatically loaded when the service starts
Expand All @@ -174,7 +175,7 @@ public void testPluginQueryReq(){
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.hasPlugins(hasPluginsRequest, mngResponseStreamObserver);
Mockito.verify(mngResponseStreamObserver).onNext(ResponseBuilder.buildHasPluginsResp(
HasPluginsResp.newBuilder().putAllResults(new HashMap<String, Boolean>(){{
HasPluginsResp.newBuilder().putAllResults(new HashMap<String, Boolean>() {{
put(DEFAULT_PRODUCT, true);
put(TEST_PRODUCT, false);
}})
Expand Down Expand Up @@ -214,13 +215,13 @@ public void testPluginQueryReq(){
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.hasDomains(hasDomainsRequest, mngResponseStreamObserver);
Mockito.verify(mngResponseStreamObserver).onNext(ResponseBuilder.buildHasDomainsResp(
HasDomainsResp.newBuilder().putAllResults(new HashMap<String, Boolean>(){{
HasDomainsResp.newBuilder().putAllResults(new HashMap<String, Boolean>() {{
put(TEST_DOMAIN, false);
}})
));
Mockito.verify(mngResponseStreamObserver).onCompleted();

// 6. all doamin
// 6. all domain
AllDomainsRequest allDomainsRequest = AllDomainsRequest.newBuilder().build();
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.allDomains(allDomainsRequest, mngResponseStreamObserver);
Expand All @@ -229,7 +230,7 @@ public void testPluginQueryReq(){
));
Mockito.verify(mngResponseStreamObserver).onCompleted();

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

// 8. all doamin
// 8. all domain
allDomainsRequest = AllDomainsRequest.newBuilder().build();
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.allDomains(allDomainsRequest, mngResponseStreamObserver);
Expand All @@ -250,4 +251,50 @@ public void testPluginQueryReq(){
Mockito.verify(mngResponseStreamObserver).onCompleted();
}

@Test
@DirtiesContext
public void testRestartBBC() {
// 1. failed to restart a domain or product not exist
RestartBBCRequest request = RestartBBCRequest.newBuilder()
.setDomain("domain")
.setProduct("product")
.build();
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.restartBBC(request, mngResponseStreamObserver);
Mockito.verify(mngResponseStreamObserver)
.onNext(ResponseBuilder.buildFailManageResp(ServerErrorCodeEnum.MANAGE_RESTART_BBC_ERROR, "product not found"));
Mockito.verify(mngResponseStreamObserver).onCompleted();

// 2. green case
PluginManageRequest pluginManageRequest = PluginManageRequest.newBuilder()
.setType(PluginManageRequest.Type.LOAD_PLUGIN)
.setPath(TEST_PLUGIN_PATH).build();
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.managePlugin(pluginManageRequest, mngResponseStreamObserver);
pluginManageRequest = PluginManageRequest.newBuilder()
.setType(PluginManageRequest.Type.START_PLUGIN)
.setPath(TEST_PLUGIN_PATH).build();
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.managePlugin(pluginManageRequest, mngResponseStreamObserver);

responseStreamObserver = Mockito.mock(StreamObserver.class);
crossChainService.bbcCall(
CallBBCRequest.newBuilder()
.setDomain("domain")
.setProduct("testchain")
.setStartUpReq(StartUpRequest.newBuilder().setRawContext(ByteString.copyFromUtf8("{\"raw_conf\": \"\"}")))
.build(),
responseStreamObserver
);

request = RestartBBCRequest.newBuilder()
.setDomain("domain")
.setProduct("testchain")
.build();
mngResponseStreamObserver = Mockito.mock(StreamObserver.class);
pluginManagementService.restartBBC(request, mngResponseStreamObserver);

Mockito.verify(mngResponseStreamObserver).onNext(ResponseBuilder.buildRestartBBCResp(RestartBBCResp.newBuilder()));
Mockito.verify(mngResponseStreamObserver).onCompleted();
}
}
1 change: 1 addition & 0 deletions ps-bootstrap/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ pluginserver:
ban-with-prefix:
APPLICATION: "META-INF/services/io.grpc."
managerserver:
host: 0.0.0.0
port: 9091
38 changes: 38 additions & 0 deletions ps-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
Loading

0 comments on commit dd8ab40

Please sign in to comment.