mirror of
https://github.com/corda/corda.git
synced 2025-01-27 22:59:54 +00:00
Implement launching "Node Explorer" for each node.
This commit is contained in:
parent
c787561141
commit
30f9cc8fcd
@ -0,0 +1,38 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.reflect.jvm.jvmName
|
||||
|
||||
|
||||
class Explorer(explorerController: ExplorerController) : AutoCloseable {
|
||||
private val log = LoggerFactory.getLogger(Explorer::class.jvmName)
|
||||
|
||||
private val explorerController: ExplorerController = explorerController
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
private var process: Process? = null
|
||||
|
||||
fun open(config: NodeConfig, onExit: (c: NodeConfig) -> Unit) {
|
||||
val p = explorerController.execute(
|
||||
"--host=localhost",
|
||||
"--port=%d".format(config.artemisPort),
|
||||
"--username=%s".format(config.user["user"]),
|
||||
"--password=%s".format(config.user["password"])
|
||||
)
|
||||
process = p
|
||||
|
||||
executor.submit {
|
||||
val exitValue = p.waitFor()
|
||||
process = null
|
||||
|
||||
log.info("Node Explorer for '{}' has exited (value={})", config.legalName, exitValue)
|
||||
onExit(config)
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
executor.shutdown()
|
||||
process?.destroy()
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import tornadofx.Controller
|
||||
import java.nio.file.Paths
|
||||
|
||||
class ExplorerController : Controller() {
|
||||
|
||||
private val jvm by inject<JVMConfig>()
|
||||
|
||||
private val explorerPath = Paths.get("explorer", "node-explorer.jar").toAbsolutePath()
|
||||
|
||||
internal fun execute(vararg args: String): Process {
|
||||
return jvm.execute(explorerPath, *args)
|
||||
}
|
||||
|
||||
fun explorer(): Explorer {
|
||||
return Explorer(this)
|
||||
}
|
||||
|
||||
init {
|
||||
log.info("Explorer JAR: " + explorerPath)
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import com.jediterm.terminal.ui.UIUtil
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import tornadofx.Controller
|
||||
|
||||
class JVMConfig : Controller() {
|
||||
|
||||
private val javaExe = if (UIUtil.isWindows) "java.exe" else "java"
|
||||
private val runtime: Runtime = Runtime.getRuntime()
|
||||
|
||||
val javaPath: Path = Paths.get(System.getProperty("java.home"), "bin", javaExe)
|
||||
|
||||
fun commandFor(jarPath: Path, vararg args: String): Array<String> {
|
||||
return arrayOf(javaPath.toString(), "-jar", jarPath.toString(), *args)
|
||||
}
|
||||
|
||||
fun execute(jarPath: Path, vararg args: String): Process {
|
||||
return runtime.exec(commandFor(jarPath, *args))
|
||||
}
|
||||
|
||||
init {
|
||||
log.info("Java executable: " + javaPath)
|
||||
}
|
||||
|
||||
}
|
@ -36,6 +36,10 @@ class NodeConfig(
|
||||
get() { return networkMapValue }
|
||||
set(value) { networkMapValue = value }
|
||||
|
||||
private val userMap: Map<String, String>
|
||||
val user: Map<String, String>
|
||||
get() = userMap
|
||||
|
||||
val toFileConfig : Config
|
||||
get() = ConfigFactory.empty()
|
||||
.withValue("myLegalName", valueFor(legalName))
|
||||
@ -47,10 +51,17 @@ class NodeConfig(
|
||||
.withValue("legalName", valueFor(n.legalName))
|
||||
} ))
|
||||
.withValue("webAddress", addressValueFor(webPort))
|
||||
.withValue("rpcUsers", valueFor(listOf<String>()))
|
||||
.withValue("rpcUsers", valueFor(listOf<Any>(user)))
|
||||
.withValue("h2port", valueFor(h2Port))
|
||||
.withValue("useTestClock", valueFor(true))
|
||||
|
||||
init {
|
||||
userMap = mapOf(
|
||||
Pair("password", "letmein"),
|
||||
Pair("user", "guest")
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun <T> valueFor(any: T): ConfigValue? {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import com.jediterm.terminal.ui.UIUtil
|
||||
import com.typesafe.config.ConfigRenderOptions
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.nio.file.Paths
|
||||
@ -15,11 +14,10 @@ class NodeController : Controller() {
|
||||
private val FIRST_PORT = 10000
|
||||
|
||||
private val workDir = Paths.get("work", localDir).toAbsolutePath()
|
||||
private val jvm by inject<JVMConfig>()
|
||||
|
||||
private val javaExe = if (UIUtil.isWindows) "java.exe" else "java"
|
||||
private val javaPath = Paths.get(System.getProperty("java.home"), "bin", javaExe)
|
||||
private val cordaPath = Paths.get("corda", "corda.jar").toAbsolutePath()
|
||||
private val command = arrayOf(javaPath.toString(), "-jar", cordaPath.toString())
|
||||
private val command = jvm.commandFor(cordaPath)
|
||||
|
||||
private val renderOptions = ConfigRenderOptions.defaults().setOriginComments(false)
|
||||
|
||||
@ -96,7 +94,6 @@ class NodeController : Controller() {
|
||||
|
||||
init {
|
||||
log.info("Working directory: " + workDir)
|
||||
log.info("Java executable: " + javaPath)
|
||||
log.info("Corda JAR: " + cordaPath)
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,7 @@ import javafx.scene.control.Label
|
||||
import javafx.scene.layout.Priority
|
||||
import javafx.scene.layout.VBox
|
||||
import javax.swing.SwingUtilities
|
||||
import net.corda.demobench.model.DBViewer
|
||||
import net.corda.demobench.model.NodeConfig
|
||||
import net.corda.demobench.model.NodeController
|
||||
import net.corda.demobench.model.*
|
||||
import net.corda.demobench.pty.R3Pty
|
||||
import net.corda.demobench.ui.PropertyLabel
|
||||
import tornadofx.Fragment
|
||||
@ -22,6 +20,7 @@ class NodeTerminalView : Fragment() {
|
||||
override val root by fxml<VBox>()
|
||||
|
||||
private val nodeController by inject<NodeController>()
|
||||
private val explorerController by inject<ExplorerController>()
|
||||
|
||||
private val nodeName by fxid<Label>()
|
||||
private val p2pPort by fxid<PropertyLabel>()
|
||||
@ -32,7 +31,8 @@ class NodeTerminalView : Fragment() {
|
||||
private val viewDatabaseButton by fxid<Button>()
|
||||
private val launchExplorerButton by fxid<Button>()
|
||||
|
||||
var viewer = DBViewer()
|
||||
val explorer = explorerController.explorer()
|
||||
val viewer = DBViewer()
|
||||
var pty : R3Pty? = null
|
||||
|
||||
fun open(config: NodeConfig) {
|
||||
@ -57,18 +57,31 @@ class NodeTerminalView : Fragment() {
|
||||
viewDatabaseButton.setOnAction {
|
||||
viewer.openBrowser(config.h2Port)
|
||||
}
|
||||
|
||||
/*
|
||||
* We only want to run one explorer for each node.
|
||||
* So disable the "launch" button when we have
|
||||
* launched the explorer and only reenable it when
|
||||
* the explorer has exited.
|
||||
*/
|
||||
launchExplorerButton.setOnAction {
|
||||
launchExplorerButton.isDisable= true
|
||||
|
||||
explorer.open(config, onExit = {
|
||||
launchExplorerButton.isDisable = false
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun close() {
|
||||
explorer.close()
|
||||
viewer.close()
|
||||
pty?.close()
|
||||
}
|
||||
|
||||
fun refreshTerminal() {
|
||||
SwingUtilities.invokeLater {
|
||||
// TODO - Force a repaint somehow? My naive attempts have not worked.
|
||||
}
|
||||
// TODO - Force a repaint somehow? My naive attempts have not worked.
|
||||
}
|
||||
|
||||
init {
|
||||
|
Loading…
x
Reference in New Issue
Block a user