Skip to content

Commit 531d797

Browse files
authored
Merge pull request #156 from oracle/alias-integration
System test for aliases
2 parents 2970210 + aa08b85 commit 531d797

File tree

7 files changed

+104
-33
lines changed

7 files changed

+104
-33
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
MERGE = 'merge'
2020
MODEL_NAME = 'model_name'
2121
NAME_VALUE = 'name_value'
22+
PASSWORD_TOKEN = "--FIX ME--"
2223
PREFERRED_MODEL_TYPE = 'preferred_model_type'
2324
RESTART_REQUIRED = 'restart_required'
2425
SET_MBEAN_TYPE = 'set_mbean_type'
@@ -73,13 +74,22 @@
7374
JAVA_LANG_BOOLEAN = 'java.lang.Boolean'
7475
LIST = 'list'
7576
LONG = 'long'
77+
OBJECT = 'object'
7678
PASSWORD = 'password'
7779
PATH_SEPARATOR_DELIMITED_STRING = 'delimited_string[path_separator]'
7880
PROPERTIES = 'properties'
7981
SEMI_COLON_DELIMITED_STRING = 'delimited_string[semicolon]'
8082
SPACE_DELIMITED_STRING = 'delimited_string[space]'
8183
STRING = 'string'
8284

85+
ALIAS_DELIMITED_TYPES = [
86+
COMMA_DELIMITED_STRING,
87+
DELIMITED_STRING,
88+
PATH_SEPARATOR_DELIMITED_STRING,
89+
SEMI_COLON_DELIMITED_STRING,
90+
SPACE_DELIMITED_STRING
91+
]
92+
8393
ALIAS_LIST_TYPES = [
8494
COMMA_DELIMITED_STRING,
8595
DELIMITED_STRING,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
from wlsdeploy.aliases.alias_constants import WLST_SUBFOLDERS_PATH
5353
from wlsdeploy.aliases.alias_constants import WLST_TYPE
5454

55-
IGNORE_FOR_MODEL_LIST = ['DynamicallyCreated', 'Id', 'Tag', 'Tags', 'Type', 'Name']
5655
_class_name = 'AliasEntries'
5756
_logger = PlatformLogger('wlsdeploy.aliases')
5857

@@ -66,6 +65,8 @@ class AliasEntries(object):
6665
This class is intended only for use by aliases.py. Other uses of this class violate
6766
encapsulation and should be avoided.
6867
"""
68+
IGNORE_FOR_MODEL_LIST = ['DynamicallyCreated', 'Id', 'Tag', 'Tags', 'Type', 'Name', 'Parent']
69+
6970
__category_modules_dir_name = 'oracle/weblogic/deploy/aliases/category_modules/'
7071
__domain_category = 'Domain'
7172

@@ -744,7 +745,7 @@ def get_alias_attribute_entry_by_wlst_name(self, location, wlst_attribute_name):
744745
else:
745746
_logger.warning('WLSDPLY-08110', wlst_attribute_name, location.get_folder_path(), WLST_PATH)
746747
else:
747-
if wlst_attribute_name not in IGNORE_FOR_MODEL_LIST:
748+
if wlst_attribute_name not in self.IGNORE_FOR_MODEL_LIST:
748749
ex = exception_helper.create_alias_exception('WLSDPLY-08111', location.get_folder_path(),
749750
wlst_attribute_name)
750751
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)

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

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from wlsdeploy.aliases.alias_constants import MBEAN
3737
from wlsdeploy.aliases.alias_constants import MERGE
3838
from wlsdeploy.aliases.alias_constants import MODEL_NAME
39+
from wlsdeploy.aliases.alias_constants import PASSWORD
40+
from wlsdeploy.aliases.alias_constants import PASSWORD_TOKEN
3941
from wlsdeploy.aliases.alias_constants import PREFERRED_MODEL_TYPE
4042
from wlsdeploy.aliases.alias_constants import PROPERTIES
4143
from wlsdeploy.aliases.alias_constants import RESTART_REQUIRED
@@ -77,6 +79,20 @@ def __init__(self, model_context, wlst_mode=WlstModes.OFFLINE, wls_version=None,
7779
# Model folder navigation-related methods #
7880
###########################################################################
7981

82+
def get_mode_string(self):
83+
"""
84+
Return WlstModes ONLINE or OFFLINE in string representation for this Aliases.
85+
:return: 'ONLINE' or 'OFFLINE'
86+
"""
87+
return WlstModes.from_value(self._wlst_mode)
88+
89+
def get_mode_enum(self):
90+
"""
91+
Return the WlstModes enum value for this Aliases.
92+
:return: WlstModes.ONLINE or WlstModes.OFFLINE
93+
"""
94+
return self._wlst_mode
95+
8096
def get_model_top_level_folder_names(self):
8197
"""
8298
Returns a list of the recognized top-level model folders corresponding to the known WLST top-level folders.
@@ -349,7 +365,7 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
349365
else:
350366
wlst_attribute_name = attribute_info[WLST_NAME]
351367

352-
if USES_PATH_TOKENS in attribute_info and string_utils.to_boolean(attribute_info[USES_PATH_TOKENS]):
368+
if self._model_context and USES_PATH_TOKENS in attribute_info and string_utils.to_boolean(attribute_info[USES_PATH_TOKENS]):
353369
model_attribute_value = self._model_context.replace_token_string(model_attribute_value)
354370

355371
data_type = attribute_info[WLST_TYPE]
@@ -387,7 +403,6 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
387403
else:
388404
merged_value = model_attribute_value
389405

390-
391406
if data_type == JARRAY:
392407
subtype = 'java.lang.String'
393408
if SET_MBEAN_TYPE in attribute_info:
@@ -774,6 +789,28 @@ def get_model_merge_required_attribute_names(self, location):
774789

775790
return model_attribute_names
776791

792+
def get_model_password_attribute_names(self, location):
793+
"""
794+
Get the list of attribute names for the current location that are marked as password.
795+
:param location: current location context
796+
:return: list of password attributes
797+
"""
798+
_method_name = 'get_model_password_attribute_names'
799+
800+
model_attribute_names = list()
801+
module_folder = self._alias_entries.get_dictionary_for_location(location, resolve=False)
802+
803+
if ATTRIBUTES not in module_folder:
804+
ex = exception_helper.create_alias_exception('WLSDPLY-08400', location.get_folder_path())
805+
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
806+
raise ex
807+
808+
for key, value in module_folder[ATTRIBUTES].iteritems():
809+
if WLST_TYPE in value and value[WLST_TYPE] == PASSWORD:
810+
model_attribute_names.append(key)
811+
812+
return model_attribute_names
813+
777814
def get_model_uses_path_tokens_attribute_names(self, location):
778815
"""
779816
Get the list of attribute names that "use path tokens" (i.e., ones whose values are file system paths).
@@ -821,7 +858,7 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
821858
if attribute_info is not None and not self.__is_model_attribute_read_only(location, attribute_info):
822859
data_type, preferred_type, delimiter = \
823860
alias_utils.compute_read_data_type_for_wlst_and_delimiter_from_attribute_info(attribute_info,
824-
wlst_attribute_value)
861+
wlst_attribute_value)
825862

826863
converted_value = alias_utils.convert_from_type(data_type, wlst_attribute_value, delimiter=delimiter,
827864
preferred=preferred_type)
@@ -843,7 +880,7 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
843880
if string_utils.is_empty(wlst_attribute_value) or converted_value == default_value:
844881
model_attribute_value = None
845882
else:
846-
model_attribute_value = "--FIX ME--"
883+
model_attribute_value = PASSWORD_TOKEN
847884
elif data_type == 'boolean':
848885
wlst_val = alias_utils.convert_boolean(converted_value)
849886
default_val = alias_utils.convert_boolean(default_value)
@@ -860,21 +897,20 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
860897
model_attribute_value = None
861898
else:
862899
model_attribute_value = converted_value
863-
if USES_PATH_TOKENS in attribute_info:
900+
if self._model_context and USES_PATH_TOKENS in attribute_info:
864901
model_attribute_value = self._model_context.tokenize_path(model_attribute_value)
865902
self._logger.exiting(class_name=self._class_name, method_name=_method_name,
866903
result={model_attribute_name: model_attribute_value})
867904
return model_attribute_name, model_attribute_value
868905

869906
def get_model_attribute_name(self, location, wlst_attribute_name):
870907
"""
871-
Returns the model attribute name for the specified WLST attribute name and value.
908+
Returns the model attribute name for the specified WLST attribute name and value. If the model attribute name
909+
is not valid for the version or the attribute is marked as read-only, return None
872910
873-
model_attribute_value will be set to None, if value assigned to wlst_attribute_value arg
874-
is the default value for model_attribute_name.
875911
:param location: the location
876912
:param wlst_attribute_name: the WLST attribute name
877-
:return: the name and value
913+
:return: matching model attribute name
878914
:raises: AliasException: if an error occurs
879915
"""
880916
_method_name = 'get_model_attribute_name'
@@ -884,7 +920,7 @@ def get_model_attribute_name(self, location, wlst_attribute_name):
884920
model_attribute_name = None
885921

886922
attribute_info = self._alias_entries.get_alias_attribute_entry_by_wlst_name(location, wlst_attribute_name)
887-
if attribute_info is not None:
923+
if attribute_info is not None and not self.__is_model_attribute_read_only(location, attribute_info):
888924
model_attribute_name = attribute_info[MODEL_NAME]
889925

890926
self._logger.exiting(class_name=self._class_name, method_name=_method_name,
@@ -964,8 +1000,8 @@ def attribute_values_are_equal(self, location, model_attribute_name, model_attri
9641000
if key == model_attribute_name:
9651001
attribute_info = module_folder[ATTRIBUTES][key]
9661002
if attribute_info and VALUE in attribute_info and DEFAULT in attribute_info[VALUE]:
967-
result = (model_attribute_value == wlst_attribute_value
968-
and model_attribute_value == attribute_info[VALUE][DEFAULT])
1003+
result = (model_attribute_value == wlst_attribute_value and
1004+
model_attribute_value == attribute_info[VALUE][DEFAULT])
9691005

9701006
return result
9711007

@@ -1037,6 +1073,27 @@ def get_model_attribute_default_value(self, location, model_attribute_name):
10371073
self._logger.exiting(class_name=self._class_name, method_name=_method_name, result=default_value)
10381074
return default_value
10391075

1076+
def get_model_attribute_type(self, location, model_attribute_name):
1077+
"""
1078+
Get the wlst_type for the model attribute name at the specified location
1079+
:param location:
1080+
:param model_attribute_name:
1081+
:return:
1082+
"""
1083+
wlst_type = None
1084+
attribute_info = self._alias_entries.get_alias_attribute_entry_by_model_name(location, model_attribute_name)
1085+
if attribute_info is not None:
1086+
wlst_type = attribute_info[WLST_TYPE]
1087+
return wlst_type
1088+
1089+
def get_ignore_attribute_names(self):
1090+
"""
1091+
Return the list of attribute names that are ignored by the aliases and not defined in the alias category
1092+
json files.
1093+
:return: list of ignored attribute
1094+
"""
1095+
return self._alias_entries.IGNORE_FOR_MODEL_LIST
1096+
10401097
####################################################################################
10411098
#
10421099
# Private methods, private inner classes and static methods only, beyond here please
@@ -1051,7 +1108,7 @@ def __decrypt_password(self, text):
10511108
:raises EncryptionException: if an error occurs while decrypting the password
10521109
"""
10531110
if text is None or len(str(text)) == 0 or \
1054-
not self._model_context.is_using_encryption() or\
1111+
(self._model_context and not self._model_context.is_using_encryption()) or\
10551112
not EncryptionUtils.isEncryptedString(text):
10561113

10571114
rtnval = text

core/src/main/python/wlsdeploy/tool/discover/discoverer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _populate_model_parameters(self, dictionary, location):
8686
pe.getLocalizedMessage(), class_name=_class_name, method_name=_method_name)
8787
continue
8888
else:
89+
_logger.finer('WLSDPLY-06131', wlst_param, class_name=_class_name, method_name=_method_name)
8990
wlst_value = wlst_params[wlst_param]
9091

