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.impl;
22 import com.fasterxml.jackson.databind.JsonNode;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import java.io.IOException;
26 import org.eclipse.jdt.annotation.Nullable;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
32 private static final Logger LOG = LoggerFactory.getLogger(DMaaPPNFRegVESMsgConsumer.class);
33 private static final String DEFAULT_PROTOCOL = "SSH";
34 private static final String DEFAULT_PORT = "17830";
35 private static final String DEFAULT_USERNAME = "netconf";
36 private static final String DEFAULT_PASSWORD = "netconf";
39 public DMaaPPNFRegVESMsgConsumer(GeneralConfig generalConfig) {
44 public void processMsg(String msg) {
45 LOG.debug("Message from DMaaP topic is - {} ", msg);
49 String pnfCommProtocol;
53 String pnfKeyId = null;
57 String pnfPasswd = null;
58 String reportingEntityName;
59 ObjectMapper oMapper = new ObjectMapper();
60 JsonNode dmaapMessageRootNode;
62 dmaapMessageRootNode = oMapper.readTree(msg);
63 reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue();
64 if (reportingEntityName.equals("ONAP SDN-R")) {
66 "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message");
70 pnfId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
71 pnfIPAddress = getPNFIPAddress(dmaapMessageRootNode);
73 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue();
74 pnfCommPort = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue();
75 if (pnfCommProtocol != null) {
76 if (pnfCommProtocol.equalsIgnoreCase("TLS")) {
77 // Read username and keyId
79 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue();
80 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
82 } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) {
83 // Read username and password
84 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
86 pnfPasswd = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password")
89 // log warning - Unknown protocol
90 LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}",
91 pnfCommProtocol, ". Defaulting to SSH");
92 pnfCommProtocol = DEFAULT_PROTOCOL;
93 pnfCommPort = DEFAULT_PORT;
94 pnfUsername = DEFAULT_USERNAME;
95 pnfPasswd = DEFAULT_PASSWORD;
98 LOG.warn("Protocol not specified in VES message, Defaulting to SSH");
99 pnfCommProtocol = DEFAULT_PROTOCOL;
100 pnfCommPort = DEFAULT_PORT;
101 pnfUsername = DEFAULT_USERNAME;
102 pnfPasswd = DEFAULT_PASSWORD;
106 "PNF Fields - ID - {} : IP Address - {} : Protocol - {} : TLS Key ID - {} : User - {} : Port - {}",
107 pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername, pnfCommPort);
109 String baseUrl = getBaseUrl();
110 String sdnrUser = getSDNRUser();
111 String sdnrPasswd = getSDNRPasswd();
113 if (hasNullInRequiredField(pnfId, pnfIPAddress, pnfCommPort, pnfCommProtocol, pnfUsername)) {
114 LOG.warn("One of the mandatory fields has a null value - pnfId = {} : pnfIPAddress = {} : " +
115 "pnfCommProtocol = {} : pnfUsername {} : pnfCommPort {} - not invoking mountpoint creation",
116 pnfId, pnfIPAddress, pnfCommProtocol, pnfUsername, pnfCommPort);
120 Map<String, String> payloadMap = PNFMountPointClient.createPNFNotificationPayloadMap(pnfId, pnfIPAddress,
121 pnfCommPort, pnfCommProtocol, pnfUsername, pnfPasswd, pnfKeyId);
123 PNFMountPointClient mountPointClient = new PNFMountPointClient(baseUrl);
124 LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
125 mountPointClient.setAuthorization(sdnrUser, sdnrPasswd);
126 String message = mountPointClient.prepareMessageFromPayloadMap(payloadMap);
127 mountPointClient.sendNotification(message);
129 } catch (IOException e) {
130 LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}",
135 private boolean hasNullInRequiredField(String pnfId, String pnfIPAddress, String pnfCommPort,
136 String pnfCommProtocol, String pnfUsername) {
138 return pnfId == null || pnfIPAddress == null || pnfCommProtocol == null ||
139 pnfCommPort == null || pnfUsername == null;
142 private String getPNFIPAddress(JsonNode dmaapMessageRootNode) {
143 String ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV6IpAddress").textValue();
144 if (ipAddress != null && ipAddress != "")
147 ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue();
148 if (ipAddress != null && ipAddress != "")