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.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
29 private static final Logger LOG = LoggerFactory.getLogger(DMaaPPNFRegVESMsgConsumer.class);
30 private static final String DEFAULT_PROTOCOL = "SSH";
31 private static final String DEFAULT_PORT = "17830";
32 private static final String DEFAULT_USERNAME = "netconf";
33 private static final String DEFAULT_PASSWORD = "netconf";
34 private static final String DEFAULT_SDNRUSER = "admin";
35 private static final String DEFAULT_SDNRPASSWD = "admin";
37 private final GeneralConfig generalConfig;
39 public DMaaPPNFRegVESMsgConsumer(GeneralConfig generalConfig) {
40 this.generalConfig = generalConfig;
44 public void processMsg(String msg) {
45 LOG.debug("Message from DMaaP topic is - {} ", msg);
47 String pnfIPv4Address;
48 String pnfCommProtocol;
50 String pnfKeyId = null;
52 String pnfPasswd = null;
53 ObjectMapper oMapper = new ObjectMapper();
54 JsonNode dmaapMessageRootNode;
56 dmaapMessageRootNode = oMapper.readTree(msg);
57 pnfId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
58 pnfIPv4Address = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue();
60 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue();
61 pnfCommPort = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue();
62 if (pnfCommProtocol != null) {
63 if (pnfCommProtocol.equalsIgnoreCase("TLS")) {
64 // Read username and keyId
66 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue();
67 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
69 } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) {
70 // Read username and password
71 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
73 pnfPasswd = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password")
76 // log warning - Unknown protocol
77 LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}",
78 pnfCommProtocol, ". Defaulting to SSH");
79 pnfCommProtocol = DEFAULT_PROTOCOL;
80 pnfCommPort = DEFAULT_PORT;
81 pnfUsername = DEFAULT_USERNAME;
82 pnfPasswd = DEFAULT_PASSWORD;
85 LOG.warn("Protocol not specified in VES message, Defaulting to SSH");
86 pnfCommProtocol = DEFAULT_PROTOCOL;
87 pnfCommPort = DEFAULT_PORT;
88 pnfUsername = DEFAULT_USERNAME;
89 pnfPasswd = DEFAULT_PASSWORD;
92 LOG.debug("PNF Fields - {} : {} : {} : {} : {} : {} : {}", pnfId, pnfIPv4Address, pnfCommProtocol, pnfKeyId,
93 pnfUsername, pnfPasswd, pnfCommPort);
95 String baseUrl = getBaseUrl();
96 String sdnrUser = getSDNRUser();
97 String sdnrPasswd = getSDNRPasswd();
99 PNFMountPointClient mountpointClient = getPNFMountPointClient(baseUrl);
100 LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
101 mountpointClient.setAuthorization(sdnrUser, sdnrPasswd);
103 if ((null != pnfId) && (null != pnfIPv4Address) && (null != pnfCommProtocol) && (null != pnfUsername)
104 && (null != pnfCommPort)) {
105 mountpointClient.pnfMountPointCreate(pnfId, pnfIPv4Address, pnfCommProtocol, pnfKeyId, pnfUsername,
106 pnfPasswd, pnfCommPort);
108 LOG.warn("One of the mandatory fields has a null value - pnfId = {} : pnfIPv4Address = {} : pnfCommProtocol = {} : pnfUsername {} : "
109 + "pnfCommPort {}", pnfId, pnfIPv4Address, pnfCommProtocol, pnfUsername, pnfCommPort, "- not invoking mountpoint creation");
111 } catch (IOException e) {
112 LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}",
117 public String getBaseUrl() {
118 return generalConfig.getBaseUrl();
121 public String getSDNRUser() {
122 return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
125 public String getSDNRPasswd() {
126 return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
129 public PNFMountPointClient getPNFMountPointClient(String baseUrl) {
130 return new PNFMountPointClient(baseUrl);