This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to set region specific JDBC urls (#193)
- Loading branch information
Showing
5 changed files
with
52 additions
and
18 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/sh | ||
|
||
java -jar -D@appId=cms -D@environment=local $* -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 build/libs/*.jar | ||
java -jar -D@appId=cms -D@environment=local $* -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 build/libs/*.jar |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/nike/cerberus/server/config/guice/JdbcPropertiesModule.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,34 @@ | ||
package com.nike.cerberus.server.config.guice; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Provides; | ||
import com.nike.cerberus.service.ConfigService; | ||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigException; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import java.util.Optional; | ||
|
||
public class JdbcPropertiesModule extends AbstractModule { | ||
|
||
/** | ||
* Attempts to fetch the region specific JDBC URL first, if not present fall back to the globally defined | ||
* JDBC url (The write cluster for the primary region). | ||
* | ||
* @return The resolved jdbc url | ||
*/ | ||
@Provides | ||
@Singleton | ||
@Named("JDBC.url") | ||
public String jdbcUrl() { | ||
ConfigService configService = ConfigService.getInstance(); | ||
Config config = configService.getAppConfigMergedWithCliGeneratedProperties(); | ||
String regionKey = Optional.ofNullable(configService.getSetRegion()).orElse("region_env_var_not_set"); | ||
try { | ||
return config.getString(String.format("JDBC.%s.url", regionKey)); | ||
} catch (ConfigException e) { | ||
return config.getString("JDBC.url"); | ||
} | ||
} | ||
} |
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