docker-compose-files/hyperledger_fabric/v1.0.5/scripts/test_configtxlator.sh

66 lines
2.2 KiB
Bash
Raw Normal View History

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