Skip to content

Commit b8ca68c

Browse files
authored
Merge pull request #657 from oracle/log-home-fixes
Fixes for WebLogic Server and Node Manager .log and .out locations
2 parents c9542be + 8c7b52b commit b8ca68c

File tree

10 files changed

+231
-24
lines changed

10 files changed

+231
-24
lines changed

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/Domain.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ public String getLogHome() {
306306
.orElse(String.format(LOG_HOME_DEFAULT_PATTERN, getDomainUID()));
307307
}
308308

309+
public boolean getLogHomeEnabled() {
310+
return spec.getLogHomeEnabled();
311+
}
312+
309313
public boolean isIncludeServerOutInPodLog() {
310314
return spec.getIncludeServerOutInPodLog();
311315
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ protected boolean isDomainHomeInImage() {
9999
}
100100

101101
String getEffectiveLogHome() {
102+
if (!getDomain().getLogHomeEnabled()) return "";
102103
String logHome = getLogHome();
103104
if (logHome == null || "".equals(logHome.trim())) {
104105
// logHome not specified, use default value

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ protected boolean isDomainHomeInImage() {
158158
}
159159

160160
String getEffectiveLogHome() {
161+
if (!getDomain().getLogHomeEnabled()) return "";
161162
String logHome = getLogHome();
162163
if (logHome == null || "".equals(logHome.trim())) {
163164
// logHome not specified, use default value

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def customizeNodeManagerCreds(self):
797797
self.writeln("</d:security-configuration>")
798798

799799
def customizeDomainLogPath(self):
800-
self.customizeLog(self.env.getDomain().getName())
800+
self.customizeLog(self.env.getDomain().getName(), self.env.getDomain(), true)
801801

802802
def customizeServers(self):
803803
for server in self.env.getDomain().getServers():
@@ -824,7 +824,7 @@ def customizeServer(self, server):
824824
self.writeln("<d:listen-address f:combine-mode=\"replace\">" + listen_address + "</d:listen-address>")
825825
self.undent()
826826
self.writeln("</d:network-access-point>")
827-
self.customizeLog(name)
827+
self.customizeLog(name, server, false)
828828
self.undent()
829829
self.writeln("</d:server>")
830830

@@ -840,18 +840,33 @@ def customizeServerTemplate(self, template):
840840
self.indent()
841841
self.writeln("<d:name>" + name + "</d:name>")
842842
self.writeln("<d:listen-address f:combine-mode=\"replace\">" + listen_address + "</d:listen-address>")
843-
self.customizeLog(server_name_prefix + "${id}")
843+
self.customizeLog(server_name_prefix + "${id}", template, false)
844844
self.undent()
845845
self.writeln("</d:server-template>")
846846

847-
def customizeLog(self, name):
847+
def customizeLog(self, name, bean, isDomainBean):
848848
logs_dir = self.env.getDomainLogHome()
849-
if logs_dir is not None:
850-
self.writeln("<d:log f:combine-mode=\"replace\">")
851-
self.indent()
852-
self.writeln("<d:file-name>" + logs_dir + "/" + name + ".log</d:file-name>")
853-
self.undent()
854-
self.writeln("</d:log>")
849+
if logs_dir is None or len(logs_dir) == 0:
850+
return
851+
852+
logaction=''
853+
fileaction=''
854+
if bean.getLog() is None:
855+
if not isDomainBean:
856+
# don't know why, but don't need to "add" a missing domain log bean, and adding it causes trouble
857+
logaction=' f:combine-mode="add"'
858+
fileaction=' f:combine-mode="add"'
859+
else:
860+
if bean.getLog().getFileName() is None:
861+
fileaction=' f:combine-mode="add"'
862+
else:
863+
fileaction=' f:combine-mode="replace"'
864+
865+
self.writeln("<d:log" + logaction + ">")
866+
self.indent()
867+
self.writeln("<d:file-name" + fileaction + ">" + logs_dir + "/" + name + ".log</d:file-name>")
868+
self.undent()
869+
self.writeln("</d:log>")
855870

856871
class CustomSitConfigIntrospector(SecretManager):
857872

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ checkEnv DOMAIN_UID \
6060
DOMAIN_HOME \
6161
JAVA_HOME \
6262
NODEMGR_HOME \
63-
LOG_HOME \
6463
WL_HOME \
6564
MW_HOME \
6665
|| exit 1

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,26 @@ function createFolder {
7979
fi
8080
}
8181

82+
8283
###############################################################################
8384
#
8485
# Determine WebLogic server log and out files locations
8586
#
8687
# -Dweblogic.Stdout system property is used to tell node manager to send server .out
8788
# file to the configured location
8889
#
89-
server_out_in_pod_log=${SERVER_OUT_IN_POD_LOG:-true}
90-
91-
# server .out file goes to the path specified in LOG_HOME
92-
serverOutFile="${LOG_HOME}/${SERVER_NAME}.out"
9390

94-
export SERVER_OUT_FILE=${serverOutFile}
91+
if [ "${SERVER_NAME}" = "introspector" ]; then
92+
# introspector pod doesn't start a WL server
93+
serverOutOption=""
94+
else
95+
# setup ".out" location for a WL server
96+
serverLogHome="${LOG_HOME:-${DOMAIN_HOME}/servers/${SERVER_NAME}/logs}"
97+
export SERVER_OUT_FILE="${serverLogHome}/${SERVER_NAME}.out"
98+
serverOutOption="-Dweblogic.Stdout=${SERVER_OUT_FILE}"
99+
createFolder "${serverLogHome}"
100+
fi
95101

96-
createFolder ${LOG_HOME}
97102

98103
###############################################################################
99104
#
@@ -108,9 +113,6 @@ NODEMGR_LOG_HOME=${NODEMGR_LOG_HOME:-${LOG_HOME:-${NODEMGR_HOME}/${DOMAIN_UID}}}
108113

109114
createFolder ${NODEMGR_LOG_HOME}
110115

111-
#nodemgr_log_file=${NODEMGR_LOG_HOME}/nodemanager.log
112-
#nodemgr_out_file=${NODEMGR_LOG_HOME}/nodemanager.out
113-
114116
nodemgr_log_file=${NODEMGR_LOG_HOME}/${SERVER_NAME}_nodemanager.log
115117
nodemgr_out_file=${NODEMGR_LOG_HOME}/${SERVER_NAME}_nodemanager.out
116118
nodemgr_lck_file=${NODEMGR_LOG_HOME}/${SERVER_NAME}_nodemanager.log.lck
@@ -228,7 +230,7 @@ RestartInterval=3600
228230
NumberOfFilesLimited=true
229231
FileTimeSpan=24
230232
NMHostName=${SERVICE_NAME}
231-
Arguments=${USER_MEM_ARGS} -XX\\:+UnlockExperimentalVMOptions -XX\\:+UseCGroupMemoryLimitForHeap -Dweblogic.Stdout=${serverOutFile} ${JAVA_OPTIONS}
233+
Arguments=${USER_MEM_ARGS} -XX\\:+UnlockExperimentalVMOptions -XX\\:+UseCGroupMemoryLimitForHeap ${serverOutOption} ${JAVA_OPTIONS}
232234
233235
EOF
234236

operator/src/test/java/oracle/kubernetes/operator/helpers/PodHelperTestBase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,22 @@ public void whenPodCreated_hasPredefinedEnvVariables() {
327327
hasEnvVar("DOMAIN_UID", UID),
328328
hasEnvVar("NODEMGR_HOME", NODEMGR_HOME),
329329
hasEnvVar("SERVER_OUT_IN_POD_LOG", Boolean.toString(INCLUDE_SERVER_OUT_IN_POD_LOG)),
330-
hasEnvVar("LOG_HOME", LOG_HOME + "/" + UID),
330+
hasEnvVar("LOG_HOME", ""),
331331
hasEnvVar("SERVICE_NAME", LegalNames.toServerServiceName(UID, getServerName())),
332332
hasEnvVar("AS_SERVICE_NAME", LegalNames.toServerServiceName(UID, ADMIN_SERVER))));
333333
}
334334

335335
@Test
336336
public void whenPodCreated_withLogHomeSpecified_hasLogHomeEnvVariable() {
337337
final String MY_LOG_HOME = "/shared/mylogs";
338+
domainPresenceInfo.getDomain().getSpec().setLogHomeEnabled(true);
338339
domainPresenceInfo.getDomain().getSpec().setLogHome("/shared/mylogs");
339340
assertThat(getCreatedPodSpecContainer().getEnv(), allOf(hasEnvVar("LOG_HOME", MY_LOG_HOME)));
340341
}
341342

342343
@Test
343344
public void whenPodCreated_withoutLogHomeSpecified_hasDefaultLogHomeEnvVariable() {
345+
domainPresenceInfo.getDomain().getSpec().setLogHomeEnabled(true);
344346
domainPresenceInfo.getDomain().getSpec().setLogHome(null);
345347
assertThat(
346348
getCreatedPodSpecContainer().getEnv(), allOf(hasEnvVar("LOG_HOME", LOG_HOME + "/" + UID)));
@@ -560,7 +562,7 @@ V1Container createPodSpecContainer() {
560562
.addEnvItem(envItem("NODEMGR_HOME", NODEMGR_HOME))
561563
.addEnvItem(
562564
envItem("SERVER_OUT_IN_POD_LOG", Boolean.toString(INCLUDE_SERVER_OUT_IN_POD_LOG)))
563-
.addEnvItem(envItem("LOG_HOME", LOG_HOME + "/" + UID))
565+
.addEnvItem(envItem("LOG_HOME", ""))
564566
.addEnvItem(envItem("SERVICE_NAME", LegalNames.toServerServiceName(UID, getServerName())))
565567
.addEnvItem(envItem("AS_SERVICE_NAME", LegalNames.toServerServiceName(UID, ADMIN_SERVER)))
566568
.livenessProbe(createLivenessProbe())
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
5+
/weblogic-operator/scripts/introspectDomain.sh
6+
7+
# the introspectTest.sh script looks for this exact line:
8+
echo "INTROSPECT_DOMAIN_EXIT=$?"
9+
10+
echo In "$0" SLEEPING
11+
12+
while [ 1 -eq 1 ]; do
13+
sleep 10
14+
done

src/integration-tests/introspector/introspectTest.sh

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ function deployTestScriptConfigMap() {
336336
cp ${SOURCEPATH}/operator/src/main/resources/scripts/traceUtils* ${test_home}/test-scripts || exit 1
337337
cp ${SCRIPTPATH}/createDomain.sh ${test_home}/test-scripts || exit 1
338338
cp ${SCRIPTPATH}/createTestRoot.sh ${test_home}/test-scripts || exit 1
339+
cp ${SCRIPTPATH}/introspectDomainProxy.sh ${test_home}/test-scripts || exit 1
339340

340341
if [ "$CREATE_DOMAIN" = "true" ]; then
341342
rm -f ${test_home}/scripts/createDomain.py
@@ -454,6 +455,7 @@ function deployCreateDomainJob() {
454455
# - this emulates what the operator pod would do prior to start wl-pods
455456
#
456457

458+
# Alternatively, run deployIntrospectJobPod() instead.
457459
function deployIntrospectJob() {
458460
local introspect_output_cm_name=${DOMAIN_UID}-weblogic-domain-introspect-cm
459461

@@ -484,6 +486,105 @@ function deployIntrospectJob() {
484486

485487
}
486488

489+
# Here we emulate the introspect job by directly starting an introspect pod and monitoring it.
490+
# deployIntrospectJob() does about the same thing, but starts a pod via a job
491+
# (Running a pod directly is helpful for debugging.)
492+
493+
function deployIntrospectJobPod() {
494+
local introspect_output_cm_name=${DOMAIN_UID}-weblogic-domain-introspect-cm
495+
local target_yaml=${test_home}/wl-introspect-pod.yaml
496+
local pod_name=${DOMAIN_UID}--introspect-domain-pod
497+
local job_name=$pod_name
498+
499+
trace "Info: Run introspection job, parse its output to files, and put files in configmap '$introspect_output_cm_name'."
500+
501+
# delete anything left over from a previous invocation of this function
502+
503+
kubectl -n $NAMESPACE delete cm $introspect_output_cm_name \
504+
--ignore-not-found \
505+
2>&1 | tracePipe "Info: kubectl output: "
506+
507+
if [ -f "${target_yaml}" ]; then
508+
kubectl -n $NAMESPACE delete -f ${target_yaml} \
509+
--ignore-not-found \
510+
2>&1 | tracePipe "Info: kubectl output: "
511+
rm -f ${target_yaml}
512+
fi
513+
514+
trace "Info: Deploying job pod '$pod_name' and waiting for it to be ready."
515+
516+
(
517+
export SERVER_NAME=introspect
518+
export JOB_NAME=${DOMAIN_UID}--introspect-domain-pod
519+
export JOB_SCRIPT=/test-scripts/introspectDomainProxy.sh
520+
export SERVICE_NAME=`toDNS1123Legal ${DOMAIN_UID}-${server_name}`
521+
export AS_SERVICE_NAME=`toDNS1123Legal ${DOMAIN_UID}-${ADMIN_NAME}`
522+
if [ "${SERVER_NAME}" = "${ADMIN_NAME}" ]; then
523+
export LOCAL_SERVER_DEFAULT_PORT=$ADMIN_PORT
524+
else
525+
export LOCAL_SERVER_DEFAULT_PORT=$MANAGED_SERVER_PORT
526+
fi
527+
${SCRIPTPATH}/util_subst.sh -g wl-introspect-pod.yamlt ${target_yaml} || exit 1
528+
) || exit 1
529+
530+
kubectl create -f ${target_yaml} \
531+
2>&1 | tracePipe "Info: kubectl output: " || exit 1
532+
533+
# Wait for pod to come up successfully
534+
535+
# TBD make the following a helper fn since this is the second place
536+
# we wait for a pod to start, and the code is exactly the same...
537+
local status="0/1"
538+
local startsecs=$SECONDS
539+
local maxsecs=180
540+
tracen "Info: Waiting up to $maxsecs seconds for pod '$pod_name' readiness"
541+
while [ "${status}" != "1/1" ] ; do
542+
if [ $((SECONDS - startsecs)) -gt $maxsecs ]; then
543+
echo
544+
trace "Error: pod $pod_name failed to start within $maxsecs seconds. kubectl describe:"
545+
kubectl -n $NAMESPACE describe pod $pod_name
546+
trace "Error: pod $pod_name failed to start within $maxsecs seconds. kubectl log:"
547+
kubectl -n $NAMESPACE logs $pod_name
548+
exit 1
549+
fi
550+
echo -n "."
551+
sleep 1
552+
status=`kubectl -n $NAMESPACE get pods 2>&1 | egrep $pod_name | awk '{print $2}'`
553+
done
554+
echo " ($((SECONDS - startsecs)) seconds)"
555+
556+
local startSecs=$SECONDS
557+
local maxsecs=30
558+
local exitString=""
559+
tracen "Info: Waiting up to $maxsecs seconds for pod '$pod_name' to run the introspectDomain.py script."
560+
printdots_start
561+
while [ $((SECONDS - startSecs)) -lt $maxsecs ] && [ "$exitString" = "" ]; do
562+
exitString="`kubectl -n $NAMESPACE logs $pod_name 2>&1 | grep INTROSPECT_DOMAIN_EXIT`"
563+
sleep 1
564+
done
565+
printdots_end
566+
if [ "$exitString" = "" ]; then
567+
trace "Error: Introspector timed out, see 'kubectl -n $NAMESPACE logs $pod_name'."
568+
exit 1
569+
fi
570+
if [ ! "$exitString" = "INTROSPECT_DOMAIN_EXIT=0" ]; then
571+
trace "Error: Introspector pod script failed, see 'kubectl -n $NAMESPACE logs $pod_name'."
572+
exit 1
573+
fi
574+
575+
# parse job pod's output files
576+
577+
kubectl -n $NAMESPACE logs $pod_name > ${test_home}/job-${DOMAIN_UID}-introspect-domain-pod-job.out
578+
579+
${SCRIPTPATH}/util_fsplit.sh \
580+
${test_home}/job-${DOMAIN_UID}-introspect-domain-pod-job.out \
581+
${test_home}/jobfiles || exit 1
582+
583+
# put the outputfile in a cm
584+
585+
createConfigMapFromDir $introspect_output_cm_name ${test_home}/jobfiles
586+
}
587+
487588
#############################################################################
488589
#
489590
# Launch pod and wait up to 180 seconds for it to succeed, also launch
@@ -669,7 +770,8 @@ if [ ! "$RERUN_INTROSPECT_ONLY" = "true" ]; then
669770
createTestRootPVDir
670771
deployWebLogic_PV_PVC_and_Secret
671772
deployCreateDomainJob
672-
deployIntrospectJob
773+
#deployIntrospectJob
774+
deployIntrospectJobPod
673775
deployPod ${ADMIN_NAME?}
674776
deploySinglePodService ${ADMIN_NAME?} ${ADMIN_PORT?} 30701
675777
deployPod ${MANAGED_SERVER_NAME_BASE?}1
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
apiVersion: v1
5+
kind: Pod
6+
metadata:
7+
labels:
8+
weblogic.createdByOperator: "true"
9+
weblogic.domainUID: ${DOMAIN_UID}
10+
weblogic.resourceVersion: domain-v2
11+
name: ${JOB_NAME}
12+
namespace: ${NAMESPACE}
13+
spec:
14+
containers:
15+
- command:
16+
- ${JOB_SCRIPT}
17+
env:
18+
- name: NAMESPACE
19+
value: "${NAMESPACE}"
20+
- name: DOMAIN_UID
21+
value: "${DOMAIN_UID}"
22+
- name: DOMAIN_HOME
23+
value: "${DOMAIN_HOME}"
24+
- name: NODEMGR_HOME
25+
value: "${NODEMGR_HOME}"
26+
- name: LOG_HOME
27+
value: "${LOG_HOME}"
28+
- name: CREDENTIALS_SECRET_NAME
29+
value: "${WEBLOGIC_CREDENTIALS_SECRET_NAME}"
30+
image: "${WEBLOGIC_IMAGE_NAME}:${WEBLOGIC_IMAGE_TAG}"
31+
imagePullPolicy: ${WEBLOGIC_IMAGE_PULL_POLICY}
32+
name: weblogic-server
33+
volumeMounts:
34+
- name: weblogic-credentials-volume
35+
mountPath: /weblogic-operator/secrets
36+
readOnly: true
37+
- name: weblogic-domain-cm-volume
38+
mountPath: /weblogic-operator/scripts
39+
readOnly: true
40+
- name: ${DOMAIN_UID}-mycustom-overrides-cm-volume
41+
mountPath: /weblogic-operator/config-overrides
42+
readOnly: true
43+
- name: test-script-cm-volume
44+
mountPath: /test-scripts
45+
readOnly: true
46+
${PVCOMMENT}- mountPath: /shared
47+
${PVCOMMENT} name: weblogic-domain-storage-volume
48+
volumes:
49+
- name: weblogic-credentials-volume
50+
secret:
51+
defaultMode: 420
52+
secretName: ${WEBLOGIC_CREDENTIALS_SECRET_NAME}
53+
- name: weblogic-domain-cm-volume
54+
configMap:
55+
defaultMode: 365
56+
name: weblogic-domain-cm
57+
- name: ${DOMAIN_UID}-mycustom-overrides-cm-volume
58+
configMap:
59+
defaultMode: 365
60+
name: ${DOMAIN_UID}-mycustom-overrides-cm
61+
- name: test-script-cm-volume
62+
configMap:
63+
defaultMode: 365
64+
name: test-script-cm
65+
${PVCOMMENT}- name: weblogic-domain-storage-volume
66+
${PVCOMMENT} persistentVolumeClaim:
67+
${PVCOMMENT} claimName: ${DOMAIN_UID}-weblogic-domain-pvc

0 commit comments

Comments
 (0)