Skip to content

Commit c17b72c

Browse files
committed
Read config.xml directly to check for Coherence intead of using readDomain
1 parent d34be8f commit c17b72c

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

operator/src/main/resources/scripts/stop-server.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at
33
# http://oss.oracle.com/licenses/upl.
44

5-
# This the the preStop hook script (stopServer.sh) that is specified by the domain resource.
6-
# This script will be called by Kubernetes before it kills a pod. Kuberentes will kill
7-
# the pod once this script returns OR when the grace period timeout expires
8-
# (see Operator shutdown.timeoutSeconds)
5+
# This is called by the preStop hook script (stopServer.sh) that is specified
6+
# by the WL operator for WL pod resource. Before killing a pod, Kubernetes calls
7+
# the preStop hook script. Kubernetes will then kill the pod once the script returns
8+
# or when the grace period timeout expires(see Operator shutdown.timeoutSeconds)
99
#
1010
# This script shuts down the local server running in the container (admin or managed).
1111
# There are 2 main scenarios, a domain with a Coherence cluster and one without.
@@ -26,6 +26,7 @@
2626
import traceback
2727
import base64
2828
import time as systime
29+
import re
2930

3031
# Get an ENV var
3132
def getEnvVar(var):
@@ -56,41 +57,37 @@ def shutdownUsingNodeManager(domainName, domainDir):
5657
raise
5758

5859

59-
# Check if Coherence exists using wlst offline
60+
# Return True if Coherence exists
6061
def doesCoherenceExist():
6162
try:
62-
readDomain(domain_path)
63-
exists = checkCoherenceClusterExist()
63+
f = open(domain_path+'/config/config.xml', 'r')
64+
configData = f.read()
65+
f.close()
66+
return checkCoherenceClusterExist(configData)
6467
except:
65-
print('Shutdown: Exception reading domain offline, assume Coherence exists')
68+
print('Shutdown: Exception reading config.xml, assume Coherence exists')
6669
return True
67-
try:
68-
closeDomain()
69-
except:
70-
pass
71-
return exists
7270

73-
# Check if there is a CoherenceClusterSystemResource. This will indicate that the domain is
71+
72+
# Return True if there is a CoherenceClusterSystemResource. This will indicate that the domain is
7473
# using Coherence
75-
def checkCoherenceClusterExist():
74+
def checkCoherenceClusterExist(configData):
7675
try:
77-
cd('/')
78-
if ls().find('CoherenceClusterSystemResource') == -1:
79-
return False
80-
cd('CoherenceClusterSystemResource')
81-
val = ls()
82-
if (val is None) or len(val.strip()) == 0:
83-
print('Shutdown: This domain does not have a CoherenceClusterSystemResource')
76+
# remove all whitespace include CR
77+
spacelessData = ''.join(configData.split())
78+
79+
ELEMENT_NAME = "coherence-cluster-system-resource"
80+
x = re.search('<coherence-cluster-system-resource>[\s\S]*?<\/coherence-cluster-system-resource>',spacelessData)
81+
if (x is None):
8482
return False
8583
else:
86-
print('Shutdown: This domain has CoherenceClusterSystemResource ' + val)
87-
return True
84+
first, last = x.span()
85+
# check if the element value is empty (add 5 for the XML slash and 4 angle brackets)
86+
return (last-first-5) > (2 * len(ELEMENT_NAME))
8887
except:
89-
# Exception will occur if CoherenceClusterSystemResource is missing
9088
traceback.print_exc(file=sys.stdout)
91-
dumpStack()
92-
print('Shutdown: Exception getting CoherenceClusterSystemResource')
93-
return False
89+
print('Shutdown: Exception processing config data, assume Coherence exists')
90+
return True
9491

9592

9693
# Coherence exists and we cannot connect to the admin server. To be on
@@ -272,6 +269,5 @@ def waitUntilServiceSafeToShutdown(objectName):
272269
except:
273270
exit(2)
274271

275-
276272
# Exit WLST
277273
exit()

0 commit comments

Comments
 (0)