Hyperledger Composer Error Identity has not been registered once issued after restart - hyperledger-composer

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.

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.

Related

Single instance of a marathon application creates multiple docker containers

I have followed the sample json app cfg # https://mesosphere.github.io/marathon/docs/native-docker.html#bridged-networking-mode (modified instance count to 1 instead of 2) on the following local setup on my mbp running macos -
mesos-1.9.0 (downloaded source and built locally)
zookeeper-3.4.8 (packaged as a 3rd party framework with mesos-1.9.0 above)
marathon-1.5.0-96 (downloaded source from mesosphere github and built locally)
With a single instance of the bridged python webapp, I have observed that multiple docker containers are created.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
120bf164b817 python:3 "/bin/sh -c 'python3…" 20 seconds ago Up 19 seconds 0.0.0.0:31532->161/udp, 0.0.0.0:31531->8080/tcp mesos-eb3765bb-2c98-4cdf-8dbe-95ef33bdd58b
eee64f6d845b python:3 "/bin/sh -c 'python3…" About a minute ago Up About a minute 0.0.0.0:31733->161/udp, 0.0.0.0:31732->8080/tcp mesos-c17f8df0-f7a3-4352-a266-c2bf74c211fa
5dc28a7457e2 python:3 "/bin/sh -c 'python3…" 2 minutes ago Up 2 minutes 0.0.0.0:31811->161/udp, 0.0.0.0:31810->8080/tcp mesos-d44f0ff6-73a1-4609-bc9a-2a32330fc37e
I don't think that this the expected behavior and for a single marathon app instance, only 1 docker container should be created.
Please help me fix this if my observation is true or correct my understanding.
TIA.
I assume you can use UNIQUE operator of constraints.
https://mesosphere.github.io/marathon/docs/constraints.html
e.g:
$ curl -X POST -H "Content-type: application/json" localhost:8080/v2/apps -d '{
"id": "sleep-unique",
"cmd": "sleep 60",
"instances": 3,
"constraints": [["hostname", "UNIQUE"]]
}'

How to use run_input.py to debug a user’s input?

How can I debug a customer's input?
What is run_input.py?
How do I use it?
Check which integrations version the customer currently has.
in MT: run kubectl describe pods -n namespace | grep Image: in watchdog
in ST: run docker ps in the user’s machine
Create a docker in the right environment (watchdog prod / dev is a good choice) - this command creates a docker with the integrations version you choose. The docker will delete itself when you exit it
:
docker run --rm -ti -e 'VAULT_GITHUB_TOKEN=<your github token>' -v `pwd`/out:/out docker-registry-2-i.alooma.io/integrations:<user's commit id> bash
Run the debugging script - (location - scripts/run_input.py) :
to see the possible flags of the script, run pypy run_input.py -h
execution example:
pypy run_input.py -e prod -d gadventures-1 -i f0dd88a4-ee3b-4414-aa90-c21b323bf473 -s e05fd -k .kafka_dump -r .result_dump
if you don’t specify a state id, the script will run configure_tasks.

HyperLedger fabric chaincode not updated

