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