9192
# if type(wlst_value) == str and len(wlst_value) == 0:

core/src/main/python/wlsdeploy/util/model_context.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -514,18 +514,18 @@ def tokenize_path(self, path):
514514
cwd = path_utils.fixup_path(os.path.dirname(os.path.abspath(__file__)))
515515

516516
# decide later what is required to be in context home for appropriate exception prevention
517-
if self.get_wl_home() and my_path.startswith(self.get_wl_home()):
518-
result = my_path.replace(self.get_wl_home(), self.__WL_HOME_TOKEN)
519-
elif self.get_domain_home() and my_path.startswith(self.get_domain_home()):
520-
result = my_path.replace(self.get_domain_home(), self.__DOMAIN_HOME_TOKEN)
521-
elif self.get_oracle_home() and my_path.startswith(self.get_oracle_home()):
522-
result = my_path.replace(self.get_oracle_home(), self.__ORACLE_HOME_TOKEN)
523-
elif my_path.startswith(cwd):
524-
result = my_path.replace(cwd, self.__CURRENT_DIRECTORY_TOKEN)
525-
elif my_path.startswith(tmp_dir):
526-
result = my_path.replace(tmp_dir, self.__TEMP_DIRECTORY_TOKEN)
527-
else:
528-
result = my_path
517+
result = my_path
518+
if my_path:
519+
if self.get_wl_home() and my_path.startswith(self.get_wl_home()):
520+
result = my_path.replace(self.get_wl_home(), self.__WL_HOME_TOKEN)
521+
elif self.get_domain_home() and my_path.startswith(self.get_domain_home()):
522+
result = my_path.replace(self.get_domain_home(), self.__DOMAIN_HOME_TOKEN)
523+
elif self.get_oracle_home() and my_path.startswith(self.get_oracle_home()):
524+
result = my_path.replace(self.get_oracle_home(), self.__ORACLE_HOME_TOKEN)
525+
elif my_path.startswith(cwd):
526+
result = my_path.replace(cwd, self.__CURRENT_DIRECTORY_TOKEN)
527+
elif my_path.startswith(tmp_dir):
528+
result = my_path.replace(tmp_dir, self.__TEMP_DIRECTORY_TOKEN)
529529

