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);
51 String pnfCommProtocol;
55 String pnfKeyId = null;
59 String pnfPasswd = null;
60 ObjectMapper oMapper = new ObjectMapper();
61 JsonNode dmaapMessageRootNode;
63 dmaapMessageRootNode = oMapper.readTree(msg);
64 pnfId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
65 pnfIPAddress = getPNFIPAddress(dmaapMessageRootNode);
67 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue();
68 pnfCommPort = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue();
69 if (pnfCommProtocol != null) {
70 if (pnfCommProtocol.equalsIgnoreCase("TLS")) {
71 // Read username and keyId
73 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue();
74 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
76 } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) {
77 // Read username and password
78 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
80 pnfPasswd = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password")
83 // log warning - Unknown protocol
84 LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}",
85 pnfCommProtocol, ". Defaulting to SSH");
86 pnfCommProtocol = DEFAULT_PROTOCOL;
87 pnfCommPort = DEFAULT_PORT;
88 pnfUsername = DEFAULT_USERNAME;
89 pnfPasswd = DEFAULT_PASSWORD;
92 LOG.warn("Protocol not specified in VES message, Defaulting to SSH");
93 pnfCommProtocol = DEFAULT_PROTOCOL;
94 pnfCommPort = DEFAULT_PORT;
95 pnfUsername = DEFAULT_USERNAME;
96 pnfPasswd = DEFAULT_PASSWORD;
100 "PNF Fields - ID - {} : IP Address - {} : Protocol - {} : TLS Key ID - {} : User - {} : Port - {}",
101 pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername, pnfCommPort);
103 String baseUrl = getBaseUrl();
104 String sdnrUser = getSDNRUser();
105 String sdnrPasswd = getSDNRPasswd();
107 PNFMountPointClient mountpointClient = getPNFMountPointClient(baseUrl);
108 LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
109 mountpointClient.setAuthorization(sdnrUser, sdnrPasswd);
111 if ((null != pnfId) && null != pnfIPAddress && (null != pnfCommProtocol) && (null != pnfUsername)
112 && (null != pnfCommPort)) {
113 mountpointClient.pnfMountPointCreate(pnfId, pnfIPAddress, pnfCommProtocol, pnfKeyId, pnfUsername,
114 pnfPasswd, pnfCommPort);
117 "One of the mandatory fields has a null value - pnfId = {} : pnfIPAddress = {} : pnfCommProtocol = {} : pnfUsername {} : "
119 pnfId, pnfIPAddress, pnfCommProtocol, pnfUsername, pnfCommPort,
120 "- not invoking mountpoint creation");
122 } catch (IOException e) {
123 LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}",
128 private String getPNFIPAddress(JsonNode dmaapMessageRootNode) {
129 String ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV6IpAddress").textValue();
130 if (ipAddress != null && ipAddress != "")
133 ipAddress = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue();
134 if (ipAddress != null && ipAddress != "")
140 public String getBaseUrl() {
141 return generalConfig.getBaseUrl();
144 public String getSDNRUser() {
145 return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
148 public String getSDNRPasswd() {
149 return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
152 private PNFMountPointClient getPNFMountPointClient(String baseUrl) {
153 return new PNFMountPointClient(baseUrl);