Hyperledger Composer Error Identity has not been r

2019-01-29 09:28发布

I am using hyperledger composer 0.16.0 and I want to persist data to database so that data can be used even after restart. so I am using loopback-connector-mongodb

Context

I have been following this tutorial and I am able to complete it.

I have setup fabric by issuing below steps

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

I issue a new identity, to an existing participant and I create a business card for this identity with the following command

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

Then, I import that business card via POST /wallet/import and I am able to call different REST API operations. After that, I stop the composer-rest-server and after a few minutes I start the composer-rest-server again with the commands 

cd ${HOME}/fabric-tools/
./startFabric.sh
docker start mongo rest

Issuing above command is not working so I am killing rest and then running it again by issuing below commands. Correct me if I am wrong

 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

Then, I authenticate to the REST API using the configured authentication mechanism (in my case passport-github strategy) and if I try to call one operation for REST API it throws a A business network card has not been specified error message, then I import the previous business card via POST /wallet/import getting a no content which is supposed to be correct.

Finally, when I try to call another REST API operation I get the following error:

{
  "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)"
  }
}

Expected Behavior

This should work even after restart

Actual Behavior

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.

Your Environment

* 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

My envvars.txt

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.cto

/**
 * 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
}

update:

After following what @R Thatcher told, When I issue command docker-compose start , it is starting fabric network but not the business network which is deployed earlier.

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

What is the correct way to bring it up?

1)When I try to start network by issuing below command

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) When I try to start docker container manually by issuing docker start container I still see it is not up.

1条回答
smile是对你的礼貌
2楼-- · 2019-01-29 09:51

The startFabric.sh does more than just start the Fabric - it actually removes your Containers and recreates new Containers from the Docker Images. The impact of this is that you lose all your data and your Business Network from the Fabric.

If you want to stop and start your Fabric after you have created it you need to change to the directory where the docker-compose.yml file is (in my case /home/rob/fabric-tools/fabric-scripts/hlfv1/composer)

Run docker-compose stop to stop the Fabric Containers and docker-compose start to restart where you left off. It is necessary to be in the correct folder before using the docker-compose command.

查看更多
登录 后发表回答