Skip to content

Commit 737239d

Browse files
author
Tom Barnes
committed
Reflect each introspector job log message in the operator log, plus ensure job log messages use same log-levels as the operator.
1 parent 4391ebe commit 737239d

File tree

12 files changed

+315
-104
lines changed

12 files changed

+315
-104
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
package oracle.kubernetes.operator.helpers;
66

7+
import java.io.BufferedReader;
8+
import java.io.IOException;
9+
import java.io.StringReader;
710
import java.util.List;
811

912
import io.kubernetes.client.models.V1DeleteOptions;
@@ -34,6 +37,7 @@
3437
import oracle.kubernetes.weblogic.domain.model.DomainSpec;
3538
import oracle.kubernetes.weblogic.domain.model.ManagedServer;
3639

40+
3741
public class JobHelper {
3842

3943
static final String START_TIME = "WlsRetriever-startTime";
@@ -329,6 +333,11 @@ public NextAction onSuccess(Packet packet, CallResponse<String> callResponse) {
329333
// Log output to Operator log
330334
LOGGER.fine("+++++ ReadDomainIntrospectorPodLogResponseStep: \n" + result);
331335

336+
// Parse out each job log message and log to Operator as SEVERE, FINE, etc...
337+
if (result != null) {
338+
convertJobLogsToOperatorLogs(result);
339+
}
340+
332341
V1Job domainIntrospectorJob = (V1Job) packet.get(ProcessingConstants.DOMAIN_INTROSPECTOR_JOB);
333342
if (domainIntrospectorJob != null && JobWatcher.isComplete(domainIntrospectorJob)) {
334343
if (result != null) {
@@ -406,4 +415,68 @@ public NextAction onSuccess(Packet packet, CallResponse<V1PodList> callResponse)
406415
return doNext(packet);
407416
}
408417
}
418+
419+
// Convert a job log message to an operator log message
420+
// - assumes the messages contins a string like '[SEVERE]', etc, if
421+
// not, then assumes the log level is 'FINE'.
422+
private static void logToOperator(StringBuffer logStr, StringBuffer extraStr) {
423+
String logMsg = "Introspector Job Log: "
424+
+ logStr
425+
+ (extraStr.length() == 0 ? "" : "\n")
426+
+ extraStr;
427+
String regExp = ".*\\[(SEVERE|ERROR|WARNING|INFO|FINE|FINER|FINEST)\\].*";
428+
String logLevel = logStr.toString().toUpperCase().replaceAll(regExp,"$1");
429+
switch (logLevel) {
430+
case "ERROR": LOGGER.severe(logMsg);
431+
break;
432+
case "SEVERE": LOGGER.severe(logMsg);
433+
break;
434+
case "WARNING": LOGGER.warning(logMsg);
435+
break;
436+
case "INFO": LOGGER.info(logMsg);
437+
break;
438+
case "FINE": LOGGER.fine(logMsg);
439+
break;
440+
case "FINER": LOGGER.finer(logMsg);
441+
break;
442+
case "FINEST": LOGGER.finest(logMsg);
443+
break;
444+
default: LOGGER.fine(logMsg);
445+
break;
446+
}
447+
}
448+
449+
// Parse log messages out of a Job Log
450+
// - assumes each job log message starts with '@['
451+
// - assumes any lines that don't start with '@[' are part
452+
// of the previous log message
453+
// - ignores all lines in the log up to the first line that starts with '@['
454+
private static void convertJobLogsToOperatorLogs(String jobLogs) {
455+
try {
456+
StringBuffer logString = new StringBuffer(1000);
457+
StringBuffer logExtra = new StringBuffer(1000);
458+
try (BufferedReader reader = new BufferedReader(new StringReader(jobLogs))) {
459+
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
460+
if (line.startsWith("@[")) {
461+
if (logString.length() > 0) {
462+
logToOperator(logString, logExtra);
463+
logString.setLength(0);
464+
logExtra.setLength(0);
465+
}
466+
logString.append(line);
467+
} else if (logString.length() != 0) {
468+
if (logExtra.length() > 0) {
469+
logExtra.append('\n');
470+
}
471+
logExtra.append(line);
472+
}
473+
}
474+
if (logString.length() > 0) {
475+
logToOperator(logString, logExtra);
476+
}
477+
}
478+
} catch (IOException ioe) {
479+
LOGGER.fine("Unexpected exception " + ioe + " while parsing string:\n" + jobLogs);
480+
}
481+
}
409482
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def printFile(self, path):
210210
def getEnv(self, name):
211211
val = os.getenv(name)
212212
if val is None or val == "null":
213-
trace("ERROR: Env var "+name+" not set.")
213+
trace("SEVERE","Env var "+name+" not set.")
214214
sys.exit(1)
215215
return val
216216

@@ -930,7 +930,7 @@ def __init__(self, env):
930930
self.macroStr+=', '
931931
self.macroStr+='${' + key + '}'
932932

933-
trace("available macros: '" + self.macroStr + "'")
933+
trace("Available macros: '" + self.macroStr + "'")
934934

935935
# Populate module maps with known module files and names, log them
936936

@@ -1149,19 +1149,21 @@ def main(env):
11491149
env.close()
11501150
exit(exitcode=0)
11511151
except WLSTException, e:
1152+
trace("SEVERE","Domain introspection failed with WLST exception: " + str(e))
11521153
print e
1153-
trace("Domain introspection failed with WLST exception:")
11541154
traceback.print_exc()
1155+
dumpStack()
11551156
exit(exitcode=1)
11561157
except UndeclaredThrowableException, f:
1157-
dumpStack()
1158+
trace("SEVERE","Domain introspection failed with undeclared exception: " + str(f))
11581159
print f
1159-
trace("Domain introspection failed with undeclared exception:")
11601160
traceback.print_exc()
1161+
dumpStack()
11611162
exit(exitcode=1)
11621163
except:
1163-
trace("Domain introspection unexpectedly failed:")
1164+
trace("SEVERE","Domain introspection unexpectedly failed:")
11641165
traceback.print_exc()
1166+
dumpStack()
11651167
exit(exitcode=1)
11661168

11671169
main(OfflineWlstEnv())

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
4141
# setup tracing
4242

4343
source ${SCRIPTPATH}/utils.sh
44-
[ $? -ne 0 ] && echo "Error: missing file ${SCRIPTPATH}/utils.sh" && exit 1
44+
[ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit 1
4545

4646
trace "Introspecting the domain"
4747

48-
trace "Current environment:"
49-
env
48+
env | tracePipe "Current environment:"
5049

5150
# set defaults
5251

@@ -68,11 +67,11 @@ checkEnv DOMAIN_UID \
6867
for script_file in "${SCRIPTPATH}/wlst.sh" \
6968
"${SCRIPTPATH}/startNodeManager.sh" \
7069
"${SCRIPTPATH}/introspectDomain.py"; do
71-
[ ! -f "$script_file" ] && trace "Error: missing file '${script_file}'." && exit 1
70+
[ ! -f "$script_file" ] && trace SEVERE "Missing file '${script_file}'." && exit 1
7271
done
7372

7473
for dir_var in DOMAIN_HOME JAVA_HOME WL_HOME MW_HOME ORACLE_HOME; do
75-
[ ! -d "${!dir_var}" ] && trace "Error: missing ${dir_var} directory '${!dir_var}'." && exit 1
74+
[ ! -d "${!dir_var}" ] && trace SEVERE "Missing ${dir_var} directory '${!dir_var}'." && exit 1
7675
done
7776

7877
# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed
@@ -94,7 +93,6 @@ ${SCRIPTPATH}/startNodeManager.sh || exit 1
9493

9594
trace "Running introspector WLST script ${SCRIPTPATH}/introspectDomain.py"
9695

97-
9896
${SCRIPTPATH}/wlst.sh ${SCRIPTPATH}/introspectDomain.py || exit 1
9997

10098
trace "Domain introspection complete"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RETVAL=$(test -f /weblogic-operator/debug/livenessProbeSuccessOverride ; echo $?
1313

1414
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
1515
source ${SCRIPTPATH}/utils.sh
16-
[ $? -ne 0 ] && echo "Error: missing file ${SCRIPTPATH}/utils.sh" && exit $RETVAL
16+
[ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit $RETVAL
1717

1818
# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed:
1919
exportEffectiveDomainHome || exit $RETVAL
@@ -26,12 +26,12 @@ STATEFILE=${DH}/servers/${SN}/data/nodemanager/${SN}.state
2626

2727
if [ "${MOCK_WLS}" != 'true' ]; then
2828
if [ `jps -l | grep -c " weblogic.NodeManager"` -eq 0 ]; then
29-
trace "Error: WebLogic NodeManager process not found."
29+
trace SEVERE "WebLogic NodeManager process not found."
3030
exit $RETVAL
3131
fi
3232
fi
3333
if [ -f ${STATEFILE} ] && [ `grep -c "FAILED_NOT_RESTARTABLE" ${STATEFILE}` -eq 1 ]; then
34-
trace "Error: WebLogic Server state is FAILED_NOT_RESTARTABLE."
34+
trace SEVERE "WebLogic Server state is FAILED_NOT_RESTARTABLE."
3535
exit $RETVAL
3636
fi
3737
exit 0

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ echo $$ > /tmp/monitorLog-pid
1515

1616
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
1717
source ${SCRIPTPATH}/utils.sh
18+
[ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit 1
1819

1920
trace "Monitoring server log file $1 every $2 seconds for selected known log messages."
2021

@@ -27,7 +28,7 @@ while true; do
2728
"For details, please search your pod log or"
2829
"${SERVER_OUT_FILE} for the keyword 'situational'."
2930
)
30-
trace "${msg[*]}"
31+
trace SEVERE "${msg[*]}"
3132
exit 0
3233
fi
3334
if grep -q "BEA-000360" $1 ; then

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
1111
source ${SCRIPTPATH}/utils.sh
12-
[ $? -ne 0 ] && echo "Error: missing file ${SCRIPTPATH}/utils.sh" && exit 1
12+
[ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit 1
1313

1414
# check DOMAIN_HOME for a config/config.xml, reset DOMAIN_HOME if needed:
1515
exportEffectiveDomainHome || exit 1
@@ -26,7 +26,7 @@ if [ `jps -v | grep -c " -Dweblogic.Name=${SERVER_NAME} "` -eq 0 ]; then
2626
fi
2727

2828
if [ ! -f ${STATEFILE} ]; then
29-
trace "Error: WebLogic Server state file not found."
29+
trace "WebLogic Server state file not found."
3030
exit 2
3131
fi
3232

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
4949

5050
source ${SCRIPTPATH}/utils.sh
51-
[ $? -ne 0 ] && echo "Error: missing file ${SCRIPTPATH}/utils.sh" && exit 1
51+
[ $? -ne 0 ] && echo "[SEVERE] Missing file ${SCRIPTPATH}/utils.sh" && exit 1
5252

5353
export WL_HOME="${WL_HOME:-/u01/oracle/wlserver}"
5454

@@ -67,11 +67,11 @@ else
6767
checkEnv SERVER_NAME ADMIN_NAME AS_SERVICE_NAME SERVICE_NAME USER_MEM_ARGS || exit 1
6868
fi
6969

70-
[ ! -d "${JAVA_HOME}" ] && trace "Error: JAVA_HOME directory not found '${JAVA_HOME}'." && exit 1
71-
[ ! -d "${DOMAIN_HOME}" ] && trace "Error: DOMAIN_HOME directory not found '${DOMAIN_HOME}'." && exit 1
72-
[ ! -f "${DOMAIN_HOME}/config/config.xml" ] && trace "Error: '${DOMAIN_HOME}/config/config.xml' not found." && exit 1
73-
[ ! -d "${WL_HOME}" ] && trace "Error: WL_HOME '${WL_HOME}' not found." && exit 1
74-
[ ! -f "${stm_script}" ] && trace "Error: Missing script '${stm_script}' in WL_HOME '${WL_HOME}'." && exit 1
70+
[ ! -d "${JAVA_HOME}" ] && trace SEVERE "JAVA_HOME directory not found '${JAVA_HOME}'." && exit 1
71+
[ ! -d "${DOMAIN_HOME}" ] && trace SEVERE "DOMAIN_HOME directory not found '${DOMAIN_HOME}'." && exit 1
72+
[ ! -f "${DOMAIN_HOME}/config/config.xml" ] && trace SEVERE "'${DOMAIN_HOME}/config/config.xml' not found." && exit 1
73+
[ ! -d "${WL_HOME}" ] && trace SEVERE "WL_HOME '${WL_HOME}' not found." && exit 1
74+
[ ! -f "${stm_script}" ] && trace SEVERE "Missing script '${stm_script}' in WL_HOME '${WL_HOME}'." && exit 1
7575

7676
#
7777
# Helper fn to create a folder
@@ -80,7 +80,7 @@ fi
8080
function createFolder {
8181
mkdir -m 750 -p "$1"
8282
if [ ! -d "$1" ]; then
83-
trace "Unable to create folder '$1'."
83+
trace SEVERE "Unable to create folder '$1'."
8484
exit 1
8585
fi
8686
}
@@ -118,12 +118,12 @@ createFolder ${NODEMGR_HOME}
118118
NODEMGR_LOG_HOME=${NODEMGR_LOG_HOME:-${LOG_HOME:-${NODEMGR_HOME}/${DOMAIN_UID}}}
119119
FAIL_BOOT_ON_SITUATIONAL_CONFIG_ERROR=${FAIL_BOOT_ON_SITUATIONAL_CONFIG_ERROR:-true}
120120

121-
trace "Info: NODEMGR_HOME='${NODEMGR_HOME}'"
122-
trace "Info: LOG_HOME='${LOG_HOME}'"
123-
trace "Info: SERVER_NAME='${SERVER_NAME}'"
124-
trace "Info: DOMAIN_UID='${DOMAIN_UID}'"
125-
trace "Info: NODEMGR_LOG_HOME='${NODEMGR_LOG_HOME}'"
126-
trace "Info: FAIL_BOOT_ON_SITUATIONAL_CONFIG_ERROR='${FAIL_BOOT_ON_SITUATIONAL_CONFIG_ERROR}'"
121+
trace "NODEMGR_HOME='${NODEMGR_HOME}'"
122+
trace "LOG_HOME='${LOG_HOME}'"
123+
trace "SERVER_NAME='${SERVER_NAME}'"
124+
trace "DOMAIN_UID='${DOMAIN_UID}'"
125+
trace "NODEMGR_LOG_HOME='${NODEMGR_LOG_HOME}'"
126+
trace "FAIL_BOOT_ON_SITUATIONAL_CONFIG_ERROR='${FAIL_BOOT_ON_SITUATIONAL_CONFIG_ERROR}'"
127127

128128
createFolder ${NODEMGR_LOG_HOME}
129129

@@ -153,7 +153,7 @@ rm -f ${nodemgr_lck_file}
153153
# is the domain name:
154154
domain_name=`cat ${DOMAIN_HOME}/config/config.xml | sed 's/[[:space:]]//g' | grep '^<name>' | head -1 | awk -F'<|>' '{print $3}'`
155155
if [ "$domain_name" = "" ]; then
156-
trace "Could not determine domain name"
156+
trace SEVERE "Could not determine domain name"
157157
exit 1
158158
fi
159159

@@ -170,7 +170,7 @@ cat <<EOF > ${nm_domains_file}
170170
${domain_name}=${DOMAIN_HOME}
171171
EOF
172172

173-
[ ! $? -eq 0 ] && trace "Failed to create '${nm_domains_file}'." && exit 1
173+
[ ! $? -eq 0 ] && trace SEVERE "Failed to create '${nm_domains_file}'." && exit 1
174174

175175
cat <<EOF > ${nm_props_file}
176176
#Node manager properties
@@ -202,7 +202,7 @@ cat <<EOF > ${nm_props_file}
202202
203203
EOF
204204

205-
[ ! $? -eq 0 ] && trace "Failed to create '${nm_props_file}'." && exit 1
205+
[ ! $? -eq 0 ] && trace SEVERE "Failed to create '${nm_props_file}'." && exit 1
206206

207207
###############################################################################
208208
#
@@ -225,7 +225,8 @@ if [ ! "${SERVER_NAME}" = "introspector" ]; then
225225

226226
if [ -f "$wl_state_file" ]; then
227227
trace "Removing stale file '$wl_state_file'."
228-
rm -f ${wl_state_file} || exit 1
228+
rm -f ${wl_state_file}
229+
[ ! $? -eq 0 ] && trace SEVERE "Could not remove stale file '$wl_state_file'." && exit 1
229230
fi
230231

231232

@@ -248,7 +249,7 @@ Arguments=${USER_MEM_ARGS} -XX\\:+UnlockExperimentalVMOptions -XX\\:+UseCGroupMe
248249
249250
EOF
250251

251-
[ ! $? -eq 0 ] && trace "Failed to create '${wl_props_file}'." && exit 1
252+
[ ! $? -eq 0 ] && trace SEVERE "Failed to create '${wl_props_file}'." && exit 1
252253

253254
if [ ! "${ADMIN_NAME}" = "${SERVER_NAME}" ]; then
254255
admin_protocol="http"
@@ -295,8 +296,10 @@ export JAVA_OPTIONS="${JAVA_OPTIONS} -Dweblogic.RootDirectory=${DOMAIN_HOME}"
295296

296297
trace "Start the nodemanager, node manager home is '${NODEMGR_HOME}', log file is '${nodemgr_log_file}', out file is '${nodemgr_out_file}'."
297298

298-
rm -f ${nodemgr_log_file} || exit 1
299-
rm -f ${nodemgr_out_file} || exit 1
299+
rm -f ${nodemgr_log_file}
300+
[ ! $? -eq 0 ] && trace SEVERE "Could not remove old file '$nodemgr_log_file'." && exit 1
301+
rm -f ${nodemgr_out_file}
302+
[ ! $? -eq 0 ] && trace SEVERE "Could not remove old file '$nodemgr_out_file'." && exit 1
300303

301304
${stm_script} > ${nodemgr_out_file} 2>&1 &
302305

@@ -309,11 +312,11 @@ while [ 1 -eq 1 ]; do
309312
break
310313
fi
311314
if [ $((SECONDS - $start_secs)) -ge $max_wait_secs ]; then
312-
trace "Info: Contents of node manager log '$nodemgr_log_file':"
315+
trace INFO "Contents of node manager log '$nodemgr_log_file':"
313316
cat ${nodemgr_log_file}
314-
trace "Info: Contents of node manager out '$nodemgr_out_file':"
317+
trace INFO "Contents of node manager out '$nodemgr_out_file':"
315318
cat ${NODEMGR_OUT_FILE}
316-
trace "Error: node manager failed to start within $max_wait_secs seconds."
319+
trace SEVERE "Node manager failed to start within $max_wait_secs seconds."
317320
exit 1
318321
fi
319322
wait_count=$((wait_count + 1))

0 commit comments

Comments
 (0)