From 3e98efe04b031ae50018be74fec3094a3570c534 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Thu, 14 Jun 2018 15:23:45 +0100 Subject: [PATCH] Delete the network visualiser sample. It's very old and the build is strange and breaks in odd ways when Gradle runs in parallel. We haven't used it for a long time and have better demos these days anyway --- samples/network-visualiser/README.md | 13 - samples/network-visualiser/build.gradle | 78 ---- .../net/corda/netmap/NetworkMapVisualiser.kt | 359 ------------------ .../net/corda/netmap/VisualiserUtils.kt | 18 - .../kotlin/net/corda/netmap/VisualiserView.kt | 305 --------------- .../net/corda/netmap/VisualiserViewModel.kt | 225 ----------- .../corda/netmap/simulation/IRSSimulation.kt | 172 --------- .../net/corda/netmap/simulation/Simulation.kt | 205 ---------- .../net/corda/irs/web/simulation/trade.json | 89 ----- .../resources/net/corda/netmap/Corda logo.png | Bin 17274 -> 0 bytes .../resources/net/corda/netmap/Europe.jpg | Bin 309247 -> 0 bytes .../net/corda/netmap/MainWindow.fxml | 26 -- .../corda/netmap/SIL Open Font License.txt | 43 --- .../net/corda/netmap/SourceSansPro-Black.otf | Bin 234176 -> 0 bytes .../corda/netmap/SourceSansPro-BlackIt.otf | Bin 81120 -> 0 bytes .../net/corda/netmap/SourceSansPro-Bold.otf | Bin 235128 -> 0 bytes .../net/corda/netmap/SourceSansPro-BoldIt.otf | Bin 80392 -> 0 bytes .../corda/netmap/SourceSansPro-ExtraLight.otf | Bin 221580 -> 0 bytes .../netmap/SourceSansPro-ExtraLightIt.otf | Bin 76400 -> 0 bytes .../net/corda/netmap/SourceSansPro-It.otf | Bin 79724 -> 0 bytes .../net/corda/netmap/SourceSansPro-Light.otf | Bin 226032 -> 0 bytes .../corda/netmap/SourceSansPro-LightIt.otf | Bin 77816 -> 0 bytes .../corda/netmap/SourceSansPro-Regular.otf | Bin 229588 -> 0 bytes .../corda/netmap/SourceSansPro-Semibold.otf | Bin 232680 -> 0 bytes .../corda/netmap/SourceSansPro-SemiboldIt.otf | Bin 80316 -> 0 bytes .../resources/net/corda/netmap/WorldMap.png | Bin 349746 -> 0 bytes .../net/corda/netmap/WorldMapSquare.png | Bin 480246 -> 0 bytes .../resources/net/corda/netmap/styles.css | 228 ----------- .../netmap/simulation/IRSSimulationTest.kt | 19 - settings.gradle | 1 - 30 files changed, 1781 deletions(-) delete mode 100644 samples/network-visualiser/README.md delete mode 100644 samples/network-visualiser/build.gradle delete mode 100644 samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt delete mode 100644 samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserUtils.kt delete mode 100644 samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserView.kt delete mode 100644 samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserViewModel.kt delete mode 100644 samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/IRSSimulation.kt delete mode 100644 samples/network-visualiser/src/main/kotlin/net/corda/netmap/simulation/Simulation.kt delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/irs/web/simulation/trade.json delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/Corda logo.png delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/Europe.jpg delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/MainWindow.fxml delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SIL Open Font License.txt delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-Black.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-BlackIt.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-Bold.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-BoldIt.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-ExtraLight.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-ExtraLightIt.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-It.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-Light.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-LightIt.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-Regular.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-Semibold.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/SourceSansPro-SemiboldIt.otf delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/WorldMap.png delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/WorldMapSquare.png delete mode 100644 samples/network-visualiser/src/main/resources/net/corda/netmap/styles.css delete mode 100644 samples/network-visualiser/src/test/kotlin/net/corda/netmap/simulation/IRSSimulationTest.kt diff --git a/samples/network-visualiser/README.md b/samples/network-visualiser/README.md deleted file mode 100644 index 4e9f9f8350..0000000000 --- a/samples/network-visualiser/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Network Visualiser - -This package contains a network visualiser that uses a simulation to visualise the interaction and messages between nodes on the Corda network. - -Please see the either the [online documentation](https://docs.corda.net/network-simulator.html) for more info on the network visualiser, or the [included offline version](../../docs/build/html/network-simulator.html). - -From the root directory of the repository, run it like this (Windows): - - gradle samples:network-visualiser:run - -or (Mac / Unix) - - ./gradlew samples:network-visualiser:run \ No newline at end of file diff --git a/samples/network-visualiser/build.gradle b/samples/network-visualiser/build.gradle deleted file mode 100644 index b45f06246f..0000000000 --- a/samples/network-visualiser/build.gradle +++ /dev/null @@ -1,78 +0,0 @@ -buildscript { - ext { - springBootVersion = '1.5.7.RELEASE' - } - repositories { - mavenCentral() - } - dependencies { - classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion" - classpath "io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE" - } -} - -// Spring Boot plugin adds a numerous hardcoded dependencies in the version much lower then Corda expects -// causing the problems in runtime. Those can be changed by manipulating above properties -// See https://github.com/spring-gradle-plugins/dependency-management-plugin/blob/master/README.md#changing-the-value-of-a-version-property -// This has to be repeated here as otherwise the order of files does matter -ext['artemis.version'] = "$artemis_version" -ext['hibernate.version'] = "$hibernate_version" -ext['jackson.version'] = "$jackson_version" -ext['dropwizard-metrics.version'] = "$metrics_version" -ext['mockito.version'] = "$mockito_version" - -apply plugin: 'java' -apply plugin: 'kotlin' -apply plugin: 'idea' -apply plugin: 'application' -apply plugin: 'org.springframework.boot' -apply plugin: 'net.corda.plugins.quasar-utils' -apply plugin: 'us.kirchmeier.capsule' - -// Spring Boot plugin have to be reimported, however it picks up the settings from irs-demo, so there is no need to -// reconfigure - -// Warning: The network visualiser is not a Cordapp so please do not use it as an example of how -// to build a cordapp - -dependencies { - testCompile "junit:junit:$junit_version" - - // Corda integration dependencies - compile project(path: ":node:capsule", configuration: 'runtimeArtifacts') - compile project(path: ":webserver:webcapsule", configuration: 'runtimeArtifacts') - compile project(':core') - compile project(':finance') - compile project(':node-driver') - compile project(':finance') - compile project(':samples:irs-demo') - - // GraphStream: For visualisation - compileOnly "co.paralleluniverse:capsule:$capsule_version" -} - -idea { - module { - downloadJavadoc = true // defaults to false - downloadSources = true - } -} - -mainClassName = 'net.corda.netmap.NetworkMapVisualiser' - -task deployVisualiser(type: FatCapsule) { - applicationClass 'net.corda.netmap.NetworkMapVisualiser' - reallyExecutable - capsuleManifest { - minJavaVersion = '1.8.0' - javaAgents = [configurations.quasar.singleFile.name] - } -} - -jar { - manifest { - attributes( - 'Automatic-Module-Name': 'net.corda.samples.network.visualiser' - ) - } -} diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt deleted file mode 100644 index 161264eb36..0000000000 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/NetworkMapVisualiser.kt +++ /dev/null @@ -1,359 +0,0 @@ -package net.corda.netmap - -import javafx.animation.* -import javafx.application.Application -import javafx.application.Platform -import javafx.beans.property.SimpleDoubleProperty -import javafx.beans.value.WritableValue -import javafx.geometry.Insets -import javafx.scene.input.KeyCode -import javafx.scene.input.KeyCodeCombination -import javafx.scene.layout.VBox -import javafx.stage.Stage -import javafx.util.Duration -import net.corda.core.serialization.deserialize -import net.corda.core.utilities.ProgressTracker -import net.corda.netmap.VisualiserViewModel.Style -import net.corda.netmap.simulation.IRSSimulation -import net.corda.node.services.statemachine.* -import net.corda.testing.core.singleIdentity -import net.corda.testing.node.InMemoryMessagingNetwork -import net.corda.testing.node.internal.InternalMockNetwork -import rx.Scheduler -import rx.schedulers.Schedulers -import java.time.format.DateTimeFormatter -import java.time.format.FormatStyle -import java.util.* -import kotlin.concurrent.schedule -import kotlin.concurrent.scheduleAtFixedRate -import kotlin.system.exitProcess - -fun WritableValue.keyValue(endValue: T, interpolator: Interpolator = Interpolator.EASE_OUT) = KeyValue(this, endValue, interpolator) - -// TODO: This code is all horribly ugly. Refactor to use TornadoFX to clean it up. - -class NetworkMapVisualiser : Application() { - enum class NodeType { - BANK, SERVICE - } - - enum class RunPauseButtonLabel { - RUN, PAUSE; - - override fun toString(): String { - return name.toLowerCase().capitalize() - } - } - - sealed class RunningPausedState { - class Running(val tickTimer: TimerTask) : RunningPausedState() - class Paused : RunningPausedState() - - val buttonLabel: RunPauseButtonLabel - get() { - return when (this) { - is RunningPausedState.Running -> RunPauseButtonLabel.PAUSE - is RunningPausedState.Paused -> RunPauseButtonLabel.RUN - } - } - } - - private val view = VisualiserView() - private val viewModel = VisualiserViewModel() - - val timer = Timer() - val uiThread: Scheduler = Schedulers.from { Platform.runLater(it) } - - override fun start(stage: Stage) { - viewModel.view = view - viewModel.presentationMode = "--presentation-mode" in parameters.raw - buildScene(stage) - viewModel.displayStyle = if ("--circle" in parameters.raw) { - Style.CIRCLE - } else { - viewModel.displayStyle - } - - val simulation = viewModel.simulation - // Update the white-backgrounded label indicating what flow step it's up to. - simulation.allFlowSteps.observeOn(uiThread).subscribe { (node, change) -> - val label = viewModel.nodesToWidgets[node]!!.statusLabel - if (change is ProgressTracker.Change.Position) { - // Fade in the status label if it's our first step. - if (label.text == "") { - with(FadeTransition(Duration(150.0), label)) { - fromValue = 0.0 - toValue = 1.0 - play() - } - } - label.text = change.newStep.label - if (change.newStep == ProgressTracker.DONE && change.tracker == change.tracker.topLevelTracker) { - runLater(500, -1) { - // Fade out the status label. - with(FadeTransition(Duration(750.0), label)) { - fromValue = 1.0 - toValue = 0.0 - setOnFinished { label.text = "" } - play() - } - } - } - } else if (change is ProgressTracker.Change.Rendering) { - label.text = change.ofStep.label - } - } - // Fire the message bullets between nodes. - simulation.mockNet.messagingNetwork.sentMessages.observeOn(uiThread).subscribe { msg: InMemoryMessagingNetwork.MessageTransfer -> - val senderNode: InternalMockNetwork.MockNode = simulation.mockNet.addressToNode(msg.sender) - val destNode: InternalMockNetwork.MockNode = simulation.mockNet.addressToNode(msg.recipients) - - if (transferIsInteresting(msg)) { - viewModel.nodesToWidgets[senderNode]!!.pulseAnim.play() - viewModel.fireBulletBetweenNodes(senderNode, destNode, "bank", "bank") - } - } - // Pulse all parties in a trade when the trade completes - simulation.doneSteps.observeOn(uiThread).subscribe { nodes: Collection -> - nodes.forEach { viewModel.nodesToWidgets[it]!!.longPulseAnim.play() } - } - - stage.setOnCloseRequest { exitProcess(0) } - //stage.isMaximized = true - stage.show() - } - - fun runLater(startAfter: Int, delayBetween: Int, body: () -> Unit) { - if (delayBetween != -1) { - timer.scheduleAtFixedRate(startAfter.toLong(), delayBetween.toLong()) { - Platform.runLater { - body() - } - } - } else { - timer.schedule(startAfter.toLong()) { - Platform.runLater { - body() - } - } - } - } - - private fun buildScene(stage: Stage) { - view.stage = stage - view.setup(viewModel.runningPausedState, viewModel.displayStyle, viewModel.presentationMode) - bindSidebar() - bindTopbar() - viewModel.createNodes() - - // Spacebar advances simulation by one step. - stage.scene.accelerators[KeyCodeCombination(KeyCode.SPACE)] = Runnable { onNextInvoked() } - - reloadStylesheet(stage) - - stage.focusedProperty().addListener { _, _, new -> - if (new) { - reloadStylesheet(stage) - } - } - } - - private fun bindTopbar() { - view.resetButton.setOnAction({ reset() }) - view.nextButton.setOnAction { - if (!view.simulateInitialisationCheckbox.isSelected && !viewModel.simulation.networkInitialisationFinished.isDone) { - skipNetworkInitialisation() - } else { - onNextInvoked() - } - } - viewModel.simulation.networkInitialisationFinished.thenAccept { - view.simulateInitialisationCheckbox.isVisible = false - } - view.runPauseButton.setOnAction { - val oldRunningPausedState = viewModel.runningPausedState - val newRunningPausedState = when (oldRunningPausedState) { - is NetworkMapVisualiser.RunningPausedState.Running -> { - oldRunningPausedState.tickTimer.cancel() - - view.nextButton.isDisable = false - view.resetButton.isDisable = false - - NetworkMapVisualiser.RunningPausedState.Paused() - } - is NetworkMapVisualiser.RunningPausedState.Paused -> { - val tickTimer = timer.scheduleAtFixedRate(viewModel.stepDuration.toMillis().toLong(), viewModel.stepDuration.toMillis().toLong()) { - Platform.runLater { - onNextInvoked() - } - } - - view.nextButton.isDisable = true - view.resetButton.isDisable = true - - if (!view.simulateInitialisationCheckbox.isSelected && !viewModel.simulation.networkInitialisationFinished.isDone) { - skipNetworkInitialisation() - } - - NetworkMapVisualiser.RunningPausedState.Running(tickTimer) - } - } - - view.runPauseButton.text = newRunningPausedState.buttonLabel.toString() - viewModel.runningPausedState = newRunningPausedState - } - view.styleChoice.selectionModel.selectedItemProperty() - .addListener { _, _, newValue -> viewModel.displayStyle = newValue } - viewModel.simulation.dateChanges.observeOn(uiThread).subscribe { view.dateLabel.text = it.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)) } - } - - private fun reloadStylesheet(stage: Stage) { - stage.scene.stylesheets.clear() - stage.scene.stylesheets.add(NetworkMapVisualiser::class.java.getResource("styles.css").toString()) - } - - private fun bindSidebar() { - viewModel.simulation.allFlowSteps.observeOn(uiThread).subscribe { (node, change) -> - if (change is ProgressTracker.Change.Position) { - val tracker = change.tracker.topLevelTracker - if (change.newStep == ProgressTracker.DONE) { - if (change.tracker == tracker) { - // Flow done; schedule it for removal in a few seconds. We batch them up to make nicer - // animations. - updateProgressTrackerWidget(change) - println("Flow done for ${node.started!!.info.singleIdentity().name}") - viewModel.doneTrackers += tracker - } else { - // Subflow is done; ignore it. - } - } else if (!viewModel.trackerBoxes.containsKey(tracker)) { - // New flow started up; add. - val extraLabel = viewModel.simulation.extraNodeLabels[node] - val label = node.started!!.info.singleIdentity().name.organisation.let { if (extraLabel != null) "$it: $extraLabel" else it } - val widget = view.buildProgressTrackerWidget(label, tracker.topLevelTracker) - println("Added: $tracker, $widget") - viewModel.trackerBoxes[tracker] = widget - view.sidebar.children += widget.vbox - } else { - updateProgressTrackerWidget(change) - } - } else if (change is ProgressTracker.Change.Structural) { - updateProgressTrackerWidget(change) - } - } - - Timer().scheduleAtFixedRate(0, 500) { - Platform.runLater { - for (tracker in viewModel.doneTrackers) { - val pane = viewModel.trackerBoxes[tracker]!!.vbox - // Slide the other tracker widgets up and over this one. - val slideProp = SimpleDoubleProperty(0.0) - slideProp.addListener { _ -> pane.padding = Insets(0.0, 0.0, slideProp.value, 0.0) } - val timeline = Timeline( - KeyFrame(Duration(250.0), - KeyValue(pane.opacityProperty(), 0.0), - KeyValue(slideProp, -pane.height - 50.0) // Subtract the bottom padding gap. - ) - ) - timeline.setOnFinished { - println("Removed: $tracker") - val vbox = viewModel.trackerBoxes.remove(tracker)?.vbox - view.sidebar.children.remove(vbox) - } - timeline.play() - } - viewModel.doneTrackers.clear() - } - } - } - - private fun updateProgressTrackerWidget(step: ProgressTracker.Change) { - if (step is ProgressTracker.Change.Position) { - // Animate the cursor to the right place. - Platform.runLater { - val tracker: ProgressTracker = step.tracker.topLevelTracker - val widget = viewModel.trackerBoxes[tracker] ?: return@runLater - val allSteps: List> = tracker.allSteps - - // Figure out the index of the new step. - val curStep = allSteps.indexOfFirst { it.second == step.newStep } - with(TranslateTransition(Duration(350.0), widget.cursor)) { - fromY = widget.cursor.translateY - toY = (curStep * view.sideBarStepHeight) + (view.sideBarStepHeight / 2.0) - play() - } - } - } else if (step is ProgressTracker.Change.Structural) { - Platform.runLater { - val tracker: ProgressTracker = step.tracker.topLevelTracker - val widget = viewModel.trackerBoxes[tracker] ?: return@runLater - val new = view.buildProgressTrackerWidget(widget.label.text, tracker) - val prevWidget = viewModel.trackerBoxes[tracker]?.vbox ?: throw AssertionError("No previous widget for tracker: $tracker") - val i = (prevWidget.parent as VBox).children.indexOf(viewModel.trackerBoxes[tracker]?.vbox) - (prevWidget.parent as VBox).children[i] = new.vbox - viewModel.trackerBoxes[tracker] = new - } - } - } - - var started = false - private fun startSimulation() { - if (!started) { - viewModel.simulation.start() - started = true - } - } - - private fun reset() { - viewModel.simulation.stop() - viewModel.simulation = IRSSimulation(true, false, null) - started = false - start(view.stage) - } - - private fun skipNetworkInitialisation() { - startSimulation() - while (!viewModel.simulation.networkInitialisationFinished.isDone) { - iterateSimulation() - } - } - - private fun onNextInvoked() { - if (started) { - iterateSimulation() - } else { - startSimulation() - } - } - - private fun iterateSimulation() { - // Loop until either we ran out of things to do, or we sent an interesting message. - while (true) { - val transfer: InMemoryMessagingNetwork.MessageTransfer = viewModel.simulation.iterate() ?: break - if (transferIsInteresting(transfer)) - break - else - System.err.println("skipping boring $transfer") - } - } - - private fun transferIsInteresting(transfer: InMemoryMessagingNetwork.MessageTransfer): Boolean { - // Loopback messages are boring. - if (transfer.sender == transfer.recipients) return false - val message = transfer.messageData.deserialize() - return when (message) { - is InitialSessionMessage -> message.firstPayload != null - is ExistingSessionMessage -> when (message.payload) { - is ConfirmSessionMessage -> false - is DataSessionMessage -> true - is ErrorSessionMessage -> true - is RejectSessionMessage -> true - is EndSessionMessage -> false - } - } - } -} - -fun main(args: Array) { - Application.launch(NetworkMapVisualiser::class.java, *args) -} diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserUtils.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserUtils.kt deleted file mode 100644 index 8fc0ab99d7..0000000000 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserUtils.kt +++ /dev/null @@ -1,18 +0,0 @@ -package net.corda.netmap - -import javafx.scene.paint.Color - -internal -fun colorToRgb(color: Color): String { - val builder = StringBuilder() - - builder.append("rgb(") - builder.append(Math.round(color.red * 256)) - builder.append(",") - builder.append(Math.round(color.green * 256)) - builder.append(",") - builder.append(Math.round(color.blue * 256)) - builder.append(")") - - return builder.toString() -} \ No newline at end of file diff --git a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserView.kt b/samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserView.kt deleted file mode 100644 index e6ba2d4ac2..0000000000 --- a/samples/network-visualiser/src/main/kotlin/net/corda/netmap/VisualiserView.kt +++ /dev/null @@ -1,305 +0,0 @@ -package net.corda.netmap - -import javafx.animation.KeyFrame -import javafx.animation.Timeline -import javafx.application.Platform -import javafx.collections.FXCollections -import javafx.event.EventHandler -import javafx.geometry.Insets -import javafx.geometry.Pos -import javafx.scene.Group -import javafx.scene.Node -import javafx.scene.Scene -import javafx.scene.control.* -import javafx.scene.image.Image -import javafx.scene.image.ImageView -import javafx.scene.input.ZoomEvent -import javafx.scene.layout.* -import javafx.scene.paint.Color -import javafx.scene.shape.Polygon -import javafx.scene.text.Font -import javafx.stage.Stage -import javafx.util.Duration -import net.corda.core.utilities.ProgressTracker -import net.corda.netmap.VisualiserViewModel.Style - -data class TrackerWidget(val vbox: VBox, val cursorBox: Pane, val label: Label, val cursor: Polygon) - -internal class VisualiserView { - lateinit var root: Pane - lateinit var stage: Stage - lateinit var splitter: SplitPane - lateinit var sidebar: VBox - lateinit var resetButton: Button - lateinit var nextButton: Button - lateinit var runPauseButton: Button - lateinit var simulateInitialisationCheckbox: CheckBox - lateinit var styleChoice: ChoiceBox