Add common-functions.sh bash lib
[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 if [ ${CONTROLLERSCOPE} == 'all' ]; then
13     ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
14     export CONTROLLERMEM="3072m"
15 else
16     ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
17 fi
18 # Some versions of jenkins job builder result in feature list containing spaces
19 # and ending in newline. Remove all that.
20 ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
21
22 # Utility function for joining strings.
23 function join {
24     delim=' '
25     final=$1; shift
26
27     for str in "$@" ; do
28         final=${final}${delim}${str}
29     done
30
31     echo ${final}
32 }
33
34 # Create the string for nodes
35 for i in `seq 1 ${NUM_ODL_SYSTEM}` ; do
36     CONTROLLERIP=ODL_SYSTEM_${i}_IP
37     nodes[$i]=${!CONTROLLERIP}
38 done
39
40 nodes_list=$(join "${nodes[@]}")
41
42 echo ${nodes_list}
43
44 # Run script plan in case it exists
45 if [ -f ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} ]; then
46     echo "scriptplan exists!!!"
47     echo "Reading the scriptplan:"
48     cat ${WORKSPACE}/test/csit/scriptplans/${TESTPLAN} | sed "s:integration:${WORKSPACE}:" > scriptplan.txt
49     cat scriptplan.txt
50     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' scriptplan.txt ); do
51         echo "Executing ${line}..."
52         source ${line}
53     done
54 fi
55
56 # Create the configuration script to be run on controllers.
57 cat > ${WORKSPACE}/configuration-script.sh <<EOF
58
59 echo "Changing to /tmp"
60 cd /tmp
61
62 echo "Downloading the distribution from ${ACTUAL_BUNDLE_URL}"
63 wget --progress=dot:mega  '${ACTUAL_BUNDLE_URL}'
64
65 echo "Extracting the new controller..."
66 unzip -q ${BUNDLE}
67
68 echo "Adding external repositories..."
69 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}
70 cat ${MAVENCONF}
71
72 echo "Configuring the startup features..."
73 sed -ie "s/\(featuresBoot=\|featuresBoot =\)/featuresBoot = ${ACTUALFEATURES},/g" ${FEATURESCONF}
74 sed -ie "s%\(featuresRepositories=\|featuresRepositories =\)%featuresRepositories = 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}
75 cat ${FEATURESCONF}
76
77 echo "Configuring the log..."
78 sed -ie 's/log4j.appender.out.maxBackupIndex=10/log4j.appender.out.maxBackupIndex=1/g' ${LOGCONF}
79 # FIXME: Make log size limit configurable from build parameter.
80 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=30GB/g' ${LOGCONF}
81 # Add custom logging levels
82 # CONTROLLERDEBUGMAP is expected to be a key:value map of space separated values like "module:level module2:level2"
83 # where module is abbreviated and does not include org.opendaylight
84 unset IFS
85 if [ -n "${CONTROLLERDEBUGMAP}" ]; then
86     for kv in ${CONTROLLERDEBUGMAP}; do
87         module=\${kv%%:*}
88         level=\${kv#*:}
89         if [ -n \${module} ] && [ -n \${level} ]; then
90             echo "log4j.logger.org.opendaylight.\${module} = \${level}" >> \${LOGCONF}
91         fi
92     done
93 fi
94 cat ${LOGCONF}
95
96 if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then
97   echo "Enable the l3.fwd in custom.properties.."
98   echo "ovsdb.l3.fwd.enabled=yes" >> ${CUSTOMPROP}
99   cat ${CUSTOMPROP}
100 fi
101
102 set_java_vars
103
104 # Copy shard file if exists
105 if [ -f /tmp/custom_shard_config.txt ]; then
106     echo "Custom shard config exists!!!"
107     echo "Copying the shard config..."
108     cp /tmp/custom_shard_config.txt /tmp/${BUNDLEFOLDER}/bin/
109 fi
110
111 echo "Configuring cluster"
112 /tmp/${BUNDLEFOLDER}/bin/configure_cluster.sh \$1 ${nodes_list}
113
114 echo "Dump akka.conf"
115 cat ${AKKACONF}
116
117 echo "Dump modules.conf"
118 cat ${MODULESCONF}
119
120 echo "Dump module-shards.conf"
121 cat ${MODULESHARDSCONF}
122
123 EOF
124
125 # Create the startup script to be run on controllers.
126 cat > ${WORKSPACE}/startup-script.sh <<EOF
127
128 echo "Redirecting karaf console output to karaf_console.log"
129 export KARAF_REDIRECT="/tmp/${BUNDLEFOLDER}/data/log/karaf_console.log"
130 mkdir -p /tmp/${BUNDLEFOLDER}/data/log
131
132 echo "Starting controller..."
133 /tmp/${BUNDLEFOLDER}/bin/start
134
135 EOF
136
137 # Copy over the configuration script and configuration files to each controller
138 # Execute the configuration script on each controller.
139 for i in `seq 1 ${NUM_ODL_SYSTEM}`
140 do
141     CONTROLLERIP=ODL_SYSTEM_${i}_IP
142     echo "Configuring member-${i} with IP address ${!CONTROLLERIP}"
143     scp ${WORKSPACE}/configuration-script.sh ${!CONTROLLERIP}:/tmp/
144     ssh ${!CONTROLLERIP} "bash /tmp/configuration-script.sh ${i}"
145 done
146
147 # Run config plan in case it exists
148 configplan_filepath="${WORKSPACE}/test/csit/configplans/${STREAMTESTPLAN}"
149 if [ ! -f "${configplan_filepath}" ]; then
150     configplan_filepath="${WORKSPACE}/test/csit/configplans/${TESTPLAN}"
151 fi
152
153 if [ -f ${configplan_filepath} ]; then
154     echo "configplan exists!!!"
155     echo "Reading the configplan:"
156     cat ${configplan_filepath} | sed "s:integration:${WORKSPACE}:" > configplan.txt
157     cat configplan.txt
158     for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' configplan.txt ); do
159         echo "Executing ${line}..."
160         source ${line}
161     done
162 fi
163
164 # Copy over the startup script to each controller and execute it.
165 for i in `seq 1 ${NUM_ODL_SYSTEM}`
166 do
167     CONTROLLERIP=ODL_SYSTEM_${i}_IP
168     echo "Starting member-${i} with IP address ${!CONTROLLERIP}"
169     scp ${WORKSPACE}/startup-script.sh ${!CONTROLLERIP}:/tmp/
170     ssh ${!CONTROLLERIP} "bash /tmp/startup-script.sh"
171 done
172
173 # vim: ts=4 sw=4 sts=4 et ft=sh :