From 88871ce8d9e069c7967734163c4406d78f91823d Mon Sep 17 00:00:00 2001 From: Filip Krzywka Date: Tue, 18 Dec 2018 10:10:06 +0100 Subject: Add script for sending messages from multiple xNFs Change-Id: I9acd3278929c30a3036f97f403a31a8817723d27 Issue-ID: DCAEGEN2-1027 Signed-off-by: Filip Krzywka --- .../simulators/xnf/impl/adapters/XnfApiServer.kt | 26 ++++++++++++++++---- .../veshv/simulators/xnf/impl/simulations.kt | 4 ++++ .../collectors/veshv/simulators/xnf/impl/status.kt | 28 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/status.kt (limited to 'sources/hv-collector-xnf-simulator/src/main') 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 @@ -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) } diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt index d7d42d88..bd58dd9c 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt @@ -57,6 +57,10 @@ class OngoingSimulations(executor: Executor = Executors.newCachedThreadPool()) { fun status(id: UUID) = simulations.getOrDefault(id, StatusNotFound) + fun isAnySimulationPending() = simulations.any { + status(it.key) is StatusOngoing + } + internal fun clear() { simulations.clear() } diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/status.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/status.kt new file mode 100644 index 00000000..a86e3d50 --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/status.kt @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.simulators.xnf.impl + +// TODO: probably should be merged with HealthDescription or made similiar to it +internal object XnfStatus { + + const val BUSY = "Busy" + const val IDLE = "Idle" + const val DETAILED_STATUS_NODE = "Detailed status" +} -- cgit 1.2.3-korg