mirror of
https://github.com/corda/corda.git
synced 2025-01-20 03:36:29 +00:00
[CORDA-879] Generate node directories as part of bootstrapping (#2285)
* Generate node directories as part of bootstrapping * Include latest corda.jar in bootstrapper package Remove SLF4J warnings on startup * Changes post review * More review changes * Review changes * Making docs clearer
This commit is contained in:
parent
ce4a640835
commit
1d66fe9296
@ -67,10 +67,21 @@ The bootstrapper tool can be built with the command:
|
||||
|
||||
The resulting jar can be found in ``tools/bootstrapper/build/libs/``.
|
||||
|
||||
To use it, run the following command, specifying the root directory which hosts all the node directories as the argument:
|
||||
To use it, create a directory containing a ``node.conf`` file for each node you want to create. Then run the following command:
|
||||
|
||||
``java -jar network-bootstrapper.jar <nodes-root-dir>``
|
||||
|
||||
For example running the command on a directory containing these files :
|
||||
|
||||
.. sourcecode:: none
|
||||
|
||||
.
|
||||
├── notary.conf // The notary's node.conf file
|
||||
├── partya.conf // Party A's node.conf file
|
||||
└── partyb.conf // Party B's node.conf file
|
||||
|
||||
Would generate directories containing three nodes: notary, partya and partyb.
|
||||
|
||||
Starting the nodes
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -19,6 +19,7 @@ import net.corda.nodeapi.internal.serialization.SerializationFactoryImpl
|
||||
import net.corda.nodeapi.internal.serialization.amqp.AMQPServerSerializationScheme
|
||||
import net.corda.nodeapi.internal.serialization.kryo.AbstractKryoSerializationScheme
|
||||
import net.corda.nodeapi.internal.serialization.kryo.KryoHeaderV0_1
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.StandardCopyOption
|
||||
@ -52,6 +53,7 @@ class NetworkBootstrapper {
|
||||
fun bootstrap(directory: Path) {
|
||||
directory.createDirectories()
|
||||
println("Bootstrapping local network in $directory")
|
||||
generateDirectoriesIfNeeded(directory)
|
||||
val nodeDirs = directory.list { paths -> paths.filter { (it / "corda.jar").exists() }.toList() }
|
||||
require(nodeDirs.isNotEmpty()) { "No nodes found" }
|
||||
println("Nodes found in the following sub-directories: ${nodeDirs.map { it.fileName }}")
|
||||
@ -73,6 +75,27 @@ class NetworkBootstrapper {
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateDirectoriesIfNeeded(directory: Path) {
|
||||
val confFiles = directory.list { it.filter { it.toString().endsWith(".conf") }.toList() }
|
||||
if (confFiles.isEmpty()) return
|
||||
println("Node config files found in the root directory - generating node directories")
|
||||
val cordaJar = extractCordaJarTo(directory)
|
||||
for (confFile in confFiles) {
|
||||
val nodeName = confFile.fileName.toString().removeSuffix(".conf")
|
||||
println("Generating directory for $nodeName")
|
||||
val nodeDir = (directory / nodeName).createDirectory()
|
||||
confFile.moveTo(nodeDir / "node.conf")
|
||||
Files.copy(cordaJar, (nodeDir / "corda.jar"))
|
||||
}
|
||||
Files.delete(cordaJar)
|
||||
}
|
||||
|
||||
private fun extractCordaJarTo(directory: Path): Path {
|
||||
val cordaJarPath = (directory / "corda.jar")
|
||||
Thread.currentThread().contextClassLoader.getResourceAsStream("corda.jar").copyTo(cordaJarPath)
|
||||
return cordaJarPath
|
||||
}
|
||||
|
||||
private fun startNodeInfoGeneration(nodeDirs: List<Path>): List<Process> {
|
||||
return nodeDirs.map { nodeDir ->
|
||||
val logsDir = (nodeDir / LOGS_DIR_NAME).createDirectories()
|
||||
@ -172,6 +195,7 @@ class NetworkBootstrapper {
|
||||
override fun canDeserializeVersion(byteSequence: ByteSequence, target: SerializationContext.UseCase): Boolean {
|
||||
return byteSequence == KryoHeaderV0_1 && target == SerializationContext.UseCase.P2P
|
||||
}
|
||||
|
||||
override fun rpcClientKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
|
||||
override fun rpcServerKryoPool(context: SerializationContext) = throw UnsupportedOperationException()
|
||||
}
|
||||
|
@ -6,7 +6,10 @@ configurations {
|
||||
runtimeArtifacts
|
||||
}
|
||||
|
||||
// TODO Fix SLF4J warnings that occur when running the bootstrapper
|
||||
dependencies {
|
||||
compile "org.slf4j:slf4j-nop:$slf4j_version"
|
||||
}
|
||||
|
||||
task buildBootstrapperJar(type: FatCapsule, dependsOn: project(':node-api').compileJava) {
|
||||
applicationClass 'net.corda.nodeapi.internal.network.NetworkBootstrapper'
|
||||
archiveName "network-bootstrapper.jar"
|
||||
@ -16,6 +19,9 @@ task buildBootstrapperJar(type: FatCapsule, dependsOn: project(':node-api').comp
|
||||
minJavaVersion = '1.8.0'
|
||||
jvmArgs = ['-XX:+UseG1GC']
|
||||
}
|
||||
from(project(':node:capsule').tasks['buildCordaJAR']) {
|
||||
rename 'corda-(.*)', 'corda.jar'
|
||||
}
|
||||
applicationSource = files(
|
||||
project(':node-api').configurations.runtime,
|
||||
project(':node-api').jar
|
||||
|
Loading…
Reference in New Issue
Block a user