mirror of
https://github.com/corda/corda.git
synced 2025-02-26 19:25:18 +00:00
Changed system and environmental variables to only be parsed as config if they're prefixed with "corda." e.g., to override "p2pPort" would now take a "corda.p2pPort" from system or environmental variables.
This commit is contained in:
parent
36cd34bff5
commit
c38dccacca
@ -59,7 +59,7 @@ SQL templates files are executed at different stage of an integration test:
|
||||
Depends on the database providers not each SQL file is present (e.g. db-setp always deletes tabels so db-cleanp is not needed).
|
||||
|
||||
The setup ensures that all nodes involved in a single integration test use different database users to achieve database separation.
|
||||
The data source configuration files (denote by ``databaseProvider``) define user and schema by ${nodeOrganizationName} placeholder.
|
||||
The data source configuration files (denote by ``databaseProvider``) define user and schema by ${custom.nodeOrganizationName} placeholder.
|
||||
At a runtime the node resolves the placeholder to its organization name.
|
||||
|
||||
|
||||
|
@ -2,6 +2,8 @@ package net.corda.node.services.config
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import com.typesafe.config.ConfigFactory.systemEnvironment
|
||||
import com.typesafe.config.ConfigFactory.systemProperties
|
||||
import com.typesafe.config.ConfigParseOptions
|
||||
import com.typesafe.config.ConfigRenderOptions
|
||||
import net.corda.core.identity.CordaX500Name
|
||||
@ -10,6 +12,7 @@ import net.corda.core.internal.div
|
||||
import net.corda.core.internal.exists
|
||||
import net.corda.nodeapi.internal.*
|
||||
import net.corda.nodeapi.internal.config.SSLConfiguration
|
||||
import net.corda.nodeapi.internal.config.toProperties
|
||||
import net.corda.nodeapi.internal.crypto.X509KeyStore
|
||||
import net.corda.nodeapi.internal.crypto.loadKeyStore
|
||||
import net.corda.nodeapi.internal.crypto.save
|
||||
@ -20,6 +23,9 @@ fun configOf(vararg pairs: Pair<String, Any?>): Config = ConfigFactory.parseMap(
|
||||
operator fun Config.plus(overrides: Map<String, Any?>): Config = ConfigFactory.parseMap(overrides).withFallback(this)
|
||||
|
||||
object ConfigHelper {
|
||||
|
||||
const val CORDA_PROPERTY_PREFIX = "corda."
|
||||
|
||||
private val log = LoggerFactory.getLogger(javaClass)
|
||||
fun loadConfig(baseDirectory: Path,
|
||||
configFile: Path = baseDirectory / "node.conf",
|
||||
@ -30,10 +36,13 @@ object ConfigHelper {
|
||||
val appConfig = ConfigFactory.parseFile(configFile.toFile(), parseOptions.setAllowMissing(allowMissingConfig))
|
||||
val databaseConfig = ConfigFactory.parseResources(System.getProperty("databaseProvider")+".conf", parseOptions.setAllowMissing(true))
|
||||
|
||||
val systemOverrides = systemProperties().cordaEntriesOnly()
|
||||
val environmentOverrides = systemEnvironment().cordaEntriesOnly()
|
||||
val finalConfig = configOverrides
|
||||
// Add substitution values here
|
||||
.withFallback(configOf("nodeOrganizationName" to parseToDbSchemaFriendlyName(baseDirectory.fileName.toString()))) //for database integration tests
|
||||
.withFallback(ConfigFactory.systemProperties()) //for database integration tests
|
||||
.withFallback(configOf("custom.nodeOrganizationName" to parseToDbSchemaFriendlyName(baseDirectory.fileName.toString()))) //for database integration tests
|
||||
.withFallback(systemOverrides) //for database integration tests
|
||||
.withFallback(environmentOverrides) //for database integration tests
|
||||
.withFallback(configOf("baseDirectory" to baseDirectory.toString()))
|
||||
.withFallback(databaseConfig) //for database integration tests
|
||||
.withFallback(appConfig)
|
||||
@ -42,6 +51,11 @@ object ConfigHelper {
|
||||
log.info("Config:\n${finalConfig.root().render(ConfigRenderOptions.defaults())}")
|
||||
return finalConfig
|
||||
}
|
||||
|
||||
private fun Config.cordaEntriesOnly(): Config {
|
||||
|
||||
return ConfigFactory.parseMap(toProperties().filterKeys { (it as String).startsWith(CORDA_PROPERTY_PREFIX) }.mapKeys { (it.key as String).removePrefix(CORDA_PROPERTY_PREFIX) })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,7 +311,7 @@ fun <T : SerializeAsToken> createMockCordaService(serviceHub: MockServices, serv
|
||||
/**
|
||||
* Reads database and dataSource configuration from a file denoted by 'databaseProvider' system property,
|
||||
* overwitten by system properties and defaults to H2 in memory db.
|
||||
* @param nodeName Reflects the "instance" of the database username/schema, the value will be used to replace ${nodeOrganizationName} placeholder
|
||||
* @param nodeName Reflects the "instance" of the database username/schema, the value will be used to replace ${custom.nodeOrganizationName} placeholder
|
||||
* if the placeholder is present in config.
|
||||
* @param postfix Additional postix added to database "instance" name in case config defaults to H2 in memory database.
|
||||
*/
|
||||
@ -330,8 +330,8 @@ fun databaseProviderDataSourceConfig(nodeName: String? = null, postfix: String?
|
||||
val databaseConfig = ConfigFactory.parseResources(System.getProperty("databaseProvider") + ".conf", parseOptions.setAllowMissing(true))
|
||||
val fixedOverride = ConfigFactory.parseString("baseDirectory = \"\"")
|
||||
|
||||
//implied property nodeOrganizationName to fill the potential placeholders in db schema/ db user properties
|
||||
val nodeOrganizationNameConfig = if (nodeName != null) configOf("nodeOrganizationName" to parseToDbSchemaFriendlyName(nodeName)) else ConfigFactory.empty()
|
||||
//implied property custom.nodeOrganizationName to fill the potential placeholders in db schema/ db user properties
|
||||
val nodeOrganizationNameConfig = if (nodeName != null) configOf("custom.nodeOrganizationName" to parseToDbSchemaFriendlyName(nodeName)) else ConfigFactory.empty()
|
||||
|
||||
//defaults to H2
|
||||
//for H2 the same db instance runs for all integration tests, so adding additional variable postfix create a unique database each time
|
||||
|
@ -15,9 +15,9 @@ import org.junit.rules.ExternalResource
|
||||
abstract class IntegrationTest {
|
||||
// System properties set in main 'corda-project' build.gradle
|
||||
// Note: the database provider configuration file for integration tests should specify:
|
||||
// dataSource.user = ${nodeOrganizationName}
|
||||
// dataSource.user = ${custom.nodeOrganizationName}
|
||||
// dataSource.password = [PASSWORD]
|
||||
// where [PASSWORD] must be the same for all ${nodeOrganizationName}
|
||||
// where [PASSWORD] must be the same for all ${custom.nodeOrganizationName}
|
||||
companion object {
|
||||
private val DATABASE_PROVIDER = "databaseProvider"
|
||||
private val dbProvider = System.getProperty(DATABASE_PROVIDER, "")
|
||||
|
@ -1,11 +1,11 @@
|
||||
dataSourceProperties = {
|
||||
dataSourceClassName = "com.microsoft.sqlserver.jdbc.SQLServerDataSource"
|
||||
dataSource.url = "jdbc:sqlserver://[HOST]:1433;databaseName=[DATABASE];encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30"
|
||||
dataSource.user = ${nodeOrganizationName}
|
||||
dataSource.user = ${custom.nodeOrganizationName}
|
||||
dataSource.password = "yourStrong(!)Password"
|
||||
}
|
||||
database = {
|
||||
transactionIsolationLevel = READ_COMMITTED
|
||||
initDatabase = true
|
||||
schema = ${nodeOrganizationName}
|
||||
schema = ${custom.nodeOrganizationName}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
dataSourceProperties = {
|
||||
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
|
||||
dataSource.url = "jdbc:oracle:thin:@[IP]:[PORT]:xe"
|
||||
dataSource.user = ${nodeOrganizationName}
|
||||
dataSource.user = ${custom.nodeOrganizationName}
|
||||
dataSource.password = 1234
|
||||
}
|
||||
database = {
|
||||
transactionIsolationLevel = READ_COMMITTED
|
||||
schema = ${nodeOrganizationName}
|
||||
schema = ${custom.nodeOrganizationName}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
dataSourceProperties = {
|
||||
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
|
||||
dataSource.url = "jdbc:oracle:thin:@[IP]:[PORT]:xe"
|
||||
dataSource.user = ${nodeOrganizationName}
|
||||
dataSource.user = ${custom.nodeOrganizationName}
|
||||
dataSource.password = 1234
|
||||
}
|
||||
database = {
|
||||
transactionIsolationLevel = READ_COMMITTED
|
||||
schema = ${nodeOrganizationName}
|
||||
schema = ${custom.nodeOrganizationName}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
dataSourceProperties = {
|
||||
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
|
||||
dataSource.url = "jdbc:postgresql://[HOST]:[PORT]/postgres"
|
||||
dataSource.user = ${nodeOrganizationName}
|
||||
dataSource.user = ${custom.nodeOrganizationName}
|
||||
dataSource.password = "1234"
|
||||
}
|
||||
database = {
|
||||
transactionIsolationLevel = READ_COMMITTED
|
||||
schema = ${nodeOrganizationName}
|
||||
schema = ${custom.nodeOrganizationName}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
dataSourceProperties = {
|
||||
dataSourceClassName = "com.microsoft.sqlserver.jdbc.SQLServerDataSource"
|
||||
dataSource.url = "jdbc:sqlserver://[HOST]:[PORT]"
|
||||
dataSource.user = ${nodeOrganizationName}
|
||||
dataSource.user = ${custom.nodeOrganizationName}
|
||||
dataSource.password = "yourStrong(!)Password"
|
||||
}
|
||||
database = {
|
||||
transactionIsolationLevel = READ_COMMITTED
|
||||
initDatabase = true
|
||||
schema = ${nodeOrganizationName}
|
||||
schema = ${custom.nodeOrganizationName}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user