System test refinement
[anna.git] / example / diameter / launcher / DEPLOY.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6 SETUPS_DIR=../../../source/diameter/stack/setups
7 MSGDTD=../../../include/anna/diameter/codec/message.dtd
8 DCTDTD=../../../include/anna/diameter/stack/dictionary.dtd
9 BASE_PROT=commands_baseProtocol.xml
10 SERVICES=./resources/services_examples
11 STACK_EXAMPLES=./resources/stack_examples
12 SRVDTD=$SERVICES/services.dtd
13
14 # Executables in priority order:
15 EXEC_installed=/opt/bin/anna/example_diameter_launcher
16 EXECS=( $EXEC_installed ./release/example_diameter_launcher ./debug/example_diameter_launcher )
17
18 # Stack management
19 STACKMGMT_EXEC_installed=/opt/bin/anna/example_diameter_stackManagement
20 STACKMGMT_EXECS=( $STACKMGMT_EXEC_installed ../stackManagement/release/example_diameter_stackManagement ../stackManagement/debug/example_diameter_stackManagement )
21 :1
22
23 #############
24 # FUNCTIONS #
25 #############
26 _exit () {
27    echo
28    echo $1
29    echo
30    exit 1
31 }
32
33 usage () {
34   echo "Usage: $0 [deployment_type: a|b|f|s] [deployment_path]"
35   echo
36   echo "       deployment_type:"
37   echo "          a=advanced"
38   echo "          b=basic"
39   echo "          f=function test client"
40   echo "          s=system test client"
41   echo "       deployment_path:"
42   echo "          non-existent path directory."
43   echo
44   echo "       For example:"
45   echo "          $0 b $HOME/ADML/basicServer"
46   echo "          $0 b $HOME/ADML/MMSbalancer"
47   echo "          $0 f $HOME/ADML/tester"
48   echo "          $0 s $HOME/ADML/stress-client"
49   echo
50   exit 0
51 }
52  
53 # $1: deployment type
54 createRunScript () {
55   # Basic launcher 'run.sh' will be created at deployment configuration: 
56   [ "$1" = "b" ] && return
57
58   local other=
59   [ "$1" = "a" ] && other="--httpServer \`grep -v ^# .httpServer\`"
60   [ "$1" = "f" ] && ln -s ADML-launcher $EXE
61   [ "$1" = "s" ] && { other="--disableLogs"; ln -s ADML-launcher $EXE ; }
62
63   echo "Creating 'run.sh' script ..."
64
65   cat << EOF > run.sh
66 #!/bin/bash
67 cd \`dirname \$0\`
68 EXE=$EXE
69 STARTED=\`pgrep \$EXE$ 2>/dev/null\`
70 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
71 ./pre-start.sh
72 0> launcher.trace
73 rm -f counters/* test-reports/*
74 # Execution line:
75 ./\$EXE --services services.xml --cntDir counters --tmDir test-reports $other &
76 echo \$! > .pid
77 EOF
78
79   chmod a+x run.sh
80 }
81
82 createDictionaryPaths () {
83   echo "Creating dictionaries ..."
84
85   for i in stacks/*commands*xml
86   do
87     stacks/dependence.sh $i >/dev/null
88     stack=`basename $i`
89     if test "$stack" != "$BASE_PROT"
90     then
91       > .dictionary-${stack}
92       for j in `cat ${i}.dep`
93       do
94         echo -n "${j} " >> .dictionary-${stack}
95       done
96       echo "stacks/$BASE_PROT stacks/${stack}" >> .dictionary-${stack}
97     fi
98   done
99
100   # Create autonomous dictionaries:
101   mkdir stacks/autonomous
102   for i in `ls .dictionary-*`
103   do
104     name=$(echo $i | cut -d\- -f2)
105     $STACKMGMT_EXEC `cat $i` >/dev/null
106     mv result.xml stacks/autonomous/$name
107   done
108
109   # Cleanup:
110   rm -f stacks/*.dep
111   rm -f .dictionary-*
112   rm -f example_diameter_stackManagement.trace*
113
114   # Default:
115   ln -s stacks/autonomous/commands_qosControl.xml dictionary.xml
116 }
117
118 #############
119 # EXECUTION #
120 #############
121 cd `dirname $0`
122 echo
123 echo "---------------------------------------"
124 echo "Anna Diameter Launcher (ADML) deployment"
125 echo "---------------------------------------"
126 [ "$1" = "--help" -o "$1" = "-h" ] && usage
127 echo " (--help or -h for more info)"
128 echo
129 echo "Basic checkings ..."
130 # Launcher executable:
131 available=
132 for EXEC in ${EXECS[@]}; do
133   echo -n "Looking executable at '$EXEC' ... "
134   [ -x $EXEC ] && { available=yes ; echo "available !" ; break ; }
135   echo "not found"
136 done
137 [ -z "$available" ] && _exit "Anna Diameter Launcher (ADML) is not installed neither linked. See README.md (Install section)."
138 # Dictionary creation:
139 available=
140 for STACKMGMT_EXEC in ${STACKMGMT_EXECS[@]}; do
141   echo -n "Looking stack management executable at '$STACKMGMT_EXEC' ... "
142   [ -x $STACKMGMT_EXEC ] && { available=yes ; echo "available !" ; break ; }
143   echo "not found"
144 done
145 [ -z "$available" ] && _exit "Anna Diameter Stack Management Tool is not installed neither linked. See README.md (Install section)."
146 STACKMGMT_EXEC=`readlink -f $STACKMGMT_EXEC`
147
148 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
149
150 echo
151 if [ "$1" = "" ]
152 then
153   echo
154   echo "Deploy one of these versions:"
155   echo
156   echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
157   echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
158   echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
159   echo " (s)ystem test client:   special client for stress testing. Requires a server/s to perform the tests."
160   echo
161   echo "Input option [b]:"
162   read option
163   [ "$option" = "" ] && option=b
164 else
165   option=$1
166 fi
167
168 case $option in
169   a)
170     echo "Advanced deployment"
171     DEPLOYMENTS_DIR=deployments/advanced
172     DPATH_dflt=$HOME/ADML/advanced
173   ;;
174
175   b)
176     echo "Basic deployment"
177     DEPLOYMENTS_DIR=deployments/basic
178     DPATH_dflt=$HOME/ADML/basic
179   ;;
180
181   f)
182     echo "FT deployment"
183     DEPLOYMENTS_DIR=deployments/ft-client
184     DPATH_dflt=$HOME/ADML/ft-client
185   ;;
186
187   s)
188     echo "ST deployment"
189     DEPLOYMENTS_DIR=deployments/st-client
190     DPATH_dflt=$HOME/ADML/st-client
191   ;;
192
193   *)
194     _exit "Invalid deployment type '$option' !!"
195   ;;
196 esac
197
198 echo
199 if [ "$2" = "" ]
200 then
201   echo "Input deployment path [$DPATH_dflt]:"
202   read DPATH
203   [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
204 else
205   DPATH=$2
206 fi
207
208 [ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
209 EXE=ADML-`basename $DPATH`
210
211 echo "Copying to '$DPATH' ..."
212 mkdir -p $DPATH
213 mkdir -p $DPATH/stacks
214 mkdir -p $DPATH/DTDs
215 mkdir -p $DPATH/counters
216 mkdir -p $DPATH/test-reports
217 [ "$option" = "b" ] && mkdir -p $DPATH/services
218 if [ "$EXEC" = "$EXEC_installed" ]
219 then
220   ln -s $EXEC_installed $DPATH/ADML-launcher
221 else
222   cp $EXEC $DPATH/ADML-launcher
223 fi
224 cp -rL $DEPLOYMENTS_DIR/* $DPATH
225 cp $SETUPS_DIR/*xml $DPATH/stacks
226 cp $SETUPS_DIR/*sh $DPATH/stacks
227 cp $SETUPS_DIR/readme.txt $DPATH/stacks
228 mkdir $DPATH/stacks/other_examples
229 cp $STACK_EXAMPLES/* $DPATH/stacks/other_examples 
230 cp $MSGDTD $DPATH/DTDs
231 cp $DCTDTD $DPATH/DTDs
232 cp $SRVDTD $DPATH/DTDs
233 [ "$option" = "b" ] && cp $SERVICES/* $DPATH/services
234
235 echo "Preparing ..."
236 cd $DPATH
237 createRunScript $option
238 createDictionaryPaths
239 cd - >/dev/null
240
241 # Help:
242 echo
243 echo "Go to '$DPATH' and see README file"
244 echo
245 echo "Done!"
246 echo
247 echo
248
249