3 # Script to configure consul with json configuration files with 'localhost' urls. This
4 # is needed when running the simulator as as a stand-alone app or via a dfc container in 'host' network mode.
5 # Assuming the input json files hostnames for MR and DR simulators are given as 'mrsim'/'drsim'
6 # See available consul files in the consul dir
7 # The script stores a json config for 'dfc_app'<dfc-instance-id>' if arg 'app' is given.
8 # And for 'dfc_app'<dfc-instance-id>':dmaap' if arg 'dmaap' is given.
9 # Instance id shall be and integer in the range 0..5
11 . ../common/test_env.sh
14 echo "Script needs three args, app|dmaap <dfc-instance-id> <json-file-path>"
18 if [ $2 -lt 0 ] || [ $2 -gt $DFC_MAX_IDX ]; then
19 __print_err "dfc-instance-id should be 0.."$DFC_MAX_IDX
23 __print_err "json file does not extis: "$3
27 if [ $1 == "app" ]; then
28 appname=$DFC_APP_BASE$2
29 echo "Replacing 'mrsim' with 'localhost' in json app config for consul"
30 sed 's/mrsim/localhost/g' $3 > .tmp_file.json
31 elif [ $1 == "dmaap" ]; then
32 appname=$DFC_APP_BASE$2":dmaap"
33 echo "Replacing 'drsim' with 'localhost' in json dmaap config for consul"
34 sed 's/drsim/localhost/g' $3 > .tmp_file.json
36 __print_err "config type should be 'app' or 'dmaap'"
40 echo "Configuring consul for " $appname " from " $3
41 curl -s http://127.0.0.1:${CONSUL_PORT}/v1/kv/${appname}?dc=dc1 -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Requested-With: XMLHttpRequest' --data-binary "@"$tmp_file.json >/dev/null