Skip to content

Commit 9ff7597

Browse files
authored
Allow removal of list items with ! notation (#732)
* JIRA WDT-469 - Allow deletion of item from list attributes * JIRA WDT-469 - Allow deletion of item from MBean list attributes * JIRA WDT-469 - Use attribute setter method for offline targets; check for empty list * JIRA WDT-469 - Use attribute setter method for all offline targets * JIRA WDT-469 - Allow undeployment of apps from deleted targets * JIRA WDT-469 - Allow undeployment of libraries from deleted targets * JIRA WDT-469 - Merge from master
1 parent 39d6592 commit 9ff7597

28 files changed

+329
-171
lines changed

core/src/main/python/wlsdeploy/aliases/alias_utils.py

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation 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
import copy
66
from org.python.modules import jarray
77
import re
8-
from sets import Set
98
from array import array
109

1110
from java.io import File
@@ -24,6 +23,7 @@
2423
from oracle.weblogic.deploy.aliases import VersionUtils
2524

2625
from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
26+
from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER
2727
from wlsdeploy.exception import exception_helper
2828
from wlsdeploy.logging.platform_logger import PlatformLogger
2929

@@ -51,39 +51,50 @@
5151
from wlsdeploy.aliases.alias_constants import WLST_READ_TYPE
5252
from wlsdeploy.aliases.alias_constants import WLST_TYPE
5353
from wlsdeploy.aliases.alias_constants import WLST_SUBFOLDERS_PATH
54+
from wlsdeploy.util import model_helper
5455

5556
_class_name = 'alias_utils'
5657
_logger = PlatformLogger('wlsdeploy.aliases')
5758
_windows_path_regex = re.compile(r'^[a-zA-Z]:[\\/].*')
5859

5960

60-
def merge_model_and_existing_lists(model_list, existing_list, string_list_separator_char=','):
61+
def merge_model_and_existing_lists(model_list, existing_list, location_path="(unknown)", attribute_name="(unknown)"):
6162
"""
6263
Merge the two lists so that the resulting list contains all of the elements in both lists one time.
63-
:param model_list: the list to merge
64-
:param existing_list: the existing list
65-
:param string_list_separator_char: the character separator to use to split the lists if either list is a string
64+
:param model_list: the list to merge, possibly a string or None
65+
:param existing_list: the existing list, possibly a string or None
66+
:param location_path: optional, the path of the attribute location, for logging
67+
:param attribute_name: optional, the attribute name, for logging
6668
:return: the merged list as a list or a string, depending on the type of the model_list
6769
:raises: DeployException: if either list is not either a string or a list
6870
"""
6971
_method_name = 'merge_model_and_existing_lists'
7072

71-
_logger.entering(model_list, existing_list, string_list_separator_char,
72-
class_name=_class_name, method_name=_method_name)
73-
if existing_list is None or len(existing_list) == 0:
74-
result = model_list
75-
elif model_list is None or len(model_list) == 0:
76-
result = existing_list
77-
if isinstance(model_list, basestring) and not isinstance(existing_list, basestring):
78-
result = string_list_separator_char.join(existing_list)
73+
_logger.entering(model_list, existing_list, location_path, attribute_name, class_name=_class_name,
74+
method_name=_method_name)
75+
76+
if model_list is None:
77+
result_is_string = isinstance(existing_list, basestring)
7978
else:
80-
model_list_is_string = isinstance(model_list, basestring)
81-
model_set = _create_set(model_list, string_list_separator_char, 'WLSDPLY-08000')
82-
existing_set = _create_set(existing_list, string_list_separator_char, 'WLSDPLY-08001')
79+
result_is_string = isinstance(model_list, basestring)
80+
81+
result = create_list(existing_list, 'WLSDPLY-08001')
82+
model_iterator = create_list(model_list, 'WLSDPLY-08000')
83+
84+
for item in model_iterator:
85+
if model_helper.is_delete_name(item):
86+
item_name = model_helper.get_delete_item_name(item)
87+
if item_name in result:
88+
result.remove(item_name)
89+
else:
90+
_logger.warning('WLSDPLY-08022', item_name, attribute_name, location_path, class_name=_class_name,
91+
method_name=_method_name)
92+
93+
elif item not in result:
94+
result.append(item)
8395

84-
result = list(existing_set.union(model_set))
85-
if model_list_is_string:
86-
result = string_list_separator_char.join(result)
96+
if result_is_string:
97+
result = MODEL_LIST_DELIMITER.join(result)
8798

8899
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
89100
return result
@@ -784,6 +795,31 @@ def get_dictionary_mode(alias_dict):
784795
return alias_dict[WLST_MODE]
785796
return None
786797

798+
799+
def create_list(list_value, message_key):
800+
"""
801+
Create a list from the specified list value.
802+
:param list_value: the model value to be examined, should be a string, list, or array
803+
:param message_key: the key of the message to display if list item type is invalid
804+
:return: a list containing the list value's elements
805+
:raises: DeployException: if either list is not either a string or a list
806+
"""
807+
_method_name = '_create_list'
808+
809+
item_type = type(list_value)
810+
if (list_value is None) or (len(list_value) == 0):
811+
item_list = []
812+
elif isinstance(list_value, basestring):
813+
item_list = [x.strip() for x in list_value.split(MODEL_LIST_DELIMITER)]
814+
elif item_type is list or item_type is array:
815+
item_list = list(list_value)
816+
else:
817+
ex = exception_helper.create_deploy_exception(message_key, str(item_type))
818+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
819+
raise ex
820+
821+
return item_list
822+
787823
###############################################################################
788824
# Private functions #
789825
###############################################################################
@@ -1104,27 +1140,3 @@ def _create_mbean_array(iterable, subtype):
11041140
myarray[idx] = element
11051141
idx += 1
11061142
return myarray
1107-
1108-
1109-
def _create_set(list_item, string_list_separator_char, message_key):
1110-
"""
1111-
Create a set object from the specified list item.
1112-
:param list_item: the item to be examined, should be a string, list, or array
1113-
:param string_list_separator_char: the character separator to use to split the lists if either list is a string
1114-
:param message_key: the key of the message to display if list item type is invalid
1115-
:return: a set containing the list item's elements
1116-
:raises: DeployException: if either list is not either a string or a list
1117-
"""
1118-
_method_name = '_create_set'
1119-
1120-
item_type = type(list_item)
1121-
if item_type in [str, unicode]:
1122-
item_set = Set([x.strip() for x in list_item.split(string_list_separator_char)])
1123-
elif item_type is list or item_type is array:
1124-
item_set = Set(list_item)
1125-
else:
1126-
ex = exception_helper.create_deploy_exception(message_key, str(item_type))
1127-
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
1128-
raise ex
1129-
1130-
return item_set

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,16 +512,21 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
512512
model_val = TypeUtils.convertToType(PROPERTIES, model_attribute_value)
513513
existing_val = TypeUtils.convertToType(PROPERTIES, existing_wlst_value)
514514
merged_value = alias_utils.merge_model_and_existing_properties(model_val, existing_val)
515-
elif merge and existing_wlst_value is not None and len(existing_wlst_value) > 0:
515+
elif merge:
516516
model_val = alias_utils.convert_to_type(LIST, model_attribute_value,
517517
delimiter=MODEL_LIST_DELIMITER)
518518

519519
_read_type, read_delimiter = \
520520
alias_utils.compute_read_data_type_and_delimiter_from_attribute_info(
521521
attribute_info, existing_wlst_value)
522+
522523
existing_val = alias_utils.convert_to_type(LIST, existing_wlst_value,
523524
delimiter=read_delimiter)
524-
merged_value = alias_utils.merge_model_and_existing_lists(model_val, existing_val)
525+
location_path = self.get_model_folder_path(location)
526+
merged_value = \
527+
alias_utils.merge_model_and_existing_lists(model_val, existing_val,
528+
location_path=location_path,
529+
attribute_name=model_attribute_name)
525530
else:
526531
merged_value = model_attribute_value
527532

0 commit comments

Comments
 (0)