Skip to content

Commit 4587ade

Browse files
continue changes for online
1 parent 4bb7ac9 commit 4587ade

File tree

5 files changed

+146
-14
lines changed

5 files changed

+146
-14
lines changed

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

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from java.lang import RuntimeException
1818
from java.lang import String
1919
from java.util import Properties
20+
from javax.management import ObjectName
2021

2122
from oracle.weblogic.deploy.aliases import TypeUtils
2223
from oracle.weblogic.deploy.aliases import VersionException
@@ -30,11 +31,13 @@
3031
from wlsdeploy.aliases.alias_constants import ATTRIBUTES
3132
from wlsdeploy.aliases.alias_constants import COMMA_DELIMITED_STRING
3233
from wlsdeploy.aliases.alias_constants import DELIMITED_STRING
34+
from wlsdeploy.aliases.alias_constants import DICTIONARY
3335
from wlsdeploy.aliases.alias_constants import JARRAY
3436
from wlsdeploy.aliases.alias_constants import JAVA_LANG_BOOLEAN
3537
from wlsdeploy.aliases.alias_constants import LIST
3638
from wlsdeploy.aliases.alias_constants import LONG
3739
from wlsdeploy.aliases.alias_constants import PATH_SEPARATOR_DELIMITED_STRING
40+
from wlsdeploy.aliases.alias_constants import PROPERTIES
3841
from wlsdeploy.aliases.alias_constants import PREFERRED_MODEL_TYPE
3942
from wlsdeploy.aliases.alias_constants import SECURITY_PROVIDER_FOLDER_PATHS
4043
from wlsdeploy.aliases.alias_constants import SECURITY_PROVIDER_MBEAN_NAME_MAP
@@ -626,6 +629,67 @@ def get_number_of_directories_to_strip(desired_path_type, actual_path_type):
626629
return result
627630

628631

632+
def convert_from_type(data_type, value, preferred=None, delimiter=None):
633+
"""
634+
Convert from wlst type
635+
:param data_type: type of data
636+
:param value: value of data
637+
:param preferred: how it should be represented
638+
:param delimiter: for representation
639+
:return: converted type
640+
"""
641+
642+
_method_name = 'convert_from_type'
643+
if value is not None and data_type == 'password':
644+
# The password is an array of bytes coming back from the WLST get() method and only
645+
# java.lang.String() is able to properly convert it to the cipher text string. However,
646+
# we don't really want to return a java.lang.String to the caller so convert that Java
647+
# String back to a Python string...ugly but effective.
648+
new_value = str(String(value))
649+
elif value is not None and isinstance(value, ObjectName):
650+
new_value = value.getKeyProperty('Name')
651+
else:
652+
try:
653+
new_value = TypeUtils.convertToType(data_type, value, delimiter)
654+
except NumberFormatException, nfe:
655+
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter,
656+
nfe.getLocalizedMessage(), error=nfe)
657+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
658+
raise ex
659+
660+
if preferred:
661+
delimiter = compute_delimiter_from_data_type(preferred, value)
662+
try:
663+
if data_type == LONG:
664+
new_value = Long(new_value)
665+
elif data_type == JAVA_LANG_BOOLEAN:
666+
new_value = Boolean(new_value)
667+
elif data_type == JARRAY:
668+
new_value = _create_array(new_value, delimiter)
669+
elif data_type == PROPERTIES:
670+
if preferred == DICTIONARY:
671+
new_value =
672+
elif data_type == LIST:
673+
new_value = list(new_value)
674+
elif data_type in (COMMA_DELIMITED_STRING, DELIMITED_STRING, SEMI_COLON_DELIMITED_STRING,
675+
SPACE_DELIMITED_STRING, PATH_SEPARATOR_DELIMITED_STRING):
676+
#
677+
# This code intentionally ignores the delimiter value passed in and computes it from the data type.
678+
# This is required to handle the special case where the value we read from WLST might have a
679+
# different delimiter than the model value. In this use case, the value passed into the method
680+
# is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the
681+
# model delimiter from the data_type directly.
682+
#
683+
delimiter = compute_delimiter_from_data_type(data_type, new_value)
684+
new_value = delimiter.join(new_value)
685+
except TypeError, te:
686+
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, te)
687+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
688+
raise ex
689+
690+
return new_value
691+
692+
629693
def convert_to_type(data_type, value, subtype=None, delimiter=None):
630694
"""
631695
Convert the value to the specified type.
@@ -661,7 +725,7 @@ def convert_to_type(data_type, value, subtype=None, delimiter=None):
661725
new_value = Boolean(new_value)
662726
elif data_type == JARRAY:
663727
if subtype is None or subtype == 'java.lang.String':
664-
new_value = _create_string_array(new_value)
728+
new_value = _create_string_jarray(new_value)
665729
else:
666730
new_value = _create_mbean_array(new_value, subtype)
667731
elif data_type == LIST:
@@ -951,7 +1015,7 @@ def _get_value_for_path_type(path_type):
9511015
return result
9521016

9531017

954-
def _create_string_array(iterable):
1018+
def _create_string_jarray(iterable):
9551019
"""
9561020
Create a jarray of java.lang.String suitable for WLST attributes that take list objects.
9571021
This is mostly used for WLST online.
@@ -962,11 +1026,38 @@ def _create_string_array(iterable):
9621026
myarray = jarray.zeros(array_len, String)
9631027
idx = 0
9641028
for element in iterable:
965-
myarray[idx] = element
1029+
if isinstance(element, String):
1030+
myarray[idx] = element
1031+
elif isinstance(element, ObjectName):
1032+
myarray[idx] = ObjectName.unquote(element.getKeyProperty('Name'))
1033+
else:
1034+
myarray[idx] = str(element)
9661035
idx += 1
9671036
return myarray
9681037

