a3492b93dc272ba214d13aaf7c4efb96892a289e
[integration.git] / test / mocks / datafilecollector-testharness / simulator-group / consul_config.sh
1 #!/bin/bash
2
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
10
11 . ../common/test_env.sh
12
13 if [ $# != 3 ]; then
14         echo "Script needs three args, app|dmaap <dfc-instance-id> <json-file-path>"
15         exit 1
16 fi
17
18 if [ $2 -lt 0 ] || [ $2 -gt $DFC_MAX_IDX ]; then
19         __print_err "dfc-instance-id should be 0.."$DFC_MAX_IDX
20         exit 1
21 fi
22 if ! [ -f $3 ]; then
23         __print_err "json file does not extis: "$3
24         exit 1
25 fi
26
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
35 else
36         __print_err "config type should be 'app' or 'dmaap'"
37         exit 1
38 fi
39
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
42
43 echo "done"