Skip to content

Commit 094f182

Browse files
authored
Merge pull request #101 from oracle/Issue#97-Report-VERSION_INVALID-as-INFO-validation-result-in-TOOL-mode
Modifications to handle VERSION_INVALID folders being present in a model
2 parents 2bd594e + 746deee commit 094f182

File tree

8 files changed

+211
-198
lines changed

8 files changed

+211
-198
lines changed

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

Lines changed: 106 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -297,54 +297,56 @@ def get_model_folder_path_for_location(self, location):
297297
_method_name = 'get_model_folder_path_for_location'
298298

299299
_logger.entering(str(location), class_name=_class_name, method_name=_method_name)
300+
301+
# Initialize return variable
302+
model_folder_path = ''
303+
300304
if not location.is_empty():
301305
location_folders = location.get_model_folders()
306+
307+
if location_folders[0] in self.get_model_topology_subfolder_names():
308+
model_folder_path += 'topology:/'
309+
elif location_folders[0] in self.get_model_resources_subfolder_names():
310+
model_folder_path += 'resources:/'
311+
elif location_folders[0] in self.get_model_app_deployments_subfolder_names():
312+
model_folder_path += 'appDeployments:/'
313+
elif location_folders[0] == 'domainInfo':
314+
model_folder_path += 'domainInfo:/'
315+
302316
my_loc = LocationContext()
303317

304-
first_folder = True
305-
result = ''
306318
for location_folder in location_folders:
307-
if first_folder:
308-
first_folder = False
309-
if location_folder in self.__topology_top_level_folders:
310-
result += 'topology:/'
311-
elif location_folder in self.__resources_top_level_folders:
312-
result += 'resources:/'
313-
elif location_folder in self.__app_deployments_top_level_folders:
314-
result += 'appDeployments:/'
315-
elif location_folder == 'domainInfo':
316-
result += 'domainInfo:/'
317-
else:
318-
ex = exception_helper.create_alias_exception('WLSDPLY-08100', location_folder)
319-
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
320-
raise ex
321-
322-
result += location_folder + '/'
319+
model_folder_path += '%s/' % location_folder
323320
my_loc.append_location(location_folder)
321+
324322
# Have to check for security provider artificial folders that don't have a trailing name token
325323
if location_folder not in SECURITY_PROVIDER_NAME_MAP:
326324
name_token = self.get_name_token_for_location(my_loc)
327325
if name_token is not None:
328326
name = location.get_name_for_token(name_token)
329327
if name is not None:
330328
my_loc.add_name_token(name_token, name)
331-
result += name + '/'
329+
model_folder_path += '%s/' % name
332330
elif location_folder != location_folders[-1]:
333-
# Allow the location to be missing a name_token for the last folder only...
331+
# Throw AliasException if name_token is missing
332+
# from any location folder, except the last one
334333
ex = exception_helper.create_alias_exception('WLSDPLY-08101', str(location), name_token)
335334
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
336335
raise ex
337-
# Strip the trailing slash only if the path is not still '<section-name>:/'
338-
section_end_index = result.find(':/')
339-
if section_end_index != -1 and len(result) > section_end_index + 2:
340-
result = result[:-1]
336+
337+
# Strip off trailing '/' if model_folder_path is not '<section-name>:/'
338+
if model_folder_path[-2:] != ':/':
339+
# Strip off trailing '/'
340+
model_folder_path = model_folder_path[:-1]
341341
else:
342-
# Hard to know exactly what to do here but since an empty location is the top-level,
343-
# just return the location of top-level Domain attributes.
344-
result = 'topology:/'
342+
# Hard to know exactly what to do here but since an empty
343+
# location is the top-level, just return the location of
344+
# top-level Domain attributes.
345+
model_folder_path = 'topology:/'
345346

346-
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
347-
return result
347+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=model_folder_path)
348+
349+
return model_folder_path
348350

