mirror of
https://github.com/corda/corda.git
synced 2024-12-19 13:08:04 +00:00
Merged in nodedircreate (pull request #139)
Todo resolution: Moved node directory creation into the abstract node.
This commit is contained in:
commit
3e82ee45f2
@ -163,6 +163,14 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run any tasks that are needed to ensure the node is in a correct state before running start()
|
||||||
|
*/
|
||||||
|
open fun setup(): AbstractNode {
|
||||||
|
createNodeDir()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildAdvertisedServices() {
|
private fun buildAdvertisedServices() {
|
||||||
val serviceTypes = info.advertisedServices
|
val serviceTypes = info.advertisedServices
|
||||||
if (NetworkMapService.Type in serviceTypes) makeNetworkMapService()
|
if (NetworkMapService.Type in serviceTypes) makeNetworkMapService()
|
||||||
@ -327,4 +335,10 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
|
|||||||
}
|
}
|
||||||
return NodeAttachmentService(attachmentsDir, services.monitoringService.metrics)
|
return NodeAttachmentService(attachmentsDir, services.monitoringService.metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun createNodeDir() {
|
||||||
|
if (!Files.exists(dir)) {
|
||||||
|
Files.createDirectories(dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import org.glassfish.jersey.servlet.ServletContainer
|
|||||||
import java.io.RandomAccessFile
|
import java.io.RandomAccessFile
|
||||||
import java.lang.management.ManagementFactory
|
import java.lang.management.ManagementFactory
|
||||||
import java.nio.channels.FileLock
|
import java.nio.channels.FileLock
|
||||||
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
import javax.management.ObjectName
|
import javax.management.ObjectName
|
||||||
@ -152,6 +153,11 @@ class Node(dir: Path, val p2pAddr: HostAndPort, configuration: NodeConfiguration
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setup(): Node {
|
||||||
|
super.setup()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
override fun stop() {
|
override fun stop() {
|
||||||
webServer.stop()
|
webServer.stop()
|
||||||
super.stop()
|
super.stop()
|
||||||
@ -177,6 +183,7 @@ class Node(dir: Path, val p2pAddr: HostAndPort, configuration: NodeConfiguration
|
|||||||
println("Shut that other node down and try again. It may have process ID ${file.readText()}")
|
println("Shut that other node down and try again. It may have process ID ${file.readText()}")
|
||||||
System.exit(1)
|
System.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeFileLock = l
|
nodeFileLock = l
|
||||||
val ourProcessID: String = ManagementFactory.getRuntimeMXBean().name.split("@")[0]
|
val ourProcessID: String = ManagementFactory.getRuntimeMXBean().name.split("@")[0]
|
||||||
f.setLength(0)
|
f.setLength(0)
|
||||||
|
@ -122,7 +122,7 @@ class MockNetwork(private val networkSendManuallyPumped: Boolean = false,
|
|||||||
override val nearestCity: String = "Atlantis"
|
override val nearestCity: String = "Atlantis"
|
||||||
}
|
}
|
||||||
val node = nodeFactory.create(path, config, this, networkMapAddress, advertisedServices.toSet(), id, keyPair)
|
val node = nodeFactory.create(path, config, this, networkMapAddress, advertisedServices.toSet(), id, keyPair)
|
||||||
if (start) node.start()
|
if (start) node.setup().start()
|
||||||
_nodes.add(node)
|
_nodes.add(node)
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ private fun startNode(params : NodeParams) : Node {
|
|||||||
|
|
||||||
val node = logElapsedTime("Node startup") { Node(params.dir, myNetAddr, config, networkMapId,
|
val node = logElapsedTime("Node startup") { Node(params.dir, myNetAddr, config, networkMapId,
|
||||||
advertisedServices, DemoClock(),
|
advertisedServices, DemoClock(),
|
||||||
listOf(InterestRateSwapAPI::class.java)).start() }
|
listOf(InterestRateSwapAPI::class.java)).setup().start() }
|
||||||
|
|
||||||
// TODO: This should all be replaced by the identity service being updated
|
// TODO: This should all be replaced by the identity service being updated
|
||||||
// as the network map changes.
|
// as the network map changes.
|
||||||
|
@ -48,12 +48,7 @@ fun main(args: Array<String>) {
|
|||||||
// Suppress the Artemis MQ noise, and activate the demo logging.
|
// Suppress the Artemis MQ noise, and activate the demo logging.
|
||||||
BriefLogFormatter.initVerbose("+demo.ratefix", "-org.apache.activemq")
|
BriefLogFormatter.initVerbose("+demo.ratefix", "-org.apache.activemq")
|
||||||
|
|
||||||
// TODO: Move this into the AbstractNode class.
|
|
||||||
val dir = Paths.get(options.valueOf(dirArg))
|
val dir = Paths.get(options.valueOf(dirArg))
|
||||||
if (!Files.exists(dir)) {
|
|
||||||
Files.createDirectory(dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
val networkMapAddr = ArtemisMessagingService.makeRecipient(options.valueOf(networkMapAddrArg))
|
val networkMapAddr = ArtemisMessagingService.makeRecipient(options.valueOf(networkMapAddrArg))
|
||||||
val networkMapIdentity = Files.readAllBytes(Paths.get(options.valueOf(networkMapIdentityArg))).deserialize<Party>()
|
val networkMapIdentity = Files.readAllBytes(Paths.get(options.valueOf(networkMapIdentityArg))).deserialize<Party>()
|
||||||
val networkMapAddress = NodeInfo(networkMapAddr, networkMapIdentity)
|
val networkMapAddress = NodeInfo(networkMapAddr, networkMapIdentity)
|
||||||
@ -78,7 +73,7 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
val node = logElapsedTime("Node startup") { Node(dir, myNetAddr, config, networkMapAddress,
|
val node = logElapsedTime("Node startup") { Node(dir, myNetAddr, config, networkMapAddress,
|
||||||
advertisedServices, DemoClock(),
|
advertisedServices, DemoClock(),
|
||||||
listOf(InterestRateSwapAPI::class.java)).start() }
|
listOf(InterestRateSwapAPI::class.java)).setup().start() }
|
||||||
|
|
||||||
val notary = node.services.networkMapCache.notaryNodes[0]
|
val notary = node.services.networkMapCache.notaryNodes[0]
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ fun main(args: Array<String>) {
|
|||||||
// for protocols will change in future.
|
// for protocols will change in future.
|
||||||
BriefLogFormatter.initVerbose("+demo.buyer", "+demo.seller", "-org.apache.activemq")
|
BriefLogFormatter.initVerbose("+demo.buyer", "+demo.seller", "-org.apache.activemq")
|
||||||
|
|
||||||
val directory = setupDirectory(role)
|
val directory = Paths.get(DIRNAME, role.name.toLowerCase())
|
||||||
|
|
||||||
// Override the default config file (which you can find in the file "reference.conf") to give each node a name.
|
// Override the default config file (which you can find in the file "reference.conf") to give each node a name.
|
||||||
val config = run {
|
val config = run {
|
||||||
@ -131,7 +131,7 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
// And now construct then start the node object. It takes a little while.
|
// And now construct then start the node object. It takes a little while.
|
||||||
val node = logElapsedTime("Node startup") {
|
val node = logElapsedTime("Node startup") {
|
||||||
Node(directory, myNetAddr, config, networkMapId, advertisedServices).start()
|
Node(directory, myNetAddr, config, networkMapId, advertisedServices).setup().start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Replace with a separate trusted cash issuer
|
// TODO: Replace with a separate trusted cash issuer
|
||||||
@ -149,12 +149,6 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setupDirectory(mode: Role): Path {
|
|
||||||
val directory = Paths.get(DIRNAME, mode.name.toLowerCase())
|
|
||||||
Files.createDirectories(directory)
|
|
||||||
return directory
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseOptions(args: Array<String>, parser: OptionParser): OptionSet {
|
fun parseOptions(args: Array<String>, parser: OptionParser): OptionSet {
|
||||||
try {
|
try {
|
||||||
return parser.parse(*args)
|
return parser.parse(*args)
|
||||||
|
Loading…
Reference in New Issue
Block a user