Skip to content

Commit aa036f9

Browse files
jshum2479rjeberhard
authored andcommitted
Use jq to get partial models for sanity check for online update forbidden...
1 parent f0f13fa commit aa036f9

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (c) 2018, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2018, 2024, Oracle and/or its affiliates.
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44

55
#
@@ -185,6 +185,10 @@ doIntrospect() {
185185
if [ $? -ne 0 ] ; then
186186
trace SEVERE "DomainSourceType is 'FromModel', 'unzip' is missing in the image. Please use an image with 'unzip' installed" && exit 1
187187
fi
188+
command -v jq
189+
if [ $? -ne 0 ] ; then
190+
trace SEVERE "DomainSourceType is 'FromModel' and 'onlineUpdate' is enabled, 'jq' is missing in the image. Please use an image with 'jq' installed" && exit 1
191+
fi
188192
createFolder "${DOMAIN_HOME}" "DomainSourceType is 'FromModel' and this is the DOMAIN_HOME directory specified by 'domain.spec.domainHome'." || exit 1
189193
createWLDomain || exit 1
190194
created_domain=$DOMAIN_CREATED

operator/src/main/resources/scripts/model-diff.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2019, 2024, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
#
44
# ------------
@@ -46,8 +46,9 @@ def is_not_safe_for_online_update(self, model, original_model):
4646

4747
def is_safe_diff(self, model, original_model):
4848
"""
49-
Is it a safe difference for update.
49+
Is the difference safe for update.
5050
:param model: diffed model
51+
:param original_model: original model (partial only contain server and template names)
5152
return 0 - always return 0 for V1
5253
"""
5354

@@ -103,48 +104,43 @@ def in_forbidden_list(self, model, original_model):
103104
for key in [ 'Server', 'ServerTemplate']:
104105
# topology.Server|ServerTemplate
105106
if model[_TOPOLOGY].has_key(key):
106-
temp = model[_TOPOLOGY][key]
107-
for server in temp:
107+
# topology.Server or topology.ServerTemplate
108+
svr_list = model[_TOPOLOGY][key]
109+
for server in svr_list:
110+
# topology.Server.item or topology.ServerTemplate.item
108111
# cannot delete server or template
109112
if server.startswith('!'):
110113
return 1
111114
# ok to add
112115
if server not in original_model['topology'][key]:
113116
continue
114117
for not_this in forbidden_network_attributes:
115-
if temp[server].has_key(not_this):
118+
if svr_list[server].has_key(not_this):
116119
return 1
117-
if temp[server].has_key(_NAP):
118-
nap = temp[server][_NAP]
119-
for n in nap:
120+
if svr_list[server].has_key(_NAP):
121+
naps = svr_list[server][_NAP]
122+
for nap in naps:
120123
for not_this in forbidden_network_attributes:
121-
if temp[server].has_key(not_this):
124+
if svr_list[server][_NAP][nap].has_key(not_this):
122125
return 1
123126
# Do not allow any SSL changes
124-
if temp[server].has_key(_SSL):
127+
if svr_list[server].has_key(_SSL):
125128
return 1
126129

127130
return 0
128131

129132

130133
class ModelFileDiffer:
131134

132-
def eval_file(self, file):
133-
true = True
134-
false = False
135-
fh = open(file, 'r')
136-
content = fh.read()
137-
return eval(content)
135+
def eval_string(self, string):
136+
return eval(string)
138137

139138
def compare(self):
140-
original_model = self.eval_file(sys.argv[1])
141-
# past_dict = self.eval_file(sys.argv[2])
139+
original_topology = self.eval_string(sys.argv[1])
140+
net_diff = self.eval_string(sys.argv[2])
142141
obj = ModelDiffer()
143-
if os.path.exists('/tmp/diffed_model.json'):
144-
net_diff = self.eval_file('/tmp/diffed_model.json')
145-
else:
146-
net_diff = {}
147-
return obj.is_safe_diff(net_diff, original_model)
142+
return obj.is_safe_diff(net_diff, original_topology)
143+
148144

149145
def debug(format_string, *arguments):
150146
if os.environ.has_key('DEBUG_INTROSPECT_JOB'):

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ diff_model() {
587587
trace "Entering diff_model"
588588
# wdt shell script or logFileRotate may return non-zero code if trap is on, then it will go to trap instead
589589
# temporarily disable it
590-
stop_trap
591590

591+
stop_trap
592592
export __WLSDEPLOY_STORE_MODEL__=1
593593
# $1 - new model, $2 original model
594594

@@ -620,17 +620,36 @@ diff_model() {
620620
fi
621621
fi
622622

623+
# Checking whether domain, rcu credentials have been changed - needed for offline
624+
# and also incompatible changes for online update.
625+
623626
if [ "${MERGED_MODEL_ENVVARS_SAME}" == "false" ] ; then
624-
# Generate diffed model update compatibility result
627+
# Generate diffed model update compatibility result, use partial model to avoid loading large model
625628
local ORACLE_SERVER_DIR=${ORACLE_HOME}/wlserver
626629
local JAVA_PROPS="-Dpython.cachedir.skip=true ${JAVA_PROPS}"
627630
local JAVA_PROPS="-Dpython.path=${ORACLE_SERVER_DIR}/common/wlst/modules/jython-modules.jar/Lib ${JAVA_PROPS}"
628631
local JAVA_PROPS="-Dpython.console= ${JAVA_PROPS} -Djava.security.egd=file:/dev/./urandom"
629632
local CP=${ORACLE_SERVER_DIR}/server/lib/weblogic.jar
633+
# Get partial models for sanity check for forbidden attribute change
634+
local SERVER_OR_SERVERTEMPLATES_NAMES=$(jq '{ topology: { Server: (.topology.Server | with_entries(.value = {})),
635+
ServerTemplate: (if .topology.ServerTemplate then (.topology.ServerTemplate | with_entries(.value = {})) else empty end)
636+
}} | if .topology.ServerTemplate == {} then del(.topology.ServerTemplate) else . end' $2)
637+
rc=$?
638+
if [ $rc -ne 0 ] ; then
639+
trace SEVERE "Failed to extract server names from original model using jq "$rc
640+
exitOrLoop
641+
fi
642+
local PARTIAL_DIFFED_MODEL=$(jq '{domainInfo: .domainInfo, topology: .topology} | with_entries(select(.value != null))' /tmp/diffed_model.json)
643+
rc=$?
644+
if [ $rc -ne 0 ] ; then
645+
trace SEVERE "Failed to extract domainInfo and topology from delta model using jq "$rc
646+
exitOrLoop
647+
fi
648+
630649
${JAVA_HOME}/bin/java -cp ${CP} \
631650
${JAVA_PROPS} \
632651
org.python.util.jython \
633-
${SCRIPTPATH}/model-diff.py $2 > ${WDT_OUTPUT} 2>&1
652+
${SCRIPTPATH}/model-diff.py "$SERVER_OR_SERVERTEMPLATES_NAMES" "$PARTIAL_DIFFED_MODEL" > ${WDT_OUTPUT} 2>&1
634653
if [ $? -ne 0 ] ; then
635654
trace SEVERE "Failed to compare models. Error output:"
636655
cat ${WDT_OUTPUT}
@@ -640,7 +659,6 @@ diff_model() {
640659

641660
wdtRotateAndCopyLogFile "${WDT_COMPARE_MODEL_LOG}"
642661

643-
# restore trap
644662
start_trap
645663

646664
trace "Exiting diff_model"

0 commit comments

Comments
 (0)