530530
return result
531531

core/src/main/python/wlsdeploy/util/wlst_helper.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,20 @@ def lsa(path=None, log_throwing=True):
239239
"""
240240
_method_name = 'lsa'
241241
result = _ls(_method_name, 'a', path, log_throwing)
242-
if wlst.WLS_ON.isConnected() and result and len(result) > 1:
243-
make_dict = dict()
242+
make_dict = dict()
243+
if result and len(result) > 1:
244244
for entry in result.entrySet():
245245
key = entry.getKey()
246246
value = entry.getValue()
247-
if value is not None and type(value) is str:
247+
if value and type(value) is str:
248248
new_value = value.rstrip()
249249
if new_value == 'null' or new_value == 'none':
250250
make_dict[key] = None
251251
else:
252252
make_dict[key] = new_value
253-
result = make_dict
254-
return result
253+
else:
254+
make_dict[key] = value
255+
return make_dict
255256

256257

257258
def lsc(path=None, log_throwing=True):

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ WLSDPLY-06126=Locate model name for MBean interface {0} for {1}
456456
WLSDPLY-06127=Unable to discover the wlst attribute {0} value at location {1} : {2}
457457
WLSDPLY-06130=Unexpected exception attempting to discover MBean entries at {0} will prevent the discovery \
458458
of attributes at this location : {1}
459+
WLSDPLY-06131=Attribute {0} retrieved from lsa() map
459460
WLSDPLY-06140=Unable to cd to the expected path {0} constructed from location context {1}; the current folder \
460461
and its sub-folders cannot be discovered : {2}
461462

@@ -944,7 +945,7 @@ WLSDPLY-12229=Changing the administration server name from {0} to {1}
944945
WLSDPLY-12230=Creating placeholder for Coherence cluster {0}
945946

946947
# domain_typedef.py
947-
WLSDPLY-12300=={0} got the domain type {1} but the domain type definition file {2} was not valid: {3}
948+
WLSDPLY-12300={0} got the domain type {1} but the domain type definition file {2} was not valid: {3}
948949
WLSDPLY-12301={0} failed to load the definition for domain type {1} from {2} due to a parsing error: {3}
949950
WLSDPLY-12302=Domain typedef class not properly initialized with the model context
950951
WLSDPLY-12303=Domain type {0} type definition in file {1} contains type definition {2} that does not \

0 commit comments

Comments
 (0)