1
1
"""
2
- Copyright (c) 2021, 2022 , Oracle and/or its affiliates.
2
+ Copyright (c) 2021, 2023 , Oracle and/or its affiliates.
3
3
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
"""
5
5
from java .util import Properties
6
6
7
- from oracle .weblogic .deploy .aliases import AliasException
8
7
from oracle .weblogic .deploy .util import PyOrderedDict
9
8
10
9
from wlsdeploy .aliases import alias_utils
11
10
from wlsdeploy .aliases .alias_constants import ALIAS_LIST_TYPES
12
11
from wlsdeploy .aliases .alias_constants import PROPERTIES
13
12
from wlsdeploy .aliases .location_context import LocationContext
14
13
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
16
15
from wlsdeploy .aliases .model_constants import LIBRARY
17
16
from wlsdeploy .logging .platform_logger import PlatformLogger
18
17
from wlsdeploy .util import dictionary_utils
19
18
from wlsdeploy .util import model_helper
20
19
import wlsdeploy .util .unicode_helper as str_helper
21
20
21
+
22
22
class ModelComparer (object ):
23
23
"""
24
24
Class for comparing two WDT models.
@@ -308,18 +308,8 @@ def _compare_attribute_sc(self, current_value, past_value, location, key, change
308
308
if current_value != past_value :
309
309
if type (current_value ) == list :
310
310
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 )
323
313
324
314
elif isinstance (current_value , Properties ):
325
315
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
339
329
"""
340
330
if current_value != past_value :
341
331
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 :
343
341
current_list = alias_utils .create_list (current_value , 'WLSDPLY-08001' )
344
342
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 )
362
344
363
345
elif attribute_type == PROPERTIES :
364
346
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):
396
378
if property_dict :
397
379
change_folder [key ] = property_dict
398
380
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
+
399
407
def _check_key (self , key , location ):
400
408
"""
401
409
Determine if the specified key and location will be compared.
@@ -405,11 +413,35 @@ def _check_key(self, key, location):
405
413
"""
406
414
_method_name = '_check_key'
407
415
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 )
410
418
return False
411
419
return True
412
420
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
+
413
445
def _finalize_folder (self , current_folder , past_folder , change_folder , location ):
414
446
"""
415
447
Perform any adjustments after a folder has been evaluated.
0 commit comments