From 986bd548fa7a65b536dfd03177618c2769054fcb Mon Sep 17 00:00:00 2001 From: Andras Slemmer Date: Mon, 27 Feb 2017 11:35:29 +0000 Subject: [PATCH] loadtest: Fix config loading, add missing fields --- .../corda/loadtest/LoadTestConfiguration.kt | 28 +++++++++++-------- .../main/kotlin/net/corda/loadtest/Main.kt | 20 ++++--------- .../main/resources/loadtest-reference.conf | 8 ++++-- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTestConfiguration.kt b/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTestConfiguration.kt index 6116f94881..35170883eb 100644 --- a/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTestConfiguration.kt +++ b/tools/loadtest/src/main/kotlin/net/corda/loadtest/LoadTestConfiguration.kt @@ -1,12 +1,16 @@ package net.corda.loadtest +import com.typesafe.config.Config import java.nio.file.Path +import net.corda.node.services.config.* /** * @param sshUser The UNIX username to use for SSH auth. * @param localCertificatesBaseDirectory The base directory to put node certificates in. * @param localTunnelStartingPort The local starting port to allocate tunneling ports from. * @param nodeHosts The nodes' resolvable addresses. + * @param rpcUsername The RPC user's name to establish the RPC connection as. + * @param rpcPassword The RPC user's password. * @param remoteNodeDirectory The remote node directory. * @param remoteMessagingPort The remote Artemis messaging port. * @param remoteSystemdServiceName The name of the node's systemd service @@ -16,14 +20,16 @@ import java.nio.file.Path * for disruptions. */ data class LoadTestConfiguration( - val sshUser: String, - val localCertificatesBaseDirectory: Path, - val localTunnelStartingPort: Int, - val nodeHosts: List, - val rpcUsername: String, - val rpcPassword: String, - val remoteNodeDirectory: Path, - val remoteMessagingPort: Int, - val remoteSystemdServiceName: String, - val seed: Long? -) + val config: Config +) { + val sshUser: String by config + val localCertificatesBaseDirectory: Path by config + val localTunnelStartingPort: Int by config + val nodeHosts: List = config.getStringList("nodeHosts") + val rpcUsername: String by config + val rpcPassword: String by config + val remoteNodeDirectory: Path by config + val remoteMessagingPort: Int by config + val remoteSystemdServiceName: String by config + val seed: Long? by config +} diff --git a/tools/loadtest/src/main/kotlin/net/corda/loadtest/Main.kt b/tools/loadtest/src/main/kotlin/net/corda/loadtest/Main.kt index b94fcba9e2..36438275e3 100644 --- a/tools/loadtest/src/main/kotlin/net/corda/loadtest/Main.kt +++ b/tools/loadtest/src/main/kotlin/net/corda/loadtest/Main.kt @@ -44,26 +44,16 @@ import java.nio.file.Paths */ fun main(args: Array) { - if (args.isEmpty()) { throw IllegalArgumentException("Usage: PATH_TO_CONFIG") } val defaultConfig = ConfigFactory.parseResources("loadtest-reference.conf", ConfigParseOptions.defaults().setAllowMissing(false)) - val customConfig = ConfigFactory.parseFile(File(args[0]), ConfigParseOptions.defaults().setAllowMissing(false)) - val resolvedConfig = customConfig.withFallback(defaultConfig).resolve() - - val loadTestConfiguration = LoadTestConfiguration( - sshUser = if (resolvedConfig.hasPath("sshUser")) resolvedConfig.getString("sshUser") else System.getProperty("user.name"), - localCertificatesBaseDirectory = Paths.get(resolvedConfig.getString("localCertificatesBaseDirectory")), - localTunnelStartingPort = resolvedConfig.getInt("localTunnelStartingPort"), - nodeHosts = resolvedConfig.getStringList("nodeHosts"), - rpcUsername = "corda", - rpcPassword = "rgb", - remoteNodeDirectory = Paths.get("/opt/corda"), - remoteMessagingPort = 10002, - remoteSystemdServiceName = "corda", - seed = if (resolvedConfig.hasPath("seed")) resolvedConfig.getLong("seed") else null + val defaultSshUserConfig = ConfigFactory.parseMap( + if (defaultConfig.hasPath("sshUser")) emptyMap() else mapOf("sshUser" to System.getProperty("user.name")) ) + val customConfig = ConfigFactory.parseFile(File(args[0]), ConfigParseOptions.defaults().setAllowMissing(false)) + val resolvedConfig = customConfig.withFallback(defaultConfig).withFallback(defaultSshUserConfig).resolve() + val loadTestConfiguration = LoadTestConfiguration(resolvedConfig) if (loadTestConfiguration.nodeHosts.isEmpty()) { throw IllegalArgumentException("Please specify at least one node host") diff --git a/tools/loadtest/src/main/resources/loadtest-reference.conf b/tools/loadtest/src/main/resources/loadtest-reference.conf index f307688604..2419df6784 100644 --- a/tools/loadtest/src/main/resources/loadtest-reference.conf +++ b/tools/loadtest/src/main/resources/loadtest-reference.conf @@ -2,6 +2,8 @@ # sshUser = "someusername", by default it uses the System property "user.name" localCertificatesBaseDirectory = "build/load-test/certificates" localTunnelStartingPort = 10000 -remoteNodeDirectory = "/opt/r3cev" -remoteMessagingPort = 31337 -remoteSystemdServiceName = "r3cev-node" \ No newline at end of file +remoteNodeDirectory = "/opt/corda" +remoteMessagingPort = 10002 +remoteSystemdServiceName = "corda" +rpcUsername = "corda" +rpcPassword = "rgb" \ No newline at end of file