From 6e43bc1db6a2a2ffe0e02e4e69017aa978df47b1 Mon Sep 17 00:00:00 2001 From: Anthony Keenan Date: Thu, 24 Oct 2019 18:54:35 +0100 Subject: [PATCH] CORDA-3302: Align OS + Ent SchemaMigration parameters (#5622) * Rename SchemaMigrationTest and make ourName parameter nullable to remove enterprise conflicts * Fix detekt baseline * Further alignment * Update detekt --- detekt-baseline.xml | 6 +++--- .../nodeapi/internal/persistence/SchemaMigration.kt | 12 +++++++++--- .../MissingSchemaMigrationTest.kt} | 7 ++----- 3 files changed, 14 insertions(+), 11 deletions(-) rename node-api/src/test/kotlin/net/corda/nodeapi/internal/{SchemaMigrationTest.kt => persistence/MissingSchemaMigrationTest.kt} (91%) diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 082f908fce..000df1e61f 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -193,7 +193,7 @@ ComplexMethod:RemoteTypeCarpenter.kt$SchemaBuildingRemoteTypeCarpenter$override fun carpent(typeInformation: RemoteTypeInformation): Type ComplexMethod:RpcReconnectTests.kt$RpcReconnectTests$ @Test fun `test that the RPC client is able to reconnect and proceed after node failure, restart, or connection reset`() ComplexMethod:SchemaMigration.kt$SchemaMigration$ private fun migrateOlderDatabaseToUseLiquibase(existingCheckpoints: Boolean): Boolean - ComplexMethod:SchemaMigration.kt$SchemaMigration$private fun doRunMigration(run: Boolean, check: Boolean, existingCheckpoints: Boolean? = null) + ComplexMethod:SchemaMigration.kt$SchemaMigration$private fun doRunMigration( run: Boolean, check: Boolean, existingCheckpoints: Boolean? = null ) ComplexMethod:SendTransactionFlow.kt$DataVendingFlow$@Suspendable override fun call(): Void? ComplexMethod:ShellCmdLineOptions.kt$ShellCmdLineOptions$private fun toConfigFile(): Config ComplexMethod:ShellCmdLineOptions.kt$ShellConfigurationFile.ShellConfigFile$fun toShellConfiguration(): ShellConfiguration @@ -3219,7 +3219,7 @@ MaxLineLength:SchemaMigration.kt$MissingMigrationException.Companion$fun errorMessageFor(mappedSchema: MappedSchema): String MaxLineLength:SchemaMigration.kt$OutstandingDatabaseChangesException : DatabaseMigrationException MaxLineLength:SchemaMigration.kt$SchemaMigration$ private fun migrateOlderDatabaseToUseLiquibase(existingCheckpoints: Boolean): Boolean - MaxLineLength:SchemaMigration.kt$SchemaMigration$( val schemas: Set<MappedSchema>, val dataSource: DataSource, private val databaseConfig: DatabaseConfig, cordappLoader: CordappLoader? = null, private val currentDirectory: Path?, // This parameter is used by the vault state migration to establish what the node's legal identity is when setting up // its copy of the identity service. It is passed through using a system property. When multiple identity support is added, this will need // reworking so that multiple identities can be passed to the migration. private val ourName: CordaX500Name, // This parameter forces an error to be thrown if there are missing migrations. When using H2, Hibernate will automatically create schemas where they are // missing, so no need to throw unless you're specifically testing whether all the migrations are present. private val forceThrowOnMissingMigration: Boolean = false) + MaxLineLength:SchemaMigration.kt$SchemaMigration$( val schemas: Set<MappedSchema>, val dataSource: DataSource, private val databaseConfig: DatabaseConfig, cordappLoader: CordappLoader? = null, private val currentDirectory: Path?, // This parameter is used by the vault state migration to establish what the node's legal identity is when setting up // its copy of the identity service. It is passed through using a system property. When multiple identity support is added, this will need // reworking so that multiple identities can be passed to the migration. private val ourName: CordaX500Name? = null, // This parameter forces an error to be thrown if there are missing migrations. When using H2, Hibernate will automatically create schemas where they are // missing, so no need to throw unless you're specifically testing whether all the migrations are present. private val forceThrowOnMissingMigration: Boolean = false) MaxLineLength:SchemaMigration.kt$SchemaMigration$(mappedSchema::class.qualifiedName == "net.corda.finance.schemas.CashSchemaV1" || mappedSchema::class.qualifiedName == "net.corda.finance.schemas.CommercialPaperSchemaV1") && mappedSchema.migrationResource == null -> null MaxLineLength:SchemaMigration.kt$SchemaMigration$(run && !check) && (unRunChanges.isNotEmpty() && existingCheckpoints!!) -> throw CheckpointsException() MaxLineLength:SchemaMigration.kt$SchemaMigration$System.setProperty(NODE_BASE_DIR_KEY, path) @@ -3998,7 +3998,7 @@ ThrowsCount:PropertyDescriptor.kt$PropertyDescriptor$ fun validate() ThrowsCount:RPCApi.kt$RPCApi.ServerToClient.Companion$fun fromClientMessage(context: SerializationContext, message: ClientMessage): ServerToClient ThrowsCount:RPCServer.kt$RPCServer$private fun invokeRpc(context: RpcAuthContext, inMethodName: String, arguments: List<Any?>): Try<Any> - ThrowsCount:SchemaMigration.kt$SchemaMigration$private fun doRunMigration(run: Boolean, check: Boolean, existingCheckpoints: Boolean? = null) + ThrowsCount:SchemaMigration.kt$SchemaMigration$private fun doRunMigration( run: Boolean, check: Boolean, existingCheckpoints: Boolean? = null ) ThrowsCount:ServicesForResolutionImpl.kt$ServicesForResolutionImpl$// We may need to recursively chase transactions if there are notary changes. fun inner(stateRef: StateRef, forContractClassName: String?): Attachment ThrowsCount:SignedNodeInfo.kt$SignedNodeInfo$// TODO Add root cert param (or TrustAnchor) to make sure all the identities belong to the same root fun verified(): NodeInfo ThrowsCount:SignedTransaction.kt$SignedTransaction$// TODO: Verify contract constraints here as well as in LedgerTransaction to ensure that anything being deserialised // from the attachment is trusted. This will require some partial serialisation work to not load the ContractState // objects from the TransactionState. @DeleteForDJVM private fun verifyRegularTransaction(services: ServiceHub, checkSufficientSignatures: Boolean) diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/SchemaMigration.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/SchemaMigration.kt index 6ab3bceb19..84f028aea8 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/SchemaMigration.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/SchemaMigration.kt @@ -31,7 +31,7 @@ class SchemaMigration( // This parameter is used by the vault state migration to establish what the node's legal identity is when setting up // its copy of the identity service. It is passed through using a system property. When multiple identity support is added, this will need // reworking so that multiple identities can be passed to the migration. - private val ourName: CordaX500Name, + private val ourName: CordaX500Name? = null, // This parameter forces an error to be thrown if there are missing migrations. When using H2, Hibernate will automatically create schemas where they are // missing, so no need to throw unless you're specifically testing whether all the migrations are present. private val forceThrowOnMissingMigration: Boolean = false) { @@ -99,7 +99,11 @@ class SchemaMigration( null } - private fun doRunMigration(run: Boolean, check: Boolean, existingCheckpoints: Boolean? = null) { + private fun doRunMigration( + run: Boolean, + check: Boolean, + existingCheckpoints: Boolean? = null + ) { // Virtual file name of the changelog that includes all schemas. val dynamicInclude = "master.changelog.json" @@ -121,7 +125,9 @@ class SchemaMigration( if (path != null) { System.setProperty(NODE_BASE_DIR_KEY, path) // base dir for any custom change set which may need to load a file (currently AttachmentVersionNumberMigration) } - System.setProperty(NODE_X500_NAME, ourName.toString()) + if (ourName != null) { + System.setProperty(NODE_X500_NAME, ourName.toString()) + } val customResourceAccessor = CustomResourceAccessor(dynamicInclude, changelogList, classLoader) checkResourcesInClassPath(changelogList) diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/SchemaMigrationTest.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/persistence/MissingSchemaMigrationTest.kt similarity index 91% rename from node-api/src/test/kotlin/net/corda/nodeapi/internal/SchemaMigrationTest.kt rename to node-api/src/test/kotlin/net/corda/nodeapi/internal/persistence/MissingSchemaMigrationTest.kt index 1864cf5e22..0bd0b4dbb4 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/SchemaMigrationTest.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/persistence/MissingSchemaMigrationTest.kt @@ -1,13 +1,10 @@ -package net.corda.nodeapi.internal +package net.corda.nodeapi.internal.persistence import net.corda.core.schemas.MappedSchema import net.corda.core.schemas.PersistentState import net.corda.node.internal.DataSourceFactory import net.corda.node.services.persistence.DBCheckpointStorage import net.corda.node.services.schema.NodeSchemaService -import net.corda.nodeapi.internal.persistence.DatabaseConfig -import net.corda.nodeapi.internal.persistence.MissingMigrationException -import net.corda.nodeapi.internal.persistence.SchemaMigration import net.corda.testing.core.ALICE_NAME import net.corda.testing.core.TestIdentity import net.corda.testing.node.MockServices @@ -20,7 +17,7 @@ import javax.persistence.Column import javax.persistence.Entity import javax.sql.DataSource -class SchemaMigrationTest { +class MissingSchemaMigrationTest { object TestSchemaFamily object GoodSchema : MappedSchema(schemaFamily = TestSchemaFamily.javaClass, version = 1, mappedTypes = listOf(State::class.java)) {