Skip to content

Commit 457dc82

Browse files
committed
Merge branch 'custom-resource' into 'main'
Deploy and discover custom resources See merge request weblogic-cloud/weblogic-deploy-tooling!1741
2 parents e4b71bf + 0928284 commit 457dc82

File tree

12 files changed

+147
-15
lines changed

12 files changed

+147
-15
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from wlsdeploy.aliases.model_constants import APP_DEPLOYMENTS
5555
from wlsdeploy.aliases.model_constants import APPLICATION
5656
from wlsdeploy.aliases.model_constants import CALLOUT
57+
from wlsdeploy.aliases.model_constants import CUSTOM_RESOURCE
5758
from wlsdeploy.aliases.model_constants import DOMAIN_INFO
5859
from wlsdeploy.aliases.model_constants import DOMAIN_INFO_ALIAS
5960
from wlsdeploy.aliases.model_constants import EJB_CONTAINER
@@ -134,6 +135,7 @@ class AliasEntries(object):
134135

135136
__resources_top_level_folders = [
136137
'CoherenceClusterSystemResource',
138+
CUSTOM_RESOURCE,
137139
EJB_CONTAINER,
138140
'FileStore',
139141
'ForeignJNDIProvider',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
CREDENTIAL_MAPPER = 'CredentialMapper'
7575
CROSS_DOMAIN = 'CrossDomain'
7676
CUSTOM_DBMS_AUTHENTICATOR = 'CustomDBMSAuthenticator'
77+
CUSTOM_RESOURCE = "CustomResource"
7778
DATA_SOURCE = 'DataSource'
7879

7980
# Deprecated in WDT 4.0.0
@@ -389,6 +390,8 @@
389390
CUSTOM_TRUST_KEYSTORE_FILE = 'CustomTrustKeyStoreFileName'
390391
DATABASE_LESS_LEASING_BASIS = 'DatabaseLessLeasingBasis'
391392
DEPLOYMENT_ORDER = 'DeploymentOrder'
393+
DESCRIPTOR_BEAN_CLASS = 'DescriptorBeanClass'
394+
DESCRIPTOR_FILE_NAME = 'DescriptorFileName'
392395
DESTINATION_SERVER = 'DestinationServer'
393396
DRIVER_NAME = 'DriverName'
394397
DRIVER_PARAMS_PROPERTY_VALUE = 'Value'
@@ -422,6 +425,7 @@
422425
PASSWORD = 'Password'
423426
PATH_TO_SCRIPT = 'PathToScript'
424427
PLAN_STAGING_MODE = 'PlanStagingMode'
428+
RESOURCE_CLASS = 'ResourceClass'
425429
SECURITY_DD_MODEL = 'SecurityDDModel'
426430
SET_OPTION_APP_DIR = 'AppDir'
427431
SET_OPTION_DOMAIN_NAME = 'DomainName'

core/src/main/python/wlsdeploy/tool/deploy/common_resources_deployer.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""
2-
Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5+
from wlsdeploy.aliases.model_constants import CUSTOM_RESOURCE
6+
from wlsdeploy.aliases.model_constants import DESCRIPTOR_BEAN_CLASS
7+
from wlsdeploy.aliases.model_constants import DESCRIPTOR_FILE_NAME
58
from wlsdeploy.aliases.model_constants import EJB_CONTAINER
69
from wlsdeploy.aliases.model_constants import FILE_STORE
710
from wlsdeploy.aliases.model_constants import FOREIGN_JNDI_PROVIDER
@@ -13,6 +16,7 @@
1316
from wlsdeploy.aliases.model_constants import MESSAGING_BRIDGE
1417
from wlsdeploy.aliases.model_constants import OHS
1518
from wlsdeploy.aliases.model_constants import PATH_SERVICE
19+
from wlsdeploy.aliases.model_constants import RESOURCE_CLASS
1620
from wlsdeploy.aliases.model_constants import SAF_AGENT
1721
from wlsdeploy.aliases.model_constants import SELF_TUNING
1822
from wlsdeploy.aliases.model_constants import SNMP_AGENT
@@ -24,6 +28,7 @@
2428
from wlsdeploy.aliases.model_constants import SYSTEM_COMPONENT
2529

2630
from wlsdeploy.aliases.wlst_modes import WlstModes
31+
from wlsdeploy.exception import exception_helper
2732
from wlsdeploy.tool.deploy.deployer import Deployer
2833
from wlsdeploy.util import dictionary_utils
2934

@@ -63,6 +68,27 @@ def _add_subfolders(self, model_nodes, location, excludes=None):
6368

6469
Deployer._add_subfolders(self, model_nodes, location, excludes=excludes)
6570

71+
# Override
72+
def _create_and_cd(self, location, existing_names, child_nodes):
73+
"""
74+
Override the base method for custom resources.
75+
These have to be created using cmo.createCustomResource(...) .
76+
"""
77+
parent_type = self.get_location_type(location)
78+
if parent_type == CUSTOM_RESOURCE and (self.wlst_mode == WlstModes.ONLINE):
79+
self.__create_custom_resource_online_and_cd(location, existing_names, child_nodes)
80+
else:
81+
Deployer._create_and_cd(self, location, existing_names, child_nodes)
82+
83+
def add_custom_resources(self, parent_dict, location):
84+
"""
85+
Deploy the custom resource elements in the dictionary at the specified location.
86+
:param parent_dict: the dictionary possibly containing custom resource elements
87+
:param location: the location to deploy the elements
88+
"""
89+
resources = dictionary_utils.get_dictionary_element(parent_dict, CUSTOM_RESOURCE)
90+
self._add_named_elements(CUSTOM_RESOURCE, resources, location)
91+
6692
def add_ejb_container(self, parent_dict, location):
6793
"""
6894
Deploy the EJB container elements in the dictionary at the specified location.
@@ -180,8 +206,7 @@ def add_snmp_agent_deployments(self, parent_dict, location):
180206
:param location: the location to deploy the elements
181207
"""
182208
deployments = dictionary_utils.get_dictionary_element(parent_dict, SNMP_AGENT_DEPLOYMENT)
183-
if len(deployments) != 0:
184-
self._add_named_elements(SNMP_AGENT_DEPLOYMENT, deployments, location)
209+
self._add_named_elements(SNMP_AGENT_DEPLOYMENT, deployments, location)
185210

186211
def add_self_tuning(self, parent_dict, location):
187212
"""
@@ -244,3 +269,38 @@ def add_ohs_components(self, parent_dict, location):
244269
self.logger.warning('WLSDPLY-09405', OHS, class_name=self._class_name, method_name=_method_name)
245270
else:
246271
self._add_named_elements(OHS, system_components, location)
272+
273+
def __create_custom_resource_online_and_cd(self, location, existing_names, child_nodes):
274+
"""
275+
Create the custom resource at the specified location if it does not exist,
276+
and change to the new directory.
277+
:param location: the location of the custom resource to create
278+
:param existing_names: existing names at the specified location
279+
:param child_nodes: used to gather information to create
280+
"""
281+
_method_name = '__create_custom_resource_online_and_cd'
282+
283+
mbean_name = self.aliases.get_wlst_mbean_name(location)
284+
if mbean_name not in existing_names:
285+
create_path = self.aliases.get_wlst_create_path(location)
286+
self.wlst_helper.cd(create_path)
287+
resource_class = dictionary_utils.get_element(child_nodes, RESOURCE_CLASS)
288+
if not resource_class:
289+
ex = exception_helper.create_deploy_exception(
290+
'WLSDPLY-09426', CUSTOM_RESOURCE, mbean_name, RESOURCE_CLASS)
291+
self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
292+
raise ex
293+
294+
bean_descriptor_class = dictionary_utils.get_element(child_nodes, DESCRIPTOR_BEAN_CLASS)
295+
if not bean_descriptor_class:
296+
ex = exception_helper.create_deploy_exception(
297+
'WLSDPLY-09426', CUSTOM_RESOURCE, mbean_name, DESCRIPTOR_BEAN_CLASS)
298+
self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
299+
raise ex
300+
301+
descriptor_file_name = dictionary_utils.get_element(child_nodes, DESCRIPTOR_FILE_NAME)
302+
self.wlst_helper.create_custom_resource(mbean_name, resource_class, bean_descriptor_class,
303+
descriptor_file_name)
304+
305+
wlst_path = self.aliases.get_wlst_attributes_path(location)
306+
self.wlst_helper.cd(wlst_path)

core/src/main/python/wlsdeploy/tool/deploy/deployer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ def _add_named_elements(self, type_name, model_nodes, location, delete_now=True)
114114

115115
if token is not None:
116116
location.add_name_token(token, name)
117-
self._create_and_cd(location, existing_names)
118117

119118
child_nodes = dictionary_utils.get_dictionary_element(model_nodes, name)
119+
self._create_and_cd(location, existing_names, child_nodes)
120120
self._set_attributes_and_add_subfolders(location, child_nodes)
121121

122122
#
123123
# This method exists purely to allow subclasses to override how an mbean is created.
124124
#
125-
def _create_and_cd(self, location, existing_names):
125+
def _create_and_cd(self, location, existing_names, child_nodes):
126126
deployer_utils.create_and_cd(location, existing_names, self.aliases)
127127

128128
def _add_subfolders(self, model_nodes, location, excludes=None):

core/src/main/python/wlsdeploy/tool/deploy/resources_deployer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import wlsdeploy.util.dictionary_utils as dictionary_utils
@@ -66,6 +66,7 @@ def _add_resources(self, location):
6666
self._add_startup_classes(location)
6767
self._add_shutdown_classes(location)
6868

69+
common_deployer.add_custom_resources(self._resources, location)
6970
common_deployer.add_ejb_container(self._resources, location)
7071
common_deployer.add_foreign_jndi_providers(self._resources, location)
7172
common_deployer.add_file_stores(self._resources, location)

core/src/main/python/wlsdeploy/tool/deploy/topology_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _add_model_elements(self, type_name, model_nodes, location):
8686
self.attribute_setter)
8787

8888
# Override
89-
def _create_and_cd(self, location, existing_names):
89+
def _create_and_cd(self, location, existing_names, child_nodes):
9090
_method_name = '_create_and_cd'
9191

9292
self.logger.entering(str_helper.to_string(location), existing_names,

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ def discover(self):
5555
_logger.entering(class_name=_class_name, method_name=_method_name)
5656
model_folder_name, folder_result = self.get_datasources()
5757
discoverer.add_to_model_if_not_empty(self._dictionary, model_folder_name, folder_result)
58-
59-
self.discover_domain_single_mbean(model_constants.EJB_CONTAINER, self._dictionary)
60-
6158
model_folder_name, folder_result = self.get_foreign_jndi_providers()
6259
discoverer.add_to_model_if_not_empty(self._dictionary, model_folder_name, folder_result)
6360
model_folder_name, folder_result = self.get_mail_sessions()
@@ -69,9 +66,6 @@ def discover(self):
6966
model_folder_name, folder_result = self.get_path_services()
7067
discoverer.add_to_model_if_not_empty(self._dictionary, model_folder_name, folder_result)
7168

72-
self.discover_domain_single_mbean(model_constants.SNMP_AGENT, self._dictionary)
73-
self.discover_domain_named_mbeans(model_constants.SNMP_AGENT_DEPLOYMENT, self._dictionary)
74-
7569
JmsResourcesDiscoverer(self._model_context, self._dictionary, self._base_location, wlst_mode=self._wlst_mode,
7670
aliases=self._aliases, credential_injector=self._get_credential_injector()).discover()
7771

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def discover(self):
6262
model_top_folder_name, optional_feature_deployment = self.get_optional_feature_deployment()
6363
discoverer.add_to_model_if_not_empty(self._dictionary, model_top_folder_name, optional_feature_deployment)
6464

65+
self.discover_domain_named_mbeans(model_constants.CUSTOM_RESOURCE, self._dictionary)
66+
self.discover_domain_single_mbean(model_constants.EJB_CONTAINER, self._dictionary)
67+
self.discover_domain_single_mbean(model_constants.SNMP_AGENT, self._dictionary)
68+
self.discover_domain_named_mbeans(model_constants.SNMP_AGENT_DEPLOYMENT, self._dictionary)
69+
6570
_logger.exiting(class_name=_class_name, method_name=_method_name)
6671
return self._dictionary
6772

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,25 @@ def create_and_cd(self, aliases, type_name, name, location, create_path=None):
378378
self.__logger.exiting(result=result, class_name=self.__class_name, method_name=_method_name)
379379
return result
380380

381+
def create_custom_resource(self, name, resource_class, bean_descriptor_class, descriptor_file_name):
382+
_method_name = 'create_custom_resource'
383+
self.__logger.entering(name, resource_class, bean_descriptor_class, descriptor_file_name,
384+
class_name=self.__class_name, method_name=_method_name)
385+
try:
386+
cmo = self.get_mbean()
387+
if descriptor_file_name:
388+
resource = cmo.createCustomResource(name, resource_class, bean_descriptor_class, descriptor_file_name)
389+
else:
390+
resource = cmo.createCustomResource(name, resource_class, bean_descriptor_class)
391+
self.__logger.exiting(class_name=self.__class_name, method_name=_method_name)
392+
return resource
393+
except (self.__load_global('WLSTException'), offlineWLSTException), e:
394+
pwe = exception_helper.create_exception(self.__exception_type, 'WLSDPLY-00137', name,
395+
resource_class, bean_descriptor_class, descriptor_file_name,
396+
_format_exception(e), error=e)
397+
self.__logger.throwing(class_name=self.__class_name, method_name=_method_name, error=pwe)
398+
raise pwe
399+
381400
def delete(self, name, folder):
382401
"""
383402
Delete an MBean of the specified name and type at the current location.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import sys
77
import traceback
88

9-
from java.lang import Exception as JException
109
from java.lang import System as JSystem
10+
from java.lang import Throwable as JThrowable
1111
from java.util.logging import Level as JLevel
1212

1313
from oracle.weblogic.deploy.aliases import VersionUtils
@@ -85,7 +85,7 @@ def run_tool(main, process_args, args, program_name, class_name, logger):
8585
except exceptions.SystemExit, ex:
8686
cla_helper.clean_up_temp_files()
8787
raise ex
88-
except (exceptions.Exception, JException), ex:
88+
except (exceptions.Exception, JThrowable), ex:
8989
exit_code = ExitCode.ERROR
9090
__handle_unexpected_exception(ex, model_context_obj, class_name, _method_name, logger)
9191

0 commit comments

Comments
 (0)