diff --git a/build.gradle b/build.gradle index 1cd1c535cb..686c7d3cff 100644 --- a/build.gradle +++ b/build.gradle @@ -139,7 +139,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { networkMap "Controller" node { name "Controller" - dirName "controller" nearestCity "London" advertisedServices = ["corda.notary.validating"] artemisPort 10002 @@ -148,7 +147,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank A" - dirName "nodea" nearestCity "London" advertisedServices = [] artemisPort 10004 @@ -157,7 +155,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank B" - dirName "nodeb" nearestCity "New York" advertisedServices = [] artemisPort 10006 diff --git a/config/dev/generalnodea.conf b/config/dev/generalnodea.conf index 009edc95cd..b55b3e1a9b 100644 --- a/config/dev/generalnodea.conf +++ b/config/dev/generalnodea.conf @@ -1,4 +1,3 @@ -basedir : "./nodea" myLegalName : "Bank A" nearestCity : "London" keyStorePassword : "cordacadevpass" diff --git a/config/dev/generalnodeb.conf b/config/dev/generalnodeb.conf index c8462cc2e8..20e773388b 100644 --- a/config/dev/generalnodeb.conf +++ b/config/dev/generalnodeb.conf @@ -1,4 +1,3 @@ -basedir : "./nodeb" myLegalName : "Bank B" nearestCity : "London" keyStorePassword : "cordacadevpass" diff --git a/config/dev/nameservernode.conf b/config/dev/nameservernode.conf index 7a91eda14f..51dd1df842 100644 --- a/config/dev/nameservernode.conf +++ b/config/dev/nameservernode.conf @@ -1,4 +1,3 @@ -basedir : "./nameserver" myLegalName : "Notary Service" nearestCity : "London" keyStorePassword : "cordacadevpass" diff --git a/docs/source/corda-configuration-file.rst b/docs/source/corda-configuration-file.rst index 66d8fc90f5..680ceb2023 100644 --- a/docs/source/corda-configuration-file.rst +++ b/docs/source/corda-configuration-file.rst @@ -4,13 +4,16 @@ Node configuration File location ------------- -The Corda all-in-one ``corda.jar`` file is generated by the ``gradle buildCordaJAR`` task and defaults to reading configuration from a ``node.conf`` file in the present working directory. -This behaviour can be overidden using the ``--config-file`` command line option to target configuration files with different names, or different file location (relative paths are relative to the current working directory). -Also, the ``--base-directory`` command line option alters the Corda node workspace location and if specified a ``node.conf`` configuration file is then expected in the root of the workspace. +The Corda all-in-one ``corda.jar`` file is generated by the ``gradle buildCordaJAR`` task and defaults to reading configuration +from a ``node.conf`` file in the present working directory. This behaviour can be overidden using the ``--config-file`` +command line option to target configuration files with different names, or different file location (relative paths are +relative to the current working directory). Also, the ``--base-directory`` command line option alters the Corda node +workspace location and if specified a ``node.conf`` configuration file is then expected in the root of the workspace. -The configuration file templates used for the ``gradle deployNodes`` task are to be found in the ``/config/dev`` folder. Also note that there is a basic set of defaults loaded from -the built in resource file ``/node/src/main/resources/reference.conf`` of the ``:node`` gradle module. All properties in this can be overidden in the file configuration -and for rarely changed properties this defaulting allows the property to be excluded from the configuration file. +The configuration file templates used for the ``gradle deployNodes`` task are to be found in the ``/config/dev`` folder. +Also note that there is a basic set of defaults loaded from the built in resource file ``/node/src/main/resources/reference.conf`` +of the ``:node`` gradle module. All properties in this can be overidden in the file configuration and for rarely changed +properties this defaulting allows the property to be excluded from the configuration file. Format ------ @@ -31,7 +34,6 @@ NetworkMapService plus Simple Notary configuration file. .. parsed-literal:: - basedir : "./nameserver" myLegalName : "Notary Service" nearestCity : "London" keyStorePassword : "cordacadevpass" @@ -47,9 +49,8 @@ NetworkMapService plus Simple Notary configuration file. Fields ------ -:basedir: This specifies the node workspace folder either as an absolute path, or relative to the current working directory. - It can be overridden by the ``--base-directory`` command line option, in which case the value in the file is ignored - and a ``node.conf`` file is expected in that workspace directory as the configuration source. +The available config fields are listed below. ``basedir`` is available as a substitution value, containing the absolute +path to the node's base directory. :myLegalName: The legal identity of the node acts as a human readable alias to the node's public key and several demos use this to lookup the NodeInfo. @@ -98,8 +99,8 @@ Fields joining them to the same cluster to replicate the committed state log. Note that the Raft cluster uses a separate transport layer for communication that does not integrate with ArtemisMQ messaging services. -:notaryClusterAddresses: List of Raft cluster member addresses used to join the cluster. At least one of the specified - members must be active and be able to communicate with the cluster leader for joining. If empty, a new cluster will be +:notaryClusterAddresses: List of Raft cluster member addresses used to join the cluster. At least one of the specified + members must be active and be able to communicate with the cluster leader for joining. If empty, a new cluster will be bootstrapped. Required only when running a distributed notary service. :networkMapService: If `null`, or missing the node is declaring itself as the NetworkMapService host. Otherwise this is diff --git a/docs/source/creating-a-cordapp.rst b/docs/source/creating-a-cordapp.rst index 64faa226c1..2cea88d0d2 100644 --- a/docs/source/creating-a-cordapp.rst +++ b/docs/source/creating-a-cordapp.rst @@ -36,9 +36,8 @@ This will output the node JAR to ``build/libs/corda.jar`` and several sample/sta node setups to ``build/nodes``. For now you can use the ``build/nodes/nodea`` configuration as a template. Each node server by default must have a ``node.conf`` file in the current working directory. After first -execution of the node server there will be many other configuration and persistence files created in a node -workspace directory. This is specified as the basedir property of the node.conf file, or else can be overidden -using ``--base-directory=``. +execution of the node server there will be many other configuration and persistence files created in this +workspace directory. The directory can be overridden by the ``--base-directory=`` command line argument. .. note:: Outside of development environments do not store your node directories in the build folder. @@ -69,7 +68,7 @@ The configuration file and workspace paths can be overidden on the command line ``java -jar corda.jar --config-file=test.conf --base-directory=/opt/r3corda/nodes/test``. -Otherwise the workspace folder for the node is created based upon the ``basedir`` property in the ``node.conf`` file and if this is relative it is applied relative to the current working path. +Otherwise the workspace folder for the node is the current working path. Debugging your node ------------------- @@ -212,7 +211,6 @@ is a three node example; networkMap "Controller" // The artemis address of the node named here will be used as the networkMapService.address on all other nodes. node { name "Controller" - dirName "controller" nearestCity "London" advertisedServices = [ "corda.notary.validating" ] artemisPort 12345 @@ -221,7 +219,6 @@ is a three node example; } node { name "NodeA" - dirName "nodea" nearestCity "London" advertisedServices = [] artemisPort 31337 @@ -230,7 +227,6 @@ is a three node example; } node { name "NodeB" - dirName "nodeb" nearestCity "New York" advertisedServices = [] artemisPort 31338 diff --git a/docs/source/example-code/build.gradle b/docs/source/example-code/build.gradle index a650f2fa40..7b0b7fe1cc 100644 --- a/docs/source/example-code/build.gradle +++ b/docs/source/example-code/build.gradle @@ -77,7 +77,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { networkMap "Notary" node { name "Notary" - dirName "notary" nearestCity "London" advertisedServices = ["corda.notary.validating"] artemisPort 10002 @@ -86,7 +85,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Alice" - dirName "alice" nearestCity "London" advertisedServices = [] artemisPort 10004 diff --git a/docs/source/example-code/src/main/resources/example-network-map-node.conf b/docs/source/example-code/src/main/resources/example-network-map-node.conf index 6a5c944631..58c80504f2 100644 --- a/docs/source/example-code/src/main/resources/example-network-map-node.conf +++ b/docs/source/example-code/src/main/resources/example-network-map-node.conf @@ -1,4 +1,3 @@ -basedir : "./nameserver" myLegalName : "Notary Service" nearestCity : "London" keyStorePassword : "cordacadevpass" diff --git a/docs/source/example-code/src/main/resources/example-node.conf b/docs/source/example-code/src/main/resources/example-node.conf index 6c2f68cbd1..9f80b968d8 100644 --- a/docs/source/example-code/src/main/resources/example-node.conf +++ b/docs/source/example-code/src/main/resources/example-node.conf @@ -1,11 +1,10 @@ -basedir : "./nodea" myLegalName : "Bank A" nearestCity : "London" keyStorePassword : "cordacadevpass" trustStorePassword : "trustpass" dataSourceProperties : { dataSourceClassName : org.h2.jdbcx.JdbcDataSource - "dataSource.url" : "jdbc:h2:"${basedir}"/persistence" + "dataSource.url" : "jdbc:h2:file:"${basedir}"/persistence" "dataSource.user" : sa "dataSource.password" : "" } diff --git a/docs/source/example-code/src/test/kotlin/net/corda/docs/ExampleNodeConfTest.kt b/docs/source/example-code/src/test/kotlin/net/corda/docs/ExampleNodeConfTest.kt index 7a898d17b1..615e4a25c9 100644 --- a/docs/source/example-code/src/test/kotlin/net/corda/docs/ExampleNodeConfTest.kt +++ b/docs/source/example-code/src/test/kotlin/net/corda/docs/ExampleNodeConfTest.kt @@ -17,9 +17,11 @@ class ExampleNodeConfTest { exampleNodeConfFilenames.forEach { println("Checking $it") val configResource = ExampleNodeConfTest::class.java.classLoader.getResource(it) + val baseDirectory = Paths.get("some-example-base-dir") val nodeConfig = FullNodeConfiguration( + baseDirectory, ConfigHelper.loadConfig( - baseDirectoryPath = Paths.get("some-example-base-dir"), + baseDirectory = baseDirectory, configFileOverride = Paths.get(configResource.toURI()) ) ) diff --git a/docs/source/tutorial-cordapp.rst b/docs/source/tutorial-cordapp.rst index 2de98710a0..3384a9a8b4 100644 --- a/docs/source/tutorial-cordapp.rst +++ b/docs/source/tutorial-cordapp.rst @@ -804,7 +804,6 @@ like to deploy for testing. See further details below: networkMap "Controller" // The artemis address of the node to be used as the network map. node { name "Controller" // Artemis name of node to be deployed. - dirName "controller" // Directory to which the node will nearestCity "London" // For use with the network visualiser. advertisedServices = ["corda.notary.validating"] // A list of services you wish the node to offer. artemisPort 10002 @@ -813,7 +812,6 @@ like to deploy for testing. See further details below: } node { // Create an additional node. name "NodeA" - dirName "nodea" nearestCity "London" advertisedServices = [] artemisPort 10004 diff --git a/gradle-plugins/cordformation/src/main/groovy/net/corda/plugins/Node.groovy b/gradle-plugins/cordformation/src/main/groovy/net/corda/plugins/Node.groovy index e50cdc02ff..cdce17fc6c 100644 --- a/gradle-plugins/cordformation/src/main/groovy/net/corda/plugins/Node.groovy +++ b/gradle-plugins/cordformation/src/main/groovy/net/corda/plugins/Node.groovy @@ -42,7 +42,6 @@ class Node { */ protected List> rpcUsers = [] - private String dirName private Config config = ConfigFactory.empty() private File nodeDir private Project project @@ -57,16 +56,6 @@ class Node { config = config.withValue("myLegalName", ConfigValueFactory.fromAnyRef(name)) } - /** - * Set the directory the node will be installed to relative to the directory specified in Cordform task. - * - * @param dirName Subdirectory name for node to be installed to. Must be valid directory name on all OSes. - */ - void dirName(String dirName) { - this.dirName = dirName - config = config.withValue("basedir", ConfigValueFactory.fromAnyRef(dirName)) - } - /** * Set the nearest city to the node. * @@ -136,13 +125,8 @@ class Node { this.project = project } - /** - * Install the nodes to the given base directory. - * - * @param baseDir The base directory for this node. All other paths are relative to it + this nodes dir name. - */ - void build(File baseDir) { - nodeDir = new File(baseDir, dirName) + void build(File rootDir) { + nodeDir = new File(rootDir, name.replaceAll("\\s","")) configureRpcUsers() installCordaJAR() installBuiltPlugin() diff --git a/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt b/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt index e0733f0b7c..7bc3da78ea 100644 --- a/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt +++ b/node/src/integration-test/kotlin/net/corda/services/messaging/P2PSecurityTest.kt @@ -52,7 +52,7 @@ class P2PSecurityTest : NodeBasedTest() { private fun startSimpleNode(legalName: String): SimpleNode { val config = TestNodeConfiguration( - basedir = tempFolder.root.toPath() / legalName, + baseDirectory = tempFolder.root.toPath() / legalName, myLegalName = legalName, networkMapService = NetworkMapInfo(networkMapNode.configuration.artemisAddress, networkMapNode.info.legalIdentity.name)) config.configureWithDevSSLCertificate() // This creates the node's TLS cert with the CN as the legal name diff --git a/node/src/main/kotlin/net/corda/node/ArgsParser.kt b/node/src/main/kotlin/net/corda/node/ArgsParser.kt new file mode 100644 index 0000000000..4716bbcc2c --- /dev/null +++ b/node/src/main/kotlin/net/corda/node/ArgsParser.kt @@ -0,0 +1,43 @@ +package net.corda.node + +import com.typesafe.config.Config +import joptsimple.OptionParser +import net.corda.core.div +import net.corda.node.services.config.ConfigHelper +import java.io.PrintStream +import java.nio.file.Path +import java.nio.file.Paths + +class ArgsParser { + private val optionParser = OptionParser() + // The intent of allowing a command line configurable directory and config path is to allow deployment flexibility. + // Other general configuration should live inside the config file unless we regularly need temporary overrides on the command line + private val baseDirectoryArg = optionParser + .accepts("base-directory", "The node working directory where all the files are kept") + .withRequiredArg() + .defaultsTo(".") + private val configFileArg = optionParser + .accepts("config-file", "The path to the config file") + .withRequiredArg() + .defaultsTo("node.conf") + private val logToConsoleArg = optionParser.accepts("log-to-console", "If set, prints logging to the console as well as to a file.") + private val helpArg = optionParser.accepts("help").forHelp() + + fun parse(vararg args: String): CmdLineOptions { + val optionSet = optionParser.parse(*args) + require(!optionSet.has(baseDirectoryArg) || !optionSet.has(configFileArg)) { + "${baseDirectoryArg.options()[0]} and ${configFileArg.options()[0]} cannot be specified together" + } + val baseDirectory = Paths.get(optionSet.valueOf(baseDirectoryArg)).normalize().toAbsolutePath() + val configFile = baseDirectory / optionSet.valueOf(configFileArg) + return CmdLineOptions(baseDirectory, configFile, optionSet.has(helpArg), optionSet.has(logToConsoleArg)) + } + + fun printHelp(sink: PrintStream) = optionParser.printHelpOn(sink) +} + +data class CmdLineOptions(val baseDirectory: Path, val configFile: Path?, val help: Boolean, val logToConsole: Boolean) { + fun loadConfig(allowMissingConfig: Boolean = false, configOverrides: Map = emptyMap()): Config { + return ConfigHelper.loadConfig(baseDirectory, configFile, allowMissingConfig, configOverrides) + } +} \ No newline at end of file diff --git a/node/src/main/kotlin/net/corda/node/Main.kt b/node/src/main/kotlin/net/corda/node/Main.kt index 9c7b5a169f..fb2486b4c3 100644 --- a/node/src/main/kotlin/net/corda/node/Main.kt +++ b/node/src/main/kotlin/net/corda/node/Main.kt @@ -1,11 +1,9 @@ package net.corda.node import com.typesafe.config.ConfigException -import joptsimple.OptionParser import net.corda.core.* import net.corda.core.utilities.Emoji import net.corda.node.internal.Node -import net.corda.node.services.config.ConfigHelper import net.corda.node.services.config.FullNodeConfiguration import net.corda.node.utilities.ANSIProgressObserver import org.fusesource.jansi.Ansi @@ -14,7 +12,6 @@ import org.slf4j.LoggerFactory import java.lang.management.ManagementFactory import java.net.InetAddress import java.nio.file.Paths -import java.time.LocalDate import kotlin.system.exitProcess private var renderBasicInfoToConsole = true @@ -31,33 +28,26 @@ fun printBasicNodeInfo(description: String, info: String? = null) { } fun main(args: Array) { + val startTime = System.currentTimeMillis() checkJavaVersion() - val startTime = System.currentTimeMillis() - - val parser = OptionParser() - // The intent of allowing a command line configurable directory and config path is to allow deployment flexibility. - // Other general configuration should live inside the config file unless we regularly need temporary overrides on the command line - val baseDirectoryArg = parser.accepts("base-directory", "The directory to put all files under").withOptionalArg() - val configFileArg = parser.accepts("config-file", "The path to the config file").withOptionalArg() - val logToConsoleArg = parser.accepts("log-to-console", "If set, prints logging to the console as well as to a file.") - val helpArg = parser.accepts("help").forHelp() + val argsParser = ArgsParser() val cmdlineOptions = try { - parser.parse(*args) + argsParser.parse(*args) } catch (ex: Exception) { println("Unknown command line arguments: ${ex.message}") exitProcess(1) } // Maybe render command line help. - if (cmdlineOptions.has(helpArg)) { - parser.printHelpOn(System.out) + if (cmdlineOptions.help) { + argsParser.printHelp(System.out) exitProcess(0) } // Set up logging. - if (cmdlineOptions.has(logToConsoleArg)) { + if (cmdlineOptions.logToConsole) { // This property is referenced from the XML config file. System.setProperty("consoleLogLevel", "info") renderBasicInfoToConsole = false @@ -65,19 +55,17 @@ fun main(args: Array) { drawBanner() - val baseDirectoryPath = if (cmdlineOptions.has(baseDirectoryArg)) Paths.get(cmdlineOptions.valueOf(baseDirectoryArg)) else Paths.get(".").normalize() - System.setProperty("log-path", (baseDirectoryPath / "logs").toAbsolutePath().toString()) + System.setProperty("log-path", (cmdlineOptions.baseDirectory / "logs").toString()) val log = LoggerFactory.getLogger("Main") printBasicNodeInfo("Logs can be found in", System.getProperty("log-path")) - val configFile = if (cmdlineOptions.has(configFileArg)) Paths.get(cmdlineOptions.valueOf(configFileArg)) else null + val conf = try { - FullNodeConfiguration(ConfigHelper.loadConfig(baseDirectoryPath, configFile)) + FullNodeConfiguration(cmdlineOptions.baseDirectory, cmdlineOptions.loadConfig()) } catch (e: ConfigException) { println("Unable to load the configuration file: ${e.rootCause.message}") exitProcess(2) } - val dir = conf.basedir.toAbsolutePath().normalize() log.info("Main class: ${FullNodeConfiguration::class.java.protectionDomain.codeSource.location.toURI().path}") val info = ManagementFactory.getRuntimeMXBean() @@ -87,13 +75,12 @@ fun main(args: Array) { log.info("classpath: ${info.classPath}") log.info("VM ${info.vmName} ${info.vmVendor} ${info.vmVersion}") log.info("Machine: ${InetAddress.getLocalHost().hostName}") - log.info("Working Directory: $dir") + log.info("Working Directory: ${cmdlineOptions.baseDirectory}") try { - dir.createDirectories() + cmdlineOptions.baseDirectory.createDirectories() val node = conf.createNode() - node.start() printPluginsAndServices(node) @@ -121,8 +108,8 @@ private fun checkJavaVersion() { Paths.get("").normalize() } catch (e: ArrayIndexOutOfBoundsException) { println(""" - You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest version. - Corda will now exit...""") +You are using a version of Java that is not supported (${System.getProperty("java.version")}). Please upgrade to the latest version. +Corda will now exit...""") exitProcess(1) } } @@ -138,13 +125,6 @@ private fun printPluginsAndServices(node: Node) { } private fun messageOfTheDay(): Pair { - // TODO: Remove this next year. - val today = LocalDate.now() - if (today.isAfter(LocalDate.of(2016, 12, 20)) && today.isBefore(LocalDate.of(2017, 1, 3))) { - val claus = if (Emoji.hasEmojiTerminal) Emoji.santaClaus else "" - return Pair("The Corda team wishes you a very merry", "christmas and a happy new year! $claus") - } - val messages = arrayListOf( "The only distributed ledger that pays\nhomage to Pac Man in its logo.", "You know, I was a banker once ...\nbut I lost interest. ${Emoji.bagOfCash}", @@ -153,7 +133,6 @@ private fun messageOfTheDay(): Pair { "\"It's OK computer, I go to sleep after\ntwenty minutes of inactivity too!\"", "It's kind of like a block chain but\ncords sounded healthier than chains.", "Computer science and finance together.\nYou should see our crazy Christmas parties!" - ) if (Emoji.hasEmojiTerminal) messages += @@ -177,5 +156,3 @@ private fun drawBanner() { """\____/ /_/ \__,_/\__,_/""").reset().newline().newline().fgBrightDefault().bold(). a("--- DEVELOPER SNAPSHOT ------------------------------------------------------------").newline().reset()) } - - diff --git a/node/src/main/kotlin/net/corda/node/driver/Driver.kt b/node/src/main/kotlin/net/corda/node/driver/Driver.kt index 3cb992a56a..533e5b660a 100644 --- a/node/src/main/kotlin/net/corda/node/driver/Driver.kt +++ b/node/src/main/kotlin/net/corda/node/driver/Driver.kt @@ -155,7 +155,7 @@ fun driver( driverDsl = DriverDSL( portAllocation = portAllocation, debugPortAllocation = debugPortAllocation, - driverDirectory = driverDirectory, + driverDirectory = driverDirectory.toAbsolutePath(), useTestClock = useTestClock, isDebug = isDebug ), @@ -349,7 +349,6 @@ open class DriverDSL( val baseDirectory = driverDirectory / name val configOverrides = mapOf( "myLegalName" to name, - "basedir" to baseDirectory.normalize().toString(), "artemisAddress" to messagingAddress.toString(), "webAddress" to apiAddress.toString(), "extraAdvertisedServiceIds" to advertisedServices.joinToString(","), @@ -367,11 +366,14 @@ open class DriverDSL( } ) + customOverrides - val configuration = FullNodeConfiguration(ConfigHelper.loadConfig( - baseDirectoryPath = baseDirectory, - allowMissingConfig = true, - configOverrides = configOverrides - )) + val configuration = FullNodeConfiguration( + baseDirectory, + ConfigHelper.loadConfig( + baseDirectory = baseDirectory, + allowMissingConfig = true, + configOverrides = configOverrides + ) + ) val startNode = startNode(executorService, configuration, quasarJarPath, debugPort) registerProcess(startNode) @@ -421,11 +423,10 @@ open class DriverDSL( val baseDirectory = driverDirectory / networkMapLegalName val config = ConfigHelper.loadConfig( - baseDirectoryPath = baseDirectory, + baseDirectory = baseDirectory, allowMissingConfig = true, configOverrides = mapOf( "myLegalName" to networkMapLegalName, - "basedir" to baseDirectory.normalize().toString(), "artemisAddress" to networkMapAddress.toString(), "webAddress" to apiAddress.toString(), "extraAdvertisedServiceIds" to "", @@ -434,7 +435,7 @@ open class DriverDSL( ) log.info("Starting network-map-service") - val startNode = startNode(executorService, FullNodeConfiguration(config), quasarJarPath, debugPort) + val startNode = startNode(executorService, FullNodeConfiguration(baseDirectory, config), quasarJarPath, debugPort) registerProcess(startNode) return startNode } @@ -456,7 +457,7 @@ open class DriverDSL( debugPort: Int? ): ListenableFuture { // Write node.conf - writeConfig(nodeConf.basedir, "node.conf", nodeConf.config) + writeConfig(nodeConf.baseDirectory, "node.conf", nodeConf.config) val className = "net.corda.node.MainKt" // cannot directly get class for this, so just use string val separator = System.getProperty("file.separator") @@ -471,11 +472,11 @@ open class DriverDSL( val javaArgs = listOf(path) + listOf("-Dname=${nodeConf.myLegalName}", "-javaagent:$quasarJarPath") + debugPortArg + listOf("-cp", classpath, className) + - "--base-directory=${nodeConf.basedir}" + "--base-directory=${nodeConf.baseDirectory}" val builder = ProcessBuilder(javaArgs) builder.redirectError(Paths.get("error.$className.log").toFile()) builder.inheritIO() - builder.directory(nodeConf.basedir.toFile()) + builder.directory(nodeConf.baseDirectory.toFile()) val process = builder.start() return Futures.allAsList( addressMustBeBound(executorService, nodeConf.artemisAddress), diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index f678dff1a8..1a79e553ca 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -203,7 +203,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, // Do all of this in a database transaction so anything that might need a connection has one. initialiseDatabasePersistence { - val storageServices = initialiseStorageService(configuration.basedir) + val storageServices = initialiseStorageService(configuration.baseDirectory) storage = storageServices.first checkpointStorage = storageServices.second netMapCache = InMemoryNetworkMapCache() @@ -285,7 +285,7 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, return advertisedServices.map { val serviceId = it.type.id val serviceName = it.name ?: "$serviceId|${configuration.myLegalName}" - val identity = obtainKeyPair(configuration.basedir, serviceId + "-private-key", serviceId + "-public", serviceName).first + val identity = obtainKeyPair(configuration.baseDirectory, serviceId + "-private-key", serviceId + "-public", serviceName).first ServiceEntry(it, identity) } } @@ -495,8 +495,8 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, stateMachineRecordedTransactionMappingStorage: StateMachineRecordedTransactionMappingStorage) = StorageServiceImpl(attachments, transactionStorage, stateMachineRecordedTransactionMappingStorage) - protected fun obtainLegalIdentity(): Party = obtainKeyPair(configuration.basedir, PRIVATE_KEY_FILE_NAME, PUBLIC_IDENTITY_FILE_NAME).first - protected fun obtainLegalIdentityKey(): KeyPair = obtainKeyPair(configuration.basedir, PRIVATE_KEY_FILE_NAME, PUBLIC_IDENTITY_FILE_NAME).second + protected fun obtainLegalIdentity(): Party = obtainKeyPair(configuration.baseDirectory, PRIVATE_KEY_FILE_NAME, PUBLIC_IDENTITY_FILE_NAME).first + protected fun obtainLegalIdentityKey(): KeyPair = obtainKeyPair(configuration.baseDirectory, PRIVATE_KEY_FILE_NAME, PUBLIC_IDENTITY_FILE_NAME).second private fun obtainKeyPair(dir: Path, privateKeyFileName: String, publicKeyFileName: String, serviceName: String? = null): Pair { // Load the private identity key, creating it if necessary. The identity key is a long term well known key that @@ -545,6 +545,6 @@ abstract class AbstractNode(open val configuration: NodeConfiguration, } protected fun createNodeDir() { - configuration.basedir.createDirectories() + configuration.baseDirectory.createDirectories() } } diff --git a/node/src/main/kotlin/net/corda/node/internal/Node.kt b/node/src/main/kotlin/net/corda/node/internal/Node.kt index 0d22fa7523..b0476427af 100644 --- a/node/src/main/kotlin/net/corda/node/internal/Node.kt +++ b/node/src/main/kotlin/net/corda/node/internal/Node.kt @@ -270,7 +270,7 @@ class Node(override val configuration: FullNodeConfiguration, override fun makeUniquenessProvider(type: ServiceType): UniquenessProvider { return when (type) { RaftValidatingNotaryService.type -> with(configuration) { - RaftUniquenessProvider(basedir, notaryNodeAddress!!, notaryClusterAddresses, database, configuration) + RaftUniquenessProvider(baseDirectory, notaryNodeAddress!!, notaryClusterAddresses, database, configuration) } else -> PersistentUniquenessProvider() } @@ -393,7 +393,7 @@ class Node(override val configuration: FullNodeConfiguration, // file that we'll do our best to delete on exit. But if we don't, it'll be overwritten next time. If it already // exists, we try to take the file lock first before replacing it and if that fails it means we're being started // twice with the same directory: that's a user error and we should bail out. - val pidPath = configuration.basedir / "process-id" + val pidPath = configuration.baseDirectory / "process-id" val file = pidPath.toFile() if (!file.exists()) { file.createNewFile() @@ -402,7 +402,7 @@ class Node(override val configuration: FullNodeConfiguration, val f = RandomAccessFile(file, "rw") val l = f.channel.tryLock() if (l == null) { - log.error("It appears there is already a node running with the specified data directory ${configuration.basedir}") + log.error("It appears there is already a node running with the specified data directory ${configuration.baseDirectory}") log.error("Shut that other node down and try again. It may have process ID ${file.readText()}") System.exit(1) } diff --git a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt index e9b4c3ed81..1f40c9ec8d 100644 --- a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt +++ b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt @@ -25,27 +25,28 @@ import kotlin.reflect.KProperty import kotlin.reflect.jvm.javaType object ConfigHelper { - val log = loggerFor() + private val log = loggerFor() - fun loadConfig(baseDirectoryPath: Path, + fun loadConfig(baseDirectory: Path, configFileOverride: Path? = null, allowMissingConfig: Boolean = false, configOverrides: Map = emptyMap()): Config { - val defaultConfig = ConfigFactory.parseResources("reference.conf", ConfigParseOptions.defaults().setAllowMissing(false)) - val normalisedBaseDir = baseDirectoryPath.normalize() - val configFile = (configFileOverride?.normalize() ?: normalisedBaseDir / "node.conf").toFile() - val appConfig = ConfigFactory.parseFile(configFile, ConfigParseOptions.defaults().setAllowMissing(allowMissingConfig)) + val configFile = configFileOverride ?: baseDirectory / "node.conf" + val appConfig = ConfigFactory.parseFile(configFile.toFile(), ConfigParseOptions.defaults().setAllowMissing(allowMissingConfig)) - val overridesMap = HashMap() // If we do require a few other command line overrides eg for a nicer development experience they would go inside this map. - overridesMap.putAll(configOverrides) - overridesMap["basedir"] = normalisedBaseDir.toAbsolutePath().toString() - val overrideConfig = ConfigFactory.parseMap(overridesMap) + val overrideConfig = ConfigFactory.parseMap(configOverrides + mapOf( + // Add substitution values here + "basedir" to baseDirectory.toString()) + ) - val mergedAndResolvedConfig = overrideConfig.withFallback(appConfig).withFallback(defaultConfig).resolve() - log.info("Config:\n ${mergedAndResolvedConfig.root().render(ConfigRenderOptions.defaults())}") - return mergedAndResolvedConfig + val finalConfig = overrideConfig + .withFallback(appConfig) + .withFallback(defaultConfig) + .resolve() + log.info("Config:\n${finalConfig.root().render(ConfigRenderOptions.defaults())}") + return finalConfig } } @@ -74,12 +75,9 @@ class OptionalConfig(val conf: Config, val lambda: () -> T) { operator fun getValue(receiver: Any, metadata: KProperty<*>): T { return if (conf.hasPath(metadata.name)) conf.getValue(receiver, metadata) else lambda() } - } -fun Config.getOrElse(lambda: () -> T): OptionalConfig { - return OptionalConfig(this, lambda) -} +fun Config.getOrElse(lambda: () -> T): OptionalConfig = OptionalConfig(this, lambda) fun Config.getProperties(path: String): Properties { val obj = this.getObject(path) @@ -106,7 +104,7 @@ inline fun Config.getListOrElse(path: String, default: Config. fun NodeConfiguration.configureWithDevSSLCertificate() = configureDevKeyAndTrustStores(myLegalName) private fun NodeSSLConfiguration.configureDevKeyAndTrustStores(myLegalName: String) { - certificatesPath.createDirectories() + certificatesDirectory.createDirectories() if (!trustStorePath.exists()) { javaClass.classLoader.getResourceAsStream("net/corda/node/internal/certificates/cordatruststore.jks").copyTo(trustStorePath) } @@ -121,7 +119,7 @@ private fun NodeSSLConfiguration.configureDevKeyAndTrustStores(myLegalName: Stri // TODO Move this to CoreTestUtils.kt once we can pry this from the explorer @JvmOverloads fun configureTestSSL(legalName: String = "Mega Corp."): NodeSSLConfiguration = object : NodeSSLConfiguration { - override val certificatesPath = Files.createTempDirectory("certs") + override val certificatesDirectory = Files.createTempDirectory("certs") override val keyStorePassword: String get() = "cordacadevpass" override val trustStorePassword: String get() = "trustpass" diff --git a/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt b/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt index 97de5de4a0..9fd3584603 100644 --- a/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt +++ b/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt @@ -13,17 +13,20 @@ import net.corda.node.utilities.TestClock import java.nio.file.Path import java.util.* +// TODO Rename this to SSLConfiguration as it's also used by non-node components interface NodeSSLConfiguration { val keyStorePassword: String val trustStorePassword: String - val certificatesPath: Path - val keyStorePath: Path get() = certificatesPath / "sslkeystore.jks" - val trustStorePath: Path get() = certificatesPath / "truststore.jks" + val certificatesDirectory: Path + // TODO Rename to keyStoreFile + val keyStorePath: Path get() = certificatesDirectory / "sslkeystore.jks" + // TODO Rename to trustStoreFile + val trustStorePath: Path get() = certificatesDirectory / "truststore.jks" } interface NodeConfiguration : NodeSSLConfiguration { - val basedir: Path - override val certificatesPath: Path get() = basedir / "certificates" + val baseDirectory: Path + override val certificatesDirectory: Path get() = baseDirectory / "certificates" val myLegalName: String val networkMapService: NetworkMapInfo? val nearestCity: String @@ -34,8 +37,10 @@ interface NodeConfiguration : NodeSSLConfiguration { val devMode: Boolean } -class FullNodeConfiguration(val config: Config) : NodeConfiguration { - override val basedir: Path by config +/** + * [baseDirectory] is not retrieved from the config file but rather from a command line argument. + */ +class FullNodeConfiguration(override val baseDirectory: Path, val config: Config) : NodeConfiguration { override val myLegalName: String by config override val nearestCity: String by config override val emailAddress: String by config diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt b/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt index ce73995619..611b409ef7 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/ArtemisMessagingServer.kt @@ -103,7 +103,7 @@ class ArtemisMessagingServer(override val config: NodeConfiguration, private var networkChangeHandle: Subscription? = null init { - config.basedir.expectedOnDefaultFileSystem() + config.baseDirectory.expectedOnDefaultFileSystem() } /** @@ -143,7 +143,7 @@ class ArtemisMessagingServer(override val config: NodeConfiguration, } private fun createArtemisConfig(): Configuration = ConfigurationImpl().apply { - val artemisDir = config.basedir / "artemis" + val artemisDir = config.baseDirectory / "artemis" bindingsDirectory = (artemisDir / "bindings").toString() journalDirectory = (artemisDir / "journal").toString() largeMessagesDirectory = (artemisDir / "large-messages").toString() diff --git a/node/src/main/kotlin/net/corda/node/utilities/certsigning/CertificateSigner.kt b/node/src/main/kotlin/net/corda/node/utilities/certsigning/CertificateSigner.kt index a01bfca19d..edb5d843be 100644 --- a/node/src/main/kotlin/net/corda/node/utilities/certsigning/CertificateSigner.kt +++ b/node/src/main/kotlin/net/corda/node/utilities/certsigning/CertificateSigner.kt @@ -1,6 +1,5 @@ package net.corda.node.utilities.certsigning -import joptsimple.OptionParser import net.corda.core.* import net.corda.core.crypto.X509Utilities import net.corda.core.crypto.X509Utilities.CORDA_CLIENT_CA @@ -9,12 +8,12 @@ import net.corda.core.crypto.X509Utilities.CORDA_ROOT_CA import net.corda.core.crypto.X509Utilities.addOrReplaceCertificate import net.corda.core.crypto.X509Utilities.addOrReplaceKey import net.corda.core.utilities.loggerFor -import net.corda.node.services.config.ConfigHelper +import net.corda.node.ArgsParser import net.corda.node.services.config.FullNodeConfiguration import net.corda.node.services.config.NodeConfiguration import net.corda.node.services.config.getValue +import net.corda.node.utilities.certsigning.CertificateSigner.Companion.log import java.net.URL -import java.nio.file.Paths import java.security.KeyPair import java.security.cert.Certificate import kotlin.system.exitProcess @@ -32,7 +31,7 @@ class CertificateSigner(val config: NodeConfiguration, val certService: Certific } fun buildKeyStore() { - config.certificatesPath.createDirectories() + config.certificatesDirectory.createDirectories() val caKeyStore = X509Utilities.loadOrCreateKeyStore(config.keyStorePath, config.keyStorePassword) @@ -97,7 +96,7 @@ class CertificateSigner(val config: NodeConfiguration, val certService: Certific * @return Request ID return from the server. */ private fun submitCertificateSigningRequest(keyPair: KeyPair): String { - val requestIdStore = config.certificatesPath / "certificate-request-id.txt" + val requestIdStore = config.certificatesDirectory / "certificate-request-id.txt" // Retrieve request id from file if exists, else post a request to server. return if (!requestIdStore.exists()) { val request = X509Utilities.createCertificateSigningRequest(config.myLegalName, config.nearestCity, config.emailAddress, keyPair) @@ -112,30 +111,21 @@ class CertificateSigner(val config: NodeConfiguration, val certService: Certific } } -object ParamsSpec { - val parser = OptionParser() - val baseDirectoryArg = parser.accepts("base-dir", "Working directory of Corda Node.").withRequiredArg().defaultsTo(".") - val configFileArg = parser.accepts("config-file", "The path to the config file.").withRequiredArg() -} - fun main(args: Array) { + val argsParser = ArgsParser() val cmdlineOptions = try { - ParamsSpec.parser.parse(*args) + argsParser.parse(*args) } catch (ex: Exception) { - CertificateSigner.log.error("Unable to parse args", ex) - ParamsSpec.parser.printHelpOn(System.out) + log.error("Unable to parse args", ex) + argsParser.printHelp(System.out) exitProcess(1) } - val baseDirectoryPath = Paths.get(cmdlineOptions.valueOf(ParamsSpec.baseDirectoryArg)) - val configFile = if (cmdlineOptions.has(ParamsSpec.configFileArg)) Paths.get(cmdlineOptions.valueOf(ParamsSpec.configFileArg)) else null - - val config = ConfigHelper.loadConfig(baseDirectoryPath, configFile, allowMissingConfig = true).let { config -> - object : NodeConfiguration by FullNodeConfiguration(config) { - val certificateSigningService: URL by config - } + val config = cmdlineOptions.loadConfig(allowMissingConfig = true) + val configuration = object : NodeConfiguration by FullNodeConfiguration(cmdlineOptions.baseDirectory, config) { + val certificateSigningService: URL by config } // TODO: Use HTTPS instead - CertificateSigner(config, HTTPCertificateSigningService(config.certificateSigningService)).buildKeyStore() + CertificateSigner(configuration, HTTPCertificateSigningService(configuration.certificateSigningService)).buildKeyStore() } diff --git a/node/src/test/kotlin/net/corda/node/ArgsParserTest.kt b/node/src/test/kotlin/net/corda/node/ArgsParserTest.kt new file mode 100644 index 0000000000..224a0a540b --- /dev/null +++ b/node/src/test/kotlin/net/corda/node/ArgsParserTest.kt @@ -0,0 +1,86 @@ +package net.corda.node + +import joptsimple.OptionException +import net.corda.core.div +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.assertThatExceptionOfType +import org.junit.Test +import java.nio.file.Paths + +class ArgsParserTest { + private val parser = ArgsParser() + private val workingDirectory = Paths.get(".").normalize().toAbsolutePath() + + @Test + fun `no command line arguments`() { + assertThat(parser.parse()).isEqualTo(CmdLineOptions( + baseDirectory = workingDirectory, + configFile = workingDirectory / "node.conf", + help = false, + logToConsole = false)) + } + + @Test + fun `just base-directory with relative path`() { + val expectedBaseDir = Paths.get("tmp").normalize().toAbsolutePath() + val cmdLineOptions = parser.parse("--base-directory", "tmp") + assertThat(cmdLineOptions).isEqualTo(CmdLineOptions( + baseDirectory = expectedBaseDir, + configFile = expectedBaseDir / "node.conf", + help = false, + logToConsole = false)) + } + + @Test + fun `just base-directory with absolute path`() { + val baseDirectory = Paths.get("tmp").normalize().toAbsolutePath() + val cmdLineOptions = parser.parse("--base-directory", baseDirectory.toString()) + assertThat(cmdLineOptions).isEqualTo(CmdLineOptions( + baseDirectory = baseDirectory, + configFile = baseDirectory / "node.conf", + help = false, + logToConsole = false)) + } + + @Test + fun `just config-file with relative path`() { + val cmdLineOptions = parser.parse("--config-file", "different.conf") + assertThat(cmdLineOptions).isEqualTo(CmdLineOptions( + baseDirectory = workingDirectory, + configFile = workingDirectory / "different.conf", + help = false, + logToConsole = false)) + } + + @Test + fun `just config-file with absolute path`() { + val configFile = Paths.get("tmp", "a.conf").normalize().toAbsolutePath() + val cmdLineOptions = parser.parse("--config-file", configFile.toString()) + assertThat(cmdLineOptions).isEqualTo(CmdLineOptions( + baseDirectory = workingDirectory, + configFile = configFile, + help = false, + logToConsole = false)) + } + + @Test + fun `both base-directory and config-file`() { + assertThatExceptionOfType(IllegalArgumentException::class.java).isThrownBy { + parser.parse("--base-directory", "base", "--config-file", "conf") + }.withMessageContaining("base-directory").withMessageContaining("config-file") + } + + @Test + fun `base-directory without argument`() { + assertThatExceptionOfType(OptionException::class.java).isThrownBy { + parser.parse("--base-directory") + }.withMessageContaining("base-directory") + } + + @Test + fun `config-file without argument`() { + assertThatExceptionOfType(OptionException::class.java).isThrownBy { + parser.parse("--config-file") + }.withMessageContaining("config-file") + } +} \ No newline at end of file diff --git a/node/src/test/kotlin/net/corda/node/services/RPCUserServiceImplTest.kt b/node/src/test/kotlin/net/corda/node/services/RPCUserServiceImplTest.kt index 9d11ef23e0..986d728b80 100644 --- a/node/src/test/kotlin/net/corda/node/services/RPCUserServiceImplTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/RPCUserServiceImplTest.kt @@ -5,6 +5,7 @@ import net.corda.node.services.config.FullNodeConfiguration import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Test +import java.nio.file.Paths class RPCUserServiceImplTest { @@ -69,6 +70,6 @@ class RPCUserServiceImplTest { } private fun loadWithContents(configString: String): RPCUserServiceImpl { - return RPCUserServiceImpl(FullNodeConfiguration(ConfigFactory.parseString(configString))) + return RPCUserServiceImpl(FullNodeConfiguration(Paths.get("."), ConfigFactory.parseString(configString))) } } \ No newline at end of file diff --git a/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt b/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt index b307d45168..cb3f8365ca 100644 --- a/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/messaging/ArtemisMessagingTests.kt @@ -4,7 +4,7 @@ import com.google.common.net.HostAndPort import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.SettableFuture -import com.typesafe.config.ConfigFactory +import com.typesafe.config.ConfigFactory.empty import net.corda.core.crypto.composite import net.corda.core.crypto.generateKeyPair import net.corda.core.messaging.Message @@ -67,9 +67,10 @@ class ArtemisMessagingTests { @Before fun setUp() { - userService = RPCUserServiceImpl(FullNodeConfiguration(ConfigFactory.empty())) + val baseDirectory = temporaryFolder.root.toPath() + userService = RPCUserServiceImpl(FullNodeConfiguration(baseDirectory, empty())) config = TestNodeConfiguration( - basedir = temporaryFolder.newFolder().toPath(), + baseDirectory = baseDirectory, myLegalName = "me", networkMapService = null) LogHelper.setLevel(PersistentUniquenessProvider::class) diff --git a/node/src/test/kotlin/net/corda/node/utilities/certsigning/CertificateSignerTest.kt b/node/src/test/kotlin/net/corda/node/utilities/certsigning/CertificateSignerTest.kt index 6ba11a2fc0..3520bab747 100644 --- a/node/src/test/kotlin/net/corda/node/utilities/certsigning/CertificateSignerTest.kt +++ b/node/src/test/kotlin/net/corda/node/utilities/certsigning/CertificateSignerTest.kt @@ -35,7 +35,7 @@ class CertificateSignerTest { } val config = TestNodeConfiguration( - basedir = tempFolder.root.toPath(), + baseDirectory = tempFolder.root.toPath(), myLegalName = "me", networkMapService = null) @@ -65,6 +65,6 @@ class CertificateSignerTest { assertFalse(containsAlias(X509Utilities.CORDA_ROOT_CA_PRIVATE_KEY)) } - assertEquals(id, (config.certificatesPath / "certificate-request-id.txt").readLines { it.findFirst().get() }) + assertEquals(id, (config.certificatesDirectory / "certificate-request-id.txt").readLines { it.findFirst().get() }) } } diff --git a/publish.properties b/publish.properties index cb959037b1..001cef1f57 100644 --- a/publish.properties +++ b/publish.properties @@ -1 +1 @@ -gradlePluginsVersion=0.6.4 \ No newline at end of file +gradlePluginsVersion=0.6.5 diff --git a/samples/attachment-demo/build.gradle b/samples/attachment-demo/build.gradle index 22196b5653..e4158e7bc0 100644 --- a/samples/attachment-demo/build.gradle +++ b/samples/attachment-demo/build.gradle @@ -66,7 +66,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { networkMap "Controller" node { name "Controller" - dirName "controller" nearestCity "London" advertisedServices ["corda.notary.validating"] artemisPort 10002 @@ -76,7 +75,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank A" - dirName "nodea" nearestCity "London" advertisedServices = [] artemisPort 10004 @@ -86,7 +84,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank B" - dirName "nodeb" nearestCity "New York" advertisedServices = [] artemisPort 10006 diff --git a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt index a0a6105a53..595b4010aa 100644 --- a/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt +++ b/samples/attachment-demo/src/main/kotlin/net/corda/attachmentdemo/AttachmentDemo.kt @@ -116,6 +116,6 @@ private fun sslConfigFor(nodename: String, certsPath: String?): NodeSSLConfigura return object : NodeSSLConfiguration { override val keyStorePassword: String = "cordacadevpass" override val trustStorePassword: String = "trustpass" - override val certificatesPath: Path = if (certsPath != null) Paths.get(certsPath) else Paths.get("build") / "nodes" / nodename / "certificates" + override val certificatesDirectory: Path = if (certsPath != null) Paths.get(certsPath) else Paths.get("build") / "nodes" / nodename / "certificates" } } \ No newline at end of file diff --git a/samples/bank-of-corda-demo/build.gradle b/samples/bank-of-corda-demo/build.gradle index 776e542810..d14e7eacd1 100644 --- a/samples/bank-of-corda-demo/build.gradle +++ b/samples/bank-of-corda-demo/build.gradle @@ -63,7 +63,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { networkMap "Notary" node { name "Notary" - dirName "notary" nearestCity "London" advertisedServices = ["corda.notary.validating"] artemisPort 10002 @@ -72,7 +71,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "BankOfCorda" - dirName "node-bank-of-corda" nearestCity "London" advertisedServices = [] artemisPort 10004 @@ -87,7 +85,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "BigCorporation" - dirName "node-big-corp" nearestCity "New York" advertisedServices = [] artemisPort 10006 diff --git a/samples/irs-demo/build.gradle b/samples/irs-demo/build.gradle index 472ee14fdb..8c09fee88b 100644 --- a/samples/irs-demo/build.gradle +++ b/samples/irs-demo/build.gradle @@ -66,7 +66,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { networkMap "Notary" node { name "Notary" - dirName "controller" nearestCity "London" advertisedServices = ["corda.notary.validating", "corda.interest_rates"] artemisPort 10002 @@ -76,7 +75,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank A" - dirName "nodea" nearestCity "London" advertisedServices = [] artemisPort 10004 @@ -86,7 +84,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank B" - dirName "nodeb" nearestCity "New York" advertisedServices = [] artemisPort 10006 diff --git a/samples/irs-demo/src/main/kotlin/net/corda/simulation/Simulation.kt b/samples/irs-demo/src/main/kotlin/net/corda/simulation/Simulation.kt index 3c2bc05c64..ab5575a761 100644 --- a/samples/irs-demo/src/main/kotlin/net/corda/simulation/Simulation.kt +++ b/samples/irs-demo/src/main/kotlin/net/corda/simulation/Simulation.kt @@ -64,7 +64,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, val city = bankLocations[counter++ % bankLocations.size] val cfg = TestNodeConfiguration( - basedir = config.basedir, + baseDirectory = config.baseDirectory, // TODO: Set this back to "Bank of $city" after video day. myLegalName = "Bank $letter", nearestCity = city, @@ -86,7 +86,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, networkMapAddr: SingleMessageRecipient?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { require(advertisedServices.containsType(NetworkMapService.type)) val cfg = TestNodeConfiguration( - basedir = config.basedir, + baseDirectory = config.baseDirectory, myLegalName = "Network coordination center", nearestCity = "Amsterdam", networkMapService = null) @@ -99,7 +99,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { require(advertisedServices.containsType(SimpleNotaryService.type)) val cfg = TestNodeConfiguration( - basedir = config.basedir, + baseDirectory = config.baseDirectory, myLegalName = "Notary Service", nearestCity = "Zurich", networkMapService = null) @@ -112,7 +112,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { require(advertisedServices.containsType(NodeInterestRates.type)) val cfg = TestNodeConfiguration( - basedir = config.basedir, + baseDirectory = config.baseDirectory, myLegalName = "Rates Service Provider", nearestCity = "Madrid", networkMapService = null) @@ -134,7 +134,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean, override fun create(config: NodeConfiguration, network: MockNetwork, networkMapAddr: SingleMessageRecipient?, advertisedServices: Set, id: Int, keyPair: KeyPair?): MockNetwork.MockNode { val cfg = TestNodeConfiguration( - basedir = config.basedir, + baseDirectory = config.baseDirectory, myLegalName = "Regulator A", nearestCity = "Paris", networkMapService = null) diff --git a/samples/raft-notary-demo/build.gradle b/samples/raft-notary-demo/build.gradle index 0ec1fb3b49..58231e9d88 100644 --- a/samples/raft-notary-demo/build.gradle +++ b/samples/raft-notary-demo/build.gradle @@ -86,7 +86,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build', 'generat networkMap "Notary 1" node { name "Notary 1" - dirName "notary1" nearestCity "London" advertisedServices = [advertisedNotary] artemisPort 10002 @@ -96,7 +95,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build', 'generat } node { name "Notary 2" - dirName "notary2" nearestCity "London" advertisedServices = [advertisedNotary] artemisPort 10004 @@ -107,7 +105,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build', 'generat } node { name "Notary 3" - dirName "notary3" nearestCity "London" advertisedServices = [advertisedNotary] artemisPort 10006 @@ -118,7 +115,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build', 'generat } node { name "Party" - dirName "party" nearestCity "London" advertisedServices = [] artemisPort 10008 @@ -127,7 +123,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build', 'generat } node { name "Counterparty" - dirName "counterparty" nearestCity "New York" advertisedServices = [] artemisPort 10010 diff --git a/samples/simm-valuation-demo/build.gradle b/samples/simm-valuation-demo/build.gradle index 1e4ffac07f..5b8270c1c1 100644 --- a/samples/simm-valuation-demo/build.gradle +++ b/samples/simm-valuation-demo/build.gradle @@ -81,7 +81,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { networkMap "Controller" node { name "Controller" - dirName "controller" nearestCity "London" advertisedServices = ["corda.notary.validating"] artemisPort 10002 @@ -90,7 +89,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank A" - dirName "nodea" nearestCity "London" advertisedServices = [] artemisPort 10004 @@ -99,7 +97,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank B" - dirName "nodeb" nearestCity "New York" advertisedServices = [] artemisPort 10006 @@ -108,7 +105,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank C" - dirName "nodec" nearestCity "tokyo" advertisedServices = [] artemisPort 10008 diff --git a/samples/trader-demo/build.gradle b/samples/trader-demo/build.gradle index 4d7c5ee1c3..4b7bb834e4 100644 --- a/samples/trader-demo/build.gradle +++ b/samples/trader-demo/build.gradle @@ -73,7 +73,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { networkMap "Notary" node { name "Notary" - dirName "notary" nearestCity "London" advertisedServices = ["corda.notary.validating"] artemisPort 10002 @@ -82,7 +81,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank A" - dirName "nodea" nearestCity "London" advertisedServices = [] artemisPort 10004 @@ -91,7 +89,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "Bank B" - dirName "nodeb" nearestCity "New York" advertisedServices = [] artemisPort 10006 @@ -100,7 +97,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) { } node { name "BankOfCorda" - dirName "bankofcorda" nearestCity "London" advertisedServices = [] artemisPort 10008 diff --git a/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt b/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt index 8229e25493..e9f1a6ac28 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/CoreTestUtils.kt @@ -164,13 +164,13 @@ inline fun > AbstractNode.initiateSingleShotFlow( } data class TestNodeConfiguration( - override val basedir: Path, - override val myLegalName: String, - override val networkMapService: NetworkMapInfo?, - override val keyStorePassword: String = "cordacadevpass", - override val trustStorePassword: String = "trustpass", - override val dataSourceProperties: Properties = makeTestDataSourceProperties(myLegalName), - override val nearestCity: String = "Null Island", - override val emailAddress: String = "", - override val exportJMXto: String = "", - override val devMode: Boolean = true) : NodeConfiguration + override val baseDirectory: Path, + override val myLegalName: String, + override val networkMapService: NetworkMapInfo?, + override val keyStorePassword: String = "cordacadevpass", + override val trustStorePassword: String = "trustpass", + override val dataSourceProperties: Properties = makeTestDataSourceProperties(myLegalName), + override val nearestCity: String = "Null Island", + override val emailAddress: String = "", + override val exportJMXto: String = "", + override val devMode: Boolean = true) : NodeConfiguration diff --git a/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt b/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt index efd8536f53..121d0b1ecc 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/node/MockNode.kt @@ -199,7 +199,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false, (path / "attachments").createDirectories() val config = TestNodeConfiguration( - basedir = path, + baseDirectory = path, myLegalName = legalName ?: "Mock Company $id", networkMapService = null, dataSourceProperties = makeTestDataSourceProperties("node_${id}_net_$networkId")) diff --git a/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt b/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt index aa3f6a50e7..7825a19283 100644 --- a/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt +++ b/test-utils/src/main/kotlin/net/corda/testing/node/NodeBasedTest.kt @@ -114,8 +114,9 @@ abstract class NodeBasedTest { advertisedServices: Set, rpcUsers: List, configOverrides: Map): Node { + val baseDirectory = (tempFolder.root.toPath() / legalName).createDirectories() val config = ConfigHelper.loadConfig( - baseDirectoryPath = (tempFolder.root.toPath() / legalName).createDirectories(), + baseDirectory = baseDirectory, allowMissingConfig = true, configOverrides = mapOf( "myLegalName" to legalName, @@ -131,7 +132,7 @@ abstract class NodeBasedTest { ) + configOverrides ) - val node = FullNodeConfiguration(config).createNode() + val node = FullNodeConfiguration(baseDirectory, config).createNode() node.start() nodes += node thread(name = legalName) { diff --git a/tools/loadtest/src/main/kotlin/net/corda/loadtest/ConnectionManager.kt b/tools/loadtest/src/main/kotlin/net/corda/loadtest/ConnectionManager.kt index f44a16b744..8bd42cd529 100644 --- a/tools/loadtest/src/main/kotlin/net/corda/loadtest/ConnectionManager.kt +++ b/tools/loadtest/src/main/kotlin/net/corda/loadtest/ConnectionManager.kt @@ -155,7 +155,7 @@ class NodeConnection( ) : Closeable { private val sslConfig = object : NodeSSLConfiguration { - override val certificatesPath = certificatesDirectory + override val certificatesDirectory = this@NodeConnection.certificatesDirectory override val keyStorePassword: String get() = "cordacadevpass" override val trustStorePassword: String get() = "trustpass" }