CORDA-3954: run database migration scripts during initial node registration (#6624)

* CORDA-3954: Added step to run database migration scripts during initial node registration with -s / --skip-schema-creation option (default to false) to prevent migration.

* CORDA-3954: Applied code convention to if statement

* CORDA-3954: Marked NodeCmdLineOptions' -s/--skip-schema-creation as deprecated and hidden in line with --initial-registration
This commit is contained in:
Edoardo Ierina 2020-08-13 15:19:16 +02:00 committed by GitHub
parent 294c2aa514
commit a7ea8df9a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -174,6 +174,13 @@ open class NodeCmdLineOptions : SharedNodeCmdLineOptions() {
) )
var networkRootTrustStorePassword: String? = null var networkRootTrustStorePassword: String? = null
@Option(
names = ["-s", "--skip-schema-creation"],
description = ["DEPRECATED. Prevent database migration scripts to run during initial node registration."],
hidden = true
)
var skipSchemaCreation: Boolean = false
override fun parseConfiguration(configuration: Config): Valid<NodeConfiguration> { override fun parseConfiguration(configuration: Config): Valid<NodeConfiguration> {
return super.parseConfiguration(configuration).doIfValid { config -> return super.parseConfiguration(configuration).doIfValid { config ->
if (isRegistration) { if (isRegistration) {

View File

@ -120,6 +120,7 @@ open class NodeStartupCli : CordaCliWrapper("corda", "Runs a Corda Node") {
requireNotNull(cmdLineOptions.networkRootTrustStorePassword) { "Network root trust store password must be provided in registration mode using --network-root-truststore-password." } requireNotNull(cmdLineOptions.networkRootTrustStorePassword) { "Network root trust store password must be provided in registration mode using --network-root-truststore-password." }
initialRegistrationCli.networkRootTrustStorePassword = cmdLineOptions.networkRootTrustStorePassword!! initialRegistrationCli.networkRootTrustStorePassword = cmdLineOptions.networkRootTrustStorePassword!!
initialRegistrationCli.networkRootTrustStorePathParameter = cmdLineOptions.networkRootTrustStorePathParameter initialRegistrationCli.networkRootTrustStorePathParameter = cmdLineOptions.networkRootTrustStorePathParameter
initialRegistrationCli.skipSchemaCreation = cmdLineOptions.skipSchemaCreation
initialRegistrationCli.cmdLineOptions.copyFrom(cmdLineOptions) initialRegistrationCli.cmdLineOptions.copyFrom(cmdLineOptions)
initialRegistrationCli.runProgram() initialRegistrationCli.runProgram()
} }

View File

@ -25,9 +25,12 @@ class InitialRegistrationCli(val startup: NodeStartup): CliWrapperBase("initial-
@Option(names = ["-p", "--network-root-truststore-password"], description = ["Network root trust store password obtained from network operator."], required = true) @Option(names = ["-p", "--network-root-truststore-password"], description = ["Network root trust store password obtained from network operator."], required = true)
var networkRootTrustStorePassword: String = "" var networkRootTrustStorePassword: String = ""
@Option(names = ["-s", "--skip-schema-creation"], description = ["Prevent database migration scripts to run during initial node registration "], required = false)
var skipSchemaCreation: Boolean = false
override fun runProgram() : Int { override fun runProgram() : Int {
val networkRootTrustStorePath: Path = networkRootTrustStorePathParameter ?: cmdLineOptions.baseDirectory / "certificates" / "network-root-truststore.jks" val networkRootTrustStorePath: Path = networkRootTrustStorePathParameter ?: cmdLineOptions.baseDirectory / "certificates" / "network-root-truststore.jks"
return startup.initialiseAndRun(cmdLineOptions, InitialRegistration(cmdLineOptions.baseDirectory, networkRootTrustStorePath, networkRootTrustStorePassword, startup)) return startup.initialiseAndRun(cmdLineOptions, InitialRegistration(cmdLineOptions.baseDirectory, networkRootTrustStorePath, networkRootTrustStorePassword, skipSchemaCreation, startup))
} }
override fun initLogging(): Boolean = this.initLogging(cmdLineOptions.baseDirectory) override fun initLogging(): Boolean = this.initLogging(cmdLineOptions.baseDirectory)
@ -36,7 +39,8 @@ class InitialRegistrationCli(val startup: NodeStartup): CliWrapperBase("initial-
val cmdLineOptions = InitialRegistrationCmdLineOptions() val cmdLineOptions = InitialRegistrationCmdLineOptions()
} }
class InitialRegistration(val baseDirectory: Path, private val networkRootTrustStorePath: Path, networkRootTrustStorePassword: String, private val startup: NodeStartup) : RunAfterNodeInitialisation, NodeStartupLogging { class InitialRegistration(val baseDirectory: Path, private val networkRootTrustStorePath: Path, networkRootTrustStorePassword: String,
private val skipSchemaMigration: Boolean, private val startup: NodeStartup) : RunAfterNodeInitialisation, NodeStartupLogging {
companion object { companion object {
private const val INITIAL_REGISTRATION_MARKER = ".initialregistration" private const val INITIAL_REGISTRATION_MARKER = ".initialregistration"
@ -76,7 +80,11 @@ class InitialRegistration(val baseDirectory: Path, private val networkRootTrustS
// Minimal changes to make registration tool create node identity. // Minimal changes to make registration tool create node identity.
// TODO: Move node identity generation logic from node to registration helper. // TODO: Move node identity generation logic from node to registration helper.
startup.createNode(conf, versionInfo).generateAndSaveNodeInfo() val node = startup.createNode(conf, versionInfo)
if(!skipSchemaMigration) {
node.runDatabaseMigrationScripts(updateCoreSchemas = true, updateAppSchemas = true, updateAppSchemasWithCheckpoints = false)
}
node.generateAndSaveNodeInfo()
println("Successfully registered Corda node with compatibility zone, node identity keys and certificates are stored in '${conf.certificatesDirectory}', it is advised to backup the private keys and certificates.") println("Successfully registered Corda node with compatibility zone, node identity keys and certificates are stored in '${conf.certificatesDirectory}', it is advised to backup the private keys and certificates.")
println("Corda node will now terminate.") println("Corda node will now terminate.")