forked from Luke-Sikina/picsure-search-refinement
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ALS-7051] BDC: Deploy Data Dictionary API (#21)
* Add dynamic environment variables for datasource Included support for setting DATASOURCE_URL and DATASOURCE_USERNAME through --env-file. This change allows the database configuration to be dynamically modified without altering the Dockerfile, improving flexibility and deployment ease. * Add support for additional environment variables Introduced new ARG directives in Dockerfile to handle DATASOURCE_URL, DATASOURCE_USERNAME, and SPRING_PROFILE. This addition ensures these variables can be passed at build time, improving flexibility in configuration. * Increase log verbosity for debugging Enabled DEBUG log level for AWS Secrets Manager SQL and Spring framework to facilitate easier debugging. This will provide more detailed logs for datasource and application behaviors. * Temporary datasource verification class Remove after testing * Update JDBC URL scheme for PostgreSQL connection * Update database URL in application-bdc.properties Changed the database path in the datasource URL from 'auth' to 'dict' to ensure connectivity with the correct database. This adjustment is necessary for the application's dictionary service to function properly. * Add application properties for dictionary weights service Introduce a new configuration file for the dictionary weights service. This file includes PostgreSQL datasource settings and a filename for weights. * Update Dockerfile and config for AWS Secrets Manager integration Added environment variables and updated entrypoint in Dockerfile. Modified pom.xml to include AWS Secrets Manager JDBC dependency. Updated application properties to use AWS Secrets Manager for database credentials. * Add DataSourceVerifier to check DB connection on startup New class `DataSourceVerifier` created to ensure that the database connection is successfully established when the application context is refreshed. It logs messages indicating the success or failure of this verification. * Update src/main/resources/application-bdc.properties * Update database URL and add schema property in config * Remove unused datasource schema property The spring.datasource.schema property was not in use and has been removed to clean up the `application-bdc.properties` file. This helps maintain the configuration file by eliminating unnecessary properties. * Update datasource URLs to include currentSchema parameter This change adds the `currentSchema=dict` parameter to the JDBC URLs in the `application-bdc.properties` files. This adjustment ensures proper schema usage for database connections in both the main and dictionaryweights modules. * Update dictionaryweights/src/main/resources/application-bdc.properties * revert * Update src/main/resources/application-bdc.properties
- Loading branch information
Showing
7 changed files
with
114 additions
and
4 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
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
39 changes: 39 additions & 0 deletions
39
...weights/src/main/java/edu/harvard/dbmi/avillach/dictionaryweights/DataSourceVerifier.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,39 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.datasource; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
@Service | ||
public class DataSourceVerifier { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DataSourceVerifier.class); | ||
|
||
private final DataSource dataSource; | ||
|
||
@Autowired | ||
public DataSourceVerifier(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@EventListener(ContextRefreshedEvent.class) | ||
public void verifyDataSourceConnection() { | ||
try (Connection connection = dataSource.getConnection()) { | ||
if (connection != null) { | ||
LOG.info("Datasource connection verified successfully."); | ||
} else { | ||
LOG.info("Failed to obtain a connection from the datasource."); | ||
} | ||
} catch (SQLException e) { | ||
LOG.info("Error verifying datasource connection: {}", e.getMessage()); | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
dictionaryweights/src/main/resources/application-bdc.properties
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,9 @@ | ||
spring.application.name=dictionaryweights | ||
spring.main.web-application-type=none | ||
|
||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.datasource.driver-class-name=com.amazonaws.secretsmanager.sql.AWSSecretsManagerPostgreSQLDriver | ||
spring.datasource.url=jdbc-secretsmanager:postgresql://${DATASOURCE_URL}/picsure?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&autoReconnectForPools=true¤tSchema=dict | ||
spring.datasource.username=${DATASOURCE_USERNAME} | ||
|
||
weights.filename=/weights.csv |
39 changes: 39 additions & 0 deletions
39
src/main/java/edu/harvard/dbmi/avillach/dictionary/datasource/DataSourceVerifier.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,39 @@ | ||
package edu.harvard.dbmi.avillach.dictionary.datasource; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
@Service | ||
public class DataSourceVerifier { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DataSourceVerifier.class); | ||
|
||
private final DataSource dataSource; | ||
|
||
@Autowired | ||
public DataSourceVerifier(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@EventListener(ContextRefreshedEvent.class) | ||
public void verifyDataSourceConnection() { | ||
try (Connection connection = dataSource.getConnection()) { | ||
if (connection != null) { | ||
LOG.info("Datasource connection verified successfully."); | ||
} else { | ||
LOG.info("Failed to obtain a connection from the datasource."); | ||
} | ||
} catch (SQLException e) { | ||
LOG.info("Error verifying datasource connection: {}", e.getMessage()); | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
spring.application.name=dictionary | ||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect | ||
spring.datasource.driver-class-name=com.amazonaws.secretsmanager.sql.AWSSecretsManagerPostgreSQLDriver | ||
spring.datasource.url=jdbc-secretsmanager:postgres://${DATASOURCE_URL}/auth?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&autoReconnectForPools=true | ||
spring.datasource.url=jdbc-secretsmanager:postgresql://${DATASOURCE_URL}/picsure?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&autoReconnectForPools=true¤tSchema=dict | ||
spring.datasource.username=${DATASOURCE_USERNAME} | ||
server.port=80 | ||
server.port=80 |