Ensure that Node Explorer can write into its working directory.

This commit is contained in:
Chris Rankin 2017-02-07 20:18:56 +00:00
parent 006fd98a51
commit 37aa486bd7
4 changed files with 15 additions and 4 deletions

View File

@ -10,7 +10,16 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable {
private var process: Process? = null
fun open(config: NodeConfig, onExit: (NodeConfig) -> Unit) {
val explorerDir = config.explorerDir.toFile()
if (!explorerDir.mkdirs()) {
log.warn("Failed to create working directory '{}'", explorerDir.getAbsolutePath())
onExit(config)
return
}
val p = explorerController.execute(
config.explorerDir,
"--host=localhost",
"--port=${config.artemisPort}",
"--username=${config.user["user"]}",
@ -35,4 +44,4 @@ class Explorer(val explorerController: ExplorerController) : AutoCloseable {
process?.destroy()
}
}
}

View File

@ -1,6 +1,7 @@
package net.corda.demobench.model
import tornadofx.Controller
import java.nio.file.Path
import java.nio.file.Paths
class ExplorerController : Controller() {
@ -12,7 +13,7 @@ class ExplorerController : Controller() {
log.info("Explorer JAR: " + explorerPath)
}
internal fun execute(vararg args: String) = jvm.execute(explorerPath, *args)
internal fun execute(cwd: Path, vararg args: String) = jvm.execute(explorerPath, cwd, *args)
fun explorer() = Explorer(this)

View File

@ -18,8 +18,8 @@ class JVMConfig : Controller() {
return arrayOf(javaPath.toString(), "-jar", jarPath.toString(), *args)
}
fun execute(jarPath: Path, vararg args: String): Process {
return Runtime.getRuntime().exec(commandFor(jarPath, *args))
fun execute(jarPath: Path, cwd: Path, vararg args: String): Process {
return Runtime.getRuntime().exec(commandFor(jarPath, *args), null, cwd.toFile())
}
}

View File

@ -19,6 +19,7 @@ class NodeConfig(
) : NetworkMapConfig(legalName, artemisPort) {
val nodeDir: Path = baseDir.resolve(key)
val explorerDir: Path = baseDir.resolve("$key-explorer")
val user: Map<String, Any> = mapOf(
"user" to "guest",