mirror of
https://github.com/corda/corda.git
synced 2025-02-27 19:46:38 +00:00
Allow configuration of extra network services.
This commit is contained in:
parent
118d5eb48f
commit
5ee7930a16
@ -4,8 +4,15 @@ import com.typesafe.config.Config
|
|||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
import com.typesafe.config.ConfigValue
|
import com.typesafe.config.ConfigValue
|
||||||
import com.typesafe.config.ConfigValueFactory
|
import com.typesafe.config.ConfigValueFactory
|
||||||
|
import java.lang.String.join
|
||||||
|
|
||||||
class NodeConfig(legalName: String, artemisPort: Int, nearestCity: String, webPort: Int) : NetworkMapConfig(legalName, artemisPort){
|
class NodeConfig(
|
||||||
|
legalName: String,
|
||||||
|
artemisPort: Int,
|
||||||
|
nearestCity: String,
|
||||||
|
webPort: Int,
|
||||||
|
extraServices: List<String>
|
||||||
|
) : NetworkMapConfig(legalName, artemisPort) {
|
||||||
|
|
||||||
private var nearestCityName: String = nearestCity
|
private var nearestCityName: String = nearestCity
|
||||||
val nearestCity : String
|
val nearestCity : String
|
||||||
@ -15,6 +22,10 @@ class NodeConfig(legalName: String, artemisPort: Int, nearestCity: String, webPo
|
|||||||
val webPort : Int
|
val webPort : Int
|
||||||
get() { return webPortValue }
|
get() { return webPortValue }
|
||||||
|
|
||||||
|
private var extraServicesValue: List<String> = extraServices
|
||||||
|
val extraServices : List<String>
|
||||||
|
get() { return extraServicesValue }
|
||||||
|
|
||||||
private var networkMapValue: NetworkMapConfig? = null
|
private var networkMapValue: NetworkMapConfig? = null
|
||||||
var networkMap : NetworkMapConfig?
|
var networkMap : NetworkMapConfig?
|
||||||
get() { return networkMapValue }
|
get() { return networkMapValue }
|
||||||
@ -25,7 +36,7 @@ class NodeConfig(legalName: String, artemisPort: Int, nearestCity: String, webPo
|
|||||||
.withValue("myLegalName", valueFor(legalName))
|
.withValue("myLegalName", valueFor(legalName))
|
||||||
.withValue("artemisAddress", addressValueFor(artemisPort))
|
.withValue("artemisAddress", addressValueFor(artemisPort))
|
||||||
.withValue("nearestCity", valueFor(nearestCity))
|
.withValue("nearestCity", valueFor(nearestCity))
|
||||||
.withValue("extraAdvertisedServiceIds", valueFor(""))
|
.withValue("extraAdvertisedServiceIds", valueFor(join(",", extraServices)))
|
||||||
.withFallback(optional("networkMapService", networkMap, {
|
.withFallback(optional("networkMapService", networkMap, {
|
||||||
c, n -> c.withValue("address", addressValueFor(n.artemisPort))
|
c, n -> c.withValue("address", addressValueFor(n.artemisPort))
|
||||||
.withValue("legalName", valueFor(n.legalName))
|
.withValue("legalName", valueFor(n.legalName))
|
||||||
|
@ -33,7 +33,8 @@ class NodeController : Controller() {
|
|||||||
nodeData.legalName.value.trim(),
|
nodeData.legalName.value.trim(),
|
||||||
nodeData.artemisPort.value,
|
nodeData.artemisPort.value,
|
||||||
nodeData.nearestCity.value.trim(),
|
nodeData.nearestCity.value.trim(),
|
||||||
nodeData.webPort.value
|
nodeData.webPort.value,
|
||||||
|
nodeData.extraServices.value
|
||||||
)
|
)
|
||||||
|
|
||||||
if (nodes.putIfAbsent(config.key, config) != null) {
|
if (nodes.putIfAbsent(config.key, config) != null) {
|
||||||
@ -77,6 +78,7 @@ class NodeController : Controller() {
|
|||||||
confFile.writeText(fileData.root().render(renderOptions))
|
confFile.writeText(fileData.root().render(renderOptions))
|
||||||
|
|
||||||
pty.run(command, System.getenv(), nodeDir.toString())
|
pty.run(command, System.getenv(), nodeDir.toString())
|
||||||
|
log.info("Launched node: " + config.legalName)
|
||||||
return true
|
return true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.severe("Failed to launch Corda:" + e)
|
log.severe("Failed to launch Corda:" + e)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package net.corda.demobench.model
|
package net.corda.demobench.model
|
||||||
|
|
||||||
|
import tornadofx.observable
|
||||||
import javafx.beans.property.SimpleIntegerProperty
|
import javafx.beans.property.SimpleIntegerProperty
|
||||||
|
import javafx.beans.property.SimpleListProperty
|
||||||
import javafx.beans.property.SimpleStringProperty
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
|
||||||
class NodeData {
|
class NodeData {
|
||||||
@ -9,5 +11,6 @@ class NodeData {
|
|||||||
val nearestCity = SimpleStringProperty("London")
|
val nearestCity = SimpleStringProperty("London")
|
||||||
val artemisPort = SimpleIntegerProperty(0)
|
val artemisPort = SimpleIntegerProperty(0)
|
||||||
val webPort = SimpleIntegerProperty(0)
|
val webPort = SimpleIntegerProperty(0)
|
||||||
|
val extraServices = SimpleListProperty(mutableListOf<String>().observable())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package net.corda.demobench.model
|
||||||
|
|
||||||
|
import tornadofx.Controller
|
||||||
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class ServiceController : Controller() {
|
||||||
|
|
||||||
|
private var serviceSet : List<String>
|
||||||
|
|
||||||
|
val services : List<String>
|
||||||
|
get() = serviceSet
|
||||||
|
|
||||||
|
private fun loadConf(name: String): List<String> {
|
||||||
|
val set = HashSet<String>()
|
||||||
|
File(name).readLines().forEach {
|
||||||
|
val service = it.trim()
|
||||||
|
set.add(service)
|
||||||
|
|
||||||
|
log.info("Supports: " + service)
|
||||||
|
}
|
||||||
|
return set.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
/*
|
||||||
|
* Load our list of known extra Corda services.
|
||||||
|
*/
|
||||||
|
val serviceConf = javaClass.classLoader.getResource("services.conf")
|
||||||
|
serviceSet = if (serviceConf == null) {
|
||||||
|
emptyList<String>()
|
||||||
|
} else {
|
||||||
|
loadConf(serviceConf.file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package net.corda.demobench.views
|
package net.corda.demobench.views
|
||||||
|
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
import javafx.scene.control.SelectionMode.MULTIPLE
|
||||||
import javafx.util.converter.NumberStringConverter
|
import javafx.util.converter.NumberStringConverter
|
||||||
import net.corda.demobench.model.NodeController
|
import net.corda.demobench.model.NodeController
|
||||||
import net.corda.demobench.model.NodeDataModel
|
import net.corda.demobench.model.NodeDataModel
|
||||||
import net.corda.demobench.model.toKey
|
import net.corda.demobench.model.ServiceController
|
||||||
import net.corda.demobench.ui.CloseableTab
|
import net.corda.demobench.ui.CloseableTab
|
||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
@ -17,10 +18,11 @@ class NodeTabView : Fragment() {
|
|||||||
private val NOT_NUMBER = "[^\\d]".toRegex()
|
private val NOT_NUMBER = "[^\\d]".toRegex()
|
||||||
|
|
||||||
private val model = NodeDataModel()
|
private val model = NodeDataModel()
|
||||||
private val controller by inject<NodeController>()
|
private val nodeController by inject<NodeController>()
|
||||||
|
private val serviceController by inject<ServiceController>()
|
||||||
|
|
||||||
private val nodeTerminalView = find<NodeTerminalView>()
|
private val nodeTerminalView = find<NodeTerminalView>()
|
||||||
private val nodeConfigView = pane {
|
private val nodeConfigView = stackpane {
|
||||||
form {
|
form {
|
||||||
fieldset("Configuration") {
|
fieldset("Configuration") {
|
||||||
field("Node Name") {
|
field("Node Name") {
|
||||||
@ -34,7 +36,7 @@ class NodeTabView : Fragment() {
|
|||||||
val name = it.trim()
|
val name = it.trim()
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
error("Node name is required")
|
error("Node name is required")
|
||||||
} else if (controller.nameExists(name)) {
|
} else if (nodeController.nameExists(name)) {
|
||||||
error("Node with this name already exists")
|
error("Node with this name already exists")
|
||||||
} else if (name.length > 10) {
|
} else if (name.length > 10) {
|
||||||
error("Name is too long")
|
error("Name is too long")
|
||||||
@ -92,23 +94,29 @@ class NodeTabView : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldset("Plugins") {
|
fieldset("Services") {
|
||||||
|
listview(serviceController.services.observable()) {
|
||||||
|
selectionModel.selectionMode = MULTIPLE
|
||||||
|
model.item.extraServices.set(selectionModel.selectedItems)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button("Create Node") {
|
button("Create Node") {
|
||||||
setOnAction() {
|
setOnAction() {
|
||||||
|
if (model.validate()) {
|
||||||
launch()
|
launch()
|
||||||
main.enableAddNodes()
|
main.enableAddNodes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val nodeTab = CloseableTab("New Node", root)
|
val nodeTab = CloseableTab("New Node", root)
|
||||||
|
|
||||||
fun launch() {
|
fun launch() {
|
||||||
model.commit()
|
model.commit()
|
||||||
val config = controller.validate(model.item)
|
val config = nodeController.validate(model.item)
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
nodeConfigView.isVisible = false
|
nodeConfigView.isVisible = false
|
||||||
nodeTab.text = config.legalName
|
nodeTab.text = config.legalName
|
||||||
@ -134,7 +142,7 @@ class NodeTabView : Fragment() {
|
|||||||
root.add(nodeConfigView)
|
root.add(nodeConfigView)
|
||||||
root.add(nodeTerminalView)
|
root.add(nodeTerminalView)
|
||||||
|
|
||||||
model.artemisPort.value = controller.nextPort
|
model.artemisPort.value = nodeController.nextPort
|
||||||
model.webPort.value = controller.nextPort
|
model.webPort.value = nodeController.nextPort
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class NodeTerminalView : Fragment() {
|
|||||||
|
|
||||||
fun refreshTerminal() {
|
fun refreshTerminal() {
|
||||||
SwingUtilities.invokeLater {
|
SwingUtilities.invokeLater {
|
||||||
// TODO
|
// TODO - Force a repaint somehow? My naive attempts have not worked.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
tools/demobench/src/main/resources/services.conf
Normal file
3
tools/demobench/src/main/resources/services.conf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
corda.notary.validating
|
||||||
|
corda.notary.simple
|
||||||
|
corda.interest_rates
|
Loading…
x
Reference in New Issue
Block a user