diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/NodeStatus.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/NodeStatus.kt new file mode 100644 index 0000000000..c6cf35f053 --- /dev/null +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/NodeStatus.kt @@ -0,0 +1,8 @@ +package net.corda.nodeapi.internal + +enum class NodeStatus { + WAITING_TO_START, + STARTING, + STARTED, + STOPPING +} diff --git a/node/src/integration-test/kotlin/net/corda/node/jmx/NodeStatus.kt b/node/src/integration-test/kotlin/net/corda/node/jmx/NodeStatus.kt new file mode 100644 index 0000000000..01aee4ee68 --- /dev/null +++ b/node/src/integration-test/kotlin/net/corda/node/jmx/NodeStatus.kt @@ -0,0 +1,45 @@ +package net.corda.node.jmx + +import com.fasterxml.jackson.databind.ObjectMapper +import net.corda.nodeapi.internal.NodeStatus +import net.corda.testing.driver.DriverParameters +import net.corda.testing.driver.JmxPolicy +import net.corda.testing.driver.driver +import org.junit.Test +import java.net.HttpURLConnection +import java.net.HttpURLConnection.* +import java.net.URL +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class NodeStatus { + + @Test(timeout=300_000) + fun `node status is published via JMX`() { + driver(DriverParameters(notarySpecs = emptyList(), jmxPolicy = JmxPolicy.defaultEnabled())) { + val jmxAddress = startNode().get().jmxAddress.toString() + val nodeStatusURL = URL("http://$jmxAddress/jolokia/read/net.corda:name=Status,type=Node") + var jmxInfo = "" + + with(nodeStatusURL.openConnection() as HttpURLConnection) { + requestMethod = "GET" + inputStream.bufferedReader().use { + it.lines().forEach { line -> + jmxInfo += line + } + } + } + + assertTrue { + jmxInfo.isNotEmpty() + } + + val jsonTree = ObjectMapper().readTree(jmxInfo) + val httpStatus = jsonTree.get("status").asInt() + val nodeStatus = jsonTree.get("value").get("Value").asText() + + assertEquals(httpStatus, HTTP_OK) + assertEquals(nodeStatus, NodeStatus.STARTED.toString()) + } + } +} \ No newline at end of file diff --git a/node/src/integration-test/kotlin/net/corda/node/jmx/Publish.kt b/node/src/integration-test/kotlin/net/corda/node/jmx/Publish.kt new file mode 100644 index 0000000000..07496e7bc1 --- /dev/null +++ b/node/src/integration-test/kotlin/net/corda/node/jmx/Publish.kt @@ -0,0 +1,29 @@ +package net.corda.node.jmx + +import net.corda.testing.driver.DriverParameters +import net.corda.testing.driver.JmxPolicy +import net.corda.testing.driver.driver +import org.junit.Test +import java.net.HttpURLConnection +import java.net.URL +import kotlin.test.assertTrue + +class Publish { + + @Test(timeout=300_000) + fun `node publishes node information via JMX when configured to do so`() { + driver(DriverParameters(notarySpecs = emptyList(), jmxPolicy = JmxPolicy.defaultEnabled())) { + val jmxAddress = startNode().get().jmxAddress.toString() + val nodeStatusURL = URL("http://$jmxAddress/jolokia/read/net.corda:*") + var httpResponse = HttpURLConnection.HTTP_NOT_FOUND + with(nodeStatusURL.openConnection() as HttpURLConnection) { + requestMethod = "GET" + httpResponse = responseCode + } + + assertTrue { + httpResponse == HttpURLConnection.HTTP_OK + } + } + } +} \ No newline at end of file diff --git a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt index e611488cd7..705d5dc447 100644 --- a/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt +++ b/node/src/main/kotlin/net/corda/node/internal/AbstractNode.kt @@ -147,6 +147,7 @@ import net.corda.node.utilities.BindableNamedCacheFactory import net.corda.node.utilities.NamedThreadFactory import net.corda.node.utilities.NotaryLoader import net.corda.nodeapi.internal.NodeInfoAndSigned +import net.corda.nodeapi.internal.NodeStatus import net.corda.nodeapi.internal.SignedNodeInfo import net.corda.nodeapi.internal.cordapp.CordappLoader import net.corda.nodeapi.internal.cryptoservice.CryptoService @@ -384,13 +385,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration, protected val keyStoreHandler = KeyStoreHandler(configuration, cryptoService) - enum class NodeStatus { - WAITING_TO_START, - STARTING, - STARTED, - STOPPING - } - + @Volatile private var nodeStatus = NodeStatus.WAITING_TO_START private fun T.tokenize(): T {