Skip to content

Commit

Permalink
Remove backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pvannierop authored and dippindots committed Aug 2, 2023
1 parent 27b330d commit 8ab95bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 55 deletions.
37 changes: 11 additions & 26 deletions core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 12 additions & 26 deletions core/src/main/scripts/importer/cbioportal_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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])
Expand Down
10 changes: 7 additions & 3 deletions docker/web-and-data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8ab95bb

Please sign in to comment.