|
2 | 2 | # Licensed under the Universal Permissive License v 1.0 as shown at
|
3 | 3 | # http://oss.oracle.com/licenses/upl.
|
4 | 4 |
|
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) |
9 | 9 | #
|
10 | 10 | # This script shuts down the local server running in the container (admin or managed).
|
11 | 11 | # There are 2 main scenarios, a domain with a Coherence cluster and one without.
|
|
26 | 26 | import traceback
|
27 | 27 | import base64
|
28 | 28 | import time as systime
|
| 29 | +import re |
29 | 30 |
|
30 | 31 | # Get an ENV var
|
31 | 32 | def getEnvVar(var):
|
@@ -56,41 +57,37 @@ def shutdownUsingNodeManager(domainName, domainDir):
|
56 | 57 | raise
|
57 | 58 |
|
58 | 59 |
|
59 |
| -# Check if Coherence exists using wlst offline |
| 60 | +# Return True if Coherence exists |
60 | 61 | def doesCoherenceExist():
|
61 | 62 | 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) |
64 | 67 | except:
|
65 |
| - print('Shutdown: Exception reading domain offline, assume Coherence exists') |
| 68 | + print('Shutdown: Exception reading config.xml, assume Coherence exists') |
66 | 69 | return True
|
67 |
| - try: |
68 |
| - closeDomain() |
69 |
| - except: |
70 |
| - pass |
71 |
| - return exists |
72 | 70 |
|
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 |
74 | 73 | # using Coherence
|
75 |
| -def checkCoherenceClusterExist(): |
| 74 | +def checkCoherenceClusterExist(configData): |
76 | 75 | 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): |
84 | 82 | return False
|
85 | 83 | 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)) |
88 | 87 | except:
|
89 |
| - # Exception will occur if CoherenceClusterSystemResource is missing |
90 | 88 | 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 |
94 | 91 |
|
95 | 92 |
|
96 | 93 | # Coherence exists and we cannot connect to the admin server. To be on
|
@@ -272,6 +269,5 @@ def waitUntilServiceSafeToShutdown(objectName):
|
272 | 269 | except:
|
273 | 270 | exit(2)
|
274 | 271 |
|
275 |
| - |
276 | 272 | # Exit WLST
|
277 | 273 | exit()
|
0 commit comments