NOTICK fix demobench (#6455)

* Add schema migration step to node start-up
* Allow to set hibernate for app schema, including error pop-up when it goes bang.
This commit is contained in:
Christian Sailer 2020-07-13 10:12:57 +01:00 committed by GitHub
parent 057a8d8ae9
commit adeea5c0de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -1,11 +1,17 @@
package net.corda.demobench.model
import javafx.application.Application.Parameters
import javafx.application.Platform
import javafx.beans.binding.IntegerExpression
import javafx.beans.property.SimpleBooleanProperty
import javafx.scene.control.Alert
import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.Party
import net.corda.core.internal.*
import net.corda.core.internal.copyToDirectory
import net.corda.core.internal.createDirectories
import net.corda.core.internal.div
import net.corda.core.internal.noneOrSingle
import net.corda.core.internal.writeText
import net.corda.core.node.NetworkParameters
import net.corda.core.node.NotaryInfo
import net.corda.core.utilities.NetworkHostAndPort
@ -52,6 +58,7 @@ class NodeController(
}
val djvmEnabled = SimpleBooleanProperty(djvmEnabled)
val allowHibernateToManageAppSchema = SimpleBooleanProperty(false)
private val jvm by inject<JVMConfig>()
private val cordappController by inject<CordappController>()
@ -61,6 +68,8 @@ class NodeController(
private val cordaPath: Path = jvm.applicationDir.resolve("corda").resolve("corda.jar")
private val command = jvm.commandFor(cordaPath).toTypedArray()
private val schemaSetupArgs = arrayOf("run-migration-scripts", "--core-schemas", "--app-schemas")
private val nodes = LinkedHashMap<String, NodeConfigWrapper>()
private var notaryIdentity: Party? = null
private var networkParametersCopier: NetworkParametersCopier? = null
@ -155,6 +164,23 @@ class NodeController(
jvm.setCapsuleCacheDir(this)
}
(networkParametersCopier ?: makeNetworkParametersCopier(config)).install(config.nodeDir)
@Suppress("SpreadOperator")
val schemaSetupCommand = jvm.commandFor(cordaPath, *schemaSetupArgs).let {
if (allowHibernateToManageAppSchema.value) {
it + "--allow-hibernate-to-manage-app-schema"
} else {
it
}
}.toTypedArray()
if (pty.runSetupProcess(schemaSetupCommand, cordaEnv, config.nodeDir.toString()) != 0) {
Platform.runLater {
Alert(
Alert.AlertType.ERROR,
"Failed to set up database schema for node [${config.nodeConfig.myLegalName}]\n" +
"Please check logfiles!").showAndWait()
}
return false
}
pty.run(command, cordaEnv, config.nodeDir.toString())
log.info("Launched node: ${config.nodeConfig.myLegalName}")
return true

View File

@ -63,6 +63,11 @@ class R3Pty(val name: CordaX500Name, settings: SettingsProvider, dimension: Dime
terminal.createTerminalSession(connector).apply { start() }
}
fun runSetupProcess(args: Array<String>, envs: Map<String, String>, workingDir: String?): Int {
val process = PtyProcess.exec(args, envs, workingDir)
return process.waitFor()
}
@Suppress("unused")
@Throws(InterruptedException::class)
fun waitFor(): Int = terminal.ttyConnector?.waitFor() ?: -1

View File

@ -155,6 +155,9 @@ class NodeTabView : Fragment() {
checkbox("Deterministic Contract Verification", nodeController.djvmEnabled).apply {
styleClass += "djvm"
}
checkbox("Allow Hibernate to manage app schema", nodeController.allowHibernateToManageAppSchema).apply {
styleClass += "hibernate"
}
}
}
}