Skip to content

Commit eb7c42c

Browse files
committed
Use null for default_value; use __NULL__ in curly-brace default_value; flatten default value structure
1 parent fcc0578 commit eb7c42c

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, 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
These constants are internal to the aliases module and should not be used, as they are not part of the public API.
@@ -10,8 +10,8 @@
1010
ATTRIBUTES = 'attributes'
1111
CHILD_FOLDERS_TYPE = 'child_folders_type'
1212
CONTAINS = 'contains'
13-
DEFAULT = 'default'
1413
DEFAULT_NAME_VALUE = 'default_name_value'
14+
DEFAULT_VALUE = 'default_value'
1515
FLATTENED_FOLDER_DATA = 'flattened_folder_data'
1616
FOLDERS = 'folders'
1717
FOLDER_ORDER = 'folder_order'
@@ -31,7 +31,6 @@
3131
UNRESOLVED_ATTRIBUTES_MAP = '__unresolved_attributes__'
3232
UNRESOLVED_FOLDERS_MAP = '__unresolved_folders__'
3333
USES_PATH_TOKENS = 'uses_path_tokens'
34-
VALUE = 'value'
3534
# VERSION is used for folder versioning
3635
VERSION = 'version'
3736
# VERSION_RAGE is used for attribute versioning
@@ -70,6 +69,9 @@
7069
ROD = 'ROD' # Read only but discover
7170
RW = 'RW' # Default Read WRITE
7271

72+
# used when DEFAULT_VALUE has curly-brace value that resolves to null
73+
NULL_VALUE_KEY = '__NULL__'
74+
7375
# attribute wlst_type values
7476
BOOLEAN = 'boolean'
7577
COMMA_DELIMITED_STRING = 'delimited_string[comma]'

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, 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
@@ -17,6 +17,7 @@
1717
from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
1818
from wlsdeploy.aliases.alias_constants import CONTAINS
1919
from wlsdeploy.aliases.alias_constants import DEFAULT_NAME_VALUE
20+
from wlsdeploy.aliases.alias_constants import DEFAULT_VALUE
2021
from wlsdeploy.aliases.alias_constants import FLATTENED_FOLDER_DATA
2122
from wlsdeploy.aliases.alias_constants import FOLDER_ORDER
2223
from wlsdeploy.aliases.alias_constants import FOLDER_PARAMS
@@ -26,6 +27,7 @@
2627
from wlsdeploy.aliases.alias_constants import MODEL_NAME
2728
from wlsdeploy.aliases.alias_constants import NAME_VALUE
2829
from wlsdeploy.aliases.alias_constants import NONE_CHILD_FOLDERS_TYPE
30+
from wlsdeploy.aliases.alias_constants import NULL_VALUE_KEY
2931
from wlsdeploy.aliases.alias_constants import PATH_TOKEN
3032
from wlsdeploy.aliases.alias_constants import SET_MBEAN_TYPE
3133
from wlsdeploy.aliases.alias_constants import SET_METHOD
@@ -890,7 +892,7 @@ def is_model_location_valid(self, location):
890892
def get_folders_in_order_for_location(self, location):
891893
"""
892894
Find the folders that are ordered (greater than zero) at the specified location and
893-
return the list in order of the
895+
return the list in ascending order
894896
:param location:
895897
:return:
896898
"""
@@ -1467,6 +1469,9 @@ def __resolve_attribute(self, attr_dict):
14671469
result[key] = self.__resolve_attribute(attr)
14681470
else:
14691471
result[key] = self._resolve_curly_braces(attr)
1472+
# resolve null key in curly brace values, such as "${__NULL__,Online}"
1473+
if key == DEFAULT_VALUE and result[key] == NULL_VALUE_KEY:
1474+
result[key] = None
14701475

