Skip to content

Commit 22df701

Browse files
authored
Improve error reporting for modelHelp (#641)
* Add folder to UNRESOLVED_FOLDERS_MAP if invalid for WLS version/mode * Check for valid location in get_wlst_mbean_type_for_location for existing calls * Check for valid locations in path and display detailed message * Revised comment
1 parent 65f1943 commit 22df701

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,11 @@ def get_wlst_mbean_type_for_location(self, location):
685685
"""
686686
_method_name = 'get_wlst_mbean_type_for_location'
687687

688+
# some callers use this method to check for location valid.
689+
# they should call is_model_location_valid(location) directly instead.
690+
if not self.is_model_location_valid(location):
691+
return None
692+
688693
_logger.entering(str(location), class_name=_class_name, method_name=_method_name)
689694
folder_dict = self.__get_dictionary_for_location(location, False)
690695
if folder_dict is None:
@@ -907,6 +912,21 @@ def is_valid_model_attribute_name_for_location(self, location, model_attribute_n
907912
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[result, valid_version_range])
908913
return result, valid_version_range
909914

915+
def is_model_location_valid(self, location):
916+
"""
917+
Determine if the specified location is valid, including version/mode checks.
918+
Returns a boolean answer instead of the (ValidationCode, message) tuple used elsewhere.
919+
:param location: the location to be checked
920+
:return: True if the location is valid, false otherwise
921+
"""
922+
if len(location.get_model_folders()) > 0:
923+
parent_location = LocationContext(location)
924+
folder = parent_location.pop_location()
925+
code, message = self.is_valid_model_folder_name_for_location(parent_location, folder)
926+
if code != ValidationCodes.VALID:
927+
return False
928+
return True
929+
910930
def get_folder_short_name_for_location(self, location):
911931
"""
912932
Retrieve the shortened name for the model folder at the provided location.
@@ -1141,10 +1161,10 @@ def __apply_wlst_context_changes(self, path_name, alias_dict, parent_dict):
11411161
"""
11421162
_method_name = '__apply_wlst_context_changes'
11431163

1144-
#
1145-
# First, determine if this dictionary is even relevant to the current WLS version.
1146-
#
11471164
self.__resolve_folder_params(path_name, alias_dict)
1165+
1166+
# if folder is not valid for this version/mode of WLS,
1167+
# add folder to parent_dict UNRESOLVED_FOLDERS_MAP and return None
11481168
if not self.__use_alias_dict(path_name, alias_dict, parent_dict):
11491169
return None
11501170

@@ -1153,8 +1173,10 @@ def __apply_wlst_context_changes(self, path_name, alias_dict, parent_dict):
11531173
result_folders = dict()
11541174
folders = alias_dict[FOLDERS]
11551175
for folder in folders:
1156-
folder_dict = self.__apply_wlst_context_changes(path_name + '/' + folder, folders[folder], alias_dict)
1157-
result_folders[folder] = folder_dict
1176+
folder_dict = self.__apply_wlst_context_changes(path_name + '/' + folder, folders[folder], result)
1177+
# if folder_dict is None, this folder was invalid for this version/mode of WLS
1178+
if folder_dict is not None:
1179+
result_folders[folder] = folder_dict
11581180
result[FOLDERS] = result_folders
11591181

11601182
if FLATTENED_FOLDER_DATA in alias_dict:

core/src/main/python/wlsdeploy/tool/modelhelp/model_help_printer.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from oracle.weblogic.deploy.exception import ExceptionHelper
88
from wlsdeploy.aliases.location_context import LocationContext
99
from wlsdeploy.aliases.model_constants import KNOWN_TOPLEVEL_MODEL_SECTIONS
10+
from wlsdeploy.aliases.validation_codes import ValidationCodes
1011
from wlsdeploy.tool.modelhelp import model_help_utils
1112
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
1213
from wlsdeploy.tool.modelhelp.model_sample_printer import ModelSamplePrinter
@@ -219,6 +220,8 @@ def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys,
219220
str(model_path_tokens), ControlOptions.from_value(control_option),
220221
str(valid_section_folder_keys), class_name=_class_name, method_name=_method_name)
221222

223+
print
224+
222225
section_name = model_path_tokens[0]
223226
top_folder = model_path_tokens[1]
224227
if top_folder not in valid_section_folder_keys:
@@ -230,6 +233,12 @@ def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys,
230233
# Populate the location context using model_path_tokens[1:]
231234
model_location = LocationContext()
232235
for folder_key in model_path_tokens[1:]:
236+
code, message = self._alias_helper.is_valid_model_folder_name(model_location, folder_key)
237+
if code != ValidationCodes.VALID:
238+
ex = exception_helper.create_cla_exception("WLSDPLY-05027", message)
239+
self._logger.throwing(ex, class_name=_class_name, method_name=_method_name)
240+
raise ex
241+
233242
model_location.append_location(folder_key)
234243
name_token = self._alias_helper.get_name_token(model_location)
235244
if name_token is not None:
@@ -245,7 +254,6 @@ def _print_model_folder_help(self, model_path_tokens, valid_section_folder_keys,
245254
model_path += " (" + type_name + ")"
246255

247256
# Print 'Path: <model_section>' header
248-
print
249257
_print_indent(model_path, 0)
250258

251259
if model_help_utils.show_attributes(control_option):

core/src/main/python/wlsdeploy/tool/modelhelp/model_sample_printer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from wlsdeploy.aliases.location_context import LocationContext
66
from wlsdeploy.aliases.model_constants import KNOWN_TOPLEVEL_MODEL_SECTIONS
7+
from wlsdeploy.aliases.validation_codes import ValidationCodes
78
from wlsdeploy.tool.modelhelp import model_help_utils
89
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
910
from wlsdeploy.exception import exception_helper
@@ -100,6 +101,11 @@ def _print_model_folder_sample(self, model_path_tokens, valid_section_folder_key
100101
model_location = LocationContext()
101102
for token in model_path_tokens:
102103
if indent > 0:
104+
code, message = self._alias_helper.is_valid_model_folder_name(model_location, token)
105+
if code != ValidationCodes.VALID:
106+
ex = exception_helper.create_cla_exception("WLSDPLY-05027", message)
107+
self._logger.throwing(ex, class_name=_class_name, method_name=_method_name)
108+
raise ex
103109
model_location.append_location(token)
104110

105111
_print_indent(token + ":", indent)
@@ -134,9 +140,6 @@ def _print_subfolders_sample(self, model_location, control_option, indent_level)
134140

135141
valid_subfolder_keys = self._alias_helper.get_model_subfolder_names(model_location)
136142

137-
if not valid_subfolder_keys:
138-
return
139-
140143
valid_subfolder_keys.sort()
141144
self._print_subfolder_keys_sample(model_location, valid_subfolder_keys, control_option, indent_level)
142145

0 commit comments

Comments
 (0)