aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-dcae-app-simulator
diff options
context:
space:
mode:
authorkjaniak <kornel.janiak@nokia.com>2018-11-29 13:44:50 +0100
committerkjaniak <kornel.janiak@nokia.com>2018-12-05 14:53:20 +0100
commit0f7bc6b6ec219b6e22a4b5b5a4ee1efd4e54efba (patch)
tree593dc7b9487d148160110be532e038f8a383846b /sources/hv-collector-dcae-app-simulator
parentd632aef8303701a1802f817c3d6fdcd4064c32b2 (diff)
Enhance of logging in test part
Change-Id: Ibdec0ac5cead7e46ada4c32983b9ccf962df703b Issue-ID: DCAEGEN2-1004 Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Diffstat (limited to 'sources/hv-collector-dcae-app-simulator')
-rw-r--r--sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt9
-rw-r--r--sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt20
-rw-r--r--sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt30
-rw-r--r--sources/hv-collector-dcae-app-simulator/src/main/resources/logback.xml2
4 files changed, 48 insertions, 13 deletions
diff --git a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt
index 490cde4a..417183fb 100644
--- a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt
+++ b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt
@@ -40,10 +40,11 @@ class DcaeAppSimulator(private val consumerFactory: ConsumerFactory,
fun listenToTopics(topicsString: String) = listenToTopics(extractTopics(topicsString))
fun listenToTopics(topics: Set<String>): IO<Unit> = IO.monadError().bindingCatch {
- if (topics.any { it.isBlank() })
- throw IllegalArgumentException("Topic list cannot contain empty elements")
- if (topics.isEmpty())
- throw IllegalArgumentException("Topic list cannot be empty")
+ if (topics.isEmpty() || topics.any { it.isBlank() }) {
+ val message = "Topic list cannot be empty or contain empty elements, topics: $topics"
+ logger.info { message }
+ throw IllegalArgumentException(message)
+ }
logger.info("Received new configuration. Creating consumer for topics: $topics")
consumerState.set(consumerFactory.createConsumerForTopics(topics).bind())
diff --git a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt
index e423191d..20c0f592 100644
--- a/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt
+++ b/sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt
@@ -19,13 +19,16 @@
*/
package org.onap.dcae.collectors.veshv.simulators.dcaeapp.impl
+import arrow.core.getOrElse
import arrow.effects.IO
import arrow.effects.fix
import arrow.effects.instances.io.monadError.monadError
+import arrow.instances.option.foldable.fold
import arrow.typeclasses.bindingCatch
import org.onap.dcae.collectors.veshv.domain.ByteData
import org.onap.dcae.collectors.veshv.domain.WireFrameMessage
import org.onap.dcae.collectors.veshv.utils.arrow.asIo
+import org.onap.dcae.collectors.veshv.utils.logging.Logger
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParameters
import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser
@@ -41,6 +44,7 @@ class MessageStreamValidation(
fun validate(jsonDescription: InputStream, consumedMessages: List<ByteArray>): IO<Boolean> =
IO.monadError().bindingCatch {
val messageParams = parseMessageParams(jsonDescription)
+ logger.debug { "Parsed message parameters: $messageParams" }
val expectedEvents = generateEvents(messageParams).bind()
val actualEvents = decodeConsumedEvents(consumedMessages)
if (shouldValidatePayloads(messageParams)) {
@@ -55,10 +59,17 @@ class MessageStreamValidation(
val messageParams = messageParametersParser.parse(expectations)
return messageParams.fold(
- { throw IllegalArgumentException("Parsing error: " + it.message) },
{
- if (it.isEmpty())
- throw IllegalArgumentException("Message param list cannot be empty")
+ logger.warn { "Error while parsing message parameters: ${it::class.qualifiedName} : ${it.message}" }
+ logger.debug { "Detailed stack trace: ${it}" }
+ throw IllegalArgumentException("Parsing error: " + it.message)
+ },
+ {
+ if (it.isEmpty()) {
+ val message = "Message param list cannot be empty"
+ logger.warn(message)
+ throw IllegalArgumentException(message)
+ }
it
}
)
@@ -85,4 +96,7 @@ class MessageStreamValidation(
private fun decodeConsumedEvents(consumedMessages: List<ByteArray>) =
consumedMessages.map(VesEventOuterClass.VesEvent::parseFrom)
+ companion object {
+ private val logger = Logger(MessageStreamValidation::class)
+ }
}
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)
}
}
+
diff --git a/sources/hv-collector-dcae-app-simulator/src/main/resources/logback.xml b/sources/hv-collector-dcae-app-simulator/src/main/resources/logback.xml
index 09ac3573..4d12b113 100644
--- a/sources/hv-collector-dcae-app-simulator/src/main/resources/logback.xml
+++ b/sources/hv-collector-dcae-app-simulator/src/main/resources/logback.xml
@@ -26,7 +26,7 @@
</rollingPolicy>
</appender>
- <logger name="org.onap.dcae.collectors.veshv" level="INFO"/>
+ <logger name="org.onap.dcae.collectors.veshv" level="DEBUG"/>
<!--<logger name="reactor.netty" level="DEBUG"/>-->
<root level="INFO">