CORDA-1131 - Fix webserver startup when headless

This commit is contained in:
Andrzej Cichocki 2018-03-02 12:35:46 +00:00 committed by Katelyn Baker
parent ab4cb7abda
commit ba925c0277
2 changed files with 12 additions and 9 deletions

View File

@ -1,4 +1,4 @@
gradlePluginsVersion=3.0.8
gradlePluginsVersion=3.0.9
kotlinVersion=1.1.60
platformVersion=3
guavaVersion=21.0

View File

@ -44,7 +44,7 @@ fun main(args: Array<String>) {
println("Finished starting nodes")
}
private abstract class JarType(private val jarName: String) {
private abstract class JarType(internal val jarName: String) {
internal abstract fun acceptNodeConf(nodeConf: File): Boolean
internal fun acceptDirAndStartProcess(dir: File, headless: Boolean, javaArgs: List<String>, jvmArgs: List<String>): Process? {
if (!File(dir, jarName).exists()) {
@ -56,19 +56,23 @@ private abstract class JarType(private val jarName: String) {
val debugPort = debugPortAlloc.next()
val monitoringPort = monitoringPortAlloc.next()
println("Starting $jarName in $dir on debug port $debugPort")
val process = (if (headless) ::HeadlessJavaCommand else ::TerminalWindowJavaCommand)(jarName, dir, debugPort, monitoringPort, javaArgs, jvmArgs).start()
val process = (if (headless) ::HeadlessJavaCommand else ::TerminalWindowJavaCommand)(this, dir, debugPort, monitoringPort, javaArgs, jvmArgs).start()
if (os == OS.MACOS) Thread.sleep(1000)
return process
}
internal abstract val headlessArgs: List<String>
}
private object NodeJarType : JarType("corda.jar") {
override fun acceptNodeConf(nodeConf: File) = true
override val headlessArgs = listOf("--no-local-shell")
}
private object WebJarType : JarType("corda-webserver.jar") {
// TODO: Add a webserver.conf, or use TypeSafe config instead of this hack
override fun acceptNodeConf(nodeConf: File) = Files.lines(nodeConf.toPath()).anyMatch { "webAddress" in it }
override val headlessArgs = emptyList<String>()
}
private abstract class JavaCommand(
@ -77,7 +81,7 @@ private abstract class JavaCommand(
debugPort: Int?,
monitoringPort: Int?,
internal val nodeName: String,
init: MutableList<String>.() -> Unit, args: List<String>,
args: List<String>,
jvmArgs: List<String>
) {
private val jolokiaJar by lazy {
@ -98,7 +102,6 @@ private abstract class JavaCommand(
}
add("-jar")
add(jarName)
init()
addAll(args)
}
@ -107,14 +110,14 @@ private abstract class JavaCommand(
internal abstract fun getJavaPath(): String
}
private class HeadlessJavaCommand(jarName: String, dir: File, debugPort: Int?, monitoringPort: Int?, args: List<String>, jvmArgs: List<String>)
: JavaCommand(jarName, dir, debugPort, monitoringPort, dir.name, { add("--no-local-shell") }, args, jvmArgs) {
private class HeadlessJavaCommand(jarType: JarType, dir: File, debugPort: Int?, monitoringPort: Int?, args: List<String>, jvmArgs: List<String>)
: JavaCommand(jarType.jarName, dir, debugPort, monitoringPort, dir.name, jarType.headlessArgs + args, jvmArgs) {
override fun processBuilder() = ProcessBuilder(command).redirectError(File("error.$nodeName.log")).inheritIO()
override fun getJavaPath() = File(File(System.getProperty("java.home"), "bin"), "java").path
}
private class TerminalWindowJavaCommand(jarName: String, dir: File, debugPort: Int?, monitoringPort: Int?, args: List<String>, jvmArgs: List<String>)
: JavaCommand(jarName, dir, debugPort, monitoringPort, "${dir.name}-$jarName", {}, args, jvmArgs) {
private class TerminalWindowJavaCommand(jarType: JarType, dir: File, debugPort: Int?, monitoringPort: Int?, args: List<String>, jvmArgs: List<String>)
: JavaCommand(jarType.jarName, dir, debugPort, monitoringPort, "${dir.name}-${jarType.jarName}", args, jvmArgs) {
override fun processBuilder() = ProcessBuilder(when (os) {
OS.MACOS -> {
listOf("osascript", "-e", """tell app "Terminal"