diff options
Diffstat (limited to 'sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt')
-rw-r--r-- | sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt index 1eca9317..a6ee1122 100644 --- a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt +++ b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt @@ -26,6 +26,7 @@ import org.onap.dcae.collectors.veshv.utils.http.HttpStatus import org.onap.dcae.collectors.veshv.utils.http.Responses import org.onap.dcae.collectors.veshv.utils.http.sendAndHandleErrors import org.onap.dcae.collectors.veshv.utils.http.sendOrError +import org.onap.dcae.collectors.veshv.utils.logging.Logger import ratpack.handling.Chain import ratpack.server.RatpackServer import ratpack.server.ServerConfig @@ -38,14 +39,14 @@ class DcaeAppApiServer(private val simulator: DcaeAppSimulator) { private val responseValid by lazy { Responses.statusResponse( name = "valid", - message = "validation succeeded" + message = VALID_RESPONSE_MESSAGE ) } private val responseInvalid by lazy { Responses.statusResponse( name = "invalid", - message = "validation failed", + message = INVALID_RESPONSE_MESSAGE, httpStatus = HttpStatus.BAD_REQUEST ) } @@ -70,12 +71,18 @@ class DcaeAppApiServer(private val simulator: DcaeAppSimulator) { } .delete("messages") { ctx -> ctx.response.contentType(CONTENT_TEXT) + logger.info("Resetting simulator state") ctx.response.sendOrError(simulator.resetState()) } .get("messages/all/count") { ctx -> + logger.info("Processing request for count of received messages") simulator.state().fold( - { ctx.response.status(HttpConstants.STATUS_NOT_FOUND) }, { + ctx.response.status(HttpConstants.STATUS_NOT_FOUND) + logger.warn("Error - number of messages could not be specified") + }, + { + logger.info { "Returned number of received messages: ${it.messagesCount}" } ctx.response .contentType(CONTENT_TEXT) .send(it.messagesCount.toString()) @@ -83,19 +90,32 @@ class DcaeAppApiServer(private val simulator: DcaeAppSimulator) { } .post("messages/all/validate") { ctx -> ctx.request.body.then { body -> + logger.info("Processing request for message validation") val response = simulator.validate(body.inputStream) .map { isValid -> - if (isValid) responseValid else responseInvalid + if (isValid) { + logger.info { "Comparison result: $VALID_RESPONSE_MESSAGE" } + responseValid + } else { + logger.info { "Comparison result: $INVALID_RESPONSE_MESSAGE" } + responseInvalid + } } ctx.response.sendAndHandleErrors(response) } } .get("healthcheck") { ctx -> - ctx.response.status(HttpConstants.STATUS_OK).send() + val status = HttpConstants.STATUS_OK + logger.info { "Healthcheck OK, returning status: $status" } + ctx.response.status(status).send() } } companion object { private const val CONTENT_TEXT = "text/plain" + private const val VALID_RESPONSE_MESSAGE = "validation passed" + private const val INVALID_RESPONSE_MESSAGE = "consumed messages don't match data from validation request" + private val logger = Logger(DcaeAppApiServer::class) } } + |