From 1aae41214ffdbe1d62ffb0458f2af36d094886db Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Thu, 25 May 2017 11:49:21 +0100 Subject: [PATCH] Unpack DemoBench's capsules within $HOME/demobench directory. (#738) * Unpack the capsules into a subdirectory of $HOME/demobench. * Minor tidy up. * Add a new suggested bank. --- .../kotlin/net/corda/demobench/model/JVMConfig.kt | 8 ++++++-- .../kotlin/net/corda/demobench/model/NodeConfig.kt | 5 ++--- .../net/corda/demobench/model/NodeController.kt | 5 ++++- .../kotlin/net/corda/demobench/model/NodeData.kt | 3 ++- .../net/corda/demobench/model/ServiceController.kt | 12 +++++------- .../src/main/kotlin/net/corda/demobench/pty/R3Pty.kt | 5 ++--- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/JVMConfig.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/JVMConfig.kt index 3e4c3d1652..148cc9025b 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/JVMConfig.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/JVMConfig.kt @@ -3,14 +3,15 @@ package net.corda.demobench.model import javafx.scene.control.Alert import javafx.scene.control.Alert.AlertType.ERROR import javafx.stage.Stage -import tornadofx.* import java.nio.file.Path import java.nio.file.Paths +import tornadofx.* class JVMConfig : Controller() { val userHome: Path = Paths.get(System.getProperty("user.home")).toAbsolutePath() val dataHome: Path = userHome.resolve("demobench") + val capsuleHome: Path = dataHome.resolve(".capsule") val javaPath: Path = Paths.get(System.getProperty("java.home"), "bin", "java") val applicationDir: Path = Paths.get(System.getProperty("user.dir")).toAbsolutePath() @@ -23,9 +24,12 @@ class JVMConfig : Controller() { } fun processFor(jarPath: Path, vararg args: String): ProcessBuilder { - return ProcessBuilder(commandFor(jarPath, *args)) + return ProcessBuilder(commandFor(jarPath, *args)).apply { setCapsuleCacheDir(environment()) } } + fun setCapsuleCacheDir(env: MutableMap): MutableMap = env.apply { + put("CAPSULE_CACHE_DIR", capsuleHome.toString()) + } } typealias atRuntime = (Path, String) -> Unit 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 7a73d40e28..baf94692f5 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 @@ -47,10 +47,9 @@ class NodeConfig( .withValue("myLegalName", valueFor(legalName.toString())) .withValue("p2pAddress", addressValueFor(p2pPort)) .withValue("extraAdvertisedServiceIds", valueFor(extraServices)) - .withFallback(optional("networkMapService", networkMap, { - c, n -> + .withFallback(optional("networkMapService", networkMap, { c, n -> c.withValue("address", addressValueFor(n.p2pPort)) - .withValue("legalName", valueFor(n.legalName.toString())) + .withValue("legalName", valueFor(n.legalName.toString())) })) .withValue("webAddress", addressValueFor(webPort)) .withValue("rpcAddress", addressValueFor(rpcPort)) 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 31460611d9..b593bc32ce 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 @@ -116,7 +116,10 @@ class NodeController(check: atRuntime = ::checkExists) : Controller() { confFile.writeText(config.toText()) // Execute the Corda node - pty.run(command, System.getenv(), nodeDir.toString()) + val cordaEnv = System.getenv().toMutableMap().apply { + jvm.setCapsuleCacheDir(this) + } + pty.run(command, cordaEnv, nodeDir.toString()) log.info("Launched node: ${config.legalName}") return true } catch (e: Exception) { diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt index 0138ae92d2..e4f234fa10 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/NodeData.kt @@ -19,7 +19,8 @@ object SuggestedDetails { "Bank of Big Apples" to "New York", "Bank of Baguettes" to "Paris", "Bank of Fondue" to "Geneve", - "Bank of Maple Syrup" to "Toronto" + "Bank of Maple Syrup" to "Toronto", + "Bank of Golden Gates" to "San Francisco" ) private var cursor = 0 diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/model/ServiceController.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/model/ServiceController.kt index 0974a4f6df..cfd1c23038 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/model/ServiceController.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/model/ServiceController.kt @@ -4,7 +4,6 @@ import tornadofx.* import java.io.IOException import java.io.InputStreamReader import java.net.URL -import java.util.* import java.util.logging.Level class ServiceController(resourceName: String = "/services.conf") : Controller() { @@ -17,11 +16,11 @@ class ServiceController(resourceName: String = "/services.conf") : Controller() * Load our list of known extra Corda services. */ private fun loadConf(url: URL?): List { - if (url == null) { - return emptyList() + return if (url == null) { + emptyList() } else { try { - val set = TreeSet() + val set = sortedSetOf() InputStreamReader(url.openStream()).useLines { sq -> sq.forEach { line -> val service = line.trim() @@ -30,12 +29,11 @@ class ServiceController(resourceName: String = "/services.conf") : Controller() log.info("Supports: $service") } } - return set.toList() + set.toList() } catch (e: IOException) { log.log(Level.SEVERE, "Failed to load $url: ${e.message}", e) - return emptyList() + emptyList() } } } - } diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt index 68152fbfc1..1269062d64 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/pty/R3Pty.kt @@ -44,7 +44,7 @@ class R3Pty(val name: X500Name, settings: SettingsProvider, dimension: Dimension @Throws(IOException::class) fun run(args: Array, envs: Map, workingDir: String?) { - check(!terminal.isSessionRunning, { "${terminal.sessionName} is already running" }) + check(!terminal.isSessionRunning) { "${terminal.sessionName} is already running" } val environment = envs.toMutableMap() if (!UIUtil.isWindows) { @@ -64,8 +64,7 @@ class R3Pty(val name: X500Name, settings: SettingsProvider, dimension: Dimension onExit(exitValue) } - val session = terminal.createTerminalSession(connector) - session.start() + terminal.createTerminalSession(connector).apply { start() } } @Suppress("unused")