Fix local server for multiple applications
[anna.git] / example / diameter / launcher / resources / rest_api / ct / ct.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6
7 REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
8 [ -z "$REPO_DIR" ] && { echo "You must execute under a valid git repository !" ; exit 1 ; }
9
10 SERVICES=${REPO_DIR}/example/diameter/launcher/resources/rest_api/ct/resources/servicesRxJson-request.json
11 ENDPOINT=http://localhost:8074
12 PORT=$(echo ${ENDPOINT} | cut -d: -f3)
13 SVC_NAME=anna-adml-http
14 # Entrypoint arguments (ft/st):
15 ADML_ARGUMENTS="--services services.xml --cntDir counters --tmDir tm --cntRecordPeriod 60000 --logStatisticSamples none --reconnectionPeriod 10000 --httpServer 0.0.0.0:8000"
16 #ADML_ARGUMENTS+=" --trace debug"
17
18 VARIANT=${1:-Release}
19
20 #############
21 # EXECUTION #
22 #############
23
24 echo
25 echo "Variant: ${VARIANT}"
26 echo "Remember usage: $0 [variant: <[Release]|Debug]>"
27 echo
28
29 cd $(dirname $0)
30
31 # Basic requirement:
32 nghttp --version 2>/dev/null
33 [ $? -ne 0 ] && { echo -e "\nThe HTTP2 client 'nghttp' is required. Install with: sudo apt install nghttp\n" ; exit 1 ; }
34 echo "Requirement found !"
35
36 echo
37 echo "Rebuild ADML HTTP service image (y/n) [n]:"
38 read opt
39 [ -z "${opt}" ] && opt=n
40 if [ "${opt}" = "y" ]
41 then
42   ${REPO_DIR}/tools/build-anna-adml-http ${VARIANT}
43 fi
44
45 version=$(${REPO_DIR}/tools/version)
46 cname=${SVC_NAME}
47 [ "${VARIANT}" = "Debug" ] && { version=${version}-debug ; cname=${cname}-debug ; }
48 echo "Restart ADML HTTP service image (version '${version}') (y/n) [y]:"
49 read opt
50 [ -z "${opt}" ] && opt=y
51 if [ "${opt}" = "y" ]
52 then
53   docker kill ${SVC_NAME} &>/dev/null
54   docker kill ${SVC_NAME}-debug &>/dev/null
55
56   cid=$(docker run --rm -d -p ${PORT}:${PORT} --name ${cname} anna-adml-http:${version} ${ADML_ARGUMENTS} >/dev/null)
57   [ $? -ne 0 ] && exit 1
58   echo "Container id: ${cid} (deployed as '${cname}')"
59 fi
60
61 echo
62 echo "Configuring services (${SERVICES}) ..."
63 sleep 4 # wait for docker running
64 nghttp -H ":method: POST" -d ${SERVICES} ${ENDPOINT}/services | tee .response.json | jq '.'
65 result=$(cat .response.json | jq -r '.["success"]')
66 rm .response.json
67 if [ "${result}" = "false" ]
68 then
69   echo
70   echo "Check if another ADML HTTP service (anna-adml-http*) has been started (port ${PORT} busy ?)"
71   exit 1
72 fi
73
74 echo
75 echo -n "Waiting for server-client connection ..."
76 while true
77 do
78   docker exec -it ${cname} bash -c "netstat -p \$(pgrep ADML) --numeric-ports | grep -w 3868 | grep -w ESTABLISHED" >/dev/null
79   [ $? -eq 0 ] && break
80   echo -n .
81   sleep 1
82 done
83 echo "Ready !"
84
85 echo
86 echo "Press ENTER to start component test, CTRL-C to abort ..."
87 read dummy
88
89 pytest
90