349351
def get_wlst_attribute_path_for_location(self, location):
350352
"""
@@ -536,46 +538,58 @@ def get_name_token_for_location(self, location):
536538
_method_name = 'get_name_token_for_location'
537539

538540
_logger.entering(str(location), class_name=_class_name, method_name=_method_name)
541+
539542
result = None
543+
540544
if len(location.get_model_folders()) == 0:
541-
result = self.__domain_name_token
542-
else:
543-
folder_dict = self.__get_dictionary_for_location(location, False)
544-
if folder_dict is not None:
545-
if WLST_ATTRIBUTES_PATH in folder_dict:
546-
paths_index = folder_dict[WLST_ATTRIBUTES_PATH]
547-
tokenized_path = \
548-
alias_utils.resolve_path_index(folder_dict, paths_index, WLST_ATTRIBUTES_PATH, location)
549-
last_token = tokenized_path.split('/')[-1]
550-
551-
if last_token != 'NO_NAME_0' and last_token.startswith('%') and last_token.endswith('%'):
552-
token_occurrences = alias_utils.count_substring_occurrences(last_token, tokenized_path)
553-
if token_occurrences == 1:
554-
result = last_token[1:-1]
555-
else:
556-
ex = exception_helper.create_alias_exception('WLSDPLY-08103', location.get_folder_path(),
557-
WLST_ATTRIBUTES_PATH)
558-
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
559-
raise ex
545+
# There are no model folders in the location, so
546+
# just return %DOMAIN% for the name token
547+
return self.__domain_name_token
548+
549+
# Use get_wlst_mbean_type_for_location(location) call
550+
# to determine if location is VERSION_INVALID, or not.
551+
if self.get_wlst_mbean_type_for_location(location) is None:
552+
# This means location is VERSION_INVALID, so just return
553+
# None for the name_token
554+
return result
555+
556+
folder_dict = self.__get_dictionary_for_location(location, False)
557+
if folder_dict is not None:
558+
if WLST_ATTRIBUTES_PATH in folder_dict:
559+
paths_index = folder_dict[WLST_ATTRIBUTES_PATH]
560+
tokenized_path = \
561+
alias_utils.resolve_path_index(folder_dict, paths_index, WLST_ATTRIBUTES_PATH, location)
562+
last_token = tokenized_path.split('/')[-1]
563+
564+
if last_token != 'NO_NAME_0' and last_token.startswith('%') and last_token.endswith('%'):
565+
token_occurrences = alias_utils.count_substring_occurrences(last_token, tokenized_path)
566+
if token_occurrences == 1:
567+
result = last_token[1:-1]
560568
else:
561-
path = location.get_folder_path()
562-
563-
err_location = LocationContext(location)
564-
if not err_location.is_empty():
565-
folder_name = err_location.pop_location()
566-
code, message = self.is_valid_model_folder_name_for_location(err_location, folder_name)
567-
if code == ValidationCodes.VERSION_INVALID:
568-
ex = exception_helper.create_alias_exception('WLSDPLY-08130', path,
569-
self._wls_helper.get_actual_weblogic_version(),
570-
message)
571-
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
572-
raise ex
573-
ex = exception_helper.create_alias_exception('WLSDPLY-08131', path,
574-
self._wls_helper.get_actual_weblogic_version())
569+
ex = exception_helper.create_alias_exception('WLSDPLY-08103', location.get_folder_path(),
570+
WLST_ATTRIBUTES_PATH)
575571
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
576572
raise ex
573+
else:
574+
path = location.get_folder_path()
575+
576+
err_location = LocationContext(location)
577+
if not err_location.is_empty():
578+
folder_name = err_location.pop_location()
579+
code, message = self.is_valid_model_folder_name_for_location(err_location, folder_name)
580+
if code == ValidationCodes.VERSION_INVALID:
581+
ex = exception_helper.create_alias_exception('WLSDPLY-08130', path,
582+
self._wls_helper.get_actual_weblogic_version(),
583+
message)
584+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
585+
raise ex
586+
ex = exception_helper.create_alias_exception('WLSDPLY-08131', path,
587+
self._wls_helper.get_actual_weblogic_version())
588+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
589+
raise ex
577590

578591
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
592+
579593
return result
580594

581595
def get_wlst_mbean_name_for_location(self, location):
@@ -789,6 +803,36 @@ def is_valid_model_folder_name_for_location(self, location, model_folder_name):
789803
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[result, valid_version_range])
790804
return result, valid_version_range
791805

806+
def is_version_valid_location(self, location):
807+
"""
808+
Verify that the specified location is valid for the WLS version
809+
being used.
810+
811+
Caller needs to determine what action (e.g. log, raise exception,
812+
continue processing, record validation item, etc.) to take, when
813+
return code is VERSION_INVALID.
814+
815+
:param location: the location to be checked
816+
:return: A ValidationCodes Enum value of either VERSION_INVALID or VALID
817+
:return: A message saying which WLS version location is valid in, if
818+
return code is VERSION_INVALID
819+
"""
820+
_method_name = 'is_version_valid_location'
821+
822+
_logger.entering(str(location),class_name=_class_name, method_name=_method_name)
823+
824+
code = ValidationCodes.VALID
825+
message = ''
826+
if self.get_wlst_mbean_type_for_location(location) is None:
827+
model_folder_path = self.get_model_folder_path_for_location(location)
828+
message = exception_helper.get_message('WLSDPLY-08138', model_folder_path,
829+
self._wls_helper.get_weblogic_version())
830+
code = ValidationCodes.VERSION_INVALID
831+
832+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[code, message])
833+
834+
return code, message
835+
792836
def is_valid_model_attribute_name_for_location(self, location, model_attribute_name):
793837
"""
794838
Is the specified model attribute name valid for the specified location?

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from wlsdeploy.aliases.alias_constants import WLST_TYPE
4747
from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER
4848

