Skip to content

Commit 2871b7c

Browse files
author
Tom Barnes
committed
Add WebLogic version and WebLogic patch checks - fail introspector job and pod startup for unsupported versions.
1 parent 40e7489 commit 2871b7c

File tree

4 files changed

+175
-1
lines changed

4 files changed

+175
-1
lines changed

operator/src/main/resources/scripts/introspectDomain.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export MW_HOME=${MW_HOME:-/u01/oracle}
5858
checkEnv DOMAIN_UID \
5959
NAMESPACE \
6060
DOMAIN_HOME \
61+
ORACLE_HOME \
6162
JAVA_HOME \
6263
NODEMGR_HOME \
6364
WL_HOME \
@@ -70,14 +71,19 @@ for script_file in "${SCRIPTPATH}/wlst.sh" \
7071
[ ! -f "$script_file" ] && trace "Error: missing file '${script_file}'." && exit 1
7172
done
7273

73-
for dir_var in DOMAIN_HOME JAVA_HOME WL_HOME MW_HOME; do
74+
for dir_var in DOMAIN_HOME JAVA_HOME WL_HOME MW_HOME ORACLE_HOME; do
7475
[ ! -d "${!dir_var}" ] && trace "Error: missing ${dir_var} directory '${!dir_var}'." && exit 1
7576
done
7677

7778
# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed
7879

7980
exportEffectiveDomainHome || exit 1
8081

82+
# check if we're using a supported WebLogic version
83+
# (the check will log a message if it fails)
84+
85+
checkWebLogicVersion || exit 1
86+
8187
# start node manager
8288

8389
trace "Starting node manager"

operator/src/main/resources/scripts/startServer.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ checkEnv \
175175
DOMAIN_NAME \
176176
DOMAIN_HOME \
177177
NODEMGR_HOME \
178+
ORACLE_HOME \
178179
SERVER_NAME \
179180
SERVICE_NAME \
180181
ADMIN_NAME \
@@ -190,6 +191,7 @@ trace "JAVA_OPTIONS=${JAVA_OPTIONS}"
190191
#
191192
# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed:
192193
#
194+
193195
exportEffectiveDomainHome || exitOrLoop
194196

195197
#
@@ -202,6 +204,15 @@ if [ ! -f /weblogic-operator/introspector/boot.properties ]; then
202204
exitOrLoop
203205
fi
204206

207+
#
208+
# Check if we're using a supported WebLogic version. The check will
209+
# log a message if it fails.
210+
#
211+
212+
if ! checkWebLogicVersion ; then
213+
exitOrLoop
214+
fi
215+
205216
#
206217
# Copy/update domain introspector files for the domain
207218
#

