Skip to content

Commit 25d1a77

Browse files
authored
Owls 741 verify jfr db connectivity (#1432)
* add precheck for db connectivity if the domain is required rcu domain type * refactor * use helper method
1 parent cd39570 commit 25d1a77

File tree

3 files changed

+180
-50
lines changed

3 files changed

+180
-50
lines changed

core/src/main/python/create.py

+66-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
"""
77
import os
88
import sys
9+
import exceptions
910

11+
from java.lang import Exception as JException
1012
from java.io import IOException
1113
from java.lang import IllegalArgumentException
1214
from java.lang import String
1315
from java.lang import System
16+
import java.sql.DriverManager as DriverManager
17+
import java.util.Properties as Properties
18+
1419
from oracle.weblogic.deploy.create import CreateException
1520
from oracle.weblogic.deploy.deploy import DeployException
1621
from oracle.weblogic.deploy.util import FileUtils
@@ -45,6 +50,7 @@
4550
from wlsdeploy.util.weblogic_helper import WebLogicHelper
4651
from wlsdeploy.tool.create import atp_helper
4752
from wlsdeploy.tool.create import ssl_helper
53+
import wlsdeploy.tool.create.rcudbinfo_helper as rcudbinfo_helper
4854

4955
wlst_helper.wlst_functions = globals()
5056

@@ -296,6 +302,54 @@ def _get_domain_path(model_context, model):
296302
return domain_parent + os.sep + DEFAULT_WLS_DOMAIN_NAME
297303

298304

305+
def _precheck_rcu_connectivity(model_context, creator, rcu_db_info):
306+
307+
_method_name = '_precheck_rcu_connectivity'
308+
domain_typename = model_context.get_domain_typedef().get_domain_type()
309+
310+
if model_context.get_domain_typedef().required_rcu() and not model_context.is_run_rcu() and 'STB' in \
311+
model_context.get_domain_typedef().get_rcu_schemas():
312+
# how to create rcu_db_info ?
313+
db_conn_props = None
314+
fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \
315+
tns_admin, truststore, truststore_pwd, \
316+
truststore_type = creator.get_rcu_basic_connection_info(rcu_db_info)
317+
318+
if is_atp_ds:
319+
db_conn_props = creator.get_atp_standard_conn_properties(tns_admin, truststore, truststore_pwd,
320+
truststore_type, keystore_pwd, keystore_type,
321+
keystore)
322+
elif is_ssl_ds:
323+
db_conn_props = creator.get_ssl_standard_conn_properties(tns_admin, truststore, truststore_pwd,
324+
truststore_type, keystore_pwd, keystore_type,
325+
keystore)
326+
327+
try:
328+
props = Properties()
329+
if db_conn_props is not None:
330+
for item in db_conn_props:
331+
for key in item.keys():
332+
props.put(key, item[key])
333+
334+
__logger.info('WLSDPLY_12575', 'test datasource', fmw_database, rcu_prefix + "_STB", props,
335+
class_name=_class_name, method_name=_method_name)
336+
337+
props.put('user', rcu_prefix + "_STB")
338+
props.put('password', rcu_schema_pwd)
339+
340+
DriverManager.getConnection(fmw_database, props)
341+
342+
except (exceptions.Exception, JException), e:
343+
__logger.severe('WLSDPLY-12505', domain_typename, e.getClass().getName(), e.getLocalizedMessage())
344+
ex = exception_helper.create_create_exception('WLSDPLY-12505', domain_typename, e.getClass().getName(),
345+
e.getLocalizedMessage(), error=e)
346+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
347+
raise ex
348+
except ee:
349+
ex = exception_helper.create_create_exception('WLSDPLY-12506', domain_typename, ee)
350+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
351+
raise ex
352+
299353
def main(model_context):
300354
"""
301355
The entry point for the createDomain tool.
@@ -337,16 +391,20 @@ def main(model_context):
337391
archive_helper.extract_all_database_wallets()
338392

339393
creator = DomainCreator(model_dictionary, model_context, aliases)
394+
395+
rcu_db_info = rcudbinfo_helper.create(model_dictionary, model_context, aliases)
396+
397+
# JRF domain pre-check connectivity
398+
_precheck_rcu_connectivity(model_context, creator, rcu_db_info)
399+
340400
creator.create()
341401

342-
if has_atp:
343-
rcu_properties_map = model_dictionary[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO]
344-
rcu_db_info = RcuDbInfo(model_context, aliases, rcu_properties_map)
345-
atp_helper.fix_jps_config(rcu_db_info, model_context)
346-
elif has_ssl:
347-
rcu_properties_map = model_dictionary[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO]
348-
rcu_db_info = RcuDbInfo(model_context, aliases, rcu_properties_map)
349-
ssl_helper.fix_jps_config(rcu_db_info, model_context)
402+
if model_context.get_domain_typedef().required_rcu():
403+
if has_atp:
404+
atp_helper.fix_jps_config(rcu_db_info, model_context)
405+
elif has_ssl:
406+
ssl_helper.fix_jps_config(rcu_db_info, model_context)
407+
350408
except WLSDeployArchiveIOException, ex:
351409
_exit_code = ExitCode.ERROR
352410
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,

core/src/main/python/wlsdeploy/tool/create/domain_creator.py

+111-41
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,6 @@ def __validate_and_get_atp_rcudbinfo(self, rcu_db_info, check_admin_pwd=False):
10701070
keystore_type = rcu_db_info.get_keystore_type()
10711071
truststore = rcu_db_info.get_truststore()
10721072
keystore = rcu_db_info.get_keystore()
1073-
10741073
if keystore_pwd is None and keystore_type != 'SSO':
10751074
ex = exception_helper.create_create_exception('WLSDPLY-12413','javax.net.ssl.keyStorePassword',
10761075
"['tns.alias','javax.net.ssl.keyStorePassword',"
@@ -1092,7 +1091,8 @@ def __validate_and_get_atp_rcudbinfo(self, rcu_db_info, check_admin_pwd=False):
10921091
"'rcu_admin_password']")
10931092
raise ex
10941093

1095-
return tns_admin, rcu_database, truststore_pwd, truststore_type, truststore, keystore_pwd, keystore_type, keystore
1094+
return tns_admin, rcu_database, truststore_pwd, truststore_type, truststore, keystore_pwd, keystore_type, \
1095+
keystore
10961096

10971097
def __validate_and_get_ssl_rcudbinfo(self, rcu_db_info, check_admin_pwd=False):
10981098
"""
@@ -1175,45 +1175,8 @@ def __set_rcu_datasource_parameters_without_shadow_table(self, rcu_db_info):
11751175
"""
11761176
_method_name = 'set_rcu_datasource_parameters'
11771177

1178-
rcu_prefix = rcu_db_info.get_preferred_prefix()
1179-
rcu_schema_pwd = rcu_db_info.get_preferred_schema_pass()
1180-
1181-
if rcu_prefix is None:
1182-
ex = exception_helper.create_create_exception('WLSDPLY-12413','rcu_prefix',
1183-
"['rcu_prefix','rcu_schema_password']")
1184-
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
1185-
raise ex
1186-
1187-
if rcu_schema_pwd is None:
1188-
ex = exception_helper.create_create_exception('WLSDPLY-12413','rcu_schema_password',
1189-
"['rcu_prefix','rcu_schema_password']")
1190-
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
1191-
raise ex
1192-
1193-
1194-
# For ATP databases : we need to set all the property for each datasource
1195-
# load atp connection properties from properties file
1196-
# HANDLE ATP case
1197-
is_atp_ds = rcu_db_info.is_use_atp()
1198-
is_ssl_ds = rcu_db_info.is_use_ssl()
1199-
1200-
if is_atp_ds:
1201-
tns_admin, rcu_database, truststore_pwd, truststore_type, \
1202-
truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_atp_rcudbinfo(rcu_db_info)
1203-
elif is_ssl_ds:
1204-
tns_admin, rcu_database, truststore_pwd, truststore_type, \
1205-
truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_ssl_rcudbinfo(rcu_db_info)
1206-
else:
1207-
rcu_database = rcu_db_info.get_preferred_db()
1208-
1209-
if rcu_database is None:
1210-
ex = exception_helper.create_create_exception('WLSDPLY-12564')
1211-
raise ex
1212-
1213-
# Need to set for the connection property for each datasource
1214-
1215-
fmw_database = self.wls_helper.get_jdbc_url_from_rcu_connect_string(rcu_database)
1216-
self.logger.fine('WLSDPLY-12221', fmw_database, class_name=self.__class_name, method_name=_method_name)
1178+
fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \
1179+
tns_admin, truststore, truststore_pwd, truststore_type = self.get_rcu_basic_connection_info(rcu_db_info)
12171180

12181181
location = LocationContext()
12191182
location.append_location(JDBC_SYSTEM_RESOURCE)
@@ -1566,3 +1529,110 @@ def __configure_opss_secrets(self):
15661529
self.wlst_helper.set_shared_secret_store_with_password(opss_wallet, opss_secret_password)
15671530

15681531
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
1532+
1533+
def get_rcu_basic_connection_info(self, rcu_db_info):
1534+
1535+
_method_name = 'get_rcu_basic_connection_info'
1536+
1537+
keystore = None
1538+
keystore_pwd = None
1539+
keystore_type = None
1540+
tns_admin = None
1541+
truststore = None
1542+
truststore_pwd = None
1543+
truststore_type = None
1544+
1545+
rcu_prefix = rcu_db_info.get_preferred_prefix()
1546+
rcu_schema_pwd = rcu_db_info.get_preferred_schema_pass()
1547+
if rcu_prefix is None:
1548+
ex = exception_helper.create_create_exception('WLSDPLY-12413', 'rcu_prefix',
1549+
"['rcu_prefix','rcu_schema_password']")
1550+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
1551+
raise ex
1552+
if rcu_schema_pwd is None:
1553+
ex = exception_helper.create_create_exception('WLSDPLY-12413', 'rcu_schema_password',
1554+
"['rcu_prefix','rcu_schema_password']")
1555+
self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name)
1556+
raise ex
1557+
1558+
# For ATP databases : we need to set all the property for each datasource
1559+
# load atp connection properties from properties file
1560+
# HANDLE ATP case
1561+
1562+
is_atp_ds = rcu_db_info.is_use_atp()
1563+
is_ssl_ds = rcu_db_info.is_use_ssl()
1564+
if is_atp_ds:
1565+
tns_admin, rcu_database, truststore_pwd, truststore_type, \
1566+
truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_atp_rcudbinfo(rcu_db_info)
1567+
elif is_ssl_ds:
1568+
tns_admin, rcu_database, truststore_pwd, truststore_type, \
1569+
truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_ssl_rcudbinfo(rcu_db_info)
1570+
else:
1571+
rcu_database = rcu_db_info.get_preferred_db()
1572+
if rcu_database is None:
1573+
ex = exception_helper.create_create_exception('WLSDPLY-12564')
1574+
raise ex
1575+
1576+
# Need to set for the connection property for each datasource
1577+
fmw_database = self.wls_helper.get_jdbc_url_from_rcu_connect_string(rcu_database)
1578+
self.logger.fine('WLSDPLY-12221', fmw_database, class_name=self.__class_name, method_name=_method_name)
1579+
1580+
return fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \
1581+
tns_admin, truststore, truststore_pwd, truststore_type
1582+
1583+
def get_ssl_standard_conn_properties(self, tns_admin, truststore, truststore_pwd,
1584+
truststore_type, keystore_pwd, keystore_type, keystore):
1585+
properties_set = []
1586+
1587+
# Should always have trust store
1588+
properties_set.append({DRIVER_PARAMS_TRUSTSTORE_PROPERTY: self.__get_store_path(tns_admin, truststore)})
1589+
1590+
properties_set.append({DRIVER_PARAMS_TRUSTSTORETYPE_PROPERTY: truststore_type})
1591+
1592+
# if not sso type then user must provide pwd
1593+
if truststore_pwd is not None and truststore_pwd != 'None':
1594+
properties_set.append({DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY: truststore_pwd})
1595+
1596+
if keystore_pwd is not None and keystore_pwd != 'None':
1597+
properties_set.append({DRIVER_PARAMS_KEYSTOREPWD_PROPERTY: keystore_pwd})
1598+
1599+
# if it is 2 ways SSL
1600+
if keystore is not None and keystore != 'None':
1601+
properties_set.append({DRIVER_PARAMS_KEYSTORE_PROPERTY: self.__get_store_path(tns_admin, keystore)})
1602+
1603+
if keystore_type is not None and keystore_type != 'None':
1604+
properties_set.append({DRIVER_PARAMS_KEYSTORETYPE_PROPERTY: keystore_type})
1605+
1606+
return properties_set
1607+
1608+
def get_atp_standard_conn_properties(self, tns_admin, truststore, truststore_pwd,
1609+
truststore_type, keystore_pwd, keystore_type, keystore):
1610+
1611+
keystore, keystore_type, truststore, truststore_type = atp_helper.fix_store_type_and_default_value(keystore,
1612+
keystore_type, truststore, truststore_type)
1613+
1614+
properties_set = []
1615+
1616+
properties_set.append({DRIVER_PARAMS_KEYSTORE_PROPERTY: self.__get_store_path(tns_admin,
1617+
keystore)})
1618+
1619+
properties_set.append({DRIVER_PARAMS_KEYSTORETYPE_PROPERTY: keystore_type})
1620+
1621+
if keystore_pwd:
1622+
properties_set.append({DRIVER_PARAMS_KEYSTOREPWD_PROPERTY: keystore_pwd})
1623+
1624+
properties_set.append({DRIVER_PARAMS_TRUSTSTORE_PROPERTY: self.__get_store_path(tns_admin,
1625+
truststore)})
1626+
1627+
properties_set.append({DRIVER_PARAMS_TRUSTSTORETYPE_PROPERTY: truststore_type})
1628+
1629+
if truststore_pwd:
1630+
properties_set.append({DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY: truststore_pwd})
1631+
1632+
properties_set.append({DRIVER_PARAMS_NET_SSL_VERSION: DRIVER_PARAMS_NET_SSL_VERSION_VALUE})
1633+
1634+
properties_set.append({DRIVER_PARAMS_NET_SERVER_DN_MATCH_PROPERTY: 'true'})
1635+
properties_set.append({DRIVER_PARAMS_NET_TNS_ADMIN: tns_admin})
1636+
properties_set.append({DRIVER_PARAMS_NET_FAN_ENABLED: 'false'})
1637+
1638+
return properties_set

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ WLSDPLY-12572=Failed to create domain because either RCUDbinfo is missing rcu_db
14531453
in command line option
14541454
WLSDPLY-12573=Invalid databaseType specified in RCUDbInfo: {0}. It must be 'SSL' or 'ATP'
14551455
WLSDPLY-12574=Path: {0} specified for JDBC driver property: {1} does not exists. Please check your model's RCUDbInfo section.
1456-
WLSDPLY_12575=Setting rcu datasource {0} driver params - url: {1} schema: {2} properties: {3}
1456+
WLSDPLY_12575=Setting rcu datasource {0} driver params - url: {1}. schema: {2}. properties: {3}.
14571457

14581458
# domain_typedef.py
14591459
WLSDPLY-12300={0} got the domain type {1} but the domain type definition file {2} was not valid: {3}
@@ -1500,6 +1500,8 @@ WLSDPLY-12501=The role {0} has no specified expression value and will be ignored
15001500
WLSDPLY-12502=The role {0} is not a WebLogic global role and will use the expression as specified
15011501
WLSDPLY-12503=The role {0} specifies an invalid update mode and will use the default replace mode
15021502
WLSDPLY-12504=The processing of WebLogic roles from the model is not support with WebLogic Server version {0}
1503+
WLSDPLY-12505={0} domain creation precheck failed. {1}: {2}
1504+
WLSDPLY-12506={0} domain creation precheck failed. {1}
15031505

15041506
###############################################################################
15051507
# YAML/JSON messages (18000 - 18999) #

0 commit comments

Comments
 (0)