Merge "Added the Hbase Client installation on Controller VM"
[releng/builder.git] / jjb / integration / include-raw-integration-configure-clustering.sh
1 echo "##################################################"
2 echo "## include-raw-integration-configure-clustering ##"
3 echo "##################################################"
4
5 #  this script configures replication on a single ODL controller.
6 #  files touched are akka.conf modules-shards.conf
7
8
9
10 echo "##################################"
11 echo "##  Loop through controller IPs  #"
12 echo "##################################"
13
14 declare CONTROLLERIPS=($(cat slave_addresses.txt | grep CONTROLLER | awk -F = '{print $2}'))
15 declare -p CONTROLLERIPS
16
17 echo "######################################################"
18 echo "##  include-raw-integration-configuration_functions ##"
19 echo "######################################################"
20
21 # writes the  functions needed for configuring clustering to
22 # configuration-functions  in the  WORKSPACE
23 env
24
25 set -x
26
27 cat > ${WORKSPACE}/configuration-functions  <<EOF
28
29
30 function getslaveaddresses
31 {
32    declare -a CONTROLLERIPS=($CONTROLLER0, $CONTROLLER1, $CONTROLLER2)
33    declare -p CONTROLLERIPS
34    export CONTROLLERIPS
35 }
36
37
38 function editakkaconf
39 {
40 set -x
41  echo "#####  editakkaconf #####"
42  echo "The number of args recieved \${#} \${1} \${2}"
43 # Expects 2 argument \$LOOPINCR and IPADDRESS of  controller.
44 # \$CONTROLLERIPS[] is set by getslaveaddresses().
45 # \$BUNDLEFOLDER is set in "include-raw-integration-deploy-controller.sh"
46 # A single copy of akka.conf is assumed to be available in \$BUNDLEFOLDER
47
48 if [ -z ${BUNDLEFOLDER} ] || [ -f ${BUNDLEFOLDER} ]; then
49     echo "WARNING: Location of ODL BUNDLEFOLDER:\$BUNDLEFOLDER is not defined"
50
51 fi
52 if [ -z \${CONTROLLERIPS} ]; then
53     echo "WARNING: Cluster IPs not known due to UNBOUND varible: CONTROLLERIPS[@] does not exist"
54     echo "WARNING: Calling getslaveaddresses to populate  CONTROLLERIPS[@]"
55     getslaveaddresses
56 fi
57
58
59
60
61 ############################
62 # BEGIN function variables #
63 ############################
64
65   # make local copies of global varibles because globals may produce interesting bugs.
66   echo "# set the IP of the current controller."
67
68   local LOOPINCR=\$1
69   local CURRENTCONTROLLERIPADDR=\$2
70   local AKKACONF=\$(find /tmp/${BUNDLEFOLDER} -name akka.conf)
71
72   # used to verify IP address of current VM
73   local HOSTIPADDR0=\$(/sbin/ifconfig eth0 | grep "inet " | awk '{print \$2}' | awk '{print \$1}')
74   local HOSTIPADDR=\${HOSTIPADDR0#'addr:'}
75   local TEMPIP = \$(/sbin/ifconfig eth0 | grep "inet " | awk '{print \$0}' )
76   local CLUSTERDATAORIG="\"akka.tcp:\/\/opendaylight-cluster-data@127.0.0.1:2550"\"
77   local CLUSTERDATANEW="\"akka.tcp:\/\/opendaylight-cluster-data@$CONTROLLER0:2550\",\"akka.tcp:\/\/opendaylight-cluster-data@$CONTROLLER1:2550\",\"akka.tcp:\/\/opendaylight-cluster-data@$CONTROLLER2:2550"\"
78
79   local CLUSTERRPCORIG="\"akka.tcp:\/\/odl-cluster-rpc@127.0.0.1:2551"\"
80   local CLUSTERRPCNEW="\"akka.tcp:\/\/odl-cluster-rpc@$CONTROLLER0:2551\",\"akka.tcp:\/\/odl-cluster-rpc@$CONTROLLER1:2551\",\"akka.tcp:\/\/odl-cluster-rpc@$CONTROLLER2:2551\""
81
82   local UIDORIG="member-1"
83   local UIDNEW="member-\$1"
84
85 ##########################
86 # END function variables #
87 ##########################
88
89 #####################################
90 # sanity test hostname in akka.conf #
91 #####################################
92 # probably overkill as SCP depends on IPaddress being correct.
93
94 #set -x
95   if [ -z \${HOSTIPADDR} ]; then
96     echo "WARNING:  HOSTIPADDR is empty."
97   fi
98
99 #set +x
100
101   if [ "\${CURRENTCONTROLLERIPADDR}" == "\${HOSTIPADDR}" ]
102   then
103     echo "CURRENTCONTROLLERIPADRR:\${CURRENTCONTROLLERIPADDR} == HOSTIPADDR:\${HOSTIPADDR}"
104   else
105     echo "WARNING: CURRENTCONTROLLERIPADRR:\${CURRENTCONTROLLERIPADDR} != HOSTIPADDR:\${HOSTIPADDR}"
106   fi
107
108 ####################################
109 # configure  hostname in akka.conf #
110 ####################################
111
112   cp \${AKKACONF} \${AKKACONF}.bak
113   sed -ri "s:hostname = \"([0-9]{1,3}[\.]){3}[0-9]{1,3}\":hostname = \
114 \$HOSTIPADDR:" \${AKKACONF}.bak
115
116 ####################################
117 # configure  seednode in akka.conf #
118 ####################################
119
120   sed -i "s/\$CLUSTERDATAORIG/\$CLUSTERDATANEW/g" \${AKKACONF}.bak
121   sed -i "s/\$CLUSTERRPCORIG/\$CLUSTERRPCNEW/g" \${AKKACONF}.bak
122
123 ####################################
124 # define unique name for each node #
125 ####################################
126
127   sed -i "s/\$UIDORIG/\$UIDNEW/g" \${AKKACONF}.bak
128   cp \${AKKACONF}.bak \${AKKACONF}
129   cat \${AKKACONF}
130 echo "#####  END editakkaconf #####"
131 set +x
132 }
133 function configuremoduleshardsconf
134 {
135   echo"### configuremoduleshardsconf ###"
136   set -x
137   if [ -z ${BUNDLEFOLDER} ] || [ -f ${BUNDLEFOLDER} ]; then
138     echo "MODULESHARDSCONF WARNING:  Location of ODL BUNDLEFOLDER:\$BUNDLEFOLDER is not defined"
139   fi
140
141   local REPLICACONFORIG='"member-1"'
142   local REPLICACONFNEW='"member-0",\n\t\t\t"member-1",\n\t\t\t"member-2"'
143
144
145   MODULESHARDSCONF=\$(find /tmp/${BUNDLEFOLDER} -name module-shards.conf)
146
147   if [ -z \${MODULESHARDSCONF} ]
148   then
149     printf "source file module-shards.conf  was not found\n"
150   else
151     printf "MODULESHARDSCONF: \${MODULESHARDSCONF}"
152     cp \${MODULESHARDSCONF} \${MODULESHARDSCONF}.bak
153     printf \$REPLICACONFNEW
154     sed -i "s/\$REPLICACONFORIG/\$REPLICACONFNEW/g" \${MODULESHARDSCONF}.bak
155
156     cp \${MODULESHARDSCONF}.bak  \${MODULESHARDSCONF}
157     cat \${MODULESHARDSCONF}
158  fi
159  set +x
160 }
161
162
163
164 function runcontrollerscript
165 {
166   local CONTROLLERIP=\$1
167   local SCRIPT=\$2
168   echo "run controller \$CONTROLLERIP on \$i"
169   ssh -v \$CONTROLLERIP 'bash /tmp/\$SCRIPT'
170 }
171
172 EOF
173 set +x
174
175
176 #less configuration-functions
177 echo "#########################################################"
178 echo "## END include-raw-integration-configuration_functions ##"
179 echo "#########################################################"
180
181 echo "##################################"
182 echo "##  Less configuration functions #"
183 echo "##################################"
184
185 #less ${WORKSPACE}/configuration-functions
186
187 echo "######################################"
188 echo "##  END Less configuration functions #"
189 echo "######################################"
190
191 ## Describe  the script run on guest vm (node) to configure clustering
192
193
194 cat > ${WORKSPACE}/configuration-script.sh <<EOF
195    source /tmp/configuration-functions
196    source /tmp/bundle_vars.txt
197    source /tmp/slave_addresses.txt
198
199    # Calling the Functions used to edit akka.comf and module-shards
200    # $1  is loop increment  and $2 is the ipaddress of current
201    # controller
202
203    editakkaconf \$1 \$2
204    configuremoduleshardsconf \$1 \$2
205
206 EOF
207
208
209
210 # Describe CONFIGURATION FUNCTIONS  available for the  script above
211 # CONFIGURATIONFUNCTIONS='configuration-functions'
212
213 set -x
214 for  i in "${!CONTROLLERIPS[@]}"
215 do
216    echo "IP address of node is: ${CONTROLLERIPS[$i]} and index is $i"
217    scp  ${WORKSPACE}/slave_addresses.txt  ${CONTROLLERIPS[$i]}:/tmp
218    scp  ${WORKSPACE}/bundle_vars.txt  ${CONTROLLERIPS[$i]}:/tmp
219
220    scp  ${WORKSPACE}/configuration-functions ${CONTROLLERIPS[$i]}:/tmp
221    scp  ${WORKSPACE}/configuration-script.sh    ${CONTROLLERIPS[$i]}:/tmp
222
223    echo "configure controller ${CONTROLLERIPS[$i]} on $i"
224
225
226    ssh -v ${CONTROLLERIPS[$i]} "bash /tmp/configuration-script.sh $i ${CONTROLLERIPS[$i]}"
227 done
228 set +x
229
230
231 echo "######################################################"
232 echo "## END include-raw-integration-configure-clustering ##"
233 echo "######################################################"
234