14711476
for key in [GET_METHOD, SET_METHOD, GET_MBEAN_TYPE, SET_MBEAN_TYPE]:
14721477
if key in result and len(result[key]) == 0:

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from wlsdeploy.aliases.alias_constants import ALIAS_MAP_TYPES
1717
from wlsdeploy.aliases.alias_constants import ATTRIBUTES
1818
from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
19-
from wlsdeploy.aliases.alias_constants import DEFAULT
19+
from wlsdeploy.aliases.alias_constants import DEFAULT_VALUE
2020
from wlsdeploy.aliases.alias_constants import FLATTENED_FOLDER_DATA
2121
from wlsdeploy.aliases.alias_constants import FOLDERS
2222
from wlsdeploy.aliases.alias_constants import GET
@@ -38,7 +38,6 @@
3838
from wlsdeploy.aliases.alias_constants import SET_METHOD
3939
from wlsdeploy.aliases.alias_constants import STRING
4040
from wlsdeploy.aliases.alias_constants import USES_PATH_TOKENS
41-
from wlsdeploy.aliases.alias_constants import VALUE
4241
from wlsdeploy.aliases.alias_constants import WLST_NAME
4342
from wlsdeploy.aliases.alias_constants import WLST_READ_TYPE
4443
from wlsdeploy.aliases.alias_constants import WLST_TYPE
@@ -990,20 +989,21 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
990989
delimiter=delimiter)
991990

992991
model_attribute_name = attribute_info[MODEL_NAME]
993-
default_value = attribute_info[VALUE][DEFAULT]
992+
default_value = attribute_info[DEFAULT_VALUE]
994993

995994
#
996995
# The logic below to compare the str() representation of the converted value and the default value
997996
# only works for lists/maps if both the converted value and the default value are the same data type...
998997
#
999998
if (model_type in ALIAS_LIST_TYPES or model_type in ALIAS_MAP_TYPES) \
1000-
and not (default_value == '[]' or default_value == 'None'):
999+
and not (default_value == '[]' or default_value is None):
10011000
# always the model delimiter
10021001
default_value = alias_utils.convert_to_type(model_type, default_value,
10031002
delimiter=MODEL_LIST_DELIMITER)
10041003

10051004
if attribute_info[WLST_TYPE] == STRING:
1006-
default_value = alias_utils.replace_tokens_in_path(location, default_value)
1005+
if default_value:
1006+
default_value = alias_utils.replace_tokens_in_path(location, default_value)
10071007

10081008
if model_type == 'password':
10091009
if string_utils.is_empty(wlst_attribute_value) or converted_value == default_value:
@@ -1021,7 +1021,7 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
10211021

10221022
elif (model_type in ALIAS_LIST_TYPES or data_type in ALIAS_MAP_TYPES) and \
10231023
(converted_value is None or len(converted_value) == 0):
1024-
if default_value == '[]' or default_value == 'None':
1024+
if default_value == '[]' or default_value is None:
10251025
model_attribute_value = None
10261026

10271027
elif self._model_context is not None and USES_PATH_TOKENS in attribute_info:
@@ -1031,6 +1031,10 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
10311031
model_attribute_value = self._model_context.tokenize_classpath(converted_value)
10321032
if model_attribute_value == default_value:
10331033
model_attribute_value = None
1034+
1035+
elif default_value is None:
1036+
model_attribute_value = converted_value
1037+
10341038
elif str(converted_value) != str(default_value):
10351039
if _strings_are_empty(converted_value, default_value):
10361040
model_attribute_value = None
@@ -1199,15 +1203,12 @@ def get_model_attribute_default_value(self, location, model_attribute_name):
11991203
default_value = None
12001204
attribute_info = self._alias_entries.get_alias_attribute_entry_by_model_name(location, model_attribute_name)
12011205
if attribute_info is not None:
1202-
default_value = attribute_info[VALUE][DEFAULT]
1203-
if default_value == 'None':
1204-
default_value = None
1205-
else:
1206-
data_type, delimiter = \
1207-
alias_utils.compute_read_data_type_and_delimiter_from_attribute_info(
1208-
attribute_info, default_value)
1206+
default_value = attribute_info[DEFAULT_VALUE]
1207+
data_type, delimiter = \
1208+
alias_utils.compute_read_data_type_and_delimiter_from_attribute_info(
1209+
attribute_info, default_value)
12091210

