Update scripts and doc

pull/108/head
Baohua Yang 2017-09-27 15:38:00 +08:00
parent 1c874a84dc
commit 4ebaf86749
6 changed files with 22 additions and 309 deletions

View File

@ -1,4 +1,5 @@
KAFKA_ENABLED ?= false
COUCHDB_ENABLED ?= false
COMPOSE_FILE ?= "docker-compose-2orgs-4peers.yaml"
@ -6,22 +7,26 @@ ifeq ($(KAFKA_ENABLED),true)
COMPOSE_FILE="docker-compose-2orgs-4peers-kafka.yaml"
endif
ifeq ($(COUCHDB_ENABLED),true)
COMPOSE_FILE="docker-compose-2orgs-4peers-couchdb.yaml"
endif
COMPOSE_DEV_FILE="docker-compose-dev.yaml"
COMPOSE_COUCHDB_FILE="docker-compose-2orgs-4peers-couchdb.yaml"
all:
@echo "Run test with ${COMPOSE_FILE}"
@echo "Please make sure u have setup Docker and pulled images by 'make setup'."
sleep 2
make ready
make lscc qscc
make stop
make stop clean
ready:
ready: restart
@echo "Restart, init network and then do cc testing..."
make restart init
sleep 2
make init
sleep 3
make test_cc
@echo "Now the fabric network is ready to play"
@ -40,7 +45,7 @@ stop: # stop the fabric network
@echo "Stop the fabric network"
docker-compose -f ${COMPOSE_FILE} down # Stop a fabric network
restart: stop start
restart: stop clean start
################## Dev testing ################
dev:
@ -78,6 +83,7 @@ dev_init: # initialize the fabric network
dev_stop: # stop the fabric network for dev
@echo "Stop and clean the fabric dev network"
docker-compose -f ${COMPOSE_DEV_FILE} down
make clean
dev_restart: dev_stop dev_start
@ -90,41 +96,6 @@ dev_download: # download required images
dev_logs: # show dev logs
docker-compose -f ${COMPOSE_DEV_FILE} logs -f --tail 200
################## Couchdb testing ################
couch:
@echo "Please make sure u have setup Docker and pulled images by 'make setup'."
sleep 2
make couch_ready
make lscc qscc
make dev_stop
couch_ready:
@echo "Restart and init network with couchdb..."
make couch_restart couch_init
sleep 2
make test_cc
@echo "Now the fabric network is ready to play"
@echo "run 'make cli' to enter into the fabric-cli container."
@echo "run 'make stop' when done."
couch_start: # start fabric network with couchdb
@echo "Start a fabric network with couchdb"
docker-compose -f ${COMPOSE_COUCHDB_FILE} up -d
couch_init: # initialize the fabric network
@echo "Install and instantiate cc example02 on the fabric dev network"
docker exec -it fabric-cli bash -c "cd /tmp; bash scripts/initialize_all.sh"
couch_stop: # stop the fabric network with couchdb
@echo "Stop the fabric network with 1 peer with couchdb"
docker-compose -f ${COMPOSE_COUCHDB_FILE} down
couch_restart: couch_stop couch_start
################## Chaincode testing operations ################
test_cc: # test user chaincode on all peers
@echo "Invoke and query cc example02 on all peers"
@ -147,9 +118,9 @@ setup: # setup the environment
bash scripts/download_images.sh # Pull required Docker images
clean: # clean up containers
@echo "Clean all containers and cc images"
docker rm -f `docker ps -qa`
docker rmi $(docker images | awk '$1 ~ /dev-peer/ { print $3}')
@echo "Clean all containers and fabric cc images"
@-docker rm -f `docker ps -qa`
@-docker rmi $$(docker images | awk '$$1 ~ /dev-peer/ { print $$3}')
clean_env: # clean up environment
@echo "Clean all images and containers"

View File

