summaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-xnf-simulator/src/main
diff options
context:
space:
mode:
authorFilip Krzywka <filip.krzywka@nokia.com>2018-12-18 10:10:06 +0100
committerFilip Krzywka <filip.krzywka@nokia.com>2019-01-03 08:36:41 +0000
commit88871ce8d9e069c7967734163c4406d78f91823d (patch)
tree39e1f60210c18658e821117dbf653d9097a41b23 /sources/hv-collector-xnf-simulator/src/main
parent3d3eff47f0f94176f351d05f7dca39957a0c3c8b (diff)
Add script for sending messages from multiple xNFs
Change-Id: I9acd3278929c30a3036f97f403a31a8817723d27 Issue-ID: DCAEGEN2-1027 Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'sources/hv-collector-xnf-simulator/src/main')
-rw-r--r--sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt26
-rw-r--r--sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/simulations.kt4
-rw-r--r--sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/status.kt28
3 files changed, 53 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)
}
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"
+}