Enhance of logging in test part 24/73924/17
authorkjaniak <kornel.janiak@nokia.com>
Thu, 29 Nov 2018 12:44:50 +0000 (13:44 +0100)
committerkjaniak <kornel.janiak@nokia.com>
Wed, 5 Dec 2018 13:53:20 +0000 (14:53 +0100)
Change-Id: Ibdec0ac5cead7e46ada4c32983b9ccf962df703b
Issue-ID: DCAEGEN2-1004
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
15 files changed:
sources/hv-collector-core/pom.xml
sources/hv-collector-ct/pom.xml
sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/DcaeAppSimulator.kt
sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/MessageStreamValidation.kt
sources/hv-collector-dcae-app-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/dcaeapp/impl/adapters/DcaeAppApiServer.kt
sources/hv-collector-dcae-app-simulator/src/main/resources/logback.xml
sources/hv-collector-ssl/pom.xml
sources/hv-collector-test-utils/pom.xml
sources/hv-collector-test-utils/src/main/resources/logback-test.xml [new file with mode: 0644]
sources/hv-collector-utils/pom.xml
sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/http/ratpack.kt
sources/hv-collector-utils/src/test/resources/logback-test.xml [new file with mode: 0644]
sources/hv-collector-ves-message-generator/pom.xml
sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageParametersParserImpl.kt
sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/XnfApiServer.kt

index 7f7922e..ae78174 100644 (file)
             <artifactId>javax.json</artifactId>
             <scope>runtime</scope>
         </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
 </project>
index 61ac426..47b707a 100644 (file)
             <artifactId>hv-collector-test-utils</artifactId>
             <version>${project.parent.version}</version>
         </dependency>
-
-
         <dependency>
             <groupId>io.arrow-kt</groupId>
             <artifactId>arrow-syntax</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <groupId>io.projectreactor</groupId>
             <artifactId>reactor-test</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
-
-
 </project>
\ No newline at end of file
index 490cde4..417183f 100644 (file)
@@ -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())
index e423191..20c0f59 100644 (file)
  */
 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)
+    }
 }
index 1eca931..a6ee112 100644 (file)
@@ -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)
     }
 }
+
index 09ac357..4d12b11 100644 (file)
@@ -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">
index 6001ba9..98c07f4 100644 (file)
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <groupId>org.jetbrains.spek</groupId>
             <artifactId>spek-junit-platform-engine</artifactId>
         </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 
index aebdd65..3c34082 100644 (file)
             <artifactId>mockito-kotlin</artifactId>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git a/sources/hv-collector-test-utils/src/main/resources/logback-test.xml b/sources/hv-collector-test-utils/src/main/resources/logback-test.xml
new file mode 100644 (file)
index 0000000..9a4eacf
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+  <property name="LOG_FILE"
+    value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}ves-hv.log}"/>
+  <property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} %-5level [%-40.40logger{10}] - %msg%n"/>
+
+  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>
+        %d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} %highlight(%-5level) [%-40.40logger{10}] - %msg%n
+      </pattern>
+    </encoder>
+  </appender>
+
+    <appender name="ROLLING-FILE"
+      class="ch.qos.logback.core.rolling.RollingFileAppender">
+      <encoder>
+        <pattern>${FILE_LOG_PATTERN}</pattern>
+      </encoder>
+      <file>${LOG_FILE}</file>
+      <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+        <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
+        <maxFileSize>50MB</maxFileSize>
+        <maxHistory>30</maxHistory>
+        <totalSizeCap>10GB</totalSizeCap>
+      </rollingPolicy>
+    </appender>
+
+  <logger name="org.onap.dcae.collectors.veshv" level="TRACE"/>
+
+  <root level="INFO">
+      <appender-ref ref="CONSOLE"/>
+      <appender-ref ref="ROLLING-FILE"/>
+    </root>
+</configuration>
index 66879ff..2490767 100644 (file)
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <groupId>com.nhaarman.mockitokotlin2</groupId>
             <artifactId>mockito-kotlin</artifactId>
         </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.glassfish</groupId>
             <artifactId>javax.json</artifactId>
