Implement dynamic procedure at REST interface
[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 EXTRA_ARGUMENTS= # default is ft (function test: debug traces and traffic logs)
16
17 VARIANT=${1:-Release}
18
19 #############
20 # EXECUTION #
21 #############
22
23 echo
24 echo "Variant: ${VARIANT}"
25 echo "Remember usage: $0 [variant: <[Release]|Debug]>"
26 echo
27
28 cd $(dirname $0)
29
30 # Basic requirement:
31 nghttp --version 2>/dev/null
32 [ $? -ne 0 ] && { echo -e "\nThe HTTP2 client 'nghttp' is required. Install with: sudo apt install nghttp\n" ; exit 1 ; }
33 echo "Requirement found !"
34
35 echo
36 echo "Rebuild ADML HTTP service image (y/n) [y]:"
37 read opt
38 [ -z "${opt}" ] && opt=y
39 if [ "${opt}" = "y" ]
40 then
41   ${REPO_DIR}/tools/build-anna-adml-http ${VARIANT}
42 fi
43
44 version=$(${REPO_DIR}/tools/version)
45 cname=${SVC_NAME}
46 [ "${VARIANT}" = "Debug" ] && { version=${version}-debug ; cname=${cname}-debug ; }
47 echo "Restart ADML HTTP service image (version '${version}') (y/n) [y]:"
48 read opt
49 [ -z "${opt}" ] && opt=y
50 if [ "${opt}" = "y" ]
51 then
52   docker kill ${SVC_NAME} &>/dev/null
53   docker kill ${SVC_NAME}-debug &>/dev/null
54   cid=$(docker run --rm -d -p ${PORT}:${PORT} --name ${cname} anna-adml-http:${version} ${EXTRA_ARGUMENTS} >/dev/null)
55   [ $? -ne 0 ] && exit 1
56   echo "Container id: ${cid} (deployed as '${cname}')"
57 fi
58
59 echo
60 echo "Configuring services (${SERVICES}) ..."
61 sleep 4 # wait for docker running
62 nghttp -H ":method: POST" -d ${SERVICES} ${ENDPOINT}/services | tee .response.json | jq '.'
63 result=$(cat .response.json | jq -r '.["success"]')
64 rm .response.json
65 if [ "${result}" = "false" ]
66 then
67   echo
68   echo "Check if another ADML HTTP service (anna-adml-http*) has been started (port ${PORT} busy ?)"
69   exit 1
70 fi
71
72 echo
73 echo -n "Waiting for server-client connection ..."
74 while true
75 do
76   docker exec -it ${cname} bash -c "netstat -p \$(pgrep ADML) --numeric-ports | grep -w 3868 | grep -w ESTABLISHED" >/dev/null
77   [ $? -eq 0 ] && break
78   echo -n .
79   sleep 1
80 done
81 echo "Ready !"
82
83 echo
84 echo "Press ENTER to start component test, CTRL-C to abort ..."
85 read dummy
86
87 pytest
88