From 6c044ae0c1a27c1290536bb3323989aba023830e Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Mon, 27 Mar 2023 14:29:17 -0500 Subject: [PATCH 1/3] add precheck for db connectivity if the domain is required rcu domain type --- core/src/main/python/create.py | 80 ++++++++- .../wlsdeploy/tool/create/domain_creator.py | 152 +++++++++++++----- .../deploy/messages/wlsdeploy_rb.properties | 4 +- 3 files changed, 186 insertions(+), 50 deletions(-) diff --git a/core/src/main/python/create.py b/core/src/main/python/create.py index 4525630ac..e2a1a972b 100644 --- a/core/src/main/python/create.py +++ b/core/src/main/python/create.py @@ -6,11 +6,16 @@ """ import os import sys +import exceptions +from java.lang import Exception as JException from java.io import IOException from java.lang import IllegalArgumentException from java.lang import String from java.lang import System +import java.sql.DriverManager as DriverManager +import java.util.Properties as Properties + from oracle.weblogic.deploy.create import CreateException from oracle.weblogic.deploy.deploy import DeployException from oracle.weblogic.deploy.util import FileUtils @@ -37,6 +42,7 @@ from wlsdeploy.tool.util import wlst_helper from wlsdeploy.tool.validate.content_validator import ContentValidator from wlsdeploy.util import cla_helper +from wlsdeploy.util import dictionary_utils from wlsdeploy.util import getcreds from wlsdeploy.util import tool_main from wlsdeploy.util.cla_utils import CommandLineArgUtil @@ -296,6 +302,34 @@ def _get_domain_path(model_context, model): return domain_parent + os.sep + DEFAULT_WLS_DOMAIN_NAME +def _precheck_rcu_connectivity(domain_typename, fmw_database, rcu_prefix, rcu_schema_pwd, db_conn_props): + _method_name = '_precheck_rcu_connectivity' + try: + props = Properties() + if db_conn_props is not None: + for item in db_conn_props: + for key in item.keys(): + props.put(key, item[key]) + + __logger.info('WLSDPLY_12575', 'test datasource', fmw_database, rcu_prefix + "_STB", props, + class_name=_class_name, method_name=_method_name) + + props.put('user', rcu_prefix + "_STB") + props.put('password', rcu_schema_pwd) + + DriverManager.getConnection(fmw_database, props) + + except (exceptions.Exception, JException), e: + __logger.severe('WLSDPLY-12505', domain_typename, e.getClass().getName(), e.getLocalizedMessage()) + ex = exception_helper.create_create_exception('WLSDPLY-12505', domain_typename, e.getClass().getName(), + e.getLocalizedMessage(), error=e) + __logger.throwing(ex, class_name=_class_name, method_name=_method_name) + raise ex + except ee: + ex = exception_helper.create_create_exception('WLSDPLY-12506', domain_typename, ee) + __logger.throwing(ex, class_name=_class_name, method_name=_method_name) + raise ex + def main(model_context): """ The entry point for the createDomain tool. @@ -337,16 +371,46 @@ def main(model_context): archive_helper.extract_all_database_wallets() creator = DomainCreator(model_dictionary, model_context, aliases) - creator.create() - if has_atp: - rcu_properties_map = model_dictionary[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO] + if dictionary_utils.get_dictionary_element(model_dictionary, model_constants.DOMAIN_INFO) is not None and \ + dictionary_utils.get_dictionary_element(model_dictionary[model_constants.DOMAIN_INFO], + model_constants.RCU_DB_INFO) is not None: + rcu_properties_map = dictionary_utils.get_dictionary_element(model_dictionary[model_constants.DOMAIN_INFO] + ,model_constants.RCU_DB_INFO) rcu_db_info = RcuDbInfo(model_context, aliases, rcu_properties_map) - atp_helper.fix_jps_config(rcu_db_info, model_context) - elif has_ssl: - rcu_properties_map = model_dictionary[model_constants.DOMAIN_INFO][model_constants.RCU_DB_INFO] - rcu_db_info = RcuDbInfo(model_context, aliases, rcu_properties_map) - ssl_helper.fix_jps_config(rcu_db_info, model_context) + else: + # create empty rcu_db_info for cli case + rcu_db_info = RcuDbInfo(model_context, aliases, None) + + # JRF domain pre-check connectivity + if model_context.get_domain_typedef().required_rcu() and not model_context.is_run_rcu() and 'STB' in \ + model_context.get_domain_typedef().get_rcu_schemas(): + # how to create rcu_db_info ? + db_conn_props = None + fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \ + tns_admin, truststore, truststore_pwd, \ + truststore_type = creator.get_rcu_basic_connection_info(rcu_db_info) + + if has_atp: + db_conn_props = creator.get_atp_standard_conn_properties(tns_admin, truststore, truststore_pwd, + truststore_type, keystore_pwd, keystore_type, + keystore) + elif has_ssl: + db_conn_props = creator.get_ssl_standard_conn_properties(tns_admin, truststore, truststore_pwd, + truststore_type, keystore_pwd, keystore_type, + keystore) + + _precheck_rcu_connectivity(model_context.get_domain_typedef().get_domain_type(), + fmw_database, rcu_prefix, rcu_schema_pwd, db_conn_props) + + creator.create() + + if model_context.get_domain_typedef().required_rcu(): + if has_atp: + atp_helper.fix_jps_config(rcu_db_info, model_context) + elif has_ssl: + ssl_helper.fix_jps_config(rcu_db_info, model_context) + except WLSDeployArchiveIOException, ex: _exit_code = ExitCode.ERROR __logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex, diff --git a/core/src/main/python/wlsdeploy/tool/create/domain_creator.py b/core/src/main/python/wlsdeploy/tool/create/domain_creator.py index 1952b4ba8..a38f8e42a 100644 --- a/core/src/main/python/wlsdeploy/tool/create/domain_creator.py +++ b/core/src/main/python/wlsdeploy/tool/create/domain_creator.py @@ -1070,7 +1070,6 @@ def __validate_and_get_atp_rcudbinfo(self, rcu_db_info, check_admin_pwd=False): keystore_type = rcu_db_info.get_keystore_type() truststore = rcu_db_info.get_truststore() keystore = rcu_db_info.get_keystore() - if keystore_pwd is None and keystore_type != 'SSO': ex = exception_helper.create_create_exception('WLSDPLY-12413','javax.net.ssl.keyStorePassword', "['tns.alias','javax.net.ssl.keyStorePassword'," @@ -1092,7 +1091,8 @@ def __validate_and_get_atp_rcudbinfo(self, rcu_db_info, check_admin_pwd=False): "'rcu_admin_password']") raise ex - return tns_admin, rcu_database, truststore_pwd, truststore_type, truststore, keystore_pwd, keystore_type, keystore + return tns_admin, rcu_database, truststore_pwd, truststore_type, truststore, keystore_pwd, keystore_type, \ + keystore def __validate_and_get_ssl_rcudbinfo(self, rcu_db_info, check_admin_pwd=False): """ @@ -1175,45 +1175,8 @@ def __set_rcu_datasource_parameters_without_shadow_table(self, rcu_db_info): """ _method_name = 'set_rcu_datasource_parameters' - rcu_prefix = rcu_db_info.get_preferred_prefix() - rcu_schema_pwd = rcu_db_info.get_preferred_schema_pass() - - if rcu_prefix is None: - ex = exception_helper.create_create_exception('WLSDPLY-12413','rcu_prefix', - "['rcu_prefix','rcu_schema_password']") - self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name) - raise ex - - if rcu_schema_pwd is None: - ex = exception_helper.create_create_exception('WLSDPLY-12413','rcu_schema_password', - "['rcu_prefix','rcu_schema_password']") - self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name) - raise ex - - - # For ATP databases : we need to set all the property for each datasource - # load atp connection properties from properties file - # HANDLE ATP case - is_atp_ds = rcu_db_info.is_use_atp() - is_ssl_ds = rcu_db_info.is_use_ssl() - - if is_atp_ds: - tns_admin, rcu_database, truststore_pwd, truststore_type, \ - truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_atp_rcudbinfo(rcu_db_info) - elif is_ssl_ds: - tns_admin, rcu_database, truststore_pwd, truststore_type, \ - truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_ssl_rcudbinfo(rcu_db_info) - else: - rcu_database = rcu_db_info.get_preferred_db() - - if rcu_database is None: - ex = exception_helper.create_create_exception('WLSDPLY-12564') - raise ex - - # Need to set for the connection property for each datasource - - fmw_database = self.wls_helper.get_jdbc_url_from_rcu_connect_string(rcu_database) - self.logger.fine('WLSDPLY-12221', fmw_database, class_name=self.__class_name, method_name=_method_name) + fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \ + tns_admin, truststore, truststore_pwd, truststore_type = self.get_rcu_basic_connection_info(rcu_db_info) location = LocationContext() location.append_location(JDBC_SYSTEM_RESOURCE) @@ -1566,3 +1529,110 @@ def __configure_opss_secrets(self): self.wlst_helper.set_shared_secret_store_with_password(opss_wallet, opss_secret_password) self.logger.exiting(class_name=self.__class_name, method_name=_method_name) + + def get_rcu_basic_connection_info(self, rcu_db_info): + + _method_name = 'get_rcu_basic_connection_info' + + keystore = None + keystore_pwd = None + keystore_type = None + tns_admin = None + truststore = None + truststore_pwd = None + truststore_type = None + + rcu_prefix = rcu_db_info.get_preferred_prefix() + rcu_schema_pwd = rcu_db_info.get_preferred_schema_pass() + if rcu_prefix is None: + ex = exception_helper.create_create_exception('WLSDPLY-12413', 'rcu_prefix', + "['rcu_prefix','rcu_schema_password']") + self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name) + raise ex + if rcu_schema_pwd is None: + ex = exception_helper.create_create_exception('WLSDPLY-12413', 'rcu_schema_password', + "['rcu_prefix','rcu_schema_password']") + self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name) + raise ex + + # For ATP databases : we need to set all the property for each datasource + # load atp connection properties from properties file + # HANDLE ATP case + + is_atp_ds = rcu_db_info.is_use_atp() + is_ssl_ds = rcu_db_info.is_use_ssl() + if is_atp_ds: + tns_admin, rcu_database, truststore_pwd, truststore_type, \ + truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_atp_rcudbinfo(rcu_db_info) + elif is_ssl_ds: + tns_admin, rcu_database, truststore_pwd, truststore_type, \ + truststore, keystore_pwd, keystore_type, keystore = self.__validate_and_get_ssl_rcudbinfo(rcu_db_info) + else: + rcu_database = rcu_db_info.get_preferred_db() + if rcu_database is None: + ex = exception_helper.create_create_exception('WLSDPLY-12564') + raise ex + + # Need to set for the connection property for each datasource + fmw_database = self.wls_helper.get_jdbc_url_from_rcu_connect_string(rcu_database) + self.logger.fine('WLSDPLY-12221', fmw_database, class_name=self.__class_name, method_name=_method_name) + + return fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \ + tns_admin, truststore, truststore_pwd, truststore_type + + def get_ssl_standard_conn_properties(self, tns_admin, truststore, truststore_pwd, + truststore_type, keystore_pwd, keystore_type, keystore): + properties_set = [] + + # Should always have trust store + properties_set.append({DRIVER_PARAMS_TRUSTSTORE_PROPERTY: self.__get_store_path(tns_admin, truststore)}) + + properties_set.append({DRIVER_PARAMS_TRUSTSTORETYPE_PROPERTY: truststore_type}) + + # if not sso type then user must provide pwd + if truststore_pwd is not None and truststore_pwd != 'None': + properties_set.append({DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY: truststore_pwd}) + + if keystore_pwd is not None and keystore_pwd != 'None': + properties_set.append({DRIVER_PARAMS_KEYSTOREPWD_PROPERTY: keystore_pwd}) + + # if it is 2 ways SSL + if keystore is not None and keystore != 'None': + properties_set.append({DRIVER_PARAMS_KEYSTORE_PROPERTY: self.__get_store_path(tns_admin, keystore)}) + + if keystore_type is not None and keystore_type != 'None': + properties_set.append({DRIVER_PARAMS_KEYSTORETYPE_PROPERTY: keystore_type}) + + return properties_set + + def get_atp_standard_conn_properties(self, tns_admin, truststore, truststore_pwd, + truststore_type, keystore_pwd, keystore_type, keystore): + + keystore, keystore_type, truststore, truststore_type = atp_helper.fix_store_type_and_default_value(keystore, + keystore_type, truststore, truststore_type) + + properties_set = [] + + properties_set.append({DRIVER_PARAMS_KEYSTORE_PROPERTY: self.__get_store_path(tns_admin, + keystore)}) + + properties_set.append({DRIVER_PARAMS_KEYSTORETYPE_PROPERTY: keystore_type}) + + if keystore_pwd: + properties_set.append({DRIVER_PARAMS_KEYSTOREPWD_PROPERTY: keystore_pwd}) + + properties_set.append({DRIVER_PARAMS_TRUSTSTORE_PROPERTY: self.__get_store_path(tns_admin, + truststore)}) + + properties_set.append({DRIVER_PARAMS_TRUSTSTORETYPE_PROPERTY: truststore_type}) + + if truststore_pwd: + properties_set.append({DRIVER_PARAMS_TRUSTSTOREPWD_PROPERTY: truststore_pwd}) + + properties_set.append({DRIVER_PARAMS_NET_SSL_VERSION: DRIVER_PARAMS_NET_SSL_VERSION_VALUE}) + + properties_set.append({DRIVER_PARAMS_NET_SERVER_DN_MATCH_PROPERTY: 'true'}) + properties_set.append({DRIVER_PARAMS_NET_TNS_ADMIN: tns_admin}) + properties_set.append({DRIVER_PARAMS_NET_FAN_ENABLED: 'false'}) + + return properties_set diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index 4765b2ebf..ea326d954 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -1453,7 +1453,7 @@ WLSDPLY-12572=Failed to create domain because either RCUDbinfo is missing rcu_db in command line option WLSDPLY-12573=Invalid databaseType specified in RCUDbInfo: {0}. It must be 'SSL' or 'ATP' WLSDPLY-12574=Path: {0} specified for JDBC driver property: {1} does not exists. Please check your model's RCUDbInfo section. -WLSDPLY_12575=Setting rcu datasource {0} driver params - url: {1} schema: {2} properties: {3} +WLSDPLY_12575=Setting rcu datasource {0} driver params - url: {1}. schema: {2}. properties: {3}. # domain_typedef.py 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 WLSDPLY-12502=The role {0} is not a WebLogic global role and will use the expression as specified WLSDPLY-12503=The role {0} specifies an invalid update mode and will use the default replace mode WLSDPLY-12504=The processing of WebLogic roles from the model is not support with WebLogic Server version {0} +WLSDPLY-12505={0} domain creation precheck failed. {1}: {2} +WLSDPLY-12506={0} domain creation precheck failed. {1} ############################################################################### # YAML/JSON messages (18000 - 18999) # From 5a7bc1d778f96622761a37bc3397c3c2ba0d651b Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Mon, 27 Mar 2023 15:20:17 -0500 Subject: [PATCH 2/3] refactor --- core/src/main/python/create.py | 83 ++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/core/src/main/python/create.py b/core/src/main/python/create.py index e2a1a972b..5903719c6 100644 --- a/core/src/main/python/create.py +++ b/core/src/main/python/create.py @@ -302,33 +302,53 @@ def _get_domain_path(model_context, model): return domain_parent + os.sep + DEFAULT_WLS_DOMAIN_NAME -def _precheck_rcu_connectivity(domain_typename, fmw_database, rcu_prefix, rcu_schema_pwd, db_conn_props): +def _precheck_rcu_connectivity(model_context, creator, rcu_db_info): + _method_name = '_precheck_rcu_connectivity' - try: - props = Properties() - if db_conn_props is not None: - for item in db_conn_props: - for key in item.keys(): - props.put(key, item[key]) + domain_typename = model_context.get_domain_typedef().get_domain_type() + + if model_context.get_domain_typedef().required_rcu() and not model_context.is_run_rcu() and 'STB' in \ + model_context.get_domain_typedef().get_rcu_schemas(): + # how to create rcu_db_info ? + db_conn_props = None + fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \ + tns_admin, truststore, truststore_pwd, \ + truststore_type = creator.get_rcu_basic_connection_info(rcu_db_info) + + if is_atp_ds: + db_conn_props = creator.get_atp_standard_conn_properties(tns_admin, truststore, truststore_pwd, + truststore_type, keystore_pwd, keystore_type, + keystore) + elif is_ssl_ds: + db_conn_props = creator.get_ssl_standard_conn_properties(tns_admin, truststore, truststore_pwd, + truststore_type, keystore_pwd, keystore_type, + keystore) - __logger.info('WLSDPLY_12575', 'test datasource', fmw_database, rcu_prefix + "_STB", props, - class_name=_class_name, method_name=_method_name) + try: + props = Properties() + if db_conn_props is not None: + for item in db_conn_props: + for key in item.keys(): + props.put(key, item[key]) - props.put('user', rcu_prefix + "_STB") - props.put('password', rcu_schema_pwd) + __logger.info('WLSDPLY_12575', 'test datasource', fmw_database, rcu_prefix + "_STB", props, + class_name=_class_name, method_name=_method_name) - DriverManager.getConnection(fmw_database, props) + props.put('user', rcu_prefix + "_STB") + props.put('password', rcu_schema_pwd) - except (exceptions.Exception, JException), e: - __logger.severe('WLSDPLY-12505', domain_typename, e.getClass().getName(), e.getLocalizedMessage()) - ex = exception_helper.create_create_exception('WLSDPLY-12505', domain_typename, e.getClass().getName(), - e.getLocalizedMessage(), error=e) - __logger.throwing(ex, class_name=_class_name, method_name=_method_name) - raise ex - except ee: - ex = exception_helper.create_create_exception('WLSDPLY-12506', domain_typename, ee) - __logger.throwing(ex, class_name=_class_name, method_name=_method_name) - raise ex + DriverManager.getConnection(fmw_database, props) + + except (exceptions.Exception, JException), e: + __logger.severe('WLSDPLY-12505', domain_typename, e.getClass().getName(), e.getLocalizedMessage()) + ex = exception_helper.create_create_exception('WLSDPLY-12505', domain_typename, e.getClass().getName(), + e.getLocalizedMessage(), error=e) + __logger.throwing(ex, class_name=_class_name, method_name=_method_name) + raise ex + except ee: + ex = exception_helper.create_create_exception('WLSDPLY-12506', domain_typename, ee) + __logger.throwing(ex, class_name=_class_name, method_name=_method_name) + raise ex def main(model_context): """ @@ -383,25 +403,8 @@ def main(model_context): rcu_db_info = RcuDbInfo(model_context, aliases, None) # JRF domain pre-check connectivity - if model_context.get_domain_typedef().required_rcu() and not model_context.is_run_rcu() and 'STB' in \ - model_context.get_domain_typedef().get_rcu_schemas(): - # how to create rcu_db_info ? - db_conn_props = None - fmw_database, is_atp_ds, is_ssl_ds, keystore, keystore_pwd, keystore_type, rcu_prefix, rcu_schema_pwd, \ - tns_admin, truststore, truststore_pwd, \ - truststore_type = creator.get_rcu_basic_connection_info(rcu_db_info) - - if has_atp: - db_conn_props = creator.get_atp_standard_conn_properties(tns_admin, truststore, truststore_pwd, - truststore_type, keystore_pwd, keystore_type, - keystore) - elif has_ssl: - db_conn_props = creator.get_ssl_standard_conn_properties(tns_admin, truststore, truststore_pwd, - truststore_type, keystore_pwd, keystore_type, - keystore) - _precheck_rcu_connectivity(model_context.get_domain_typedef().get_domain_type(), - fmw_database, rcu_prefix, rcu_schema_pwd, db_conn_props) + _precheck_rcu_connectivity(model_context, creator, rcu_db_info) creator.create() From e9a1b50c3d2e98adc08ef5cc7248a3a50b5eeab2 Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Wed, 29 Mar 2023 14:58:07 -0500 Subject: [PATCH 3/3] use helper method --- core/src/main/python/create.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/core/src/main/python/create.py b/core/src/main/python/create.py index 5903719c6..4b8bdc41c 100644 --- a/core/src/main/python/create.py +++ b/core/src/main/python/create.py @@ -42,7 +42,6 @@ from wlsdeploy.tool.util import wlst_helper from wlsdeploy.tool.validate.content_validator import ContentValidator from wlsdeploy.util import cla_helper -from wlsdeploy.util import dictionary_utils from wlsdeploy.util import getcreds from wlsdeploy.util import tool_main from wlsdeploy.util.cla_utils import CommandLineArgUtil @@ -51,6 +50,7 @@ from wlsdeploy.util.weblogic_helper import WebLogicHelper from wlsdeploy.tool.create import atp_helper from wlsdeploy.tool.create import ssl_helper +import wlsdeploy.tool.create.rcudbinfo_helper as rcudbinfo_helper wlst_helper.wlst_functions = globals() @@ -392,18 +392,9 @@ def main(model_context): creator = DomainCreator(model_dictionary, model_context, aliases) - if dictionary_utils.get_dictionary_element(model_dictionary, model_constants.DOMAIN_INFO) is not None and \ - dictionary_utils.get_dictionary_element(model_dictionary[model_constants.DOMAIN_INFO], - model_constants.RCU_DB_INFO) is not None: - rcu_properties_map = dictionary_utils.get_dictionary_element(model_dictionary[model_constants.DOMAIN_INFO] - ,model_constants.RCU_DB_INFO) - rcu_db_info = RcuDbInfo(model_context, aliases, rcu_properties_map) - else: - # create empty rcu_db_info for cli case - rcu_db_info = RcuDbInfo(model_context, aliases, None) + rcu_db_info = rcudbinfo_helper.create(model_dictionary, model_context, aliases) # JRF domain pre-check connectivity - _precheck_rcu_connectivity(model_context, creator, rcu_db_info) creator.create()