Skip to content

Commit b817c94

Browse files
Use the MBeanInfo and MBean interface methods to drive the attribute discovery
1 parent bebeb13 commit b817c94

File tree

6 files changed

+288
-151
lines changed

6 files changed

+288
-151
lines changed

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

Lines changed: 15 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,19 @@ def _populate_model_parameters(self, dictionary, location):
9494
class_name=_class_name, method_name=_method_name)
9595
if wlst_extra_params is not None:
9696
for wlst_extra_param in wlst_extra_params:
97-
if wlst_extra_param not in wlst_get_params:
98-
_logger.info('WLSDPLY-06148', wlst_extra_param, str(location),
97+
if wlst_extra_param in wlst_get_params:
98+
success, wlst_value = self._get_attribute_value_with_get(wlst_extra_param, wlst_path)
99+
if success:
100+
self._add_to_dictionary(dictionary, location, wlst_extra_param, wlst_value, wlst_path)
101+
else:
102+
_logger.info('WLSDPLY-06152', wlst_extra_param, location.get_folder_path(),
103+
class_name=_class_name, method_name=_method_name)
104+
elif self._is_defined_attribute(location, wlst_extra_param):
105+
_logger.info('WLSDPLY-06154', wlst_extra_param, location.get_folder_path(),
106+
class_name=_class_name, method_name=_method_name)
107+
else:
108+
_logger.info('WLSDPLY-06153', wlst_extra_param, location.get_folder_path(),
99109
class_name=_class_name, method_name=_method_name)
100-
success, wlst_value = self._get_attribute_value_with_get(wlst_extra_param, wlst_path)
101-
if success:
102-
self._add_to_dictionary(dictionary, location, wlst_extra_param, wlst_value, wlst_path)
103110

104111
def _get_attribute_value_with_get(self, wlst_get_param, wlst_path):
105112
_method_name = '_get_attribute_value_with_get'
@@ -142,13 +149,7 @@ def _get_attributes_for_current_location(self, location):
142149
:param location: context with the current location information
143150
:return: list of attributes
144151
"""
145-
if self._wlst_mode == WlstModes.OFFLINE:
146-
return self._get_attributes_for_current_location_offline(location)
147-
else:
148-
return self._get_attributes_for_current_location_online(location)
149-
150-
def _get_attributes_for_current_location_offline(self, location):
151-
_method_name = '_get_attributes_for_current_location_offline'
152+
_method_name = '_get_attributes_for_current_location'
152153
attributes = []
153154
path = self._alias_helper.get_wlst_attributes_path(location)
154155
try:
@@ -159,37 +160,12 @@ def _get_attributes_for_current_location_offline(self, location):
159160
method_name=_method_name)
160161
return attributes
161162

162-
def _get_attributes_for_current_location_online(self, location):
163-
_method_name = '_get_attributes_for_current_location_online'
164-
lsa_attributes = dict()
165-
path = self._alias_helper.get_wlst_attributes_path(location)
166-
try:
167-
lsa_attributes = wlst_helper.lsa(path)
168-
mbi_attributes = _get_mbi_attribute_list(path)
169-
if mbi_attributes:
170-
for lsa_attribute_name in lsa_attributes:
171-
if lsa_attribute_name in lsa_attributes and lsa_attribute_name not in mbi_attributes:
172-
_logger.finer('WLSDPLY-06142', lsa_attribute_name)
173-
del lsa_attributes[lsa_attribute_name]
174-
for mbi_attribute_name in mbi_attributes:
175-
if mbi_attribute_name not in lsa_attributes and mbi_attribute_name in mbi_attributes:
176-
# don't count on the item in the get required list in caller, just get the value
177-
# and add it to our lsa list
178-
_logger.finer('WLSDPLY-06141', mbi_attribute_name, class_name=_class_name,
179-
method_name=_method_name)
180-
lsa_attributes[mbi_attribute_name] = wlst_helper.get(mbi_attribute_name)
181-
except PyWLSTException, pe:
182-
name = location.get_model_folders()[-1]
183-
_logger.fine('WLSDPLY-06109', name, str(location), pe.getLocalizedMessage(), class_name=_class_name,
184-
method_name=_method_name)
185-
return lsa_attributes
186-
187163
def _is_defined_attribute(self, location, wlst_name):
188164
attribute = False
189165
try:
190-
if self._aliases.get_model_attribute_name(location, wlst_name):
166+
if self._alias_helper.get_model_attribute_name(location, wlst_name, check_read_only=False):
191167
attribute = True
192-
except AliasException:
168+
except DiscoverException, de:
193169
pass
194170
return attribute
195171

@@ -722,47 +698,10 @@ def convert_to_absolute_path(relative_to, file_name):
722698
return file_name
723699

724700

725-
def _get_mbi_attribute_list(path):
726-
attribute_list = []
727-
for mbean_attribute_info in wlst_helper.get_mbi(path).getAttributes():
728-
if _is_attribute(mbean_attribute_info):
729-
attribute_list.append(mbean_attribute_info.getName())
730-
return attribute_list
731-
732-
733-
def _is_attribute(attributes_info):
734-
return _is_attribute_type(attributes_info) or _is_valid_reference(attributes_info)
735-
736-
737-
def _is_valid_reference(attribute_info):
738-
# check again after all done to see whether need to use get deprecated
739-
return _is_reference(attribute_info) and (
740-
attribute_info.isWritable() or not _is_deprecated(attribute_info))
741-
742-
743-
def _is_reference(mbean_attribute_info):
744-
return mbean_attribute_info.getDescriptor().getFieldValue('com.bea.relationship') == 'reference'
745-
746-
747-
def _is_deprecated(mbean_attribute_info):
748-
deprecated_version = mbean_attribute_info.getDescriptor().getFieldValue('deprecated')
749-
return deprecated_version is not None and deprecated_version != 'null' and len(deprecated_version) > 1
750-
751-
752701
def _is_containment(mbean_attribute_info):
753702
return mbean_attribute_info.getDescriptor().getFieldValue('com.bea.relationship') == 'containment'
754703

755704

756-
def _is_attribute_type(attribute_info):
757-
_method_name = '_is_attribute_type'
758-
if not attribute_info.isWritable() and _is_deprecated(attribute_info):
759-
_logger.finer('WLSDPLY-06143', attribute_info.getName(), wlst_helper.get_pwd(),
760-
class_name=_class_name, method_name=_method_name)
761-
return attribute_info.getDescriptor().getFieldValue(
762-
'descriptorType') == 'Attribute' and attribute_info.getDescriptor().getFieldValue(
763-
'com.bea.relationship') is None and (attribute_info.isWritable() or not _is_deprecated(attribute_info))
764-
765-
766705
def _massage_online_folders(lsc_folders):
767706
_method_name = '_massage_online_folders'
768707
location = wlst_helper.get_pwd()

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ def get_model_attribute_name_and_value(self, location, wlst_name, wlst_value):
3939
raise ex
4040
return model_name, model_value
4141

42+
def get_model_attribute_name(self, location, wlst_attribute_name, check_read_only=True):
43+
"""
44+
Returns the model attribute name for the specified WLST attribute name. If the model attribute name
45+
is not valid for the version or the attribute is marked as read-only, and the check_read_only flag
46+
is True, return None
47+
48+
:param location: the location
49+
:param wlst_attribute_name: the WLST attribute name
50+
:param check_read_only: Defaults to True. If False, return the WLST attribute name even if read only
51+
:return: matching model attribute name
52+
:raises: BundleAwareException: if a AliasException is thrown by the aliases
53+
"""
54+
_method_name = 'get_model_attribute_name'
55+
try:
56+
model_name = self.__aliases.get_model_attribute_name(location, wlst_attribute_name, check_read_only)
57+
except AliasException, ae:
58+
ex = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-19039', str(location),
59+
ae.getLocalizedMessage(), error=ae)
60+
self.__logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
61+
raise ex
62+
return model_name
63+
4264
def get_model_subfolder_names(self, location):
4365
"""
4466
Get the model subfolder names for the specified location.

0 commit comments

Comments
 (0)