Skip to content

Commit 5e33bfb

Browse files
authored
Allow whitespace variations in comparison of startup JVM arguments (#1376)
* Allow whitespace variations in comparison of startup JVM arguments * Cleaned up imports
1 parent afe9c10 commit 5e33bfb

File tree

3 files changed

+71
-48
lines changed

3 files changed

+71
-48
lines changed

core/src/main/python/compare_model.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2020, 2023, 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
# ------------
@@ -14,23 +14,22 @@
1414
import os
1515
import sets
1616
import sys
17-
import traceback
1817

1918
import java.io.File as JFile
2019
import java.io.FileOutputStream as JFileOutputStream
2120
import java.io.IOException as JIOException
2221
import java.io.PrintWriter as JPrintWriter
2322
from java.lang import System
23+
2424
from oracle.weblogic.deploy.compare import CompareException
2525
from oracle.weblogic.deploy.exception import ExceptionHelper
2626
from oracle.weblogic.deploy.util import CLAException
2727
from oracle.weblogic.deploy.util import FileUtils
28-
from oracle.weblogic.deploy.util import PyWLSTException
28+
from oracle.weblogic.deploy.util import TranslateException
2929
from oracle.weblogic.deploy.util import VariableException
3030
from oracle.weblogic.deploy.validate import ValidateException
3131
from oracle.weblogic.deploy.yaml import YamlException
3232

33-
import oracle.weblogic.deploy.util.TranslateException as TranslateException
3433
from wlsdeploy.aliases.aliases import Aliases
3534
from wlsdeploy.aliases.wlst_modes import WlstModes
3635
from wlsdeploy.exception import exception_helper
@@ -326,14 +325,6 @@ def main(model_context):
326325
except CompareException, ce:
327326
_exit_code = ExitCode.ERROR
328327
__logger.severe('WLSDPLY-05704', ce.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
329-
except PyWLSTException, pe:
330-
_exit_code = ExitCode.ERROR
331-
__logger.severe('WLSDPLY-05704', pe.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
332-
except:
333-
exc_type, exc_obj, exc_tb = sys.exc_info()
334-
_exit_code = ExitCode.ERROR
335-
ee_string = traceback.format_exception(exc_type, exc_obj, exc_tb)
336-
__logger.severe('WLSDPLY-05704', ee_string)
337328

338329
__logger.exiting(class_name=_class_name, method_name=_method_name, result=_exit_code)
339330
return _exit_code

core/src/main/python/wlsdeploy/tool/compare/model_comparer.py

Lines changed: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
"""
2-
Copyright (c) 2021, 2022, Oracle and/or its affiliates.
2+
Copyright (c) 2021, 2023, 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
from java.util import Properties
66

7-
from oracle.weblogic.deploy.aliases import AliasException
87
from oracle.weblogic.deploy.util import PyOrderedDict
98

109
from wlsdeploy.aliases import alias_utils
1110
from wlsdeploy.aliases.alias_constants import ALIAS_LIST_TYPES
1211
from wlsdeploy.aliases.alias_constants import PROPERTIES
1312
from wlsdeploy.aliases.location_context import LocationContext
1413
from wlsdeploy.aliases.model_constants import APPLICATION
15-
from wlsdeploy.aliases.model_constants import KUBERNETES
14+
from wlsdeploy.aliases.model_constants import CRD_MODEL_SECTIONS
1615
from wlsdeploy.aliases.model_constants import LIBRARY
1716
from wlsdeploy.logging.platform_logger import PlatformLogger
1817
from wlsdeploy.util import dictionary_utils
1918
from wlsdeploy.util import model_helper
2019
import wlsdeploy.util.unicode_helper as str_helper
2120

21+
2222
class ModelComparer(object):
2323
"""
2424
Class for comparing two WDT models.
@@ -308,18 +308,8 @@ def _compare_attribute_sc(self, current_value, past_value, location, key, change
308308
if current_value != past_value:
309309
if type(current_value) == list:
310310
current_list = list(current_value)
311-
previous_list = list(past_value)
312-
313-
change_list = list(previous_list)
314-
for item in current_list:
315-
if item in previous_list:
316-
change_list.remove(item)
317-
else:
318-
change_list.append(item)
319-
for item in previous_list:
320-
if item not in current_list:
321-
change_list.remove(item)
322-
change_list.append(model_helper.get_delete_name(item))
311+
past_list = list(past_value)
312+
self._compare_lists(current_list, past_list, key, change_folder)
323313

324314
elif isinstance(current_value, Properties):
325315
self._compare_properties(current_value, past_value, key, change_folder)
@@ -339,26 +329,18 @@ def _compare_attribute(self, current_value, past_value, location, key, change_fo
339329
"""
340330
if current_value != past_value:
341331
attribute_type = self._aliases.get_model_attribute_type(location, key)
342-
if attribute_type in ALIAS_LIST_TYPES:
332+
if self._is_jvm_args_key(key, location):
333+
current_text = self._get_jvm_args_text(current_value)
334+
previous_text = self._get_jvm_args_text(past_value)
335+
if current_text != previous_text:
336+
comment = key + ": '" + str_helper.to_string(previous_text) + "'"
337+
change_folder.addComment(key, comment)
338+
change_folder[key] = current_text
339+
340+
elif attribute_type in ALIAS_LIST_TYPES:
343341
current_list = alias_utils.create_list(current_value, 'WLSDPLY-08001')
344342
previous_list = alias_utils.create_list(past_value, 'WLSDPLY-08000')
345-
346-
change_list = list(previous_list)
347-
for item in current_list:
348-
if item in previous_list:
349-
change_list.remove(item)
350-
else:
351-
change_list.append(item)
352-
for item in previous_list:
353-
if item not in current_list:
354-
change_list.remove(item)
355-
change_list.append(model_helper.get_delete_name(item))
356-
357-
current_text = ','.join(current_list)
358-
previous_text = ','.join(previous_list)
359-
comment = key + ": '" + previous_text + "' -> '" + current_text + "'"
360-
change_folder.addComment(key, comment)
361-
change_folder[key] = ','.join(change_list)
343+
self._compare_lists(current_list, previous_list, key, change_folder)
362344

363345
elif attribute_type == PROPERTIES:
364346
self._compare_properties(current_value, past_value, key, change_folder)
@@ -396,6 +378,32 @@ def _compare_properties(self, current_value, past_value, key, change_folder):
396378
if property_dict:
397379
change_folder[key] = property_dict
398380

381+
def _compare_lists(self, current_list, past_list, key, change_folder):
382+
"""
383+
Compare values of a list attribute from the current and past folders.
384+
The change value and any comments will be added to the change folder.
385+
:param current_list: the value from the current model
386+
:param past_list: the value from the past model
387+
:param key: the key of the attribute
388+
:param change_folder: the folder in the change model to be updated
389+
"""
390+
change_list = list(past_list)
391+
for item in current_list:
392+
if item in past_list:
393+
change_list.remove(item)
394+
else:
395+
change_list.append(item)
396+
for item in past_list:
397+
if item not in current_list:
398+
change_list.remove(item)
399+
change_list.append(model_helper.get_delete_name(item))
400+
401+
current_text = ','.join(current_list)
402+
previous_text = ','.join(past_list)
403+
comment = key + ": '" + previous_text + "' -> '" + current_text + "'"
404+
change_folder.addComment(key, comment)
405+
change_folder[key] = ','.join(change_list)
406+
399407
def _check_key(self, key, location):
400408
"""
401409
Determine if the specified key and location will be compared.
@@ -405,11 +413,35 @@ def _check_key(self, key, location):
405413
"""
406414
_method_name = '_check_key'
407415

408-
if (location is None) and (key == KUBERNETES):
409-
self._logger.info('WLSDPLY-05713', KUBERNETES, class_name=self._class_name, method_name=_method_name)
416+
if (location is None) and (key in CRD_MODEL_SECTIONS):
417+
self._logger.info('WLSDPLY-05713', key, class_name=self._class_name, method_name=_method_name)
410418
return False
411419
return True
412420

421+
def _is_jvm_args_key(self, key, location):
422+
"""
423+
Determine if the specified attribute requires special JVM argument processing.
424+
:param key: the key to be checked
425+
:param location: the location to be checked
426+
:return: True if the attribute requires special processing, False otherwise
427+
"""
428+
set_method_info = self._aliases.get_model_mbean_set_method_attribute_names_and_types(location)
429+
return key in set_method_info and set_method_info[key]['set_method'] == 'set_jvm_args'
430+
431+
def _get_jvm_args_text(self, value):
432+
"""
433+
Return the normalized text for the specified JVM arguments value.
434+
These attributes have special handling for create and deploy,
435+
so list delimiter comparison will not cover all the cases.
436+
:param value: the value to be converted, may be a list, string, or None
437+
:return: the normalized text value
438+
"""
439+
if isinstance(value, basestring):
440+
value = value.split()
441+
if isinstance(value, list):
442+
return ' '.join(value)
443+
return value
444+
413445
def _finalize_folder(self, current_folder, past_folder, change_folder, location):
414446
"""
415447
Perform any adjustments after a folder has been evaluated.

core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/ServerTemplate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@
10421042
"ClassPath": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "ClassPath", "wlst_path": "WP001", "default_value": null, "wlst_type": "delimited_string[path_separator]", "preferred_model_type": "delimited_string", "uses_path_tokens": "true"} ],
10431043
"JavaHome": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "JavaHome", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "uses_path_tokens": "true"} ],
10441044
"JavaVendor": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "JavaVendor", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ],
1045-
"Arguments": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "Arguments", "wlst_path": "WP001", "default_value": null, "wlst_type": "delimited_string[space]" } ],
1045+
"Arguments": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "Arguments", "wlst_path": "WP001", "default_value": null, "wlst_type": "delimited_string[space]", "set_method": "MBEAN.set_jvm_args"} ],
10461046
"MaxRestartCount": [ {"version": "[12.1.2,)", "wlst_mode": "offline", "wlst_name": "MaxRestartCount", "wlst_path": "WP001", "default_value": 0, "wlst_type": "integer" } ],
10471047
"MwHome": [ {"version": "[12.1.3,)", "wlst_mode": "both", "wlst_name": "${MwHome:MWHome}", "wlst_path": "WP001", "default_value": null, "wlst_type": "string", "uses_path_tokens": "true"} ],
10481048
"Notes": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "Notes", "wlst_path": "WP001", "default_value": null, "wlst_type": "string" } ],

0 commit comments

Comments
 (0)