Prevent node from starting across upgrades (until we support it better) (#199)

* Prevent node from starting across upgrades (until we support it better).

On first run a version file is created in the node dir, and on subsequent runs the node version is matched against it.

* Move version check from caplet to node.
This commit is contained in:
Andrius Dagys
2017-02-02 18:21:00 +00:00
committed by GitHub
parent 087570e74d
commit 56dbf1e844
2 changed files with 25 additions and 0 deletions

View File

@ -31,6 +31,8 @@ import org.jetbrains.exposed.sql.Database
import java.io.RandomAccessFile
import java.lang.management.ManagementFactory
import java.nio.channels.FileLock
import java.nio.file.Files
import java.nio.file.Paths
import java.time.Clock
import javax.management.ObjectName
import javax.servlet.*
@ -100,6 +102,27 @@ class Node(override val configuration: FullNodeConfiguration,
private lateinit var userService: RPCUserService
init {
checkVersionUnchanged()
}
/**
* Abort starting the node if an existing deployment with a different version is detected in the current directory.
* The current version is expected to be specified as a system property. If not provided, the check will be ignored.
*/
private fun checkVersionUnchanged() {
val currentVersion = System.getProperty("corda.version") ?: return
val versionFile = Paths.get("version")
if (Files.exists(versionFile)) {
val existingVersion = Files.readAllLines(versionFile)[0]
check(existingVersion == currentVersion) {
"Version change detected - current: $currentVersion, existing: $existingVersion. Node upgrades are not yet supported."
}
} else {
Files.write(versionFile, currentVersion.toByteArray())
}
}
override fun makeMessagingService(): MessagingServiceInternal {
userService = RPCUserServiceImpl(configuration)