Merge pull request #2470 from corda/fixes/sollecitom/failfast_rpc_settings

Added basic node configuration validation.
This commit is contained in:
Katelyn Baker 2018-02-06 16:32:26 +00:00 committed by GitHub
commit 9b8fe3a1d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 2 deletions

View File

@ -89,6 +89,11 @@ open class NodeStartup(val args: Array<String>) {
logger.error("Exception during node configuration", e) logger.error("Exception during node configuration", e)
return false return false
} }
val errors = conf.validate()
if (errors.isNotEmpty()) {
logger.error("Invalid node configuration. Errors where:${System.lineSeparator()}${errors.joinToString(System.lineSeparator())}")
return false
}
try { try {
banJavaSerialisation(conf) banJavaSerialisation(conf)

View File

@ -49,6 +49,8 @@ interface NodeConfiguration : NodeSSLConfiguration {
val attachmentContentCacheSizeBytes: Long get() = defaultAttachmentContentCacheSize val attachmentContentCacheSizeBytes: Long get() = defaultAttachmentContentCacheSize
val attachmentCacheBound: Long get() = defaultAttachmentCacheBound val attachmentCacheBound: Long get() = defaultAttachmentCacheBound
fun validate(): List<String>
companion object { companion object {
// default to at least 8MB and a bit extra for larger heap sizes // default to at least 8MB and a bit extra for larger heap sizes
val defaultTransactionCacheSize: Long = 8.MB + getAdditionalCacheMemory() val defaultTransactionCacheSize: Long = 8.MB + getAdditionalCacheMemory()
@ -157,6 +159,22 @@ data class NodeConfigurationImpl(
}.asOptions(fallbackSslOptions) }.asOptions(fallbackSslOptions)
} }
override fun validate(): List<String> {
val errors = mutableListOf<String>()
errors + validateRpcOptions(rpcOptions)
return errors
}
private fun validateRpcOptions(options: NodeRpcOptions): List<String> {
val errors = mutableListOf<String>()
if (!options.useSsl) {
if (options.adminAddress == null) {
errors + "'rpcSettings.adminAddress': missing. Property is mandatory when 'rpcSettings.useSsl' is false (default)."
}
}
return errors
}
override val exportJMXto: String get() = "http" override val exportJMXto: String get() = "http"
override val transactionCacheSizeBytes: Long override val transactionCacheSizeBytes: Long
get() = transactionCacheSizeMegaBytes?.MB ?: super.transactionCacheSizeBytes get() = transactionCacheSizeMegaBytes?.MB ?: super.transactionCacheSizeBytes

View File

@ -711,7 +711,12 @@ class DriverDSLImpl(
* Keeping [Config] around is needed as the user may specify extra config options not specified in [NodeConfiguration]. * Keeping [Config] around is needed as the user may specify extra config options not specified in [NodeConfiguration].
*/ */
private class NodeConfig(val typesafe: Config) { private class NodeConfig(val typesafe: Config) {
val corda: NodeConfiguration = typesafe.parseAsNodeConfiguration() val corda: NodeConfiguration = typesafe.parseAsNodeConfiguration().also { nodeConfiguration ->
val errors = nodeConfiguration.validate()
if (errors.isNotEmpty()) {
throw IllegalStateException("Invalid node configuration. Errors where:${System.lineSeparator()}${errors.joinToString(System.lineSeparator())}")
}
}
} }
companion object { companion object {

View File

@ -99,7 +99,12 @@ abstract class NodeBasedTest(private val cordappPackages: List<String> = emptyLi
) + configOverrides ) + configOverrides
) )
val parsedConfig = config.parseAsNodeConfiguration() val parsedConfig = config.parseAsNodeConfiguration().also { nodeConfiguration ->
val errors = nodeConfiguration.validate()
if (errors.isNotEmpty()) {
throw IllegalStateException("Invalid node configuration. Errors where:${System.lineSeparator()}${errors.joinToString(System.lineSeparator())}")
}
}
defaultNetworkParameters.install(baseDirectory) defaultNetworkParameters.install(baseDirectory)
val node = InProcessNode(parsedConfig, MOCK_VERSION_INFO.copy(platformVersion = platformVersion), cordappPackages).start() val node = InProcessNode(parsedConfig, MOCK_VERSION_INFO.copy(platformVersion = platformVersion), cordappPackages).start()
nodes += node nodes += node