I am trying to follow along this sample Hyperledger Fabric code: https://github.com/hyperledger/education/tree/master/LFS171x/fabric-material
Initially I replaced chaincode/tuna-app/tuna-chaincode.go with my go file chaincode/tuna-app/test.go. test.go had changes just in what we initialize in the ledger through its initLedger function call. It worked fine, with no changes required in tuna-app/.startFabric.sh.
Now when I again try to change the ledger through its initLedger function call, its not happening. Even if I comment the function itself, it still shows the old content of the ledger.
How do I update my chaincode with visible changes?
startFabric.sh contains the following code:
set -e
# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1
starttime=$(date +%s)
if [ ! -d ~/.hfc-key-store/ ]; then
mkdir ~/.hfc-key-store/
fi
# launch network; create channel and join peer to channel
cd ../basic-network
./start.sh
# Now launch the CLI container in order to install, instantiate chaincode
# and prime the ledger with our 10 tuna catches
docker-compose -f ./docker-compose.yml up -d cli
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" cli peer chaincode install -n tuna-app -v 1.0 -p github.com/test-app
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
sleep 10
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'
printf "\nTotal execution time : $(($(date +%s) - starttime)) secs ...\n\n"
printf "\nStart with the registerAdmin.js, then registerUser.js, then server.js\n\n"
I tried by adding the following line after peer chaincode instantiate :
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'
But it gives the following error:
Error: Chaincode version is not provided for upgrade
When I change upgrade statement to:
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin#org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"function":"initLedger","Args":[""]}'
Error changes to:
Error: Error endorsing chaincode: rpc error: code = Unknown desc = chaincode error (status: 500, message: version already exists for chaincode with name 'tuna-app')
To make the changes in the chaincode made reflect, following steps were taken:
1. Stop all the containers
docker stop $(docker ps -aq)
Delete all the containers
docker rm -f $(docker ps -aq)
Find the following image when you run docker images
One of the output will be this among the other hyperledger binary images.
REPOSITORY TAG, IMAGE ID, CREATED, SIZE: dev-peer0.org1.example.com-tuna-app-1.0-b58eb592ed6ced10f52cc063bda0c303a4272089a3f9a99000d921f94b9bae9b, latest, 0919d7c15f0a, 3 minutes ago, 172MB
Delete it using the following command:
docker rmi 0919d7c15f0a
Run the fabric again using ./startFabric.sh, npm install, node registerAdmin.js, node registerUser.js and node server.js. It should work
I would guess you alrwady have version 1.0 installed, thats why its complaining that it already exists. Try it with 1.1 or 2.0 by using -v 2.0 instead of -v 1.0.
It's pretty tricky once you miss the sequence.
As per my knowledge, deployment of a chaincode in HLF is a two step process.
Step 1. Transfer the source code into the peer ( each chaincode gets a chaincode id which approximately is a function of their name, path and version). This gets signed by your keys and transferred to the all the peers you have chosen as target. ( This step by the way, is called installation. )
Step 2. The source code is compiled, with all the vendor libs ( I'm talking about the GoLang chaincode version here, hoping that it would be same for the other ones too.). A docker image is built and a container gets formed with that binary. ( This is the part which is known as instantiation - which also becomes an Upgrade if it's already done earlier. )
In this process, the step 1 would want the chaincode to be unique. If you have installed once, then if you want to send it again, then make sure you have changed the version number to say abc-1.0 to abc-2.0. This will save you at Installation step.
Once your installation is successful, then it's the matter of when to call for an upgrade and when not. If you have run this container earlier, then right step is to upgrade.
Or the other way around is to do what you did. Clean up and start fresh - which works ok for development, but not for production - as your data goes "poof" with that clean up.
when developing chaincode on hyperledger fabric.
1: we have to remove chaincode docker image for testing each change.
For Example: name of install chaincode is mycc
#remove container
docker rm -f $(docker ps -aq)
#remove images
docker rmi mycc-0-container id or name
2: you can install chaincode just by changing its name like mycc is currently running then you have to change mycc1 and now you need to use mycc1 and perform your transactions.
For Example:
#Already install chaincode has named mycc
#following command will install same chaincode(updated) with chaincodeName
#mycc1
docker exec cli peer chaincode install -n mycc1 -v 0 -p github.com/sacc
Note: now you need to instantiate , invoke and query chaincode with name mycc1.

installing transmission on debian with docker, right trouble

I am a biginner with docker, I try to make my transmission container work!
First I am running on a debian 8.1.
To make things work I created this 2 folder:
mkdir -p /opt/docker/transmission/config
mkdir -p /opt/docker/transmission/downloads
after this I added the "good" right:
chown -R root:docker /opt/docker
chmod -R 775 /opt/docker
At the end I tried to create my docker by doing this:
docker run -d \
--net="host" \
--name="Transmission" \
-e USERNAME="root" \
-e PASSWORD="mdp" \
-v /opt/docker/transmission/config:/config \
-v /opt/docker/transmission/downloads:/downloads \
-v /etc/localtime:/etc/localtime:ro \
gfjardim/transmission
The command docker logs transmission gives:
Couldn't save temporary file "/config/resume/myfile.resume.tmp.hYhTPF": No such file or directory
I guessed that the folder resume in config was not created so I created it, but I didn't work.
The message in transmission GUI is:
unable to save resume file: permission denied
I cannot reproduce you errors using your commands. I suggest you delete your /opt/docker/transmission/ directory and then run the docker run command.
Docker will take care of creating those repositories.
I didn't find a solution for gfjardim/transmission container
But by changing container it worked directly.
I followed the dperson/transmission in the hub site, and it work perfectly.
Thanks for your help.

Could not find entity for dockerfile/elasticsearch

Im new to Docker and im having an issue.
Im trying to start the pblittle/docker-logstash container using this command:
sudo docker run -d -e LOGSTASH_CONFIG_URL=pathtomyconfig --link dockerfile/elasticsearch:es -p 9292:9292 -p 9200:9200 pblittle/docker-logstash
and i am getting the following error:
Error: Could not find entity for dockerfile/elasticsearch
If i do sudo docker ps is get the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0021bd567d95 dockerfile/elasticsearch:latest /elasticsearch/bin/e 7 minutes ago Up 7 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp cranky_meitner2
e900cbb758a5 dockerfile/redis:latest redis-server /etc/re 12 hours ago Up 7 minutes 0.0.0.0:6379->6379/tcp redis
592a4f8d97f2 dockerfile/redis:latest redis-server /etc/re 12 hours ago Up 7 minutes 6379/tcp cocky_thompson4
What the devil am i doing wrong? How can i work out what is going on?
You got the value for the --link option wrong. The --link option of the docker run command takes a container name or id as value followed by : followed by an alias (which can be whatever you want).
What you did wrong with --link dockerfile/elasticsearch:es is to pass in a Docker image name instead of a docker container name/id.
Firstly you need a running container for ElasticSearch:
sudo docker run -d -p 9300:9300 --name myelasticsearch dockerfile/elasticsearch
Then you can run your logstash container linking to the container named myelasticsearch:
sudo docker run -d -e LOGSTASH_CONFIG_URL=pathtomyconfig --link myelasticsearch:es -p 9292:9292 -p 9200:9200 pblittle/docker-logstash

Resources