diff options
Diffstat (limited to 'sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae')
8 files changed, 42 insertions, 37 deletions
diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageParameters.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageParameters.kt index 82b79c0c..a7187166 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageParameters.kt +++ b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageParameters.kt @@ -19,20 +19,36 @@ */ package org.onap.dcae.collectors.veshv.ves.message.generator.api +import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType.INVALID_WIRE_FRAME +import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.options.ImmutableWireFrameVersion +import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.options.WireFrameVersion import org.onap.ves.VesEventOuterClass /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since June 2018 */ -abstract class MessageParameters(val amount: Long = -1) +sealed class MessageParameters /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since February 2019 */ class WireFrameParameters(val messageType: WireFrameType, - amount: Long = -1) : MessageParameters(amount) + val amount: Long = -1) : MessageParameters() { + + val wireFrameVersion: WireFrameVersion + get() = ImmutableWireFrameVersion.builder().let { + if (messageType == INVALID_WIRE_FRAME) + it.major(UNSUPPORTED_MAJOR_VERSION) + else + it + }.build() + + companion object { + private const val UNSUPPORTED_MAJOR_VERSION: Short = 2 + } +} /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> @@ -40,4 +56,4 @@ class WireFrameParameters(val messageType: WireFrameType, */ class VesEventParameters(val commonEventHeader: VesEventOuterClass.CommonEventHeader, val messageType: VesEventType, - amount: Long = -1) : MessageParameters(amount) + val amount: Long = -1) : MessageParameters() diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/factory/MessageGeneratorFactory.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/factory/MessageGeneratorFactory.kt index aa473796..613f9bd1 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/factory/MessageGeneratorFactory.kt +++ b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/factory/MessageGeneratorFactory.kt @@ -19,9 +19,9 @@ */ package org.onap.dcae.collectors.veshv.ves.message.generator.factory -import org.onap.dcae.collectors.veshv.ves.message.generator.impl.vesevent.PayloadGenerator -import org.onap.dcae.collectors.veshv.ves.message.generator.impl.vesevent.VesEventGenerator -import org.onap.dcae.collectors.veshv.ves.message.generator.impl.wireframe.WireFrameGenerator +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator +import org.onap.dcae.collectors.veshv.ves.message.generator.generators.VesEventGenerator +import org.onap.dcae.collectors.veshv.ves.message.generator.generators.RawMessageGenerator /** * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com> @@ -30,5 +30,5 @@ import org.onap.dcae.collectors.veshv.ves.message.generator.impl.wireframe.WireF class MessageGeneratorFactory(private val maxPayloadSizeBytes: Int) { fun createVesEventGenerator() = VesEventGenerator(PayloadGenerator(), maxPayloadSizeBytes) - fun createWireFrameGenerator() = WireFrameGenerator() + fun createWireFrameGenerator() = RawMessageGenerator() } diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/generators/MessageGenerator.kt index 5f8638f0..5682cc4c 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt +++ b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/generators/MessageGenerator.kt @@ -17,8 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.api +package org.onap.dcae.collectors.veshv.ves.message.generator.generators +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParameters import reactor.core.publisher.Flux import reactor.core.publisher.Mono diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/wireframe/WireFrameGenerator.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/generators/RawMessageGenerator.kt index ad45bc5c..9f20bd29 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/wireframe/WireFrameGenerator.kt +++ b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/generators/RawMessageGenerator.kt @@ -17,12 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.impl.wireframe +package org.onap.dcae.collectors.veshv.ves.message.generator.generators -import org.onap.dcae.collectors.veshv.domain.ByteData -import org.onap.dcae.collectors.veshv.domain.PayloadContentType -import org.onap.dcae.collectors.veshv.domain.WireFrameMessage -import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator +import io.netty.buffer.Unpooled import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameParameters import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType.INVALID_GPB_DATA @@ -30,37 +27,29 @@ import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType.IN import org.onap.ves.VesEventOuterClass.VesEvent import reactor.core.publisher.Flux import reactor.core.publisher.Mono +import java.nio.ByteBuffer import java.nio.charset.Charset /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since February 2019 */ -class WireFrameGenerator : MessageGenerator<WireFrameParameters, WireFrameMessage>() { +class RawMessageGenerator : MessageGenerator<WireFrameParameters, ByteBuffer>() { - override fun createMessageFlux(parameters: WireFrameParameters): Flux<WireFrameMessage> = + override fun createMessageFlux(parameters: WireFrameParameters): Flux<ByteBuffer> = parameters.run { Mono .fromCallable { createMessage(messageType) } .let { repeatMessage(it, amount) } } - private fun createMessage(messageType: WireFrameType): WireFrameMessage = + private fun createMessage(messageType: WireFrameType): ByteBuffer = when (messageType) { - INVALID_WIRE_FRAME -> { - val payload = ByteData(VesEvent.getDefaultInstance().toByteArray()) - WireFrameMessage( - payload, - UNSUPPORTED_VERSION, - UNSUPPORTED_VERSION, - PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue, - payload.size()) - } - INVALID_GPB_DATA -> - WireFrameMessage("invalid vesEvent".toByteArray(Charset.defaultCharset())) + INVALID_WIRE_FRAME -> wrap(VesEvent.getDefaultInstance().toByteArray()) + INVALID_GPB_DATA -> wrap("invalid vesEvent".toByteArray(Charset.defaultCharset())) } - companion object { - private const val UNSUPPORTED_VERSION: Short = 2 - } + private fun wrap(bytes: ByteArray) = Unpooled.wrappedBuffer(bytes).nioBuffer() + + } diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/VesEventGenerator.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/generators/VesEventGenerator.kt index 7abd6054..a6669e7d 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/VesEventGenerator.kt +++ b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/generators/VesEventGenerator.kt @@ -17,15 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.impl.vesevent +package org.onap.dcae.collectors.veshv.ves.message.generator.generators import com.google.protobuf.ByteString -import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageGenerator import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventParameters import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType.FIXED_PAYLOAD import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType.TOO_BIG_PAYLOAD import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType.VALID +import org.onap.dcae.collectors.veshv.ves.message.generator.impl.PayloadGenerator import org.onap.ves.VesEventOuterClass.CommonEventHeader import org.onap.ves.VesEventOuterClass.VesEvent import reactor.core.publisher.Flux diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/CommonEventHeaderParser.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/CommonEventHeaderParser.kt index 05938924..f0ae4607 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/CommonEventHeaderParser.kt +++ b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/CommonEventHeaderParser.kt @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * dcaegen2-collectors-veshv * ================================================================================ - * Copyright (C) 2018 NOKIA + * Copyright (C) 2018-2019 NOKIA * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.impl.vesevent +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import arrow.core.Option import com.google.protobuf.util.JsonFormat @@ -29,7 +29,7 @@ import javax.json.JsonObject * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since July 2018 */ -class CommonEventHeaderParser { +internal class CommonEventHeaderParser { fun parse(json: JsonObject): Option<CommonEventHeader> = Option.fromNullable( CommonEventHeader.newBuilder() .apply { JsonFormat.parser().merge(json.toString(), this) } diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageParametersParserImpl.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageParametersParserImpl.kt index 174a01fd..7d6087c2 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageParametersParserImpl.kt +++ b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageParametersParserImpl.kt @@ -33,7 +33,6 @@ import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType.Com import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameParameters import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType import org.onap.dcae.collectors.veshv.ves.message.generator.api.WireFrameType.Companion.isWireFrameType -import org.onap.dcae.collectors.veshv.ves.message.generator.impl.vesevent.CommonEventHeaderParser import javax.json.JsonArray import javax.json.JsonObject import javax.json.JsonValue diff --git a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/PayloadGenerator.kt b/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt index ed521054..5891e7bc 100644 --- a/sources/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/vesevent/PayloadGenerator.kt +++ b/sources/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.ves.message.generator.impl.vesevent +package org.onap.dcae.collectors.veshv.ves.message.generator.impl import com.google.protobuf.ByteString import java.util.* |