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 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21 import com.fasterxml.jackson.databind.JsonNode;
22 import com.fasterxml.jackson.databind.ObjectMapper;
23 import java.io.IOException;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
30 private static final Logger LOG = LoggerFactory.getLogger(DMaaPPNFRegVESMsgConsumer.class);
31 private static final String DEFAULT_PROTOCOL = "SSH";
32 private static final String DEFAULT_PORT = "17830";
33 private static final String DEFAULT_USERNAME = "netconf";
34 private static final String DEFAULT_PASSWORD = "netconf";
35 private static final String DEFAULT_SDNRUSER = "admin";
36 private static final String DEFAULT_SDNRPASSWD = "admin";
38 private final GeneralConfig generalConfig;
40 public DMaaPPNFRegVESMsgConsumer(GeneralConfig generalConfig) {
41 this.generalConfig = generalConfig;
45 public void processMsg(String msg) {
46 LOG.debug("Message from DMaaP topic is - {} ", msg);
50 String pnfCommProtocol;
54 String pnfKeyId = null;
58 String pnfPasswd = null;
59 String reportingEntityName;
60 ObjectMapper oMapper = new ObjectMapper();
61 JsonNode dmaapMessageRootNode;
63 dmaapMessageRootNode = oMapper.readTree(msg);
64 reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue();
65 if (reportingEntityName.equals("ONAP SDN-R")) {
67 "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message");
71 pnfId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
72 pnfIPAddress = getPNFIPAddress(dmaapMessageRootNode);
74 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue();
75 pnfCommPort = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue();
76 if (pnfCommProtocol != null) {
77 if (pnfCommProtocol.equalsIgnoreCase("TLS")) {
78 // Read username and keyId
80 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue();
81 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
83 } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) {
84 // Read username and password
85 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
87 pnfPasswd = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password")
90 // log warning - Unknown protocol
91 LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}",
92 pnfCommProtocol, ". Defaulting to SSH");
93 pnfCommProtocol = DEFAULT_PROTOCOL;
94 pnfCommPort = DEFAULT_PORT;
95 pnfUsername = DEFAULT_USERNAME;
96 pnfPasswd = DEFAULT_PASSWORD;
99 LOG.warn("Protocol not specified in VES message, Defaulting to SSH");
100 pnfCommProtocol = DEFAULT_PROTOCOL;
101 pnfCommPort = DEFAULT_PORT;
102 pnfUsername = DEFAULT_USERNAME;
103 pnfPasswd = DEFAULT_PASSWORD;
107 "PNF Fields - ID - {} : IP Address - {} : Protocol - {} : TLS Key ID - {} : User - {} : Port - {}",
108 pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername, pnfCommPort);
110 String baseUrl = getBaseUrl();
111 String sdnrUser = getSDNRUser();
112 String sdnrPasswd = getSDNRPasswd();
114 PNFMountPointClient mountpointClient = getPNFMountPointClient(baseUrl);
115 LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
116 mountpointClient.setAuthorization(sdnrUser, sdnrPasswd);
118 if ((null != pnfId) && null != pnfIPAddress && (null != pnfCommProtocol) && (null != pnfUsername)
119 && (null != pnfCommPort)) {
120 mountpointClient.pnfMountPointCreate(pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername,
121 pnfPasswd, pnfCommPort);
124 "One of the mandatory fields has a null value - pnfId = {} : pnfIPAddress = {} : pnfCommProtocol = {} : pnfUsername {} : "
126 pnfId, pnfIPAddress, pnfCommProtocol, pnfUsername, pnfCommPort,
127 "- not invoking mountpoint creation");
129 } catch (IOException e) {
130 LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}",
135 private String getPNFIPAddress(JsonNode dmaapMessageRootNode) {
136 String ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV6IpAddress").textValue();
137 if (ipAddress != null && ipAddress != "")
140 ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue();
141 if (ipAddress != null && ipAddress != "")
147 public String getBaseUrl() {
148 return generalConfig.getBaseUrl();
151 public String getSDNRUser() {
152 return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
155 public String getSDNRPasswd() {
156 return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
159 private PNFMountPointClient getPNFMountPointClient(String baseUrl) {
160 return new PNFMountPointClient(baseUrl);