Skip to content

Commit 07dfffa

Browse files
authored
Merge pull request #555 from oracle/develop-feature-mock-wls
Develop feature mock wls
2 parents 2ed4e27 + efc4f69 commit 07dfffa

File tree

7 files changed

+71
-24
lines changed

7 files changed

+71
-24
lines changed

kubernetes/charts/weblogic-operator/templates/_operator-dep.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ spec:
4040
- name: "REMOTE_DEBUG_PORT"
4141
value: {{ .internalDebugHttpPort | quote }}
4242
{{- end }}
43+
{{- if .mockWLS }}
44+
- name: "MOCK_WLS"
45+
value: "true"
46+
{{- end }}
4347
volumeMounts:
4448
- name: "weblogic-operator-cm-volume"
4549
mountPath: "/operator/config"

kubernetes/charts/weblogic-operator/templates/_validate-inputs.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
{{- end -}}
3636
{{- $ignore := include "utils.verifyString" (list $scope "tillerNamespace") -}}
3737
{{- $ignore := include "utils.verifyString" (list $scope "tillerServiceAccount") -}}
38+
{{- $ignore := include "utils.verifyOptionalBoolean" (list $scope "mockWLS") -}}
3839
{{- $ignore:= include "utils.endValidation" $scope -}}
3940
{{- include "operator.operatorVerificationHook" (list $scope "pre-upgrade") }}
4041
{{- include "operator.operatorVerificationHook" (list $scope "pre-install") }}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,12 @@ private V1Container createContainer(TuningParameters tuningParameters) {
650650
.addVolumeMountsItem(readOnlyVolumeMount(SECRETS_VOLUME, SECRETS_MOUNT_PATH))
651651
.addVolumeMountsItem(readOnlyVolumeMount(SCRIPTS_VOLUME, SCRIPTS_MOUNTS_PATH))
652652
.addVolumeMountsItem(readOnlyVolumeMount(DEBUG_CM_VOLUME, DEBUG_CM_MOUNTS_PATH))
653-
.readinessProbe(createReadinessProbe(tuningParameters.getPodTuning()))
654653
.livenessProbe(createLivenessProbe(tuningParameters.getPodTuning()));
655654

655+
if (!mockWLS()) {
656+
v1Container.readinessProbe(createReadinessProbe(tuningParameters.getPodTuning()));
657+
}
658+
656659
for (V1VolumeMount additionalVolumeMount : getAdditionalVolumeMounts()) {
657660
v1Container.addVolumeMountsItem(additionalVolumeMount);
658661
}
@@ -699,6 +702,9 @@ void overrideContainerWeblogicEnvVars(List<V1EnvVar> vars) {
699702
addEnvVar(
700703
vars, "SERVICE_NAME", LegalNames.toServerServiceName(getDomainUID(), getServerName()));
701704
addEnvVar(vars, "AS_SERVICE_NAME", LegalNames.toServerServiceName(getDomainUID(), getAsName()));
705+
if (mockWLS()) {
706+
addEnvVar(vars, "MOCK_WLS", "true");
707+
}
702708
hideAdminUserCredentials(vars);
703709
}
704710

@@ -813,4 +819,8 @@ private int getLivenessProbePeriodSeconds(TuningParameters.PodTuning tuning) {
813819
return Optional.ofNullable(getServerSpec().getLivenessProbe().getPeriodSeconds())
814820
.orElse(tuning.livenessProbePeriodSeconds);
815821
}
822+
823+
private boolean mockWLS() {
824+
return Boolean.getBoolean("mockWLS");
825+
}
816826
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ DN=${DOMAIN_NAME?}
1212
SN=${SERVER_NAME?}
1313
DH=${DOMAIN_HOME?}
1414

15-
STATEFILE=/${DH}/servers/${SN}/data/nodemanager/${SN}.state
15+
STATEFILE=${DH}/servers/${SN}/data/nodemanager/${SN}.state
1616

1717
# if the livenessProbeSuccessOverride file is available, treat failures as success
1818
#
1919
RETVAL=$(test -f /weblogic-operator/debug/livenessProbeSuccessOverride ; echo $?)
2020

21-
if [ `jps -l | grep -c " weblogic.NodeManager"` -eq 0 ]; then
22-
echo "Error: WebLogic NodeManager process not found."
23-
exit $RETVAL
21+
if [ "${MOCK_WLS}" != 'true' ]; then
22+
if [ `jps -l | grep -c " weblogic.NodeManager"` -eq 0 ]; then
23+
echo "Error: WebLogic NodeManager process not found."
24+
exit $RETVAL
25+
fi
2426
fi
2527
if [ -f ${STATEFILE} ] && [ `grep -c "FAILED_NOT_RESTARTABLE" ${STATEFILE}` -eq 1 ]; then
2628
echo "Error: WebLogic Server state is FAILED_NOT_RESTARTABLE."

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

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,40 @@ function copyIfChanged() {
6060
}
6161

6262
#
63+
# Define function to start weblogic
64+
#
65+
66+
function startWLS() {
67+
#
68+
# Start NM
69+
#
70+
71+
trace "Start node manager"
72+
# call script to start node manager in same shell
73+
# $SERVER_OUT_FILE will be set in startNodeManager.sh
74+
. ${SCRIPTPATH}/startNodeManager.sh || exitOrLoop
75+
76+
#
77+
# Start WL Server
78+
#
79+
80+
# TBD We should probably || exit 1 if start-server.py itself fails, and dump NM log to stdout
81+
82+
trace "Start WebLogic Server via the nodemanager"
83+
${SCRIPTPATH}/wlst.sh $SCRIPTPATH/start-server.py
84+
}
85+
86+
function mockWLS() {
87+
88+
trace "Mocking WebLogic Server"
89+
90+
STATEFILE_DIR=${DOMAIN_HOME}/servers/${SERVER_NAME}/data/nodemanager
91+
STATEFILE=${STATEFILE_DIR}/${SERVER_NAME}.state
92+
93+
createFolder $STATEFILE_DIR
94+
echo "RUNNING:Y:N" > $STATEFILE
95+
}
96+
6397
# Define helper fn to copy sit cfg xml files from one dir to another
6498
# $src_dir files are assumed to start with $fil_prefix and end with .xml
6599
# Copied $tgt_dir files are stripped of their $fil_prefix
@@ -144,29 +178,17 @@ copySitCfg /weblogic-operator/introspector ${DOMAIN_HOME}/optconfig/jms 'Sit-C
144178
copySitCfg /weblogic-operator/introspector ${DOMAIN_HOME}/optconfig/jdbc 'Sit-Cfg-JDBC--'
145179
copySitCfg /weblogic-operator/introspector ${DOMAIN_HOME}/optconfig/wldf 'Sit-Cfg-WLDF--'
146180

147-
#
148-
# Start NM
149-
#
150-
151-
trace "Start node manager"
152-
# call script to start node manager in same shell
153-
# $SERVER_OUT_FILE will be set in startNodeManager.sh
154-
. ${SCRIPTPATH}/startNodeManager.sh || exitOrLoop
155-
156-
#
157-
# Start WL Server
158-
#
159-
160-
# TBD We should probably || exitOrLoop if start-server.py itself fails, and dump NM log to stdout
161-
162-
trace "Start WebLogic Server via the nodemanager"
163-
${SCRIPTPATH}/wlst.sh $SCRIPTPATH/start-server.py
181+
if [ "${MOCK_WLS}" == 'true' ]; then
182+
mockWLS
183+
else
184+
startWLS
185+
fi
164186

165187
#
166188
# Wait forever. Kubernetes will monitor this pod via liveness and readyness probes.
167189
#
168190

169-
if [ "${SERVER_OUT_IN_POD_LOG}" == 'true' ] ; then
191+
if [ "${MOCK_WLS}" != 'true' ] && [ "${SERVER_OUT_IN_POD_LOG}" == 'true' ] ; then
170192
trace "Showing the server out file from ${SERVER_OUT_FILE}"
171193
tail -F -n +0 ${SERVER_OUT_FILE} || exitOrLoop
172194
else

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ trace "Stop server ${SERVER_NAME}"
1717

1818
checkEnv SERVER_NAME || exit 1
1919

20+
if [ "${MOCK_WLS}" == 'true' ]; then
21+
exit 0
22+
fi
23+
2024
[ ! -f "${SCRIPTPATH}/wlst.sh" ] && trace "Error: missing file '${SCRIPTPATH}/wlst.sh'." && exit 1
2125

2226
${SCRIPTDIR}/wlst.sh /weblogic-operator/scripts/stop-server.py

src/scripts/operator.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ if [[ ! -z "$JAVA_LOGGING_LEVEL" ]]; then
5454
fi
5555
fi
5656

57+
if [ "${MOCK_WLS}" == 'true' ]; then
58+
MOCKING_WLS="-DmockWLS=true"
59+
fi
60+
5761
LOGGING="-Djava.util.logging.config.file=${LOGGING_CONFIG}"
5862
mkdir -m 777 -p /logs
5963
cp /operator/logstash.conf /logs/logstash.conf
6064
# assumption is that we have mounted a volume on /logs which is also visible to
6165
# the logstash container/pod.
6266

6367
# Start operator
64-
java $DEBUG $LOGGING -jar /operator/weblogic-kubernetes-operator.jar &
68+
java $MOCKING_WLS $DEBUG $LOGGING -jar /operator/weblogic-kubernetes-operator.jar &
6569
PID=$!
6670
wait $PID

0 commit comments

Comments
 (0)