49+
4950
class Aliases(object):
5051
"""
5152
The public interface into the aliases subsystem that abstracts out the WLST knowledge base from the
@@ -526,6 +527,22 @@ def get_model_subfolder_name(self, location, wlst_subfolder_name):
526527

527528
return model_subfolder_name
528529

530+
def is_version_valid_location(self, location):
531+
"""
532+
Verify that the specified location is valid for the WLS version
533+
being used.
534+
535+
Caller needs to determine what action (e.g. log, raise exception,
536+
continue processing, record validation item, etc.) to take, when
537+
return code is VERSION_INVALID.
538+
539+
:param location: the location to be checked
540+
:return: A ValidationCodes Enum value of either VERSION_INVALID or VALID
541+
:return: A message saying which WLS version location is valid in, if
542+
return code is VERSION_INVALID
543+
"""
544+
return self._alias_entries.is_version_valid_location(location)
545+
529546
def is_valid_model_folder_name(self, location, model_folder_name):
530547
"""
531548
Return whether or not location's model folders list has a subfolder
@@ -804,8 +821,8 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
804821
# The logic below to compare the str() representation of the converted value and the default value
805822
# only works for lists/maps if both the converted value and the default value are the same data type...
806823
#
807-
if (data_type in ALIAS_LIST_TYPES or data_type in ALIAS_MAP_TYPES) and not \
808-
(default_value == '[]' or default_value == 'None'):
824+
if (data_type in ALIAS_LIST_TYPES or data_type in ALIAS_MAP_TYPES) \
825+
and not (default_value == '[]' or default_value == 'None'):
809826
default_value = alias_utils.convert_to_type(data_type, default_value, delimiter=delimiter)
810827

811828
if data_type == 'password':

core/src/main/python/wlsdeploy/tool/create/creator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ def _create_mbean(self, type_name, model_nodes, base_location, log_created=False
121121
return
122122

123123
location = LocationContext(base_location).append_location(type_name)
124+
result, message = self.alias_helper.is_version_valid_location(location)
125+
if result == ValidationCodes.VERSION_INVALID:
126+
self.logger.warning('WLSDPLY-12123', message,
127+
class_name=self.__class_name, method_name=_method_name)
128+
return
129+
124130
create_path = self.alias_helper.get_wlst_create_path(location)
125131
existing_folder_names = self._get_existing_folders(create_path)
126132

core/src/main/python/wlsdeploy/tool/util/alias_helper.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,32 @@ def is_valid_model_folder_name(self, location, model_folder_name):
468468
raise ex
469469
return result, message
470470

471+
def is_version_valid_location(self, location):
472+
"""
473+
Verify that the specified location is valid for the WLS version
474+
being used.
475+
476+
Caller needs to determine what action (e.g. log, raise exception,
477+
continue processing, record validation item, etc.) to take, when
478+
return code is VERSION_INVALID.
479+
480+
:param location: the location to be checked
481+
:return: A ValidationCodes Enum value of either VERSION_INVALID or VALID
482+
:return: A message saying which WLS version location is valid in, if
483+
return code is VERSION_INVALID
484+
"""
485+
_method_name = 'is_version_valid_location'
486+
487+
try:
488+
code, message = self.__aliases.is_version_valid_location(location)
489+
except AliasException, ae:
490+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19033',
491+
location.get_folder_path(), ae.getLocalizedMessage(), error=ae)
492+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
493+
raise ex
494+
495+
return code, message
496+
471497
def is_valid_model_attribute_name(self, location, model_attribute_name):
472498
"""
473499
Return whether or not location's model folders list has an attribute

0 commit comments

Comments
 (0)