mirror of
https://github.com/corda/corda.git
synced 2025-02-27 11:36:42 +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.ConfigValue
|
||||
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
|
||||
val nearestCity : String
|
||||
@ -15,6 +22,10 @@ class NodeConfig(legalName: String, artemisPort: Int, nearestCity: String, webPo
|
||||
val webPort : Int
|
||||
get() { return webPortValue }
|
||||
|
||||
private var extraServicesValue: List<String> = extraServices
|
||||
val extraServices : List<String>
|
||||
get() { return extraServicesValue }
|
||||
|
||||
private var networkMapValue: NetworkMapConfig? = null
|
||||
var networkMap : NetworkMapConfig?
|
||||
get() { return networkMapValue }
|
||||
@ -25,7 +36,7 @@ class NodeConfig(legalName: String, artemisPort: Int, nearestCity: String, webPo
|
||||
.withValue("myLegalName", valueFor(legalName))
|
||||
.withValue("artemisAddress", addressValueFor(artemisPort))
|
||||
.withValue("nearestCity", valueFor(nearestCity))
|
||||
.withValue("extraAdvertisedServiceIds", valueFor(""))
|
||||
.withValue("extraAdvertisedServiceIds", valueFor(join(",", extraServices)))
|
||||
.withFallback(optional("networkMapService", networkMap, {
|
||||
c, n -> c.withValue("address", addressValueFor(n.artemisPort))
|
||||
.withValue("legalName", valueFor(n.legalName))
|
||||
|
@ -33,7 +33,8 @@ class NodeController : Controller() {
|
||||
nodeData.legalName.value.trim(),
|
||||
nodeData.artemisPort.value,
|
||||
nodeData.nearestCity.value.trim(),
|
||||
nodeData.webPort.value
|
||||
nodeData.webPort.value,
|
||||
nodeData.extraServices.value
|
||||
)
|
||||
|
||||
if (nodes.putIfAbsent(config.key, config) != null) {
|
||||
@ -77,6 +78,7 @@ class NodeController : Controller() {
|
||||
confFile.writeText(fileData.root().render(renderOptions))
|
||||
|
||||
pty.run(command, System.getenv(), nodeDir.toString())
|
||||
log.info("Launched node: " + config.legalName)
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
log.severe("Failed to launch Corda:" + e)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.corda.demobench.model
|
||||
|
||||
import tornadofx.observable
|
||||
import javafx.beans.property.SimpleIntegerProperty
|
||||
import javafx.beans.property.SimpleListProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
|
||||
class NodeData {
|
||||
@ -9,5 +11,6 @@ class NodeData {
|
||||
val nearestCity = SimpleStringProperty("London")
|
||||
val artemisPort = 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
|
||||
|
||||
import java.text.DecimalFormat
|
||||
import javafx.scene.control.SelectionMode.MULTIPLE
|
||||
import javafx.util.converter.NumberStringConverter
|
||||
import net.corda.demobench.model.NodeController
|
||||
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 tornadofx.*
|
||||
|
||||
@ -17,10 +18,11 @@ class NodeTabView : Fragment() {
|
||||
private val NOT_NUMBER = "[^\\d]".toRegex()
|
||||
|
||||
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 nodeConfigView = pane {
|
||||
private val nodeConfigView = stackpane {
|
||||
form {
|
||||
fieldset("Configuration") {
|
||||
field("Node Name") {
|
||||
@ -34,7 +36,7 @@ class NodeTabView : Fragment() {
|
||||
val name = it.trim()
|
||||
if (name.isEmpty()) {
|
||||
error("Node name is required")
|
||||
} else if (controller.nameExists(name)) {
|
||||
} else if (nodeController.nameExists(name)) {
|
||||
error("Node with this name already exists")
|
||||
} else if (name.length > 10) {
|
||||
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") {
|
||||
setOnAction() {
|
||||
if (model.validate()) {
|
||||
launch()
|
||||
main.enableAddNodes()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val nodeTab = CloseableTab("New Node", root)
|
||||
|
||||
fun launch() {
|
||||
model.commit()
|
||||
val config = controller.validate(model.item)
|
||||
val config = nodeController.validate(model.item)
|
||||
if (config != null) {
|
||||
nodeConfigView.isVisible = false
|
||||
nodeTab.text = config.legalName
|
||||
@ -134,7 +142,7 @@ class NodeTabView : Fragment() {
|
||||
root.add(nodeConfigView)
|
||||
root.add(nodeTerminalView)
|
||||
|
||||
model.artemisPort.value = controller.nextPort
|
||||
model.webPort.value = controller.nextPort
|
||||
model.artemisPort.value = nodeController.nextPort
|
||||
model.webPort.value = nodeController.nextPort
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class NodeTerminalView : Fragment() {
|
||||
|
||||
fun refreshTerminal() {
|
||||
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