diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-07-18 14:33:10 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-03 07:59:03 +0200 |
commit | f4a58fbdbcaaba92a4daae0e2807536c3da4c857 (patch) | |
tree | 8a1b7b9db9fe2d65d67661aee142bc0aba7e4ef1 /hv-collector-ves-message-generator/src/main | |
parent | 0d15767178ffff59009de51d3737883aa81df2a6 (diff) |
Support scenarios for continuous streaming test
Added support for below scenarios
-too big payloads
-invalid wire frames
-invalid GPB data
-unsupported domains
Changed input json for xnf simulator endpoint
Closes ONAP-500
Change-Id: I19e84a76cef501e274ea8152f3c33c95dddcaac9
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Issue-ID: DCAEGEN2-601
Diffstat (limited to 'hv-collector-ves-message-generator/src/main')
-rw-r--r-- | hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt | 6 | ||||
-rw-r--r-- | hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageParameters.kt (renamed from hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/config/MessageParameters.kt) | 8 | ||||
-rw-r--r-- | hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageType.kt | 32 | ||||
-rw-r--r-- | hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt | 110 | ||||
-rw-r--r-- | hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt | 4 |
5 files changed, 120 insertions, 40 deletions
diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt index e52db848..7407f692 100644 --- a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageGenerator.kt @@ -20,20 +20,16 @@ package org.onap.dcae.collectors.veshv.ves.message.generator.api import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage -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> * @since June 2018 */ interface MessageGenerator { - fun createMessageFlux(messageParameters: MessageParameters): Flux<PayloadWireFrameMessage> - fun parseCommonHeader(json: JsonObject): VesEventV5.VesEvent.CommonEventHeader + fun createMessageFlux(messageParameters: List<MessageParameters>): Flux<PayloadWireFrameMessage> companion object { val INSTANCE: MessageGenerator by lazy { diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/config/MessageParameters.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageParameters.kt index 7e80cc66..cc00f5ac 100644 --- a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/config/MessageParameters.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageParameters.kt @@ -17,12 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcae.collectors.veshv.ves.message.generator.config +package org.onap.dcae.collectors.veshv.ves.message.generator.api -import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> * @since June 2018 */ -data class MessageParameters(val commonEventHeader: CommonEventHeader, val amount: Long = -1) +data class MessageParameters(val domain: Domain, + val messageType: MessageType, + val amount: Long = -1) diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageType.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageType.kt new file mode 100644 index 00000000..e34ed6d6 --- /dev/null +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/api/MessageType.kt @@ -0,0 +1,32 @@ +/* + * ============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.ves.message.generator.api + +/** + * @author Jakub Dudycz <jakub.dudycz@nokia.com> + * @since July 2018 + */ +enum class MessageType { + VALID, + TOO_BIG_PAYLOAD, + UNSUPPORTED_DOMAIN, + INVALID_WIRE_FRAME, + INVALID_GPB_DATA +} diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt index b2f73894..dca573dc 100644 --- a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/MessageGeneratorImpl.kt @@ -20,14 +20,23 @@ package org.onap.dcae.collectors.veshv.ves.message.generator.impl import com.google.protobuf.ByteString +import org.onap.dcae.collectors.veshv.domain.ByteData +import org.onap.dcae.collectors.veshv.domain.PayloadContentType import org.onap.dcae.collectors.veshv.domain.PayloadWireFrameMessage 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.dcae.collectors.veshv.ves.message.generator.api.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType.* +import org.onap.ves.HVRanMeasFieldsV5 +import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields +import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload import org.onap.ves.VesEventV5.VesEvent import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain.OTHER import reactor.core.publisher.Flux import reactor.core.publisher.Mono -import javax.json.JsonObject +import java.nio.charset.Charset /** * @author Jakub Dudycz <jakub.dudycz@nokia.com> @@ -35,41 +44,78 @@ import javax.json.JsonObject */ class MessageGeneratorImpl internal constructor(private val payloadGenerator: PayloadGenerator) : MessageGenerator { - override fun createMessageFlux(messageParameters: MessageParameters): Flux<PayloadWireFrameMessage> = - Mono.fromCallable { createMessage(messageParameters.commonEventHeader) }.let { - if (messageParameters.amount < 0) - it.repeat() - else - it.repeat(messageParameters.amount) - } + override fun createMessageFlux(messageParameters: List<MessageParameters>): Flux<PayloadWireFrameMessage> = Flux + .fromIterable(messageParameters) + .flatMap { createMessageFlux(it) } - override fun parseCommonHeader(json: JsonObject): CommonEventHeader = CommonEventHeader.newBuilder() - .setVersion(json.getString("version")) - .setDomain(CommonEventHeader.Domain.forNumber(json.getInt("domain"))) - .setSequence(json.getInt("sequence")) - .setPriority(CommonEventHeader.Priority.forNumber(json.getInt("priority"))) - .setEventId(json.getString("eventId")) - .setEventName(json.getString("eventName")) - .setEventType(json.getString("eventType")) - .setStartEpochMicrosec(json.getJsonNumber("startEpochMicrosec").longValue()) - .setLastEpochMicrosec(json.getJsonNumber("lastEpochMicrosec").longValue()) - .setNfNamingCode(json.getString("nfNamingCode")) - .setNfcNamingCode(json.getString("nfcNamingCode")) - .setReportingEntityId(json.getString("reportingEntityId")) - .setReportingEntityName(ByteString.copyFromUtf8(json.getString("reportingEntityName"))) - .setSourceId(ByteString.copyFromUtf8(json.getString("sourceId"))) - .setSourceName(json.getString("sourceName")) - .build() + private fun createMessageFlux(parameters: MessageParameters): Flux<PayloadWireFrameMessage> = + Mono.fromCallable { createMessage(parameters.domain, parameters.messageType) } + .let { + if (parameters.amount < 0) + it.repeat() + else + it.repeat(parameters.amount) + } + private fun createMessage(domain: Domain, messageType: MessageType): PayloadWireFrameMessage = + when (messageType) { + VALID -> + PayloadWireFrameMessage(vesEvent(domain, payloadGenerator.generatePayload())) + TOO_BIG_PAYLOAD -> + PayloadWireFrameMessage(vesEvent(domain, oversizedPayload())) + UNSUPPORTED_DOMAIN -> + PayloadWireFrameMessage(vesEvent(OTHER, payloadGenerator.generatePayload())) + INVALID_WIRE_FRAME -> { + val payload = ByteData(vesEvent(domain, payloadGenerator.generatePayload())) + PayloadWireFrameMessage( + payload, + UNSUPPORTED_VERSION, + PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue, + payload.size()) + } + INVALID_GPB_DATA -> + PayloadWireFrameMessage("invalid vesEvent".toByteArray(Charset.defaultCharset())) + } - private fun createMessage(commonHeader: CommonEventHeader): PayloadWireFrameMessage = - PayloadWireFrameMessage(vesMessageBytes(commonHeader)) + private fun vesEvent(domain: Domain, hvRanMeasPayload: HVRanMeasPayload): ByteArray { + return vesEvent(domain, hvRanMeasPayload.toByteString()) + } + private fun vesEvent(domain: Domain, hvRanMeasPayload: ByteString): ByteArray { + return createVesEvent(createCommonHeader(domain), hvRanMeasPayload).toByteArray() + } - private fun vesMessageBytes(commonHeader: CommonEventHeader): ByteArray = + private fun createVesEvent(commonEventHeader: CommonEventHeader, payload: ByteString): VesEvent = VesEvent.newBuilder() - .setCommonEventHeader(commonHeader) - .setHvRanMeasFields(payloadGenerator.generatePayload().toByteString()) + .setCommonEventHeader(commonEventHeader) + .setHvRanMeasFields(payload) .build() - .toByteArray() + + private fun oversizedPayload() = + payloadGenerator.generateRawPayload(PayloadWireFrameMessage.MAX_PAYLOAD_SIZE + 1) + + + private fun createCommonHeader(domain: Domain): CommonEventHeader = CommonEventHeader.newBuilder() + .setVersion("sample-version") + .setDomain(domain) + .setSequence(1) + .setPriority(CommonEventHeader.Priority.NORMAL) + .setEventId("sample-event-id") + .setEventName("sample-event-name") + .setEventType("sample-event-type") + .setStartEpochMicrosec(SAMPLE_START_EPOCH) + .setLastEpochMicrosec(SAMPLE_LAST_EPOCH) + .setNfNamingCode("sample-nf-naming-code") + .setNfcNamingCode("sample-nfc-naming-code") + .setReportingEntityId("sample-reporting-entity-id") + .setReportingEntityName(ByteString.copyFromUtf8("sample-reporting-entity-name")) + .setSourceId(ByteString.copyFromUtf8("sample-source-id")) + .setSourceName("sample-source-name") + .build() + + companion object { + private const val UNSUPPORTED_VERSION: Short = 2 + private const val SAMPLE_START_EPOCH = 120034455L + private const val SAMPLE_LAST_EPOCH = 120034455L + } } diff --git a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt index 66f34e9e..c85ce035 100644 --- a/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt +++ b/hv-collector-ves-message-generator/src/main/kotlin/org/onap/dcae/collectors/veshv/ves/message/generator/impl/PayloadGenerator.kt @@ -19,6 +19,7 @@ */ package org.onap.dcae.collectors.veshv.ves.message.generator.impl +import com.google.protobuf.ByteString import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload.PMObject import org.onap.ves.HVRanMeasFieldsV5.HVRanMeasFields.HVRanMeasPayload.PMObject.HVRanMeas @@ -28,6 +29,9 @@ internal class PayloadGenerator { private val randomGenerator = Random() + fun generateRawPayload(size: Int): ByteString = + ByteString.copyFrom(ByteArray(size)) + fun generatePayload(numOfCountPerMeas: Long = 2, numOfMeasPerObject: Int = 2): HVRanMeasPayload { val pmObject = generatePmObject(numOfCountPerMeas, numOfMeasPerObject) return HVRanMeasPayload.newBuilder() |