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