From 96d645c316d0abac4cbe1c15113c7d73a596e75e Mon Sep 17 00:00:00 2001 From: Matthew Layton Date: Tue, 10 Jul 2018 10:24:59 +0100 Subject: [PATCH] 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 --- .../net/corda/demobench/explorer/Explorer.kt | 2 +- .../corda/demobench/model/InstallFactory.kt | 2 +- .../net/corda/demobench/model/NodeConfig.kt | 11 +- .../corda/demobench/model/NodeController.kt | 8 +- .../corda/demobench/model/NodeRpcSettings.kt | 8 ++ .../kotlin/net/corda/demobench/rpc/NodeRPC.kt | 2 +- .../corda/demobench/model/NodeConfigTest.kt | 111 +++++++++--------- .../demobench/model/NodeControllerTest.kt | 6 +- 8 files changed, 83 insertions(+), 67 deletions(-) create mode 100644 tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeRpcSettings.kt diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/explorer/Explorer.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/explorer/Explorer.kt index eb28552c88..4606621280 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/explorer/Explorer.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/explorer/Explorer.kt @@ -43,7 +43,7 @@ class Explorer internal constructor(private val explorerController: ExplorerCont val user = config.nodeConfig.rpcUsers[0] val p = explorerController.process( "--host=localhost", - "--port=${config.nodeConfig.rpcAddress.port}", + "--port=${config.nodeConfig.rpcSettings.address.port}", "--username=${user.username}", "--password=${user.password}") .directory(explorerDir.toFile()) diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/InstallFactory.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/InstallFactory.kt index 86f987c33a..68c5e0a42b 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/InstallFactory.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/InstallFactory.kt @@ -22,7 +22,7 @@ class InstallFactory : Controller() { val nodeConfig = config.parseAs(UnknownConfigKeysPolicy.IGNORE::handle) nodeConfig.p2pAddress.checkPort() - nodeConfig.rpcAddress.checkPort() + nodeConfig.rpcSettings.address.checkPort() nodeConfig.webAddress.checkPort() val tempDir = Files.createTempDirectory(baseDir, ".node") diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt index 0270d12cfb..9f63d8f38b 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeConfig.kt @@ -20,8 +20,7 @@ import java.util.Properties data class NodeConfig( val myLegalName: CordaX500Name, val p2pAddress: NetworkHostAndPort, - val rpcAddress: NetworkHostAndPort, - val rpcAdminAddress: NetworkHostAndPort, + val rpcSettings: NodeRpcSettings, /** This is not used by the node but by the webserver which looks at node.conf. */ val webAddress: NetworkHostAndPort, val notary: NotaryService?, @@ -44,8 +43,8 @@ data class NodeConfig( fun nodeConf(): Config { val rpcSettings: ConfigObject = empty() - .withValue("address", valueFor(rpcAddress.toString())) - .withValue("adminAddress", valueFor(rpcAdminAddress.toString())) + .withValue("address", valueFor(rpcSettings.address.toString())) + .withValue("adminAddress", valueFor(rpcSettings.adminAddress.toString())) .root() val customMap: Map = HashMap().also { if (issuableCurrencies.isNotEmpty()) { @@ -53,7 +52,7 @@ data class NodeConfig( } } 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() .withoutPath("rpcAddress") .withoutPath("rpcAdminAddress") @@ -61,7 +60,7 @@ data class NodeConfig( .withOptionalValue("custom", custom) } - fun webServerConf() = WebServerConfigurationData(myLegalName, rpcAddress, webAddress, rpcUsers).asConfig() + fun webServerConf() = WebServerConfigurationData(myLegalName, rpcSettings.address, webAddress, rpcUsers).asConfig() fun toNodeConfText() = nodeConf().render() diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt index 7ffff3cfbb..aa25cc163c 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeController.kt @@ -70,8 +70,10 @@ class NodeController(check: atRuntime = ::checkExists) : Controller() { country = location.countryCode ), p2pAddress = nodeData.p2pPort.toLocalAddress(), - rpcAddress = nodeData.rpcPort.toLocalAddress(), - rpcAdminAddress = nodeData.rpcAdminPort.toLocalAddress(), + rpcSettings = NodeRpcSettings( + address = nodeData.rpcPort.toLocalAddress(), + adminAddress = nodeData.rpcAdminPort.toLocalAddress() + ), webAddress = nodeData.webPort.toLocalAddress(), notary = notary, h2port = nodeData.h2Port.value, @@ -202,7 +204,7 @@ class NodeController(check: atRuntime = ::checkExists) : Controller() { } 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) } } diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeRpcSettings.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeRpcSettings.kt new file mode 100644 index 0000000000..04d093a318 --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeRpcSettings.kt @@ -0,0 +1,8 @@ +package net.corda.demobench.model + +import net.corda.core.utilities.NetworkHostAndPort + +data class NodeRpcSettings( + val address: NetworkHostAndPort, + val adminAddress: NetworkHostAndPort +) \ No newline at end of file diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt index 9300fc9643..c762a1e132 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/rpc/NodeRPC.kt @@ -15,7 +15,7 @@ class NodeRPC(config: NodeConfigWrapper, start: (NodeConfigWrapper, CordaRPCOps) 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 private var rpcConnection: CordaRPCConnection? = null private val timer = Timer("DemoBench NodeRPC (${config.key})", true) diff --git a/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeConfigTest.kt b/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeConfigTest.kt index d85acad092..d044c63f14 100644 --- a/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeConfigTest.kt +++ b/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeConfigTest.kt @@ -10,7 +10,10 @@ import net.corda.webserver.WebServerConfig import org.junit.Test import java.nio.file.Path 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 { companion object { @@ -21,21 +24,21 @@ class NodeConfigTest { @Test fun `reading node configuration`() { val config = createConfig( - legalName = myLegalName, - p2pPort = 10001, - rpcPort = 40002, - rpcAdminPort = 40005, - webPort = 20001, - h2port = 30001, - notary = NotaryService(validating = false), - users = listOf(user("jenny")) + legalName = myLegalName, + p2pPort = 10001, + rpcPort = 40002, + rpcAdminPort = 40005, + webPort = 20001, + h2port = 30001, + notary = NotaryService(validating = false), + users = listOf(user("jenny")) ) val nodeConfig = config.nodeConf() - .withValue("baseDirectory", valueFor(baseDir.toString())) - .withFallback(ConfigFactory.parseResources("reference.conf")) - .withFallback(ConfigFactory.parseMap(mapOf("devMode" to true))) - .resolve() + .withValue("baseDirectory", valueFor(baseDir.toString())) + .withFallback(ConfigFactory.parseResources("reference.conf")) + .withFallback(ConfigFactory.parseMap(mapOf("devMode" to true))) + .resolve() val fullConfig = nodeConfig.parseAsNodeConfiguration() // No custom configuration is created by default. @@ -52,20 +55,20 @@ class NodeConfigTest { @Test fun `reading node configuration with currencies`() { val config = createConfig( - legalName = myLegalName, - p2pPort = 10001, - rpcPort = 10002, - rpcAdminPort = 10003, - webPort = 10004, - h2port = 10005, - notary = NotaryService(validating = false), - issuableCurrencies = listOf("GBP") + legalName = myLegalName, + p2pPort = 10001, + rpcPort = 10002, + rpcAdminPort = 10003, + webPort = 10004, + h2port = 10005, + notary = NotaryService(validating = false), + issuableCurrencies = listOf("GBP") ) val nodeConfig = config.nodeConf() - .withValue("baseDirectory", valueFor(baseDir.toString())) - .withFallback(ConfigFactory.parseResources("reference.conf")) - .resolve() + .withValue("baseDirectory", valueFor(baseDir.toString())) + .withFallback(ConfigFactory.parseResources("reference.conf")) + .resolve() val custom = nodeConfig.getConfig("custom") assertEquals(listOf("GBP"), custom.getAnyRefList("issuableCurrencies")) } @@ -73,20 +76,20 @@ class NodeConfigTest { @Test fun `reading webserver configuration`() { val config = createConfig( - legalName = myLegalName, - p2pPort = 10001, - rpcPort = 40002, - rpcAdminPort = 40003, - webPort = 20001, - h2port = 30001, - notary = NotaryService(validating = false), - users = listOf(user("jenny")) + legalName = myLegalName, + p2pPort = 10001, + rpcPort = 40002, + rpcAdminPort = 40003, + webPort = 20001, + h2port = 30001, + notary = NotaryService(validating = false), + users = listOf(user("jenny")) ) val nodeConfig = config.webServerConf() - .withValue("baseDirectory", valueFor(baseDir.toString())) - .withFallback(ConfigFactory.parseResources("web-reference.conf")) - .resolve() + .withValue("baseDirectory", valueFor(baseDir.toString())) + .withFallback(ConfigFactory.parseResources("web-reference.conf")) + .resolve() val webConfig = WebServerConfig(baseDir, nodeConfig) // No custom configuration is created by default. @@ -99,26 +102,28 @@ class NodeConfigTest { } private fun createConfig( - legalName: CordaX500Name = CordaX500Name(organisation = "Unknown", locality = "Nowhere", country = "GB"), - p2pPort: Int = -1, - rpcPort: Int = -1, - rpcAdminPort: Int = -1, - webPort: Int = -1, - h2port: Int = -1, - notary: NotaryService?, - users: List = listOf(user("guest")), - issuableCurrencies: List = emptyList() + legalName: CordaX500Name = CordaX500Name(organisation = "Unknown", locality = "Nowhere", country = "GB"), + p2pPort: Int = -1, + rpcPort: Int = -1, + rpcAdminPort: Int = -1, + webPort: Int = -1, + h2port: Int = -1, + notary: NotaryService?, + users: List = listOf(user("guest")), + issuableCurrencies: List = emptyList() ): NodeConfig { return NodeConfig( - myLegalName = legalName, - p2pAddress = localPort(p2pPort), - rpcAddress = localPort(rpcPort), - rpcAdminAddress = localPort(rpcAdminPort), - webAddress = localPort(webPort), - h2port = h2port, - notary = notary, - rpcUsers = users, - issuableCurrencies = issuableCurrencies + myLegalName = legalName, + p2pAddress = localPort(p2pPort), + rpcSettings = NodeRpcSettings( + address = localPort(rpcPort), + adminAddress = localPort(rpcAdminPort) + ), + webAddress = localPort(webPort), + h2port = h2port, + notary = notary, + rpcUsers = users, + issuableCurrencies = issuableCurrencies ) } diff --git a/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeControllerTest.kt b/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeControllerTest.kt index e6b5454144..46bbde3dfb 100644 --- a/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeControllerTest.kt +++ b/tools/demobench/src/test/kotlin/net/corda/demobench/model/NodeControllerTest.kt @@ -163,8 +163,10 @@ class NodeControllerTest { country = "US" ), p2pAddress = localPort(p2pPort), - rpcAddress = localPort(rpcPort), - rpcAdminAddress = localPort(rpcAdminPort), + rpcSettings = NodeRpcSettings( + address = localPort(rpcPort), + adminAddress = localPort(rpcAdminPort) + ), webAddress = localPort(webPort), h2port = h2port, notary = notary,