From 146f274dd0a29c486eefff21d3d2f732a3f4590b Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Mon, 6 Jun 2016 15:23:32 +0100 Subject: [PATCH] Demo now requires the setup steps if the configuration is not default. Documentation updated to reflect these changes. --- docs/source/running-the-demos.rst | 3 ++ src/main/kotlin/com/r3corda/demos/IRSDemo.kt | 33 +++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/source/running-the-demos.rst b/docs/source/running-the-demos.rst index d54ceabc9c..93499522a5 100644 --- a/docs/source/running-the-demos.rst +++ b/docs/source/running-the-demos.rst @@ -20,6 +20,9 @@ Trader demo Open two terminals, and in the first run: +.. note:: If you are planning to use non-default configuration you will need to run with --role=SetupA and --role=SetupB + beforehand with the same parameters you plan to supply to the respective nodes. + **Windows**:: gradlew.bat & .\build\install\r3prototyping\bin\trader-demo --role=BUYER diff --git a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt index fbd4dfb903..036b774591 100644 --- a/src/main/kotlin/com/r3corda/demos/IRSDemo.kt +++ b/src/main/kotlin/com/r3corda/demos/IRSDemo.kt @@ -36,6 +36,7 @@ import java.util.* import kotlin.concurrent.fixedRateTimer import kotlin.system.exitProcess import org.apache.commons.io.IOUtils +import java.io.FileNotFoundException // IRS DEMO // @@ -77,6 +78,10 @@ private class DemoArgs() { lateinit var nonOptions: OptionSpec } +private class NotSetupException: Throwable { + constructor(message: String): super(message) {} +} + fun main(args: Array) { val parser = OptionParser() val demoArgs = setupArgs(parser) @@ -133,13 +138,20 @@ fun main(args: Array) { exitProcess(1) } } else { - // If the directories are default assume both will be and ensure all config is created - if(!options.has(demoArgs.dirArg)) { + // If these directory and identity file arguments aren't specified then we can assume a default setup and + // create everything that is needed without needing to run setup. + if(!options.has(demoArgs.dirArg) && !options.has(demoArgs.fakeTradeWithIdentityFile)) { createNodeConfig(createNodeAParams()); createNodeConfig(createNodeBParams()); } - runNode(configureNodeParams(role, demoArgs, options)) + try { + runNode(configureNodeParams(role, demoArgs, options)) + } catch (e: NotSetupException) { + println(e.message) + exitProcess(1) + } + exitProcess(0) } } @@ -351,8 +363,21 @@ private fun createNodeConfig(params: NodeParams) : NodeConfiguration { return config } +private fun getNodeConfig(params: NodeParams): NodeConfiguration { + if(!Files.exists(params.dir)) { + throw NotSetupException("Missing config directory. Please run node setup before running the node") + } + + if(!Files.exists(params.dir.resolve(AbstractNode.PUBLIC_IDENTITY_FILE_NAME))) { + throw NotSetupException("Missing identity file. Please run node setup before running the node") + } + + val configFile = params.dir.resolve("config").toFile() + return loadConfigFile(configFile, params.defaultLegalName) +} + private fun startNode(params : NodeParams) : Node { - val config = createNodeConfig(params) + val config = getNodeConfig(params) val advertisedServices: Set val myNetAddr = HostAndPort.fromString(params.address).withDefaultPort(Node.DEFAULT_PORT) val networkMapId = if (params.mapAddress.equals(params.address)) {