Merge "Switch global-jjb jobs to use mvn35"
[releng/builder.git] / jjb / integration / distribution / distribution-check-bootup.sh
1 CONTROLLERMEM="3072m"
2 ACTUALFEATURES="odl-integration-all"
3
4 if [[ ! -z "${CONTROLLERFEATURES}" ]]; then
5     ACTUALFEATURES="odl-integration-all,${CONTROLLERFEATURES}"
6 fi
7
8 echo "Kill any controller running"
9 ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sh
10
11 echo "Clean Existing distribution"
12 rm -rf ${BUNDLEFOLDER}
13
14 echo "Fetch the distribution..."
15 if  [[ -z "${BUNDLE_PATH}" ]]; then
16     wget --progress=dot:mega  "${ACTUAL_BUNDLE_URL}"
17 else
18     cp "${BUNDLE_PATH}" .
19 fi
20
21 echo "Extracting the new controller..."
22 unzip -q "${BUNDLE}"
23
24 echo "Configuring the startup features..."
25 FEATURESCONF="${WORKSPACE}/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg"
26 FEATURE_TEST_STRING="features-test"
27 if [[ "$KARAF_VERSION" == "karaf3" ]]; then
28     FEATURE_TEST_STRING="features-integration-test"
29 fi
30
31 sed -ie "s%\(featuresRepositories= \|featuresRepositories = \)%featuresRepositories = mvn:org.opendaylight.integration/${FEATURE_TEST_STRING}/${BUNDLE_VERSION}/xml/features,%g" ${FEATURESCONF}
32
33 if [[ ! -z "${REPO_URL}" ]]; then
34    sed -ie "s%featuresRepositories = %featuresRepositories = ${REPO_URL},%g" ${FEATURESCONF}
35 fi
36
37 # Add actual boot features.
38 sed -ie "s/\(featuresBoot= \|featuresBoot = \)/featuresBoot = ${ACTUALFEATURES},/g" "${FEATURESCONF}"
39 cat "${FEATURESCONF}"
40
41 echo "Configuring the log..."
42 LOGCONF="${WORKSPACE}/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg"
43 sed -ie 's/log4j.appender.out.maxFileSize=1MB/log4j.appender.out.maxFileSize=20MB/g' "${LOGCONF}"
44 cat "${LOGCONF}"
45
46 echo "Configure max memory..."
47 MEMCONF="${WORKSPACE}/${BUNDLEFOLDER}/bin/setenv"
48 sed -ie "s/2048m/${CONTROLLERMEM}/g" "${MEMCONF}"
49 cat "${MEMCONF}"
50
51 echo "Listing all open ports on controller system"
52 netstat -pnatu
53
54 if [ "${JDKVERSION}" == 'openjdk8' ]; then
55     echo "Setting the JRE Version to 8"
56     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
57     # sudo /usr/sbin/alternatives --set java /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.60-2.b27.el7_1.x86_64/jre/bin/java
58     export JAVA_HOME='/usr/lib/jvm/java-1.8.0'
59 elif [ "${JDKVERSION}" == 'openjdk7' ]; then
60     echo "Setting the JRE Version to 7"
61     # dynamic_verify does not allow sudo, JAVA_HOME should be enough for karaf start.
62     # sudo /usr/sbin/alternatives --set java /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85-2.6.1.2.el7_1.x86_64/jre/bin/java
63     export JAVA_HOME='/usr/lib/jvm/java-1.7.0'
64 fi
65 readlink -e "${JAVA_HOME}/bin/java"
66 echo "JDK Version should be overriden by JAVA_HOME"
67 java -version
68
69 echo "Redirecting karaf console output to karaf_console.log"
70 export KARAF_REDIRECT="${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"
71 mkdir -p ${WORKSPACE}/${BUNDLEFOLDER}/data/log
72
73 echo "Starting controller..."
74 ${WORKSPACE}/${BUNDLEFOLDER}/bin/start
75
76 function dump_log_and_exit {
77     echo "Dumping first 500K bytes of karaf log..."
78     head --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
79     echo "Dumping last 500K bytes of karaf log..."
80     tail --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
81     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
82     cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
83     exit 1
84 }
85
86 echo "Waiting up to 5 minutes for controller to come up, checking every 5 seconds..."
87 COUNT="0"
88 while true; do
89     COUNT=$(( ${COUNT} + 5 ))
90     sleep 5
91     echo "already waited ${COUNT} seconds..."
92     if grep --quiet 'org.opendaylight.infrautils.ready-impl.*System ready' "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"; then
93         echo "Controller is UP"
94         break
95     elif (( "${COUNT}" > "300" )); then
96         echo "Timeout Controller DOWN"
97         dump_log_and_exit
98     fi
99 done
100
101 # echo "Checking OSGi bundles..."
102 # sshpass seems to fail with new karaf version
103 # sshpass -p karaf ${WORKSPACE}/${BUNDLEFOLDER}/bin/client -u karaf 'bundle:list'
104
105 echo "Listing all open ports on controller system"
106 netstat -pnatu
107
108 function exit_on_log_file_message {
109     echo "looking for \"$1\" in karaf.log file"
110     if grep --quiet "$1" "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"; then
111         echo ABORTING: found "$1"
112         dump_log_and_exit
113     fi
114
115     echo "looking for \"$1\" in karaf_console.log file"
116     if grep --quiet "$1" "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log"; then
117         echo ABORTING: found "$1"
118         dump_log_and_exit
119     fi
120 }
121
122 exit_on_log_file_message 'Error installing boot feature repository'
123 exit_on_log_file_message 'BindException: Address already in use'
124 exit_on_log_file_message 'server is unhealthy'
125
126 echo "Fetching Karaf logs"
127 # TODO: Move instead of copy? Gzip?
128 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
129 cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
130
131 echo "Kill controller"
132 ps axf | grep karaf | grep -v grep | awk '{print "kill -9 " $1}' | sh
133
134 echo "Bug 4628: Detecting misplaced config files"
135 pushd "${WORKSPACE}/${BUNDLEFOLDER}" || exit
136 XMLS_FOUND="$(echo *.xml)"
137 popd || exit
138 if [ "$XMLS_FOUND" != "*.xml" ]; then
139     echo "Bug 4628 confirmed."
140     ## TODO: Uncomment the following when ODL is fixed, to guard against regression.
141     # exit 1
142 else
143     echo "Bug 4628 not detected."
144 fi
145
146 # vim: ts=4 sw=4 sts=4 et ft=sh :