mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
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:
parent
f94abf726b
commit
96d645c316
@ -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())
|
||||
|
@ -22,7 +22,7 @@ class InstallFactory : Controller() {
|
||||
|
||||
val nodeConfig = config.parseAs<NodeConfig>(UnknownConfigKeysPolicy.IGNORE::handle)
|
||||
nodeConfig.p2pAddress.checkPort()
|
||||
nodeConfig.rpcAddress.checkPort()
|
||||
nodeConfig.rpcSettings.address.checkPort()
|
||||
nodeConfig.webAddress.checkPort()
|
||||
|
||||
val tempDir = Files.createTempDirectory(baseDir, ".node")
|
||||
|
@ -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<String, Any> = HashMap<String, Any>().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()
|
||||
|
||||
|
@ -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) }
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
|
||||
data class NodeRpcSettings(
|
||||
val address: NetworkHostAndPort,
|
||||
val adminAddress: NetworkHostAndPort
|
||||
)
|
@ -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)
|
||||
|
@ -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<User> = listOf(user("guest")),
|
||||
issuableCurrencies: List<String> = 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<User> = listOf(user("guest")),
|
||||
issuableCurrencies: List<String> = 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
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user