Skip to content

Commit 0d182c2

Browse files
Add wlst_mode to the folder level and change NMProperties to offline folder
1 parent 17ffdcc commit 0d182c2

File tree

7 files changed

+135
-70
lines changed

7 files changed

+135
-70
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,18 @@ def __apply_wlst_context_changes(self, path_name, alias_dict, parent_dict):
11051105
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
11061106
raise ex
11071107

1108+
if WLST_MODE in alias_dict:
1109+
dict_wlst_mode = alias_dict[WLST_MODE]
1110+
mode = WlstModes.from_value(self._wlst_mode)
1111+
if not self.__wlst_mode_matches(dict_wlst_mode):
1112+
_logger.finer('WLSDPLY-08132', path_name, dict_wlst_mode, mode, class_name=_class_name,
1113+
method_name=_method_name)
1114+
if UNRESOLVED_FOLDERS_MAP not in parent_dict:
1115+
parent_dict[UNRESOLVED_FOLDERS_MAP] = dict()
1116+
alias_dict_folder_name = alias_utils.compute_folder_name_from_path(path_name)
1117+
parent_dict[UNRESOLVED_FOLDERS_MAP][alias_dict_folder_name] = mode
1118+
return None
1119+
11081120
result = dict()
11091121
if FOLDERS in alias_dict:
11101122
result_folders = dict()

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

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -343,78 +343,84 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
343343
wlst_attribute_value = None
344344

345345
module_folder = self._alias_entries.get_dictionary_for_location(location)
346-
if ATTRIBUTES not in module_folder:
347-
ex = exception_helper.create_alias_exception('WLSDPLY-08400', location.get_folder_path())
348-
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
349-
raise ex
350-
351-
if model_attribute_name not in module_folder[ATTRIBUTES]:
352-
ex = exception_helper.create_alias_exception('WLSDPLY-08401', model_attribute_name,
353-
location.get_folder_path())
354-
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
355-
raise ex
356-
357-
attribute_info = module_folder[ATTRIBUTES][model_attribute_name]
358-
359-
if attribute_info and not self.__is_model_attribute_read_only(location, attribute_info):
360-
password_attribute_name = \
361-
password_utils.get_wlst_attribute_name(attribute_info, model_attribute_value, self._wlst_mode)
346+
if not module_folder:
347+
self._logger.fine('WLSDPLY-08410', location.get_current_model_folder(), location.get_parent_folder_path(),
348+
WlstModes.from_value(self._wlst_mode), self._wls_version)
349+
else:
350+
if ATTRIBUTES not in module_folder:
351+
ex = exception_helper.create_alias_exception('WLSDPLY-08400', location.get_folder_path())
352+
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
353+
raise ex
362354

363-
if password_attribute_name is not None:
364-
wlst_attribute_name = password_attribute_name
365-
else:
366-
wlst_attribute_name = attribute_info[WLST_NAME]
355+
if model_attribute_name not in module_folder[ATTRIBUTES]:
356+
ex = exception_helper.create_alias_exception('WLSDPLY-08401', model_attribute_name,
357+
location.get_folder_path())
358+
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
359+
raise ex
367360

368-
if self._model_context and USES_PATH_TOKENS in attribute_info and string_utils.to_boolean(attribute_info[USES_PATH_TOKENS]):
369-
model_attribute_value = self._model_context.replace_token_string(model_attribute_value)
361+
attribute_info = module_folder[ATTRIBUTES][model_attribute_name]
370362

