From 2f244ad1ada9652f4915175fee05d441b2937564 Mon Sep 17 00:00:00 2001 From: Rick Herrick <jrherrick@wustl.edu> Date: Sat, 14 May 2016 17:43:34 -0500 Subject: [PATCH] Added default settings for database connection pooling. Fixed issue with illegal characters in site-admin-elements.yaml. --- .../xnat/initialization/DatabaseConfig.java | 35 ++++++++++++++++--- .../xnat/spawner/site-admin-elements.yaml | 14 ++++---- .../webapp/WEB-INF/conf/xnat-conf.properties | 3 -- .../webapp/WEB-INF/conf/xnat-security.xml | 3 +- .../page/admin/data/config/site-setup.yaml | 4 +-- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/nrg/xnat/initialization/DatabaseConfig.java b/src/main/java/org/nrg/xnat/initialization/DatabaseConfig.java index fc9a179b..83b59d90 100644 --- a/src/main/java/org/nrg/xnat/initialization/DatabaseConfig.java +++ b/src/main/java/org/nrg/xnat/initialization/DatabaseConfig.java @@ -1,6 +1,7 @@ package org.nrg.xnat.initialization; import org.apache.commons.dbcp2.BasicDataSource; +import org.apache.commons.lang3.StringUtils; import org.nrg.framework.exceptions.NrgServiceError; import org.nrg.framework.exceptions.NrgServiceException; import org.nrg.framework.utilities.Beans; @@ -23,11 +24,14 @@ import java.util.Properties; @Configuration public class DatabaseConfig { - public static final String DEFAULT_DATASOURCE_URL = "jdbc:postgresql://localhost/xnat"; - public static final String DEFAULT_DATASOURCE_USERNAME = "xnat"; - public static final String DEFAULT_DATASOURCE_PASSWORD = "xnat"; - public static final String DEFAULT_DATASOURCE_CLASS = BasicDataSource.class.getName(); - public static final String DEFAULT_DATASOURCE_DRIVER = Driver.class.getName(); + public static final String DEFAULT_DATASOURCE_URL = "jdbc:postgresql://localhost/xnat"; + public static final String DEFAULT_DATASOURCE_USERNAME = "xnat"; + public static final String DEFAULT_DATASOURCE_PASSWORD = "xnat"; + public static final String DEFAULT_DATASOURCE_CLASS = BasicDataSource.class.getName(); + public static final String DEFAULT_DATASOURCE_DRIVER = Driver.class.getName(); + public static final String DEFAULT_DATASOURCE_INITIAL_SIZE = "20"; + public static final String DEFAULT_DATASOURCE_MAX_TOTAL = "40"; + public static final String DEFAULT_DATASOURCE_MAX_IDLE = "10"; @Bean public DataSource dataSource() throws NrgServiceException { @@ -65,6 +69,27 @@ public class DatabaseConfig { } properties.setProperty("class", DEFAULT_DATASOURCE_CLASS); } + // If the BasicDataSource class is specified, then set some default database connection pooling parameters. + if (StringUtils.equals(properties.getProperty("class"), DEFAULT_DATASOURCE_CLASS)) { + if (!properties.containsKey("initialSize")) { + if (_log.isWarnEnabled()) { + _log.warn("No value set for the XNAT datasource initial connection pool size, using the default value of " + DEFAULT_DATASOURCE_INITIAL_SIZE); + } + properties.setProperty("initialSize", DEFAULT_DATASOURCE_INITIAL_SIZE); + } + if (!properties.containsKey("maxTotal")) { + if (_log.isWarnEnabled()) { + _log.warn("No value set for the XNAT datasource maximum connection pool size, using the default value of " + DEFAULT_DATASOURCE_MAX_TOTAL); + } + properties.setProperty("maxTotal", DEFAULT_DATASOURCE_MAX_TOTAL); + } + if (!properties.containsKey("maxIdle")) { + if (_log.isWarnEnabled()) { + _log.warn("No value set for the XNAT datasource connection pool idle size, using the default value of " + DEFAULT_DATASOURCE_MAX_IDLE); + } + properties.setProperty("maxIdle", DEFAULT_DATASOURCE_MAX_IDLE); + } + } if (!properties.containsKey("driver")) { if (_log.isWarnEnabled()) { _log.warn("No value set for the XNAT datasource driver, using the default value of " + DEFAULT_DATASOURCE_DRIVER); diff --git a/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml b/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml index 0a28fd6a..c1ce7c54 100644 --- a/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml +++ b/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml @@ -102,14 +102,14 @@ fileSystemSettingsWarning: style: fontWeight: bold -archiveRootPath: +archivePath: kind: panel.input.text - id: archiveRootPath - name: archiveRootPath - label: Archive Root Path + id: archivePath + name: archivePath + label: Archive Path validation: required path description: "" - value: ?? XNAT.data.siteConfig.archiveRootPath + value: ?? XNAT.data.siteConfig.archivePath cachePath: kind: panel.input.text @@ -999,7 +999,7 @@ fileSystem: lookup: XNAT.data.siteConfig contentType: json contents: - ${archiveRootPath} + ${archivePath} ${cachePath} ${prearchivePath} ${ftpPath} @@ -1185,7 +1185,7 @@ sitePaths: name: sitePaths label: Site Paths contents: -# ${archiveRootPath} +# ${archivePath} # ${cachePath} # ${prearchivePath} # ${ftpPath} diff --git a/src/main/webapp/WEB-INF/conf/xnat-conf.properties b/src/main/webapp/WEB-INF/conf/xnat-conf.properties index ea775bca..965c8506 100644 --- a/src/main/webapp/WEB-INF/conf/xnat-conf.properties +++ b/src/main/webapp/WEB-INF/conf/xnat-conf.properties @@ -10,9 +10,6 @@ datasource.driver=org.postgresql.Driver datasource.url=jdbc:postgresql://localhost/xnat datasource.username=xnat datasource.password=xnat -datasource.initialSize=20 -datasource.maxTotal=40 -datasource.maxIdle=10 hibernate.dialect=org.hibernate.dialect.PostgreSQL9Dialect hibernate.hbm2ddl.auto=update diff --git a/src/main/webapp/WEB-INF/conf/xnat-security.xml b/src/main/webapp/WEB-INF/conf/xnat-security.xml index bbd738c2..933f700c 100644 --- a/src/main/webapp/WEB-INF/conf/xnat-security.xml +++ b/src/main/webapp/WEB-INF/conf/xnat-security.xml @@ -12,7 +12,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> - <context:property-placeholder location="WEB-INF/conf/services.properties,WEB-INF/conf/services-custom.properties" + <context:property-placeholder location="WEB-INF/conf/services.properties" ignore-resource-not-found="true" ignore-unresolvable="true"/> <context:annotation-config/> @@ -177,7 +177,6 @@ <constructor-arg name="fileNames"> <util:list> <value>WEB-INF/conf/services.properties</value> - <value>WEB-INF/conf/services-custom.properties</value> </util:list> </constructor-arg> </bean> diff --git a/src/main/webapp/page/admin/data/config/site-setup.yaml b/src/main/webapp/page/admin/data/config/site-setup.yaml index 16bb194c..6e4a509f 100644 --- a/src/main/webapp/page/admin/data/config/site-setup.yaml +++ b/src/main/webapp/page/admin/data/config/site-setup.yaml @@ -83,9 +83,9 @@ initialSetup: refresh: /xapi/siteConfig contents: - archiveRootPath: + archivePath: kind: panel.input.text - name: archiveRootPath + name: archivePath label: Archive Location size: 50 value: '' -- GitLab