Merge "Revert - Fix memory usage per pod table"
[dcaegen2/collectors/hv-ves.git] / sources / hv-collector-test-utils / src / main / kotlin / org / onap / dcae / collectors / veshv / tests / utils / vesEvents.kt
1 /*
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.dcae.collectors.veshv.tests.utils
21
22
23 import com.google.protobuf.ByteString
24 import com.google.protobuf.MessageLite
25 import org.onap.dcae.collectors.veshv.domain.ByteData
26 import org.onap.dcae.collectors.veshv.domain.PayloadContentType
27 import org.onap.dcae.collectors.veshv.domain.VesEventDomain
28 import org.onap.dcae.collectors.veshv.domain.VesEventDomain.PERF3GPP
29 import org.onap.dcae.collectors.veshv.domain.WireFrameMessage
30 import org.onap.ves.VesEventOuterClass
31 import org.onap.ves.VesEventOuterClass.CommonEventHeader
32 import org.onap.ves.VesEventOuterClass.CommonEventHeader.Priority
33 import java.time.Instant
34 import java.time.temporal.Temporal
35 import java.util.UUID.randomUUID
36
37 fun vesEvent(domain: VesEventDomain = PERF3GPP,
38              id: String = randomUUID().toString(),
39              eventFields: ByteString = ByteString.EMPTY,
40              vesEventListenerVersion: String = "7.0.2"
41 ): VesEventOuterClass.VesEvent = vesEvent(
42         commonHeader(domain, id, vesEventListenerVersion, lastEpochMicrosec = 100000005),
43         eventFields
44 )
45
46 fun vesEvent(commonEventHeader: CommonEventHeader,
47              eventFields: ByteString = ByteString.EMPTY): VesEventOuterClass.VesEvent =
48         VesEventOuterClass.VesEvent.newBuilder()
49                 .setCommonEventHeader(commonEventHeader)
50                 .setEventFields(eventFields)
51                 .build()
52
53 fun commonHeader(domain: VesEventDomain = PERF3GPP,
54                  id: String = randomUUID().toString(),
55                  vesEventListenerVersion: String = "7.0.2",
56                  priority: Priority = Priority.NORMAL,
57                  lastEpochMicrosec: Long = 100000005
58 ): CommonEventHeader =
59         CommonEventHeader.newBuilder()
60                 .setVersion("sample-version")
61                 .setDomain(domain.domainName)
62                 .setSequence(1)
63                 .setPriority(priority)
64                 .setEventId(id)
65                 .setEventName("sample-event-name")
66                 .setEventType("sample-event-type")
67                 .setStartEpochMicrosec(100000000)
68                 .setLastEpochMicrosec(lastEpochMicrosec)
69                 .setNfNamingCode("sample-nf-naming-code")
70                 .setNfcNamingCode("sample-nfc-naming-code")
71                 .setNfVendorName("vendor-name")
72                 .setReportingEntityId(ByteString.copyFromUtf8("sample-reporting-entity-id"))
73                 .setReportingEntityName("sample-reporting-entity-name")
74                 .setSourceId(ByteString.copyFromUtf8("sample-source-id"))
75                 .setSourceName("sample-source-name")
76                 .setTimeZoneOffset("+1")
77                 .setVesEventListenerVersion(vesEventListenerVersion)
78                 .build()
79
80 fun emptyWireProtocolFrame(): WireFrameMessage = wireProtocolFrameWithPayloadSize(0)
81
82
83 fun wireProtocolFrameWithPayloadSize(size: Int): WireFrameMessage = WireFrameMessage(
84         payload = ByteData(ByteArray(size)),
85         versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
86         versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
87         payloadSize = size,
88         payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue
89 )
90
91 fun wireProtocolFrame(commonHeader: CommonEventHeader,
92                       eventFields: ByteString = ByteString.EMPTY,
93                       receivedAt: Temporal = Instant.now()): WireFrameMessage =
94         vesEventBytes(commonHeader, eventFields).let { payload ->
95             WireFrameMessage(
96                     payload = payload,
97                     versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
98                     versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR,
99                     payloadSize = payload.size(),
100                     payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
101                     receivedAt = receivedAt
102             )
103         }
104
105 fun wireProtocolFrame(evt: VesEventOuterClass.VesEvent) =
106         WireFrameMessage(
107                 payload = ByteData(evt.toByteArray()),
108                 payloadSize = evt.serializedSize,
109                 payloadType = PayloadContentType.GOOGLE_PROTOCOL_BUFFER.hexValue,
110                 versionMajor = WireFrameMessage.SUPPORTED_VERSION_MAJOR,
111                 versionMinor = WireFrameMessage.SUPPORTED_VERSION_MINOR
112         )
113
114 fun vesEventBytes(commonHeader: CommonEventHeader, eventFields: ByteString = ByteString.EMPTY): ByteData =
115         vesEvent(commonHeader, eventFields).toByteData()
116
117 fun MessageLite.toByteData(): ByteData = ByteData(toByteArray())