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-12-29 22:29:56 +08:00
|
|
|
[ -f ${BLOCK_FILE}.json ] || configtxlatorDecode "common.Block" ${BLOCK_FILE} ${BLOCK_FILE}.json
|
|
|
|
decode_result=$?
|
|
|
|
#echo_b "Parse payload..."
|
|
|
|
#[ ${decode_result} -eq 0 ] && jq "$PAYLOAD_PATH" ${BLOCK_FILE}.json > ${BLOCK_FILE}_payload.json
|
2017-11-02 10:19:05 +08:00
|
|
|
done
|
|
|
|
|
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"
|