@ -1,247 +0,0 @@
#!/bin/bash
echo
echo " ____ _____ _ ____ _____ _____ ____ _____ "
echo "/ ___| |_ _| / \ | _ \ |_ _| | ____| |___ \ | ____|"
echo "\___ \ | | / _ \ | |_) | | | _____ | _| __) | | _| "
echo " ___) | | | / ___ \ | _ < | | |_____| | |___ / __/ | |___ "
echo "|____/ |_| /_/ \_\ |_| \_\ |_| |_____| |_____| |_____|"
echo
CHANNEL_NAME="$1"
: ${CHANNEL_NAME:="testchannel"}
: ${TIMEOUT:="60"}
COUNTER=1
MAX_RETRY=5
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/cacerts/ca.example.com-cert.pem
echo "Channel name : "$CHANNEL_NAME
verifyResult () {
if [ $1 -ne 0 ] ; then
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
echo
exit 1
fi
}
setGlobals () {
if [ $1 -eq 0 -o $1 -eq 1 ] ; then
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
if [ $1 -eq 0 ]; then
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
else
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
fi
elif [ $1 -eq 4 ] ; then
CORE_PEER_LOCALMSPID="Org3MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
CORE_PEER_ADDRESS=peer0.org3.example.com:7051
else
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
if [ $1 -eq 2 ]; then
CORE_PEER_ADDRESS=peer0.org2.example.com:7051
else
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
fi
fi
env |grep CORE
}
createChannel() {
setGlobals 0
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./peer/channel-artifacts/channel.tx >&log.txt
else
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./peer/channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Channel creation failed"
echo "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== "
echo
}
updateAnchorPeers() {
PEER=$1
setGlobals $PEER
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./peer/channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx >&log.txt
else
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./peer/channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Anchor peer update failed"
echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== "
echo
}
## Sometimes Join takes time hence RETRY atleast for 5 times
joinWithRetry () {
peer channel join -b $CHANNEL_NAME.block >&log.txt
res=$?
cat log.txt
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
COUNTER=` expr $COUNTER + 1`
echo "PEER$1 failed to join the channel, Retry after 2 seconds"
sleep 2
joinWithRetry $1
else
COUNTER=1
fi
verifyResult $res "After $MAX_RETRY attempts, PEER$ch has failed to Join the Channel"
}
joinChannel () {
for ch in 0 1 2 3 4; do
setGlobals $ch
joinWithRetry $ch
echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== "
sleep 2
echo
done
}
installChaincode () {
PEER=$1
setGlobals $PEER
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txt
res=$?
cat log.txt
verifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed"
echo "===================== Chaincode is installed on remote peer PEER$PEER ===================== "
echo
}
instantiateChaincode () {
PEER=$1
setGlobals $PEER
# while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful),
# lets supply it directly as we know it using the "-o" option
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer chaincode instantiate -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')" >&log.txt
else
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')" >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Chaincode instantiation on PEER$PEER on channel '$CHANNEL_NAME' failed"
echo "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
echo
}
chaincodeQuery () {
PEER=$1
echo "===================== Querying on PEER$PEER on channel '$CHANNEL_NAME'... ===================== "
setGlobals $PEER
local rc=1
local starttime=$(date +%s)
# continue to poll
# we either get a successful response, or reach TIMEOUT
while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0
do
sleep 3
echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs"
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
test $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')
test "$VALUE" = "$2" && let rc=0
done
echo
cat log.txt
if test $rc -eq 0 ; then
echo "===================== Query on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
else
echo "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!"
echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="
echo
exit 1
fi
}
chaincodeInvoke () {
PEER=$1
setGlobals $PEER
# while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful),
# lets supply it directly as we know it using the "-o" option
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}' >&log.txt
else
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}' >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Invoke execution on PEER$PEER failed "
echo "===================== Invoke transaction on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "
echo
}
## Create channel
echo "Creating channel..."
createChannel
## Join all the peers to the channel
echo "Having all peers join the channel..."
joinChannel
## Set the anchor peers for each org in the channel
echo "Updating anchor peers using peer0/org1(peer0) for org1..."
updateAnchorPeers 0
echo "Updating anchor peers using peer0/org2(peer2) for org2..."
updateAnchorPeers 2
updateAnchorPeers 4
## Install chaincode on Peer0/Org1 and Peer0/Org2
echo "Installing chaincode on peer0/org1..."
installChaincode 0
echo "Install chaincode on peer0/org2.."
installChaincode 2
echo "Install chaincode on peer0/org3.."
installChaincode 4
#Instantiate chaincode on Peer0/Org2
echo "Instantiating chaincode on peer0/org2..."
instantiateChaincode 2
#Query on chaincode on Peer0/Org1
echo "Querying chaincode on peer0/org1..."
chaincodeQuery 0 100
#Invoke on chaincode on Peer0/Org1
echo "Sending invoke transaction on peer0/org1..."
chaincodeInvoke 0
## Install chaincode on Peer1/Org2
echo "Installing chaincode on peer1/org2..."
installChaincode 3
#Query on chaincode on Peer0/Org3, check if the result is 90
echo "Querying chaincode on org2/peer1..."
chaincodeQuery 4 90
echo
echo "===================== All GOOD, End-2-End execution completed ===================== "
echo
echo
echo " _____ _ _ ____ _____ ____ _____ "
echo "| ____| | \ | | | _ \ | ____| |___ \ | ____|"
echo "| _| | \| | | | | | _____ | _| __) | | _| "
echo "| |___ | |\ | | |_| | |_____| | |___ / __/ | |___ "
echo "|_____| |_| \_| |____/ |_____| |_____| |_____|"
echo
exit 0

View File

@ -1,24 +1,13 @@
[WIP]
## Start a network base on kafka
### Quick testing with kafka
```bash
$ cd ~/docker-compose-files/tree/master/hyperledger/1.0/kafka
$ docker-compose -f orderer-kafka.yaml up (-d)
$ KAFKA_ENABLED=true make
```
When the fabric-network fully started, it takes about 15-20s.
When the fabric-network fully started, it takes about 30~60s to finish all the test.
## Test chaincode
## Generate crypto-config and channel-artifacts
```bash
$ docker exec -it fabric-cli bash
$ bash ./scripts/initialize.sh # initialize the fabric network
$ bash ./scripts/test_4peers.sh
$ make gen_kafka
```
>(Optional) If you want to use official images, you can run the following command first
>
> ```bash
> $ cd ~/docker-compose-files/tree/master/hyperledger/1.0
> $ bash ./scripts/download_images.sh
> ```

View File

@ -99,8 +99,8 @@ channelCreate() {
cat log.txt
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
COUNTER=` expr $COUNTER + 1`
echo_b "PEER$1 failed to create the channel, Retry after 2 seconds"
sleep 2
echo_b "PEER$1 failed to create the channel, Retry after 3 seconds"
sleep 3
channelCreate
else
COUNTER=1