From a7ea8df9a7a21aad0e3cff561dd780e2442d30da Mon Sep 17 00:00:00 2001 From: Edoardo Ierina Date: Thu, 13 Aug 2020 15:19:16 +0200 Subject: [PATCH] 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 --- .../kotlin/net/corda/node/NodeCmdLineOptions.kt | 7 +++++++ .../kotlin/net/corda/node/internal/NodeStartup.kt | 1 + .../internal/subcommands/InitialRegistrationCli.kt | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt b/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt index 6f392da6da..d97b7118f2 100644 --- a/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt +++ b/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt @@ -174,6 +174,13 @@ open class NodeCmdLineOptions : SharedNodeCmdLineOptions() { ) 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 { return super.parseConfiguration(configuration).doIfValid { config -> if (isRegistration) { diff --git a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt index b17ffbc1bd..7400161c02 100644 --- a/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt +++ b/node/src/main/kotlin/net/corda/node/internal/NodeStartup.kt @@ -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." } initialRegistrationCli.networkRootTrustStorePassword = cmdLineOptions.networkRootTrustStorePassword!! initialRegistrationCli.networkRootTrustStorePathParameter = cmdLineOptions.networkRootTrustStorePathParameter + initialRegistrationCli.skipSchemaCreation = cmdLineOptions.skipSchemaCreation initialRegistrationCli.cmdLineOptions.copyFrom(cmdLineOptions) initialRegistrationCli.runProgram() } diff --git a/node/src/main/kotlin/net/corda/node/internal/subcommands/InitialRegistrationCli.kt b/node/src/main/kotlin/net/corda/node/internal/subcommands/InitialRegistrationCli.kt index 881de2c7df..9fb7df564a 100644 --- a/node/src/main/kotlin/net/corda/node/internal/subcommands/InitialRegistrationCli.kt +++ b/node/src/main/kotlin/net/corda/node/internal/subcommands/InitialRegistrationCli.kt @@ -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) 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 { 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) @@ -36,7 +39,8 @@ class InitialRegistrationCli(val startup: NodeStartup): CliWrapperBase("initial- 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 { 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. // 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("Corda node will now terminate.")