diff --git a/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java b/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java index 63ce5eea200..de76214c49d 100644 --- a/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java +++ b/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java @@ -18,38 +18,23 @@ public JdbcDataSource () { String password = dbProperties.getDbPassword(); String mysqlDriverClassName = dbProperties.getDbDriverClassName(); String database = dbProperties.getDbName(); - String useSSL = (!StringUtils.isBlank(dbProperties.getDbUseSSL())) ? dbProperties.getDbUseSSL() : "false"; String enablePooling = (!StringUtils.isBlank(dbProperties.getDbEnablePooling())) ? dbProperties.getDbEnablePooling(): "false"; String connectionURL = dbProperties.getConnectionURL(); - Assert.hasText(userName, errorMessage("username", "db.user")); - Assert.hasText(password, errorMessage("password", "db.password")); - Assert.hasText(mysqlDriverClassName, errorMessage("driver class name", "db.driver")); - Assert.isTrue( - !((defined(host) || defined(database) || defined(dbProperties.getDbUseSSL())) && defined(connectionURL)), - "The portal.properties file defines both db.connection_string and (one of) db.host, " + - "db.portal_db_name and db.use_ssl. Please configure with either db.connection_string (preferred), " + - "or db.host, db.portal_db_name and db.use_ssl." + defined(host) || defined(database) || defined(dbProperties.getDbUseSSL()), + "\n----------------------------------------------------------------------------------------------------------------" + + "-- Connection error:\n" + + "-- You try to connect to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' properties.\n" + + "-- Please remove these properties and use the 'db.connection_string' property instead. See https://docs.cbioportal.org/deployment/customization/portal.properties-reference/\n" + + "-- for assistance on building a valid connection string.\n" + + "----------------------------------------------------------------------------------------------------------------\n" ); - // For backward compatibility, build connection URL from individual properties. - if (connectionURL == null) { - Assert.hasText(host, errorMessage("host", "db.host") + - " Or preferably, set the 'db.connection_string' and remove 'db.host', 'db.portal_db_name' and 'db.use_ssl' (best practice)."); - Assert.hasText(database, errorMessage("database name", "db.portal_db_name") + - " Or preferably, set the 'db.connection_string' and remove 'db.host', 'db.portal_db_name' and 'db.use_ssl (best practice)."); - System.out.println("\n----------------------------------------------------------------------------------------------------------------"); - System.out.println("-- Deprecation warning:"); - System.out.println("-- You are connecting to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' properties."); - System.out.println("-- Please use the 'db.connection_string' instead (see https://docs.cbioportal.org/deployment/customization/portal.properties-reference/)."); - System.out.println("----------------------------------------------------------------------------------------------------------------\n"); - connectionURL = String.format( - "jdbc:mysql://%s/%s?zeroDateTimeBehavior=convertToNull&useSSL=%s", - host, database, useSSL - ); - } - + Assert.hasText(userName, errorMessage("username", "db.user")); + Assert.hasText(password, errorMessage("password", "db.password")); + Assert.hasText(mysqlDriverClassName, errorMessage("driver class name", "db.driver")); + this.setUrl(connectionURL); // Set up poolable data source diff --git a/core/src/main/scripts/importer/cbioportal_common.py b/core/src/main/scripts/importer/cbioportal_common.py index 490981be720..71428f1dcb2 100644 --- a/core/src/main/scripts/importer/cbioportal_common.py +++ b/core/src/main/scripts/importer/cbioportal_common.py @@ -45,7 +45,7 @@ PORTAL_PROPERTY_DATABASE_NAME = 'db.portal_db_name' PORTAL_PROPERTY_DATABASE_URL = 'db.connection_string' PORTAL_PROPERTY_DATABASE_USESSL = 'db.use_ssl' -REQUIRED_DATABASE_PROPERTIES = [PORTAL_PROPERTY_DATABASE_USER, PORTAL_PROPERTY_DATABASE_PW] +REQUIRED_DATABASE_PROPERTIES = [PORTAL_PROPERTY_DATABASE_USER, PORTAL_PROPERTY_DATABASE_PW, PORTAL_PROPERTY_DATABASE_URL] # provides a key for data types to metafile specification dict. class MetaFileTypes(object): @@ -1039,33 +1039,19 @@ def get_database_properties(properties_filename: str) -> Optional[PortalProperti file=ERROR_FILE) return None - if (properties.get(PORTAL_PROPERTY_DATABASE_HOST) is not None or properties.get(PORTAL_PROPERTY_DATABASE_NAME) is not None)\ - and properties.get(PORTAL_PROPERTY_DATABASE_URL) is not None: - print( - "The portal.properties file defines both db.connection_string and (one of) db.host, db.portal_db_name and " - "db.use_ssl. Please configure with either db.connection_string (preferred), or " - "db.host, db.portal_db_name and db.use_ssl.", file=ERROR_FILE) + if properties.get(PORTAL_PROPERTY_DATABASE_HOST) is not None \ + or properties.get(PORTAL_PROPERTY_DATABASE_NAME) is not None \ + or properties.get(PORTAL_PROPERTY_DATABASE_USESSL) is not None: + print(""" + ---------------------------------------------------------------------------------------------------------------- + -- Connection error: + -- You try to connect to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' properties. + -- Please remove these properties and use the 'db.connection_string' property instead. See https://docs.cbioportal.org/deployment/customization/portal.properties-reference/ + -- for assistance on building a valid connection string. + ------------------------------------------------------------f--------------------------------------------------- + """, file=ERROR_FILE) return None - # For backward compatibility, build connection URL from individual properties - if properties.get(PORTAL_PROPERTY_DATABASE_URL) is None: - if properties.get(PORTAL_PROPERTY_DATABASE_HOST) is None or properties.get(PORTAL_PROPERTY_DATABASE_NAME) is None: - print("No connection information provided for database connection. Please set 'db.host' and " - "'db.portal_db_name' in portal.properties. Or better, use the 'db.connection_string' " - "(see https://docs.cbioportal.org/deployment/customization/portal.properties-reference/)", - file=ERROR_FILE) - return None - print("\n" + "-"*112) - print("-- Deprecation warning:") - print("-- You are connection to the database using the deprecated 'db.host', 'db.portal_db_name' and " - "'db.use_ssl' properties.") - print("-- Please use the 'db.connection_string' instead " - "(see https://docs.cbioportal.org/deployment/customization/portal.properties-reference/).") - print("-"*112 + "\n") - properties[PORTAL_PROPERTY_DATABASE_URL] = f"jdbc:mysql://{properties[PORTAL_PROPERTY_DATABASE_HOST]}" \ - f"/{properties[PORTAL_PROPERTY_DATABASE_NAME]}" \ - f"?zeroDateTimeBehavior=convertToNull&useSSL={properties[PORTAL_PROPERTY_DATABASE_USESSL]}" - return PortalProperties(properties[PORTAL_PROPERTY_DATABASE_USER], properties[PORTAL_PROPERTY_DATABASE_PW], properties[PORTAL_PROPERTY_DATABASE_URL]) diff --git a/docker/web-and-data/docker-entrypoint.sh b/docker/web-and-data/docker-entrypoint.sh index 99f8fa68e8b..9e1b9abf098 100755 --- a/docker/web-and-data/docker-entrypoint.sh +++ b/docker/web-and-data/docker-entrypoint.sh @@ -59,10 +59,14 @@ parse_connection_string() { check_db_connection() { eval $(parse_db_params_from_config_and_command_line $@) - if ([[ -n $db_host ]] || [[ -n $db_portal_db_name ]] || [[ -n $db_use_ssl ]]) && [[ -n $db_connection_string ]] + if [[ -n $db_host ]] || [[ -n $db_portal_db_name ]] || [[ -n $db_use_ssl ]] then - echo "The portal.properties file defines both db.connection_string and (one of) db.host, db.portal_db_name and " - echo "db.use_ssl. Please configure with either db.connection_string (preferred), or db.host, db.portal_db_name and db.use_ssl." + echo "----------------------------------------------------------------------------------------------------------------" + echo "-- Connection error:" + echo "-- You try to connect to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' properties." + echo "-- Please remove these properties and use the 'db.connection_string' property instead. See https://docs.cbioportal.org/deployment/customization/portal.properties-reference/" + echo "-- for assistance on building a valid connection string." + echo "------------------------------------------------------------f---------------------------------------------------" exit 1 fi