2
0

test_configtxlator.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # Demo to use configtxlator to modify orderer config
  3. # Usage: bash test_configtxlator solo|kafka
  4. # Configtxlator APIs:
  5. # Json -> ProtoBuf: http://$SERVER:$PORT/protolator/encode/<message.Name>
  6. # ProtoBuf -> Json: http://$SERVER:$PORT/protolator/decode/<message.Name>
  7. # Compute Update: http://$SERVER:$PORT/configtxlator/compute/update-from-configs
  8. # <message.Name> could be: common.Block, common.Envelope, common.ConfigEnvelope, common.ConfigUpdateEnvelope, common.Config, common.ConfigUpdate
  9. # More details about configtxlator, see http://hlf.readthedocs.io/en/latest/configtxlator.html
  10. if [ -f ./func.sh ]; then
  11. source ./func.sh
  12. elif [ -f scripts/func.sh ]; then
  13. source scripts/func.sh
  14. fi
  15. [ $# -ne 1 ] && echo_r "Usage: bash test_configtxlator solo|kafka" && exit 1
  16. MODE=$1
  17. pushd $MODE/${CHANNEL_ARTIFACTS}
  18. # Must run `make gen_config` to generate config files first
  19. echo_b "Clean potential existing container $CTL_CONTAINER"
  20. [ "$(docker ps -a | grep $CTL_CONTAINER)" ] && docker rm -f $CTL_CONTAINER
  21. echo_b "Start configtxlator service in background (listen on port 7059)"
  22. docker run \
  23. -d -it \
  24. --name ${CTL_CONTAINER} \
  25. -p 127.0.0.1:7059:7059 \
  26. ${CTL_IMG} \
  27. configtxlator start --port=7059
  28. sleep 1
  29. echo_b "Convert all config block files into json"
  30. for BLOCK_FILE in *.block; do
  31. if [ -f ${BLOCK_FILE} ]; then
  32. configtxlatorDecode "common.Block" ${BLOCK_FILE} ${BLOCK_FILE}.json
  33. decode_result=$?
  34. echo_b "Parse payload..."
  35. [ ${decode_result} -eq 0 ] && jq "$PAYLOAD_PATH" ${BLOCK_FILE}.json > ${BLOCK_FILE}_payload.json
  36. fi
  37. done
  38. echo_b "Update the content of orderer genesis file"
  39. if [ -f ${ORDERER_GENESIS} ]; then
  40. echo_b "Checking existing Orderer.BatchSize.max_message_count in the genesis json"
  41. jq "$MAX_BATCH_SIZE_PATH" ${ORDERER_GENESIS_JSON}
  42. echo_b "Creating new genesis json with updated Orderer.BatchSize.max_message_count"
  43. jq "$MAX_BATCH_SIZE_PATH=20" ${ORDERER_GENESIS_JSON} > ${ORDERER_GENESIS_UPDATED_JSON}
  44. echo_b "Re-Encoding the orderer genesis json to block"
  45. configtxlatorEncode "common.Block" ${ORDERER_GENESIS_UPDATED_JSON} ${ORDERER_GENESIS_UPDATED_BLOCK}
  46. fi
  47. echo_b "Stop configtxlator service"
  48. docker rm -f $CTL_CONTAINER
  49. echo_g "Test configtxlator for $MODE Passed"