2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt mountpoint-registrar
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
7 * =================================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software distributed under the License
14 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15 * or implied. See the License for the specific language governing permissions and limitations under
17 * ============LICENSE_END==========================================================================
20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg;
22 import com.fasterxml.jackson.databind.JsonNode;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import java.io.IOException;
26 import org.apache.kafka.clients.admin.Admin;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config.GeneralConfig;
29 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.StrimziKafkaVESMsgConsumerImpl;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class StrimziKafkaPNFRegVESMsgConsumer extends StrimziKafkaVESMsgConsumerImpl {
35 private static final Logger LOG = LoggerFactory.getLogger(StrimziKafkaPNFRegVESMsgConsumer.class);
36 private static final String DEFAULT_PROTOCOL = "SSH";
37 private static final String DEFAULT_PORT = "17830";
38 private static final String DEFAULT_USERNAME = "netconf";
39 private static final String DEFAULT_PASSWORD = "netconf";
42 public StrimziKafkaPNFRegVESMsgConsumer(GeneralConfig generalConfig, Admin kafkaAdminClient) {
43 super(generalConfig, kafkaAdminClient);
47 public void processMsg(String msg) {
48 LOG.debug("Message from Kafka topic is - {} ", msg);
52 String pnfCommProtocol;
56 String pnfKeyId = null;
60 String pnfPasswd = null;
61 String reportingEntityName;
62 ObjectMapper oMapper = new ObjectMapper();
63 JsonNode sKafkaMessageRootNode;
65 sKafkaMessageRootNode = oMapper.readTree(msg);
66 reportingEntityName = sKafkaMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue();
67 if (reportingEntityName.equals("ONAP SDN-R")) {
69 "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message");
73 pnfId = sKafkaMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
74 pnfIPAddress = getPNFIPAddress(sKafkaMessageRootNode);
76 sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue();
77 pnfCommPort = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue();
78 if (pnfCommProtocol != null) {
79 if (pnfCommProtocol.equalsIgnoreCase("TLS")) {
80 // Read username and keyId
82 sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue();
83 pnfUsername = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
85 } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) {
86 // Read username and password
87 pnfUsername = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
89 pnfPasswd = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password")
92 // log warning - Unknown protocol
93 LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}",
94 pnfCommProtocol, ". Defaulting to SSH");
95 pnfCommProtocol = DEFAULT_PROTOCOL;
96 pnfCommPort = DEFAULT_PORT;
97 pnfUsername = DEFAULT_USERNAME;
98 pnfPasswd = DEFAULT_PASSWORD;
101 LOG.warn("Protocol not specified in VES message, Defaulting to SSH");
102 pnfCommProtocol = DEFAULT_PROTOCOL;
103 pnfCommPort = DEFAULT_PORT;
104 pnfUsername = DEFAULT_USERNAME;
105 pnfPasswd = DEFAULT_PASSWORD;
109 "PNF Fields - ID - {} : IP Address - {} : Protocol - {} : TLS Key ID - {} : User - {} : Port - {}",
110 pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername, pnfCommPort);
112 String baseUrl = getBaseUrl();
113 String sdnrUser = getSDNRUser();
114 String sdnrPasswd = getSDNRPasswd();
116 if (hasNullInRequiredField(pnfId, pnfIPAddress, pnfCommPort, pnfCommProtocol, pnfUsername)) {
117 LOG.warn("One of the mandatory fields has a null value - pnfId = {} : pnfIPAddress = {} : " +
118 "pnfCommProtocol = {} : pnfUsername {} : pnfCommPort {} - not invoking mountpoint creation",
119 pnfId, pnfIPAddress, pnfCommProtocol, pnfUsername, pnfCommPort);
123 Map<String, String> payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap(pnfId, pnfIPAddress,
124 pnfCommPort, pnfCommProtocol, pnfUsername, pnfPasswd, pnfKeyId);
126 PNFMountPointClient mountPointClient = new PNFMountPointClient(baseUrl);
127 LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
128 mountPointClient.setAuthorization(sdnrUser, sdnrPasswd);
129 String message = mountPointClient.prepareMessageFromPayloadMap(payloadMap);
130 mountPointClient.sendNotification(message);
132 } catch (IOException e) {
133 LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}",
138 private boolean hasNullInRequiredField(String pnfId, String pnfIPAddress, String pnfCommPort,
139 String pnfCommProtocol, String pnfUsername) {
141 return pnfId == null || pnfIPAddress == null || pnfCommProtocol == null ||
142 pnfCommPort == null || pnfUsername == null;
145 private String getPNFIPAddress(JsonNode sKafkaMessageRootNode) {
146 String ipAddress = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/oamV6IpAddress").textValue();
147 if (ipAddress != null && ipAddress != "")
150 ipAddress = sKafkaMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue();
151 if (ipAddress != null && ipAddress != "")