371-
data_type = attribute_info[WLST_TYPE]
372-
if data_type == 'password':
373-
try:
374-
wlst_attribute_value = self.__decrypt_password(model_attribute_value)
375-
except EncryptionException, ee:
376-
ex = exception_helper.create_alias_exception('WLSDPLY-08402', model_attribute_name,
377-
location.get_folder_path(),
378-
ee.getLocalizedMessage(), error=ee)
379-
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
380-
raise ex
381-
else:
382-
if data_type in ALIAS_LIST_TYPES or data_type in ALIAS_MAP_TYPES:
383-
merge = True
384-
if MERGE in attribute_info:
385-
merge = alias_utils.convert_boolean(attribute_info[MERGE])
386-
387-
if merge and data_type in ALIAS_MAP_TYPES:
388-
model_val = TypeUtils.convertToType(PROPERTIES, model_attribute_value)
389-
existing_val = TypeUtils.convertToType(PROPERTIES, existing_wlst_value)
390-
merged_value = alias_utils.merge_model_and_existing_properties(model_val, existing_val)
391-
elif merge and alias_utils.is_attribute_server_start_arguments(location, model_attribute_name):
392-
merged_value = \
393-
alias_utils.merge_server_start_argument_values(model_attribute_value, existing_wlst_value)
394-
elif merge and existing_wlst_value is not None and len(existing_wlst_value) > 0:
395-
model_val = alias_utils.convert_to_type(LIST, model_attribute_value,
396-
delimiter=MODEL_LIST_DELIMITER)
397-
398-
_read_type, read_delimiter = \
399-
alias_utils.compute_read_data_type_and_delimiter_from_attribute_info(attribute_info,
400-
existing_wlst_value)
401-
existing_val = alias_utils.convert_to_type(LIST, existing_wlst_value, delimiter=read_delimiter)
402-
merged_value = alias_utils.merge_model_and_existing_lists(model_val, existing_val)
403-
else:
404-
merged_value = model_attribute_value
363+
if attribute_info and not self.__is_model_attribute_read_only(location, attribute_info):
364+
password_attribute_name = \
365+
password_utils.get_wlst_attribute_name(attribute_info, model_attribute_value, self._wlst_mode)
405366

