mirror of
https://github.com/corda/corda.git
synced 2025-06-06 01:11:45 +00:00
Merged in rnicoll-web-server-diagnostics (pull request #416)
Add diagnostics for web server and API plugin instantiation
This commit is contained in:
commit
0232628f49
@ -33,6 +33,7 @@ import org.glassfish.jersey.servlet.ServletContainer
|
|||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
import java.io.RandomAccessFile
|
import java.io.RandomAccessFile
|
||||||
import java.lang.management.ManagementFactory
|
import java.lang.management.ManagementFactory
|
||||||
|
import java.lang.reflect.InvocationTargetException
|
||||||
import java.nio.channels.FileLock
|
import java.nio.channels.FileLock
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -143,13 +144,18 @@ class Node(override val configuration: FullNodeConfiguration, networkMapAddress:
|
|||||||
|
|
||||||
// Export JMX monitoring statistics and data over REST/JSON.
|
// Export JMX monitoring statistics and data over REST/JSON.
|
||||||
if (configuration.exportJMXto.split(',').contains("http")) {
|
if (configuration.exportJMXto.split(',').contains("http")) {
|
||||||
handlerCollection.addHandler(WebAppContext().apply {
|
val classpath = System.getProperty("java.class.path").split(System.getProperty("path.separator"))
|
||||||
// Find the jolokia WAR file on the classpath.
|
val warpath = classpath.firstOrNull() { it.contains("jolokia-agent-war-2") && it.endsWith(".war") }
|
||||||
contextPath = "/monitoring/json"
|
if (warpath != null) {
|
||||||
setInitParameter("mimeType", "application/json")
|
handlerCollection.addHandler(WebAppContext().apply {
|
||||||
val classpath = System.getProperty("java.class.path").split(System.getProperty("path.separator"))
|
// Find the jolokia WAR file on the classpath.
|
||||||
war = classpath.first { it.contains("jolokia-agent-war-2") && it.endsWith(".war") }
|
contextPath = "/monitoring/json"
|
||||||
})
|
setInitParameter("mimeType", "application/json")
|
||||||
|
war = warpath
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
log.warn("Unable to locate Jolokia WAR on classpath")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// API, data upload and download to services (attachments, rates oracles etc)
|
// API, data upload and download to services (attachments, rates oracles etc)
|
||||||
@ -157,7 +163,7 @@ class Node(override val configuration: FullNodeConfiguration, networkMapAddress:
|
|||||||
|
|
||||||
val server = Server()
|
val server = Server()
|
||||||
|
|
||||||
if (configuration.useHTTPS) {
|
val connector = if (configuration.useHTTPS) {
|
||||||
val httpsConfiguration = HttpConfiguration()
|
val httpsConfiguration = HttpConfiguration()
|
||||||
httpsConfiguration.outputBufferSize = 32768
|
httpsConfiguration.outputBufferSize = 32768
|
||||||
httpsConfiguration.addCustomizer(SecureRequestCustomizer())
|
httpsConfiguration.addCustomizer(SecureRequestCustomizer())
|
||||||
@ -173,14 +179,16 @@ class Node(override val configuration: FullNodeConfiguration, networkMapAddress:
|
|||||||
sslContextFactory.setIncludeCipherSuites(".*AES.*GCM.*")
|
sslContextFactory.setIncludeCipherSuites(".*AES.*GCM.*")
|
||||||
val sslConnector = ServerConnector(server, SslConnectionFactory(sslContextFactory, "http/1.1"), HttpConnectionFactory(httpsConfiguration))
|
val sslConnector = ServerConnector(server, SslConnectionFactory(sslContextFactory, "http/1.1"), HttpConnectionFactory(httpsConfiguration))
|
||||||
sslConnector.port = configuration.webAddress.port
|
sslConnector.port = configuration.webAddress.port
|
||||||
server.connectors = arrayOf<Connector>(sslConnector)
|
sslConnector
|
||||||
} else {
|
} else {
|
||||||
val httpConfiguration = HttpConfiguration()
|
val httpConfiguration = HttpConfiguration()
|
||||||
httpConfiguration.outputBufferSize = 32768
|
httpConfiguration.outputBufferSize = 32768
|
||||||
val httpConnector = ServerConnector(server, HttpConnectionFactory(httpConfiguration))
|
val httpConnector = ServerConnector(server, HttpConnectionFactory(httpConfiguration))
|
||||||
httpConnector.port = configuration.webAddress.port
|
httpConnector.port = configuration.webAddress.port
|
||||||
server.connectors = arrayOf<Connector>(httpConnector)
|
httpConnector
|
||||||
}
|
}
|
||||||
|
server.connectors = arrayOf<Connector>(connector)
|
||||||
|
log.info("Starting web API server on port ${connector.port}")
|
||||||
|
|
||||||
server.handler = handlerCollection
|
server.handler = handlerCollection
|
||||||
runOnStop += Runnable { server.stop() }
|
runOnStop += Runnable { server.stop() }
|
||||||
@ -203,8 +211,19 @@ class Node(override val configuration: FullNodeConfiguration, networkMapAddress:
|
|||||||
|
|
||||||
val webAPIsOnClasspath = pluginRegistries.flatMap { x -> x.webApis }
|
val webAPIsOnClasspath = pluginRegistries.flatMap { x -> x.webApis }
|
||||||
for (webapi in webAPIsOnClasspath) {
|
for (webapi in webAPIsOnClasspath) {
|
||||||
log.info("Add Plugin web API from attachment ${webapi.name}")
|
log.info("Add plugin web API from attachment ${webapi.name}")
|
||||||
val customAPI = webapi.getConstructor(ServiceHub::class.java).newInstance(services)
|
val constructor = try {
|
||||||
|
webapi.getConstructor(ServiceHub::class.java)
|
||||||
|
} catch (ex: NoSuchMethodException) {
|
||||||
|
log.error("Missing constructor ${webapi.name}(ServiceHub)")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
val customAPI = try {
|
||||||
|
constructor.newInstance(services)
|
||||||
|
} catch (ex: InvocationTargetException) {
|
||||||
|
log.error("Constructor ${webapi.name}(ServiceHub) threw an error: ", ex.targetException)
|
||||||
|
continue
|
||||||
|
}
|
||||||
resourceConfig.register(customAPI)
|
resourceConfig.register(customAPI)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +289,13 @@ class Node(override val configuration: FullNodeConfiguration, networkMapAddress:
|
|||||||
super.start()
|
super.start()
|
||||||
// Only start the service API requests once the network map registration is complete
|
// Only start the service API requests once the network map registration is complete
|
||||||
networkMapRegistrationFuture.then {
|
networkMapRegistrationFuture.then {
|
||||||
webServer = initWebServer()
|
try {
|
||||||
|
webServer = initWebServer()
|
||||||
|
} catch(ex: Exception) {
|
||||||
|
// TODO: We need to decide if this is a fatal error, given the API is unavailable, or whether the API
|
||||||
|
// is not critical and we continue anyway.
|
||||||
|
log.error("Web server startup failed", ex)
|
||||||
|
}
|
||||||
// Begin exporting our own metrics via JMX.
|
// Begin exporting our own metrics via JMX.
|
||||||
JmxReporter.
|
JmxReporter.
|
||||||
forRegistry(services.monitoringService.metrics).
|
forRegistry(services.monitoringService.metrics).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user