From 3323a01bc3633dd723c1c7e9ad9488f89029bd1f Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Tue, 14 Mar 2023 18:02:29 +0530 Subject: Use Strimzi Kafka and Kafka native APIs dmaapClient library is no longer used as DMaaP-MR is being deprecated Issue-ID: CCSDK-3784 Signed-off-by: Ravi Pendurty Change-Id: I12b9b7c8c57ad983a162e04ad8e76a57978fa9ee Signed-off-by: Ravi Pendurty --- sdnr/wt/mountpoint-registrar/provider/pom.xml | 27 +- .../wt/mountpointregistrar/config/FaultConfig.java | 38 +++ .../mountpointregistrar/config/GeneralConfig.java | 74 ++++++ .../mountpointregistrar/config/MessageConfig.java | 95 ++++++++ .../config/PNFRegistrationConfig.java | 38 +++ .../config/ProvisioningConfig.java | 35 +++ .../config/StndDefinedFaultConfig.java | 37 +++ .../config/StrimziKafkaConfig.java | 98 ++++++++ .../impl/CMBasicHeaderFieldsNotification.java | 100 -------- .../mountpointregistrar/impl/CMNotification.java | 113 --------- .../impl/CMNotificationClient.java | 81 ------ .../impl/DMaaPCMVESMsgConsumer.java | 134 ---------- .../impl/DMaaPFaultVESMsgConsumer.java | 111 --------- .../impl/DMaaPPNFRegVESMsgConsumer.java | 154 ------------ .../impl/DMaaPVESMsgConsumer.java | 35 --- .../impl/DMaaPVESMsgConsumerImpl.java | 194 --------------- .../impl/DMaaPVESMsgConsumerMain.java | 225 ----------------- .../impl/DMaaPVESMsgValidator.java | 25 -- .../wt/mountpointregistrar/impl/FaultConfig.java | 44 ---- .../impl/FaultNotificationClient.java | 75 ------ .../wt/mountpointregistrar/impl/GeneralConfig.java | 87 ------- .../wt/mountpointregistrar/impl/MessageClient.java | 12 +- .../wt/mountpointregistrar/impl/MessageConfig.java | 187 -------------- .../impl/MountpointRegistrarImpl.java | 67 ++--- .../impl/PNFMountPointClient.java | 122 ---------- .../impl/PNFRegistrationConfig.java | 44 ---- .../impl/ProvisioningConfig.java | 41 ---- .../impl/StrimziKafkaVESMsgConsumer.java | 35 +++ .../impl/StrimziKafkaVESMsgConsumerImpl.java | 155 ++++++++++++ .../impl/StrimziKafkaVESMsgConsumerMain.java | 227 +++++++++++++++++ .../impl/StrimziKafkaVESMsgValidator.java | 25 ++ .../kafka/VESMsgKafkaConsumer.java | 81 ++++++ .../cm/CMBasicHeaderFieldsNotification.java | 100 ++++++++ .../vesdomain/cm/CMNotification.java | 113 +++++++++ .../vesdomain/cm/CMNotificationClient.java | 84 +++++++ .../vesdomain/cm/StrimziKafkaCMVESMsgConsumer.java | 138 +++++++++++ .../vesdomain/fault/FaultNotificationClient.java | 77 ++++++ .../fault/StrimziKafkaFaultVESMsgConsumer.java | 114 +++++++++ .../vesdomain/pnfreg/PNFMountPointClient.java | 123 ++++++++++ .../pnfreg/StrimziKafkaPNFRegVESMsgConsumer.java | 156 ++++++++++++ ...StrimziKafkaStndDefinedFaultVESMsgConsumer.java | 141 +++++++++++ .../test/GeneralConfigForTest.java | 66 ----- .../test/PNFRegistrationConfigTest.java | 98 -------- .../test/TestCMBasicHeaderFieldsNotification.java | 45 ---- .../test/TestCMNotificationBuilder.java | 79 ------ .../test/TestCMNotificationClient.java | 70 ------ .../test/TestDMaaPCMVESMsgConsumer.java | 239 ------------------ .../test/TestDMaaPFaultVESMsgConsumer.java | 148 ----------- .../test/TestDMaaPPNFRegVESMsgConsumer.java | 270 -------------------- .../test/TestDMaaPVESMsgConsumerMain.java | 170 ------------- .../mountpointregistrar/test/TestFaultConfig.java | 98 -------- .../test/TestFaultNotificationClient.java | 60 ----- .../test/TestGeneralConfig.java | 54 ---- .../test/TestPNFMountPointClient.java | 63 ----- .../test/TestProvisioningConfig.java | 95 -------- .../TestCMBasicHeaderFieldsNotification.java | 45 ++++ .../test/client/TestCMNotificationBuilder.java | 79 ++++++ .../test/client/TestCMNotificationClient.java | 70 ++++++ .../test/client/TestFaultNotificationClient.java | 60 +++++ .../test/client/TestPNFMountPointClient.java | 63 +++++ .../test/config/GeneralConfigForTest.java | 65 +++++ .../test/config/PNFRegistrationConfigTest.java | 75 ++++++ .../test/config/TestFaultConfig.java | 76 ++++++ .../test/config/TestGeneralConfig.java | 53 ++++ .../test/config/TestProvisioningConfig.java | 69 ++++++ .../test/config/TestStrimziKafkaConfig.java | 73 ++++++ .../consumer/TestStrimziKafkaCMVESMsgConsumer.java | 239 ++++++++++++++++++ .../TestStrimziKafkaFaultVESMsgConsumer.java | 150 ++++++++++++ .../TestStrimziKafkaPNFRegVESMsgConsumer.java | 271 +++++++++++++++++++++ .../TestStrimziKafkaStndDefinedVESMsgConsumer.java | 239 ++++++++++++++++++ .../TestStrimziKafkaVESMsgConsumerMain.java | 175 +++++++++++++ 71 files changed, 3850 insertions(+), 3369 deletions(-) create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/FaultConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/GeneralConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/PNFRegistrationConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/ProvisioningConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StndDefinedFaultConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StrimziKafkaConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMBasicHeaderFieldsNotification.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotification.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotificationClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPCMVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerImpl.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgValidator.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultNotificationClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFMountPointClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFRegistrationConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/ProvisioningConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerMain.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgValidator.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMBasicHeaderFieldsNotification.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotification.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotificationClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/StrimziKafkaCMVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/FaultNotificationClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/StrimziKafkaFaultVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/PNFMountPointClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/StrimziKafkaPNFRegVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/stnddefined/StrimziKafkaStndDefinedFaultVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java delete mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMBasicHeaderFieldsNotification.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationBuilder.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestFaultNotificationClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaFaultVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java create mode 100644 sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java diff --git a/sdnr/wt/mountpoint-registrar/provider/pom.xml b/sdnr/wt/mountpoint-registrar/provider/pom.xml index 5cfd49bda..6f1676e9e 100644 --- a/sdnr/wt/mountpoint-registrar/provider/pom.xml +++ b/sdnr/wt/mountpoint-registrar/provider/pom.xml @@ -22,7 +22,9 @@ ~ ============LICENSE_END======================================================= ~ --> - + + 4.0.0 @@ -48,10 +50,14 @@ true yyyy-MM-dd HH:mm - ${maven.build.timestamp} UTC + ${maven.build.timestamp} UTC + + org.apache.kafka + kafka-clients + ${project.groupId} sdnr-wt-mountpoint-registrar-model @@ -90,6 +96,11 @@ rfc6991-ietf-yang-types provided + + jakarta.servlet + jakarta.servlet-api + test + org.opendaylight.mdsal yang-binding @@ -106,14 +117,10 @@ provided - org.onap.dmaap.messagerouter.dmaapclient - dmaapClient + com.google.code.findbugs + annotations + provided - - com.google.code.findbugs - annotations - provided - org.mockito @@ -121,7 +128,7 @@ test - + diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/FaultConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/FaultConfig.java new file mode 100644 index 000000000..42180bd44 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/FaultConfig.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.config; + +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; + +public class FaultConfig extends MessageConfig { + + private static final String SECTION_MARKER = "fault"; + private static final String DEFAULT_VALUE_CONSUMER_TOPIC = "unauthenticated.SEC_FAULT_OUTPUT"; + + + public FaultConfig(ConfigurationFileRepresentation configuration) { + super(configuration); + sectionMarker = SECTION_MARKER; + super.configuration.addSection(SECTION_MARKER); + super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_TOPIC, + DEFAULT_VALUE_CONSUMER_TOPIC); + defaults(); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/GeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/GeneralConfig.java new file mode 100644 index 000000000..a8f920497 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/GeneralConfig.java @@ -0,0 +1,74 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.config; + +import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; + +/** + * Configuration of mountpoint-registrar, general section
+ */ +public class GeneralConfig implements Configuration { + + private static final String SECTION_MARKER = "general"; + + private static final String PROPERTY_KEY_USER = "sdnrUser"; + private static final String DEFAULT_VALUE_USER = "${SDNRUSERNAME}"; + + private static final String PROPERTY_KEY_USERPASSWD = "sdnrPasswd"; + private static final String DEFAULT_VALUE_USERPASSWD = "${SDNRPASSWORD}"; + + private static final String PROPERTY_KEY_BASEURL = "baseUrl"; + private static final String DEFAULT_VALUE_BASEURL = "http://localhost:8181"; + + + private ConfigurationFileRepresentation configuration; + + public GeneralConfig(ConfigurationFileRepresentation configuration) { + this.configuration = configuration; + configuration.addSection(SECTION_MARKER); + defaults(); + } + + public String getBaseUrl() { + return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BASEURL); + } + + public String getSDNRUser() { + return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USER); + } + + public String getSDNRPasswd() { + return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USERPASSWD); + } + + @Override + public String getSectionName() { + return SECTION_MARKER; + } + + @Override + public void defaults() { + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_BASEURL, DEFAULT_VALUE_BASEURL); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USER, DEFAULT_VALUE_USER); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USERPASSWD, DEFAULT_VALUE_USERPASSWD); + } + + + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java new file mode 100644 index 000000000..3b3394454 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/MessageConfig.java @@ -0,0 +1,95 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.config; + +import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; + + +public abstract class MessageConfig implements Configuration { + protected String sectionMarker; + + public static final String PROPERTY_KEY_CONSUMER_TOPIC = "topic"; + + public static final String PROPERTY_KEY_CONSUMER_GROUP = "consumerGroup"; + private static final String DEFAULT_VALUE_CONSUMER_GROUP = "myG"; + + public static final String PROPERTY_KEY_CONSUMER_ID = "consumerID"; + private static final String DEFAULT_VALUE_CONSUMER_ID = "C1"; + + public static final String PROPERTY_KEY_CONSUMER_TIMEOUT = "timeout"; + private static final String DEFAULT_VALUE_CONSUMER_TIMEOUT = "20000"; + + public static final String PROPERTY_KEY_CONSUMER_LIMIT = "limit"; + private static final String DEFAULT_VALUE_CONSUMER_LIMIT = "10000"; + + public static final String PROPERTY_KEY_CONSUMER_FETCHPAUSE = "fetchPause"; + private static final String DEFAULT_VALUE_CONSUMER_FETCHPAUSE = "5000"; + + protected ConfigurationFileRepresentation configuration; + + public MessageConfig(ConfigurationFileRepresentation configuration) { + this.configuration = configuration; + } + + @Override + public String getSectionName() { + return sectionMarker; + } + + @Override + public void defaults() { + configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_GROUP, + DEFAULT_VALUE_CONSUMER_GROUP); + configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_ID, DEFAULT_VALUE_CONSUMER_ID); + configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_TIMEOUT, + DEFAULT_VALUE_CONSUMER_TIMEOUT); + configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_LIMIT, + DEFAULT_VALUE_CONSUMER_LIMIT); + configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_FETCHPAUSE, + DEFAULT_VALUE_CONSUMER_FETCHPAUSE); + } + + public String getTopic() { + return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_TOPIC); + } + + public String getConsumerGroup() { + return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_GROUP); + } + + public String getConsumerId() { + return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_ID); + } + + public String getTimeout() { + return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_TIMEOUT); + } + + public String getLimit() { + return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_LIMIT); + } + + public String getFetchPause() { + return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_FETCHPAUSE); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/PNFRegistrationConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/PNFRegistrationConfig.java new file mode 100644 index 000000000..a2292f576 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/PNFRegistrationConfig.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.config; + +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; + +public class PNFRegistrationConfig extends MessageConfig { + + private static final String SECTION_MARKER = "pnfRegistration"; + private static final String DEFAULT_VALUE_CONSUMER_TOPIC = "unauthenticated.VES_PNFREG_OUTPUT"; + + + public PNFRegistrationConfig(ConfigurationFileRepresentation configuration) { + super(configuration); + sectionMarker = SECTION_MARKER; + super.configuration.addSection(SECTION_MARKER); + super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_TOPIC, + DEFAULT_VALUE_CONSUMER_TOPIC); + defaults(); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/ProvisioningConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/ProvisioningConfig.java new file mode 100644 index 000000000..a2119dbc5 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/ProvisioningConfig.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.config; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; + +public class ProvisioningConfig extends MessageConfig { + + private static final String SECTION_MARKER = "provisioning"; + private static final String DEFAULT_VALUE_CONSUMER_TOPIC = "unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT"; + + public ProvisioningConfig(ConfigurationFileRepresentation configuration) { + super(configuration); + sectionMarker = SECTION_MARKER; + super.configuration.addSection(SECTION_MARKER); + super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_TOPIC, + DEFAULT_VALUE_CONSUMER_TOPIC); + defaults(); + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StndDefinedFaultConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StndDefinedFaultConfig.java new file mode 100644 index 000000000..0a1381c2a --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StndDefinedFaultConfig.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2022 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.config; + +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; + +public class StndDefinedFaultConfig extends MessageConfig { + + private static final String SECTION_MARKER = "stndDefinedFault"; + private static final String DEFAULT_VALUE_CONSUMER_TOPIC = "unauthenticated.SEC_3GPP_FAULTSUPERVISION_OUTPUT"; + + public StndDefinedFaultConfig(ConfigurationFileRepresentation configuration) { + super(configuration); + sectionMarker = SECTION_MARKER; + super.configuration.addSection(SECTION_MARKER); + super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_TOPIC, + DEFAULT_VALUE_CONSUMER_TOPIC); + defaults(); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StrimziKafkaConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StrimziKafkaConfig.java new file mode 100644 index 000000000..41ab8a7cb --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/config/StrimziKafkaConfig.java @@ -0,0 +1,98 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2022 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.config; + +import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; + +/* + * [strimzi-kafka] + * bootstrapServers=abc:9092,def:9092 + * securityProtocol=PLAINTEXT #OTHER POSSIBLE VALUES - SSL, SASL_PLAINTEXT, SASL_SSL + * saslMechanism=PLAIN #Need to understand more + * saslJaasConfig= + * consumerGroup= + * consumerID= + */ +public class StrimziKafkaConfig implements Configuration { + + private static final String SECTION_MARKER = "strimzi-kafka"; + + private static final String PROPERTY_KEY_ENABLED = "strimziEnabled"; + + private static final String PROPERTY_KEY_BOOTSTRAPSERVERS = "bootstrapServers"; + private static final String DEFAULT_VALUE_BOOTSTRAPSERVERS = "onap-strimzi-kafka-0:9094,onap-strimzi-kafka-1:9094"; + + private static final String PROPERTY_KEY_SECURITYPROTOCOL = "securityProtocol"; + private static final String DEFAULT_VALUE_SECURITYPROTOCOL = "PLAINTEXT"; + + private static final String PROPERTY_KEY_SASLMECHANISM = "saslMechanism"; + private static final String DEFAULT_VALUE_SASLMECHANISM = "PLAIN"; + + private static final String PROPERTY_KEY_SASLJAASCONFIG = "saslJaasConfig"; + private static final String DEFAULT_VALUE_SASLJAASCONFIG = "PLAIN"; // TBD + + private ConfigurationFileRepresentation configuration; + + public StrimziKafkaConfig(ConfigurationFileRepresentation configuration) { + this.configuration = configuration; + configuration.addSection(SECTION_MARKER); + defaults(); + } + + public Boolean getEnabled() { + return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_ENABLED); + } + + public String getBootstrapServers() { + return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BOOTSTRAPSERVERS); + } + + public String getSecurityProtocol() { + return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SECURITYPROTOCOL); + } + + public String getSaslMechanism() { + return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SASLMECHANISM); + } + + public String getSaslJaasConfig() { + return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SASLJAASCONFIG); + } + + @Override + public String getSectionName() { + return SECTION_MARKER; + } + + @Override + public void defaults() { + // The default value should be "false" given that SDNR can be run in + // environments where Strimzi is not used + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_ENABLED, Boolean.FALSE); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_BOOTSTRAPSERVERS, + DEFAULT_VALUE_BOOTSTRAPSERVERS); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SECURITYPROTOCOL, + DEFAULT_VALUE_SECURITYPROTOCOL); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SASLMECHANISM, + DEFAULT_VALUE_SASLMECHANISM); + configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SASLJAASCONFIG, + DEFAULT_VALUE_SASLJAASCONFIG); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMBasicHeaderFieldsNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMBasicHeaderFieldsNotification.java deleted file mode 100644 index 98f02ec7a..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMBasicHeaderFieldsNotification.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -public class CMBasicHeaderFieldsNotification { - private String cmNodeId; - private String cmSequence; - private String cmOccurrenceTime; - private String sourceId; - private String notificationType; - - public static CMBasicHeaderFieldsNotificationBuilder builder() { - return new CMBasicHeaderFieldsNotificationBuilder(); - } - - private CMBasicHeaderFieldsNotification( - CMBasicHeaderFieldsNotification.CMBasicHeaderFieldsNotificationBuilder builder) { - this.cmNodeId = builder.cmNodeId; - this.cmSequence = builder.cmSequence; - this.cmOccurrenceTime = builder.cmOccurrenceTime; - this.sourceId = builder.sourceId; - this.notificationType = builder.notificationType; - } - - public static class CMBasicHeaderFieldsNotificationBuilder { - private String cmNodeId; - private String cmSequence; - private String cmOccurrenceTime; - private String sourceId; - private String notificationType; - - public CMBasicHeaderFieldsNotification build() { - return new CMBasicHeaderFieldsNotification(this); - } - - public CMBasicHeaderFieldsNotificationBuilder withCMNodeId(String cmNodeId) { - this.cmNodeId = cmNodeId; - return this; - } - - public CMBasicHeaderFieldsNotificationBuilder withCMSequence( - String cmSequence) { - this.cmSequence = cmSequence; - return this; - } - - public CMBasicHeaderFieldsNotificationBuilder withCMOccurrenceTime( - String cmOccurrenceTime) { - this.cmOccurrenceTime = cmOccurrenceTime; - return this; - } - - public CMBasicHeaderFieldsNotificationBuilder withSourceId(String sourceId) { - this.sourceId = sourceId; - return this; - } - - public CMBasicHeaderFieldsNotificationBuilder withNotificationType( - String notificationType) { - this.notificationType = notificationType; - return this; - } - } - - public String getCmNodeId() { - return cmNodeId; - } - - public String getCmSequence() { - return cmSequence; - } - - public String getCmOccurrenceTime() { - return cmOccurrenceTime; - } - - public String getNotificationType() { - return notificationType; - } - - public String getSourceId() { - return sourceId; - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotification.java deleted file mode 100644 index 014ff648d..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotification.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmOperation; - -public class CMNotification { - private CMBasicHeaderFieldsNotification basicHeaderFields; - private String cmNotificationId; - private String cmSourceIndicator; - private String cmPath; - private String cmOperation; - private String cmValue; - - public static CMNotificationBuilder builder() { - return new CMNotificationBuilder(); - } - - private CMNotification(CMNotificationBuilder builder) { - this.basicHeaderFields = builder.basicHeaderFields; - this.cmNotificationId = builder.cmNotificationId; - this.cmSourceIndicator = builder.cmSourceIndicator; - this.cmPath = builder.cmPath; - this.cmOperation = builder.cmOperation; - this.cmValue = builder.cmValue; - } - - public static class CMNotificationBuilder { - private CMBasicHeaderFieldsNotification basicHeaderFields; - private String cmNotificationId; - private String cmSourceIndicator; - private String cmValue; - private String cmPath; - - private String cmOperation = CmOperation.NULL.getName(); - - - public CMNotification build() { - return new CMNotification(this); - } - - public CMNotificationBuilder withCMBasicHeaderFieldsNotification( - CMBasicHeaderFieldsNotification basicHeaderFields) { - this.basicHeaderFields = basicHeaderFields; - return this; - } - - public CMNotificationBuilder withCMNotificationId( - String cmNotificationId) { - this.cmNotificationId = cmNotificationId; - return this; - } - - public CMNotificationBuilder withCMSourceIndicator(String cmSourceIndicator) { - this.cmSourceIndicator = cmSourceIndicator; - return this; - } - - public CMNotificationBuilder withCMValue(String cmValue) { - this.cmValue = cmValue; - return this; - } - - public CMNotificationBuilder withCMOperation(String cmOperation) { - this.cmOperation = cmOperation; - return this; - } - - public CMNotificationBuilder withCMPath(String cmPath) { - this.cmPath = cmPath; - return this; - } - } - - public CMBasicHeaderFieldsNotification getBasicHeaderFields() { - return basicHeaderFields; - } - - public String getCmSourceIndicator() { - return cmSourceIndicator; - } - - public String getCmPath() { - return cmPath; - } - - public String getCmNotificationId() { - return cmNotificationId; - } - - public String getCmOperation() { - return cmOperation; - } - - public String getCmValue() { - return cmValue; - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotificationClient.java deleted file mode 100644 index 115f0f0c0..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/CMNotificationClient.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.POST; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CMNotificationClient extends MessageClient { - - private static final String CM_NOTIFICATION_URI = "rests/operations/devicemanager:push-cm-notification"; - public static final String NODE_ID = "@node-id@", COUNTER = "@counter@", TIMESTAMP = "@timestamp@", - OBJECT_ID = "@object-id@", NOTIFICATION_TYPE = "@notification-type@", SOURCE_INDICATOR = "@source-indicator@", - NOTIFICATION_ID = "@notification-id@", PATH = "@path@", OPERATION = "@operation@", VALUE = "@value@"; - public static final List REQUIRED_FIELDS = - List.of(NODE_ID, COUNTER, TIMESTAMP, OBJECT_ID, NOTIFICATION_TYPE, NOTIFICATION_ID, SOURCE_INDICATOR, PATH, - OPERATION, VALUE); - - private static final String CM_PAYLOAD = "{\n" - + " \"input\": {\n" - + " \"node-id\": \"" + NODE_ID + "\",\n" - + " \"counter\": \"" + COUNTER + "\",\n" - + " \"timestamp\": \"" + TIMESTAMP + "\",\n" - + " \"object-id\": \"" + OBJECT_ID + "\",\n" - + " \"notification-type\": \"" + NOTIFICATION_TYPE + "\",\n" - + " \"notification-id\": \"" + NOTIFICATION_ID + "\",\n" - + " \"source-indicator\": \"" + SOURCE_INDICATOR + "\",\n" - + " \"path\": \"" + PATH + "\",\n" - + " \"operation\": \"" + OPERATION + "\",\n" - + " \"value\": \"" + VALUE + "\"\n" - + " }\n" - + "}"; - - public CMNotificationClient(String baseUrl) { - super(baseUrl, CM_NOTIFICATION_URI); - } - - @Override - public String prepareMessageFromPayloadMap(Map notificationPayloadMap) { - return super.prepareMessageFromPayloadMap(notificationPayloadMap, CM_PAYLOAD, REQUIRED_FIELDS); - } - - @Override - public boolean sendNotification(String message) { - return super.sendNotification(message, POST, MessageType.json); - } - - - public static Map createCMNotificationPayloadMap(CMNotification cmNotification) { - HashMap map = new HashMap<>(); - map.put(NODE_ID, cmNotification.getBasicHeaderFields().getCmNodeId()); - map.put(COUNTER, cmNotification.getBasicHeaderFields().getCmSequence()); - map.put(TIMESTAMP, cmNotification.getBasicHeaderFields().getCmOccurrenceTime()); - map.put(OBJECT_ID, cmNotification.getBasicHeaderFields().getSourceId()); - map.put(NOTIFICATION_TYPE, cmNotification.getBasicHeaderFields().getNotificationType()); - map.put(NOTIFICATION_ID, cmNotification.getCmNotificationId()); - map.put(SOURCE_INDICATOR, cmNotification.getCmSourceIndicator()); - map.put(PATH, cmNotification.getCmPath()); - map.put(OPERATION, cmNotification.getCmOperation()); - map.put(VALUE, cmNotification.getCmValue()); - return map; - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPCMVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPCMVESMsgConsumer.java deleted file mode 100644 index 8412e3730..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPCMVESMsgConsumer.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import java.time.Instant; -import java.time.ZoneId; -import java.util.Iterator; -import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DMaaPCMVESMsgConsumer extends DMaaPVESMsgConsumerImpl { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPCMVESMsgConsumer.class); - - public DMaaPCMVESMsgConsumer(GeneralConfig generalConfig) { - super(generalConfig); - LOG.info("DMaaPCMVESMsgConsumer started successfully"); - } - - @Override - public void processMsg(String msg) throws InvalidMessageException, JsonProcessingException { - LOG.debug("Processing CM message {}", msg); - JsonNode rootNode = convertMessageToJsonNode(msg); - try { - - String cmNodeId = rootNode.at("/event/commonEventHeader/reportingEntityName").textValue(); - String notificationType = rootNode.at("/event/stndDefinedFields/data/notificationType").textValue(); - - if (notificationType.equalsIgnoreCase("notifyMOIChanges")) { - LOG.info("Read CM message from DMaaP topic that is moiChanges type with id {}", cmNodeId); - processMoiChanges(rootNode); - } else if (notificationType.equalsIgnoreCase("notifyMOICreation")) { - LOG.info("Read CM message from DMaaP topic that is moiCreation type with id {}", cmNodeId); - sendCMNotification(preparePayloadMapFromMoi(rootNode, "/event/stndDefinedFields/data/attributeList")); - } else if (notificationType.equalsIgnoreCase("notifyMOIDeletion")) { - LOG.info("Read CM message from DMaaP topic that is moiDeletion type with id {}", cmNodeId); - sendCMNotification(preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList")); - } else if (notificationType.equalsIgnoreCase("notifyMOIAttributeValueChanges")) { - LOG.info("Read CM message from DMaaP topic that is moiAttributeValueChanges type with id {}", cmNodeId); - sendCMNotification(preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeListValueChanges")); - } else { - LOG.warn("Message is invalid, sending aborted, wrong CM notification type {}", notificationType); - throw new InvalidMessageException(); - } - - } catch (NullPointerException e) { - LOG.warn("Message is invalid, sending aborted, processing stopped because one of fields is missing"); - throw new InvalidMessageException("Missing field"); - } - } - - private CMBasicHeaderFieldsNotification prepareCMCommonHeaderFields(JsonNode rootNode) { - return CMBasicHeaderFieldsNotification.builder() - .withCMNodeId(rootNode.at("/event/commonEventHeader/reportingEntityName").textValue()) - .withCMSequence(rootNode.at("/event/commonEventHeader/sequence").toString()) - .withCMOccurrenceTime(Instant - .ofEpochMilli( - rootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000) - .atZone(ZoneId.of("Z")).toString()) - .withSourceId(rootNode.at("/event/commonEventHeader/sourceId").textValue()) - .withNotificationType(rootNode.at("/event/stndDefinedFields/data/notificationType").textValue()) - .build(); - } - - private void processMoiChanges(JsonNode rootNode) { - Iterator nodes = rootNode - .at("/event/stndDefinedFields/data/moiChanges") - .elements(); - while (nodes.hasNext()) { - sendCMNotification(preparePayloadMapFromMoiChangesArray(rootNode, nodes)); - } - } - - public Map preparePayloadMapFromMoiChangesArray(JsonNode rootNode, Iterator nodes) { - JsonNode slaidNode = nodes.next(); - return CMNotificationClient.createCMNotificationPayloadMap( - CMNotification.builder() - .withCMBasicHeaderFieldsNotification( - prepareCMCommonHeaderFields(rootNode)) - .withCMNotificationId(slaidNode.get("notificationId").toString()) - .withCMSourceIndicator(slaidNode.get("sourceIndicator").textValue()) - .withCMPath(slaidNode.get("path").textValue()) - .withCMOperation(slaidNode.get("operation").textValue()) - .withCMValue(slaidNode.get("value").toString() - .replace("\"", "")) - .build()); - } - - public Map preparePayloadMapFromMoi(JsonNode rootNode, String cmValueKey){ - return CMNotificationClient.createCMNotificationPayloadMap( - CMNotification.builder() - .withCMBasicHeaderFieldsNotification( - prepareCMCommonHeaderFields(rootNode)) - .withCMSourceIndicator(rootNode.at("/event/stndDefinedFields/data/sourceIndicator").textValue()) - .withCMValue(rootNode.at(cmValueKey).toString() - .replace("\"", "")) - .build()); - } - - private void sendCMNotification(Map payloadMapMessage) { - CMNotificationClient cmClient = setRESTConfAuthorization(); - String message = cmClient.prepareMessageFromPayloadMap(payloadMapMessage); - cmClient.sendNotification(message); - } - - - private CMNotificationClient setRESTConfAuthorization() { - String sdnrUser = getSDNRUser(); - String sdnrPasswd = getSDNRPasswd(); - - CMNotificationClient cmClient = new CMNotificationClient(getBaseUrl()); - LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd); - cmClient.setAuthorization(sdnrUser, sdnrPasswd); - return cmClient; - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java deleted file mode 100644 index ee9d0220a..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPFaultVESMsgConsumer.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.time.Instant; -import java.time.ZoneId; -import java.util.Map; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPFaultVESMsgConsumer.class); - - public DMaaPFaultVESMsgConsumer(GeneralConfig generalConfig) { - super(generalConfig); - } - - @Override - public void processMsg(String msg) throws Exception { - String faultNodeId; - String faultOccurrenceTime; - String faultObjectId; - String faultReason; - String faultSeverity; - String vesDomain; - int faultSequence; - String reportingEntityName; - ObjectMapper oMapper = new ObjectMapper(); - JsonNode dmaapMessageRootNode; - - LOG.info("Fault VES Message is - {}", msg); - try { - dmaapMessageRootNode = oMapper.readTree(msg); - reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue(); - if (reportingEntityName.equals("ONAP SDN-R")) { - LOG.info( - "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message"); - return; - } - - vesDomain = dmaapMessageRootNode.at("/event/commonEventHeader/domain").textValue(); - if (!vesDomain.equalsIgnoreCase("fault")) { - LOG.warn("Received {} domain VES Message in DMaaP Fault topic, ignoring it", vesDomain); - return; - } - faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue(); - faultOccurrenceTime = Instant - .ofEpochMilli( - dmaapMessageRootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000) - .atZone(ZoneId.of("Z")).toString(); - faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue(); - faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue(); - faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue(); - faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue(); - - if (faultSeverity.equalsIgnoreCase("critical")) { - faultSeverity = SeverityType.Critical.toString(); - } else if (faultSeverity.equalsIgnoreCase("major")) { - faultSeverity = SeverityType.Major.toString(); - } else if (faultSeverity.equalsIgnoreCase("minor")) { - faultSeverity = SeverityType.Minor.toString(); - } else if (faultSeverity.equalsIgnoreCase("warning")) { - faultSeverity = SeverityType.Warning.toString(); - } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) { - faultSeverity = SeverityType.NonAlarmed.toString(); - } else { - faultSeverity = SeverityType.NonAlarmed.toString(); - } - - String baseUrl = getBaseUrl(); - String sdnrUser = getSDNRUser(); - String sdnrPasswd = getSDNRPasswd(); - - Map payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId, - Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity); - - FaultNotificationClient faultClient = new FaultNotificationClient(baseUrl); - LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd); - faultClient.setAuthorization(sdnrUser, sdnrPasswd); - String message = faultClient.prepareMessageFromPayloadMap(payloadMapMessage); - faultClient.sendNotification(message); - - } catch (IOException e) { - LOG.info("Cannot parse json object "); - throw new Exception("Cannot parse json object", e); - } - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java deleted file mode 100644 index 51d6d1950..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPPNFRegVESMsgConsumer.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.util.Map; -import org.eclipse.jdt.annotation.Nullable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPPNFRegVESMsgConsumer.class); - private static final String DEFAULT_PROTOCOL = "SSH"; - private static final String DEFAULT_PORT = "17830"; - private static final String DEFAULT_USERNAME = "netconf"; - private static final String DEFAULT_PASSWORD = "netconf"; - - - public DMaaPPNFRegVESMsgConsumer(GeneralConfig generalConfig) { - super(generalConfig); - } - - @Override - public void processMsg(String msg) { - LOG.debug("Message from DMaaP topic is - {} ", msg); - String pnfId; - String pnfIPAddress; - @Nullable - String pnfCommProtocol; - @Nullable - String pnfCommPort; - @Nullable - String pnfKeyId = null; - @Nullable - String pnfUsername; - @Nullable - String pnfPasswd = null; - String reportingEntityName; - ObjectMapper oMapper = new ObjectMapper(); - JsonNode dmaapMessageRootNode; - try { - dmaapMessageRootNode = oMapper.readTree(msg); - reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue(); - if (reportingEntityName.equals("ONAP SDN-R")) { - LOG.info( - "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message"); - return; - } - - pnfId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue(); - pnfIPAddress = getPNFIPAddress(dmaapMessageRootNode); - pnfCommProtocol = - dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue(); - pnfCommPort = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue(); - if (pnfCommProtocol != null) { - if (pnfCommProtocol.equalsIgnoreCase("TLS")) { - // Read username and keyId - pnfKeyId = - dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue(); - pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username") - .textValue(); - } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) { - // Read username and password - pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username") - .textValue(); - pnfPasswd = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password") - .textValue(); - } else { - // log warning - Unknown protocol - LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}", - pnfCommProtocol, ". Defaulting to SSH"); - pnfCommProtocol = DEFAULT_PROTOCOL; - pnfCommPort = DEFAULT_PORT; - pnfUsername = DEFAULT_USERNAME; - pnfPasswd = DEFAULT_PASSWORD; - } - } else { - LOG.warn("Protocol not specified in VES message, Defaulting to SSH"); - pnfCommProtocol = DEFAULT_PROTOCOL; - pnfCommPort = DEFAULT_PORT; - pnfUsername = DEFAULT_USERNAME; - pnfPasswd = DEFAULT_PASSWORD; - } - - LOG.debug( - "PNF Fields - ID - {} : IP Address - {} : Protocol - {} : TLS Key ID - {} : User - {} : Port - {}", - pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername, pnfCommPort); - - String baseUrl = getBaseUrl(); - String sdnrUser = getSDNRUser(); - String sdnrPasswd = getSDNRPasswd(); - - if (hasNullInRequiredField(pnfId, pnfIPAddress, pnfCommPort, pnfCommProtocol, pnfUsername)) { - LOG.warn("One of the mandatory fields has a null value - pnfId = {} : pnfIPAddress = {} : " + - "pnfCommProtocol = {} : pnfUsername {} : pnfCommPort {} - not invoking mountpoint creation", - pnfId, pnfIPAddress, pnfCommProtocol, pnfUsername, pnfCommPort); - return; - } - - Map payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap(pnfId, pnfIPAddress, - pnfCommPort, pnfCommProtocol, pnfUsername, pnfPasswd, pnfKeyId); - - PNFMountPointClient mountPointClient = new PNFMountPointClient(baseUrl); - LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd); - mountPointClient.setAuthorization(sdnrUser, sdnrPasswd); - String message = mountPointClient.prepareMessageFromPayloadMap(payloadMap); - mountPointClient.sendNotification(message); - - } catch (IOException e) { - LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}", - e.getMessage()); - } - } - - private boolean hasNullInRequiredField(String pnfId, String pnfIPAddress, String pnfCommPort, - String pnfCommProtocol, String pnfUsername) { - - return pnfId == null || pnfIPAddress == null || pnfCommProtocol == null || - pnfCommPort == null || pnfUsername == null; - } - - private String getPNFIPAddress(JsonNode dmaapMessageRootNode) { - String ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV6IpAddress").textValue(); - if (ipAddress != null && ipAddress != "") - return ipAddress; - - ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue(); - if (ipAddress != null && ipAddress != "") - return ipAddress; - - return null; - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumer.java deleted file mode 100644 index 2874c906f..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import java.util.Properties; - -public abstract interface DMaaPVESMsgConsumer extends Runnable { - - public abstract void init(Properties baseProperties); - - public abstract void processMsg(String msg) throws Exception;//Implement something like InvalidMessageException; - - public abstract boolean isReady(); - - public abstract boolean isRunning(); - - public abstract void stopConsumer(); - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerImpl.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerImpl.java deleted file mode 100644 index 34b8d4031..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerImpl.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import java.util.Properties; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.dmaap.mr.client.MRClientFactory; -import org.onap.dmaap.mr.client.MRConsumer; -import org.onap.dmaap.mr.client.response.MRConsumerResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class DMaaPVESMsgConsumerImpl implements DMaaPVESMsgConsumer, DMaaPVESMsgValidator { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPVESMsgConsumerImpl.class); - private static final String DEFAULT_SDNRUSER = "admin"; - private static final String DEFAULT_SDNRPASSWD = "admin"; - - private final String name = this.getClass().getSimpleName(); - private Properties properties = null; - private MRConsumer consumer = null; - private boolean running = false; - private boolean ready = false; - private int fetchPause = 5000; // Default pause between fetch - 5 seconds - private int timeout = 15000; // Default timeout - 15 seconds - protected final GeneralConfig generalConfig; - - protected DMaaPVESMsgConsumerImpl(GeneralConfig generalConfig) { - this.generalConfig = generalConfig; - } - - /* - * Thread to fetch messages from the DMaaP topic. Waits for the messages to arrive on the topic until a certain timeout and returns. - * If no data arrives on the topic, sleeps for a certain time period before checking again - */ - @Override - public void run() { - - if (ready) { - running = true; - while (running) { - try { - boolean noData = true; - MRConsumerResponse consumerResponse = null; - consumerResponse = consumer.fetchWithReturnConsumerResponse(timeout, -1); - for (String msg : consumerResponse.getActualMessages()) { - noData = false; - LOG.debug("{} received ActualMessage from DMaaP VES Message topic {}", name,msg); - if(isMessageValid(msg)) { - processMsg(msg); - } - } - - if (noData) { - LOG.debug("{} received ResponseCode: {}", name, consumerResponse.getResponseCode()); - LOG.debug("{} received ResponseMessage: {}", name, consumerResponse.getResponseMessage()); - if ((consumerResponse.getResponseCode() == null) - && (consumerResponse.getResponseMessage().contains("SocketTimeoutException"))) { - LOG.warn("Client timeout while waiting for response from Server {}", - consumerResponse.getResponseMessage()); - } - pauseThread(); - } - } catch (InterruptedException e) { - LOG.warn("Caught exception reading from DMaaP VES Message Topic", e); - Thread.currentThread().interrupt(); - } catch (JsonProcessingException jsonProcessingException) { - LOG.warn("Failed to convert message to JsonNode: {}", jsonProcessingException.getMessage()); - } catch (InvalidMessageException invalidMessageException) { - LOG.warn("Message is invalid because of: {}", invalidMessageException.getMessage()); - } catch (Exception e) { - LOG.error("Caught exception reading from DMaaP VES Message Topic", e); - running = false; - } - } - } - } - - @Override - public boolean isMessageValid(String message) { - return true; - } - - protected JsonNode convertMessageToJsonNode(String message) throws JsonProcessingException { - return new ObjectMapper().readTree(message); - } - - /* - * Create a consumer by specifying properties containing information such as topic name, timeout, URL etc - */ - @Override - public void init(Properties properties) { - - try { - - String timeoutStr = properties.getProperty("timeout"); - LOG.debug("timeoutStr: {}", timeoutStr); - - if ((timeoutStr != null) && (timeoutStr.length() > 0)) { - timeout = parseTimeOutValue(timeoutStr); - } - - String fetchPauseStr = properties.getProperty("fetchPause"); - LOG.debug("fetchPause(Str): {}",fetchPauseStr); - if ((fetchPauseStr != null) && (fetchPauseStr.length() > 0)) { - fetchPause = parseFetchPause(fetchPauseStr); - } - LOG.debug("fetchPause: {} ",fetchPause); - - this.consumer = MRClientFactory.createConsumer(properties); - ready = true; - } catch (Exception e) { - LOG.error("Error initializing DMaaP VES Message consumer from file {} {}",properties, e); - } - } - - private int parseTimeOutValue(String timeoutStr) { - try { - return Integer.parseInt(timeoutStr); - } catch (NumberFormatException e) { - LOG.error("Non-numeric value specified for timeout ({})",timeoutStr); - } - return timeout; - } - - private int parseFetchPause(String fetchPauseStr) { - try { - return Integer.parseInt(fetchPauseStr); - } catch (NumberFormatException e) { - LOG.error("Non-numeric value specified for fetchPause ({})",fetchPauseStr); - } - return fetchPause; - } - - private void pauseThread() throws InterruptedException { - if (fetchPause > 0) { - LOG.debug("No data received from fetch. Pausing {} ms before retry", fetchPause); - Thread.sleep(fetchPause); - } else { - LOG.debug("No data received from fetch. No fetch pause specified - retrying immediately"); - } - } - - @Override - public boolean isReady() { - return ready; - } - - @Override - public boolean isRunning() { - return running; - } - - public String getProperty(String name) { - return properties.getProperty(name, ""); - } - - @Override - public void stopConsumer() { - running = false; - } - - - public String getBaseUrl() { - return generalConfig.getBaseUrl(); - } - - public String getSDNRUser() { - return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER; - } - - public String getSDNRPasswd() { - return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD; - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java deleted file mode 100644 index 3626f534a..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgConsumerMain.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DMaaPVESMsgConsumerMain implements Runnable { - - private static final Logger LOG = LoggerFactory.getLogger(DMaaPVESMsgConsumerMain.class); - private static final String _PNFREG_CLASS = - "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer"; - private static final String _FAULT_CLASS = - "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer"; - private static final String _CM_CLASS = - "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPCMVESMsgConsumer"; - private static final String _PNFREG_DOMAIN = "pnfRegistration"; - private static final String _FAULT_DOMAIN = "fault"; - private static final String _CM_DOMAIN = "provisioning"; - - boolean threadsRunning = false; - List consumers = new LinkedList<>(); - private PNFRegistrationConfig pnfRegistrationConfig; - private FaultConfig faultConfig; - private GeneralConfig generalConfig; - private ProvisioningConfig provisioningConfig; - - public DMaaPVESMsgConsumerMain(Map configMap, GeneralConfig generalConfig) { - this.generalConfig = generalConfig; - configMap.forEach(this::initialize); - } - - public void initialize(String domain, MessageConfig domainConfig) { - LOG.debug("In initialize method : Domain = {} and domainConfig = {}", domain, domainConfig); - String consumerClass; - Properties consumerProperties = new Properties(); - if (domain.equalsIgnoreCase(_PNFREG_DOMAIN)) { - this.pnfRegistrationConfig = (PNFRegistrationConfig) domainConfig; - consumerClass = _PNFREG_CLASS; - LOG.debug("Consumer class = {}", consumerClass); - - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_TRANSPORTTYPE, - pnfRegistrationConfig.getTransportType()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_HOST_PORT, - pnfRegistrationConfig.getHostPort()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CONTENTTYPE, - pnfRegistrationConfig.getContenttype()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_GROUP, - pnfRegistrationConfig.getConsumerGroup()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_ID, - pnfRegistrationConfig.getConsumerId()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_TOPIC, pnfRegistrationConfig.getTopic()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_TIMEOUT, - pnfRegistrationConfig.getTimeout()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_LIMIT, pnfRegistrationConfig.getLimit()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_FETCHPAUSE, - pnfRegistrationConfig.getFetchPause()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_PROTOCOL, - pnfRegistrationConfig.getProtocol()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_USERNAME, - pnfRegistrationConfig.getUsername()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_PASSWORD, - pnfRegistrationConfig.getPassword()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CLIENT_READTIMEOUT, - pnfRegistrationConfig.getClientReadTimeout()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT, - pnfRegistrationConfig.getClientConnectTimeout()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_URI, - pnfRegistrationConfig.getHTTPProxyURI()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER, - pnfRegistrationConfig.getHTTPProxyUsername()); - consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD, - pnfRegistrationConfig.getHTTPProxyPassword()); - - threadsRunning = createConsumer(_PNFREG_DOMAIN, consumerProperties); - } else if (domain.equalsIgnoreCase(_FAULT_DOMAIN)) { - this.faultConfig = (FaultConfig) domainConfig; - consumerClass = _FAULT_CLASS; - LOG.debug("Consumer class = {}", consumerClass); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_TRANSPORTTYPE, faultConfig.getTransportType()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_HOST_PORT, faultConfig.getHostPort()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CONTENTTYPE, faultConfig.getContenttype()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_GROUP, faultConfig.getConsumerGroup()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_ID, faultConfig.getConsumerId()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_TOPIC, faultConfig.getTopic()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_TIMEOUT, faultConfig.getTimeout()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_LIMIT, faultConfig.getLimit()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_FETCHPAUSE, faultConfig.getFetchPause()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_PROTOCOL, faultConfig.getProtocol()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_USERNAME, faultConfig.getUsername()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_PASSWORD, faultConfig.getPassword()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CLIENT_READTIMEOUT, - faultConfig.getClientReadTimeout()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT, - faultConfig.getClientConnectTimeout()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_URI, - faultConfig.getHTTPProxyURI()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER, - faultConfig.getHTTPProxyUsername()); - consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD, - faultConfig.getHTTPProxyPassword()); - threadsRunning = createConsumer(_FAULT_DOMAIN, consumerProperties); - } else if (domain.equalsIgnoreCase(_CM_DOMAIN)) { - this.provisioningConfig = (ProvisioningConfig) domainConfig; - consumerClass = _CM_CLASS; - LOG.debug("Consumer class = {}", consumerClass); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_TRANSPORTTYPE, - provisioningConfig.getTransportType()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_HOST_PORT, - provisioningConfig.getHostPort()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_CONTENTTYPE, - provisioningConfig.getContenttype()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_GROUP, - provisioningConfig.getConsumerGroup()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_ID, provisioningConfig.getConsumerId()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_TOPIC, provisioningConfig.getTopic()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_TIMEOUT, provisioningConfig.getTimeout()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_LIMIT, provisioningConfig.getLimit()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_FETCHPAUSE, - provisioningConfig.getFetchPause()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_PROTOCOL, provisioningConfig.getProtocol()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_USERNAME, provisioningConfig.getUsername()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_PASSWORD, provisioningConfig.getPassword()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_CLIENT_READTIMEOUT, - provisioningConfig.getClientReadTimeout()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT, - provisioningConfig.getClientConnectTimeout()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_URI, - provisioningConfig.getHTTPProxyURI()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER, - provisioningConfig.getHTTPProxyUsername()); - consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD, - provisioningConfig.getHTTPProxyPassword()); - threadsRunning = createConsumer(_CM_DOMAIN, consumerProperties); - } - } - - private boolean updateThreadState(List consumers) { - boolean threadsRunning = false; - for (DMaaPVESMsgConsumer consumer : consumers) { - if (consumer.isRunning()) { - threadsRunning = true; - } - } - return threadsRunning; - } - - public boolean createConsumer(String consumerType, Properties properties) { - DMaaPVESMsgConsumerImpl consumer = null; - - if (consumerType.equalsIgnoreCase(_PNFREG_DOMAIN)) - consumer = new DMaaPPNFRegVESMsgConsumer(generalConfig); - else if (consumerType.equalsIgnoreCase(_FAULT_DOMAIN)) - consumer = new DMaaPFaultVESMsgConsumer(generalConfig); - else if (consumerType.equalsIgnoreCase(_CM_DOMAIN)) - consumer = new DMaaPCMVESMsgConsumer(generalConfig); - - handleConsumer(consumer, properties, consumers); - return !consumers.isEmpty(); - } - - private boolean handleConsumer(DMaaPVESMsgConsumer consumer, Properties properties, - List consumers) { - if (consumer != null) { - consumer.init(properties); - - if (consumer.isReady()) { - Thread consumerThread = new Thread(consumer); - consumerThread.start(); - consumers.add(consumer); - - LOG.info("Started consumer thread ({} : {})", consumer.getClass().getSimpleName(), properties); - return true; - } else { - LOG.debug("Consumer {} is not ready", consumer.getClass().getSimpleName()); - } - } - return false; - } - - @Override - public void run() { - while (threadsRunning) { - threadsRunning = updateThreadState(consumers); - if (!threadsRunning) { - break; - } - - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - LOG.error(e.getLocalizedMessage(), e); - Thread.currentThread().interrupt(); - } - } - - LOG.info("No listener threads running - exiting"); - } - - public List getConsumers() { - return consumers; - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgValidator.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgValidator.java deleted file mode 100644 index 0532334ef..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/DMaaPVESMsgValidator.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -public interface DMaaPVESMsgValidator { - - boolean isMessageValid(String message); - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultConfig.java deleted file mode 100644 index 7c71f7ee7..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; - -public class FaultConfig extends MessageConfig { - - private static final String SECTION_MARKER = "fault"; - private static final String DEFAULT_VALUE_CONSUMER_USERNAME = "${DMAAP_FAULT_TOPIC_USERNAME}"; - private static final String DEFAULT_VALUE_CONSUMER_PASSWORD = "${DMAAP_FAULT_TOPIC_PASSWORD}"; - private static final String DEFAULT_VALUE_CONSUMER_TOPIC = "unauthenticated.SEC_FAULT_OUTPUT"; - - - public FaultConfig(ConfigurationFileRepresentation configuration) { - super(configuration); - sectionMarker = SECTION_MARKER; - super.configuration.addSection(SECTION_MARKER); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_USERNAME, - DEFAULT_VALUE_CONSUMER_USERNAME); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_PASSWORD, - DEFAULT_VALUE_CONSUMER_PASSWORD); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_TOPIC, - DEFAULT_VALUE_CONSUMER_TOPIC); - defaults(); - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultNotificationClient.java deleted file mode 100644 index ce2538628..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/FaultNotificationClient.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.MessageType.*; -import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.*; - - -public class FaultNotificationClient extends MessageClient { - - private static final String FAULT_NOTIFICATION_URI = "rests/operations/devicemanager:push-fault-notification"; - public static final String NODE_ID = "@node-id@", COUNTER = "@counter@", TIMESTAMP = "@timestamp@", - OBJECT_ID = "@object-id@", PROBLEM = "@problem@", SEVERITY = "@severity@"; - public static final List REQUIRED_FIELDS = List.of(NODE_ID, COUNTER, TIMESTAMP, OBJECT_ID, PROBLEM, SEVERITY); - - private static final String FAULT_PAYLOAD = "{\n" - + " \"input\": {\n" - + " \"node-id\": \"" + NODE_ID + "\",\n" - + " \"counter\": \"" + COUNTER + "\",\n" - + " \"timestamp\": \"" + TIMESTAMP + "\",\n" - + " \"object-id\": \"" + OBJECT_ID + "\",\n" - + " \"problem\": \"" + PROBLEM + "\",\n" - + " \"severity\": \"" + SEVERITY + "\"\n" - + " }\n" - + "}"; - - - public FaultNotificationClient(String baseUrl) { - super(baseUrl, FAULT_NOTIFICATION_URI); - } - - @Override - public String prepareMessageFromPayloadMap(Map notificationPayloadMap) { - return super.prepareMessageFromPayloadMap(notificationPayloadMap, FAULT_PAYLOAD, REQUIRED_FIELDS); - } - - @Override - public boolean sendNotification(String message) { - return super.sendNotification(message, POST, json); - } - - public static Map createFaultNotificationPayloadMap(String nodeId, String counter, String timestamp, - String objectId, String problem, String severity) { - HashMap map = new HashMap<>(); - map.put(NODE_ID, nodeId); - map.put(COUNTER, counter); - map.put(TIMESTAMP, timestamp); - map.put(OBJECT_ID, objectId); - map.put(PROBLEM, problem); - map.put(SEVERITY, severity); - return map; - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java deleted file mode 100644 index eec4e7a9e..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/GeneralConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; - -/** - * Configuration of mountpoint-registrar, general section
- * - dmaapEnabled : Boolean disable/enable service depending on whether DMaaP is running or not Generates default - * Configuration properties if none exist or exist partially Generates Consumer properties only for - * TransportType=HTTPNOAUTH. Other TransportTypes like HTTP, AUTH_KEY and DME2 have additional properties and are not - * generated by default. For a list of applicable properties for the different TranportType values, please see - - * https://wiki.onap.org/display/DW/Feature+configuration+requirements - */ -public class GeneralConfig implements Configuration { - - private static final String SECTION_MARKER = "general"; - - private static final String PROPERTY_KEY_ENABLED = "dmaapEnabled"; - - private static final String PROPERTY_KEY_USER = "sdnrUser"; - private static final String DEFAULT_VALUE_USER = "${SDNRUSERNAME}"; - - private static final String PROPERTY_KEY_USERPASSWD = "sdnrPasswd"; - private static final String DEFAULT_VALUE_USERPASSWD = "${SDNRPASSWORD}"; - - private static final String PROPERTY_KEY_BASEURL = "baseUrl"; - private static final String DEFAULT_VALUE_BASEURL = "http://localhost:8181"; - - - private ConfigurationFileRepresentation configuration; - - public GeneralConfig(ConfigurationFileRepresentation configuration) { - this.configuration = configuration; - configuration.addSection(SECTION_MARKER); - defaults(); - } - - public Boolean getEnabled() { - return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_ENABLED); - } - - public String getBaseUrl() { - return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BASEURL); - } - - public String getSDNRUser() { - return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USER); - } - - public String getSDNRPasswd() { - return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USERPASSWD); - } - - @Override - public String getSectionName() { - return SECTION_MARKER; - } - - @Override - public void defaults() { - // The default value should be "false" given that SDNR can be run in environments where DMaaP is not used - configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_ENABLED, Boolean.FALSE); - configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_BASEURL, DEFAULT_VALUE_BASEURL); - configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USER, DEFAULT_VALUE_USER); - configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USERPASSWD, DEFAULT_VALUE_USERPASSWD); - } - - - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageClient.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageClient.java index 584982a5b..d9d487257 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageClient.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageClient.java @@ -1,5 +1,10 @@ /* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= * Copyright (C) 2021 Samsung Electronics + * Copyright (C) 2022 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= * 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 @@ -9,6 +14,7 @@ * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; @@ -31,11 +37,11 @@ public abstract class MessageClient extends BaseHTTPClient { protected final Map headerMap; private String notificationUri; - protected enum SendMethod { + public /* protected */ enum SendMethod { PUT, POST } - protected enum MessageType { + public /* protected */ enum MessageType { xml, json } @@ -95,7 +101,7 @@ public abstract class MessageClient extends BaseHTTPClient { try { response = sendRequest(notificationUri, method.toString(), message, headerMap); } catch (IOException e) { - LOG.warn("Problem sending fault message: {}", e.getMessage()); + LOG.warn("Problem sending message: {}", e.getMessage()); return false; } LOG.debug("Finished with response code {}", response.code); diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageConfig.java deleted file mode 100644 index 8a6f6442e..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MessageConfig.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; - -public abstract class MessageConfig implements Configuration { - protected String sectionMarker; - - public static final String PROPERTY_KEY_CONSUMER_TRANSPORTTYPE = "TransportType"; - private static final String DEFAULT_VALUE_CONSUMER_TRANSPORTTYPE = "HTTPNOAUTH"; - - public static final String PROPERTY_KEY_CONSUMER_PROTOCOL = "Protocol"; - private static final String DEFAULT_VALUE_CONSUMER_PROTOCOL = "http"; - - public static final String PROPERTY_KEY_CONSUMER_USERNAME = "username"; - public static final String PROPERTY_KEY_CONSUMER_PASSWORD = "password"; - - public static final String PROPERTY_KEY_CONSUMER_HOST_PORT = "host"; - private static final String DEFAULT_VALUE_CONSUMER_HOST_PORT = "onap-dmaap:3904"; - - public static final String PROPERTY_KEY_CONSUMER_TOPIC = "topic"; - - public static final String PROPERTY_KEY_CONSUMER_CONTENTTYPE = "contenttype"; - private static final String DEFAULT_VALUE_CONSUMER_CONTENTTYPE = "application/json"; - - public static final String PROPERTY_KEY_CONSUMER_GROUP = "group"; - private static final String DEFAULT_VALUE_CONSUMER_GROUP = "myG"; - - public static final String PROPERTY_KEY_CONSUMER_ID = "id"; - private static final String DEFAULT_VALUE_CONSUMER_ID = "C1"; - - public static final String PROPERTY_KEY_CONSUMER_TIMEOUT = "timeout"; - private static final String DEFAULT_VALUE_CONSUMER_TIMEOUT = "20000"; - - public static final String PROPERTY_KEY_CONSUMER_LIMIT = "limit"; - private static final String DEFAULT_VALUE_CONSUMER_LIMIT = "10000"; - - public static final String PROPERTY_KEY_CONSUMER_FETCHPAUSE = "fetchPause"; - private static final String DEFAULT_VALUE_CONSUMER_FETCHPAUSE = "5000"; - - public static final String PROPERTY_KEY_CONSUMER_CLIENT_READTIMEOUT = "jersey.config.client.readTimeout"; - private static final String DEFAULT_VALUE_CONSUMER_CLIENT_READTIMEOUT = "25000"; - - public static final String PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT = "jersey.config.client.connectTimeout"; - private static final String DEFAULT_VALUE_CONSUMER_CLIENT_CONNECTTIMEOUT = "25000"; - - public static final String PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER = "jersey.config.client.proxy.username"; - private static final String DEFAULT_VALUE_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER = "${HTTP_PROXY_USERNAME}"; - - public static final String PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD = "jersey.config.client.proxy.password"; - private static final String DEFAULT_VALUE_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD = "${HTTP_PROXY_PASSWORD}"; - - public static final String PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_URI = "jersey.config.client.proxy.uri"; - private static final String DEFAULT_VALUE_CONSUMER_CLIENT_HTTPPROXY_URI = "${HTTP_PROXY_URI}"; - - protected ConfigurationFileRepresentation configuration; - - public MessageConfig(ConfigurationFileRepresentation configuration) { - this.configuration = configuration; - } - - @Override - public String getSectionName() { - return sectionMarker; - } - - @Override - public void defaults() { - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_TRANSPORTTYPE, - DEFAULT_VALUE_CONSUMER_TRANSPORTTYPE); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_PROTOCOL, - DEFAULT_VALUE_CONSUMER_PROTOCOL); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_HOST_PORT, - DEFAULT_VALUE_CONSUMER_HOST_PORT); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_CONTENTTYPE, - DEFAULT_VALUE_CONSUMER_CONTENTTYPE); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_GROUP, - DEFAULT_VALUE_CONSUMER_GROUP); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_ID, DEFAULT_VALUE_CONSUMER_ID); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_TIMEOUT, - DEFAULT_VALUE_CONSUMER_TIMEOUT); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_LIMIT, - DEFAULT_VALUE_CONSUMER_LIMIT); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_FETCHPAUSE, - DEFAULT_VALUE_CONSUMER_FETCHPAUSE); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_READTIMEOUT, - DEFAULT_VALUE_CONSUMER_CLIENT_READTIMEOUT); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT, - DEFAULT_VALUE_CONSUMER_CLIENT_CONNECTTIMEOUT); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER, - DEFAULT_VALUE_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD, - DEFAULT_VALUE_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD); - configuration.setPropertyIfNotAvailable(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_URI, - DEFAULT_VALUE_CONSUMER_CLIENT_HTTPPROXY_URI); - } - - - - public String getHostPort() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_HOST_PORT); - } - - public String getTransportType() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_TRANSPORTTYPE); - } - - public String getProtocol() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_PROTOCOL); - } - - public String getUsername() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_USERNAME); - } - - public String getPassword() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_PASSWORD); - } - - public String getTopic() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_TOPIC); - } - - public String getConsumerGroup() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_GROUP); - } - - public String getConsumerId() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_ID); - } - - public String getTimeout() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_TIMEOUT); - } - - public String getLimit() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_LIMIT); - } - - public String getFetchPause() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_FETCHPAUSE); - } - - public String getContenttype() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_CONTENTTYPE); - } - - public String getClientReadTimeout() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_READTIMEOUT); - } - - public String getClientConnectTimeout() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_CONNECTTIMEOUT); - } - - public String getHTTPProxyURI() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_URI); - } - - public String getHTTPProxyUsername() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_USER); - } - - public String getHTTPProxyPassword() { - return configuration.getProperty(sectionMarker, PROPERTY_KEY_CONSUMER_CLIENT_HTTPPROXY_AUTH_PASSWORD); - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java index 136d2a12b..32d68ee62 100644 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/MountpointRegistrarImpl.java @@ -24,6 +24,13 @@ import java.util.List; import java.util.Map; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.FaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.MessageConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.PNFRegistrationConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.ProvisioningConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.StndDefinedFaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.StrimziKafkaConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,12 +40,13 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis private static final String APPLICATION_NAME = "mountpoint-registrar"; private static final String CONFIGURATIONFILE = "etc/mountpoint-registrar.properties"; - private Thread dmaapVESMsgConsumerMain = null; + private Thread sKafkaVESMsgConsumerMain = null; private GeneralConfig generalConfig; - private boolean dmaapEnabled = false; + private boolean strimziEnabled = false; private Map configMap = new HashMap<>(); - private DMaaPVESMsgConsumerMain dmaapConsumerMain = null; + private StrimziKafkaVESMsgConsumerMain sKafkaConsumerMain = null; + private StrimziKafkaConfig strimziKafkaConfig; // Blueprint 1 public MountpointRegistrarImpl() { @@ -53,22 +61,25 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis configFileRepresentation.registerConfigChangedListener(this); generalConfig = new GeneralConfig(configFileRepresentation); + strimziKafkaConfig = new StrimziKafkaConfig(configFileRepresentation); PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); FaultConfig faultConfig = new FaultConfig(configFileRepresentation); ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); + StndDefinedFaultConfig stndFaultConfig = new StndDefinedFaultConfig(configFileRepresentation); configMap.put("pnfRegistration", pnfRegConfig); configMap.put("fault", faultConfig); configMap.put("provisioning", provisioningConfig); - - dmaapEnabled = generalConfig.getEnabled(); - if (dmaapEnabled) { // start dmaap consumer thread only if dmaapEnabled=true - LOG.info("DMaaP seems to be enabled, starting consumer(s)"); - dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); - dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain); - dmaapVESMsgConsumerMain.start(); + configMap.put("stndDefinedFault", stndFaultConfig); + + strimziEnabled = strimziKafkaConfig.getEnabled(); + if (strimziEnabled) { // start Kafka consumer thread only if strimziEnabled=true + LOG.info("Strimzi Kafka seems to be enabled, starting consumer(s)"); + sKafkaConsumerMain = new StrimziKafkaVESMsgConsumerMain(configMap, generalConfig, strimziKafkaConfig); + sKafkaVESMsgConsumerMain = new Thread(sKafkaConsumerMain); + sKafkaVESMsgConsumerMain.start(); } else { - LOG.info("DMaaP seems to be disabled, not starting any consumer(s)"); + LOG.info("Strimzi Kafka seems to be disabled, not starting any consumer(s)"); } } @@ -83,26 +94,26 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis @Override public void onConfigChanged() { - if (generalConfig == null) { // Included as NullPointerException observed once in docker logs - LOG.warn("onConfigChange cannot be handled. Unexpected Null"); - return; - } - LOG.info("Service configuration state changed. Enabled: {}", generalConfig.getEnabled()); - boolean dmaapEnabledNewVal = generalConfig.getEnabled(); - if (!dmaapEnabled && dmaapEnabledNewVal) { // Dmaap disabled earlier (or during bundle startup) but enabled later, start Consumer(s) - LOG.info("DMaaP is enabled, starting consumer(s)"); - dmaapConsumerMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); - dmaapVESMsgConsumerMain = new Thread(dmaapConsumerMain); - dmaapVESMsgConsumerMain.start(); - } else if (dmaapEnabled && !dmaapEnabledNewVal) { // Dmaap enabled earlier (or during bundle startup) but disabled later, stop consumer(s) - LOG.info("DMaaP is disabled, stopping consumer(s)"); - List consumers = dmaapConsumerMain.getConsumers(); - for (DMaaPVESMsgConsumer consumer : consumers) { + if (generalConfig == null) { // Included as NullPointerException observed once in docker logs + LOG.warn("onConfigChange cannot be handled. Unexpected Null"); + return; + } + LOG.info("Service configuration state changed. Enabled: {}", strimziKafkaConfig.getEnabled()); + boolean strimziEnabledNewVal = strimziKafkaConfig.getEnabled(); + if (!strimziEnabled && strimziEnabledNewVal) { // Strimzi kafka disabled earlier (or during bundle startup) but enabled later, start Consumer(s) + LOG.info("Strimzi Kafka is enabled, starting consumer(s)"); + sKafkaConsumerMain = new StrimziKafkaVESMsgConsumerMain(configMap, generalConfig, strimziKafkaConfig); + sKafkaVESMsgConsumerMain = new Thread(sKafkaConsumerMain); + sKafkaVESMsgConsumerMain.start(); + } else if (strimziEnabled && !strimziEnabledNewVal) { // Strimzi kafka enabled earlier (or during bundle startup) but disabled later, stop consumer(s) + LOG.info("Strimzi Kafka is disabled, stopping consumer(s)"); + List consumers = sKafkaConsumerMain.getConsumers(); + for (StrimziKafkaVESMsgConsumer consumer : consumers) { // stop all consumers consumer.stopConsumer(); } } - dmaapEnabled = dmaapEnabledNewVal; + strimziEnabled = strimziEnabledNewVal; } @Override @@ -125,6 +136,4 @@ public class MountpointRegistrarImpl implements AutoCloseable, IConfigChangedLis } } } - - } diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFMountPointClient.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFMountPointClient.java deleted file mode 100644 index fd31a3fd6..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFMountPointClient.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.MessageType.xml; -import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.PUT; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.jdt.annotation.NonNull; -import org.onap.ccsdk.features.sdnr.wt.common.database.requests.BaseRequest; - -public class PNFMountPointClient extends MessageClient { - - private static final String MOUNTPOINT_URI = - "rests/data/network-topology:network-topology/topology=topology-netconf/node="; - public static final String DEVICE_NAME = "@device-name@", DEVICE_IP = "@device-ip@", DEVICE_PORT = "@device-port@", - USERNAME = "@username@", PASSWORD = "@password@", KEY_ID = "@key-id@"; - private static final String PROTOCOL = "protocol_sec"; - public static List REQUIRED_FIELDS_SSH = List.of(PROTOCOL, DEVICE_NAME, DEVICE_IP, DEVICE_PORT, USERNAME, PASSWORD); - public static List REQUIRED_FIELDS_TLS = List.of(PROTOCOL, DEVICE_NAME, DEVICE_IP, DEVICE_PORT, USERNAME, KEY_ID); - - private static final String SSH_PAYLOAD = "\n" - + " " + DEVICE_NAME + "\n" - + " " + DEVICE_IP + "\n" - + " " + DEVICE_PORT + "\n" - + " " + USERNAME + "\n" - + " " + PASSWORD + "\n" - + " false\n" - + " \n" - + " false\n" - + " 20000\n" - + " 0\n" - + " 2000\n" - + " 1.5\n" - + " \n" - + " 120\n" - + ""; - - private static final String TLS_PAYLOAD = "\n" - + " " + DEVICE_NAME + "\n" - + " " + DEVICE_IP + "\n" - + " " + DEVICE_PORT + "\n" - + " \n" - + " " + USERNAME + "\n" - + " " + KEY_ID + "\n" - + " \n" - + " false\n" - + " \n" - + " TLS\n" - + " \n" - + "\n" - + "false\n" - + "20000\n" - + "0\n" - + "2000\n" - + "1.5\n" - + "\n" - + "120\n" - + ""; - - - public PNFMountPointClient(String baseUrl) { - super(baseUrl, MOUNTPOINT_URI); - } - - @Override - public String prepareMessageFromPayloadMap(Map notificationPayloadMap) { - updateNotificationUriWithPnfName(notificationPayloadMap.get(DEVICE_NAME)); - String message = ""; - if(!notificationPayloadMap.containsKey(PROTOCOL)) { - return message; - } - if(notificationPayloadMap.get(PROTOCOL).equals("SSH")) { - message = super.prepareMessageFromPayloadMap(notificationPayloadMap, SSH_PAYLOAD, REQUIRED_FIELDS_SSH); - } else if(notificationPayloadMap.get(PROTOCOL).equals("TLS")) { - message = super.prepareMessageFromPayloadMap(notificationPayloadMap, TLS_PAYLOAD, REQUIRED_FIELDS_TLS); - } - return message; - } - - private void updateNotificationUriWithPnfName(String pnfName) { - setNotificationUri(MOUNTPOINT_URI + BaseRequest.urlEncodeValue(pnfName)); - } - - @Override - public boolean sendNotification(String message) { - return super.sendNotification(message, PUT, xml); - } - - public static Map createPNFNotificationPayloadMap(@NonNull String pnfName, @NonNull String ipAddress, - @NonNull String commPort, @NonNull String protocol, - String username, String password, String keyId) { - HashMap map = new HashMap<>(); - map.put(DEVICE_NAME, pnfName); - map.put(DEVICE_IP, ipAddress); - map.put(DEVICE_PORT, commPort); - map.put(PROTOCOL, protocol); - map.put(USERNAME, username); - map.put(PASSWORD, password); - map.put(KEY_ID, keyId); - return map; - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFRegistrationConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFRegistrationConfig.java deleted file mode 100644 index acc0b3a89..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/PNFRegistrationConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; - -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; - -public class PNFRegistrationConfig extends MessageConfig { - - private static final String SECTION_MARKER = "pnfRegistration"; - private static final String DEFAULT_VALUE_CONSUMER_USERNAME = "${DMAAP_PNFREG_TOPIC_USERNAME}"; - private static final String DEFAULT_VALUE_CONSUMER_PASSWORD = "${DMAAP_PNFREG_TOPIC_PASSWORD}"; - private static final String DEFAULT_VALUE_CONSUMER_TOPIC = "unauthenticated.VES_PNFREG_OUTPUT"; - - - public PNFRegistrationConfig(ConfigurationFileRepresentation configuration) { - super(configuration); - sectionMarker = SECTION_MARKER; - super.configuration.addSection(SECTION_MARKER); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_USERNAME, - DEFAULT_VALUE_CONSUMER_USERNAME); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_PASSWORD, - DEFAULT_VALUE_CONSUMER_PASSWORD); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_TOPIC, - DEFAULT_VALUE_CONSUMER_TOPIC); - defaults(); - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/ProvisioningConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/ProvisioningConfig.java deleted file mode 100644 index 91a1f3fbe..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/ProvisioningConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; - -public class ProvisioningConfig extends MessageConfig { - - private static final String SECTION_MARKER = "provisioning"; - private static final String DEFAULT_VALUE_CONSUMER_USERNAME = "${DMAAP_CM_TOPIC_USERNAME}"; - private static final String DEFAULT_VALUE_CONSUMER_PASSWORD = "${DMAAP_CM_TOPIC_PASSWORD}"; - private static final String DEFAULT_VALUE_CONSUMER_TOPIC = "unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT"; - - public ProvisioningConfig(ConfigurationFileRepresentation configuration) { - super(configuration); - sectionMarker = SECTION_MARKER; - super.configuration.addSection(SECTION_MARKER); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_USERNAME, - DEFAULT_VALUE_CONSUMER_USERNAME); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_PASSWORD, - DEFAULT_VALUE_CONSUMER_PASSWORD); - super.configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_CONSUMER_TOPIC, - DEFAULT_VALUE_CONSUMER_TOPIC); - defaults(); - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumer.java new file mode 100644 index 000000000..2872384f1 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumer.java @@ -0,0 +1,35 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; + +import java.util.Properties; + +public abstract interface StrimziKafkaVESMsgConsumer extends Runnable { + + public abstract void init(Properties strimziKafkaProperties, Properties properties); + + public abstract void processMsg(String msg) throws Exception;//Implement something like InvalidMessageException; + + public abstract boolean isReady(); + + public abstract boolean isRunning(); + + public abstract void stopConsumer(); + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java new file mode 100644 index 000000000..249eb612e --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerImpl.java @@ -0,0 +1,155 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.List; +import java.util.Properties; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.kafka.VESMsgKafkaConsumer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class StrimziKafkaVESMsgConsumerImpl + implements StrimziKafkaVESMsgConsumer, StrimziKafkaVESMsgValidator { + + private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaVESMsgConsumerImpl.class); + private static final String DEFAULT_SDNRUSER = "admin"; + private static final String DEFAULT_SDNRPASSWD = "admin"; + + private final String name = this.getClass().getSimpleName(); + private VESMsgKafkaConsumer consumer = null; + private boolean running = false; + private boolean ready = false; + private int fetchPause = 5000; // Default pause between fetch - 5 seconds + protected final GeneralConfig generalConfig; + + protected StrimziKafkaVESMsgConsumerImpl(GeneralConfig generalConfig) { + this.generalConfig = generalConfig; + } + + /* + * Thread to fetch messages from the Kafka topic. Waits for the messages to + * arrive on the topic until a certain timeout and returns. If no data arrives + * on the topic, sleeps for a certain time period before checking again + */ + @Override + public void run() { + + if (ready) { + running = true; + while (running) { + try { + boolean noData = true; + List consumerResponse = null; + consumerResponse = consumer.poll(); + for (String msg : consumerResponse) { + noData = false; + LOG.debug("{} received ActualMessage from Kafka VES Message topic {}", name, msg); + if (isMessageValid(msg)) { + processMsg(msg); + } + } + + if (noData) { + pauseThread(); + } + } catch (InterruptedException e) { + LOG.warn("Caught exception reading from Kafka Message Topic", e); + Thread.currentThread().interrupt(); + } catch (JsonProcessingException jsonProcessingException) { + LOG.warn("Failed to convert message to JsonNode: {}", jsonProcessingException.getMessage()); + } catch (InvalidMessageException invalidMessageException) { + LOG.warn("Message is invalid because of: {}", invalidMessageException.getMessage()); + } catch (Exception e) { + LOG.error("Caught exception reading from Kafka Message Topic", e); + running = false; + } + } + } + } + + @Override + public boolean isMessageValid(String message) { + return true; + } + + protected JsonNode convertMessageToJsonNode(String message) throws JsonProcessingException { + return new ObjectMapper().readTree(message); + } + + /* + * Create a Kafka consumer by specifying properties containing information such as + * topic name, timeout, URL etc + */ + @Override + public void init(Properties strimziKafkaProperties, Properties consumerProperties) { + + try { + this.consumer = new VESMsgKafkaConsumer(strimziKafkaProperties, consumerProperties); + this.consumer.subscribe(consumerProperties.getProperty("topic")); + ready = true; + } catch (Exception e) { + LOG.error("Error initializing Kafka Message consumer from file {} {}", consumerProperties, e); + } + } + + private void pauseThread() throws InterruptedException { + if (fetchPause > 0) { + LOG.debug("No data received from fetch. Pausing {} ms before retry", fetchPause); + Thread.sleep(fetchPause); + } else { + LOG.debug("No data received from fetch. No fetch pause specified - retrying immediately"); + } + } + + @Override + public boolean isReady() { + return ready; + } + + @Override + public boolean isRunning() { + return running; + } + + /* + * public String getProperty(String name) { return properties.getProperty(name, + * ""); } + */ + @Override + public void stopConsumer() { + running = false; + } + + public String getBaseUrl() { + return generalConfig.getBaseUrl(); + } + + public String getSDNRUser() { + return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER; + } + + public String getSDNRPasswd() { + return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD; + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerMain.java new file mode 100644 index 000000000..03573d85b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgConsumerMain.java @@ -0,0 +1,227 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.FaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.MessageConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.PNFRegistrationConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.ProvisioningConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.StndDefinedFaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.StrimziKafkaConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.StrimziKafkaCMVESMsgConsumer; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault.StrimziKafkaFaultVESMsgConsumer; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg.StrimziKafkaPNFRegVESMsgConsumer; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.stnddefined.StrimziKafkaStndDefinedFaultVESMsgConsumer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StrimziKafkaVESMsgConsumerMain implements Runnable { + + private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaVESMsgConsumerMain.class); + Properties strimziKafkaProperties = new Properties(); + private static final String _PNFREG_CLASS = + "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer"; + private static final String _FAULT_CLASS = + "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer"; + private static final String _CM_CLASS = + "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPCMVESMsgConsumer"; + private static final String _STNDDEFINED_FAULT_CLASS = + "org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPStndDefinedFaultVESMsgConsumer"; + private static final String _PNFREG_DOMAIN = "pnfRegistration"; + private static final String _FAULT_DOMAIN = "fault"; + private static final String _CM_DOMAIN = "provisioning"; + private static final String _STNDDEFINED_FAULT_DOMAIN = "stndDefinedFault"; + + boolean threadsRunning = false; + List consumers = new LinkedList<>(); + private PNFRegistrationConfig pnfRegistrationConfig; + private FaultConfig faultConfig; + private GeneralConfig generalConfig; + private ProvisioningConfig provisioningConfig; + private StndDefinedFaultConfig stndDefinedFaultConfig; + private StrimziKafkaConfig strimziKafkaConfig; + + public StrimziKafkaVESMsgConsumerMain(Map configMap, GeneralConfig generalConfig) { + this.generalConfig = generalConfig; + configMap.forEach(this::initialize); + } + + public StrimziKafkaVESMsgConsumerMain(Map configMap, GeneralConfig generalConfig, + StrimziKafkaConfig strimziKafkaConfig) { + this.generalConfig = generalConfig; + this.strimziKafkaConfig = strimziKafkaConfig; + configMap.forEach(this::initialize); + } + + public void initialize(String domain, MessageConfig domainConfig) { + LOG.debug("In initialize method : Domain = {} and domainConfig = {}", domain, domainConfig); + String consumerClass; + Properties consumerProperties = new Properties(); + if (domain.equalsIgnoreCase(_PNFREG_DOMAIN)) { + this.pnfRegistrationConfig = (PNFRegistrationConfig) domainConfig; + consumerClass = _PNFREG_CLASS; + LOG.debug("Consumer class = {}", consumerClass); + + consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_GROUP, + pnfRegistrationConfig.getConsumerGroup()); + consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_ID, + pnfRegistrationConfig.getConsumerId()); + consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_TOPIC, pnfRegistrationConfig.getTopic()); + consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_TIMEOUT, + pnfRegistrationConfig.getTimeout()); + consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_LIMIT, pnfRegistrationConfig.getLimit()); + consumerProperties.put(PNFRegistrationConfig.PROPERTY_KEY_CONSUMER_FETCHPAUSE, + pnfRegistrationConfig.getFetchPause()); + + threadsRunning = + createConsumer(_PNFREG_DOMAIN, consumerProperties, getStrimziKafkaProps(strimziKafkaConfig)); + } else if (domain.equalsIgnoreCase(_FAULT_DOMAIN)) { + this.faultConfig = (FaultConfig) domainConfig; + consumerClass = _FAULT_CLASS; + LOG.debug("Consumer class = {}", consumerClass); + consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_GROUP, faultConfig.getConsumerGroup()); + consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_ID, faultConfig.getConsumerId()); + consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_TOPIC, faultConfig.getTopic()); + consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_TIMEOUT, faultConfig.getTimeout()); + consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_LIMIT, faultConfig.getLimit()); + consumerProperties.put(FaultConfig.PROPERTY_KEY_CONSUMER_FETCHPAUSE, faultConfig.getFetchPause()); + + threadsRunning = + createConsumer(_FAULT_DOMAIN, consumerProperties, getStrimziKafkaProps(strimziKafkaConfig)); + } else if (domain.equalsIgnoreCase(_CM_DOMAIN)) { + this.provisioningConfig = (ProvisioningConfig) domainConfig; + consumerClass = _CM_CLASS; + LOG.debug("Consumer class = {}", consumerClass); + consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_GROUP, + provisioningConfig.getConsumerGroup()); + consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_ID, provisioningConfig.getConsumerId()); + consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_TOPIC, provisioningConfig.getTopic()); + consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_TIMEOUT, provisioningConfig.getTimeout()); + consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_LIMIT, provisioningConfig.getLimit()); + consumerProperties.put(ProvisioningConfig.PROPERTY_KEY_CONSUMER_FETCHPAUSE, + provisioningConfig.getFetchPause()); + + threadsRunning = createConsumer(_CM_DOMAIN, consumerProperties, getStrimziKafkaProps(strimziKafkaConfig)); + } else if (domain.equalsIgnoreCase(_STNDDEFINED_FAULT_DOMAIN)) { + this.stndDefinedFaultConfig = (StndDefinedFaultConfig) domainConfig; + consumerClass = _STNDDEFINED_FAULT_CLASS; + LOG.debug("Consumer class = {}", consumerClass); + consumerProperties.put(StndDefinedFaultConfig.PROPERTY_KEY_CONSUMER_GROUP, + stndDefinedFaultConfig.getConsumerGroup()); + consumerProperties.put(StndDefinedFaultConfig.PROPERTY_KEY_CONSUMER_ID, + stndDefinedFaultConfig.getConsumerId()); + consumerProperties.put(StndDefinedFaultConfig.PROPERTY_KEY_CONSUMER_TOPIC, + stndDefinedFaultConfig.getTopic()); + consumerProperties.put(StndDefinedFaultConfig.PROPERTY_KEY_CONSUMER_TIMEOUT, + stndDefinedFaultConfig.getTimeout()); + consumerProperties.put(StndDefinedFaultConfig.PROPERTY_KEY_CONSUMER_LIMIT, + stndDefinedFaultConfig.getLimit()); + consumerProperties.put(StndDefinedFaultConfig.PROPERTY_KEY_CONSUMER_FETCHPAUSE, + stndDefinedFaultConfig.getFetchPause()); + + threadsRunning = createConsumer(_STNDDEFINED_FAULT_DOMAIN, consumerProperties, + getStrimziKafkaProps(strimziKafkaConfig)); + } + } + + private Properties getStrimziKafkaProps(StrimziKafkaConfig strimziKafkaConfig) { + if (strimziKafkaProperties.size() == 0) { + strimziKafkaProperties.put("bootstrapServers", strimziKafkaConfig.getBootstrapServers()); + strimziKafkaProperties.put("securityProtocol", strimziKafkaConfig.getSecurityProtocol()); + strimziKafkaProperties.put("saslMechanism", strimziKafkaConfig.getSaslMechanism()); + strimziKafkaProperties.put("saslJaasConfig", strimziKafkaConfig.getSaslJaasConfig()); + } + return strimziKafkaProperties; + } + + private boolean updateThreadState(List consumers) { + boolean threadsRunning = false; + for (StrimziKafkaVESMsgConsumer consumer : consumers) { + if (consumer.isRunning()) { + threadsRunning = true; + } + } + return threadsRunning; + } + + public boolean createConsumer(String consumerType, Properties consumerProperties, Properties strimziKafkaProps) { + StrimziKafkaVESMsgConsumerImpl consumer = null; + + if (consumerType.equalsIgnoreCase(_PNFREG_DOMAIN)) + consumer = new StrimziKafkaPNFRegVESMsgConsumer(generalConfig); + else if (consumerType.equalsIgnoreCase(_FAULT_DOMAIN)) + consumer = new StrimziKafkaFaultVESMsgConsumer(generalConfig); + else if (consumerType.equalsIgnoreCase(_CM_DOMAIN)) + consumer = new StrimziKafkaCMVESMsgConsumer(generalConfig); + else if (consumerType.equals(_STNDDEFINED_FAULT_DOMAIN)) + consumer = new StrimziKafkaStndDefinedFaultVESMsgConsumer(generalConfig); + + handleConsumer(consumer, consumerProperties, strimziKafkaProps, consumers); + return !consumers.isEmpty(); + } + + private boolean handleConsumer(StrimziKafkaVESMsgConsumer consumer, Properties consumerProperties, + Properties strimziKafkaProps, List consumers) { + if (consumer != null) { + consumer.init(strimziKafkaProps, consumerProperties); + + if (consumer.isReady()) { + Thread consumerThread = new Thread(consumer); + consumerThread.start(); + consumers.add(consumer); + + LOG.info("Started consumer thread ({} : {})", consumer.getClass().getSimpleName(), consumerProperties); + return true; + } else { + LOG.debug("Consumer {} is not ready", consumer.getClass().getSimpleName()); + } + } + return false; + } + + @Override + public void run() { + while (threadsRunning) { + threadsRunning = updateThreadState(consumers); + if (!threadsRunning) { + break; + } + + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + LOG.error(e.getLocalizedMessage(), e); + Thread.currentThread().interrupt(); + } + } + + LOG.info("No listener threads running - exiting"); + } + + public List getConsumers() { + return consumers; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgValidator.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgValidator.java new file mode 100644 index 000000000..b1bd2fca5 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/impl/StrimziKafkaVESMsgValidator.java @@ -0,0 +1,25 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.impl; + +public interface StrimziKafkaVESMsgValidator { + + boolean isMessageValid(String message); + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java new file mode 100644 index 000000000..b8dee44b0 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/kafka/VESMsgKafkaConsumer.java @@ -0,0 +1,81 @@ +package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.kafka; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import org.apache.kafka.clients.CommonClientConfigs; +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.common.config.SaslConfigs; +import org.apache.kafka.common.errors.InvalidGroupIdException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Utility class that provides a KafkaConsumer to communicate with a kafka cluster + */ +public class VESMsgKafkaConsumer { + + private static final Logger log = LoggerFactory.getLogger(VESMsgKafkaConsumer.class); + final KafkaConsumer consumer; + private final int pollTimeout; + private String topicName; + private static final String DESERIALIZER_CLASS = "org.apache.kafka.common.serialization.StringDeserializer"; + + /** + * + * @param consumerProperties + * @param configuration The config provided to the client + */ + public VESMsgKafkaConsumer(Properties strimziKafkaProperties, Properties consumerProperties) { + Properties props = new Properties(); + props.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, strimziKafkaProperties.getProperty("bootstrapServers")); + props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, strimziKafkaProperties.getProperty("securityProtocol")); + props.put(SaslConfigs.SASL_MECHANISM, strimziKafkaProperties.getProperty("saslMechanism")); + props.put(SaslConfigs.SASL_JAAS_CONFIG, strimziKafkaProperties.getProperty("saslJaasConfig")); + props.put(ConsumerConfig.GROUP_ID_CONFIG, + consumerProperties.getProperty("topic") + "-" + consumerProperties.getProperty("consumerGroup")); + props.put(ConsumerConfig.CLIENT_ID_CONFIG, + consumerProperties.getProperty("topic") + "-" + consumerProperties.getProperty("consumerID")); + props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest"); + props.put(ConsumerConfig.ALLOW_AUTO_CREATE_TOPICS_CONFIG, false); + props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, DESERIALIZER_CLASS); + props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, DESERIALIZER_CLASS); + consumer = new KafkaConsumer<>(props); + pollTimeout = Integer.parseInt(consumerProperties.getProperty("timeout")); + } + + /** + * + * @param topic The kafka topic to subscribe to + */ + public void subscribe(String topic) { + try { + consumer.subscribe(Collections.singleton(topic)); + this.topicName = topic; + } catch (InvalidGroupIdException e) { + log.error("Invalid Group {}", e.getMessage()); + } + } + + /** + * + * @return The list of records returned from the poll + */ + public List poll() { + List msgs = new ArrayList<>(); + ConsumerRecords records = consumer.poll(Duration.ofSeconds(pollTimeout)); + for (ConsumerRecord rec : records) { + msgs.add(rec.value()); + } + return msgs; + } + + public String getTopicName() { + return topicName; + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMBasicHeaderFieldsNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMBasicHeaderFieldsNotification.java new file mode 100644 index 000000000..9a01d53d1 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMBasicHeaderFieldsNotification.java @@ -0,0 +1,100 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm; + +public class CMBasicHeaderFieldsNotification { + private String cmNodeId; + private String cmSequence; + private String cmOccurrenceTime; + private String sourceId; + private String notificationType; + + public static CMBasicHeaderFieldsNotificationBuilder builder() { + return new CMBasicHeaderFieldsNotificationBuilder(); + } + + private CMBasicHeaderFieldsNotification( + CMBasicHeaderFieldsNotification.CMBasicHeaderFieldsNotificationBuilder builder) { + this.cmNodeId = builder.cmNodeId; + this.cmSequence = builder.cmSequence; + this.cmOccurrenceTime = builder.cmOccurrenceTime; + this.sourceId = builder.sourceId; + this.notificationType = builder.notificationType; + } + + public static class CMBasicHeaderFieldsNotificationBuilder { + private String cmNodeId; + private String cmSequence; + private String cmOccurrenceTime; + private String sourceId; + private String notificationType; + + public CMBasicHeaderFieldsNotification build() { + return new CMBasicHeaderFieldsNotification(this); + } + + public CMBasicHeaderFieldsNotificationBuilder withCMNodeId(String cmNodeId) { + this.cmNodeId = cmNodeId; + return this; + } + + public CMBasicHeaderFieldsNotificationBuilder withCMSequence( + String cmSequence) { + this.cmSequence = cmSequence; + return this; + } + + public CMBasicHeaderFieldsNotificationBuilder withCMOccurrenceTime( + String cmOccurrenceTime) { + this.cmOccurrenceTime = cmOccurrenceTime; + return this; + } + + public CMBasicHeaderFieldsNotificationBuilder withSourceId(String sourceId) { + this.sourceId = sourceId; + return this; + } + + public CMBasicHeaderFieldsNotificationBuilder withNotificationType( + String notificationType) { + this.notificationType = notificationType; + return this; + } + } + + public String getCmNodeId() { + return cmNodeId; + } + + public String getCmSequence() { + return cmSequence; + } + + public String getCmOccurrenceTime() { + return cmOccurrenceTime; + } + + public String getNotificationType() { + return notificationType; + } + + public String getSourceId() { + return sourceId; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotification.java new file mode 100644 index 000000000..8de9a21d0 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotification.java @@ -0,0 +1,113 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmOperation; + +public class CMNotification { + private CMBasicHeaderFieldsNotification basicHeaderFields; + private String cmNotificationId; + private String cmSourceIndicator; + private String cmPath; + private String cmOperation; + private String cmValue; + + public static CMNotificationBuilder builder() { + return new CMNotificationBuilder(); + } + + private CMNotification(CMNotificationBuilder builder) { + this.basicHeaderFields = builder.basicHeaderFields; + this.cmNotificationId = builder.cmNotificationId; + this.cmSourceIndicator = builder.cmSourceIndicator; + this.cmPath = builder.cmPath; + this.cmOperation = builder.cmOperation; + this.cmValue = builder.cmValue; + } + + public static class CMNotificationBuilder { + private CMBasicHeaderFieldsNotification basicHeaderFields; + private String cmNotificationId; + private String cmSourceIndicator; + private String cmValue; + private String cmPath; + + private String cmOperation = CmOperation.NULL.getName(); + + + public CMNotification build() { + return new CMNotification(this); + } + + public CMNotificationBuilder withCMBasicHeaderFieldsNotification( + CMBasicHeaderFieldsNotification basicHeaderFields) { + this.basicHeaderFields = basicHeaderFields; + return this; + } + + public CMNotificationBuilder withCMNotificationId( + String cmNotificationId) { + this.cmNotificationId = cmNotificationId; + return this; + } + + public CMNotificationBuilder withCMSourceIndicator(String cmSourceIndicator) { + this.cmSourceIndicator = cmSourceIndicator; + return this; + } + + public CMNotificationBuilder withCMValue(String cmValue) { + this.cmValue = cmValue; + return this; + } + + public CMNotificationBuilder withCMOperation(String cmOperation) { + this.cmOperation = cmOperation; + return this; + } + + public CMNotificationBuilder withCMPath(String cmPath) { + this.cmPath = cmPath; + return this; + } + } + + public CMBasicHeaderFieldsNotification getBasicHeaderFields() { + return basicHeaderFields; + } + + public String getCmSourceIndicator() { + return cmSourceIndicator; + } + + public String getCmPath() { + return cmPath; + } + + public String getCmNotificationId() { + return cmNotificationId; + } + + public String getCmOperation() { + return cmOperation; + } + + public String getCmValue() { + return cmValue; + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotificationClient.java new file mode 100644 index 000000000..bdd83cce9 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/CMNotificationClient.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm; + +import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.POST; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.MessageType; + +public class CMNotificationClient extends MessageClient { + + private static final String CM_NOTIFICATION_URI = "rests/operations/devicemanager:push-cm-notification"; + public static final String NODE_ID = "@node-id@", COUNTER = "@counter@", TIMESTAMP = "@timestamp@", + OBJECT_ID = "@object-id@", NOTIFICATION_TYPE = "@notification-type@", SOURCE_INDICATOR = "@source-indicator@", + NOTIFICATION_ID = "@notification-id@", PATH = "@path@", OPERATION = "@operation@", VALUE = "@value@"; + public static final List REQUIRED_FIELDS = + List.of(NODE_ID, COUNTER, TIMESTAMP, OBJECT_ID, NOTIFICATION_TYPE, NOTIFICATION_ID, SOURCE_INDICATOR, PATH, + OPERATION, VALUE); + + private static final String CM_PAYLOAD = "{\n" + + " \"input\": {\n" + + " \"node-id\": \"" + NODE_ID + "\",\n" + + " \"counter\": \"" + COUNTER + "\",\n" + + " \"timestamp\": \"" + TIMESTAMP + "\",\n" + + " \"object-id\": \"" + OBJECT_ID + "\",\n" + + " \"notification-type\": \"" + NOTIFICATION_TYPE + "\",\n" + + " \"notification-id\": \"" + NOTIFICATION_ID + "\",\n" + + " \"source-indicator\": \"" + SOURCE_INDICATOR + "\",\n" + + " \"path\": \"" + PATH + "\",\n" + + " \"operation\": \"" + OPERATION + "\",\n" + + " \"value\": \"" + VALUE + "\"\n" + + " }\n" + + "}"; + + public CMNotificationClient(String baseUrl) { + super(baseUrl, CM_NOTIFICATION_URI); + } + + @Override + public String prepareMessageFromPayloadMap(Map notificationPayloadMap) { + return super.prepareMessageFromPayloadMap(notificationPayloadMap, CM_PAYLOAD, REQUIRED_FIELDS); + } + + @Override + public boolean sendNotification(String message) { + return super.sendNotification(message, POST, MessageType.json); + } + + + public static Map createCMNotificationPayloadMap(CMNotification cmNotification) { + HashMap map = new HashMap<>(); + map.put(NODE_ID, cmNotification.getBasicHeaderFields().getCmNodeId()); + map.put(COUNTER, cmNotification.getBasicHeaderFields().getCmSequence()); + map.put(TIMESTAMP, cmNotification.getBasicHeaderFields().getCmOccurrenceTime()); + map.put(OBJECT_ID, cmNotification.getBasicHeaderFields().getSourceId()); + map.put(NOTIFICATION_TYPE, cmNotification.getBasicHeaderFields().getNotificationType()); + map.put(NOTIFICATION_ID, cmNotification.getCmNotificationId()); + map.put(SOURCE_INDICATOR, cmNotification.getCmSourceIndicator()); + map.put(PATH, cmNotification.getCmPath()); + map.put(OPERATION, cmNotification.getCmOperation()); + map.put(VALUE, cmNotification.getCmValue()); + return map; + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/StrimziKafkaCMVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/StrimziKafkaCMVESMsgConsumer.java new file mode 100644 index 000000000..c32d16273 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/cm/StrimziKafkaCMVESMsgConsumer.java @@ -0,0 +1,138 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import java.time.Instant; +import java.time.ZoneId; +import java.util.Iterator; +import java.util.Map; + +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.StrimziKafkaVESMsgConsumerImpl; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StrimziKafkaCMVESMsgConsumer extends StrimziKafkaVESMsgConsumerImpl { + + private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaCMVESMsgConsumer.class); + + public StrimziKafkaCMVESMsgConsumer(GeneralConfig generalConfig) { + super(generalConfig); + LOG.info("StrimziKafkaCMVESMsgConsumer started successfully"); + } + + @Override + public void processMsg(String msg) throws InvalidMessageException, JsonProcessingException { + LOG.debug("Processing CM message {}", msg); + JsonNode rootNode = convertMessageToJsonNode(msg); + try { + + String cmNodeId = rootNode.at("/event/commonEventHeader/reportingEntityName").textValue(); + String notificationType = rootNode.at("/event/stndDefinedFields/data/notificationType").textValue(); + + if (notificationType.equalsIgnoreCase("notifyMOIChanges")) { + LOG.info("Read CM message from Kafka topic that is moiChanges type with id {}", cmNodeId); + processMoiChanges(rootNode); + } else if (notificationType.equalsIgnoreCase("notifyMOICreation")) { + LOG.info("Read CM message from Kafka topic that is moiCreation type with id {}", cmNodeId); + sendCMNotification(preparePayloadMapFromMoi(rootNode, "/event/stndDefinedFields/data/attributeList")); + } else if (notificationType.equalsIgnoreCase("notifyMOIDeletion")) { + LOG.info("Read CM message from Kafka topic that is moiDeletion type with id {}", cmNodeId); + sendCMNotification(preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList")); + } else if (notificationType.equalsIgnoreCase("notifyMOIAttributeValueChanges")) { + LOG.info("Read CM message from Kafka topic that is moiAttributeValueChanges type with id {}", cmNodeId); + sendCMNotification(preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeListValueChanges")); + } else { + LOG.warn("Message is invalid, sending aborted, wrong CM notification type {}", notificationType); + throw new InvalidMessageException(); + } + + } catch (NullPointerException e) { + LOG.warn("Message is invalid, sending aborted, processing stopped because one of fields is missing"); + throw new InvalidMessageException("Missing field"); + } + } + + private CMBasicHeaderFieldsNotification prepareCMCommonHeaderFields(JsonNode rootNode) { + return CMBasicHeaderFieldsNotification.builder() + .withCMNodeId(rootNode.at("/event/commonEventHeader/reportingEntityName").textValue()) + .withCMSequence(rootNode.at("/event/commonEventHeader/sequence").toString()) + .withCMOccurrenceTime(Instant + .ofEpochMilli( + rootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000) + .atZone(ZoneId.of("Z")).toString()) + .withSourceId(rootNode.at("/event/commonEventHeader/sourceId").textValue()) + .withNotificationType(rootNode.at("/event/stndDefinedFields/data/notificationType").textValue()) + .build(); + } + + private void processMoiChanges(JsonNode rootNode) { + Iterator nodes = rootNode + .at("/event/stndDefinedFields/data/moiChanges") + .elements(); + while (nodes.hasNext()) { + sendCMNotification(preparePayloadMapFromMoiChangesArray(rootNode, nodes)); + } + } + + public Map preparePayloadMapFromMoiChangesArray(JsonNode rootNode, Iterator nodes) { + JsonNode slaidNode = nodes.next(); + return CMNotificationClient.createCMNotificationPayloadMap( + CMNotification.builder() + .withCMBasicHeaderFieldsNotification( + prepareCMCommonHeaderFields(rootNode)) + .withCMNotificationId(slaidNode.get("notificationId").toString()) + .withCMSourceIndicator(slaidNode.get("sourceIndicator").textValue()) + .withCMPath(slaidNode.get("path").textValue()) + .withCMOperation(slaidNode.get("operation").textValue()) + .withCMValue(slaidNode.get("value").toString() + .replace("\"", "")) + .build()); + } + + public Map preparePayloadMapFromMoi(JsonNode rootNode, String cmValueKey){ + return CMNotificationClient.createCMNotificationPayloadMap( + CMNotification.builder() + .withCMBasicHeaderFieldsNotification( + prepareCMCommonHeaderFields(rootNode)) + .withCMSourceIndicator(rootNode.at("/event/stndDefinedFields/data/sourceIndicator").textValue()) + .withCMValue(rootNode.at(cmValueKey).toString() + .replace("\"", "")) + .build()); + } + + private void sendCMNotification(Map payloadMapMessage) { + CMNotificationClient cmClient = setRESTConfAuthorization(); + String message = cmClient.prepareMessageFromPayloadMap(payloadMapMessage); + cmClient.sendNotification(message); + } + + + private CMNotificationClient setRESTConfAuthorization() { + String sdnrUser = getSDNRUser(); + String sdnrPasswd = getSDNRPasswd(); + + CMNotificationClient cmClient = new CMNotificationClient(getBaseUrl()); + LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd); + cmClient.setAuthorization(sdnrUser, sdnrPasswd); + return cmClient; + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/FaultNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/FaultNotificationClient.java new file mode 100644 index 000000000..60a241831 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/FaultNotificationClient.java @@ -0,0 +1,77 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient; + +import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.MessageType.*; +import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.*; + + +public class FaultNotificationClient extends MessageClient { + + private static final String FAULT_NOTIFICATION_URI = "rests/operations/devicemanager:push-fault-notification"; + public static final String NODE_ID = "@node-id@", COUNTER = "@counter@", TIMESTAMP = "@timestamp@", + OBJECT_ID = "@object-id@", PROBLEM = "@problem@", SEVERITY = "@severity@"; + public static final List REQUIRED_FIELDS = List.of(NODE_ID, COUNTER, TIMESTAMP, OBJECT_ID, PROBLEM, SEVERITY); + + private static final String FAULT_PAYLOAD = "{\n" + + " \"input\": {\n" + + " \"node-id\": \"" + NODE_ID + "\",\n" + + " \"counter\": \"" + COUNTER + "\",\n" + + " \"timestamp\": \"" + TIMESTAMP + "\",\n" + + " \"object-id\": \"" + OBJECT_ID + "\",\n" + + " \"problem\": \"" + PROBLEM + "\",\n" + + " \"severity\": \"" + SEVERITY + "\"\n" + + " }\n" + + "}"; + + + public FaultNotificationClient(String baseUrl) { + super(baseUrl, FAULT_NOTIFICATION_URI); + } + + @Override + public String prepareMessageFromPayloadMap(Map notificationPayloadMap) { + return super.prepareMessageFromPayloadMap(notificationPayloadMap, FAULT_PAYLOAD, REQUIRED_FIELDS); + } + + @Override + public boolean sendNotification(String message) { + return super.sendNotification(message, POST, json); + } + + public static Map createFaultNotificationPayloadMap(String nodeId, String counter, String timestamp, + String objectId, String problem, String severity) { + HashMap map = new HashMap<>(); + map.put(NODE_ID, nodeId); + map.put(COUNTER, counter); + map.put(TIMESTAMP, timestamp); + map.put(OBJECT_ID, objectId); + map.put(PROBLEM, problem); + map.put(SEVERITY, severity); + return map; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/StrimziKafkaFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/StrimziKafkaFaultVESMsgConsumer.java new file mode 100644 index 000000000..dc65732b4 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/fault/StrimziKafkaFaultVESMsgConsumer.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.time.Instant; +import java.time.ZoneId; +import java.util.Map; + +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.StrimziKafkaVESMsgConsumerImpl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StrimziKafkaFaultVESMsgConsumer extends StrimziKafkaVESMsgConsumerImpl { + + private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaFaultVESMsgConsumer.class); + + public StrimziKafkaFaultVESMsgConsumer(GeneralConfig generalConfig) { + super(generalConfig); + } + + @Override + public void processMsg(String msg) throws Exception { + String faultNodeId; + String faultOccurrenceTime; + String faultObjectId; + String faultReason; + String faultSeverity; + String vesDomain; + int faultSequence; + String reportingEntityName; + ObjectMapper oMapper = new ObjectMapper(); + JsonNode sKafkaMessageRootNode; + + LOG.info("Fault VES Message is - {}", msg); + try { + sKafkaMessageRootNode = oMapper.readTree(msg); + reportingEntityName = sKafkaMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue(); + if (reportingEntityName.equals("ONAP SDN-R")) { + LOG.info( + "VES Fault message generated by SDNR, hence no need to process any further; Ignoring the received message"); + return; + } + + vesDomain = sKafkaMessageRootNode.at("/event/commonEventHeader/domain").textValue(); + if (!vesDomain.equalsIgnoreCase("fault")) { + LOG.warn("Received {} domain VES Message in Kafka Fault topic, ignoring it", vesDomain); + return; + } + faultNodeId = sKafkaMessageRootNode.at("/event/commonEventHeader/sourceName").textValue(); + faultOccurrenceTime = Instant + .ofEpochMilli( + sKafkaMessageRootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000) + .atZone(ZoneId.of("Z")).toString(); + faultObjectId = sKafkaMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue(); + faultReason = sKafkaMessageRootNode.at("/event/faultFields/specificProblem").textValue(); + faultSeverity = sKafkaMessageRootNode.at("/event/faultFields/eventSeverity").textValue(); + faultSequence = sKafkaMessageRootNode.at("/event/commonEventHeader/sequence").intValue(); + + if (faultSeverity.equalsIgnoreCase("critical")) { + faultSeverity = SeverityType.Critical.toString(); + } else if (faultSeverity.equalsIgnoreCase("major")) { + faultSeverity = SeverityType.Major.toString(); + } else if (faultSeverity.equalsIgnoreCase("minor")) { + faultSeverity = SeverityType.Minor.toString(); + } else if (faultSeverity.equalsIgnoreCase("warning")) { + faultSeverity = SeverityType.Warning.toString(); + } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) { + faultSeverity = SeverityType.NonAlarmed.toString(); + } else { + faultSeverity = SeverityType.NonAlarmed.toString(); + } + + String baseUrl = getBaseUrl(); + String sdnrUser = getSDNRUser(); + String sdnrPasswd = getSDNRPasswd(); + + Map payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId, + Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity); + + FaultNotificationClient faultClient = new FaultNotificationClient(baseUrl); + LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd); + faultClient.setAuthorization(sdnrUser, sdnrPasswd); + String message = faultClient.prepareMessageFromPayloadMap(payloadMapMessage); + faultClient.sendNotification(message); + + } catch (IOException e) { + LOG.info("Cannot parse json object "); + throw new Exception("Cannot parse json object", e); + } + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/PNFMountPointClient.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/PNFMountPointClient.java new file mode 100644 index 000000000..70402a878 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/PNFMountPointClient.java @@ -0,0 +1,123 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg; + +import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.MessageType.xml; +import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.PUT; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.eclipse.jdt.annotation.NonNull; +import org.onap.ccsdk.features.sdnr.wt.common.database.requests.BaseRequest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient; + +public class PNFMountPointClient extends MessageClient { + + private static final String MOUNTPOINT_URI = + "rests/data/network-topology:network-topology/topology=topology-netconf/node="; + public static final String DEVICE_NAME = "@device-name@", DEVICE_IP = "@device-ip@", DEVICE_PORT = "@device-port@", + USERNAME = "@username@", PASSWORD = "@password@", KEY_ID = "@key-id@"; + private static final String PROTOCOL = "protocol_sec"; + public static List REQUIRED_FIELDS_SSH = List.of(PROTOCOL, DEVICE_NAME, DEVICE_IP, DEVICE_PORT, USERNAME, PASSWORD); + public static List REQUIRED_FIELDS_TLS = List.of(PROTOCOL, DEVICE_NAME, DEVICE_IP, DEVICE_PORT, USERNAME, KEY_ID); + + private static final String SSH_PAYLOAD = "\n" + + " " + DEVICE_NAME + "\n" + + " " + DEVICE_IP + "\n" + + " " + DEVICE_PORT + "\n" + + " " + USERNAME + "\n" + + " " + PASSWORD + "\n" + + " false\n" + + " \n" + + " false\n" + + " 20000\n" + + " 0\n" + + " 2000\n" + + " 1.5\n" + + " \n" + + " 120\n" + + ""; + + private static final String TLS_PAYLOAD = "\n" + + " " + DEVICE_NAME + "\n" + + " " + DEVICE_IP + "\n" + + " " + DEVICE_PORT + "\n" + + " \n" + + " " + USERNAME + "\n" + + " " + KEY_ID + "\n" + + " \n" + + " false\n" + + " \n" + + " TLS\n" + + " \n" + + "\n" + + "false\n" + + "20000\n" + + "0\n" + + "2000\n" + + "1.5\n" + + "\n" + + "120\n" + + ""; + + + public PNFMountPointClient(String baseUrl) { + super(baseUrl, MOUNTPOINT_URI); + } + + @Override + public String prepareMessageFromPayloadMap(Map notificationPayloadMap) { + updateNotificationUriWithPnfName(notificationPayloadMap.get(DEVICE_NAME)); + String message = ""; + if(!notificationPayloadMap.containsKey(PROTOCOL)) { + return message; + } + if(notificationPayloadMap.get(PROTOCOL).equals("SSH")) { + message = super.prepareMessageFromPayloadMap(notificationPayloadMap, SSH_PAYLOAD, REQUIRED_FIELDS_SSH); + } else if(notificationPayloadMap.get(PROTOCOL).equals("TLS")) { + message = super.prepareMessageFromPayloadMap(notificationPayloadMap, TLS_PAYLOAD, REQUIRED_FIELDS_TLS); + } + return message; + } + + private void updateNotificationUriWithPnfName(String pnfName) { + setNotificationUri(MOUNTPOINT_URI + BaseRequest.urlEncodeValue(pnfName)); + } + + @Override + public boolean sendNotification(String message) { + return super.sendNotification(message, PUT, xml); + } + + public static Map createPNFNotificationPayloadMap(@NonNull String pnfName, @NonNull String ipAddress, + @NonNull String commPort, @NonNull String protocol, + String username, String password, String keyId) { + HashMap map = new HashMap<>(); + map.put(DEVICE_NAME, pnfName); + map.put(DEVICE_IP, ipAddress); + map.put(DEVICE_PORT, commPort); + map.put(PROTOCOL, protocol); + map.put(USERNAME, username); + map.put(PASSWORD, password); + map.put(KEY_ID, keyId); + return map; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/StrimziKafkaPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/StrimziKafkaPNFRegVESMsgConsumer.java new file mode 100644 index 000000000..147202fb8 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/pnfreg/StrimziKafkaPNFRegVESMsgConsumer.java @@ -0,0 +1,156 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.util.Map; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.StrimziKafkaVESMsgConsumerImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StrimziKafkaPNFRegVESMsgConsumer extends StrimziKafkaVESMsgConsumerImpl { + + private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaPNFRegVESMsgConsumer.class); + private static final String DEFAULT_PROTOCOL = "SSH"; + private static final String DEFAULT_PORT = "17830"; + private static final String DEFAULT_USERNAME = "netconf"; + private static final String DEFAULT_PASSWORD = "netconf"; + + + public StrimziKafkaPNFRegVESMsgConsumer(GeneralConfig generalConfig) { + super(generalConfig); + } + + @Override + public void processMsg(String msg) { + LOG.debug("Message from Kafka topic is - {} ", msg); + String pnfId; + String pnfIPAddress; + @Nullable + String pnfCommProtocol; + @Nullable + String pnfCommPort; + @Nullable + String pnfKeyId = null; + @Nullable + String pnfUsername; + @Nullable + String pnfPasswd = null; + String reportingEntityName; + ObjectMapper oMapper = new ObjectMapper(); + JsonNode sKafkaMessageRootNode; + try { + sKafkaMessageRootNode = oMapper.readTree(msg); + reportingEntityName = sKafkaMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue(); + if (reportingEntityName.equals("ONAP SDN-R")) { + LOG.info( + "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message"); + return; + } + + pnfId = sKafkaMessageRootNode.at("/event/commonEventHeader/sourceName").textValue(); + pnfIPAddress = getPNFIPAddress(sKafkaMessageRootNode); + pnfCommProtocol = + sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue(); + pnfCommPort = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue(); + if (pnfCommProtocol != null) { + if (pnfCommProtocol.equalsIgnoreCase("TLS")) { + // Read username and keyId + pnfKeyId = + sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue(); + pnfUsername = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username") + .textValue(); + } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) { + // Read username and password + pnfUsername = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username") + .textValue(); + pnfPasswd = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password") + .textValue(); + } else { + // log warning - Unknown protocol + LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}", + pnfCommProtocol, ". Defaulting to SSH"); + pnfCommProtocol = DEFAULT_PROTOCOL; + pnfCommPort = DEFAULT_PORT; + pnfUsername = DEFAULT_USERNAME; + pnfPasswd = DEFAULT_PASSWORD; + } + } else { + LOG.warn("Protocol not specified in VES message, Defaulting to SSH"); + pnfCommProtocol = DEFAULT_PROTOCOL; + pnfCommPort = DEFAULT_PORT; + pnfUsername = DEFAULT_USERNAME; + pnfPasswd = DEFAULT_PASSWORD; + } + + LOG.debug( + "PNF Fields - ID - {} : IP Address - {} : Protocol - {} : TLS Key ID - {} : User - {} : Port - {}", + pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername, pnfCommPort); + + String baseUrl = getBaseUrl(); + String sdnrUser = getSDNRUser(); + String sdnrPasswd = getSDNRPasswd(); + + if (hasNullInRequiredField(pnfId, pnfIPAddress, pnfCommPort, pnfCommProtocol, pnfUsername)) { + LOG.warn("One of the mandatory fields has a null value - pnfId = {} : pnfIPAddress = {} : " + + "pnfCommProtocol = {} : pnfUsername {} : pnfCommPort {} - not invoking mountpoint creation", + pnfId, pnfIPAddress, pnfCommProtocol, pnfUsername, pnfCommPort); + return; + } + + Map payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap(pnfId, pnfIPAddress, + pnfCommPort, pnfCommProtocol, pnfUsername, pnfPasswd, pnfKeyId); + + PNFMountPointClient mountPointClient = new PNFMountPointClient(baseUrl); + LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd); + mountPointClient.setAuthorization(sdnrUser, sdnrPasswd); + String message = mountPointClient.prepareMessageFromPayloadMap(payloadMap); + mountPointClient.sendNotification(message); + + } catch (IOException e) { + LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}", + e.getMessage()); + } + } + + private boolean hasNullInRequiredField(String pnfId, String pnfIPAddress, String pnfCommPort, + String pnfCommProtocol, String pnfUsername) { + + return pnfId == null || pnfIPAddress == null || pnfCommProtocol == null || + pnfCommPort == null || pnfUsername == null; + } + + private String getPNFIPAddress(JsonNode sKafkaMessageRootNode) { + String ipAddress = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/oamV6IpAddress").textValue(); + if (ipAddress != null && ipAddress != "") + return ipAddress; + + ipAddress = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue(); + if (ipAddress != null && ipAddress != "") + return ipAddress; + + return null; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/stnddefined/StrimziKafkaStndDefinedFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/stnddefined/StrimziKafkaStndDefinedFaultVESMsgConsumer.java new file mode 100644 index 000000000..648809722 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/vesdomain/stnddefined/StrimziKafkaStndDefinedFaultVESMsgConsumer.java @@ -0,0 +1,141 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2022 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.stnddefined; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import java.time.Instant; +import java.time.ZoneId; +import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.StrimziKafkaVESMsgConsumerImpl; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault.FaultNotificationClient; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class StrimziKafkaStndDefinedFaultVESMsgConsumer extends StrimziKafkaVESMsgConsumerImpl { + + private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaStndDefinedFaultVESMsgConsumer.class); + Map payloadMapMessage = null; + String faultNodeId; + String notificationType; + + public StrimziKafkaStndDefinedFaultVESMsgConsumer(GeneralConfig generalConfig) { + super(generalConfig); + LOG.info("StrimziKafkaStndDefinedFaultVESMsgConsumer started successfully"); + } + + /* + * Supports processing of notifyNewAlarm and notifyClearedAlarm messages ONLY + */ + @Override + public void processMsg(String msg) throws InvalidMessageException, JsonProcessingException { + LOG.debug("Processing StndDefined Fault message {}", msg); + JsonNode rootNode = convertMessageToJsonNode(msg); + try { + + faultNodeId = rootNode.at("/event/commonEventHeader/sourceName").textValue(); + notificationType = rootNode.at("/event/stndDefinedFields/data/notificationType").textValue(); + + if (notificationType.equalsIgnoreCase("notifyNewAlarm")) { + LOG.info("Read stndDefined Fault message of type - {} with id {} from Kafka topic", notificationType, + faultNodeId); + processNewAlarm(rootNode); + } else if (notificationType.equalsIgnoreCase("notifyClearedAlarm")) { + LOG.info("Read stdnDefined Fault message of type - {} with id {} from Kafka topic", notificationType, + faultNodeId); + processClearedAlarm(rootNode); + } else { + LOG.warn( + "Read stdnDefined Fault message of type - {} with id {} from Kafka topic. No suitable implementation for processing this message", + notificationType, faultNodeId); + throw new InvalidMessageException(); + } + // Send Fault Notification + String baseUrl = getBaseUrl(); + String sdnrUser = getSDNRUser(); + String sdnrPasswd = getSDNRPasswd(); + + FaultNotificationClient faultClient = new FaultNotificationClient(baseUrl); + LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd); + faultClient.setAuthorization(sdnrUser, sdnrPasswd); + String message = faultClient.prepareMessageFromPayloadMap(payloadMapMessage); + faultClient.sendNotification(message); + } catch (NullPointerException e) { + LOG.warn("Message is invalid, sending aborted, processing stopped because one of fields is missing"); + throw new InvalidMessageException("Missing field"); + } + + } + + private void processClearedAlarm(JsonNode rootNode) { + String faultOccurrenceTime = + Instant.ofEpochMilli(rootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000) + .atZone(ZoneId.of("Z")).toString(); + int faultSequence = rootNode.at("/event/commonEventHeader/sequence").intValue(); + String faultObjectId = rootNode.at("/event/stndDefinedFields/data/alarmId").textValue(); + String faultReason = rootNode.at("/event/stndDefinedFields/data/specificProblem").textValue(); + String faultSeverity = + getSDNRSeverityType(rootNode.at("/event/stndDefinedFields/data/perceivedSeverity").textValue()); + + payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId, + Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity); + + } + + private void processNewAlarm(JsonNode rootNode) { + String faultOccurrenceTime = + Instant.ofEpochMilli(rootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000) + .atZone(ZoneId.of("Z")).toString(); + int faultSequence = rootNode.at("/event/commonEventHeader/sequence").intValue(); + String faultObjectId = rootNode.at("/event/stndDefinedFields/data/alarmId").textValue(); + String faultReason = rootNode.at("/event/stndDefinedFields/data/specificProblem").textValue(); + String faultSeverity = + getSDNRSeverityType(rootNode.at("/event/stndDefinedFields/data/perceivedSeverity").textValue()); + + payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId, + Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity); + + } + + /* + * 3GPP Definition PerceivedSeverity: type: string enum: - INDETERMINATE - + * CRITICAL - MAJOR - MINOR - WARNING - CLEARED + * + */ + private String getSDNRSeverityType(String faultSeverity) { + if (faultSeverity.equalsIgnoreCase("critical")) { + faultSeverity = SeverityType.Critical.toString(); + } else if (faultSeverity.equalsIgnoreCase("major")) { + faultSeverity = SeverityType.Major.toString(); + } else if (faultSeverity.equalsIgnoreCase("minor")) { + faultSeverity = SeverityType.Minor.toString(); + } else if (faultSeverity.equalsIgnoreCase("warning") || faultSeverity.equalsIgnoreCase("indeterminate")) { + faultSeverity = SeverityType.Warning.toString(); + } else if (faultSeverity.equalsIgnoreCase("cleared")) { + faultSeverity = SeverityType.NonAlarmed.toString(); + } else { + faultSeverity = SeverityType.NonAlarmed.toString(); + } + return faultSeverity; + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java deleted file mode 100644 index 3413e9766..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/GeneralConfigForTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.GeneralConfig; - -public class GeneralConfigForTest implements AutoCloseable { - - // @formatter:off - private static final String TESTCONFIG_CONTENT = "[general]\n" - + "dmaapEnabled=false\n" - + "baseUrl=http://localhost:8181\n" - + "sdnrUser=admin\n" - + "sdnrPasswd=admin\n" - + ""; - // @formatter:on - - private GeneralConfig cfg ; - private String filename; - - GeneralConfigForTest(String filename) throws IOException { - - Files.asCharSink(new File(filename), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - ConfigurationFileRepresentation globalCfg = new ConfigurationFileRepresentation(filename); - this.filename = filename; - this.cfg = new GeneralConfig(globalCfg); - - } - - public GeneralConfig getCfg() { - return cfg; - } - - - @Override - public - void close() { - File file = new File(filename); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java deleted file mode 100644 index d3f4a13d6..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/PNFRegistrationConfigTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertEquals; -import com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.junit.After; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFRegistrationConfig; - -public class PNFRegistrationConfigTest { - - // @formatter:off - private static final String TESTCONFIG_CONTENT = "[pnfRegistration]\n" - + "TransportType=HTTPNOAUTH\n" - + "Protocol=http\n" - + "username=username\n" - + "password=password\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=5000\n" - + "jersey.config.client.readTimeout=25000\n" - + "jersey.config.client.connectTimeout=25000\n" - + "jersey.config.client.proxy.uri=http://http-proxy\n" - + "jersey.config.client.proxy.username=proxy-user\n" - + "jersey.config.client.proxy.password=proxy-password\n" - + ""; - // @formatter:on - private ConfigurationFileRepresentation cfg; - private static final String configFile = "test.properties"; - - @Test - public void test() { - try { - Files.asCharSink(new File(configFile), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - cfg = new ConfigurationFileRepresentation(configFile); - PNFRegistrationConfig pnfCfg = new PNFRegistrationConfig(cfg); - assertEquals("pnfRegistration", pnfCfg.getSectionName()); - assertEquals("HTTPNOAUTH", pnfCfg.getTransportType()); - assertEquals("onap-dmap:3904", pnfCfg.getHostPort()); - assertEquals("unauthenticated.VES_PNFREG_OUTPUT", pnfCfg.getTopic()); - assertEquals("application/json", pnfCfg.getContenttype()); - assertEquals("myG", pnfCfg.getConsumerGroup()); - assertEquals("C1", pnfCfg.getConsumerId()); - assertEquals("20000", pnfCfg.getTimeout()); - assertEquals("10000", pnfCfg.getLimit()); - assertEquals("5000", pnfCfg.getFetchPause()); - assertEquals("http", pnfCfg.getProtocol()); - assertEquals("username", pnfCfg.getUsername()); - assertEquals("password", pnfCfg.getPassword()); - assertEquals("25000", pnfCfg.getClientReadTimeout()); - assertEquals("25000", pnfCfg.getClientConnectTimeout()); - assertEquals("http://http-proxy", pnfCfg.getHTTPProxyURI()); - assertEquals("proxy-user", pnfCfg.getHTTPProxyUsername()); - assertEquals("proxy-password", pnfCfg.getHTTPProxyPassword()); - - } catch (IOException e) { - e.printStackTrace(); - } - - } - - @After - public void cleanUp() { - File file = new File(configFile); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java deleted file mode 100644 index 5446da048..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMBasicHeaderFieldsNotification.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMBasicHeaderFieldsNotification; - -public class TestCMBasicHeaderFieldsNotification { - - private CMBasicHeaderFieldsNotification cmBasicFields; - - @Test - public void testCMBasicFieldsBuilder() { - cmBasicFields = cmBasicFields.builder() - .withCMNodeId("test-node") - .withCMSequence("1") - .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") - .withSourceId("src_device_id_1732") - .withNotificationType("notifyMOIChanges") - .build(); - - assertEquals("test-node", cmBasicFields.getCmNodeId()); - assertEquals("1", cmBasicFields.getCmSequence()); - assertEquals("src_device_id_1732", cmBasicFields.getSourceId()); - assertEquals("2021-10-18T15:25:19.948Z", cmBasicFields.getCmOccurrenceTime()); - assertEquals("notifyMOIChanges", cmBasicFields.getNotificationType()); - } -} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java deleted file mode 100644 index 3b74df321..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationBuilder.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMBasicHeaderFieldsNotification; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMNotification; - -public class TestCMNotificationBuilder { - - private CMNotification cmNotification; - - @Test - public void testCMNotificationBuilderWithAllDefinedFields() { - cmNotification = cmNotification.builder() - .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() - .withCMNodeId("test-node") - .withCMSequence("1") - .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") - .withSourceId("src_device_id_1732") - .withNotificationType("notifyMOIChanges") - .build()) - .withCMNotificationId("123") - .withCMSourceIndicator("UNKNOWN") - .withCMPath("http://samsung.com/ves=1") - .withCMOperation("CREATE") - .withCMValue("value") - .build(); - - assertEquals("test-node", cmNotification.getBasicHeaderFields().getCmNodeId()); - assertEquals("1", cmNotification.getBasicHeaderFields().getCmSequence()); - assertEquals("src_device_id_1732", cmNotification.getBasicHeaderFields().getSourceId()); - assertEquals("2021-10-18T15:25:19.948Z", cmNotification.getBasicHeaderFields().getCmOccurrenceTime()); - assertEquals("notifyMOIChanges", cmNotification.getBasicHeaderFields().getNotificationType()); - assertEquals("123", cmNotification.getCmNotificationId()); - assertEquals("UNKNOWN", cmNotification.getCmSourceIndicator()); - assertEquals("http://samsung.com/ves=1", cmNotification.getCmPath()); - assertEquals("CREATE", cmNotification.getCmOperation()); - assertEquals("value", cmNotification.getCmValue()); - } - - @Test - public void testCMNotificationBuilderWithDefaultCMOperation() { - cmNotification = cmNotification.builder() - .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() - .withCMNodeId("test-node") - .withCMSequence("1") - .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") - .withSourceId("src_device_id_1732") - .withNotificationType("notifyMOIChanges") - .build()) - .withCMNotificationId("123") - .withCMSourceIndicator("UNKNOWN") - .withCMPath("http://samsung.com/ves=1") - .build(); - - assertEquals("test-node", cmNotification.getBasicHeaderFields().getCmNodeId()); - assertEquals("NULL", cmNotification.getCmOperation()); - assertNull(cmNotification.getCmValue()); - } -} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java deleted file mode 100644 index 12ccd4c62..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestCMNotificationClient.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt mountpoint-registrar - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertTrue; - -import java.util.Map; -import javax.annotation.Nonnull; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMBasicHeaderFieldsNotification; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMNotification; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.CMNotificationClient; - -public class TestCMNotificationClient extends CMNotificationClient { - public static String baseUrl = "http://localhost:8181"; - CMNotificationClient testClient; - - public TestCMNotificationClient() { - super(baseUrl); - } - - @Test - public void testCMNotificationClient() { - testClient = new TestCMNotificationClient(); - testClient.setAuthorization("admin", "admin"); - - String msg = testClient.prepareMessageFromPayloadMap( - CMNotificationClient.createCMNotificationPayloadMap( - CMNotification.builder() - .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() - .withCMNodeId("test-node") - .withCMSequence("1") - .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") - .withSourceId("src_device_id_1732") - .withNotificationType("notifyMOIChanges") - .build()) - .withCMNotificationId("123") - .withCMSourceIndicator("UNKNOWN") - .withCMPath("http://samsung.com/ves=1") - .withCMOperation("CREATE") - .withCMValue("value") - .build() - )); - assertTrue(testClient.sendNotification(msg)); - } - - @Override - @Nonnull - public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) { - System.out.println("In overridden sendRequest in TestCMNotificationClient"); - return new BaseHTTPResponse(200, body); - } -} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java deleted file mode 100644 index 2c4fb647b..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPCMVESMsgConsumer.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import com.fasterxml.jackson.core.JsonProcessingException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPCMVESMsgConsumer; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Paths; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import static org.junit.Assert.fail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import java.util.Iterator; -import java.util.Map; - -public class TestDMaaPCMVESMsgConsumer { - - private static final String CONFIGURATION_FILE = "cm_test.properties"; - private DMaaPCMVESMsgConsumer dMaaPCMVESMsgConsumer; - private GeneralConfigForTest generalConfigForTest; - - @Before - public void setUp() throws Exception { - generalConfigForTest = new GeneralConfigForTest(CONFIGURATION_FILE); - dMaaPCMVESMsgConsumer = new DMaaPCMVESMsgConsumer(generalConfigForTest.getCfg()); - } - - @Test - public void processValidMsg() throws URISyntaxException, IOException { - File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); - String cmEvent = readFileToString(cmFileValid); - try { - dMaaPCMVESMsgConsumer.processMsg(cmEvent); - } catch (Exception e) { - fail("Test fail with message: " + e.getMessage()); - } - } - - @Test(expected = InvalidMessageException.class) - public void processMsgThatMissesField() throws URISyntaxException, IOException, InvalidMessageException { - File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_invalid.json").toURI()); - String cmEvent = readFileToString(cmFileInvalid); - dMaaPCMVESMsgConsumer.processMsg(cmEvent); - } - - @Test(expected = InvalidMessageException.class) - public void processMsgThatHasInvalidNotificationType() - throws URISyntaxException, IOException, InvalidMessageException { - File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_invalid_type.json").toURI()); - String cmEvent = readFileToString(cmFileInvalid); - dMaaPCMVESMsgConsumer.processMsg(cmEvent); - } - - @Test(expected = JsonProcessingException.class) - public void processMsgThatIsNotValidJson() throws URISyntaxException, IOException, InvalidMessageException { - File cmFileInvalid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/not_a_json.json").toURI()); - String cmEvent = readFileToString(cmFileInvalid); - dMaaPCMVESMsgConsumer.processMsg(cmEvent); - } - - @Test - public void processMsgWithOneElementMoiChangesArray() throws URISyntaxException, IOException { - File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); - String cmEvent = readFileToString(cmFileValid); - try { - JsonNode rootNode = convertMessageToJsonNode(cmEvent); - Iterator nodes = rootNode - .at("/event/stndDefinedFields/data/moiChanges") - .elements(); - Map payloadMap = - dMaaPCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); - - assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); - assertEquals("0", payloadMap.get("@counter@")); - assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); - assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); - assertEquals("notifyMOIChanges", payloadMap.get("@notification-type@")); - assertEquals("123", payloadMap.get("@notification-id@")); - assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); - assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=1", payloadMap.get("@path@")); - assertEquals("REPLACE", payloadMap.get("@operation@")); - assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); - - } catch (Exception e) { - fail("Test fail with message: " + e.getMessage()); - } - } - - @Test - public void processMsgWithTwoElementMoiChangesArray() throws URISyntaxException, IOException { - File cmFileValid = - new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_valid_two_element_moi_changes_array.json") - .toURI()); - String cmEvent = readFileToString(cmFileValid); - try { - JsonNode rootNode = convertMessageToJsonNode(cmEvent); - Iterator nodes = rootNode - .at("/event/stndDefinedFields/data/moiChanges") - .elements(); - Map payloadMap = - dMaaPCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); - - assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); - assertEquals("0", payloadMap.get("@counter@")); - assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); - assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); - assertEquals("notifyMOIChanges", payloadMap.get("@notification-type@")); - assertEquals("123", payloadMap.get("@notification-id@")); - assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); - assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=1", payloadMap.get("@path@")); - assertEquals("REPLACE", payloadMap.get("@operation@")); - assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); - - Map payloadMap2 = null; - while (nodes.hasNext()) { - payloadMap2 = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); - } - assertEquals("samsung-O-DU-1122", payloadMap2.get("@node-id@")); - assertEquals("124", payloadMap2.get("@notification-id@")); - assertEquals("RESOURCE_OPERATION", payloadMap2.get("@source-indicator@")); - assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=2", payloadMap2.get("@path@")); - assertEquals("CREATE", payloadMap2.get("@operation@")); - assertEquals("{pnf-registration:false,faults-enabled:false}", payloadMap2.get("@value@")); - - } catch (Exception e) { - fail("Test fail with message: " + e.getMessage()); - } - } - - @Test - public void processMsgNotifyMoiCreationType() throws URISyntaxException, IOException { - File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_moi_creation.json").toURI()); - String cmEvent = readFileToString(cmFileValid); - try { - JsonNode rootNode = convertMessageToJsonNode(cmEvent); - Map payloadMap = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList"); - assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); - assertEquals("0", payloadMap.get("@counter@")); - assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); - assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); - assertEquals("notifyMOICreation", payloadMap.get("@notification-type@")); - assertNull(payloadMap.get("@notification-id@")); - assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); - assertNull(payloadMap.get("@path@")); - assertEquals("NULL", payloadMap.get("@operation@")); - assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); - - } catch (Exception e) { - fail("Test fail with message: " + e.getMessage()); - } - } - - @Test - public void processMsgNotifyMoiDeletionType() throws URISyntaxException, IOException { - File cmFileValid = new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_moi_deletion.json").toURI()); - String cmEvent = readFileToString(cmFileValid); - try { - JsonNode rootNode = convertMessageToJsonNode(cmEvent); - Map payloadMap = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList"); - assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); - assertEquals("0", payloadMap.get("@counter@")); - assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); - assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); - assertEquals("notifyMOIDeletion", payloadMap.get("@notification-type@")); - assertNull(payloadMap.get("@notification-id@")); - assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); - assertNull(payloadMap.get("@path@")); - assertEquals("NULL", payloadMap.get("@operation@")); - assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); - - } catch (Exception e) { - fail("Test fail with message: " + e.getMessage()); - } - } - - @Test - public void processMsgNotifyMoiAttributeValueChangesType() throws URISyntaxException, IOException { - File cmFileValid = - new File(TestDMaaPCMVESMsgConsumer.class.getResource("/msgs/cm_moi_attribute_value_changes.json").toURI()); - String cmEvent = readFileToString(cmFileValid); - try { - JsonNode rootNode = convertMessageToJsonNode(cmEvent); - Map payloadMap = dMaaPCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeListValueChanges"); - assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); - assertEquals("0", payloadMap.get("@counter@")); - assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); - assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); - assertEquals("notifyMOIAttributeValueChanges", payloadMap.get("@notification-type@")); - assertNull(payloadMap.get("@notification-id@")); - assertEquals("UNKNOWN", payloadMap.get("@source-indicator@")); - assertNull(payloadMap.get("@path@")); - assertEquals("NULL", payloadMap.get("@operation@")); - assertEquals("[{attributeNameValuePairSet:{faults-enabled:true}}]", payloadMap.get("@value@")); - - } catch (Exception e) { - fail("Test fail with message: " + e.getMessage()); - } - } - - private String readFileToString(File file) throws IOException { - StringBuilder fileContent = new StringBuilder(); - Files.lines(Paths.get(file.toURI())).forEach(fileContent::append); - return fileContent.toString(); - } - - private JsonNode convertMessageToJsonNode(String message) throws JsonProcessingException { - return new ObjectMapper().readTree(message); - } - - @After - public void after() { - generalConfigForTest.close(); - } -} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java deleted file mode 100644 index cf25e1e7b..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPFaultVESMsgConsumer.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer; - -public class TestDMaaPFaultVESMsgConsumer { - - private static final String DEFAULT_SDNRUSER = "admin"; - private static final String DEFAULT_SDNRPASSWD = "admin"; - private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; - private static final String CONFIGURATIONFILE = "test2.properties"; - - // @formatter:off - private static final String faultVESMsg = "" - + "{\"event\":" + " {\"commonEventHeader\":" - + " { \"domain\":\"fault\"," - + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," - + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," - + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," - + " \"sequence\":1," - + " \"priority\":\"Low\"," - + " \"reportingEntityId\":\"\"," - + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," - + " \"sourceId\":\"\"," - + " \"sourceName\":\"1e9a28bcd119_50007\"," - + " \"startEpochMicrosec\":1614004128699785," - + " \"lastEpochMicrosec\":1614004128699785," - + " \"nfNamingCode\":\"sdn controller\"," - + " \"nfVendorName\":\"sdn\"," - + " \"timeZoneOffset\":\"+00:00\"," - + " \"version\":\"4.0.1\"," - + " \"vesEventListenerVersion\":\"7.0.1\"" - + " }," - + " \"faultFields\":" - + " {" - + " \"faultFieldsVersion\":\"4.0\"," - + " \"alarmCondition\":\"8\"," - + " \"alarmInterfaceA\":\"dkom32\"," - + " \"eventSourceType\":\"O_RAN_COMPONENT\"," - + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," - + " \"eventSeverity\":\"@eventSeverity@\"," - + " \"vfStatus\":\"Active\"," - + " \"alarmAdditionalInformation\":" - + " {" - + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," - + " \"equipType\":\"O-RAN-sim\"," - + " \"vendor\":\"Melacon\"," - + " \"model\":\"Simulated Device\"" - + " }" - + " }" - + " }" - + "}"; - // @formatter:on - // @formatter:off - private static final String faultVESMsg_Incomplete = "" - + "{\"event\":" - + " {\"commonEventHeader\":" - + " { \"domain\":\"fault\"," - + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," - + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," - + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," - + " \"sequence\":1," - + " \"priority\":\"Low\"," - + " \"reportingEntityId\":\"\"," - + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," - + " \"sourceId\":\"\"," - + " \"sourceName\":\"1e9a28bcd119_50007\"," - + " \"startEpochMicrosec\":1612349525626," - + " \"lastEpochMicrosec\":1612349525626," - + " \"nfNamingCode\":\"sdn controller\"," - + " \"nfVendorName\":\"sdn\"," - + " \"timeZoneOffset\":\"+00:00\"," - + " \"version\":\"4.0.1\"," - + " \"vesEventListenerVersion\":\"7.0.1\"," - + " }," - + " \"faultFields\":" - + " {" - + " \"faultFieldsVersion\":\"4.0\"," - + " \"alarmCondition\":\"8\"," - + " \"alarmInterfaceA\":\"dkom32\"," - + " \"eventSourceType\":\"O_RAN_COMPONENT\"," - + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," - + " \"eventSeverity\":\"CRITICAL\"," - + " \"vfStatus\":\"Active\"," - + " \"alarmAdditionalInformation\":" - + " {" - + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," - + " \"equipType\":\"O-RAN-sim\"," - + " \"vendor\":\"Melacon\"," - + " \"model\":\"Simulated Device\"" - + " }" - + " }" - + " }" - + "}"; - // @formatter:on - - private GeneralConfigForTest cfgTest; - - @Before - public void before() throws IOException { - cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); - } - @After - public void after() { - cfgTest.close(); - } - - - @Test - public void test() throws IOException { - DMaaPFaultVESMsgConsumer faultMsgConsumer = new DMaaPFaultVESMsgConsumer(cfgTest.getCfg()); - try { - - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "CRITICAL")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Major")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "minor")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "NonAlarmed")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "warning")); - faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Unknown")); - faultMsgConsumer.processMsg(faultVESMsg_Incomplete); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Exception while processing Fault Message - " + e.getMessage()); - } - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java deleted file mode 100644 index 2c07caa1c..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPPNFRegVESMsgConsumer.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer; - -public class TestDMaaPPNFRegVESMsgConsumer { - - private static final String DEFAULT_SDNRUSER = "admin"; - private static final String DEFAULT_SDNRPASSWD = "admin"; - private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; - private static final String CONFIGURATIONFILE = "test4.properties"; - - // @formatter:off - private static final String pnfRegMsg_TLS = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"additionalFields\": \n" - + " { \n" - + " \"protocol\":\"TLS\",\n" - + " \"keyId\":\"netconf\",\n" - + " \"oamPort\":\"50000\",\n" - + " \"betweenAttemptsTimeout\":\"2000\",\n" - + " \"keepaliveDelay\":\"120\",\n" - + " \"sleep-factor\":\"1.5\",\n" - + " \"reconnectOnChangedSchema\":\"false\",\n" - + " \"connectionTimeout\":\"20000\",\n" - + " \"maxConnectionAttempts\":\"100\",\n" - + " \"username\":\"netconf\",\n" - + " \"tcpOnly\":\"false\"\n" - + " },\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - private static final String pnfRegMsg_SSH = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"additionalFields\": \n" - + " { \n" - + " \"protocol\":\"SSH\",\n" - + " \"password\":\"netconf\",\n" - + " \"oamPort\":\"50000\",\n" - + " \"betweenAttemptsTimeout\":\"2000\",\n" - + " \"keepaliveDelay\":\"120\",\n" - + " \"sleep-factor\":\"1.5\",\n" - + " \"reconnectOnChangedSchema\":\"false\",\n" - + " \"connectionTimeout\":\"20000\",\n" - + " \"maxConnectionAttempts\":\"100\",\n" - + " \"username\":\"netconf\",\n" - + " \"tcpOnly\":\"false\"\n" - + " },\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - private static final String pnfRegMsg_OTHER = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"additionalFields\": \n" - + " { \n" - + " \"protocol\":\"OTHER\",\n" - + " \"password\":\"netconf\",\n" - + " \"oamPort\":\"50000\",\n" - + " \"betweenAttemptsTimeout\":\"2000\",\n" - + " \"keepaliveDelay\":\"120\",\n" - + " \"sleep-factor\":\"1.5\",\n" - + " \"reconnectOnChangedSchema\":\"false\",\n" - + " \"connectionTimeout\":\"20000\",\n" - + " \"maxConnectionAttempts\":\"100\",\n" - + " \"username\":\"netconf\",\n" - + " \"tcpOnly\":\"false\"\n" - + " },\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - private static final String pnfRegMsg = "{\n" - + " \"event\": {\n" - + " \"commonEventHeader\": {\n" - + " \"domain\": \"pnfRegistration\",\n" - + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" - + " \"eventName\": \"pnfRegistration_EventType5G\",\n" - + " \"eventType\": \"EventType5G\",\n" - + " \"sequence\": 0,\n" - + " \"priority\": \"Low\",\n" - + " \"reportingEntityId\": \"\",\n" - + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" - + " \"sourceId\": \"\",\n" - + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" - + " \"startEpochMicrosec\": 1571300004203,\n" - + " \"lastEpochMicrosec\": 1571300004203,\n" - + " \"nfNamingCode\": \"1234\",\n" - + " \"nfVendorName\": \"VENDORA\",\n" - + " \"timeZoneOffset\": \"+00:00\",\n" - + " \"version\": \"4.0.1\",\n" - + " \"vesEventListenerVersion\":\"7.0.1\"\n" - + " },\n" - + " \"pnfRegistrationFields\": {\n" - + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" - + " \"lastServiceDate\":\"2019-08-16\",\n" - + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" - + " \"manufactureDate\":\"2019-08-16\",\n" - + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" - + " \"oamV4IpAddress\": \"10.10.10.11\",\n" - + " \"oamPort\":\"17380\",\n" - //+ " \"oamV6IpAddress\": \"\",\n" - + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" - + " \"softwareVersion\": \"2.3.5\",\n" - + " \"unitFamily\": \"VENDORA-1234\",\n" - + " \"unitType\": \"1234\",\n" - + " \"vendorName\": \"VENDORA\"\n" - + " }\n" - + " }\n" - + "}\n" - + ""; - // @formatter:on - - private GeneralConfigForTest cfgTest; - - @Before - public void before() throws IOException { - cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); - } - - @After - public void after() { - cfgTest.close(); - } - - @Test - public void processMsgTest() { - - DMaaPPNFRegVESMsgConsumer pnfRegMsgConsumer = new DMaaPPNFRegVESMsgConsumer(cfgTest.getCfg()); - try { - pnfRegMsgConsumer.processMsg(pnfRegMsg); - pnfRegMsgConsumer.processMsg(pnfRegMsg_SSH); - pnfRegMsgConsumer.processMsg(pnfRegMsg_TLS); - pnfRegMsgConsumer.processMsg(pnfRegMsg_OTHER); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("Exception while processing PNF Registration Message - " + e.getMessage()); - } - } - - @Test - public void Test1() { - DMaaPPNFRegVESMsgConsumer pnfConsumer = new DMaaPPNFRegVESMsgConsumer(cfgTest.getCfg()); - System.out.println(pnfConsumer.getBaseUrl()); - System.out.println(pnfConsumer.getSDNRUser()); - System.out.println(pnfConsumer.getSDNRPasswd()); - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java deleted file mode 100644 index ecfb8d081..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestDMaaPVESMsgConsumerMain.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertNotNull; -import com.google.common.io.Files; -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.After; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.*; - -public class TestDMaaPVESMsgConsumerMain { - - private static final String CONFIGURATIONFILE = "test1.properties"; - private static final String TESTCONFIG_GENERAL = "[general]\n" - + "dmaapEnabled=false\n" - + "baseUrl=http://localhost:8181\n" - + "sdnrUser=admin\n" - + "sdnrPasswd=admin\n" - + "\n" - + "[pnfRegistration]\n" - + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DMaaPPNFRegVESMsgConsumer\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "\n" - + "[fault]\n" - + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=10000\n" - + "\n" - + ""; - - private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n" - + "dmaapEnabled=false\n" - + "baseUrl=http://localhost:8181\n" - + "sdnrUser=admin\n" - + "sdnrPasswd=admin\n" - + "\n" - + "[pnfRegistration]\n" - + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer.java\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "\n" - + "[fault]\n" - + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" - + "TransportType=HTTPNOAUTH\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=HELLO\n" - + "limit=10000\n" - + "fetchPause=WORLD\n" - + "\n" - + ""; - public GeneralConfig generalConfig; - Map configMap = new HashMap<>(); - DMaaPVESMsgConsumerMain dmaapMain; - - - public void preTest1() { - try { - Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL); - ConfigurationFileRepresentation configFileRepresentation = - new ConfigurationFileRepresentation(CONFIGURATIONFILE); - - generalConfig = new GeneralConfig(configFileRepresentation); - PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); - FaultConfig faultConfig = new FaultConfig(configFileRepresentation); - ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); - - configMap.put("pnfRegistration", pnfRegConfig); - configMap.put("fault", faultConfig); - configMap.put("provisioning", provisioningConfig); - } catch (Exception e) { - System.out.println("Failed in preTest execution " + e.getMessage()); - } - } - - public void preTest2() { - try { - Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID); - ConfigurationFileRepresentation configFileRepresentation = - new ConfigurationFileRepresentation(CONFIGURATIONFILE); - - generalConfig = new GeneralConfig(configFileRepresentation); - PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); - FaultConfig faultConfig = new FaultConfig(configFileRepresentation); - ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); - - configMap.put("pnfRegistration", pnfRegConfig); - configMap.put("fault", faultConfig); - configMap.put("provisioning", provisioningConfig); - } catch (Exception e) { - System.out.println("Failed in preTest execution " + e.getMessage()); - } - } - - @Test - public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() { - preTest1(); - assertNotNull(configMap); - dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); - } - - @Test - public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() { - preTest2(); - assertNotNull(configMap); - dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); - } - - @After - public void postTest() { - File file = new File(CONFIGURATIONFILE); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - List consumers = dmaapMain.getConsumers(); - for (DMaaPVESMsgConsumer consumer : consumers) { - // stop all consumers - consumer.stopConsumer(); - } - } -} - - diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java deleted file mode 100644 index 422d24935..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultConfig.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertEquals; -import com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.junit.After; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultConfig; - -public class TestFaultConfig { - - // @formatter:off - private static final String TESTCONFIG_CONTENT = "[fault]\n" - + "TransportType=HTTPNOAUTH\n" - + "Protocol=http\n" - + "username=username\n" - + "password=password\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=5000\n" - + "jersey.config.client.readTimeout=25000\n" - + "jersey.config.client.connectTimeout=25000\n" - + "jersey.config.client.proxy.uri=http://http-proxy\n" - + "jersey.config.client.proxy.username=proxy-user\n" - + "jersey.config.client.proxy.password=proxy-password\n" - + "\n" - + ""; - // @formatter:on - - private ConfigurationFileRepresentation cfg; - private static final String CONFIGURATIONFILE = "test2.properties"; - @Test - public void test() { - try { - Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - cfg = new ConfigurationFileRepresentation(CONFIGURATIONFILE); - FaultConfig faultCfg = new FaultConfig(cfg); - assertEquals("fault", faultCfg.getSectionName()); - assertEquals("HTTPNOAUTH", faultCfg.getTransportType()); - assertEquals("onap-dmap:3904", faultCfg.getHostPort()); - assertEquals("unauthenticated.SEC_FAULT_OUTPUT", faultCfg.getTopic()); - assertEquals("application/json", faultCfg.getContenttype()); - assertEquals("myG", faultCfg.getConsumerGroup()); - assertEquals("C1", faultCfg.getConsumerId()); - assertEquals("20000", faultCfg.getTimeout()); - assertEquals("10000", faultCfg.getLimit()); - assertEquals("5000", faultCfg.getFetchPause()); - assertEquals("http", faultCfg.getProtocol()); - assertEquals("username", faultCfg.getUsername()); - assertEquals("password", faultCfg.getPassword()); - assertEquals("25000", faultCfg.getClientReadTimeout()); - assertEquals("25000", faultCfg.getClientConnectTimeout()); - assertEquals("http://http-proxy", faultCfg.getHTTPProxyURI()); - assertEquals("proxy-user", faultCfg.getHTTPProxyUsername()); - assertEquals("proxy-password", faultCfg.getHTTPProxyPassword()); - - } catch (IOException e) { - e.printStackTrace(); - } - } - - @After - public void cleanUp() { - File file = new File(CONFIGURATIONFILE); - if (file.exists()) { - System.out.println("File exists, Deleting it"); - file.delete(); - } - - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java deleted file mode 100644 index fa289aa4b..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestFaultNotificationClient.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.util.Map; -import javax.annotation.Nonnull; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.FaultNotificationClient; - -public class TestFaultNotificationClient extends FaultNotificationClient { - - public static String baseUrl = "http://localhost:8181"; - FaultNotificationClient testClient; - - - public TestFaultNotificationClient() { - super(baseUrl); - - } - - @Test - public void testFaultNotificationClient() { - testClient = new TestFaultNotificationClient(); - testClient.setAuthorization("admin", "admin"); - Map payloadMap = FaultNotificationClient.createFaultNotificationPayloadMap( - "TEST_50001", "1", "2019-11-20T09:25:19.948Z", - "SEDNKSAHQ01M01nSky01", "lossOfSignal", "Critical"); - String msg = testClient.prepareMessageFromPayloadMap(payloadMap); - assertTrue(testClient.sendNotification(msg)); - assertTrue(testClient.sendNotification(msg)); - } - - @Override - @Nonnull - public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) - throws IOException { - System.out.println("In overridden sendRequest in TestFaultNotificationClient"); - return new BaseHTTPResponse(200, body); - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java deleted file mode 100644 index f73f3a5bf..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestGeneralConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertEquals; -import java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.GeneralConfig; - -public class TestGeneralConfig { - - private static final String CONFIGURATIONFILE = "test1.properties"; - - private GeneralConfigForTest config; - - @Before - public void before() throws IOException { - config = new GeneralConfigForTest(CONFIGURATIONFILE); - } - - @Test - public void test() throws IOException { - GeneralConfig cfg = config.getCfg(); - - assertEquals(false, cfg.getEnabled()); - assertEquals("http://localhost:8181", cfg.getBaseUrl()); - assertEquals("admin", cfg.getSDNRUser()); - assertEquals("admin", cfg.getSDNRPasswd()); - assertEquals("general", cfg.getSectionName()); - } - - @After - public void cleanUp() { - config.close(); - } -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java deleted file mode 100644 index 0858a7faa..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestPNFMountPointClient.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertTrue; -import java.io.IOException; -import java.util.Map; -import javax.annotation.Nonnull; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.PNFMountPointClient; - -public class TestPNFMountPointClient extends PNFMountPointClient { - - public static String baseUrl = "http://localhost:8181"; - PNFMountPointClient testClient; - - - public TestPNFMountPointClient() { - super(baseUrl); - - } - - @Test - public void testPNFMountPointClient() { - testClient = new TestPNFMountPointClient(); - testClient.setAuthorization("admin", "admin"); - Map payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap( - "TEST 50001", "127.0.0.1", "17830", "TLS", - "admin", "admin", "key_id"); - String msg = testClient.prepareMessageFromPayloadMap(payloadMap); - - assertTrue(testClient.sendNotification(msg)); - assertTrue(testClient.sendNotification(msg)); - - } - - @Override - @Nonnull - public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) - throws IOException { - System.out.println("In overridden sendRequest in TestPNFMountPointClient, uri = "+uri); - return new BaseHTTPResponse(200, body); - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java deleted file mode 100644 index 42c204aec..000000000 --- a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/TestProvisioningConfig.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt - * ================================================================================================= - * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. - * ================================================================================================= - * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test; - -import static org.junit.Assert.assertEquals; -import com.google.common.io.Files; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; -import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.ProvisioningConfig; - -public class TestProvisioningConfig { - - private static final String TESTCONFIG_CONTENT = "[provisioning]\n" - + "TransportType=HTTPNOAUTH\n" - + "Protocol=http\n" - + "username=username\n" - + "password=password\n" - + "host=onap-dmap:3904\n" - + "topic=unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT\n" - + "contenttype=application/json\n" - + "group=myG\n" - + "id=C1\n" - + "timeout=20000\n" - + "limit=10000\n" - + "fetchPause=5000\n" - + "jersey.config.client.readTimeout=25000\n" - + "jersey.config.client.connectTimeout=25000\n" - + "jersey.config.client.proxy.uri=http://http-proxy\n" - + "jersey.config.client.proxy.username=proxy-user\n" - + "jersey.config.client.proxy.password=proxy-password\n" - + ""; - - private static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); - private static File configFile; - - @Test - public void testConfigValuesAssignment() throws IOException { - configFile = new File(TEMP_DIR, "test.properties"); - Files.asCharSink(configFile, StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); - ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(configFile); - ProvisioningConfig provisioningConfig = new ProvisioningConfig(cfg); - assertEquals("provisioning", provisioningConfig.getSectionName()); - assertEquals("HTTPNOAUTH", provisioningConfig.getTransportType()); - assertEquals("onap-dmap:3904", provisioningConfig.getHostPort()); - assertEquals("unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT", provisioningConfig.getTopic()); - assertEquals("application/json", provisioningConfig.getContenttype()); - assertEquals("myG", provisioningConfig.getConsumerGroup()); - assertEquals("C1", provisioningConfig.getConsumerId()); - assertEquals("20000", provisioningConfig.getTimeout()); - assertEquals("10000", provisioningConfig.getLimit()); - assertEquals("5000", provisioningConfig.getFetchPause()); - assertEquals("http", provisioningConfig.getProtocol()); - assertEquals("username", provisioningConfig.getUsername()); - assertEquals("password", provisioningConfig.getPassword()); - assertEquals("25000", provisioningConfig.getClientReadTimeout()); - assertEquals("25000", provisioningConfig.getClientConnectTimeout()); - assertEquals("http://http-proxy", provisioningConfig.getHTTPProxyURI()); - assertEquals("proxy-user", provisioningConfig.getHTTPProxyUsername()); - assertEquals("proxy-password", provisioningConfig.getHTTPProxyPassword()); - } - - @After - public void cleanUp() { - if (configFile.exists()) { - System.out.println(String.format("File %s exists, deleting it", configFile.getName())); - configFile.delete(); - } - } - -} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMBasicHeaderFieldsNotification.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMBasicHeaderFieldsNotification.java new file mode 100644 index 000000000..5ad73e25c --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMBasicHeaderFieldsNotification.java @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.client; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMBasicHeaderFieldsNotification; + +public class TestCMBasicHeaderFieldsNotification { + + private CMBasicHeaderFieldsNotification cmBasicFields; + + @Test + public void testCMBasicFieldsBuilder() { + cmBasicFields = cmBasicFields.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build(); + + assertEquals("test-node", cmBasicFields.getCmNodeId()); + assertEquals("1", cmBasicFields.getCmSequence()); + assertEquals("src_device_id_1732", cmBasicFields.getSourceId()); + assertEquals("2021-10-18T15:25:19.948Z", cmBasicFields.getCmOccurrenceTime()); + assertEquals("notifyMOIChanges", cmBasicFields.getNotificationType()); + } +} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationBuilder.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationBuilder.java new file mode 100644 index 000000000..9badc02cb --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationBuilder.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.client; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMBasicHeaderFieldsNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMNotification; + +public class TestCMNotificationBuilder { + + private CMNotification cmNotification; + + @Test + public void testCMNotificationBuilderWithAllDefinedFields() { + cmNotification = cmNotification.builder() + .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build()) + .withCMNotificationId("123") + .withCMSourceIndicator("UNKNOWN") + .withCMPath("http://samsung.com/ves=1") + .withCMOperation("CREATE") + .withCMValue("value") + .build(); + + assertEquals("test-node", cmNotification.getBasicHeaderFields().getCmNodeId()); + assertEquals("1", cmNotification.getBasicHeaderFields().getCmSequence()); + assertEquals("src_device_id_1732", cmNotification.getBasicHeaderFields().getSourceId()); + assertEquals("2021-10-18T15:25:19.948Z", cmNotification.getBasicHeaderFields().getCmOccurrenceTime()); + assertEquals("notifyMOIChanges", cmNotification.getBasicHeaderFields().getNotificationType()); + assertEquals("123", cmNotification.getCmNotificationId()); + assertEquals("UNKNOWN", cmNotification.getCmSourceIndicator()); + assertEquals("http://samsung.com/ves=1", cmNotification.getCmPath()); + assertEquals("CREATE", cmNotification.getCmOperation()); + assertEquals("value", cmNotification.getCmValue()); + } + + @Test + public void testCMNotificationBuilderWithDefaultCMOperation() { + cmNotification = cmNotification.builder() + .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build()) + .withCMNotificationId("123") + .withCMSourceIndicator("UNKNOWN") + .withCMPath("http://samsung.com/ves=1") + .build(); + + assertEquals("test-node", cmNotification.getBasicHeaderFields().getCmNodeId()); + assertEquals("NULL", cmNotification.getCmOperation()); + assertNull(cmNotification.getCmValue()); + } +} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationClient.java new file mode 100644 index 000000000..8cea25f1f --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestCMNotificationClient.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt mountpoint-registrar + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.client; + +import static org.junit.Assert.assertTrue; + +import java.util.Map; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMBasicHeaderFieldsNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMNotification; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.CMNotificationClient; + +public class TestCMNotificationClient extends CMNotificationClient { + public static String baseUrl = "http://localhost:8181"; + CMNotificationClient testClient; + + public TestCMNotificationClient() { + super(baseUrl); + } + + @Test + public void testCMNotificationClient() { + testClient = new TestCMNotificationClient(); + testClient.setAuthorization("admin", "admin"); + + String msg = testClient.prepareMessageFromPayloadMap( + CMNotificationClient.createCMNotificationPayloadMap( + CMNotification.builder() + .withCMBasicHeaderFieldsNotification(CMBasicHeaderFieldsNotification.builder() + .withCMNodeId("test-node") + .withCMSequence("1") + .withCMOccurrenceTime("2021-10-18T15:25:19.948Z") + .withSourceId("src_device_id_1732") + .withNotificationType("notifyMOIChanges") + .build()) + .withCMNotificationId("123") + .withCMSourceIndicator("UNKNOWN") + .withCMPath("http://samsung.com/ves=1") + .withCMOperation("CREATE") + .withCMValue("value") + .build() + )); + assertTrue(testClient.sendNotification(msg)); + } + + @Override + @Nonnull + public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) { + System.out.println("In overridden sendRequest in TestCMNotificationClient"); + return new BaseHTTPResponse(200, body); + } +} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestFaultNotificationClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestFaultNotificationClient.java new file mode 100644 index 000000000..a33970269 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestFaultNotificationClient.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.client; + +import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.util.Map; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault.FaultNotificationClient; + +public class TestFaultNotificationClient extends FaultNotificationClient { + + public static String baseUrl = "http://localhost:8181"; + FaultNotificationClient testClient; + + + public TestFaultNotificationClient() { + super(baseUrl); + + } + + @Test + public void testFaultNotificationClient() { + testClient = new TestFaultNotificationClient(); + testClient.setAuthorization("admin", "admin"); + Map payloadMap = FaultNotificationClient.createFaultNotificationPayloadMap( + "TEST_50001", "1", "2019-11-20T09:25:19.948Z", + "SEDNKSAHQ01M01nSky01", "lossOfSignal", "Critical"); + String msg = testClient.prepareMessageFromPayloadMap(payloadMap); + assertTrue(testClient.sendNotification(msg)); + assertTrue(testClient.sendNotification(msg)); + } + + @Override + @Nonnull + public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) + throws IOException { + System.out.println("In overridden sendRequest in TestFaultNotificationClient"); + return new BaseHTTPResponse(200, body); + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java new file mode 100644 index 000000000..c43800044 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/client/TestPNFMountPointClient.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.client; + +import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.util.Map; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg.PNFMountPointClient; + +public class TestPNFMountPointClient extends PNFMountPointClient { + + public static String baseUrl = "http://localhost:8181"; + PNFMountPointClient testClient; + + + public TestPNFMountPointClient() { + super(baseUrl); + + } + + @Test + public void testPNFMountPointClient() { + testClient = new TestPNFMountPointClient(); + testClient.setAuthorization("admin", "admin"); + Map payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap( + "TEST 50001", "127.0.0.1", "17830", "TLS", + "admin", "admin", "key_id"); + String msg = testClient.prepareMessageFromPayloadMap(payloadMap); + + assertTrue(testClient.sendNotification(msg)); + assertTrue(testClient.sendNotification(msg)); + + } + + @Override + @Nonnull + public BaseHTTPResponse sendRequest(String uri, String method, String body, Map headers) + throws IOException { + System.out.println("In overridden sendRequest in TestPNFMountPointClient, uri = "+uri); + return new BaseHTTPResponse(200, body); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java new file mode 100644 index 000000000..23c009a5b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/GeneralConfigForTest.java @@ -0,0 +1,65 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.config; + +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; + +public class GeneralConfigForTest implements AutoCloseable { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[general]\n" + + "baseUrl=http://localhost:8181\n" + + "sdnrUser=admin\n" + + "sdnrPasswd=admin\n" + + ""; + // @formatter:on + + private GeneralConfig cfg ; + private String filename; + + public GeneralConfigForTest(String filename) throws IOException { + + Files.asCharSink(new File(filename), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + ConfigurationFileRepresentation globalCfg = new ConfigurationFileRepresentation(filename); + this.filename = filename; + this.cfg = new GeneralConfig(globalCfg); + + } + + public GeneralConfig getCfg() { + return cfg; + } + + + @Override + public + void close() { + File file = new File(filename); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java new file mode 100644 index 000000000..b76e71372 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/PNFRegistrationConfigTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.config; + +import static org.junit.Assert.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.PNFRegistrationConfig; + +public class PNFRegistrationConfigTest { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[pnfRegistration]\n" + + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" + + "consumerGroup=myG\n" + + "consumerID=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=5000\n" + + ""; + // @formatter:on + private ConfigurationFileRepresentation cfg; + private static final String configFile = "test.properties"; + + @Test + public void test() { + try { + Files.asCharSink(new File(configFile), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation(configFile); + PNFRegistrationConfig pnfCfg = new PNFRegistrationConfig(cfg); + assertEquals("pnfRegistration", pnfCfg.getSectionName()); + assertEquals("unauthenticated.VES_PNFREG_OUTPUT", pnfCfg.getTopic()); + assertEquals("myG", pnfCfg.getConsumerGroup()); + assertEquals("C1", pnfCfg.getConsumerId()); + assertEquals("20000", pnfCfg.getTimeout()); + assertEquals("10000", pnfCfg.getLimit()); + assertEquals("5000", pnfCfg.getFetchPause()); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + @After + public void cleanUp() { + File file = new File(configFile); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java new file mode 100644 index 000000000..8741370aa --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestFaultConfig.java @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.FaultConfig; + +public class TestFaultConfig { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[fault]\n" + + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" + + "contenttype=application/json\n" + + "consumerGroup=myG\n" + + "consumerID=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=5000\n" + + ""; + // @formatter:on + + private ConfigurationFileRepresentation cfg; + private static final String CONFIGURATIONFILE = "test2.properties"; + + @Test + public void test() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation(CONFIGURATIONFILE); + FaultConfig faultCfg = new FaultConfig(cfg); + assertEquals("fault", faultCfg.getSectionName()); + assertEquals("unauthenticated.SEC_FAULT_OUTPUT", faultCfg.getTopic()); + assertEquals("myG", faultCfg.getConsumerGroup()); + assertEquals("C1", faultCfg.getConsumerId()); + assertEquals("20000", faultCfg.getTimeout()); + assertEquals("10000", faultCfg.getLimit()); + assertEquals("5000", faultCfg.getFetchPause()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @After + public void cleanUp() { + File file = new File(CONFIGURATIONFILE); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java new file mode 100644 index 000000000..9324f794d --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestGeneralConfig.java @@ -0,0 +1,53 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.config; + +import static org.junit.Assert.assertEquals; +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; + +public class TestGeneralConfig { + + private static final String CONFIGURATIONFILE = "test1.properties"; + + private GeneralConfigForTest config; + + @Before + public void before() throws IOException { + config = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @Test + public void test() throws IOException { + GeneralConfig cfg = config.getCfg(); + + assertEquals("http://localhost:8181", cfg.getBaseUrl()); + assertEquals("admin", cfg.getSDNRUser()); + assertEquals("admin", cfg.getSDNRPasswd()); + assertEquals("general", cfg.getSectionName()); + } + + @After + public void cleanUp() { + config.close(); + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java new file mode 100644 index 000000000..0a1ab241b --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestProvisioningConfig.java @@ -0,0 +1,69 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.ProvisioningConfig; + +public class TestProvisioningConfig { + + private static final String TESTCONFIG_CONTENT = "[provisioning]\n" + + + "topic=unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT\n" + + "consumerGroup=myG\n" + + "consumerID=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=5000\n" + + ""; + + private static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); + private static File configFile; + + @Test + public void testConfigValuesAssignment() throws IOException { + configFile = new File(TEMP_DIR, "test.properties"); + Files.asCharSink(configFile, StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(configFile); + ProvisioningConfig provisioningConfig = new ProvisioningConfig(cfg); + assertEquals("provisioning", provisioningConfig.getSectionName()); + assertEquals("unauthenticated.SEC_3GPP_PROVISIONING_OUTPUT", provisioningConfig.getTopic()); + assertEquals("myG", provisioningConfig.getConsumerGroup()); + assertEquals("C1", provisioningConfig.getConsumerId()); + assertEquals("20000", provisioningConfig.getTimeout()); + assertEquals("10000", provisioningConfig.getLimit()); + assertEquals("5000", provisioningConfig.getFetchPause()); + } + + @After + public void cleanUp() { + if (configFile.exists()) { + System.out.println(String.format("File %s exists, deleting it", configFile.getName())); + configFile.delete(); + } + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java new file mode 100644 index 000000000..b3546ea06 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/config/TestStrimziKafkaConfig.java @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.common.io.Files; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.StrimziKafkaConfig; + +public class TestStrimziKafkaConfig { + + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[strimzi-kafka]\n" + + "strimziEnabled=false\n" + + "bootstrapServers=onap-strimzi-kafka-0:9094,onap-strimzi-kafka-1:9094\n" + + "securityProtocol=PLAINTEXT\n" + + "saslMechanism=PLAIN\n" + + "saslJaasConfig=PLAIN\n" + + ""; + // @formatter:on + + private ConfigurationFileRepresentation cfg; + private static final String CONFIGURATIONFILE = "test2.properties"; + + @Test + public void test() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + cfg = new ConfigurationFileRepresentation(CONFIGURATIONFILE); + StrimziKafkaConfig sKafkaCfg = new StrimziKafkaConfig(cfg); + assertEquals("strimzi-kafka", sKafkaCfg.getSectionName()); + assertEquals("onap-strimzi-kafka-0:9094,onap-strimzi-kafka-1:9094", sKafkaCfg.getBootstrapServers()); + assertEquals("PLAINTEXT", sKafkaCfg.getSecurityProtocol()); + assertEquals(false, sKafkaCfg.getEnabled()); + assertEquals("PLAIN", sKafkaCfg.getSaslJaasConfig()); + assertEquals("PLAIN", sKafkaCfg.getSaslMechanism()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @After + public void cleanUp() { + File file = new File(CONFIGURATIONFILE); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } + + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java new file mode 100644 index 000000000..c3beb29f7 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaCMVESMsgConsumer.java @@ -0,0 +1,239 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.consumer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Iterator; +import java.util.Map; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.cm.StrimziKafkaCMVESMsgConsumer; + +public class TestStrimziKafkaCMVESMsgConsumer { + + private static final String CONFIGURATION_FILE = "cm_test.properties"; + private StrimziKafkaCMVESMsgConsumer sKafkaCMVESMsgConsumer; + private GeneralConfigForTest generalConfigForTest; + + @Before + public void setUp() throws Exception { + generalConfigForTest = new GeneralConfigForTest(CONFIGURATION_FILE); + sKafkaCMVESMsgConsumer = new StrimziKafkaCMVESMsgConsumer(generalConfigForTest.getCfg()); + } + + @Test + public void processValidMsg() throws URISyntaxException, IOException { + File cmFileValid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test(expected = InvalidMessageException.class) + public void processMsgThatMissesField() throws URISyntaxException, IOException, InvalidMessageException { + File cmFileInvalid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_invalid.json").toURI()); + String cmEvent = readFileToString(cmFileInvalid); + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } + + @Test(expected = InvalidMessageException.class) + public void processMsgThatHasInvalidNotificationType() + throws URISyntaxException, IOException, InvalidMessageException { + File cmFileInvalid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_invalid_type.json").toURI()); + String cmEvent = readFileToString(cmFileInvalid); + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } + + @Test(expected = JsonProcessingException.class) + public void processMsgThatIsNotValidJson() throws URISyntaxException, IOException, InvalidMessageException { + File cmFileInvalid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/not_a_json.json").toURI()); + String cmEvent = readFileToString(cmFileInvalid); + sKafkaCMVESMsgConsumer.processMsg(cmEvent); + } + + @Test + public void processMsgWithOneElementMoiChangesArray() throws URISyntaxException, IOException { + File cmFileValid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_valid.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Iterator nodes = rootNode + .at("/event/stndDefinedFields/data/moiChanges") + .elements(); + Map payloadMap = + sKafkaCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); + + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIChanges", payloadMap.get("@notification-type@")); + assertEquals("123", payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=1", payloadMap.get("@path@")); + assertEquals("REPLACE", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgWithTwoElementMoiChangesArray() throws URISyntaxException, IOException { + File cmFileValid = + new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_valid_two_element_moi_changes_array.json") + .toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Iterator nodes = rootNode + .at("/event/stndDefinedFields/data/moiChanges") + .elements(); + Map payloadMap = + sKafkaCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); + + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIChanges", payloadMap.get("@notification-type@")); + assertEquals("123", payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=1", payloadMap.get("@path@")); + assertEquals("REPLACE", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + Map payloadMap2 = null; + while (nodes.hasNext()) { + payloadMap2 = sKafkaCMVESMsgConsumer.preparePayloadMapFromMoiChangesArray(rootNode, nodes); + } + assertEquals("samsung-O-DU-1122", payloadMap2.get("@node-id@")); + assertEquals("124", payloadMap2.get("@notification-id@")); + assertEquals("RESOURCE_OPERATION", payloadMap2.get("@source-indicator@")); + assertEquals("https://samsung.com/3GPP/simulation/network-function/ves=2", payloadMap2.get("@path@")); + assertEquals("CREATE", payloadMap2.get("@operation@")); + assertEquals("{pnf-registration:false,faults-enabled:false}", payloadMap2.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgNotifyMoiCreationType() throws URISyntaxException, IOException { + File cmFileValid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_moi_creation.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map payloadMap = sKafkaCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList"); + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOICreation", payloadMap.get("@notification-type@")); + assertNull(payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertNull(payloadMap.get("@path@")); + assertEquals("NULL", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgNotifyMoiDeletionType() throws URISyntaxException, IOException { + File cmFileValid = new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_moi_deletion.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map payloadMap = sKafkaCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeList"); + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIDeletion", payloadMap.get("@notification-type@")); + assertNull(payloadMap.get("@notification-id@")); + assertEquals("MANAGEMENT_OPERATION", payloadMap.get("@source-indicator@")); + assertNull(payloadMap.get("@path@")); + assertEquals("NULL", payloadMap.get("@operation@")); + assertEquals("{pnf-registration:true,faults-enabled:true}", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + @Test + public void processMsgNotifyMoiAttributeValueChangesType() throws URISyntaxException, IOException { + File cmFileValid = + new File(TestStrimziKafkaCMVESMsgConsumer.class.getResource("/msgs/cm_moi_attribute_value_changes.json").toURI()); + String cmEvent = readFileToString(cmFileValid); + try { + JsonNode rootNode = convertMessageToJsonNode(cmEvent); + Map payloadMap = sKafkaCMVESMsgConsumer.preparePayloadMapFromMoi(rootNode,"/event/stndDefinedFields/data/attributeListValueChanges"); + assertEquals("samsung-O-DU-1122", payloadMap.get("@node-id@")); + assertEquals("0", payloadMap.get("@counter@")); + assertEquals("2019-01-09T12:30:07.722Z", payloadMap.get("@timestamp@")); + assertEquals("src_device_id_1732f1ad-53fd-4fd1-8b73-a677987d4e8f", payloadMap.get("@object-id@")); + assertEquals("notifyMOIAttributeValueChanges", payloadMap.get("@notification-type@")); + assertNull(payloadMap.get("@notification-id@")); + assertEquals("UNKNOWN", payloadMap.get("@source-indicator@")); + assertNull(payloadMap.get("@path@")); + assertEquals("NULL", payloadMap.get("@operation@")); + assertEquals("[{attributeNameValuePairSet:{faults-enabled:true}}]", payloadMap.get("@value@")); + + } catch (Exception e) { + fail("Test fail with message: " + e.getMessage()); + } + } + + private String readFileToString(File file) throws IOException { + StringBuilder fileContent = new StringBuilder(); + Files.lines(Paths.get(file.toURI())).forEach(fileContent::append); + return fileContent.toString(); + } + + private JsonNode convertMessageToJsonNode(String message) throws JsonProcessingException { + return new ObjectMapper().readTree(message); + } + + @After + public void after() { + generalConfigForTest.close(); + } +} \ No newline at end of file diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaFaultVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaFaultVESMsgConsumer.java new file mode 100644 index 000000000..912b73584 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaFaultVESMsgConsumer.java @@ -0,0 +1,150 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.consumer; + +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.fault.StrimziKafkaFaultVESMsgConsumer; + +public class TestStrimziKafkaFaultVESMsgConsumer { + + private static final String DEFAULT_SDNRUSER = "admin"; + private static final String DEFAULT_SDNRPASSWD = "admin"; + private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; + private static final String CONFIGURATIONFILE = "test2.properties"; + + // @formatter:off + private static final String faultVESMsg = "" + + "{\"event\":" + " {\"commonEventHeader\":" + + " { \"domain\":\"fault\"," + + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," + + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," + + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," + + " \"sequence\":1," + + " \"priority\":\"Low\"," + + " \"reportingEntityId\":\"\"," + + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," + + " \"sourceId\":\"\"," + + " \"sourceName\":\"1e9a28bcd119_50007\"," + + " \"startEpochMicrosec\":1614004128699785," + + " \"lastEpochMicrosec\":1614004128699785," + + " \"nfNamingCode\":\"sdn controller\"," + + " \"nfVendorName\":\"sdn\"," + + " \"timeZoneOffset\":\"+00:00\"," + + " \"version\":\"4.0.1\"," + + " \"vesEventListenerVersion\":\"7.0.1\"" + + " }," + + " \"faultFields\":" + + " {" + + " \"faultFieldsVersion\":\"4.0\"," + + " \"alarmCondition\":\"8\"," + + " \"alarmInterfaceA\":\"dkom32\"," + + " \"eventSourceType\":\"O_RAN_COMPONENT\"," + + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," + + " \"eventSeverity\":\"@eventSeverity@\"," + + " \"vfStatus\":\"Active\"," + + " \"alarmAdditionalInformation\":" + + " {" + + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," + + " \"equipType\":\"O-RAN-sim\"," + + " \"vendor\":\"Melacon\"," + + " \"model\":\"Simulated Device\"" + + " }" + + " }" + + " }" + + "}"; + // @formatter:on + // @formatter:off + private static final String faultVESMsg_Incomplete = "" + + "{\"event\":" + + " {\"commonEventHeader\":" + + " { \"domain\":\"fault\"," + + " \"eventId\":\"1e9a28bcd119_50007_2019-11-20T14:59:47.3Z\"," + + " \"eventName\":\"fault_O_RAN_COMPONENT_Alarms\"," + + " \"eventType\":\"O_RAN_COMPONENT_Alarms\"," + + " \"sequence\":1," + + " \"priority\":\"Low\"," + + " \"reportingEntityId\":\"\"," + + " \"reportingEntityName\":\"1e9a28bcd119_50007\"," + + " \"sourceId\":\"\"," + + " \"sourceName\":\"1e9a28bcd119_50007\"," + + " \"startEpochMicrosec\":1612349525626," + + " \"lastEpochMicrosec\":1612349525626," + + " \"nfNamingCode\":\"sdn controller\"," + + " \"nfVendorName\":\"sdn\"," + + " \"timeZoneOffset\":\"+00:00\"," + + " \"version\":\"4.0.1\"," + + " \"vesEventListenerVersion\":\"7.0.1\"," + + " }," + + " \"faultFields\":" + + " {" + + " \"faultFieldsVersion\":\"4.0\"," + + " \"alarmCondition\":\"8\"," + + " \"alarmInterfaceA\":\"dkom32\"," + + " \"eventSourceType\":\"O_RAN_COMPONENT\"," + + " \"specificProblem\":\"dsonj32 don32 mdson32pk654\"," + + " \"eventSeverity\":\"CRITICAL\"," + + " \"vfStatus\":\"Active\"," + + " \"alarmAdditionalInformation\":" + + " {" + + " \"eventTime\":\"2019-11-20T14:59:47.3Z\"," + + " \"equipType\":\"O-RAN-sim\"," + + " \"vendor\":\"Melacon\"," + + " \"model\":\"Simulated Device\"" + + " }" + + " }" + + " }" + + "}"; + // @formatter:on + + private GeneralConfigForTest cfgTest; + + @Before + public void before() throws IOException { + cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @After + public void after() { + cfgTest.close(); + } + + + @Test + public void test() throws IOException { + StrimziKafkaFaultVESMsgConsumer faultMsgConsumer = new StrimziKafkaFaultVESMsgConsumer(cfgTest.getCfg()); + try { + + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "CRITICAL")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Major")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "minor")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "NonAlarmed")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "warning")); + faultMsgConsumer.processMsg(faultVESMsg.replace("@eventSeverity@", "Unknown")); + faultMsgConsumer.processMsg(faultVESMsg_Incomplete); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing Fault Message - " + e.getMessage()); + } + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java new file mode 100644 index 000000000..20b6c4ae7 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaPNFRegVESMsgConsumer.java @@ -0,0 +1,271 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.consumer; + +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg.StrimziKafkaPNFRegVESMsgConsumer; + +public class TestStrimziKafkaPNFRegVESMsgConsumer { + + private static final String DEFAULT_SDNRUSER = "admin"; + private static final String DEFAULT_SDNRPASSWD = "admin"; + private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181"; + private static final String CONFIGURATIONFILE = "test4.properties"; + + // @formatter:off + private static final String pnfRegMsg_TLS = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"additionalFields\": \n" + + " { \n" + + " \"protocol\":\"TLS\",\n" + + " \"keyId\":\"netconf\",\n" + + " \"oamPort\":\"50000\",\n" + + " \"betweenAttemptsTimeout\":\"2000\",\n" + + " \"keepaliveDelay\":\"120\",\n" + + " \"sleep-factor\":\"1.5\",\n" + + " \"reconnectOnChangedSchema\":\"false\",\n" + + " \"connectionTimeout\":\"20000\",\n" + + " \"maxConnectionAttempts\":\"100\",\n" + + " \"username\":\"netconf\",\n" + + " \"tcpOnly\":\"false\"\n" + + " },\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + private static final String pnfRegMsg_SSH = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"additionalFields\": \n" + + " { \n" + + " \"protocol\":\"SSH\",\n" + + " \"password\":\"netconf\",\n" + + " \"oamPort\":\"50000\",\n" + + " \"betweenAttemptsTimeout\":\"2000\",\n" + + " \"keepaliveDelay\":\"120\",\n" + + " \"sleep-factor\":\"1.5\",\n" + + " \"reconnectOnChangedSchema\":\"false\",\n" + + " \"connectionTimeout\":\"20000\",\n" + + " \"maxConnectionAttempts\":\"100\",\n" + + " \"username\":\"netconf\",\n" + + " \"tcpOnly\":\"false\"\n" + + " },\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + private static final String pnfRegMsg_OTHER = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"additionalFields\": \n" + + " { \n" + + " \"protocol\":\"OTHER\",\n" + + " \"password\":\"netconf\",\n" + + " \"oamPort\":\"50000\",\n" + + " \"betweenAttemptsTimeout\":\"2000\",\n" + + " \"keepaliveDelay\":\"120\",\n" + + " \"sleep-factor\":\"1.5\",\n" + + " \"reconnectOnChangedSchema\":\"false\",\n" + + " \"connectionTimeout\":\"20000\",\n" + + " \"maxConnectionAttempts\":\"100\",\n" + + " \"username\":\"netconf\",\n" + + " \"tcpOnly\":\"false\"\n" + + " },\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + + " \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + private static final String pnfRegMsg = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"pnfRegistration\",\n" + + " \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n" + + " \"eventName\": \"pnfRegistration_EventType5G\",\n" + + " \"eventType\": \"EventType5G\",\n" + + " \"sequence\": 0,\n" + + " \"priority\": \"Low\",\n" + + " \"reportingEntityId\": \"\",\n" + + " \"reportingEntityName\": \"pendurty-virtual-machine\",\n" + + " \"sourceId\": \"\",\n" + + " \"sourceName\": \"NSHMRIACQ01M01123401\",\n" + + " \"startEpochMicrosec\": 1571300004203,\n" + + " \"lastEpochMicrosec\": 1571300004203,\n" + + " \"nfNamingCode\": \"1234\",\n" + + " \"nfVendorName\": \"VENDORA\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"version\": \"4.0.1\",\n" + + " \"vesEventListenerVersion\":\"7.0.1\"\n" + + " },\n" + + " \"pnfRegistrationFields\": {\n" + + " \"pnfRegistrationFieldsVersion\": \"2.0\",\n" + + " \"lastServiceDate\":\"2019-08-16\",\n" + + " \"macAddress\":\"02:42:f7:d4:62:ce\",\n" + + " \"manufactureDate\":\"2019-08-16\",\n" + + " \"modelNumbsdnrer\": \"1234 BestInClass\",\n" + + " \"oamV4IpAddress\": \"10.10.10.11\",\n" + + " \"oamPort\":\"17380\",\n" + //+ " \"oamV6IpAddress\": \"\",\n" + + " \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n" + + " \"softwareVersion\": \"2.3.5\",\n" + + " \"unitFamily\": \"VENDORA-1234\",\n" + + " \"unitType\": \"1234\",\n" + + " \"vendorName\": \"VENDORA\"\n" + + " }\n" + + " }\n" + + "}\n" + + ""; + // @formatter:on + + private GeneralConfigForTest cfgTest; + + @Before + public void before() throws IOException { + cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @After + public void after() { + cfgTest.close(); + } + + @Test + public void processMsgTest() { + + StrimziKafkaPNFRegVESMsgConsumer pnfRegMsgConsumer = new StrimziKafkaPNFRegVESMsgConsumer(cfgTest.getCfg()); + try { + pnfRegMsgConsumer.processMsg(pnfRegMsg); + pnfRegMsgConsumer.processMsg(pnfRegMsg_SSH); + pnfRegMsgConsumer.processMsg(pnfRegMsg_TLS); + pnfRegMsgConsumer.processMsg(pnfRegMsg_OTHER); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing PNF Registration Message - " + e.getMessage()); + } + } + + @Test + public void Test1() { + StrimziKafkaPNFRegVESMsgConsumer pnfConsumer = new StrimziKafkaPNFRegVESMsgConsumer(cfgTest.getCfg()); + System.out.println(pnfConsumer.getBaseUrl()); + System.out.println(pnfConsumer.getSDNRUser()); + System.out.println(pnfConsumer.getSDNRPasswd()); + } + +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java new file mode 100644 index 000000000..0185bf687 --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaStndDefinedVESMsgConsumer.java @@ -0,0 +1,239 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.consumer; + +import com.fasterxml.jackson.core.JsonProcessingException; +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.InvalidMessageException; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.config.GeneralConfigForTest; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.stnddefined.StrimziKafkaStndDefinedFaultVESMsgConsumer; + +public class TestStrimziKafkaStndDefinedVESMsgConsumer { + + private static final String CONFIGURATIONFILE = "test2.properties"; + + // @formatter:off + private static final String stndDefinedVESMsg_NotifyNewAlarm = + "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"startEpochMicrosec\": 1669022429000000,\n" + + " \"eventId\": \"stndDefined000000001\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"internalHeaderFields\": {\n" + + " \"collectorTimeStamp\": \"Mon, 11 21 2022 09:20:30 UTC\"\n" + + " },\n" + + " \"eventType\": \"5GCell-NodeH_Alarms\",\n" + + " \"priority\": \"Low\",\n" + + " \"version\": \"4.1\",\n" + + " \"nfVendorName\": \"NodeH\",\n" + + " \"reportingEntityName\": \"NodeH-5GCell-1234\",\n" + + " \"sequence\": 5,\n" + + " \"domain\": \"stndDefined\",\n" + + " \"lastEpochMicrosec\": 1669022429000000,\n" + + " \"eventName\": \"StndDefined_5GCell-NodeH_Alarms_MyAlarm\",\n" + + " \"vesEventListenerVersion\": \"7.2.1\",\n" + + " \"sourceName\": \"NodeH-5GCell-1234\",\n" + + " \"stndDefinedNamespace\": \"3GPP-FaultSupervision\",\n" + + " \"nfNamingCode\": \"5GCell\"\n" + + " },\n" + + " \"stndDefinedFields\": {\n" + + " \"stndDefinedFieldsVersion\": \"1.0\",\n" + + " \"data\": {\n" + + " \"additionalInformation\": {\n" + + " \"equipType\": \"5GCell\",\n" + + " \"vendor\": \"NodeH\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"model\": \"SF1234\"\n" + + " },\n" + + " \"backedUpStatus\": false,\n" + + " \"rootCauseIndicator\": false,\n" + + " \"notificationType\": \"notifyNewAlarm\",\n" + + " \"systemDN\": \"DC=com.Node-H,CN=5GCell\",\n" + + " \"alarmType\": \"COMMUNICATIONS_ALARM\",\n" + + " \"probableCause\": \"My cause\",\n" + + " \"perceivedSeverity\": \"@eventSeverity@\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"alarmId\": \"MyAlarm\",\n" + + " \"proposedRepairActions\": \"Repair me\",\n" + + " \"notificationId\": 0,\n" + + " \"href\": \"http://10.0.33.23/3GPPManagement/FaultSupervisionMnS/17.1.0\"\n" + + " },\n" + + " \"schemaReference\": \"https://forge.3gpp.org/rep/sa5/MnS/-/blob/Rel-18/OpenAPI/TS28532_FaultMnS.yaml#components/schemas/NotifyNewAlarm\"\n" + + " }\n" + + " }\n" + + "}"; + // @formatter:on + // @formatter:off + private static final String stndDefinedVESMsg_NotifyClearedAlarm = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"startEpochMicrosec\": 1669022429000000,\n" + + " \"eventId\": \"stndDefined000000001\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"internalHeaderFields\": {\n" + + " \"collectorTimeStamp\": \"Mon, 11 21 2022 09:20:30 UTC\"\n" + + " },\n" + + " \"eventType\": \"5GCell-NodeH_Alarms\",\n" + + " \"priority\": \"Low\",\n" + + " \"version\": \"4.1\",\n" + + " \"nfVendorName\": \"NodeH\",\n" + + " \"reportingEntityName\": \"NodeH-5GCell-1234\",\n" + + " \"sequence\": 5,\n" + + " \"domain\": \"stndDefined\",\n" + + " \"lastEpochMicrosec\": 1669022429000000,\n" + + " \"eventName\": \"StndDefined_5GCell-NodeH_Alarms_MyAlarm\",\n" + + " \"vesEventListenerVersion\": \"7.2.1\",\n" + + " \"sourceName\": \"NodeH-5GCell-1234\",\n" + + " \"stndDefinedNamespace\": \"3GPP-FaultSupervision\",\n" + + " \"nfNamingCode\": \"5GCell\"\n" + + " },\n" + + " \"stndDefinedFields\": {\n" + + " \"stndDefinedFieldsVersion\": \"1.0\",\n" + + " \"data\": {\n" + + " \"additionalInformation\": {\n" + + " \"equipType\": \"5GCell\",\n" + + " \"vendor\": \"NodeH\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"model\": \"SF1234\"\n" + + " },\n" + + " \"backedUpStatus\": false,\n" + + " \"rootCauseIndicator\": false,\n" + + " \"notificationType\": \"notifyClearedAlarm\",\n" + + " \"systemDN\": \"DC=com.Node-H,CN=5GCell\",\n" + + " \"alarmType\": \"COMMUNICATIONS_ALARM\",\n" + + " \"probableCause\": \"My cause\",\n" + + " \"perceivedSeverity\": \"@eventSeverity@\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"alarmId\": \"MyAlarm\",\n" + + " \"proposedRepairActions\": \"Repair me\",\n" + + " \"notificationId\": 0,\n" + + " \"href\": \"http://10.0.33.23/3GPPManagement/FaultSupervisionMnS/17.1.0\"\n" + + " },\n" + + " \"schemaReference\": \"https://forge.3gpp.org/rep/sa5/MnS/-/blob/Rel-18/OpenAPI/TS28532_FaultMnS.yaml#components/schemas/NotifyClearedAlarm\"\n" + + " }\n" + + " }\n" + + "}"; + // @formatter:on + + // @formatter:off + private static final String stndDefinedVESMsg_Invalid = "{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"startEpochMicrosec\": 1669022429000000,\n" + + " \"eventId\": \"stndDefined000000001\",\n" + + " \"timeZoneOffset\": \"+00:00\",\n" + + " \"internalHeaderFields\": {\n" + + " \"collectorTimeStamp\": \"Mon, 11 21 2022 09:20:30 UTC\"\n" + + " },\n" + + " \"eventType\": \"5GCell-NodeH_Alarms\",\n" + + " \"priority\": \"Low\",\n" + + " \"version\": \"4.1\",\n" + + " \"nfVendorName\": \"NodeH\",\n" + + " \"reportingEntityName\": \"NodeH-5GCell-1234\",\n" + + " \"sequence\": 5,\n" + + " \"domain\": \"stndDefined\",\n" + + " \"lastEpochMicrosec\": 1669022429000000,\n" + + " \"eventName\": \"StndDefined_5GCell-NodeH_Alarms_MyAlarm\",\n" + + " \"vesEventListenerVersion\": \"7.2.1\",\n" + + " \"sourceName\": \"NodeH-5GCell-1234\",\n" + + " \"stndDefinedNamespace\": \"3GPP-FaultSupervision\",\n" + + " \"nfNamingCode\": \"5GCell\"\n" + + " },\n" + + " \"stndDefinedFields\": {\n" + + " \"stndDefinedFieldsVersion\": \"1.0\",\n" + + " \"data\": {\n" + + " \"additionalInformation\": {\n" + + " \"equipType\": \"5GCell\",\n" + + " \"vendor\": \"NodeH\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"model\": \"SF1234\"\n" + + " },\n" + + " \"backedUpStatus\": false,\n" + + " \"rootCauseIndicator\": false,\n" + + " \"notificationType\": \"notifyChangedAlarm\",\n" + + " \"systemDN\": \"DC=com.Node-H,CN=5GCell\",\n" + + " \"alarmType\": \"COMMUNICATIONS_ALARM\",\n" + + " \"probableCause\": \"My cause\",\n" + + " \"perceivedSeverity\": \"@eventSeverity@\",\n" + + " \"eventTime\": \"2022-11-21T09:20:29Z\",\n" + + " \"alarmId\": \"MyAlarm\",\n" + + " \"proposedRepairActions\": \"Repair me\",\n" + + " \"notificationId\": 0,\n" + + " \"href\": \"http://10.0.33.23/3GPPManagement/FaultSupervisionMnS/17.1.0\"\n" + + " },\n" + + " \"schemaReference\": \"https://forge.3gpp.org/rep/sa5/MnS/-/blob/Rel-18/OpenAPI/TS28532_FaultMnS.yaml#components/schemas/NotifyClearedAlarm\"\n" + + " }\n" + + " }\n" + + "}"; + // @formatter:on + private GeneralConfigForTest cfgTest; + + @Before + public void before() throws IOException { + cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE); + } + + @After + public void after() { + cfgTest.close(); + } + + + @Test + public void testNotifyNewAlarm() throws IOException { + StrimziKafkaStndDefinedFaultVESMsgConsumer stndDefinedFaultMsgConsumer = new StrimziKafkaStndDefinedFaultVESMsgConsumer(cfgTest.getCfg()); + try { + + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "CRITICAL")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "Major")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "minor")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "NonAlarmed")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "warning")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyNewAlarm.replace("@eventSeverity@", "Unknown")); + //stndDefinedFaultMsgConsumer.processMsg(faultVESMsg_Incomplete); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing Fault Message - " + e.getMessage()); + } + } + + @Test + public void testNotifyClearedAlarm() throws IOException { + StrimziKafkaStndDefinedFaultVESMsgConsumer stndDefinedFaultMsgConsumer = new StrimziKafkaStndDefinedFaultVESMsgConsumer(cfgTest.getCfg()); + try { + + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyClearedAlarm.replace("@eventSeverity@", "cleared")); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_NotifyClearedAlarm.replace("@eventSeverity@", "Indeterminate")); + //stndDefinedFaultMsgConsumer.processMsg(faultVESMsg_Incomplete); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("Exception while processing Fault Message - " + e.getMessage()); + } + } + + @Test(expected = InvalidMessageException.class) + public void testInvalidStndDefinedMessage() throws InvalidMessageException, JsonProcessingException { + StrimziKafkaStndDefinedFaultVESMsgConsumer stndDefinedFaultMsgConsumer = new StrimziKafkaStndDefinedFaultVESMsgConsumer(cfgTest.getCfg()); + stndDefinedFaultMsgConsumer.processMsg(stndDefinedVESMsg_Invalid.replace("@eventSeverity@", "cleared")); + } +} diff --git a/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java new file mode 100644 index 000000000..d218d0d6f --- /dev/null +++ b/sdnr/wt/mountpoint-registrar/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/mountpointregistrar/test/consumer/TestStrimziKafkaVESMsgConsumerMain.java @@ -0,0 +1,175 @@ +/* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved. + * ================================================================================================= + * 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.ccsdk.features.sdnr.wt.mountpointregistrar.test.consumer; + +import static org.junit.Assert.assertNotNull; +import com.google.common.io.Files; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.After; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.FaultConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.MessageConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.PNFRegistrationConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.ProvisioningConfig; +import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.*; + +public class TestStrimziKafkaVESMsgConsumerMain { + + private static final String CONFIGURATIONFILE = "test1.properties"; + private static final String TESTCONFIG_GENERAL = "[general]\n" + + "dmaapEnabled=false\n" + + "baseUrl=http://localhost:8181\n" + + "sdnrUser=admin\n" + + "sdnrPasswd=admin\n" + + "\n" + + "[pnfRegistration]\n" + + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test.impl.DMaaPPNFRegVESMsgConsumer\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "\n" + + "[fault]\n" + + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "fetchPause=10000\n" + + "\n" + + ""; + + private static final String TESTCONFIG_GENERAL_INVALID = "[general]\n" + + "dmaapEnabled=false\n" + + "baseUrl=http://localhost:8181\n" + + "sdnrUser=admin\n" + + "sdnrPasswd=admin\n" + + "\n" + + "[pnfRegistration]\n" + + "pnfRegConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer.java\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.VES_PNFREG_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=20000\n" + + "limit=10000\n" + + "\n" + + "[fault]\n" + + "faultConsumerClass=org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPFaultVESMsgConsumer.java\n" + + "TransportType=HTTPNOAUTH\n" + + "host=onap-dmap:3904\n" + + "topic=unauthenticated.SEC_FAULT_OUTPUT\n" + + "contenttype=application/json\n" + + "group=myG\n" + + "id=C1\n" + + "timeout=HELLO\n" + + "limit=10000\n" + + "fetchPause=WORLD\n" + + "\n" + + ""; + public GeneralConfig generalConfig; + Map configMap = new HashMap<>(); + StrimziKafkaVESMsgConsumerMain dmaapMain; + + + public void preTest1() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL); + ConfigurationFileRepresentation configFileRepresentation = + new ConfigurationFileRepresentation(CONFIGURATIONFILE); + + generalConfig = new GeneralConfig(configFileRepresentation); + PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); + FaultConfig faultConfig = new FaultConfig(configFileRepresentation); + ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); + + configMap.put("pnfRegistration", pnfRegConfig); + configMap.put("fault", faultConfig); + configMap.put("provisioning", provisioningConfig); + } catch (Exception e) { + System.out.println("Failed in preTest execution " + e.getMessage()); + } + } + + public void preTest2() { + try { + Files.asCharSink(new File(CONFIGURATIONFILE), StandardCharsets.UTF_8).write(TESTCONFIG_GENERAL_INVALID); + ConfigurationFileRepresentation configFileRepresentation = + new ConfigurationFileRepresentation(CONFIGURATIONFILE); + + generalConfig = new GeneralConfig(configFileRepresentation); + PNFRegistrationConfig pnfRegConfig = new PNFRegistrationConfig(configFileRepresentation); + FaultConfig faultConfig = new FaultConfig(configFileRepresentation); + ProvisioningConfig provisioningConfig = new ProvisioningConfig(configFileRepresentation); + + configMap.put("pnfRegistration", pnfRegConfig); + configMap.put("fault", faultConfig); + configMap.put("provisioning", provisioningConfig); + } catch (Exception e) { + System.out.println("Failed in preTest execution " + e.getMessage()); + } + } + + @Test + public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration() { + preTest1(); + assertNotNull(configMap); +// dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); + } + + @Test + public void testDMaaPVESMsgConsumerMainMapOfStringConfiguration1() { + preTest2(); + assertNotNull(configMap); +// dmaapMain = new DMaaPVESMsgConsumerMain(configMap, generalConfig); + } + + @After + public void postTest() { + File file = new File(CONFIGURATIONFILE); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } +// List consumers = dmaapMain.getConsumers(); +// for (DMaaPVESMsgConsumer consumer : consumers) { +// // stop all consumers +// consumer.stopConsumer(); +// } + } +} + + -- cgit 1.2.3-korg