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 java.io.IOException;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.fasterxml.jackson.databind.JsonNode;
27 import com.fasterxml.jackson.databind.ObjectMapper;
29 public class DMaaPPNFRegVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
31 private static final Logger LOG = LoggerFactory.getLogger(DMaaPPNFRegVESMsgConsumer.class);
32 private static final String DEFAULT_PROTOCOL = "SSH";
33 private static final String DEFAULT_PORT = "17830";
34 private static final String DEFAULT_USERNAME = "netconf";
35 private static final String DEFAULT_PASSWORD = "netconf";
36 private static final String DEFAULT_SDNRUSER = "admin";
37 private static final String DEFAULT_SDNRPASSWD = "admin";
40 public void processMsg(String msg) {
41 LOG.debug("Message from DMaaP topic is - {} ", msg);
43 String pnfIPv4Address;
44 String pnfCommProtocol;
46 String pnfKeyId = null;
48 String pnfPasswd = null;
49 ObjectMapper oMapper = new ObjectMapper();
50 JsonNode dmaapMessageRootNode;
52 dmaapMessageRootNode = oMapper.readTree(msg);
53 pnfId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
54 pnfIPv4Address = dmaapMessageRootNode.at("/event/pnfRegistrationFields/oamV4IpAddress").textValue();
56 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue();
57 pnfCommPort = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue();
58 if (pnfCommProtocol != null) {
59 if (pnfCommProtocol.equalsIgnoreCase("TLS")) {
60 // Read username and keyId
62 dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue();
63 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
65 } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) {
66 // Read username and password
67 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username")
69 pnfPasswd = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password")
72 // log warning - Unknown protocol
73 LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}",
74 pnfCommProtocol, ". Defaulting to SSH");
75 pnfCommProtocol = DEFAULT_PROTOCOL;
76 pnfCommPort = DEFAULT_PORT;
77 pnfUsername = DEFAULT_USERNAME;
78 pnfPasswd = DEFAULT_PASSWORD;
81 LOG.warn("Protocol not specified in VES message, Defaulting to SSH");
82 pnfCommProtocol = DEFAULT_PROTOCOL;
83 pnfCommPort = DEFAULT_PORT;
84 pnfUsername = DEFAULT_USERNAME;
85 pnfPasswd = DEFAULT_PASSWORD;
88 LOG.debug("PNF Fields - {} : {} : {} : {} : {} : {} : {}", pnfId, pnfIPv4Address, pnfCommProtocol, pnfKeyId,
89 pnfUsername, pnfPasswd, pnfCommPort);
91 String baseUrl = getBaseUrl();
92 String sdnrUser = getSDNRUser();
93 String sdnrPasswd = getSDNRPasswd();
95 PNFMountPointClient mountpointClient = getPNFMountPointClient(baseUrl);
96 LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
97 mountpointClient.setAuthorization(sdnrUser, sdnrPasswd);
99 mountpointClient.pnfMountPointCreate(pnfId, pnfIPv4Address, pnfCommProtocol, pnfKeyId, pnfUsername,
100 pnfPasswd, pnfCommPort);
101 } catch (IOException e) {
102 LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}",
107 public String getBaseUrl() {
108 return GeneralConfig.getBaseUrl();
111 public String getSDNRUser() {
112 return GeneralConfig.getSDNRUser() != null ? GeneralConfig.getSDNRUser() : DEFAULT_SDNRUSER;
115 public String getSDNRPasswd() {
116 return GeneralConfig.getSDNRPasswd() != null ? GeneralConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
119 public PNFMountPointClient getPNFMountPointClient(String baseUrl) {
120 return new PNFMountPointClient(baseUrl);