series0ne/corda-demobench-node-config-fix

Fixes an issue where profiles don't load because the node.conf format has changed between V1 and V3
This commit is contained in:
Matthew Layton 2018-07-10 10:24:59 +01:00 committed by Mike Hearn
parent f94abf726b
commit 96d645c316
8 changed files with 83 additions and 67 deletions

View File

@ -43,7 +43,7 @@ class Explorer internal constructor(private val explorerController: ExplorerCont
val user = config.nodeConfig.rpcUsers[0] val user = config.nodeConfig.rpcUsers[0]
val p = explorerController.process( val p = explorerController.process(
"--host=localhost", "--host=localhost",
"--port=${config.nodeConfig.rpcAddress.port}", "--port=${config.nodeConfig.rpcSettings.address.port}",
"--username=${user.username}", "--username=${user.username}",
"--password=${user.password}") "--password=${user.password}")
.directory(explorerDir.toFile()) .directory(explorerDir.toFile())

View File

@ -22,7 +22,7 @@ class InstallFactory : Controller() {
val nodeConfig = config.parseAs<NodeConfig>(UnknownConfigKeysPolicy.IGNORE::handle) val nodeConfig = config.parseAs<NodeConfig>(UnknownConfigKeysPolicy.IGNORE::handle)
nodeConfig.p2pAddress.checkPort() nodeConfig.p2pAddress.checkPort()
nodeConfig.rpcAddress.checkPort() nodeConfig.rpcSettings.address.checkPort()
nodeConfig.webAddress.checkPort() nodeConfig.webAddress.checkPort()
val tempDir = Files.createTempDirectory(baseDir, ".node") val tempDir = Files.createTempDirectory(baseDir, ".node")

View File

@ -20,8 +20,7 @@ import java.util.Properties
data class NodeConfig( data class NodeConfig(
val myLegalName: CordaX500Name, val myLegalName: CordaX500Name,
val p2pAddress: NetworkHostAndPort, val p2pAddress: NetworkHostAndPort,
val rpcAddress: NetworkHostAndPort, val rpcSettings: NodeRpcSettings,
val rpcAdminAddress: NetworkHostAndPort,
/** This is not used by the node but by the webserver which looks at node.conf. */ /** This is not used by the node but by the webserver which looks at node.conf. */
val webAddress: NetworkHostAndPort, val webAddress: NetworkHostAndPort,
val notary: NotaryService?, val notary: NotaryService?,
@ -44,8 +43,8 @@ data class NodeConfig(
fun nodeConf(): Config { fun nodeConf(): Config {
val rpcSettings: ConfigObject = empty() val rpcSettings: ConfigObject = empty()
.withValue("address", valueFor(rpcAddress.toString())) .withValue("address", valueFor(rpcSettings.address.toString()))
.withValue("adminAddress", valueFor(rpcAdminAddress.toString())) .withValue("adminAddress", valueFor(rpcSettings.adminAddress.toString()))
.root() .root()
val customMap: Map<String, Any> = HashMap<String, Any>().also { val customMap: Map<String, Any> = HashMap<String, Any>().also {
if (issuableCurrencies.isNotEmpty()) { if (issuableCurrencies.isNotEmpty()) {
@ -53,7 +52,7 @@ data class NodeConfig(
} }
} }
val custom: ConfigObject = ConfigFactory.parseMap(customMap).root() val custom: ConfigObject = ConfigFactory.parseMap(customMap).root()
return NodeConfigurationData(myLegalName, p2pAddress, rpcAddress, notary, h2port, rpcUsers, useTestClock, detectPublicIp, devMode) return NodeConfigurationData(myLegalName, p2pAddress, this.rpcSettings.address, notary, h2port, rpcUsers, useTestClock, detectPublicIp, devMode)
.toConfig() .toConfig()
.withoutPath("rpcAddress") .withoutPath("rpcAddress")
.withoutPath("rpcAdminAddress") .withoutPath("rpcAdminAddress")
@ -61,7 +60,7 @@ data class NodeConfig(
.withOptionalValue("custom", custom) .withOptionalValue("custom", custom)
} }
fun webServerConf() = WebServerConfigurationData(myLegalName, rpcAddress, webAddress, rpcUsers).asConfig() fun webServerConf() = WebServerConfigurationData(myLegalName, rpcSettings.address, webAddress, rpcUsers).asConfig()
fun toNodeConfText() = nodeConf().render() fun toNodeConfText() = nodeConf().render()

View File

@ -70,8 +70,10 @@ class NodeController(check: atRuntime = ::checkExists) : Controller() {
country = location.countryCode country = location.countryCode
), ),
p2pAddress = nodeData.p2pPort.toLocalAddress(), p2pAddress = nodeData.p2pPort.toLocalAddress(),
rpcAddress = nodeData.rpcPort.toLocalAddress(), rpcSettings = NodeRpcSettings(
rpcAdminAddress = nodeData.rpcAdminPort.toLocalAddress(), address = nodeData.rpcPort.toLocalAddress(),
adminAddress = nodeData.rpcAdminPort.toLocalAddress()
),
webAddress = nodeData.webPort.toLocalAddress(), webAddress = nodeData.webPort.toLocalAddress(),
notary = notary, notary = notary,
h2port = nodeData.h2Port.value, h2port = nodeData.h2Port.value,
@ -202,7 +204,7 @@ class NodeController(check: atRuntime = ::checkExists) : Controller() {
} }
private fun updatePort(config: NodeConfig) { private fun updatePort(config: NodeConfig) {
val nextPort = 1 + arrayOf(config.p2pAddress.port, config.rpcAddress.port, config.webAddress.port, config.h2port).max() as Int val nextPort = 1 + arrayOf(config.p2pAddress.port, config.rpcSettings.address.port, config.webAddress.port, config.h2port).max() as Int
port.getAndUpdate { Math.max(nextPort, it) } port.getAndUpdate { Math.max(nextPort, it) }
} }

View File

@ -0,0 +1,8 @@
package net.corda.demobench.model
import net.corda.core.utilities.NetworkHostAndPort
data class NodeRpcSettings(
val address: NetworkHostAndPort,
val adminAddress: NetworkHostAndPort
)

View File

@ -15,7 +15,7 @@ class NodeRPC(config: NodeConfigWrapper, start: (NodeConfigWrapper, CordaRPCOps)
private val oneSecond = SECONDS.toMillis(1) private val oneSecond = SECONDS.toMillis(1)
} }
private val rpcClient = CordaRPCClient(NetworkHostAndPort("localhost", config.nodeConfig.rpcAddress.port)) private val rpcClient = CordaRPCClient(NetworkHostAndPort("localhost", config.nodeConfig.rpcSettings.address.port))
@Volatile @Volatile
private var rpcConnection: CordaRPCConnection? = null private var rpcConnection: CordaRPCConnection? = null
private val timer = Timer("DemoBench NodeRPC (${config.key})", true) private val timer = Timer("DemoBench NodeRPC (${config.key})", true)

View File

@ -10,7 +10,10 @@ import net.corda.webserver.WebServerConfig
import org.junit.Test import org.junit.Test
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import kotlin.test.* import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class NodeConfigTest { class NodeConfigTest {
companion object { companion object {
@ -21,21 +24,21 @@ class NodeConfigTest {
@Test @Test
fun `reading node configuration`() { fun `reading node configuration`() {
val config = createConfig( val config = createConfig(
legalName = myLegalName, legalName = myLegalName,
p2pPort = 10001, p2pPort = 10001,
rpcPort = 40002, rpcPort = 40002,
rpcAdminPort = 40005, rpcAdminPort = 40005,
webPort = 20001, webPort = 20001,
h2port = 30001, h2port = 30001,
notary = NotaryService(validating = false), notary = NotaryService(validating = false),
users = listOf(user("jenny")) users = listOf(user("jenny"))
) )
val nodeConfig = config.nodeConf() val nodeConfig = config.nodeConf()
.withValue("baseDirectory", valueFor(baseDir.toString())) .withValue("baseDirectory", valueFor(baseDir.toString()))
.withFallback(ConfigFactory.parseResources("reference.conf")) .withFallback(ConfigFactory.parseResources("reference.conf"))
.withFallback(ConfigFactory.parseMap(mapOf("devMode" to true))) .withFallback(ConfigFactory.parseMap(mapOf("devMode" to true)))
.resolve() .resolve()
val fullConfig = nodeConfig.parseAsNodeConfiguration() val fullConfig = nodeConfig.parseAsNodeConfiguration()
// No custom configuration is created by default. // No custom configuration is created by default.
@ -52,20 +55,20 @@ class NodeConfigTest {
@Test @Test
fun `reading node configuration with currencies`() { fun `reading node configuration with currencies`() {
val config = createConfig( val config = createConfig(
legalName = myLegalName, legalName = myLegalName,
p2pPort = 10001, p2pPort = 10001,
rpcPort = 10002, rpcPort = 10002,
rpcAdminPort = 10003, rpcAdminPort = 10003,
webPort = 10004, webPort = 10004,
h2port = 10005, h2port = 10005,
notary = NotaryService(validating = false), notary = NotaryService(validating = false),
issuableCurrencies = listOf("GBP") issuableCurrencies = listOf("GBP")
) )
val nodeConfig = config.nodeConf() val nodeConfig = config.nodeConf()
.withValue("baseDirectory", valueFor(baseDir.toString())) .withValue("baseDirectory", valueFor(baseDir.toString()))
.withFallback(ConfigFactory.parseResources("reference.conf")) .withFallback(ConfigFactory.parseResources("reference.conf"))
.resolve() .resolve()
val custom = nodeConfig.getConfig("custom") val custom = nodeConfig.getConfig("custom")
assertEquals(listOf("GBP"), custom.getAnyRefList("issuableCurrencies")) assertEquals(listOf("GBP"), custom.getAnyRefList("issuableCurrencies"))
} }
@ -73,20 +76,20 @@ class NodeConfigTest {
@Test @Test
fun `reading webserver configuration`() { fun `reading webserver configuration`() {
val config = createConfig( val config = createConfig(
legalName = myLegalName, legalName = myLegalName,
p2pPort = 10001, p2pPort = 10001,
rpcPort = 40002, rpcPort = 40002,
rpcAdminPort = 40003, rpcAdminPort = 40003,
webPort = 20001, webPort = 20001,
h2port = 30001, h2port = 30001,
notary = NotaryService(validating = false), notary = NotaryService(validating = false),
users = listOf(user("jenny")) users = listOf(user("jenny"))
) )
val nodeConfig = config.webServerConf() val nodeConfig = config.webServerConf()
.withValue("baseDirectory", valueFor(baseDir.toString())) .withValue("baseDirectory", valueFor(baseDir.toString()))
.withFallback(ConfigFactory.parseResources("web-reference.conf")) .withFallback(ConfigFactory.parseResources("web-reference.conf"))
.resolve() .resolve()
val webConfig = WebServerConfig(baseDir, nodeConfig) val webConfig = WebServerConfig(baseDir, nodeConfig)
// No custom configuration is created by default. // No custom configuration is created by default.
@ -99,26 +102,28 @@ class NodeConfigTest {
} }
private fun createConfig( private fun createConfig(
legalName: CordaX500Name = CordaX500Name(organisation = "Unknown", locality = "Nowhere", country = "GB"), legalName: CordaX500Name = CordaX500Name(organisation = "Unknown", locality = "Nowhere", country = "GB"),
p2pPort: Int = -1, p2pPort: Int = -1,
rpcPort: Int = -1, rpcPort: Int = -1,
rpcAdminPort: Int = -1, rpcAdminPort: Int = -1,
webPort: Int = -1, webPort: Int = -1,
h2port: Int = -1, h2port: Int = -1,
notary: NotaryService?, notary: NotaryService?,
users: List<User> = listOf(user("guest")), users: List<User> = listOf(user("guest")),
issuableCurrencies: List<String> = emptyList() issuableCurrencies: List<String> = emptyList()
): NodeConfig { ): NodeConfig {
return NodeConfig( return NodeConfig(
myLegalName = legalName, myLegalName = legalName,
p2pAddress = localPort(p2pPort), p2pAddress = localPort(p2pPort),
rpcAddress = localPort(rpcPort), rpcSettings = NodeRpcSettings(
rpcAdminAddress = localPort(rpcAdminPort), address = localPort(rpcPort),
webAddress = localPort(webPort), adminAddress = localPort(rpcAdminPort)
h2port = h2port, ),
notary = notary, webAddress = localPort(webPort),
rpcUsers = users, h2port = h2port,
issuableCurrencies = issuableCurrencies notary = notary,
rpcUsers = users,
issuableCurrencies = issuableCurrencies
) )
} }

View File

@ -163,8 +163,10 @@ class NodeControllerTest {
country = "US" country = "US"
), ),
p2pAddress = localPort(p2pPort), p2pAddress = localPort(p2pPort),
rpcAddress = localPort(rpcPort), rpcSettings = NodeRpcSettings(
rpcAdminAddress = localPort(rpcAdminPort), address = localPort(rpcPort),
adminAddress = localPort(rpcAdminPort)
),
webAddress = localPort(webPort), webAddress = localPort(webPort),
h2port = h2port, h2port = h2port,
notary = notary, notary = notary,