From f738ede42e619f1a5c13671cb560224aa639f1db Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Wed, 25 Jul 2018 16:13:28 +0200 Subject: Pass CommonEventHeader to XNF simulator api This change makes XNF simulator more configurable and allows to validate more message parameters in robot integration tests Closes ONAP-689 Change-Id: Ic0a10f1e1cdd84ac415c00050b4cca1ac496c56b Signed-off-by: Jakub Dudycz Issue-ID: DCAEGEN2-601 --- hv-collector-utils/pom.xml | 14 ++++++ .../utils/messages/CommonEventHeaderParser.kt | 52 ++++++++++++++++++++++ .../utils/messages/MessageParametersParser.kt | 48 ++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/CommonEventHeaderParser.kt create mode 100644 hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt (limited to 'hv-collector-utils') diff --git a/hv-collector-utils/pom.xml b/hv-collector-utils/pom.xml index ea19ba3f..d0e44932 100644 --- a/hv-collector-utils/pom.xml +++ b/hv-collector-utils/pom.xml @@ -59,6 +59,20 @@ + + ${project.parent.groupId} + hv-collector-domain + ${project.parent.version} + + + ${project.parent.groupId} + hv-collector-ves-message-generator + ${project.parent.version} + + + org.glassfish + javax.json + commons-cli commons-cli diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/CommonEventHeaderParser.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/CommonEventHeaderParser.kt new file mode 100644 index 00000000..d115675d --- /dev/null +++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/CommonEventHeaderParser.kt @@ -0,0 +1,52 @@ +/* + * ============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.utils.messages + +import com.google.protobuf.ByteString +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Priority +import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.newBuilder +import javax.json.JsonObject + +/** + * @author Jakub Dudycz + * @since July 2018 + */ +class CommonEventHeaderParser { + fun parse(json: JsonObject): CommonEventHeader = newBuilder() + .setVersion(json.getString("version")) + .setDomain(Domain.valueOf(json.getString("domain"))) + .setSequence(json.getInt("sequence")) + .setPriority(Priority.forNumber(json.getInt("priority"))) + .setEventId(json.getString("version")) + .setEventName(json.getString("version")) + .setEventType(json.getString("version")) + .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() + +} diff --git a/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt new file mode 100644 index 00000000..24c2cbfa --- /dev/null +++ b/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/messages/MessageParametersParser.kt @@ -0,0 +1,48 @@ +/* + * ============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.utils.messages + +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageType +import javax.json.JsonArray + +/** + * @author Jakub Dudycz + * @since July 2018 + */ +class MessageParametersParser( + private val commonEventHeaderParser: CommonEventHeaderParser = CommonEventHeaderParser()) { + + fun parse(request: JsonArray): List = + try { + request + .map { it.asJsonObject() } + .map { + val commonEventHeader = commonEventHeaderParser.parse(it.getJsonObject("commonEventHeader")) + val messageType = MessageType.valueOf(it.getString("messageType")) + val messagesAmount = it.getJsonNumber("messagesAmount").longValue() + MessageParameters(commonEventHeader, messageType, messagesAmount) + } + } catch (e: Exception) { + throw ParsingException("Parsing request body failed", e) + } + + internal class ParsingException(message: String?, cause: Exception) : Exception(message, cause) +} -- cgit 1.2.3-korg