11"""
2- Copyright (c) 2021, 2022 , Oracle and/or its affiliates.
2+ Copyright (c) 2021, 2023 , Oracle and/or its affiliates.
33Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44"""
55from java .util import Properties
66
7- from oracle .weblogic .deploy .aliases import AliasException
87from oracle .weblogic .deploy .util import PyOrderedDict
98
109from wlsdeploy .aliases import alias_utils
1110from wlsdeploy .aliases .alias_constants import ALIAS_LIST_TYPES
1211from wlsdeploy .aliases .alias_constants import PROPERTIES
1312from wlsdeploy .aliases .location_context import LocationContext
1413from wlsdeploy .aliases .model_constants import APPLICATION
15- from wlsdeploy .aliases .model_constants import KUBERNETES
14+ from wlsdeploy .aliases .model_constants import CRD_MODEL_SECTIONS
1615from wlsdeploy .aliases .model_constants import LIBRARY
1716from wlsdeploy .logging .platform_logger import PlatformLogger
1817from wlsdeploy .util import dictionary_utils
1918from wlsdeploy .util import model_helper
2019import wlsdeploy .util .unicode_helper as str_helper
2120
21+
2222class 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.
0 commit comments