forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IQSS#7422 from poikilotherm/7418-datasourcedefinition
7418 datasourcedefinition
- Loading branch information
Showing
8 changed files
with
207 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
## Release Highlights | ||
|
||
### Easier Configuration of Database Connections | ||
|
||
Dataverse now being able to use up-to-date Java technologies, transforms | ||
the way how to configure the connection to your PostgreSQL database. | ||
|
||
In the past, the configuration of the connection has been quite static | ||
and not very easy to update. This has been an issue especially for cloud | ||
and container usage. | ||
|
||
Using MicroProfile Config API (#7000, #7418), you can much more easily specify configuration | ||
details. For an overview of supported options, please see the | ||
[installation guide](https://guides.dataverse.org/en/5.3/installation/config.html#jvm-options). | ||
|
||
Note that some settings have been moved from domain.xml to code such as min and max pool size. | ||
|
||
## Notes for Dataverse Installation Administrators | ||
|
||
### New JVM Options | ||
|
||
- dataverse.db.name | ||
- dataverse.db.user | ||
- dataverse.db.password | ||
- dataverse.db.host | ||
- dataverse.db.port | ||
|
||
<!-- ## Update to Payara Platform 5.2020.6 --> | ||
<!-- ... --> | ||
|
||
<!-- PLACEHOLDER REPLACEMENT TEXT FOR PAYARA UPGRADE NOTE #7417 --> | ||
🚨 THIS VERSION OF DATAVERSE **REQUIRES** UPGRADING TO PAYARA 5.2020.6. 🚨 | ||
|
||
<!-- ... --> | ||
|
||
## Upgrading from earlier releases | ||
|
||
ℹ️ You need to update the Payara Application Server before continuing here. See above. | ||
|
||
1. Undeploy the previous version. | ||
``` | ||
<payara install path>/asadmin list-applications | ||
<payara install path>/asadmin undeploy dataverse-<version> | ||
``` | ||
|
||
(where `<payara install path>` is where Payara 5 is installed, for example: `/usr/local/payara5`) | ||
|
||
2. Update your database connection before updating. | ||
|
||
Please configure your connection details, replacing all the `${DB_...}`. | ||
(If you are using a PostgreSQL server on `localhost:5432`, you can omit `dataverse.db.host` and `dataverse.db.port`.) | ||
|
||
``` | ||
<payara install path>/asadmin create-system-properties "dataverse.db.user=${DB_USER}" | ||
<payara install path>/asadmin create-system-properties "dataverse.db.host=${DB_HOST}" | ||
<payara install path>/asadmin create-system-properties "dataverse.db.port=${DB_PORT}" | ||
<payara install path>/asadmin create-system-properties "dataverse.db.name=${DB_NAME}" | ||
echo "AS_ADMIN_ALIASPASSWORD=${DB_PASS}" > /tmp/password.txt | ||
<payara install path>/asadmin create-password-alias --passwordfile /tmp/password.txt dataverse.db.password | ||
rm /tmp/password.txt | ||
``` | ||
|
||
<!-- PLACE HOLDER FOR EJB TIMER DATABASE RESET NOTE #5345 --> | ||
|
||
Now you are safe to delete the old password alias and DB pool: | ||
``` | ||
<payara install path>/asadmin delete-jdbc-connection-pool --cascade=true dvnDbPool | ||
<payara install path>/asadmin delete-password-alias db_password_alias | ||
``` | ||
|
||
3. Stop payara and remove the generated directory, start. | ||
``` | ||
service payara stop | ||
# remove the generated directory: | ||
rm -rf <payara install path>/payara/domains/domain1/generated | ||
service payara start | ||
``` | ||
|
||
3. Deploy this version. | ||
``` | ||
<payara install path>/bin/asadmin deploy dataverse-5.3.war | ||
``` | ||
|
||
4. Restart Payara | ||
``` | ||
service payara stop | ||
service payara start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/edu/harvard/iq/dataverse/util/DataSourceProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package edu.harvard.iq.dataverse.util; | ||
|
||
import javax.annotation.Resource; | ||
import javax.annotation.sql.DataSourceDefinition; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Singleton; | ||
import javax.sql.DataSource; | ||
|
||
// Find docs here: https://javaee.github.io/javaee-spec/javadocs/javax/annotation/sql/DataSourceDefinition.html | ||
@Singleton | ||
@DataSourceDefinition( | ||
name = "java:app/jdbc/dataverse", | ||
// The app server (Payara) deploys a managed pool for this data source for us. | ||
// We don't need to deal with this on our own. | ||
// | ||
// HINT: PGSimpleDataSource would work too, but as we use a connection pool, go with a javax.sql.ConnectionPoolDataSource | ||
// HINT: PGXADataSource is unnecessary (no distributed transactions used) and breaks ingest. | ||
className = "org.postgresql.ds.PGConnectionPoolDataSource", | ||
user = "${MPCONFIG=dataverse.db.user}", | ||
password = "${MPCONFIG=dataverse.db.password}", | ||
url = "jdbc:postgresql://${MPCONFIG=dataverse.db.host}:${MPCONFIG=dataverse.db.port}/${MPCONFIG=dataverse.db.name}", | ||
// If we ever need to change these pool settings, we need to remove this class and create the resource | ||
// from web.xml. We can use MicroProfile Config in there for these values, impossible to do in the annotation. | ||
// | ||
// See also https://blog.payara.fish/an-intro-to-connection-pools-in-payara-server-5 | ||
// Payara DataSourceDefinitionDeployer default value = 8 | ||
minPoolSize = 10, | ||
// HINT: Payara DataSourceDefinitionDeployer default value = 32 | ||
// HINT: Harvard Dataverse is fine for a while with 64 | ||
maxPoolSize = 100, | ||
// "The number of seconds that a physical connection should remain unused in the pool before the connection is closed for a connection pool. " | ||
// Payara DataSourceDefinitionDeployer default value = 300 (seconds) | ||
maxIdleTime = 300) | ||
// It's possible to add additional properties like this... | ||
// | ||
//properties = { | ||
// "fish.payara.log-jdbc-calls=true" | ||
//}) | ||
// | ||
// ... but at this time we don't think we need any. The full list | ||
// of properties can be found at https://docs.payara.fish/community/docs/5.2020.6/documentation/payara-server/jdbc/advanced-connection-pool-properties.html#full-list-of-properties | ||
// | ||
// All these properties cannot be configured via MPCONFIG as Payara doesn't support this (yet). To be enhanced. | ||
// See also https://github.com/payara/Payara/issues/5024 | ||
public class DataSourceProducer { | ||
|
||
@Resource(lookup = "java:app/jdbc/dataverse") | ||
DataSource ds; | ||
|
||
@Produces | ||
public DataSource getDatasource() { | ||
return ds; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dataverse.db.host=localhost | ||
dataverse.db.port=5432 | ||
dataverse.db.user=dataverse | ||
dataverse.db.name=dataverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters