FABRIC-JAVA-SDK 一直没有人提及,我来吃螃蟹啦!
# 环境检查
除了之前文章所述的一切,还要
- 安装maven
- 安装jdk
```
sudo apt install maven
sudo apt install default-jdk
```
# 下载源代码
```
ssh username@IP地址
```
ssh进入虚拟机后:
```
cd ~
git clone https://github.com/hyperledger/fabric-sdk-java
cd ~/fabric-sdk-java/
mvn install
```
这个时候客户端的一切准备完毕,编译安装了
target/fabric-sdk-java-1.0-SNAPSHOT.jar
等启用服务端,就可以开始测试
# DOCKER 环境
```
cd ~/fabric-sdk-java/src/test/fixture/sdkintegration/e2e-2Orgs/
ls
```
目录结构:
- src/test/fixture/sdkintegration/e2e-2Orgs/channel Orderer创始块和频道建立所需
- src/test/fixture/sdkintegration/e2e-2Orgs/crypto-config configtxgen and docker-compose 映射到 MSP 目录
- src/test/fixture/sdkintegration/docker-compose.yaml 这个不用说了吧
启动起之前,先清理环境。
```
docker rm -f $(docker ps -aq)
cd ~/fabric-sdk-java/src/test/fixture/sdkintegration/
docker-compose up
```
# 测试
创建创始块和两个通道
```
build/bin/configtxgen -outputCreateChannelTx foo.tx -profile TwoOrgs -channelID foo
build/bin/configtxgen -outputCreateChannelTx bar.tx -profile TwoOrgs -channelID bar
build/bin/configtxgen -outputBlock twoorgs.orderer.block -profile TwoOrgs
```
启动客户端测试
```
cd ~/fabric-sdk-java/
mvn failsafe:integration-test -DskipITs=false
```
# 其他
couchDb数据库访问方式:
- http://localhost:5984/_utils/
- http://localhost:5984/member_db
cd $GOPATH/src/github.com/hyperledger/fabric/
build/bin/configtxgen -outputCreateChannelTx foo.tx -profile TwoOrgs -channelID foo
build/bin/configtxgen -outputCreateChannelTx bar.tx -profile TwoOrgs -channelID bar
build/bin/configtxgen -outputBlock twoorgs.orderer.block -profile TwoOrgs
# Vagrant 环境
Vagrant 环境比Docker复杂,同时坑也更多,目录结构与配置文件,让我想起来仙剑奇侠传第一版那醉人的迷宫。
```
cd $GOPATH/src/github.com/hyperledger/fabric/devenv
cp Vagrantfile Vagrantfile.back
vim Vagrantfile
```
对比修改成:
```
config.vm.network :forwarded_port, guest: 7050, host: 7050 # fabric orderer service
config.vm.network :forwarded_port, guest: 7051, host: 7051 # fabric peer service
config.vm.network :forwarded_port, guest: 7053, host: 7053 # fabric peer event service
config.vm.network :forwarded_port, guest: 7054, host: 7054 # fabric-ca service
config.vm.network :forwarded_port, guest: 5984, host: 15984 # CouchDB service
### Below are probably missing.....
config.vm.network :forwarded_port, guest: 7056, host: 7056
config.vm.network :forwarded_port, guest: 7058, host: 7058
config.vm.network :forwarded_port, guest: 8051, host: 8051
config.vm.network :forwarded_port, guest: 8053, host: 8053
config.vm.network :forwarded_port, guest: 8054, host: 8054
config.vm.network :forwarded_port, guest: 8056, host: 8056
config.vm.network :forwarded_port, guest: 8058, host: 8058
### Below are probably missing.....
config.vm.synced_folder "..", "#{SRCMOUNT}"
config.vm.synced_folder "..", "/opt/gopath/src/github.com/hyperledger/fabric"
config.vm.synced_folder "/Users/kunpeng/IdeaProjects/fabric-sdk-java/src/test/fixture/sdkintegration", "/opt/gopath/src/github.com/hyperledger/fabric-sdk-java/src/test/fixture"
config.vm.synced_folder ENV.fetch('LOCALDEVDIR', ".."), "#{LOCALDEV}"
```
```
vagrant up
OR
vagrant provision
```
如果再次启动 vagrant up,需要注释掉 setup.sh相关内容
否则,镜像会被删除,需要重新编译
```
vi setup.sh
# NOTE: This must be done before the chown below
cd $GOPATH/src/github.com/hyperledger/fabric
# make clean gotools
```
进入 并编译docker镜像,需要翻墙状态下
不编译,也可以直接拉取镜像,重新打latest标签
```
vagrant ssh
cd $GOPATH/src/github.com/hyperledger/fabric
make gotools
make docker
cd $GOPATH/src/github/hyperledger/fabric-ca
make docker
rm -rf /var/hyperledger/*
cd $GOPATH/src/github.com/hyperledger/fabric/sdkintegration
docker-compose up -d --force-recreate
```
## 创建通道
configuration artifacts,重新生成
```
cd $GOPATH/src/github.com/hyperledger/fabric/common/configtx/tool
mv configtx.yaml configtx.yaml.bak
cp $GOPATH/src/github.com/hyperledger/fabric-sdk-java/sdkintegration/e2e-2Orgs/channel/configtx.yaml $GOPATH/src/github.com/hyperledger/fabric/common/configtx/tool
cd $GOPATH/src/github.com/hyperledger/fabric
make configtxgen
build/bin/configtxgen -outputCreateChannelTx foo.tx -profile TwoOrgs -channelID foo
build/bin/configtxgen -outputCreateChannelTx bar.tx -profile TwoOrgs -channelID bar
build/bin/configtxgen -outputBlock twoorgs.orderer.block -profile TwoOrgs
docker rm -f $(docker ps -aq)
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-java/src/test/fixture
docker-compose up -d --force-recreate
```
# 参考
- https://github.com/hyperledger/fabric-sdk-java