Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to spring db naming scheme #3

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,25 @@ public class JdbcDataSource extends BasicDataSource {
public JdbcDataSource () {
DatabaseProperties dbProperties = DatabaseProperties.getInstance();

String host = dbProperties.getDbHost();
String userName = dbProperties.getDbUser();
String password = dbProperties.getDbPassword();
String mysqlDriverClassName = dbProperties.getDbDriverClassName();
String database = dbProperties.getDbName();
String userName = dbProperties.getSpringDbUser();
String password = dbProperties.getSpringDbPassword();
String mysqlDriverClassName = dbProperties.getSpringDbDriverClassName();
String enablePooling = (!StringUtils.isBlank(dbProperties.getDbEnablePooling())) ? dbProperties.getDbEnablePooling(): "false";
String connectionURL = dbProperties.getConnectionURL();
String connectionURL = dbProperties.getSpringConnectionURL();

Assert.isTrue(
!defined(host) && !defined(database) && !defined(dbProperties.getDbUseSSL()),
!defined(dbProperties.getDbHost()) && !defined(dbProperties.getDbUser()) && !defined(dbProperties.getDbPassword()) && !defined(dbProperties.getDbName()) && !defined(dbProperties.getConnectionURL()) && !defined(dbProperties.getDbDriverClassName()) && !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" +
"-- You try to connect to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' or 'db.connection_string' and. 'db.driver' properties.\n" +
"-- Please remove these properties and use the 'spring.datasource.url' property instead. See https://docs.cbioportal.org/deployment/customization/application.properties-reference/\n" +
"-- for assistance on building a valid connection string.\n" +
"----------------------------------------------------------------------------------------------------------------\n"
);

Assert.hasText(userName, errorMessage("username", "db.user"));
Assert.hasText(password, errorMessage("password", "db.password"));
Assert.hasText(mysqlDriverClassName, errorMessage("driver class name", "db.driver"));
Assert.hasText(userName, errorMessage("username", "spring.datasource.username"));
Assert.hasText(password, errorMessage("password", "spring.datasource.password"));
Assert.hasText(mysqlDriverClassName, errorMessage("driver class name", "spring.datasource.driver-class-name"));

this.setUrl(connectionURL);

Expand All @@ -51,11 +49,10 @@ public JdbcDataSource () {
this.setMinEvictableIdleTimeMillis(30000);
this.setTestOnBorrow(true);
this.setValidationQuery("SELECT 1");
this.setJmxName("org.cbioportal:DataSource=" + database);
}

private String errorMessage(String displayName, String propertyName) {
return String.format("No %s provided for database connection. Please set '%s' in portal.properties.", displayName, propertyName);
return String.format("No %s provided for database connection. Please set '%s' in application.properties.", displayName, propertyName);
}

private boolean defined(String property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected void doPost(HttpServletRequest httpServletRequest,
// String extraMessage = "";
// //extra message for the cases where property is missing (will happen often in transition period to this new versioning model):
// if (dbPortalExpectedSchemaVersion.equals("0")) {
// extraMessage = "The db.version property also not found in your portal.properties file. This new property needs to be added by the administrator.";
// extraMessage = "The db.version property also not found in your application.properties file. This new property needs to be added by the administrator.";
// }
// String finalMessage = "Current DB schema version: " + dbActualSchemaVersion + "<br/>" +
// "DB schema version expected by Portal: " + dbPortalExpectedSchemaVersion + "<br/>" + extraMessage;
Expand Down
45 changes: 43 additions & 2 deletions src/main/java/org/mskcc/cbio/portal/util/DatabaseProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.mskcc.cbio.portal.util.GlobalProperties;

/**
* Stores db props (name, id, pw, host) from portal.properties
* Stores db props (name, id, pw, host) from application.properties
* and makes them accessible.
*/
public class DatabaseProperties {
Expand All @@ -48,14 +48,18 @@ public class DatabaseProperties {
private String dbUseSSL;
private String dbEnablePooling;
private String connectionURL;
private String springDbUser;
private String springDbPassword;
private String springConnectionURL;
private String springDbDriverClassName;

// No production keys stored in filesystem or code: digest the key; put it in properties; load it into dbms on startup
private static DatabaseProperties dbProperties;

public static DatabaseProperties getInstance() {
if (dbProperties == null) {
dbProperties = new DatabaseProperties();
// Get DB Properties from portal.properties.
// Get DB Properties from application.properties.
dbProperties.setDbHost(GlobalProperties.getProperty("db.host"));
dbProperties.setDbName(GlobalProperties.getProperty("db.portal_db_name"));
dbProperties.setDbUser(GlobalProperties.getProperty("db.user"));
Expand All @@ -65,6 +69,11 @@ public static DatabaseProperties getInstance() {
dbProperties.setDbUseSSL(GlobalProperties.getProperty("db.use_ssl"));
dbProperties.setDbEnablePooling(GlobalProperties.getProperty("db.enable_pooling"));
dbProperties.setConnectionURL(GlobalProperties.getProperty("db.connection_string"));
dbProperties.setSpringDbUser(GlobalProperties.getProperty("spring.datasource.username"));
dbProperties.setSpringDbPassword(GlobalProperties.getProperty("spring.datasource.password"));
dbProperties.setSpringConnectionURL(GlobalProperties.getProperty("spring.datasource.url"));
dbProperties.setSpringDbDriverClassName(GlobalProperties.getProperty("spring.datasource.driver-class-name"));

}
return dbProperties;
}
Expand Down Expand Up @@ -143,5 +152,37 @@ public String getConnectionURL() {
public void setConnectionURL(String connectionURL) {
this.connectionURL = connectionURL;
}

public String getSpringConnectionURL() {
return springConnectionURL;
}

public void setSpringConnectionURL(String springConnectionURL) {
this.springConnectionURL = springConnectionURL;
}

public String getSpringDbUser() {
return springDbUser;
}

public void setSpringDbUser(String springDbUser) {
this.springDbUser = springDbUser;
}

public String getSpringDbPassword() {
return springDbPassword;
}

public void setSpringDbPassword(String springDbPassword) {
this.springDbPassword = springDbPassword;
}

public String getSpringDbDriverClassName() {
return springDbDriverClassName;
}

public void setSpringDbDriverClassName(String springDbDriverClassName) {
this.springDbDriverClassName = springDbDriverClassName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,15 @@ public static String parseUrl(String url)
* Minimal portal property resolver that takes system property overrides.
*
* Provides properties from runtime or the baked-in
* portal.properties config file, but takes overrides from <code>-D</code>
* application.properties config file, but takes overrides from <code>-D</code>
* system properties.
*/
private static class ConfigPropertyResolver {
private Properties configFileProperties;
/**
* Finds the config file for properties not overridden by system props.
*
* Either the runtime or buildtime portal.properties file.
* Either the runtime or buildtime application.properties file.
*/
public ConfigPropertyResolver() {
configFileProperties = initializeProperties(PORTAL_PROPERTIES_FILE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:/portal.properties</value>
<value>file:///#{systemEnvironment['PORTAL_HOME']}/portal.properties</value>
<value>classpath:/application.properties</value>
<value>file:///#{systemEnvironment['PORTAL_HOME']}/application.properties</value>
</list>
</property>
</bean>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/scripts/compareDirectAndBulkDBMSload.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# on laptop: ./compareDirectAndBulkDBMSload.pl --outputDir "/Users/goldbera/Documents/Projects/TCGA Portal/Fast DBMS load/data/" --MySQLdbParams h=localhost,u=root,p=anOKpwd --database cgds
# on toro: nohup ./compareDirectAndBulkDBMSload.pl --outputDir "/home/goldberg/data" --MySQLdbParams h=localhost,u=cbio,p=cbio --database cgds_arthur &> stdout.txt&
# on toro: uses ./build/WEB-INF/classes/org/mskcc/cbio/portal/util/portal.properties
# on toro: uses ./build/WEB-INF/classes/org/mskcc/cbio/portal/util/application.properties


# CONSTANTS
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/scripts/hot-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ HOST=$1
USER=$2
REV=$3

# Note, this script was intended to be run via cron. Please ensure that the path to portal.properties.*
$PORTAL_HOME/portal/scripts/hotDeploy.py --credentials $PORTAL_HOME/src/main/resources/properties.txt --portal-properties $PORTAL_HOME/src/main/resources/portal.properties.GDAC --rev $REV --host $HOST --user $USER
# Note, this script was intended to be run via cron. Please ensure that the path to application.properties.*
$PORTAL_HOME/portal/scripts/hotDeploy.py --credentials $PORTAL_HOME/src/main/resources/properties.txt --portal-properties $PORTAL_HOME/src/main/resources/application.properties.GDAC --rev $REV --host $HOST --user $USER
14 changes: 7 additions & 7 deletions src/main/resources/scripts/hotDeploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ------------------------------------------------------------------------------
# Script which hot deploys cbio portal fixes. Script assumes
# properties file argument lives within $PORTAL_HOME/portal. This
# script will clobber any existing portal.properties file within $PORTAL_HOME/portal.
# script will clobber any existing application.properties file within $PORTAL_HOME/portal.

# ------------------------------------------------------------------------------
# imports
Expand All @@ -29,9 +29,9 @@

WAR_FILE_DEST = "/srv/www/sander-tomcat/tomcat6/webapps/"

# fields in credentials - should match portal portal.properties
CGDS_DATABASE_USER = 'db.user'
CGDS_DATABASE_PW = 'db.password'
# fields in credentials - should match portal application.properties
CGDS_DATABASE_USER = 'spring.datasource.username'
CGDS_DATABASE_PW = 'spring.datasource.password'
BITLY_USER = 'bitly.user'
BITLY_KEY = 'bitly.api_key'
CGDS_USERS_SPREADSHEET = 'users.spreadsheet'
Expand Down Expand Up @@ -104,12 +104,12 @@ def deploy_war(host, user):

def build_war(portal_credentials, portal_properties):

# setup portal.properties
portal_properties = PORTAL_PROJECT + os.sep + "portal.properties"
# setup application.properties
portal_properties = PORTAL_PROJECT + os.sep + "application.properties"
if os.path.exists(portal_properties):
print >> OUTPUT_FILE, "Clobbering %s" % portal_properties

# we are going to create a new portal.properties file using
# we are going to create a new application.properties file using
# portal_properties as the template and get credentials from portal_credentials
portal_properties_file = open(portal_properties, 'w')
portal_properties_file = open(portal_properties, 'r')
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/scripts/import-portal-users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ PYTHONHOME=
PYTHONPATH=
PORTAL_HOME=

# Note, this script was intended to be run via cron. Please ensure that the path to portal.properties.*
# Note, this script was intended to be run via cron. Please ensure that the path to application.properties.*
# points to an unchanging location and version of the file. The path below is only meant for illustrative purposes.
$PORTAL_HOME/portal/scripts/importUsers.py --properties-file $PORTAL_HOME/portal/portal.properties.GDAC --send-email-confirm true 2>&1 > /dev/null
$PORTAL_HOME/portal/scripts/importUsers.py --properties-file $PORTAL_HOME/portal/portal.properties.PRIVATE --send-email-confirm true 2>&1 > /dev/null
$PORTAL_HOME/portal/scripts/importUsers.py --properties-file $PORTAL_HOME/portal/portal.properties.SU2C --send-email-confirm true 2>&1 > /dev/null
$PORTAL_HOME/portal/scripts/importUsers.py --properties-file $PORTAL_HOME/portal/application.properties.GDAC --send-email-confirm true 2>&1 > /dev/null
$PORTAL_HOME/portal/scripts/importUsers.py --properties-file $PORTAL_HOME/portal/application.properties.PRIVATE --send-email-confirm true 2>&1 > /dev/null
$PORTAL_HOME/portal/scripts/importUsers.py --properties-file $PORTAL_HOME/portal/application.properties.SU2C --send-email-confirm true 2>&1 > /dev/null
10 changes: 5 additions & 5 deletions src/main/resources/scripts/importUsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# ------------------------------------------------------------------------------
# Script which adds new users fram google spreadsheet into the the cgds
# user table. The following properties must be specified in portal.properties:
# user table. The following properties must be specified in application.properties:
#
# db.name
# db.user
Expand Down Expand Up @@ -51,10 +51,10 @@
ERROR_FILE = sys.stderr
OUTPUT_FILE = sys.stdout

# fields in portal.properties
CGDS_DATABASE_HOST = 'db.host'
# fields in application.properties
CGDS_DATABASE_HOST = 'spring.datasource.password'
CGDS_DATABASE_NAME = 'db.portal_db_name'
CGDS_DATABASE_USER = 'db.user'
CGDS_DATABASE_USER = 'spring.datasource.user'
CGDS_DATABASE_PW = 'db.password'
GOOGLE_ID = 'google.id'
GOOGLE_PW = 'google.pw'
Expand Down Expand Up @@ -345,7 +345,7 @@ def get_db_connection(portal_properties):


# ------------------------------------------------------------------------------
# parse portal.properties
# parse application.properties

def get_portal_properties(portal_properties_filename):

Expand Down
20 changes: 12 additions & 8 deletions src/main/resources/scripts/importer/cbioportal_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
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, PORTAL_PROPERTY_DATABASE_URL]
PORTAL_PROPERTY_SPRING_DATABASE_USER = 'spring.datasource.username'
PORTAL_PROPERTY_SPRING_DATABASE_PW = 'spring.datasource.password'
PORTAL_PROPERTY_SPRING_DATABASE_URL = 'spring.datasource.url'
REQUIRED_DATABASE_PROPERTIES = [PORTAL_PROPERTY_SPRING_DATABASE_USER, PORTAL_PROPERTY_SPRING_DATABASE_PW, PORTAL_PROPERTY_SPRING_DATABASE_URL]

# provides a key for data types to metafile specification dict.
class MetaFileTypes(object):
Expand Down Expand Up @@ -1013,7 +1016,7 @@ def run_java(*args):


def properties_error_message(display_name: str, property_name: str) -> str:
return f"No {display_name} provided for database connection. Please set '{property_name}' in portal.properties."
return f"No {display_name} provided for database connection. Please set '{property_name}' in application.properties."


class PortalProperties(object):
Expand Down Expand Up @@ -1041,20 +1044,21 @@ def get_database_properties(properties_filename: str) -> Optional[PortalProperti

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:
or properties.get(PORTAL_PROPERTY_DATABASE_USESSL) is not None \
or properties.get(PORTAL_PROPERTY_DATABASE_URL) 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/
-- You try to connect to the database using the deprecated 'db.host', 'db.portal_db_name' and 'db.use_ssl' or 'db.connection_string' properties.
-- Please remove these properties and use the 'db.spring.datasource.url' property instead. See https://docs.cbioportal.org/deployment/customization/application.properties-reference/
-- for assistance on building a valid connection string.
------------------------------------------------------------f---------------------------------------------------
""", file=ERROR_FILE)
return None

return PortalProperties(properties[PORTAL_PROPERTY_DATABASE_USER],
properties[PORTAL_PROPERTY_DATABASE_PW],
properties[PORTAL_PROPERTY_DATABASE_URL])
return PortalProperties(properties[PORTAL_PROPERTY_SPRING_DATABASE_USER],
properties[PORTAL_PROPERTY_SPRING_DATABASE_PW],
properties[PORTAL_PROPERTY_SPRING_DATABASE_URL])


def parse_properties_file(properties_filename: str) -> Dict[str, str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def interface():
required=True,
help='Study Identifier')
parser.add_argument('-p', '--portal_properties', type=str, required=True,
help='portal.properties of cBioPortal')
help='application.properties of cBioPortal')
parser = parser.parse_args()
return parser

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/scripts/importer/validateData.py
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ def checkOffPanelVariant(self, data, normalized_gene, panel_id, hugo_symbol, ent

def checkNCBIbuild(self, value):
"""
Checks whether the value found in MAF NCBI_Build column matches the genome specified in portal.properties at
Checks whether the value found in MAF NCBI_Build column matches the genome specified in application.properties at
field ncbi.build. Expecting GRCh37, GRCh38, GRCm38 or without the GRCx prefix
"""

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/scripts/importer/validateStudies.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def interface(args=None):
help='Skip tests requiring information '
'from the cBioPortal installation')
parser.add_argument('-P', '--portal_properties', type=str,
help='portal.properties file path (default: assumed hg19)',
help='application.properties file path (default: assumed hg19)',
required=False)

parser.add_argument('-m', '--strict_maf_checks', required=False,
Expand Down
Loading
Loading