Merge "Move global variables to parent script"
[releng/builder.git] / jjb / integration / integration-configure-clustering.sh
1 #@IgnoreInspection BashAddShebang
2 # Activate robotframework virtualenv
3 # ${ROBOT_VENV} comes from the integration-install-robotframework.sh
4 # script.
5 # shellcheck source=${ROBOT_VENV}/bin/activate disable=SC1091
6 source ${ROBOT_VENV}/bin/activate
7
8 echo "#################################################"
9 echo "##         Configure Cluster and Start         ##"
10 echo "#################################################"
11
12 AKKACONF=/tmp/${BUNDLEFOLDER}/configuration/initial/akka.conf
13 MODULESCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/modules.conf
14 MODULESHARDSCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/module-shards.conf
15 FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg
16 CUSTOMPROP=/tmp/${BUNDLEFOLDER}/etc/custom.properties
17 LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
18 MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv
19 CONTROLLERMEM="2048m"
20
21
22 if [ ${CONTROLLERSCOPE} == 'all' ]; then
23     ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
24     CONTROLLERMEM="3072m"
25 else
26     ACTUALFEATURES="${CONTROLLERFEATURES}"
27 fi
28 # Some versions of jenkins job builder result in feature list containing spaces
29 # and ending in newline. Remove all that.
30 ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
31
32 # Utility function for joining strings.
33 function join {
34     delim=' '
35     final=$1; shift
36
37     for str in "$@" ; do
38         final=${final}${delim}${str}
39     done
40
41     echo ${final}
42 }
43
44 # Create the string for nodes
45 for i in `seq 1 ${NUM_ODL_SYSTEM}` ; do
46     CONTROLLERIP=ODL_SYSTEM_${i}_IP
47     nodes[$i]=${!CONTROLLERIP}
48 done
49
50 nodes_list=$(join "${nodes[@]}")
51
52 echo ${nodes_list}
53
54 # Run script plan in case it exists
55 if [ -f ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} ]; then
56     echo "scriptplan exists!!!"
57     echo "Reading the scriptplan:"
58     cat ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > scriptplan.txt
59     cat scriptplan.txt
60     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' scriptplan.txt ); do
61         echo "Executing ${line}..."
62         source ${line}
63     done
64 fi
65
66 # Create the configuration script to be run on controllers.
67 cat > ${WORKSPACE}/configuration-script.sh <<EOF
68
69 echo "Changing to /tmp"
70 cd /tmp
71
72 echo "Downloading the distribution from ${ACTUAL_BUNDLE_URL}"
73 wget --progress=dot:mega  '${ACTUAL_BUNDLE_URL}'
74
75 echo "Extracting the new controller..."
76 unzip -q ${BUNDLE}
77
78 echo "Configuring the startup features..."
79 sed -ie "s/\(featuresBoot=\|featuresBoot =\)/featuresBoot = ${ACTUALFEATURES},/g" ${FEATURESCONF}
80 sed -ie "s%mvn:org.opendaylight.integration/features-integration-index/${BUNDLEVERSION}/xml/features%mvn:org.opendaylight.integration/features-integration-index/${BUNDLEVERSION}/xml/features,mvn:org.opendaylight.integration/features-integration-test/${BUNDLEVERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.0.0/xml/features%g" ${FEATURESCONF}
81 cat ${FEATURESCONF}
82
83 echo "Configuring the log..."
84 sed -ie 's/log4j.appender.out.maxBackupIndex=10/log4j.appender.out.maxBackupIndex=1/g' ${LOGCONF}
85 # FIXME: Make log size limit configurable from build parameter.
86 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=30GB/g' ${LOGCONF}
87 cat ${LOGCONF}
88
89 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
90   echo "Enable the l3.fwd in custom.properties.."
91   echo "ovsdb.l3.fwd.enabled=yes" >> ${CUSTOMPROP}
92   cat ${CUSTOMPROP}
93 fi
94
95 echo "Configure java home and max memory..."
96 sed -ie 's%^# export JAVA_HOME%export JAVA_HOME="\${JAVA_HOME:-${JAVA_HOME}}"%g' ${MEMCONF}
97 sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' ${MEMCONF}
98 cat ${MEMCONF}
99
100 echo "Set Java version"
101 sudo /usr/sbin/alternatives --install /usr/bin/java java ${JAVA_HOME}/bin/java 1
102 sudo /usr/sbin/alternatives --set java ${JAVA_HOME}/bin/java
103 echo "JDK default version ..."
104 java -version
105
106 echo "Set JAVA_HOME"
107 export JAVA_HOME="${JAVA_HOME}"
108 # Did you know that in HERE documents, single quote is an ordinary character, but backticks are still executing?
109 JAVA_RESOLVED=\`readlink -e "\${JAVA_HOME}/bin/java"\`
110 echo "Java binary pointed at by JAVA_HOME: \${JAVA_RESOLVED}"
111
112 # Copy shard file if exists
113 if [ -f /tmp/custom_shard_config.txt ]; then
114     echo "Custom shard config exists!!!"
115     echo "Copying the shard config..."
116     cp /tmp/custom_shard_config.txt /tmp/${BUNDLEFOLDER}/bin/
117 fi
118
119 echo "Configuring cluster"
120 /tmp/${BUNDLEFOLDER}/bin/configure_cluster.sh \$1 ${nodes_list}
121
122 echo "Dump akka.conf"
123 cat ${AKKACONF}
124
125 echo "Dump modules.conf"
126 cat ${MODULESCONF}
127
128 echo "Dump module-shards.conf"
129 cat ${MODULESHARDSCONF}
130
131 EOF
132
133 # Create the startup script to be run on controllers.
134 cat > ${WORKSPACE}/startup-script.sh <<EOF
135
136 echo "Redirecting karaf console output to karaf_console.log"
137 export KARAF_REDIRECT="/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log"
138
139 echo "Starting controller..."
140 /tmp/${BUNDLEFOLDER}/bin/start
141
142 EOF
143
144 # Copy over the configuration script and configuration files to each controller
145 # Execute the configuration script on each controller.
146 for i in `seq 1 ${NUM_ODL_SYSTEM}`
147 do
148     CONTROLLERIP=ODL_SYSTEM_${i}_IP
149     echo "Configuring member-${i} with IP address ${!CONTROLLERIP}"
150     scp ${WORKSPACE}/configuration-script.sh ${!CONTROLLERIP}:/tmp/
151     ssh ${!CONTROLLERIP} "bash /tmp/configuration-script.sh ${i}"
152 done
153
154 # Run config plan in case it exists
155 configplan_filepath="${WORKSPACE}/test/csit/configplans/${STREAMTESTPLAN}"
156 if [ ! -f "${configplan_filepath}" ]; then
157     configplan_filepath="${WORKSPACE}/test/csit/configplans/${TESTPLAN}"
158 fi
159
160 if [ -f ${configplan_filepath} ]; then
161     echo "configplan exists!!!"
162     echo "Reading the configplan:"
163     cat ${configplan_filepath} | sed "s:integration:${WORKSPACE}:" > configplan.txt
164     cat configplan.txt
165     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' configplan.txt ); do
166         echo "Executing ${line}..."
167         source ${line}
168     done
169 fi
170
171 # Copy over the startup script to each controller and execute it.
172 for i in `seq 1 ${NUM_ODL_SYSTEM}`
173 do
174     CONTROLLERIP=ODL_SYSTEM_${i}_IP
175     echo "Starting member-${i} with IP address ${!CONTROLLERIP}"
176     scp ${WORKSPACE}/startup-script.sh ${!CONTROLLERIP}:/tmp/
177     ssh ${!CONTROLLERIP} "bash /tmp/startup-script.sh"
178 done
179
180 # vim: ts=4 sw=4 sts=4 et ft=sh :