From 312f3d2e8b93e8cfd9ae9d14a7c2b7e5036b9f10 Mon Sep 17 00:00:00 2001 From: "Luan, Xiaocheng (NIH/NLM/LHC) [C]" Date: Mon, 11 Feb 2019 13:56:01 -0500 Subject: [PATCH 1/2] Allow optional, external configurations to override the entries in hapi.properties. Such configurations can be specified in a properteis file outside of the war (or webapps/hapi-fhir-jpaserver) and the server may be instructed to load the configuration using -Dhapi.properties= This is helpful in at least two use cases: 1. Deploying multiple instances with different configurations (e.g., differnt databases) 2. Future upgrade - just update the war without the need to change hapi.properties after update. --- .../uhn/fhir/jpa/demo/FhirServerConfig.java | 2 + .../ca/uhn/fhir/jpa/demo/HapiProperties.java | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java b/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java index 1f6182b..e0f9a8a 100644 --- a/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java +++ b/src/main/java/ca/uhn/fhir/jpa/demo/FhirServerConfig.java @@ -44,6 +44,7 @@ public class FhirServerConfig extends BaseJavaConfigDstu3 { public DaoConfig daoConfig() { DaoConfig retVal = new DaoConfig(); retVal.setAllowMultipleDelete(HapiProperties.getAllowMultipleDelete()); + retVal.setFetchSizeDefaultMaximum(HapiProperties.getMaximumFetchSize()); retVal.setAllowExternalReferences(HapiProperties.getAllowExternalReferences()); retVal.setExpungeEnabled(HapiProperties.getExpungeEnabled()); @@ -90,6 +91,7 @@ public class FhirServerConfig extends BaseJavaConfigDstu3 { retVal.setUrl(HapiProperties.getDataSourceUrl()); retVal.setUsername(HapiProperties.getDataSourceUsername()); retVal.setPassword(HapiProperties.getDataSourcePassword()); + retVal.setMaxTotal(HapiProperties.getDataSourceMaxPoolSize()); return retVal; } diff --git a/src/main/java/ca/uhn/fhir/jpa/demo/HapiProperties.java b/src/main/java/ca/uhn/fhir/jpa/demo/HapiProperties.java index a04a429..6254bb0 100644 --- a/src/main/java/ca/uhn/fhir/jpa/demo/HapiProperties.java +++ b/src/main/java/ca/uhn/fhir/jpa/demo/HapiProperties.java @@ -8,12 +8,14 @@ import ca.uhn.fhir.rest.server.ETagSupportEnum; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.FileInputStream; import java.util.Properties; public class HapiProperties { public static final String SERVER_ADDRESS = "server_address"; public static final String DEFAULT_PRETTY_PRINT = "default_pretty_print"; public static final String MAX_PAGE_SIZE = "max_page_size"; + public static final String MAX_FETCH_SIZE = "max_fetch_size"; public static final String DEFAULT_PAGE_SIZE = "default_page_size"; public static final String LOGGER_NAME = "logger.name"; public static final String LOGGER_FORMAT = "logger.format"; @@ -23,6 +25,7 @@ public class HapiProperties { public static final String DATASOURCE_USERNAME = "datasource.username"; public static final String DATASOURCE_URL = "datasource.url"; public static final String DATASOURCE_DRIVER = "datasource.driver"; + public static final String DATASOURCE_MAX_POOL_SIZE = "datasource.max_pool_size"; public static final String LOGGER_LOG_EXCEPTIONS = "logger.log_exceptions"; public static final String LOGGER_ERROR_FORMAT = "logger.error_format"; public static final String PERSISTENCE_UNIT_NAME = "persistence_unit_name"; @@ -49,11 +52,37 @@ public class HapiProperties { } catch (Exception e) { throw new ConfigurationException("Could not load HAPI properties", e); } + + Properties overrideProps = loadOverrideProperties(); + if(overrideProps != null) { + properties.putAll(overrideProps); + } } return properties; } + /** + * If a configuration file path is explicitly specified via -Dhapi.properties=, the properties there will + * be used to override the entries in the default hapi.properties file (currently under WEB-INF/classes) + * @return properties loaded from the explicitly specified configuraiton file if there is one, or null otherwise. + */ + private static Properties loadOverrideProperties() { + String confFile = System.getProperty(HAPI_PROPERTIES); + if(confFile != null) { + try { + Properties props = new Properties(); + props.load(new FileInputStream(confFile)); + return props; + } + catch (Exception e) { + throw new ConfigurationException("Could not load HAPI properties file: " + confFile, e); + } + } + + return null; + } + private static String getProperty(String propertyName) { Properties properties = HapiProperties.getProperties(); @@ -144,6 +173,10 @@ public class HapiProperties { return HapiProperties.getIntegerProperty(MAX_PAGE_SIZE, 200); } + public static Integer getMaximumFetchSize() { + return HapiProperties.getIntegerProperty(MAX_FETCH_SIZE, Integer.MAX_VALUE); + } + public static String getPersistenceUnitName() { return HapiProperties.getProperty(PERSISTENCE_UNIT_NAME, "HAPI_PU"); } @@ -168,6 +201,10 @@ public class HapiProperties { return HapiProperties.getProperty(DATASOURCE_DRIVER, "org.apache.derby.jdbc.EmbeddedDriver"); } + public static Integer getDataSourceMaxPoolSize() { + return HapiProperties.getIntegerProperty(DATASOURCE_MAX_POOL_SIZE, 10); + } + public static String getDataSourceUrl() { return HapiProperties.getProperty(DATASOURCE_URL, "jdbc:derby:directory:target/jpaserver_derby_files;create=true"); } From 8f95a50e9f43ebd1937e72da172a611e865af795 Mon Sep 17 00:00:00 2001 From: xluandc Date: Wed, 13 Feb 2019 13:14:36 -0500 Subject: [PATCH 2/2] set fetch size. --- .../ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java b/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java index 25f2556..b3718a7 100644 --- a/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java +++ b/src/main/java/ca/uhn/fhir/jpa/starter/FhirServerConfigCommon.java @@ -48,6 +48,10 @@ public class FhirServerConfigCommon { Boolean allowPlaceholderReferences = HapiProperties.getAllowPlaceholderReferences(); retVal.setAutoCreatePlaceholderReferenceTargets(allowPlaceholderReferences); ourLog.info("Server configured to " + (allowPlaceholderReferences ? "allow" : "deny") + " placeholder references"); + + Integer maxFetchSize = HapiProperties.getMaximumFetchSize(); + retVal.setFetchSizeDefaultMaximum(maxFetchSize); + ourLog.info("Server configured to have a maximum fetch size of " + (maxFetchSize == Integer.MAX_VALUE? "'unlimited'": maxFetchSize)); // You can enable these if you want to support Subscriptions from your server if (HapiProperties.getSubscriptionRestHookEnabled()) { @@ -82,7 +86,7 @@ public class FhirServerConfigCommon { retVal.setUrl(HapiProperties.getDataSourceUrl()); retVal.setUsername(HapiProperties.getDataSourceUsername()); retVal.setPassword(HapiProperties.getDataSourcePassword()); - retVal.setMaxTotal(HapiProperties.getDataSourceMaxPoolSize()); + retVal.setMaxTotal(HapiProperties.getDataSourceMaxPoolSize()); return retVal; }