index 0282d0c..5a733f2 100644 (file)
@@ -42,7 +42,7 @@ fun ratpack.http.Response.sendOrError(action: IO<Unit>) {
 }
 
 fun <A> ratpack.http.Response.sendEitherErrorOrResponse(response: Either<A, Response>) {
-    when(response) {
+    when (response) {
         is Either.Left -> send(errorResponse(response.a.toString()))
         is Either.Right -> sendAndHandleErrors(IO.just(response.b))
     }
diff --git a/sources/hv-collector-utils/src/test/resources/logback-test.xml b/sources/hv-collector-utils/src/test/resources/logback-test.xml
new file mode 100644 (file)
index 0000000..9a4eacf
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+  <property name="LOG_FILE"
+    value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}ves-hv.log}"/>
+  <property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} %-5level [%-40.40logger{10}] - %msg%n"/>
+
+  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>
+        %d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} %highlight(%-5level) [%-40.40logger{10}] - %msg%n
+      </pattern>
+    </encoder>
+  </appender>
+
+    <appender name="ROLLING-FILE"
+      class="ch.qos.logback.core.rolling.RollingFileAppender">
+      <encoder>
+        <pattern>${FILE_LOG_PATTERN}</pattern>
+      </encoder>
+      <file>${LOG_FILE}</file>
+      <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+        <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
+        <maxFileSize>50MB</maxFileSize>
+        <maxHistory>30</maxHistory>
+        <totalSizeCap>10GB</totalSizeCap>
+      </rollingPolicy>
+    </appender>
+
+  <logger name="org.onap.dcae.collectors.veshv" level="TRACE"/>
+
+  <root level="INFO">
+      <appender-ref ref="CONSOLE"/>
+      <appender-ref ref="ROLLING-FILE"/>
+    </root>
+</configuration>
index c5ce7f6..29e32f4 100644 (file)
             <artifactId>hv-collector-domain</artifactId>
             <version>${project.parent.version}</version>
         </dependency>
+        <dependency>
+            <groupId>${project.parent.groupId}</groupId>
+            <artifactId>hv-collector-utils</artifactId>
+            <version>${project.parent.version}</version>
+        </dependency>
         <dependency>
             <groupId>${project.parent.groupId}</groupId>
             <artifactId>hv-collector-test-utils</artifactId>
             <groupId>io.projectreactor</groupId>
             <artifactId>reactor-test</artifactId>
         </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-            <scope>runtime</scope>
-        </dependency>
         <dependency>
             <groupId>org.glassfish</groupId>
             <artifactId>javax.json</artifactId>
index 6ef6d53..88cc47a 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.dcae.collectors.veshv.ves.message.generator.impl
 import arrow.core.Option
 import arrow.core.Try
 import arrow.core.identity
+import org.onap.dcae.collectors.veshv.utils.logging.Logger
 import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParameters
 import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser
 import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType
@@ -40,6 +41,7 @@ internal class MessageParametersParserImpl(
             Try {
                 request
                         .map { it.asJsonObject() }
+                        .onEach { logger.info { "Parsing MessageParameters body: $it" } }
                         .map { json ->
                             val commonEventHeader = commonEventHeaderParser
                                     .parse(json.getJsonObject("commonEventHeader"))
@@ -54,4 +56,9 @@ internal class MessageParametersParserImpl(
                         ex.message ?: "Unable to parse message parameters",
                         Option.fromNullable(ex))
             }
+
+    companion object {
+        private val logger = Logger(MessageParametersParserImpl::class)
+    }
+
 }
index 06f1cff..1601938 100644 (file)
@@ -20,6 +20,7 @@
 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
@@ -64,9 +65,13 @@ internal class XnfApiServer(
     }
 
     private fun startSimulationHandler(ctx: Context) {
-        logger.info("Starting asynchronous scenario")
+        logger.info("Attempting to start asynchronous scenario")
         ctx.request.body.then { body ->
             val id = startSimulation(body)
+            when (id) {
+                is Either.Left -> logger.warn { "Failed to start scenario, ${id.a}"}
+                is Either.Right -> logger.info { "Scenario started, details: ${id.b}" }
+            }
             ctx.response.sendEitherErrorOrResponse(id)
         }
     }
@@ -78,9 +83,12 @@ internal class XnfApiServer(
     }
 
     private fun simulatorStatusHandler(ctx: Context) {
+        logger.debug("Checking task status")
         val id = UUID.fromString(ctx.pathTokens["id"])
+        logger.debug { "Checking status for id: $id" }
         val status = ongoingSimulations.status(id)
         val response = Responses.statusResponse(status.toString(), status.message)
+        logger.info { "Task $id status: $response" }
         ctx.response.sendAndHandleErrors(IO.just(response))
     }