我正在使用hyperledger composer 0.16.0,我想将数据保存到数据库,以便即使重启后也可以使用数据。所以我正在使用loopback-connector-mongodb
我一直在关注this教程,我可以完成它。
我通过发布以下步骤来设置结构
cd ${HOME}/fabric-tools/
./stopFabric.sh
./teardownFabric.sh
./downloadFabric.sh
./startFabric.sh
cd ${HOME}/tmt/Profile/
composer card create -p connection.json -u PeerAdmin -c Admin@org1.example.com-cert.pem -k 114aab0e76bf0c78308f89efc4b8c9423e31568da0c340ca187a9b17aa9a4457_sk -r PeerAdmin -r ChannelAdmin
composer card import -f PeerAdmin@fabric-network.card
composer runtime install -c PeerAdmin@fabric-network -n dam-network
cd ../dam-network/
# added model.cto file below
composer archive create -t dir -n .
composer network start -c PeerAdmin@fabric-network -a dam-network@0.0.1.bna -A admin -S adminpw
composer card import -f admin@dam-network.card
composer network ping -c admin@dam-network
chmod -R 777 ${HOME}/.composer
## onetime setup using npm install -g loopback-connector-mongodb
docker run -d --name mongo --network composer_default -p 27017:27017 mongo
cd ${HOME}/tmt/docker
docker build -t myorg/my-composer-rest-server .
#Which is attached below
source envvars.txt
docker run \
-d \
-e COMPOSER_CARD=${COMPOSER_CARD} \
-e COMPOSER_NAMESPACES=${COMPOSER_NAMESPACES} \
-e COMPOSER_AUTHENTICATION=${COMPOSER_AUTHENTICATION} \
-e COMPOSER_MULTIUSER=${COMPOSER_MULTIUSER} \
-e COMPOSER_PROVIDERS="${COMPOSER_PROVIDERS}" \
-e COMPOSER_DATASOURCES="${COMPOSER_DATASOURCES}" \
-v ~/.composer:/home/composer/.composer \
--name rest \
--network composer_default \
-p 3000:3000 \
myorg/my-composer-rest-server
我向现有参与者发出新身份,并使用以下命令为此身份创建名片
composer participant add -c admin@dam-network -d ' {"$class": "com.asset.tmt.User","userId": "tmtadmin","email": "tmtadmin@gmail.com","firstName": "TMT","lastName": "Admin","userGroup": "peerAdmin"} '
composer identity issue -u tmtadmin -a com.asset.tmt.User#tmtadmin -c admin@dam-network
composer card import -f tmtadmin@dam-network.card
然后,我通过POST / wallet / import导入该名片,我可以调用不同的REST API操作。之后,我停止了composer-rest-server,几分钟后我再次使用命令启动composer-rest-server
cd ${HOME}/fabric-tools/
./startFabric.sh
docker start mongo rest
发出上述命令不起作用,所以我通过发出以下命令来杀死休息然后再次运行它。如果我错了,请纠正我
docker stop rest
docker rm rest
docker run \
-d \
-e COMPOSER_CARD=${COMPOSER_CARD} \
-e COMPOSER_NAMESPACES=${COMPOSER_NAMESPACES} \
-e COMPOSER_AUTHENTICATION=${COMPOSER_AUTHENTICATION} \
-e COMPOSER_MULTIUSER=${COMPOSER_MULTIUSER} \
-e COMPOSER_PROVIDERS="${COMPOSER_PROVIDERS}" \
-e COMPOSER_DATASOURCES="${COMPOSER_DATASOURCES}" \
-v ~/.composer:/home/composer/.composer \
--name rest \
--network composer_default \
-p 3000:3000 \
myorg/my-composer-rest-server
然后,我使用配置的身份验证机制(在我的案例中,使用passport-github策略)对REST API进行身份验证,如果我尝试为REST API调用一个操作,则会抛出一个尚未指定的业务网卡错误消息,然后我通过POST / wallet / import导入以前的名片,得到一个没有内容,这应该是正确的。
最后,当我尝试调用另一个REST API操作时,我收到以下错误:
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Enrollment failed with errors [[{\"code\":400,\"message\":\"Authorization failure\"}]]",
"stack": "Error: Error trying login and get user Context. Error: Error trying to enroll user or load channel configuration. Error: Enrollment failed with errors [[{\"code\":400,\"message\":\"Authorization failure\"}]]\n at client.getUserContext.then.then.catch (/home/composer/.npm-global/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:305:34)\n at <anonymous>\n at process._tickDomainCallback (internal/process/next_tick.js:228:7)"
}
}
This should work even after restart
This is the main issue, I don't know why my identity is not being recognized by the REST API if I used it previously to call some operations.
* Version used: 0.16.0
* Environment name and version (e.g. Chrome 39, node.js 5.4): chrome latest and node.js 8.9.1
* Operating System and version (desktop or mobile): Ubuntu desktop
COMPOSER_CARD=admin@dam-network
COMPOSER_NAMESPACES=never
COMPOSER_AUTHENTICATION=true
COMPOSER_MULTIUSER=true
COMPOSER_PROVIDERS='{
"github": {
"provider": "github",
"module": "passport-github",
"clientID": "xxxxxxxxxxxxx",
"clientSecret": "xxxxxxxxxxxxxxxxxxxxx",
"authPath": "/auth/github",
"callbackURL": "/auth/github/callback",
"successRedirect": "/",
"failureRedirect": "/"
}
}'
COMPOSER_DATASOURCES='{
"db": {
"name": "db",
"connector": "mongodb",
"host": "10.142.0.10"
}
}'
/**
* Model Definitions
*/
namespace com.asset.tmt
participant User identified by userId {
o String userId
o String email
o String firstName
o String lastName
o String userGroup
}
asset Asset identified by assetId {
o String assetId
o String name
o String creationDate
o String expiryDate
}
transaction ChangeAssetValue {
o String expiryDate
o String assetId
o String userId
}
更新
在遵循@R撒切尔所说的内容之后,当我发出命令docker-compose start
时,它正在启动结构网络,但不是之前部署的业务网络。
tmt@blockchain:~/tmt/dam-network$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a6833bd7d3a myorg/my-composer-rest-server "pm2-docker compos..." 17 hours ago Exited (0) 10 hours ago rest
9bffab63a048 mongo "docker-entrypoint..." 17 hours ago Exited (0) 10 hours ago mongo
5bafb4dd5662 dev-peer0.org1.example.com-dam-network-0.16.0-4a77c4c8eabde9e440464f91b1655a48c6c5e0dac908e36a7b437034152bf141 "chaincode -peer.a..." 17 hours ago Exited (0) 4 minutes ago dev-peer0.org1.example.com-dam-network-0.16.0
4bfc67f13811 hyperledger/fabric-peer:x86_64-1.0.4 "peer node start -..." 17 hours ago Up 6 minutes 0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp peer0.org1.example.com
762a42bc0eb7 hyperledger/fabric-orderer:x86_64-1.0.4 "orderer" 17 hours ago Up 6 minutes 0.0.0.0:7050->7050/tcp orderer.example.com
49c925a8cc43 hyperledger/fabric-couchdb:x86_64-1.0.4 "tini -- /docker-e..." 17 hours ago Up 6 minutes 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp couchdb
cee51891308f hyperledger/fabric-ca:x86_64-1.0.4 "sh -c 'fabric-ca-..." 17 hours ago Up 6 minutes 0.0.0.0:7054->7054/tcp ca.org1.example.com
提出这个问题的正确方法是什么?
1)当我尝试通过发出以下命令启动网络时
tmt@blockchain:~/tmt/dam-network$ composer network start -c PeerAdmin@fabric-network -a dam-network@0.0.1.bna -A admin -S adminpw
Starting business network from archive: dam-network@0.0.1.bna
Business network definition:
Identifier: dam-network@0.0.1
Description: Blockchain dam integration
Processing these Network Admins:
userName: admin
✖ Starting business network definition. This may take a minute...
Error: Error trying to instantiate composer runtime. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: chaincode error (status: 500, message: chaincode exists dam-network)
Command failed
2)当我尝试通过发出docker start容器手动启动docker容器时,我仍然看到它没有启动。
答案 0 :(得分:2)
startFabric.sh
不仅仅是启动Fabric - 它实际上会删除容器并从Docker Images重新创建新容器。这样做的影响是您从Fabric中丢失了所有数据和业务网络。
如果您想在创建Fabric后停止并启动Fabric,则需要切换到docker-compose.yml
文件所在的目录(在我的情况下为/home/rob/fabric-tools/fabric-scripts/hlfv1/composer
)
运行docker-compose stop
以停止Fabric容器,并docker-compose start
从您停止的位置重新启动。在使用docker-compose命令之前,必须在正确的文件夹中。