diff options
12 files changed, 154 insertions, 57 deletions
diff --git a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt b/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt index 54a7ea11..b793f3aa 100644 --- a/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt +++ b/hv-collector-ct/src/test/kotlin/org/onap/dcae/collectors/veshv/tests/component/PerformanceSpecification.kt @@ -26,10 +26,10 @@ import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.describe import org.jetbrains.spek.api.dsl.it import org.onap.dcae.collectors.veshv.domain.WireFrameEncoder -import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters -import org.onap.dcae.collectors.veshv.simulators.xnf.createMessageGenerator import org.onap.dcae.collectors.veshv.tests.fakes.CountingSink import org.onap.dcae.collectors.veshv.tests.fakes.basicConfiguration +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator +import org.onap.dcae.collectors.veshv.ves.message.generator.config.MessageParameters import reactor.core.publisher.Flux import reactor.math.sum import java.security.MessageDigest @@ -161,7 +161,7 @@ fun dropWhenIndex(predicate: (Long) -> Boolean, stream: Flux<ByteBuf>): Flux<Byt private fun generateDataStream(alloc: ByteBufAllocator, params: MessageParameters): Flux<ByteBuf> = WireFrameEncoder(alloc).let { encoder -> - createMessageGenerator() + MessageGenerator.INSTANCE .createMessageFlux(params) .map(encoder::encode) .transform { simulateRemoteTcp(alloc, 1000, it) } diff --git a/hv-collector-ves-message-generator/pom.xml b/hv-collector-ves-message-generator/pom.xml new file mode 100644 index 00000000..dfa30b10 --- /dev/null +++ b/hv-collector-ves-message-generator/pom.xml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ ============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========================================================= + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <licenses> + <license> + <name>The Apache Software License, Version 2.0</name> + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> + </license> + </licenses> + + <parent> + <groupId>org.onap.dcaegen2.collectors.veshv</groupId> + <artifactId>ves-hv-collector</artifactId> + <version>1.0.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>hv-collector-ves-message-generator</artifactId> + <description>VES HighVolume Collector :: VES message generator</description> + + <properties> + <skipAnalysis>false</skipAnalysis> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>kotlin-maven-plugin</artifactId> + <groupId>org.jetbrains.kotlin</groupId> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <groupId>org.apache.maven.plugins</groupId> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>${project.parent.groupId}</groupId> + <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>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-stdlib-jdk8</artifactId> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + <dependency> + <groupId>org.jetbrains.kotlin</groupId> + <artifactId>kotlin-test</artifactId> + </dependency> + <dependency> + <groupId>org.jetbrains.spek</groupId> + <artifactId>spek-api</artifactId> + </dependency> + <dependency> + <groupId>org.jetbrains.spek</groupId> + <artifactId>spek-junit-platform-engine</artifactId> + </dependency> + <dependency> + <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> + </dependency> + </dependencies> + + +</project>
\ No newline at end of file diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/api/MessageGenerator.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt index a6d6af84..e52db848 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/api/MessageGenerator.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt @@ -17,11 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.simulators.xnf.api +package org.onap.dcae.collectors.veshv.ves.message.generator.api import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage -import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.config.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.MessageGeneratorImpl +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator +import org.onap.ves.VesEventV5 import reactor.core.publisher.Flux +import javax.json.JsonObject /** * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> @@ -29,4 +33,12 @@ import reactor.core.publisher.Flux */ interface MessageGenerator { fun createMessageFlux(messageParameters: MessageParameters): Flux<PayloadWireFrameMessage> + fun parseCommonHeader(json: JsonObject): VesEventV5.VesEvent.CommonEventHeader + + companion object { + val INSTANCE: MessageGenerator by lazy { + MessageGeneratorImpl(PayloadGenerator()) + } + } } + diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/MessageParameters.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/config/MessageParameters.kt index f993f45a..7e80cc66 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/config/MessageParameters.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/config/MessageParameters.kt @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.simulators.xnf.config +package org.onap.dcae.collectors.veshv.ves.message.generator.config import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageGeneratorImpl.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt index baff967a..b2f73894 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageGeneratorImpl.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt @@ -17,12 +17,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.simulators.xnf.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import com.google.protobuf.ByteString import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage -import org.onap.dcae.collectors.veshv.simulators.xnf.api.MessageGenerator -import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator +import org.onap.dcae.collectors.veshv.ves.message.generator.config.MessageParameters import org.onap.ves.VesEventV5.VesEvent import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader import reactor.core.publisher.Flux @@ -33,7 +33,7 @@ import javax.json.JsonObject * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since June 2018 */ -internal class MessageGeneratorImpl(private val payloadGenerator: PayloadGenerator) : MessageGenerator { +class MessageGeneratorImpl internal constructor(private val payloadGenerator: PayloadGenerator) : MessageGenerator { override fun createMessageFlux(messageParameters: MessageParameters): Flux<PayloadWireFrameMessage> = Mono.fromCallable { createMessage(messageParameters.commonEventHeader) }.let { @@ -43,7 +43,7 @@ internal class MessageGeneratorImpl(private val payloadGenerator: PayloadGenerat it.repeat(messageParameters.amount) } - fun parseCommonHeader(json: JsonObject): CommonEventHeader = CommonEventHeader.newBuilder() + override fun parseCommonHeader(json: JsonObject): CommonEventHeader = CommonEventHeader.newBuilder() .setVersion(json.getString("version")) .setDomain(CommonEventHeader.Domain.forNumber(json.getInt("domain"))) .setSequence(json.getInt("sequence")) @@ -72,8 +72,4 @@ internal class MessageGeneratorImpl(private val payloadGenerator: PayloadGenerat .setHvRanMeasFields(payloadGenerator.generatePayload().toByteString()) .build() .toByteArray() - - companion object { - val INSTANCE = MessageGeneratorImpl(PayloadGenerator()) - } } diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGenerator.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt index c8b97639..66f34e9e 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGenerator.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.simulators.xnf.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload.PMObject diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt index 6f8a95a4..07027173 100644 --- a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/MessageFactoryTest.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/MessageGeneratorImplTest.kt @@ -17,14 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.simulators.xnf.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl.impl import com.google.protobuf.ByteString import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.describe import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it -import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator +import org.onap.dcae.collectors.veshv.ves.message.generator.config.MessageParameters import org.onap.ves.VesEventV5 import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.HVRANMEAS import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Priority.MEDIUM @@ -37,22 +38,22 @@ const val SAMPLE_LAST_EPOCH: Long = 120034455 * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since June 2018 */ -object MessageFactoryTest : Spek({ +object MessageGeneratorImplTest : Spek({ describe("message factory") { - val factory = MessageGeneratorImpl.INSTANCE + val generator = MessageGenerator.INSTANCE given("only common header") { it("should return infinite flux") { val limit = 1000L - factory.createMessageFlux(getSampleMessageParameters()).take(limit).test() + generator.createMessageFlux(getSampleMessageParameters()).take(limit).test() .expectNextCount(limit) .verifyComplete() } } given("common header and messages amount") { it("should return message flux of specified size") { - factory.createMessageFlux((getSampleMessageParameters(5))).test() + generator.createMessageFlux((getSampleMessageParameters(5))).test() .expectNextCount(5) .verifyComplete() } @@ -60,7 +61,7 @@ object MessageFactoryTest : Spek({ } }) -fun getSampleMessageParameters(amount: Long = -1): MessageParameters{ +fun getSampleMessageParameters(amount: Long = -1): MessageParameters { val commonHeader = VesEventV5.VesEvent.CommonEventHeader.newBuilder() .setVersion("sample-version") .setDomain(HVRANMEAS) diff --git a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGeneratorTest.kt b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt index 73129a7f..9760208f 100644 --- a/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/PayloadGeneratorTest.kt +++ b/hv-collector-ves-message-generator/src/test/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/impl/PayloadGeneratorTest.kt @@ -17,13 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.simulators.xnf.impl +package org.onap.dcae.collectors.veshv.ves.message.generator.impl.impl import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it import org.assertj.core.api.Assertions.assertThat import org.jetbrains.spek.api.dsl.on +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator private const val DEFAULT_MEASUREMENTS_NUMBER = 2 private const val DEFAULT_COUNTERS_NUMBER = 2 diff --git a/hv-collector-xnf-simulator/pom.xml b/hv-collector-xnf-simulator/pom.xml index 9af2246d..2a02fae1 100644 --- a/hv-collector-xnf-simulator/pom.xml +++ b/hv-collector-xnf-simulator/pom.xml @@ -94,6 +94,11 @@ <version>${project.parent.version}</version> </dependency> <dependency> + <groupId>${project.parent.groupId}</groupId> + <artifactId>hv-collector-ves-message-generator</artifactId> + <version>${project.parent.version}</version> + </dependency> + <dependency> <groupId>io.arrow-kt</groupId> <artifactId>arrow-effects</artifactId> </dependency> diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/factory.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/factory.kt deleted file mode 100644 index dce386b1..00000000 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/factory.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ============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 - -import org.onap.dcae.collectors.veshv.simulators.xnf.api.MessageGenerator -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.MessageGeneratorImpl -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.PayloadGenerator - -/** - * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> - * @since June 2018 - */ -fun createMessageGenerator(): MessageGenerator = MessageGeneratorImpl(PayloadGenerator()) diff --git a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt index 6346b648..08a35d42 100644 --- a/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt +++ b/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/HttpServer.kt @@ -21,8 +21,9 @@ package org.onap.dcae.collectors.veshv.simulators.xnf.impl import arrow.effects.IO import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage -import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.config.MessageParameters import org.onap.dcae.collectors.veshv.utils.logging.Logger +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator import ratpack.exec.Promise import ratpack.handling.Chain import ratpack.handling.Context @@ -69,7 +70,7 @@ internal class HttpServer(private val vesClient: XnfSimulator) { return ctx.request.body .map { Json.createReader(it.inputStream).readObject() } .map { extractMessageParameters(it) } - .map { MessageGeneratorImpl.INSTANCE.createMessageFlux(it) } + .map { MessageGenerator.INSTANCE.createMessageFlux(it) } } private fun sendAcceptedResponse(ctx: Context) { @@ -95,7 +96,7 @@ internal class HttpServer(private val vesClient: XnfSimulator) { private fun extractMessageParameters(request: JsonObject): MessageParameters = try { - val commonEventHeader = MessageGeneratorImpl.INSTANCE + val commonEventHeader = MessageGenerator.INSTANCE .parseCommonHeader(request.getJsonObject("commonEventHeader")) val messagesAmount = request.getJsonNumber("messagesAmount").longValue() MessageParameters(commonEventHeader, messagesAmount) @@ -47,6 +47,7 @@ <module>hv-collector-domain</module> <module>hv-collector-main</module> <module>hv-collector-utils</module> + <module>hv-collector-ves-message-generator</module> </modules> <properties> |