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 {
@ -112,8 +115,10 @@ class NodeConfigTest {
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),
adminAddress = localPort(rpcAdminPort)
),
webAddress = localPort(webPort), webAddress = localPort(webPort),
h2port = h2port, h2port = h2port,
notary = notary, notary = notary,

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,