mirror of
https://github.com/corda/corda.git
synced 2025-06-16 14:18:20 +00:00
CORDA-1621: The finance CorDapp uses the app config feature rather than the node's config (#4100)
This commit is contained in:
@ -69,12 +69,11 @@ class FlowCheckpointVersionNodeStartupCheckTest {
|
||||
// Create the CorDapp jar file manually first to get hold of the directory that will contain it so that we can
|
||||
// rename the filename later. The cordappDir, which acts as pointer to the jar file, does not get renamed.
|
||||
val cordappDir = TestCordappDirectories.getJarDirectory(cordapp)
|
||||
val cordappJar = cordappDir.list().single()
|
||||
val cordappJar = cordappDir.list().single { it.toString().endsWith(".jar") }
|
||||
|
||||
createSuspendedFlowInBob(setOf(cordapp))
|
||||
|
||||
// Rename the jar file. TestCordappDirectories caches the location of the jar file but the use of the random
|
||||
// UUID in the name means there's zero chance of contaminating another test.
|
||||
// Rename the jar file.
|
||||
cordappJar.moveTo(cordappDir / "renamed-${cordappJar.fileName}")
|
||||
|
||||
assertBobFailsToStartWithLogMessage(
|
||||
@ -88,13 +87,13 @@ class FlowCheckpointVersionNodeStartupCheckTest {
|
||||
fun `restart node with incompatible version of suspended flow due to different jar hash`() {
|
||||
driver(parametersForRestartingNodes()) {
|
||||
val originalCordapp = defaultCordapp.withName("different-jar-hash-test-${UUID.randomUUID()}")
|
||||
val originalCordappJar = TestCordappDirectories.getJarDirectory(originalCordapp).list().single()
|
||||
val originalCordappJar = TestCordappDirectories.getJarDirectory(originalCordapp).list().single { it.toString().endsWith(".jar") }
|
||||
|
||||
createSuspendedFlowInBob(setOf(originalCordapp))
|
||||
|
||||
// The vendor is part of the MANIFEST so changing it is sufficient to change the jar hash
|
||||
val modifiedCordapp = originalCordapp.withVendor("${originalCordapp.vendor}-modified")
|
||||
val modifiedCordappJar = TestCordappDirectories.getJarDirectory(modifiedCordapp).list().single()
|
||||
val modifiedCordappJar = TestCordappDirectories.getJarDirectory(modifiedCordapp).list().single { it.toString().endsWith(".jar") }
|
||||
modifiedCordappJar.moveTo(originalCordappJar, REPLACE_EXISTING)
|
||||
|
||||
assertBobFailsToStartWithLogMessage(
|
||||
|
@ -167,7 +167,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
val transactionStorage = makeTransactionStorage(configuration.transactionCacheSizeBytes).tokenize()
|
||||
val networkMapClient: NetworkMapClient? = configuration.networkServices?.let { NetworkMapClient(it.networkMapURL, versionInfo) }
|
||||
val attachments = NodeAttachmentService(metricRegistry, cacheFactory, database).tokenize()
|
||||
val cordappProvider = CordappProviderImpl(cordappLoader, CordappConfigFileProvider(), attachments).tokenize()
|
||||
val cordappProvider = CordappProviderImpl(cordappLoader, CordappConfigFileProvider(configuration.cordappDirectories), attachments).tokenize()
|
||||
@Suppress("LeakingThis")
|
||||
val keyManagementService = makeKeyManagementService(identityService).tokenize()
|
||||
val servicesForResolution = ServicesForResolutionImpl(identityService, attachments, cordappProvider, transactionStorage).also {
|
||||
|
@ -5,30 +5,26 @@ import com.typesafe.config.ConfigFactory
|
||||
import net.corda.core.internal.createDirectories
|
||||
import net.corda.core.internal.div
|
||||
import net.corda.core.internal.exists
|
||||
import net.corda.core.internal.isDirectory
|
||||
import net.corda.core.internal.noneOrSingle
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
class CordappConfigFileProvider(private val configDir: Path = DEFAULT_CORDAPP_CONFIG_DIR) : CordappConfigProvider {
|
||||
class CordappConfigFileProvider(cordappDirectories: List<Path>) : CordappConfigProvider {
|
||||
companion object {
|
||||
val DEFAULT_CORDAPP_CONFIG_DIR = Paths.get("cordapps") / "config"
|
||||
const val CONFIG_EXT = ".conf"
|
||||
val logger = contextLogger()
|
||||
private val logger = contextLogger()
|
||||
}
|
||||
|
||||
init {
|
||||
configDir.createDirectories()
|
||||
}
|
||||
private val configDirectories = cordappDirectories.map { (it / "config").createDirectories() }
|
||||
|
||||
override fun getConfigByName(name: String): Config {
|
||||
val configFile = configDir / "$name$CONFIG_EXT"
|
||||
return if (configFile.exists()) {
|
||||
check(!configFile.isDirectory()) { "${configFile.toAbsolutePath()} is a directory, expected a config file" }
|
||||
logger.info("Found config for cordapp $name in ${configFile.toAbsolutePath()}")
|
||||
// TODO There's nothing stopping the same CorDapp jar from occuring in different directories and thus causing
|
||||
// conflicts. The cordappDirectories list config option should just be a single cordappDirectory
|
||||
val configFile = configDirectories.map { it / "$name.conf" }.noneOrSingle { it.exists() }
|
||||
return if (configFile != null) {
|
||||
logger.info("Found config for cordapp $name in $configFile")
|
||||
ConfigFactory.parseFile(configFile.toFile())
|
||||
} else {
|
||||
logger.info("No config found for cordapp $name in ${configFile.toAbsolutePath()}")
|
||||
logger.info("No config found for cordapp $name in $configDirectories")
|
||||
ConfigFactory.empty()
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,16 @@ import java.nio.file.Paths
|
||||
|
||||
class CordappConfigFileProviderTests {
|
||||
private companion object {
|
||||
val cordappConfDir = Paths.get("build") / "tmp" / "cordapps" / "config"
|
||||
val cordappDir = Paths.get("build") / "tmp" / "cordapps"
|
||||
const val cordappName = "test"
|
||||
val cordappConfFile = cordappConfDir / "$cordappName.conf"
|
||||
val cordappConfFile = cordappDir / "config" / "$cordappName.conf"
|
||||
|
||||
val validConfig: Config = ConfigFactory.parseString("key=value")
|
||||
val alternateValidConfig: Config = ConfigFactory.parseString("key=alternateValue")
|
||||
const val invalidConfig = "Invalid"
|
||||
}
|
||||
|
||||
private val provider = CordappConfigFileProvider(cordappConfDir)
|
||||
private val provider = CordappConfigFileProvider(listOf(cordappDir))
|
||||
|
||||
@Test
|
||||
fun `test that config can be loaded`() {
|
||||
|
Reference in New Issue
Block a user