Make Node override configuration and use FullNodeConfiguration so that no casting is needed

This commit is contained in:
Andrius Dagys 2016-10-05 14:49:18 +01:00
parent fac12b4fce
commit 3b187a2171
5 changed files with 19 additions and 25 deletions

View File

@ -72,7 +72,7 @@ import kotlin.reflect.KClass
// TODO: Where this node is the initial network map service, currently no networkMapService is provided.
// In theory the NodeInfo for the node should be passed in, instead, however currently this is constructed by the
// AbstractNode. It should be possible to generate the NodeInfo outside of AbstractNode, so it can be passed in.
abstract class AbstractNode(val configuration: NodeConfiguration, val networkMapService: SingleMessageRecipient?,
abstract class AbstractNode(open val configuration: NodeConfiguration, val networkMapService: SingleMessageRecipient?,
val advertisedServices: Set<ServiceInfo>, val platformClock: Clock) : SingletonSerializeAsToken() {
companion object {
val PRIVATE_KEY_FILE_NAME = "identity-private-key"

View File

@ -9,7 +9,6 @@ import com.r3corda.core.utilities.loggerFor
import com.r3corda.node.serialization.NodeClock
import com.r3corda.node.services.api.MessagingServiceInternal
import com.r3corda.node.services.config.FullNodeConfiguration
import com.r3corda.node.services.config.NodeConfiguration
import com.r3corda.node.services.messaging.ArtemisMessagingServer
import com.r3corda.node.services.messaging.CordaRPCOps
import com.r3corda.node.services.messaging.NodeMessagingClient
@ -60,7 +59,7 @@ class ConfigurationException(message: String) : Exception(message)
* @param messagingServerAddr The address of the Artemis broker instance. If not provided the node will run one locally.
*/
class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
configuration: NodeConfiguration, networkMapAddress: SingleMessageRecipient?,
override val configuration: FullNodeConfiguration, networkMapAddress: SingleMessageRecipient?,
advertisedServices: Set<ServiceInfo>, clock: Clock = NodeClock(),
val messagingServerAddr: HostAndPort? = null) : AbstractNode(configuration, networkMapAddress, advertisedServices, clock) {
companion object {
@ -163,7 +162,7 @@ class Node(val p2pAddr: HostAndPort, val webServerAddr: HostAndPort,
val server = Server()
if (configuration is FullNodeConfiguration && configuration.useHTTPS) {
if (configuration.useHTTPS) {
val httpsConfiguration = HttpConfiguration()
httpsConfiguration.outputBufferSize = 32768
httpsConfiguration.addCustomizer(SecureRequestCustomizer())

View File

@ -11,5 +11,6 @@ dataSourceProperties = {
"dataSource.password" = ""
}
devMode = true
hostNotaryServiceLocally = false
certificateSigningService = "https://cordaci-netperm.corda.r3cev.com"
useHTTPS = false

View File

@ -437,7 +437,7 @@ private fun runUploadRates(host: HostAndPort): ListenableFuture<Int> {
return result
}
private fun getNodeConfig(cliParams: CliParams.RunNode): NodeConfiguration {
private fun getNodeConfig(cliParams: CliParams.RunNode): FullNodeConfiguration {
if (!Files.exists(cliParams.dir)) {
throw NotSetupException("Missing config directory. Please run node setup before running the node")
}
@ -450,7 +450,7 @@ private fun getNodeConfig(cliParams: CliParams.RunNode): NodeConfiguration {
return loadConfigFile(cliParams.dir, configFile, cliParams.defaultLegalName)
}
private fun loadConfigFile(baseDir: Path, configFile: Path, defaultLegalName: String): NodeConfiguration {
private fun loadConfigFile(baseDir: Path, configFile: Path, defaultLegalName: String): FullNodeConfiguration {
if (!Files.exists(configFile)) {
createDefaultConfigFile(configFile, defaultLegalName)
log.warn("Default config created at $configFile.")

View File

@ -10,17 +10,15 @@ import com.r3corda.core.utilities.Emoji
import com.r3corda.core.utilities.LogHelper
import com.r3corda.demos.api.NodeInterestRates
import com.r3corda.node.internal.Node
import com.r3corda.node.services.config.FullNodeConfiguration
import com.r3corda.node.services.config.NodeConfiguration
import com.r3corda.node.services.messaging.NodeMessagingClient
import com.r3corda.protocols.RatesFixProtocol
import com.r3corda.testing.node.makeTestDataSourceProperties
import joptsimple.OptionParser
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.math.BigDecimal
import java.nio.file.Path
import java.nio.file.Paths
import java.util.*
import kotlin.system.exitProcess
private val log: Logger = LoggerFactory.getLogger("RatesFixDemo")
@ -60,25 +58,21 @@ fun main(args: Array<String>) {
val advertisedServices: Set<ServiceInfo> = emptySet()
val myNetAddr = HostAndPort.fromString(options.valueOf(networkAddressArg))
// TODO: create a base class that provides a default implementation
val config = object : NodeConfiguration {
override val basedir: Path = dir
override val myLegalName: String = "Rate fix demo node"
override val nearestCity: String = "Atlantis"
override val emailAddress: String = ""
override val devMode: Boolean = true
override val exportJMXto: String = "http"
override val keyStorePassword: String = "cordacadevpass"
override val trustStorePassword: String = "trustpass"
override val dataSourceProperties: Properties = makeTestDataSourceProperties()
}
val apiAddr = HostAndPort.fromParts(myNetAddr.hostText, myNetAddr.port + 1)
val config = NodeConfiguration.loadConfig(
baseDirectoryPath = dir,
allowMissingConfig = true,
configOverrides = mapOf(
"myLegalName" to "Rate fix demo node",
"basedir" to dir.normalize().toString()
)
)
val nodeConfiguration = FullNodeConfiguration(config)
val node = logElapsedTime("Node startup") {
Node(myNetAddr, apiAddr, config, networkMapAddr,
advertisedServices, DemoClock()).setup().start()
Node(myNetAddr, apiAddr, nodeConfiguration, networkMapAddr, advertisedServices, DemoClock()).setup().start()
}
node.networkMapRegistrationFuture.get()
val notaryNode = node.services.networkMapCache.notaryNodes[0]