mirror of
https://github.com/corda/corda.git
synced 2024-12-21 22:07:55 +00:00
Runnodes now works with the new separate webserver.
This commit is contained in:
parent
537ffae113
commit
13551a6b23
@ -145,7 +145,6 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['build']) {
|
|||||||
nearestCity "London"
|
nearestCity "London"
|
||||||
advertisedServices = ["corda.notary.validating"]
|
advertisedServices = ["corda.notary.validating"]
|
||||||
artemisPort 10002
|
artemisPort 10002
|
||||||
webPort 10003
|
|
||||||
cordapps = []
|
cordapps = []
|
||||||
}
|
}
|
||||||
node {
|
node {
|
||||||
|
@ -69,6 +69,10 @@ task buildCordaJAR(type: FatCapsule, dependsOn: ['buildCertSigningRequestUtility
|
|||||||
// If you change these flags, please also update Driver.kt
|
// If you change these flags, please also update Driver.kt
|
||||||
jvmArgs = ['-Xmx200m', '-XX:+UseG1GC']
|
jvmArgs = ['-Xmx200m', '-XX:+UseG1GC']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
manifest {
|
||||||
|
attributes('Corda-Version': corda_version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildCertSigningRequestUtilityJAR(type: FatCapsule) {
|
task buildCertSigningRequestUtilityJAR(type: FatCapsule) {
|
||||||
|
@ -58,7 +58,8 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
drawBanner()
|
drawBanner()
|
||||||
|
|
||||||
System.setProperty("log-path", (cmdlineOptions.baseDirectory / "logs").toString())
|
val logDir = if (cmdlineOptions.isWebserver) "logs/web" else "logs"
|
||||||
|
System.setProperty("log-path", (cmdlineOptions.baseDirectory / logDir).toString())
|
||||||
|
|
||||||
val log = LoggerFactory.getLogger("Main")
|
val log = LoggerFactory.getLogger("Main")
|
||||||
printBasicNodeInfo("Logs can be found in", System.getProperty("log-path"))
|
printBasicNodeInfo("Logs can be found in", System.getProperty("log-path"))
|
||||||
@ -79,7 +80,7 @@ fun main(args: Array<String>) {
|
|||||||
log.info("VM ${info.vmName} ${info.vmVendor} ${info.vmVersion}")
|
log.info("VM ${info.vmName} ${info.vmVendor} ${info.vmVersion}")
|
||||||
log.info("Machine: ${InetAddress.getLocalHost().hostName}")
|
log.info("Machine: ${InetAddress.getLocalHost().hostName}")
|
||||||
log.info("Working Directory: ${cmdlineOptions.baseDirectory}")
|
log.info("Working Directory: ${cmdlineOptions.baseDirectory}")
|
||||||
log.info("Started as webserver: ${cmdlineOptions.isWebserver}")
|
log.info("Starting as webserver: ${cmdlineOptions.isWebserver}")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cmdlineOptions.baseDirectory.createDirectories()
|
cmdlineOptions.baseDirectory.createDirectories()
|
||||||
@ -101,7 +102,11 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
node.run()
|
node.run()
|
||||||
} else {
|
} else {
|
||||||
WebServer(conf).start()
|
val server = WebServer(conf)
|
||||||
|
server.start()
|
||||||
|
val elapsed = (System.currentTimeMillis() - startTime) / 10 / 100.0
|
||||||
|
printBasicNodeInfo("Webserver started up in $elapsed sec")
|
||||||
|
server.run()
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.error("Exception during node startup", e)
|
log.error("Exception during node startup", e)
|
||||||
|
@ -425,7 +425,7 @@ open class DriverDSL(
|
|||||||
}
|
}
|
||||||
val url = URL(protocol + configuration.webAddress.toString() + "/api/status")
|
val url = URL(protocol + configuration.webAddress.toString() + "/api/status")
|
||||||
val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).build()
|
val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).build()
|
||||||
val retries = 5
|
val retries = 50
|
||||||
|
|
||||||
for (i in 0..retries) {
|
for (i in 0..retries) {
|
||||||
try {
|
try {
|
||||||
@ -456,7 +456,6 @@ open class DriverDSL(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun startNetworkMapService(): ListenableFuture<Process> {
|
private fun startNetworkMapService(): ListenableFuture<Process> {
|
||||||
val apiAddress = portAllocation.nextHostAndPort()
|
|
||||||
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
|
val debugPort = if (isDebug) debugPortAllocation.nextPort() else null
|
||||||
|
|
||||||
val baseDirectory = driverDirectory / networkMapLegalName
|
val baseDirectory = driverDirectory / networkMapLegalName
|
||||||
|
@ -3,6 +3,7 @@ package net.corda.node.webserver
|
|||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
import net.corda.core.node.CordaPluginRegistry
|
import net.corda.core.node.CordaPluginRegistry
|
||||||
import net.corda.core.utilities.loggerFor
|
import net.corda.core.utilities.loggerFor
|
||||||
|
import net.corda.node.printBasicNodeInfo
|
||||||
import net.corda.node.services.config.FullNodeConfiguration
|
import net.corda.node.services.config.FullNodeConfiguration
|
||||||
import net.corda.node.services.messaging.ArtemisMessagingComponent
|
import net.corda.node.services.messaging.ArtemisMessagingComponent
|
||||||
import net.corda.node.services.messaging.CordaRPCClient
|
import net.corda.node.services.messaging.CordaRPCClient
|
||||||
@ -11,6 +12,7 @@ import net.corda.node.webserver.servlets.ObjectMapperConfig
|
|||||||
import net.corda.node.webserver.servlets.DataUploadServlet
|
import net.corda.node.webserver.servlets.DataUploadServlet
|
||||||
import net.corda.node.webserver.servlets.ResponseFilter
|
import net.corda.node.webserver.servlets.ResponseFilter
|
||||||
import net.corda.node.webserver.internal.APIServerImpl
|
import net.corda.node.webserver.internal.APIServerImpl
|
||||||
|
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
|
||||||
import org.eclipse.jetty.server.*
|
import org.eclipse.jetty.server.*
|
||||||
import org.eclipse.jetty.server.handler.HandlerCollection
|
import org.eclipse.jetty.server.handler.HandlerCollection
|
||||||
import org.eclipse.jetty.servlet.DefaultServlet
|
import org.eclipse.jetty.servlet.DefaultServlet
|
||||||
@ -28,12 +30,19 @@ import java.util.*
|
|||||||
class WebServer(val config: FullNodeConfiguration) {
|
class WebServer(val config: FullNodeConfiguration) {
|
||||||
private companion object {
|
private companion object {
|
||||||
val log = loggerFor<WebServer>()
|
val log = loggerFor<WebServer>()
|
||||||
|
val maxRetries = 60 // TODO: Make configurable
|
||||||
|
val retryDelay = 1000L // Milliseconds
|
||||||
}
|
}
|
||||||
|
|
||||||
val address = config.webAddress
|
val address = config.webAddress
|
||||||
|
private lateinit var server: Server
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
val server = initWebServer(connectLocalRpcAsNodeUser())
|
printBasicNodeInfo("Starting as webserver: ${config.webAddress}")
|
||||||
|
server = initWebServer(connectLocalRpcWithRetries(maxRetries))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun run() {
|
||||||
while(server.isRunning) {
|
while(server.isRunning) {
|
||||||
Thread.sleep(100) // TODO: Redesign
|
Thread.sleep(100) // TODO: Redesign
|
||||||
}
|
}
|
||||||
@ -85,7 +94,7 @@ class WebServer(val config: FullNodeConfiguration) {
|
|||||||
val httpConfiguration = HttpConfiguration()
|
val httpConfiguration = HttpConfiguration()
|
||||||
httpConfiguration.outputBufferSize = 32768
|
httpConfiguration.outputBufferSize = 32768
|
||||||
val httpConnector = ServerConnector(server, HttpConnectionFactory(httpConfiguration))
|
val httpConnector = ServerConnector(server, HttpConnectionFactory(httpConfiguration))
|
||||||
println("Starting webserver on address $address")
|
log.info("Starting webserver on address $address")
|
||||||
httpConnector.port = address.port
|
httpConnector.port = address.port
|
||||||
httpConnector
|
httpConnector
|
||||||
}
|
}
|
||||||
@ -94,7 +103,7 @@ class WebServer(val config: FullNodeConfiguration) {
|
|||||||
server.handler = handlerCollection
|
server.handler = handlerCollection
|
||||||
//runOnStop += Runnable { server.stop() }
|
//runOnStop += Runnable { server.stop() }
|
||||||
server.start()
|
server.start()
|
||||||
println("Server started")
|
log.info("Server started")
|
||||||
log.info("Embedded web server is listening on", "http://${InetAddress.getLocalHost().hostAddress}:${connector.port}/")
|
log.info("Embedded web server is listening on", "http://${InetAddress.getLocalHost().hostAddress}:${connector.port}/")
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
@ -144,6 +153,22 @@ class WebServer(val config: FullNodeConfiguration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun connectLocalRpcWithRetries(retries: Int): CordaRPCOps {
|
||||||
|
for(i in 0..retries - 1) {
|
||||||
|
try {
|
||||||
|
log.info("Connecting to node at ${config.artemisAddress} as node user")
|
||||||
|
val client = CordaRPCClient(config.artemisAddress, config)
|
||||||
|
client.start(ArtemisMessagingComponent.NODE_USER, ArtemisMessagingComponent.NODE_USER)
|
||||||
|
return client.proxy()
|
||||||
|
} catch (e: ActiveMQNotConnectedException) {
|
||||||
|
log.debug("Could not connect to ${config.artemisAddress} due to exception: ", e)
|
||||||
|
Thread.sleep(retryDelay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return connectLocalRpcAsNodeUser()
|
||||||
|
}
|
||||||
|
|
||||||
private fun connectLocalRpcAsNodeUser(): CordaRPCOps {
|
private fun connectLocalRpcAsNodeUser(): CordaRPCOps {
|
||||||
log.info("Connecting to node at ${config.artemisAddress} as node user")
|
log.info("Connecting to node at ${config.artemisAddress} as node user")
|
||||||
val client = CordaRPCClient(config.artemisAddress, config)
|
val client = CordaRPCClient(config.artemisAddress, config)
|
||||||
|
@ -1 +1 @@
|
|||||||
gradlePluginsVersion=0.7
|
gradlePluginsVersion=0.7.1
|
||||||
|
Loading…
Reference in New Issue
Block a user