mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
CORPRIV-660: Allow user to launch Web server for each node.
This commit is contained in:
parent
655cdf5e96
commit
28d7170aca
@ -12,8 +12,8 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable {
|
||||
fun open(config: NodeConfig, onExit: (NodeConfig) -> Unit) {
|
||||
val explorerDir = config.explorerDir.toFile()
|
||||
|
||||
if (!explorerDir.isDirectory() && !explorerDir.mkdirs()) {
|
||||
log.warn("Failed to create working directory '{}'", explorerDir.getAbsolutePath())
|
||||
if (!explorerDir.isDirectory && !explorerDir.mkdirs()) {
|
||||
log.warn("Failed to create working directory '{}'", explorerDir.absolutePath)
|
||||
onExit(config)
|
||||
return
|
||||
}
|
||||
@ -30,6 +30,8 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable {
|
||||
)
|
||||
process = p
|
||||
|
||||
log.info("Launched Node Explorer for '{}'", config.legalName)
|
||||
|
||||
executor.submit {
|
||||
val exitValue = p.waitFor()
|
||||
process = null
|
||||
|
@ -0,0 +1,40 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class WebServer(val webServerController: WebServerController) : AutoCloseable {
|
||||
private val log = LoggerFactory.getLogger(WebServer::class.java)
|
||||
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
private var process: Process? = null
|
||||
|
||||
fun open(config: NodeConfig, onExit: (NodeConfig) -> Unit) {
|
||||
val nodeDir = config.nodeDir.toFile()
|
||||
|
||||
if (!nodeDir.isDirectory) {
|
||||
log.warn("Working directory '{}' does not exist.", nodeDir.absolutePath)
|
||||
onExit(config)
|
||||
return
|
||||
}
|
||||
|
||||
val p = webServerController.execute(config.nodeDir)
|
||||
process = p
|
||||
|
||||
log.info("Launched Web Server for '{}'", config.legalName)
|
||||
|
||||
executor.submit {
|
||||
val exitValue = p.waitFor()
|
||||
process = null
|
||||
|
||||
log.info("Web Server for '{}' has exited (value={})", config.legalName, exitValue)
|
||||
onExit(config)
|
||||
}
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
executor.shutdown()
|
||||
process?.destroy()
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import tornadofx.Controller
|
||||
import java.nio.file.Path
|
||||
|
||||
class WebServerController : Controller() {
|
||||
|
||||
private val jvm by inject<JVMConfig>()
|
||||
private val cordaPath = jvm.applicationDir.resolve("corda").resolve("corda.jar")
|
||||
|
||||
init {
|
||||
log.info("Web Server JAR: $cordaPath")
|
||||
}
|
||||
|
||||
internal fun execute(cwd: Path) = jvm.execute(cordaPath, cwd, "--webserver")
|
||||
|
||||
fun webServer() = WebServer(this)
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ class NodeTerminalView : Fragment() {
|
||||
|
||||
private val nodeController by inject<NodeController>()
|
||||
private val explorerController by inject<ExplorerController>()
|
||||
private val webServerController by inject<WebServerController>()
|
||||
|
||||
private val nodeName by fxid<Label>()
|
||||
private val p2pPort by fxid<PropertyLabel>()
|
||||
@ -31,10 +32,12 @@ class NodeTerminalView : Fragment() {
|
||||
private val balance by fxid<PropertyLabel>()
|
||||
|
||||
private val viewDatabaseButton by fxid<Button>()
|
||||
private val launchWebButton by fxid<Button>()
|
||||
private val launchExplorerButton by fxid<Button>()
|
||||
|
||||
private var isClosed: Boolean = false
|
||||
private val explorer = explorerController.explorer()
|
||||
private val webServer = webServerController.webServer()
|
||||
private val viewer = DBViewer()
|
||||
private var rpc: NodeRPC? = null
|
||||
private var pty: R3Pty? = null
|
||||
@ -62,23 +65,9 @@ class NodeTerminalView : Fragment() {
|
||||
swingTerminal.content = r3pty.terminal
|
||||
nodeController.runCorda(r3pty, config)
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
configureDatabaseButton(config)
|
||||
configureExplorerButton(config)
|
||||
configureWebButton(config)
|
||||
|
||||
/*
|
||||
* Start RPC client that will update node statistics on UI.
|
||||
@ -93,6 +82,39 @@ class NodeTerminalView : Fragment() {
|
||||
|
||||
launchExplorerButton.isDisable = false
|
||||
viewDatabaseButton.isDisable = false
|
||||
launchWebButton.isDisable = false
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
fun configureExplorerButton(config: NodeConfig) {
|
||||
launchExplorerButton.setOnAction {
|
||||
launchExplorerButton.isDisable = true
|
||||
|
||||
explorer.open(config, onExit = {
|
||||
launchExplorerButton.isDisable = false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun configureDatabaseButton(config: NodeConfig) {
|
||||
viewDatabaseButton.setOnAction {
|
||||
viewer.openBrowser(config.h2Port)
|
||||
}
|
||||
}
|
||||
|
||||
fun configureWebButton(config: NodeConfig) {
|
||||
launchWebButton.setOnAction {
|
||||
launchWebButton.isDisable = true
|
||||
|
||||
webServer.open(config, onExit = {
|
||||
launchWebButton.isDisable = false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fun launchRPC(config: NodeConfig) = NodeRPC(config, start = { enable(config) }, invoke = { ops ->
|
||||
@ -116,6 +138,7 @@ class NodeTerminalView : Fragment() {
|
||||
|
||||
fun close() {
|
||||
if (!isClosed) {
|
||||
webServer.close()
|
||||
explorer.close()
|
||||
viewer.close()
|
||||
rpc?.close()
|
||||
|
@ -26,6 +26,7 @@
|
||||
</VBox>
|
||||
<Pane prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
|
||||
<Button fx:id="viewDatabaseButton" disable="true" mnemonicParsing="false" prefHeight="92.0" prefWidth="115.0" styleClass="big-button" text="View Database" textAlignment="CENTER" />
|
||||
<Button fx:id="launchWebButton" disable="true" mnemonicParsing="false" prefHeight="92.0" prefWidth="115.0" styleClass="big-button" text="Launch Web Server" textAlignment="CENTER" />
|
||||
<Button fx:id="launchExplorerButton" disable="true" mnemonicParsing="false" prefHeight="92.0" prefWidth="115.0" styleClass="big-button" text="Launch Explorer" textAlignment="CENTER" />
|
||||
</children>
|
||||
</HBox>
|
||||
|
Loading…
Reference in New Issue
Block a user