diff --git a/first-network/byfn.sh b/first-network/byfn.sh index 04436ed91e..ffcc5392bc 100755 --- a/first-network/byfn.sh +++ b/first-network/byfn.sh @@ -34,7 +34,7 @@ export FABRIC_CFG_PATH=${PWD} # Print the usage message function printHelp () { echo "Usage: " - echo " byfn.sh -m up|down|restart|generate [-c ] [-t ]" + echo " byfn.sh -m up|down|restart|generate [-c ] [-t ] [-d ] " echo " byfn.sh -h|--help (print this message)" echo " -m - one of 'up', 'down', 'restart' or 'generate'" echo " - 'up' - bring up the network with docker-compose up" @@ -43,6 +43,7 @@ function printHelp () { echo " - 'generate' - generate required certificates and genesis block" echo " -c - channel name to use (defaults to \"mychannel\")" echo " -t - CLI timeout duration in microseconds (defaults to 10000)" + echo " -d - delay duration in seconds (defaults to 3)" echo echo "Typically, one would first generate the required certificates and " echo "genesis block, then bring up the network. e.g.:" @@ -106,7 +107,7 @@ function networkUp () { replacePrivateKey generateChannelArtifacts fi - CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1 + CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=$CLI_TIMEOUT DELAY=$CLI_DELAY docker-compose -f $COMPOSE_FILE up -d 2>&1 if [ $? -ne 0 ]; then echo "ERROR !!!! Unable to start network" docker logs -f cli @@ -295,13 +296,15 @@ OS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/window # timeout duration - the duration the CLI should wait for a response from # another container before giving up CLI_TIMEOUT=10000 +#default for delay +CLI_DELAY=3 # channel name defaults to "mychannel" CHANNEL_NAME="mychannel" # use this as the default docker-compose yaml definition COMPOSE_FILE=docker-compose-cli.yaml # Parse commandline args -while getopts "h?m:c:t:" opt; do +while getopts "h?m:c:t:d:" opt; do case "$opt" in h|\?) printHelp @@ -313,6 +316,8 @@ while getopts "h?m:c:t:" opt; do ;; t) CLI_TIMEOUT=$OPTARG ;; + d) CLI_DELAY=$OPTARG + ;; esac done diff --git a/first-network/docker-compose-cli.yaml b/first-network/docker-compose-cli.yaml index 28e4b66eb4..25e64800f1 100644 --- a/first-network/docker-compose-cli.yaml +++ b/first-network/docker-compose-cli.yaml @@ -67,7 +67,7 @@ services: - 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 working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer - command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT' + command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME} ${DELAY}; sleep $TIMEOUT' volumes: - /var/run/:/host/var/run/ - ./../chaincode/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go diff --git a/first-network/scripts/script.sh b/first-network/scripts/script.sh index a49fbb73ff..43a308ed3d 100755 --- a/first-network/scripts/script.sh +++ b/first-network/scripts/script.sh @@ -10,6 +10,7 @@ echo echo "Build your first network (BYFN) end-to-end test" echo CHANNEL_NAME="$1" +DELAY="$2" : ${CHANNEL_NAME:="mychannel"} : ${TIMEOUT:="60"} COUNTER=1 @@ -82,6 +83,7 @@ updateAnchorPeers() { cat log.txt verifyResult $res "Anchor peer update failed" echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== " + sleep $DELAY echo } @@ -93,7 +95,7 @@ joinWithRetry () { 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 + sleep $DELAY joinWithRetry $1 else COUNTER=1 @@ -106,7 +108,7 @@ joinChannel () { setGlobals $ch joinWithRetry $ch echo "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== " - sleep 2 + sleep $DELAY echo done } @@ -150,7 +152,7 @@ chaincodeQuery () { # we either get a successful response, or reach TIMEOUT while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0 do - sleep 3 + sleep $DELAY 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}')