9691038

1039+
def _create_array(iterable, delimiter):
1040+
"""
1041+
Create an array from the jarray objects. If the delimiter is present, convert it to
1042+
a string with the delimiter.
1043+
:param iterable: a List object or other iterable type
1044+
:param delimiter: to create a string from the array
1045+
:return: an array or a string containing the same contents as the provided iterable
1046+
"""
1047+
myarray = []
1048+
for element in iterable:
1049+
if isinstance(element, ObjectName):
1050+
myarray.append(element.getKeyProperty('Name'))
1051+
elif not delimiter or isinstance(element, String):
1052+
myarray.append(str(element))
1053+
else:
1054+
myarray.append(element)
1055+
if delimiter:
1056+
# make it to a string
1057+
myarray = delimiter.join(myarray)
1058+
return myarray
1059+
1060+
9701061
def _create_mbean_array(iterable, subtype):
9711062
"""
9721063
Create a jarray of the subtype suitable for WLST attributes that take list objects.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,12 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
814814
alias_utils.compute_read_data_type_and_delimiter_from_attribute_info(attribute_info,
815815
wlst_attribute_value)
816816

817-
converted_value = alias_utils.convert_to_type(data_type, wlst_attribute_value, delimiter=delimiter)
817+
preferred_type = None
818+
if PREFERRED_MODEL_TYPE in attribute_info:
819+
preferred_type = attribute_info[PREFERRED_MODEL_TYPE]
820+
self._logger.fine('wlst attribute {0} data type {1} delimiter {2}')
821+
converted_value = alias_utils.convert_from_type(data_type, wlst_attribute_value, delimiter=delimiter,
822+
preferred=preferred_type)
818823
model_attribute_name = attribute_info[MODEL_NAME]
819824
default_value = attribute_info[VALUE][DEFAULT]
820825
#

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

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import javaos as os
66

7+
from oracle.weblogic.deploy.aliases import AliasException
78
from oracle.weblogic.deploy.discover import DiscoverException
89
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
910
from oracle.weblogic.deploy.util import PyWLSTException
@@ -131,21 +132,38 @@ def _get_attributes_for_current_location_offline(self, location):
131132

132133
def _get_attributes_for_current_location_online(self, location):
133134
_method_name = '_get_attributes_for_current_location_online'
134-
attributes = []
135+
attributes = dict()
135136
path = self._alias_helper.get_wlst_attributes_path(location)
137+
added = False
136138
try:
137139
attributes = wlst_helper.lsa(path)
138140
mbean_attributes = wlst_helper.get_mbi().getAttributes()
139-
for mbean_attribute in mbean_attributes:
140-
name = mbean_attribute.getName()
141-
if name not in attributes:
142-
attributes[name] = wlst_helper.get(name)
141+
if mbean_attributes:
142+
alias_attributes = self._get_wlst_attributes(location)
143+
for mbean_attribute in mbean_attributes:
144+
name = mbean_attribute.getName()
145+
if name not in attributes and name in alias_attributes:
146+
attributes[name] = wlst_helper.get(name)
147+
added = True
148+
_logger.fine('Adding attribute {0} value {1}', name, attributes[name])
143149
except PyWLSTException, pe:
144150
name = location.get_model_folders()[-1]
145151
_logger.fine('WLSDPLY-06109', name, str(location), pe.getLocalizedMessage(), class_name=_class_name,
146152
method_name=_method_name)
153+
if added:
154+
for key, value in attributes.iteritems():
155+
_logger.fine('attribute list {0}={1}', key, value)
147156
return attributes
148157

158+
def _is_defined_attribute(self, location, wlst_name):
159+
attribute = False
160+
try:
161+
if self._aliases.get_model_attribute_name(location, wlst_name):
162+
attribute = True
163+
except AliasException, ae:
164+
pass
165+
return attribute
166+
149167
def _get_required_attributes(self, location):
150168
"""
151169
Use get for all online attributes, and use the attribute names in the
@@ -247,8 +265,13 @@ def _find_subfolders(self, location):
247265
wlst_path = self._alias_helper.get_wlst_subfolders_path(location)
248266
self._wlst_helper.cd(wlst_path)
249267
wlst_subfolders = self._wlst_helper.lsc()
250-
if len(wlst_subfolders) == 0:
251-
wlst_subfolders = None
268+
if wlst_subfolders:
269+
new_subfolders = []
270+
for wlst_subfolder in wlst_subfolders:
271+
model_subfolder_name = self._get_model_name(location, wlst_subfolder)
272+
if model_subfolder_name:
273+
new_subfolders.append(wlst_subfolder)
274+
wlst_subfolders = new_subfolders
252275
return wlst_subfolders
253276

