[CORDA-2636] Ensure states created with contract upgrades can be migrated (#4786)

* Ensure states created with contract upgrades can be migrated

* Remove line from api-current.txt representing an uncallable constructor
This commit is contained in:
JamesHR3
2019-02-19 09:48:39 +00:00
committed by Tommy Lillehagen
parent 21d32681ff
commit efabab35c4
13 changed files with 40 additions and 22 deletions

View File

@ -0,0 +1,33 @@
package net.corda.nodeapi.internal.cordapp
import net.corda.core.cordapp.Cordapp
import net.corda.core.flows.FlowLogic
import net.corda.core.internal.cordapp.CordappImpl
import net.corda.core.schemas.MappedSchema
/**
* Handles loading [Cordapp]s.
*/
interface CordappLoader : AutoCloseable {
/**
* Returns all [Cordapp]s found.
*/
val cordapps: List<CordappImpl>
/**
* Returns a [ClassLoader] containing all types from all [Cordapp]s.
*/
val appClassLoader: ClassLoader
/**
* Returns a map between flow class and owning [Cordapp].
* The mappings are unique, and the node will not start otherwise.
*/
val flowCordappMap: Map<Class<out FlowLogic<*>>, Cordapp>
/**
* Returns all [MappedSchema] found inside the [Cordapp]s.
*/
val cordappSchemas: Set<MappedSchema>
}

View File

@ -12,6 +12,7 @@ import net.corda.core.identity.CordaX500Name
import net.corda.nodeapi.internal.MigrationHelpers.getMigrationResource
import net.corda.core.schemas.MappedSchema
import net.corda.core.utilities.contextLogger
import net.corda.nodeapi.internal.cordapp.CordappLoader
import sun.security.x509.X500Name
import java.io.ByteArrayInputStream
import java.io.InputStream
@ -28,7 +29,7 @@ class SchemaMigration(
val schemas: Set<MappedSchema>,
val dataSource: DataSource,
private val databaseConfig: DatabaseConfig,
private val classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
cordappLoader: CordappLoader? = null,
private val currentDirectory: Path?,
private val ourName: CordaX500Name) {
@ -36,8 +37,15 @@ class SchemaMigration(
private val logger = contextLogger()
const val NODE_BASE_DIR_KEY = "liquibase.nodeDaseDir"
const val NODE_X500_NAME = "liquibase.nodeName"
val loader = ThreadLocal<CordappLoader>()
}
init {
loader.set(cordappLoader)
}
private val classLoader = cordappLoader?.appClassLoader ?: Thread.currentThread().contextClassLoader
/**
* Main entry point to the schema migration.
* Called during node startup.

View File

@ -16,7 +16,7 @@ import net.corda.core.serialization.deserialize
import net.corda.core.serialization.serialize
import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.TransactionBuilder
import net.corda.node.cordapp.CordappLoader
import net.corda.nodeapi.internal.cordapp.CordappLoader
import net.corda.node.internal.cordapp.CordappProviderImpl
import net.corda.node.internal.cordapp.JarScanningCordappLoader
import net.corda.nodeapi.internal.AttachmentsClassLoaderStaticContractTests.AttachmentDummyContract.Companion.ATTACHMENT_PROGRAM_ID