Added basic node configuration validation. (#2433)

This commit is contained in:
Michele Sollecito
2018-02-05 18:17:54 +00:00
committed by GitHub
parent 69c989478a
commit 3b5d89883d
4 changed files with 35 additions and 2 deletions

View File

@ -90,6 +90,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)

View File

@ -50,6 +50,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()
@ -163,6 +165,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