254277
def _discover_subfolder_singleton(self, model_subfolder_name, location):
@@ -540,6 +563,19 @@ def _find_mbean_interface(self, location, interfaces):
540563
break
541564
return mbean_name
542565

566+
def _get_wlst_attributes(self, location):
567+
wlst_attributes = []
568+
model_attributes = self._alias_helper.get_model_attribute_names(location)
569+
if model_attributes:
570+
for model_attribute in model_attributes:
571+
try:
572+
wlst_attribute = self._aliases.get_wlst_attribute_name(location, model_attribute)
573+
if wlst_attribute:
574+
wlst_attributes.append(wlst_attribute)
575+
except AliasException, ae:
576+
continue
577+
return wlst_attributes
578+
543579

544580
def add_to_model_if_not_empty(dictionary, entry_name, entry_value):
545581
"""

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ def lsa(path=None, log_throwing=True):
242242
if wlst.WLS_ON.isConnected() and result and len(result) > 1:
243243
make_dict = dict()
244244
for entry in result.entrySet():
245-
key = entry.getValue()
246-
value = entry.getKey()
245+
key = entry.getKey()
246+
value = entry.getValue()
247247
if value is not None and type(value) is str:
248248
new_value = value.rstrip()
249249
if new_value == 'null':

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"DeploymentOrder": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "DeploymentOrder", "wlst_path": "WP001", "value": {"default": 1000 }, "wlst_type": "integer" } ],
1515
"Notes": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "Notes", "wlst_path": "WP001", "value": {"default": "None"}, "wlst_type": "string" } ],
1616
"Target": [ {"version": "[10,)", "wlst_mode": "offline", "wlst_name": "Target", "wlst_path": "WP001", "value": {"default": "None"}, "wlst_type": "delimited_string" },
17-
{"version": "[10,)", "wlst_mode": "online", "wlst_name": "Targets", "wlst_path": "WP002", "value": {"default": "None"}, "wlst_type": "jarray", "set_method": "MBEAN.set_target_mbeans", "set_mbean_type": "weblogic.management.configuration.TargetMBean"} ]
17+
{"version": "[10,)", "wlst_mode": "online", "wlst_name": "Targets", "wlst_path": "WP002", "value": {"default": "None"}, "wlst_type": "jarray", "preferred_model_type": "delimited_string", "set_method": "MBEAN.set_target_mbeans", "set_mbean_type": "weblogic.management.configuration.TargetMBean"} ]
1818
},
1919
"wlst_attributes_path": "WP001",
2020
"wlst_paths": {

0 commit comments

Comments
 (0)