Skip to content

Commit 7ec2a31

Browse files
committed
JIRA WDT-47 Create provider MBean from model, set attributes, revise logging
1 parent 6e390e2 commit 7ec2a31

File tree

3 files changed

+122
-2
lines changed

3 files changed

+122
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* The Universal Permissive License (UPL), Version 1.0
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
7+
/**
8+
* Utility methods related to data type conversion.
9+
*/
10+
public final class ConvertUtils {
11+
12+
private ConvertUtils() {
13+
// hide the constructor for this utility class
14+
}
15+
16+
/**
17+
* Convert the specified value to the specified type.
18+
* The conversions and available types are specific to user-defined custom mbeans.
19+
*
20+
* @param value the value to be converted
21+
* @param dataType the class representing the target type
22+
* @return the value converted to the new type, or null if conversion failed
23+
*/
24+
public static Object convertValue(Object value, Class<?> dataType) {
25+
// TODO: fill in data types
26+
27+
if(dataType.equals(String.class)) {
28+
return value;
29+
}
30+
31+
return null;
32+
}
33+
}

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

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
"""
5+
from java.lang import IllegalArgumentException, IllegalAccessException
6+
from java.lang.reflect import InvocationTargetException
7+
from oracle.weblogic.deploy.util import ConvertUtils
58

9+
from wlsdeploy.exception import exception_helper
610
from wlsdeploy.tool.util.alias_helper import AliasHelper
711
from wlsdeploy.tool.util.wlst_helper import WlstHelper
12+
from wlsdeploy.util.weblogic_helper import WebLogicHelper
813

914

1015
class CustomFolderHelper(object):
@@ -18,6 +23,7 @@ def __init__(self, aliases, logger, exception_type):
1823
self.logger = logger
1924
self.exception_type = exception_type
2025
self.alias_helper = AliasHelper(aliases, self.logger, self.exception_type)
26+
self.weblogic_helper = WebLogicHelper(self.logger)
2127
self.wlst_helper = WlstHelper(self.logger, self.exception_type)
2228

2329
def update_security_folder(self, location, model_category, model_type, model_name, model_nodes):
@@ -39,7 +45,80 @@ def update_security_folder(self, location, model_category, model_type, model_nam
3945
self.logger.info('WLSDPLY-12124', model_category, model_name, model_type, location_path,
4046
class_name=self.__class_name, method_name=_method_name)
4147

48+
create_path = self.alias_helper.get_wlst_subfolders_path(location)
49+
self.wlst_helper.cd(create_path)
50+
51+
# TODO for updateDomain: check for existing provider, just cd if present
52+
4253
# create the MBean using the model name, model_type, category
4354

44-
# wlst.create(model_name, model_type, category)
45-
# wlst.create('RAK-SAML', 'SAMLAuthenticator', 'AuthenticationProvider')
55+
self.wlst_helper.create(model_name, model_type, model_category)
56+
57+
provider_path = create_path + '/' + model_category + '/' + model_name
58+
provider_mbean = self.wlst_helper.cd(provider_path)
59+
60+
interface_name = model_type + 'MBean'
61+
bean_info = self.weblogic_helper.get_bean_info_for_interface(interface_name)
62+
if bean_info is None:
63+
ex = exception_helper.create_exception(self.exception_type, 'WLSDPLY-12125', interface_name)
64+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
65+
raise ex
66+
67+
property_map = dict()
68+
for property_descriptor in bean_info.getPropertyDescriptors():
69+
self.logger.finer('WLSDPLY-12126', str(property_descriptor), class_name=self.__class_name,
70+
method_name=_method_name)
71+
property_map[property_descriptor.getName()] = property_descriptor
72+
73+
for model_key in model_nodes:
74+
model_value = model_nodes[model_key]
75+
property_descriptor = property_map.get(model_key)
76+
77+
if not property_descriptor:
78+
ex = exception_helper.create_exception(self.exception_type, 'WLSDPLY-12128', model_key)
79+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
80+
raise ex
81+
82+
# find the setter method for the attribute
83+
84+
method = property_descriptor.writeMethod
85+
if not method:
86+
# this must be a read-only attribute, just log it and continue with next attribute
87+
self.logger.info('WLSDPLY-12129', str(model_key), class_name=self.__class_name,
88+
method_name=_method_name)
89+
continue
90+
91+
self.logger.finer('WLSDPLY-12127', str(model_key), str(model_value), class_name=self.__class_name,
92+
method_name=_method_name)
93+
94+
# determine the data type from the set method
95+
96+
parameter_types = method.getParameterTypes()
97+
parameter_count = len(parameter_types)
98+
99+
if parameter_count != 1:
100+
ex = exception_helper.create_exception(self.exception_type, 'WLSDPLY-12130', model_key,
101+
parameter_count)
102+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
103+
raise ex
104+
105+
property_type = parameter_types[0]
106+
107+
# convert the model value to the target type
108+
109+
set_value = ConvertUtils.convertValue(model_value, property_type)
110+
if set_value is None:
111+
ex = exception_helper.create_exception(self.exception_type, 'WLSDPLY-12131', str(model_value),
112+
str(property_type), model_key)
113+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
114+
raise ex
115+
116+
# call the setter with the target value
117+
118+
try:
119+
method.invoke(provider_mbean, [set_value])
120+
except (IllegalAccessException, IllegalArgumentException, InvocationTargetException), ex:
121+
ex = exception_helper.create_exception(self.exception_type, 'WLSDPLY-12132', str(method),
122+
str(set_value), ex.getLocalizedMessage(), error=ex)
123+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
124+
raise ex

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,14 @@ WLSDPLY-12122=The attribute {0} in model location {1} has value {2} that referen
950950
# The WLSDPLY-12123 resource is used for messages returned from aliases.is_version_valid_location()
951951
WLSDPLY-12123={0}
952952
WLSDPLY-12124=Updating {0} "{1}" ({2}) at location {3}
953+
WLSDPLY-12125=Unable to load bean information for interface {0}
954+
WLSDPLY-12126=Property descriptor {0}
955+
WLSDPLY-12127=Updating attribute {0} to {1}
956+
WLSDPLY-12128=No property descriptor found for attribute {0}
957+
WLSDPLY-12129=Skipping read-only attribute {0}
958+
WLSDPLY-12130=The set method for attribute {0} has {1} arguments
959+
WLSDPLY-12131=Unable to convert value {0} to type {1} for attribute {2}
960+
WLSDPLY-12132=Unable to invoke method {0} with argument {1}: {2}
953961

954962
# domain_creator.py
955963
WLSDPLY-12200={0} did not find the required {1} section in the model file {2}

0 commit comments

Comments
 (0)