diff options
Diffstat (limited to 'sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt')
-rw-r--r-- | sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt index cfd3a6e9..a0785620 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt @@ -20,10 +20,12 @@ package org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters import arrow.core.Either -import arrow.core.getOrElse import arrow.effects.IO import org.onap.dcae.collectors.veshv.simulators.xnf.impl.OngoingSimulations import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfSimulator +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfStatus.BUSY +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfStatus.DETAILED_STATUS_NODE +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfStatus.IDLE import org.onap.dcae.collectors.veshv.utils.http.HttpConstants import org.onap.dcae.collectors.veshv.utils.http.Response import org.onap.dcae.collectors.veshv.utils.http.Responses @@ -37,6 +39,7 @@ import ratpack.http.TypedData import ratpack.server.RatpackServer import ratpack.server.ServerConfig import java.util.* +import javax.json.Json /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> @@ -58,10 +61,7 @@ internal class XnfApiServer( .post("simulator", ::startSimulationHandler) .post("simulator/async", ::startSimulationHandler) .get("simulator/:id", ::simulatorStatusHandler) - .get("healthcheck") { ctx -> - logger.info { "Checking health" } - ctx.response.status(HttpConstants.STATUS_OK).send() - } + .get("healthcheck", ::healthcheckHandler) } private fun startSimulationHandler(ctx: Context) { @@ -82,6 +82,7 @@ internal class XnfApiServer( .map(Responses::acceptedResponse) } + private fun simulatorStatusHandler(ctx: Context) { logger.debug { "Checking task status" } val id = UUID.fromString(ctx.pathTokens["id"]) @@ -92,6 +93,21 @@ internal class XnfApiServer( ctx.response.sendAndHandleErrors(IO.just(response)) } + private fun healthcheckHandler(ctx: Context) { + val healthCheckDetailedMessage = createHealthCheckDetailedMessage() + val simulatorStatus = HttpConstants.STATUS_OK + logger.info { "Returning simulator status: ${simulatorStatus} ${healthCheckDetailedMessage}" } + ctx.response.status(simulatorStatus).send(healthCheckDetailedMessage) + } + + private fun createHealthCheckDetailedMessage() = + Json.createObjectBuilder() + .add(DETAILED_STATUS_NODE, when { + ongoingSimulations.isAnySimulationPending() -> BUSY + else -> IDLE + }) + .build().toString() + companion object { private val logger = Logger(XnfApiServer::class) } |