operator/src/main/resources/scripts/traceUtils.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,107 @@ function exportEffectiveDomainHome() {
164164
trace "Error: More than one config.xml found at DOMAIN_HOME/config/config.xml and DOMAIN_HOME/*/config/config.xml, DOMAIN_HOME='$DOMAIN_HOME': ${found_configs}. Configure your 'domainHome' setting in your WebLogic Operator Domain resource to reference a single WebLogic domain."
165165
return 1
166166
}
167+
168+
169+
# versionCmp
170+
# Compares two wl versions $1 $2 up to the length of $2
171+
# Expects form N.N.N.N
172+
# Uses '0' for an N in $1 if $1 is shorter than $2
173+
# echo "1" if v1 > v2
174+
# echo "-1" if v1 < v2
175+
# echo "0" if v1 == v2
176+
versionCmp()
177+
{
178+
IFS='.' read -r -a v1_arr <<< "`echo $1`"
179+
IFS='.' read -r -a v2_arr <<< "`echo $2`"
180+
181+
for i in "${!v2_arr[@]}"
182+
do
183+
[ ${v1_arr[i]:-0} -gt ${v2_arr[i]:-0} ] && echo "1" && return
184+
[ ${v1_arr[i]:-0} -lt ${v2_arr[i]:-0} ] && echo "-1" && return
185+
done
186+
echo "0"
187+
}
188+
189+
# versionGE
190+
# return success if WL v1 >= v2
191+
versionGE()
192+
{
193+
[ `versionCmp "$1" "$2"` -ge 0 ] && return 0
194+
return 1
195+
}
196+
197+
# versionEQ
198+
# return success if v1 == v2
199+
versionEQ()
200+
{
201+
[ `versionCmp "$1" "$2"` -eq 0 ] && return 0
202+
return 1
203+
}
204+
205+
# hasWebLogicPatches
206+
# check for the given patch numbers in the install inventory,
207+
# and return 1 if not found
208+
# - if we can't find the install inventory then we
209+
# assume the patch is there...
210+
# - we parse the install inventory as this is far faster than
211+
# using opatch or weblogic.version
212+
hasWebLogicPatches()
213+
{
214+
local reg_file=$ORACLE_HOME/inventory/registry.xml
215+
[ ! -f $reg_file ] && return 0
216+
for pnum in "$@"; do
217+
grep --silent "patch-id=\"$1\"" $reg_file || return 1
218+
done
219+
}
220+
221+
# getWebLogicVersion
222+
# parse wl version from install inventory
223+
# - if we can't get a version number then we return
224+
# a high dummy version number that's sufficient
225+
# to pass version checks "9999.9999.9999.9999"
226+
# - we parse the install inventory as this is far faster than
227+
# using opatch or weblogic.version
228+
getWebLogicVersion()
229+
{
230+
local reg_file=$ORACLE_HOME/inventory/registry.xml
231+
232+
[ ! -f $reg_file ] && echo "9999.9999.9999.9999" && return
233+
234+
local wlver="`grep 'name="WebLogic Server".*version=' $reg_file \
235+
| sed 's/.*version="\([0-9.]*\)".*/\1/g'`"
236+
237+
echo ${wlver:-"9999.9999.9999.9999"}
238+
}
239+
240+
241+
# checkWebLogicVersion
242+
# check if the WL version is supported by the Operator
243+
# - skip check if SKIP_WL_VERSION_CHECK = "true"
244+
# - log an error if WL version < 12.2.1.3
245+
# - log an error if WL version == 12.2.1.3 && patch 29135930 is missing
246+
# - you can override the required 12.2.1.3 patches by exporting
247+
# global WL12213REQUIREDPATCHES to an empty string or to other
248+
# patch number(s)
249+
# - return 1 if logged an error
250+
# - return 0 otherwise
251+
checkWebLogicVersion()
252+
{
253+
[ "$SKIP_WL_VERSION_CHECK" = "true" ] && return 0
254+
local cur_wl_ver="`getWebLogicVersion`"
255+
local exp_wl_ver="12.2.1.3"
256+
local exp_wl_12213_patches="${WL12213REQUIREDPATCHES:-"29135930"}"
257+
if versionEQ "$cur_wl_ver" "12.2.1.3" ; then
258+
if ! hasWebLogicPatches $exp_wl_12213_patches ; then
259+
trace "Error: The Operator requires that WebLogic version '12.2.1.3' have patch '$exp_wl_12213_patches'. To bypass this check, set env var SKIP_WL_VERSION_CHECK to 'true'."
260+
return 1
261+
fi
262+
fi
263+
if versionGE "$cur_wl_ver" "${exp_wl_ver}" ; then
264+
trace "Info: WebLogic version='$cur_wl_ver'. Version check passed. (The Operator requires WebLogic version '${exp_wl_ver}' or higher)."
265+
else
266+
trace "Error: WebLogic version='$cur_wl_ver' and the Operator requires WebLogic version '${exp_wl_ver}' or higher. To bypass this check, set env var SKIP_WL_VERSION_CHECK to 'true'."
267+
return 1
268+
fi
269+
return 0
270+
}

src/integration-tests/introspector/introspectTest.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,54 @@ function checkOverrides() {
596596
fi
597597
}
598598

599+
#############################################################################
600+
#
601+
# Check if wl version checks are working on the admin pod
602+
#
603+
604+
function checkWLVersionChecks() {
605+
606+
trace "Info: Checking pod log for 'error' strings."
607+
608+
# Check for exactly 0 occurances of 'Error:' lines.
609+
# a version issue is reported as an 'error:' to the log
610+
# the awk expression below gets the tail of the log, everything after the last occurance of 'Starting WebLogic...'
611+
612+
linecount="`kubectl -n ${NAMESPACE} logs ${DOMAIN_UID}-${ADMIN_NAME} | awk '/.*Starting WebLogic server with command/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' | grep -ci 'error:'`"
613+
logstatus=0
614+
615+
if [ ! "$linecount" == "0" ]; then
616+
trace "Error: The latest boot in 'kubectl -n ${NAMESPACE} logs ${DOMAIN_UID}-${ADMIN_NAME}' contains lines with the keyword 'error'."
617+
logstatus=1
618+
fi
619+
620+
# Copy version test file up to admin server and run it
621+
622+
local testscript="util_testwlversion.sh"
623+
local outfile="$test_home/${testscript}.out"
624+
625+
trace "Info: Running version checks on admin-server, output file '$outfile'."
626+
627+
kubectl -n ${NAMESPACE} \
628+
cp ${SCRIPTPATH}/${testscript} \
629+
${DOMAIN_UID}-${ADMIN_NAME}:/shared/${testscript} \
630+
|| exit 1
631+
632+
rm -f ${outfile}
633+
kubectl exec -it ${DOMAIN_UID}-${ADMIN_NAME} \
634+
/shared/${testscript} \
635+
> ${outfile} 2>&1
636+
status=$?
637+
638+
if [ $status -ne 0 ]; then
639+
trace "Error: The version checks failed, see '${outfile}'."
640+
fi
641+
642+
if [ $status -ne 0 ] || [ $logstatus -ne 0 ]; then
643+
exit 1
644+
fi
645+
}
646+
599647
#############################################################################
600648
#
601649
# Check if datasource is working
@@ -675,6 +723,11 @@ deployPod ${MANAGED_SERVER_NAME_BASE?}1
675723
deploySinglePodService ${MANAGED_SERVER_NAME_BASE?}1 ${MANAGED_SERVER_PORT?} 30801
676724
waitForPod ${DOMAIN_UID}-${MANAGED_SERVER_NAME_BASE?}1
677725

726+
# Check admin-server pod log for wl version errors and run some
727+
# tests on the life-cycle WL version checking code.
728+
729+
checkWLVersionChecks
730+
678731
# Check admin-server pod log and also call on-line WLST to check if
679732
# automatic and custom overrides are taking effect in the bean tree:
680733

0 commit comments

Comments
 (0)