1210-
default_value = alias_utils.convert_to_type(data_type, default_value, delimiter=delimiter)
1211+
default_value = alias_utils.convert_to_type(data_type, default_value, delimiter=delimiter)
12111212
self._logger.exiting(class_name=self._class_name, method_name=_method_name, result=default_value)
12121213
return default_value
12131214
except AliasException, ae:

core/src/test/python/alias_json_file_test.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import copy
@@ -23,8 +23,8 @@
2323
from wlsdeploy.aliases.alias_constants import ATTRIBUTES
2424
from wlsdeploy.aliases.alias_constants import CHILD_FOLDERS_TYPE
2525
from wlsdeploy.aliases.alias_constants import CONTAINS
26-
from wlsdeploy.aliases.alias_constants import DEFAULT
2726
from wlsdeploy.aliases.alias_constants import DEFAULT_NAME_VALUE
27+
from wlsdeploy.aliases.alias_constants import DEFAULT_VALUE
2828
from wlsdeploy.aliases.alias_constants import FLATTENED_FOLDER_DATA
2929
from wlsdeploy.aliases.alias_constants import FOLDER_ORDER
3030
from wlsdeploy.aliases.alias_constants import FOLDER_PARAMS
@@ -42,7 +42,6 @@
4242
from wlsdeploy.aliases.alias_constants import SET_METHOD
4343
from wlsdeploy.aliases.alias_constants import SHORT_NAME
4444
from wlsdeploy.aliases.alias_constants import USES_PATH_TOKENS
45-
from wlsdeploy.aliases.alias_constants import VALUE
4645
from wlsdeploy.aliases.alias_constants import VERSION
4746
from wlsdeploy.aliases.alias_constants import WLST_ATTRIBUTES_PATH
4847
from wlsdeploy.aliases.alias_constants import WLST_CREATE_PATH
@@ -96,7 +95,7 @@ class ListTestCase(unittest.TestCase):
9695
]
9796

9897
_required_attribute_keys = [
99-
VALUE,
98+
DEFAULT_VALUE,
10099
VERSION,
101100
WLST_MODE,
102101
WLST_NAME,
@@ -585,18 +584,9 @@ def _verify_attribute_set_method(self, folder_name, attribute_name, wlst_mode, a
585584
def _verify_attribute_uses_path_tokens_attribute_value(self, folder_name, attribute_name, alias_attribute_value):
586585
return self._verify_boolean_value(folder_name, attribute_name, USES_PATH_TOKENS, alias_attribute_value)
587586

588-
def _verify_attribute_value_attribute_value(self, folder_name, attribute_name, alias_attribute_value):
589-
result = []
590-
if type(alias_attribute_value) is not dict:
591-
message = self._get_invalid_attribute_dictionary_type_message(folder_name, attribute_name,
592-
VALUE, alias_attribute_value)
593-
result.append(message)
594-
elif DEFAULT not in alias_attribute_value:
595-
new_folder_name = folder_name + '/' + ATTRIBUTES + '/' + attribute_name
596-
message = self._get_missing_required_attribute_key_message(new_folder_name, VALUE, DEFAULT)
597-
result.append(message)
598-
599-
return result
587+
def _verify_attribute_default_value_attribute_value(self, folder_name, attribute_name, alias_attribute_value):
588+
# nothing to verify - default_value can be any type or null
589+
return []
600590

601591
def _verify_attribute_version_attribute_value(self, folder_name, attribute_name, alias_attribute_value):
602592
result = []

0 commit comments

Comments
 (0)