406-
if data_type == JARRAY:
407-
subtype = 'java.lang.String'
408-
if SET_MBEAN_TYPE in attribute_info:
409-
subtype = attribute_info[SET_MBEAN_TYPE]
410-
wlst_attribute_value = alias_utils.convert_to_type(data_type, merged_value, subtype=subtype,
411-
delimiter=MODEL_LIST_DELIMITER)
367+
if password_attribute_name is not None:
368+
wlst_attribute_name = password_attribute_name
369+
else:
370+
wlst_attribute_name = attribute_info[WLST_NAME]
371+
372+
if self._model_context and USES_PATH_TOKENS in attribute_info\
373+
and string_utils.to_boolean(attribute_info[USES_PATH_TOKENS]):
374+
model_attribute_value = self._model_context.replace_token_string(model_attribute_value)
375+
376+
data_type = attribute_info[WLST_TYPE]
377+
if data_type == 'password':
378+
try:
379+
wlst_attribute_value = self.__decrypt_password(model_attribute_value)
380+
except EncryptionException, ee:
381+
ex = exception_helper.create_alias_exception('WLSDPLY-08402', model_attribute_name,
382+
location.get_folder_path(),
383+
ee.getLocalizedMessage(), error=ee)
384+
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
385+
raise ex
386+
else:
387+
if data_type in ALIAS_LIST_TYPES or data_type in ALIAS_MAP_TYPES:
388+
merge = True
389+
if MERGE in attribute_info:
390+
merge = alias_utils.convert_boolean(attribute_info[MERGE])
391+
392+
if merge and data_type in ALIAS_MAP_TYPES:
393+
model_val = TypeUtils.convertToType(PROPERTIES, model_attribute_value)
394+
existing_val = TypeUtils.convertToType(PROPERTIES, existing_wlst_value)
395+
merged_value = alias_utils.merge_model_and_existing_properties(model_val, existing_val)
396+
elif merge and alias_utils.is_attribute_server_start_arguments(location, model_attribute_name):
397+
merged_value = alias_utils.merge_server_start_argument_values(model_attribute_value,
398+
existing_wlst_value)
399+
elif merge and existing_wlst_value is not None and len(existing_wlst_value) > 0:
400+
model_val = alias_utils.convert_to_type(LIST, model_attribute_value,
401+
delimiter=MODEL_LIST_DELIMITER)
402+
403+
_read_type, read_delimiter = \
404+
alias_utils.compute_read_data_type_and_delimiter_from_attribute_info(attribute_info,
405+
existing_wlst_value)
406+
existing_val = alias_utils.convert_to_type(LIST, existing_wlst_value,
407+
delimiter=read_delimiter)
408+
merged_value = alias_utils.merge_model_and_existing_lists(model_val, existing_val)
409+
else:
410+
merged_value = model_attribute_value
411+
412+
if data_type == JARRAY:
413+
subtype = 'java.lang.String'
414+
if SET_MBEAN_TYPE in attribute_info:
415+
subtype = attribute_info[SET_MBEAN_TYPE]
416+
wlst_attribute_value = alias_utils.convert_to_type(data_type, merged_value, subtype=subtype,
417+
delimiter=MODEL_LIST_DELIMITER)
418+
else:
419+
wlst_attribute_value = alias_utils.convert_to_type(data_type, merged_value,
420+
delimiter=MODEL_LIST_DELIMITER)
412421
else:
413-
wlst_attribute_value = alias_utils.convert_to_type(data_type, merged_value,
422+
wlst_attribute_value = alias_utils.convert_to_type(data_type, model_attribute_value,
414423
delimiter=MODEL_LIST_DELIMITER)
415-
else:
416-
wlst_attribute_value = alias_utils.convert_to_type(data_type, model_attribute_value,
417-
delimiter=MODEL_LIST_DELIMITER)
418424

419425
return wlst_attribute_name, wlst_attribute_value
420426

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ def get_current_model_folder(self):
105105
model_folder = model_folder_list[-1]
106106
return model_folder
107107

108+
def get_parent_folder_path(self):
109+
"""
110+
Return the parent folder path for the location. This is the parent of the last folder or None if no parent.
111+
:return: return the parent folder path
112+
"""
113+
result = None
114+
model_folder_list = self.get_model_folders()
115+
if model_folder_list:
116+
result = ''
117+
if len(model_folder_list) > 1:
118+
for folder in model_folder_list[-2]:
119+
result += '/' + folder
120+
if len(result) == 0:
121+
result = '/'
122+
return result
123+
108124
def get_name_tokens(self):
109125
"""
110126
Copy constructor for ``name_tokens`` dictionary of location context.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"copyright": "Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.",
33
"license": "The Universal Permissive License (UPL), Version 1.0",
44
"wlst_type": "NMProperties",
5+
"wlst_mode": "offline",
56
"folders": {},
67
"attributes": {
78
"AuthenticationEnabled": [ {"version": "[12.1.2,)", "wlst_mode": "offline", "wlst_name": "AuthenticationEnabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean"} ],

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ WLSDPLY-08130=Unable to compute the name token for folder {0} because the folder
683683
WebLogic Server version {1}: {2}
684684
WLSDPLY-08131=Unable to compute the name token for folder {0} because the folder is not valid in \
685685
WebLogic Server version {1}
686+
WLSDPLY-08132=Folder {0} present only for {1} mode is not relevant for WLST in {2} mode
686687
#
687688
# Empty slots to fill up...
688689
#
@@ -749,6 +750,7 @@ WLSDPLY-08406={0} WLST attribute name is not associated with a model attribute n
749750
WLSDPLY-08407=Attribute {0} in folder {1} is supported in WebLogic version {2}
750751
WLSDPLY-08408=Attribute {0} in folder {1} is not supported in WebLogic version {2}
751752
WLSDPLY-08409=Access for attribute {0} in folder {1} is read-only or validation-only in WLST {2} mode
753+
WLSDPLY-08410={0} model folder at location {1} is not supported for WLST {2} mode WebLogic version {3}
752754

753755
# oracle.weblogic.deploy.aliases.TypeUtils.java
754756
WLSDPLY-08500=Unable to convert type due to an unknown type {0}

core/src/test/python/alias_json_file_test.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class ListTestCase(unittest.TestCase):
7070
VERSION,
7171
WLST_CREATE_PATH,
7272
WLST_LIST_PATH,
73+
WLST_MODE,
7374
WLST_SUBFOLDERS_PATH
7475
]
7576

@@ -276,6 +277,7 @@ def _verify_folder_wlst_paths_attribute_type(self, folder_name, attribute_value)
276277
result.append(self._get_invalid_dictionary_type_message(folder_name, WLST_PATHS, attribute_value))
277278
return result
278279

280+
279281
def _verify_folder_wlst_type_attribute_type(self, folder_name, attribute_value):
280282
result = []
281283
if type(attribute_value) is not str:
@@ -341,6 +343,19 @@ def _verify_folder_version_attribute_value(self, folder_name, attribute_value):
341343
result.append(self._get_invalid_string_type_message(folder_name, VERSION, attribute_value))
342344
return result
343345

346+
def _verify_folder_wlst_mode_attribute_value(self, folder_name, attribute_value):
347+
result = []
348+
if type(attribute_value) is not str:
349+
message = self._get_invalid_attribute_string_type_message(folder_name, folder_name,
350+
WLST_MODE, attribute_value)
351+
result.append(message)
352+
else:
353+
# curly braces not allowed in wlst_mode
354+
if attribute_value not in self._known_wlst_mode_attribute_values:
355+
message = self._get_invalid_wlst_mode_message(folder_name, attribute_value)
356+
result.append(message)
357+
return result
358+
344359
def _verify_folder_wlst_create_path_attribute_value(self, folder_name, attribute_value):
345360
result = []
346361
if type(attribute_value) is not str:
@@ -653,6 +668,12 @@ def _get_invalid_attribute_boolean_string_value_message(self, folder_name, attri
653668

654669
return text % (folder_name, attribute_name, alias_attribute_name, alias_attribute_value)
655670

671+
672+
def _get_invalid_wlst_mode_message(self, folder_name, alias_attribute_name):
673+
text = 'Folder at path %s has invalid wlst mode type of %s'
674+
result = text %(folder_name, alias_attribute_name)
675+
return result
676+
656677
def _get_empty_constrained_value_message(self, folder_name, attribute_name, alias_attribute_name, wlst_mode=None):
657678
if wlst_mode is None:
658679
text = 'Folder at path %s has a defined attribute %s with alias attribute %s whose value was empty'
@@ -673,4 +694,4 @@ def _get_invalid_alias_attribute_value_message(self, folder_name, attribute_name
673694
wlst_mode, alias_attribute_value, cause):
674695
text = 'Folder at path %s has a defined attribute %s with alias attribute %s whose ' \
675696
'%s value %s was not valid because %s'
676-
return text % (folder_name, attribute_name, alias_attribute_name, wlst_mode, alias_attribute_value, cause)
697+
return text % (folder_name, attribute_name, alias_attribute_name, wlst_mode, alias_attribute_value, cause)

core/src/test/python/aliases_test.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from oracle.weblogic.deploy.aliases import TypeUtils
1414

1515
from wlsdeploy.aliases.aliases import Aliases
16+
from wlsdeploy.aliases.alias_constants import ATTRIBUTES
1617
from wlsdeploy.aliases.location_context import LocationContext
1718
import wlsdeploy.aliases.model_constants as FOLDERS
1819
from wlsdeploy.aliases.validation_codes import ValidationCodes
@@ -1234,10 +1235,16 @@ def testIssue91Fix(self):
12341235
wlst_list_path = self.aliases.get_wlst_list_path(location)
12351236
self.assertEqual(wlst_list_path, expected)
12361237

1237-
# All the attributes in FOLDERS.NM_PROPERTIES have 'wlst_mode':'offline", so
1238-
# the default value should be None
1238+
# NMProperties is an offline only folder and the get_model_attribute_default_value will throw and exception
1239+
model_attribute_name = 'weblogic.StartScriptName'
1240+
1241+
self.assertRaises(AliasException, getattr(self.online_aliases, 'get_model_attribute_default_value'),
1242+
location, model_attribute_name)
1243+
1244+
# this method will not return an exception but should return a None
1245+
default_name, default_value = \
1246+
self.online_aliases.get_wlst_attribute_name_and_value(location, model_attribute_name, 'script')
12391247
expected = None
1240-
default_value = self.online_aliases.get_model_attribute_default_value(location, 'weblogic.StartScriptName')
12411248
self.assertEqual(default_value, expected)
12421249

12431250
return

0 commit comments

Comments
 (0)