2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.simulators.xnf.impl
22 import com.google.protobuf.ByteString
23 import org.onap.dcae.collectors.veshv.domain.WireFrame
24 import org.onap.dcae.collectors.veshv.simulators.xnf.config.MessageParameters
25 import org.onap.ves.VesEventV5.VesEvent
26 import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
27 import reactor.core.publisher.Flux
28 import reactor.core.publisher.Mono
29 import javax.json.JsonObject
32 * @author Jakub Dudycz <jakub.dudycz@nokia.com>
35 class MessageFactory(private val payloadGenerator: PayloadGenerator) {
37 fun createMessageFlux(messageParameters: MessageParameters): Flux<WireFrame> =
38 Mono.fromCallable { createMessage(messageParameters.commonEventHeader) }.let {
39 if (messageParameters.amount < 0)
42 it.repeat(messageParameters.amount)
45 fun parseCommonHeader(json: JsonObject): CommonEventHeader = CommonEventHeader.newBuilder()
46 .setVersion(json.getString("version"))
47 .setDomain(CommonEventHeader.Domain.forNumber(json.getInt("domain")))
48 .setSequence(json.getInt("sequence"))
49 .setPriority(CommonEventHeader.Priority.forNumber(json.getInt("priority")))
50 .setEventId(json.getString("eventId"))
51 .setEventName(json.getString("eventName"))
52 .setEventType(json.getString("eventType"))
53 .setStartEpochMicrosec(json.getJsonNumber("startEpochMicrosec").longValue())
54 .setLastEpochMicrosec(json.getJsonNumber("lastEpochMicrosec").longValue())
55 .setNfNamingCode(json.getString("nfNamingCode"))
56 .setNfcNamingCode(json.getString("nfcNamingCode"))
57 .setReportingEntityId(json.getString("reportingEntityId"))
58 .setReportingEntityName(ByteString.copyFromUtf8(json.getString("reportingEntityName")))
59 .setSourceId(ByteString.copyFromUtf8(json.getString("sourceId")))
60 .setSourceName(json.getString("sourceName"))
64 private fun createMessage(commonHeader: CommonEventHeader): WireFrame =
65 WireFrame(vesMessageBytes(commonHeader))
68 private fun vesMessageBytes(commonHeader: CommonEventHeader): ByteArray {
69 val msg = VesEvent.newBuilder()
70 .setCommonEventHeader(commonHeader)
71 .setHvRanMeasFields(PayloadGenerator().generatePayload().toByteString())
74 return msg.toByteArray()
78 val INSTANCE = MessageFactory(PayloadGenerator())