ENT-5760 Log db configuration issues (#6706)

ENT-5760 Return config error instead of throwing an exception so that the config error logging mechanism works.
This commit is contained in:
Christian Sailer 2020-09-14 15:55:38 +01:00 committed by GitHub
parent ea423215c2
commit 879e93ed47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View File

@ -2,7 +2,6 @@ package net.corda.node.persistence
import net.corda.core.utilities.getOrThrow
import net.corda.node.flows.isQuasarAgentSpecified
import net.corda.node.internal.ConfigurationException
import net.corda.nodeapi.internal.persistence.CouldNotCreateDataSourceException
import net.corda.nodeapi.internal.persistence.HibernateSchemaChangeException
import net.corda.testing.core.ALICE_NAME
@ -10,16 +9,16 @@ import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.NodeParameters
import net.corda.testing.driver.driver
import net.corda.testing.node.TestCordapp
import org.junit.Test
import net.corda.testing.node.internal.startNode
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.Test
import kotlin.test.assertFailsWith
class DbSchemaInitialisationTest {
@Test(timeout = 300_000)
fun `database initialisation not allowed in config`() {
driver(DriverParameters(startNodesInProcess = isQuasarAgentSpecified(), cordappsForAllNodes = emptyList())) {
assertFailsWith(ConfigurationException::class) {
assertFailsWith(IllegalStateException::class) {
startNode(NodeParameters(customOverrides = mapOf("database.initialiseSchema" to "false"))).getOrThrow()
}
}

View File

@ -14,7 +14,6 @@ import net.corda.common.validation.internal.Validated.Companion.invalid
import net.corda.common.validation.internal.Validated.Companion.valid
import net.corda.core.context.AuthServiceId
import net.corda.core.internal.notary.NotaryServiceFlow
import net.corda.node.internal.ConfigurationException
import net.corda.node.services.config.AuthDataSourceType
import net.corda.node.services.config.CertChainPolicyConfig
import net.corda.node.services.config.CertChainPolicyType
@ -281,17 +280,26 @@ internal object DatabaseConfigSpec : Configuration.Specification<DatabaseConfig>
private val mappedSchemaCacheSize by long().optional().withDefaultValue(DatabaseConfig.Defaults.mappedSchemaCacheSize)
override fun parseValid(configuration: Config, options: Configuration.Options): Valid<DatabaseConfig> {
if (initialiseSchema.isSpecifiedBy(configuration)){
throw ConfigurationException("Unsupported configuration database/initialiseSchema - this option has been removed, please use the run-migration-scripts sub-command or the database management tool to modify schemas")
if (initialiseSchema.isSpecifiedBy(configuration)) {
return invalid(Configuration.Validation.Error.BadPath.of(
"Unsupported configuration database/initialiseSchema - this option has been removed, please use the run-migration-scripts sub-command or the database management tool to modify schemas",
"initialiseSchema",
"Boolean"))
}
if (initialiseAppSchema.isSpecifiedBy(configuration)){
throw ConfigurationException("Unsupported configuration database/initialiseAppSchema - this option has been removed, please use the run-migration-scripts sub-command or the database management tool to modify schemas")
if (initialiseAppSchema.isSpecifiedBy(configuration)) {
return invalid(Configuration.Validation.Error.BadPath.of(
"Unsupported configuration database/initialiseAppSchema - this option has been removed, please use the run-migration-scripts sub-command or the database management tool to modify schemas",
"initialiseAppSchema",
SchemaInitializationType::class.qualifiedName!!))
}
if (transactionIsolationLevel.isSpecifiedBy(configuration)){
throw ConfigurationException("Unsupported configuration database/transactionIsolationLevel - this option has been removed and cannot be changed")
if (transactionIsolationLevel.isSpecifiedBy(configuration)) {
return invalid(Configuration.Validation.Error.BadPath.of(
"Unsupported configuration database/transactionIsolationLevel - this option has been removed and cannot be changed",
"transactionIsolationLevel",
TransactionIsolationLevel::class.qualifiedName!!))
}
val config = configuration.withOptions(options)
val config = configuration.withOptions(options)
return valid(DatabaseConfig(config[exportHibernateJMXStatistics], config[mappedSchemaCacheSize]))
}
}