mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Merge pull request #2470 from corda/fixes/sollecitom/failfast_rpc_settings
Added basic node configuration validation.
This commit is contained in:
commit
9b8fe3a1d4
@ -89,6 +89,11 @@ open class NodeStartup(val args: Array<String>) {
|
||||
logger.error("Exception during node configuration", e)
|
||||
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 {
|
||||
banJavaSerialisation(conf)
|
||||
|
@ -49,6 +49,8 @@ interface NodeConfiguration : NodeSSLConfiguration {
|
||||
val attachmentContentCacheSizeBytes: Long get() = defaultAttachmentContentCacheSize
|
||||
val attachmentCacheBound: Long get() = defaultAttachmentCacheBound
|
||||
|
||||
fun validate(): List<String>
|
||||
|
||||
companion object {
|
||||
// default to at least 8MB and a bit extra for larger heap sizes
|
||||
val defaultTransactionCacheSize: Long = 8.MB + getAdditionalCacheMemory()
|
||||
@ -157,6 +159,22 @@ data class NodeConfigurationImpl(
|
||||
}.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 transactionCacheSizeBytes: Long
|
||||
get() = transactionCacheSizeMegaBytes?.MB ?: super.transactionCacheSizeBytes
|
||||
|
@ -711,7 +711,12 @@ class DriverDSLImpl(
|
||||
* Keeping [Config] around is needed as the user may specify extra config options not specified in [NodeConfiguration].
|
||||
*/
|
||||
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 {
|
||||
|
@ -99,7 +99,12 @@ abstract class NodeBasedTest(private val cordappPackages: List<String> = emptyLi
|
||||
) + 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)
|
||||
val node = InProcessNode(parsedConfig, MOCK_VERSION_INFO.copy(platformVersion = platformVersion), cordappPackages).start()
|
||||
nodes += node
|
||||
|
Loading…
Reference in New Issue
Block a user