mirror of
https://github.com/corda/corda.git
synced 2024-12-20 05:28:21 +00:00
Broke up the runIRSDemo function into smaller functions for readability.
This commit is contained in:
parent
560989a914
commit
5986e785cf
@ -103,60 +103,71 @@ fun runIRSDemo(args: Array<String>, demoNodeConfig: DemoConfig = DemoConfig()):
|
|||||||
BriefLogFormatter.initVerbose("+demo.irsdemo", "+api-call", "+platform.deal", "-org.apache.activemq")
|
BriefLogFormatter.initVerbose("+demo.irsdemo", "+api-call", "+platform.deal", "-org.apache.activemq")
|
||||||
|
|
||||||
val role = options.valueOf(demoArgs.roleArg)!!
|
val role = options.valueOf(demoArgs.roleArg)!!
|
||||||
if(role == IRSDemoRole.SetupNodeA) {
|
return when (role) {
|
||||||
val nodeParams = configureNodeParams(IRSDemoRole.NodeA, demoArgs, options)
|
IRSDemoRole.SetupNodeA -> setup(configureNodeParams(IRSDemoRole.NodeA, demoArgs, options))
|
||||||
setup(nodeParams)
|
IRSDemoRole.SetupNodeB -> setup(configureNodeParams(IRSDemoRole.NodeB, demoArgs, options))
|
||||||
} else if(role == IRSDemoRole.SetupNodeB) {
|
IRSDemoRole.NodeA -> runNode(role, demoArgs, options, demoNodeConfig)
|
||||||
val nodeParams = configureNodeParams(IRSDemoRole.NodeB, demoArgs, options)
|
IRSDemoRole.NodeB -> runNode(role, demoArgs, options, demoNodeConfig)
|
||||||
setup(nodeParams)
|
IRSDemoRole.Trade -> runTrade(demoArgs, options)
|
||||||
} else if(role == IRSDemoRole.Trade) {
|
IRSDemoRole.Date -> runDateChange(demoArgs, options)
|
||||||
val tradeIdArgs = options.valuesOf(demoArgs.nonOptions)
|
}
|
||||||
if (tradeIdArgs.size > 0) {
|
}
|
||||||
val tradeId = tradeIdArgs[0]
|
|
||||||
val host = if (options.has(demoArgs.networkAddressArg)) {
|
|
||||||
options.valueOf(demoArgs.networkAddressArg)
|
|
||||||
} else {
|
|
||||||
"http://localhost:" + (Node.DEFAULT_PORT + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!runTrade(tradeId, host)) {
|
private fun runTrade(demoArgs: DemoArgs, options: OptionSet): Int {
|
||||||
return 1
|
val tradeIdArgs = options.valuesOf(demoArgs.nonOptions)
|
||||||
}
|
if (tradeIdArgs.size > 0) {
|
||||||
|
val tradeId = tradeIdArgs[0]
|
||||||
|
val host = if (options.has(demoArgs.networkAddressArg)) {
|
||||||
|
options.valueOf(demoArgs.networkAddressArg)
|
||||||
} else {
|
} else {
|
||||||
println("Please provide a trade ID")
|
"http://localhost:" + (Node.DEFAULT_PORT + 1)
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
} else if(role == IRSDemoRole.Date) {
|
|
||||||
val dateStrArgs = options.valuesOf(demoArgs.nonOptions)
|
|
||||||
if (dateStrArgs.size > 0) {
|
|
||||||
val dateStr = dateStrArgs[0]
|
|
||||||
val host = if (options.has(demoArgs.networkAddressArg)) {
|
|
||||||
options.valueOf(demoArgs.networkAddressArg)
|
|
||||||
} else {
|
|
||||||
"http://localhost:" + (Node.DEFAULT_PORT + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!runDateChange(dateStr, host)) {
|
if (!uploadTrade(tradeId, host)) {
|
||||||
return 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println("Please provide a date")
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If these directory and identity file arguments aren't specified then we can assume a default setup and
|
println("Please provide a trade ID")
|
||||||
// create everything that is needed without needing to run setup.
|
return 1
|
||||||
if(!options.has(demoArgs.dirArg) && !options.has(demoArgs.fakeTradeWithIdentityFile)) {
|
}
|
||||||
createNodeConfig(createNodeAParams());
|
|
||||||
createNodeConfig(createNodeBParams());
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runDateChange(demoArgs: DemoArgs, options: OptionSet): Int {
|
||||||
|
val dateStrArgs = options.valuesOf(demoArgs.nonOptions)
|
||||||
|
if (dateStrArgs.size > 0) {
|
||||||
|
val dateStr = dateStrArgs[0]
|
||||||
|
val host = if (options.has(demoArgs.networkAddressArg)) {
|
||||||
|
options.valueOf(demoArgs.networkAddressArg)
|
||||||
|
} else {
|
||||||
|
"http://localhost:" + (Node.DEFAULT_PORT + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if(!changeDate(dateStr, host)) {
|
||||||
runNode(configureNodeParams(role, demoArgs, options), demoNodeConfig)
|
|
||||||
} catch (e: NotSetupException) {
|
|
||||||
println(e.message)
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
println("Please provide a date")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runNode(role: IRSDemoRole, demoArgs: DemoArgs, options: OptionSet, demoNodeConfig: DemoConfig): Int {
|
||||||
|
// 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
runNode(configureNodeParams(role, demoArgs, options), demoNodeConfig)
|
||||||
|
} catch (e: NotSetupException) {
|
||||||
|
println(e.message)
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -178,11 +189,12 @@ private fun setupArgs(parser: OptionParser): DemoArgs {
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setup(params: NodeParams) {
|
private fun setup(params: NodeParams): Int {
|
||||||
createNodeConfig(params)
|
createNodeConfig(params)
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runDateChange(date: String, host: String) : Boolean {
|
private fun changeDate(date: String, host: String) : Boolean {
|
||||||
println("Changing date to " + date)
|
println("Changing date to " + date)
|
||||||
val url = URL(host + "/api/irs/demodate")
|
val url = URL(host + "/api/irs/demodate")
|
||||||
if(putJson(url, "\"" + date + "\"")) {
|
if(putJson(url, "\"" + date + "\"")) {
|
||||||
@ -194,7 +206,7 @@ private fun runDateChange(date: String, host: String) : Boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runTrade(tradeId: String, host: String) : Boolean {
|
private fun uploadTrade(tradeId: String, host: String) : Boolean {
|
||||||
println("Uploading tradeID " + tradeId)
|
println("Uploading tradeID " + tradeId)
|
||||||
val fileContents = IOUtils.toString(NodeParams::class.java.getResourceAsStream("example-irs-trade.json"))
|
val fileContents = IOUtils.toString(NodeParams::class.java.getResourceAsStream("example-irs-trade.json"))
|
||||||
val tradeFile = fileContents.replace("tradeXXX", tradeId)
|
val tradeFile = fileContents.replace("tradeXXX", tradeId)
|
||||||
|
Loading…
Reference in New Issue
Block a user