41e99411e90253ba107a77e5960cd1ea8c7c7ddf
[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 MAVENCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.url.mvn.cfg
16 FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg
17 CUSTOMPROP=/tmp/${BUNDLEFOLDER}/etc/custom.properties
18 LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
19 MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv
20 CONTROLLERMEM="2048m"
21
22
23 if [ ${CONTROLLERSCOPE} == 'all' ]; then
24     ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
25     CONTROLLERMEM="3072m"
26 else
27     ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
28 fi
29 # Some versions of jenkins job builder result in feature list containing spaces
30 # and ending in newline. Remove all that.
31 ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
32
33 # Utility function for joining strings.
34 function join {
35     delim=' '
36     final=$1; shift
37
38     for str in "$@" ; do
39         final=${final}${delim}${str}
40     done
41
42     echo ${final}
43 }
44
45 # Create the string for nodes
46 for i in `seq 1 ${NUM_ODL_SYSTEM}` ; do
47     CONTROLLERIP=ODL_SYSTEM_${i}_IP
48     nodes[$i]=${!CONTROLLERIP}
49 done
50
51 nodes_list=$(join "${nodes[@]}")
52
53 echo ${nodes_list}
54
55 # Run script plan in case it exists
56 if [ -f ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} ]; then
57     echo "scriptplan exists!!!"
58     echo "Reading the scriptplan:"
59     cat ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > scriptplan.txt
60     cat scriptplan.txt
61     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' scriptplan.txt ); do
62         echo "Executing ${line}..."
63         source ${line}
64     done
65 fi
66
67 # Create the configuration script to be run on controllers.
68 cat > ${WORKSPACE}/configuration-script.sh <<EOF
69 echo "Create RAM disk"
70 sudo mount -t tmpfs -o size=2G tmpfs /tmp
71
72 echo "Changing to /tmp"
73 cd /tmp
74
75 echo "Downloading the distribution from ${ACTUAL_BUNDLE_URL}"
76 wget --progress=dot:mega  '${ACTUAL_BUNDLE_URL}'
77
78 echo "Extracting the new controller..."
79 unzip -q ${BUNDLE}
80
81 echo "Adding external repositories..."
82 sed -ie "s%org.ops4j.pax.url.mvn.repositories=%org.ops4j.pax.url.mvn.repositories=http://repo1.maven.org/maven2@id=central, http://repository.springsource.com/maven/bundles/release@id=spring.ebr.release, http://repository.springsource.com/maven/bundles/external@id=spring.ebr.external, http://zodiac.springsource.com/maven/bundles/release@id=gemini, http://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases, https://oss.sonatype.org/content/repositories/snapshots@id=sonatype.snapshots.deploy@snapshots@noreleases, https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases%g" ${MAVENCONF}
83 cat ${MAVENCONF}
84
85 echo "Configuring the startup features..."
86 sed -ie "s/\(featuresBoot=\|featuresBoot =\)/featuresBoot = ${ACTUALFEATURES},/g" ${FEATURESCONF}
87 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}
88 cat ${FEATURESCONF}
89
90 echo "Configuring the log..."
91 sed -ie 's/log4j.appender.out.maxBackupIndex=10/log4j.appender.out.maxBackupIndex=1/g' ${LOGCONF}
92 # FIXME: Make log size limit configurable from build parameter.
93 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=30GB/g' ${LOGCONF}
94 # Add custom logging levels
95 # CONTROLLERDEBUGMAP is expected to be a key:value map of space separated values like "module:level module2:level2"
96 # where module is abbreviated and does not include org.opendaylight
97 unset IFS
98 if [ -n "${CONTROLLERDEBUGMAP}" ]; then
99     for kv in ${CONTROLLERDEBUGMAP}; do
100         module=\${kv%%:*}
101         level=\${kv#*:}
102         if [ -n \${module} ] && [ -n \${level} ]; then
103             echo "log4j.logger.org.opendaylight.\${module} = \${level}" >> \${LOGCONF}
104         fi
105     done
106 fi
107 cat ${LOGCONF}
108
109 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
110   echo "Enable the l3.fwd in custom.properties.."
111   echo "ovsdb.l3.fwd.enabled=yes" >> ${CUSTOMPROP}
112   cat ${CUSTOMPROP}
113 fi
114
115 echo "Configure java home and max memory..."
116 sed -ie 's%^# export JAVA_HOME%export JAVA_HOME="\${JAVA_HOME:-${JAVA_HOME}}"%g' ${MEMCONF}
117 sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' ${MEMCONF}
118 cat ${MEMCONF}
119
120 echo "Set Java version"
121 sudo /usr/sbin/alternatives --install /usr/bin/java java ${JAVA_HOME}/bin/java 1
122 sudo /usr/sbin/alternatives --set java ${JAVA_HOME}/bin/java
123 echo "JDK default version ..."
124 java -version
125
126 echo "Set JAVA_HOME"
127 export JAVA_HOME="${JAVA_HOME}"
128 # Did you know that in HERE documents, single quote is an ordinary character, but backticks are still executing?
129 JAVA_RESOLVED=\`readlink -e "\${JAVA_HOME}/bin/java"\`
130 echo "Java binary pointed at by JAVA_HOME: \${JAVA_RESOLVED}"
131
132 # Copy shard file if exists
133 if [ -f /tmp/custom_shard_config.txt ]; then
134     echo "Custom shard config exists!!!"
135     echo "Copying the shard config..."
136     cp /tmp/custom_shard_config.txt /tmp/${BUNDLEFOLDER}/bin/
137 fi
138
139 echo "Configuring cluster"
140 /tmp/${BUNDLEFOLDER}/bin/configure_cluster.sh \$1 ${nodes_list}
141
142 echo "Dump akka.conf"
143 cat ${AKKACONF}
144
145 echo "Dump modules.conf"
146 cat ${MODULESCONF}
147
148 echo "Dump module-shards.conf"
149 cat ${MODULESHARDSCONF}
150
151 EOF
152
153 # Create the startup script to be run on controllers.
154 cat > ${WORKSPACE}/startup-script.sh <<EOF
155
156 echo "Redirecting karaf console output to karaf_console.log"
157 export KARAF_REDIRECT="/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log"
158
159 echo "Starting controller..."
160 /tmp/${BUNDLEFOLDER}/bin/start
161
162 EOF
163
164 # Copy over the configuration script and configuration files to each controller
165 # Execute the configuration script on each controller.
166 for i in `seq 1 ${NUM_ODL_SYSTEM}`
167 do
168     CONTROLLERIP=ODL_SYSTEM_${i}_IP
169     echo "Configuring member-${i} with IP address ${!CONTROLLERIP}"
170     scp ${WORKSPACE}/configuration-script.sh ${!CONTROLLERIP}:/tmp/
171     ssh ${!CONTROLLERIP} "bash /tmp/configuration-script.sh ${i}"
172 done
173
174 # Run config plan in case it exists
175 configplan_filepath="${WORKSPACE}/test/csit/configplans/${STREAMTESTPLAN}"
176 if [ ! -f "${configplan_filepath}" ]; then
177     configplan_filepath="${WORKSPACE}/test/csit/configplans/${TESTPLAN}"
178 fi
179
180 if [ -f ${configplan_filepath} ]; then
181     echo "configplan exists!!!"
182     echo "Reading the configplan:"
183     cat ${configplan_filepath} | sed "s:integration:${WORKSPACE}:" > configplan.txt
184     cat configplan.txt
185     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' configplan.txt ); do
186         echo "Executing ${line}..."
187         source ${line}
188     done
189 fi
190
191 # Copy over the startup script to each controller and execute it.
192 for i in `seq 1 ${NUM_ODL_SYSTEM}`
193 do
194     CONTROLLERIP=ODL_SYSTEM_${i}_IP
195     echo "Starting member-${i} with IP address ${!CONTROLLERIP}"
196     scp ${WORKSPACE}/startup-script.sh ${!CONTROLLERIP}:/tmp/
197     ssh ${!CONTROLLERIP} "bash /tmp/startup-script.sh"
198 done
199
200 # vim: ts=4 sw=4 sts=4 et ft=sh :