1 /*******************************************************************************
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==========================================================================
17 ******************************************************************************/
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();
55 pnfCommProtocol = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/protocol").textValue();
56 pnfCommPort = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/oamPort").textValue();
57 if (pnfCommProtocol != null) {
58 if (pnfCommProtocol.equalsIgnoreCase("TLS")) {
59 // Read username and keyId
60 pnfKeyId = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/keyId").textValue();
61 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username").textValue();
62 } else if (pnfCommProtocol.equalsIgnoreCase("SSH")) {
63 // Read username and password
64 pnfUsername = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/username").textValue();
65 pnfPasswd = dmaapMessageRootNode.at("/event/pnfRegistrationFields/additionalFields/password").textValue();
67 // log warning - Unknown protocol
68 LOG.warn("Only SSH and TLS protocols supported. Protocol specified in VES message is - {}",pnfCommProtocol,". Defaulting to SSH");
69 pnfCommProtocol = DEFAULT_PROTOCOL;
70 pnfCommPort = DEFAULT_PORT;
71 pnfUsername = DEFAULT_USERNAME;
72 pnfPasswd = DEFAULT_PASSWORD;
75 LOG.warn("Protocol not specified in VES message, Defaulting to SSH");
76 pnfCommProtocol = DEFAULT_PROTOCOL;
77 pnfCommPort = DEFAULT_PORT;
78 pnfUsername = DEFAULT_USERNAME;
79 pnfPasswd = DEFAULT_PASSWORD;
82 LOG.debug("PNF Fields - {} : {} : {} : {} : {} : {} : {}",pnfId,pnfIPv4Address,pnfCommProtocol,pnfKeyId,pnfUsername,pnfPasswd,pnfCommPort);
84 String baseUrl = getBaseUrl();
85 String sdnrUser = getSDNRUser();
86 String sdnrPasswd = getSDNRPasswd();
88 PNFMountPointClient mountpointClient = getPNFMountPointClient(baseUrl);
89 LOG.debug("Setting RESTConf Authorization values - {} : {}",sdnrUser,sdnrPasswd);
90 mountpointClient.setAuthorization(sdnrUser, sdnrPasswd);
92 mountpointClient.pnfMountPointCreate(pnfId,
94 pnfCommProtocol, pnfKeyId,
95 pnfUsername, pnfPasswd,
97 } catch (IOException e) {
98 LOG.info("Cannot parse json object, ignoring the received PNF Registration VES Message. Reason: {}",e.getMessage());
102 public String getBaseUrl() {
103 return GeneralConfig.getBaseUrl();
106 public String getSDNRUser() {
107 return GeneralConfig.getSDNRUser()!= null?GeneralConfig.getSDNRUser():DEFAULT_SDNRUSER;
110 public String getSDNRPasswd() {
111 return GeneralConfig.getSDNRPasswd()!= null?GeneralConfig.getSDNRPasswd():DEFAULT_SDNRPASSWD;
114 public PNFMountPointClient getPNFMountPointClient(String baseUrl) {
115 return new PNFMountPointClient(baseUrl);