2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
7 * =================================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software distributed under the License
14 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15 * or implied. See the License for the specific language governing permissions and limitations under
17 * ============LICENSE_END==========================================================================
20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
22 import com.fasterxml.jackson.databind.JsonNode;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import java.io.IOException;
25 import java.time.Instant;
26 import java.time.ZoneId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
34 private static final Logger LOG = LoggerFactory.getLogger(DMaaPFaultVESMsgConsumer.class);
36 private static final String DEFAULT_SDNRUSER = "admin";
37 private static final String DEFAULT_SDNRPASSWD = "admin";
39 private final GeneralConfig generalConfig;
41 public DMaaPFaultVESMsgConsumer(GeneralConfig generalConfig) {
42 this.generalConfig = generalConfig;
46 public void processMsg(String msg) throws Exception {
48 String faultOccurrenceTime;
54 String reportingEntityName;
55 ObjectMapper oMapper = new ObjectMapper();
56 JsonNode dmaapMessageRootNode;
58 LOG.info("Fault VES Message is - {}", msg);
60 dmaapMessageRootNode = oMapper.readTree(msg);
61 reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue();
62 if (reportingEntityName.equals("ONAP SDN-R")) {
64 "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message");
68 vesDomain = dmaapMessageRootNode.at("/event/commonEventHeader/domain").textValue();
69 if (!vesDomain.equalsIgnoreCase("fault")) {
70 LOG.warn("Received {} domain VES Message in DMaaP Fault topic, ignoring it", vesDomain);
73 faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
74 faultOccurrenceTime = Instant
76 dmaapMessageRootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000)
77 .atZone(ZoneId.of("Z")).toString();
78 faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue();
79 faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue();
80 faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue();
81 faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue();
83 if (faultSeverity.equalsIgnoreCase("critical")) {
84 faultSeverity = SeverityType.Critical.toString();
85 } else if (faultSeverity.equalsIgnoreCase("major")) {
86 faultSeverity = SeverityType.Major.toString();
87 } else if (faultSeverity.equalsIgnoreCase("minor")) {
88 faultSeverity = SeverityType.Minor.toString();
89 } else if (faultSeverity.equalsIgnoreCase("warning")) {
90 faultSeverity = SeverityType.Warning.toString();
91 } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) {
92 faultSeverity = SeverityType.NonAlarmed.toString();
94 faultSeverity = SeverityType.NonAlarmed.toString();
97 String baseUrl = getBaseUrl();
98 String sdnrUser = getSDNRUser();
99 String sdnrPasswd = getSDNRPasswd();
101 Map<String, String> payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId,
102 Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity);
104 FaultNotificationClient faultClient = new FaultNotificationClient(baseUrl);
105 LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
106 faultClient.setAuthorization(sdnrUser, sdnrPasswd);
107 String message = faultClient.prepareMessageFromPayloadMap(payloadMapMessage);
108 faultClient.sendNotification(message);
110 } catch (IOException e) {
111 LOG.info("Cannot parse json object ");
112 throw new Exception("Cannot parse json object", e);
116 public String getBaseUrl() {
117 return generalConfig.getBaseUrl();
120 public String getSDNRUser() {
121 return generalConfig.getSDNRUser() != null ? generalConfig.getSDNRUser() : DEFAULT_SDNRUSER;
124 public String getSDNRPasswd() {
125 return generalConfig.getSDNRPasswd() != null ? generalConfig.getSDNRPasswd() : DEFAULT_SDNRPASSWD;
128 public FaultNotificationClient getFaultNotificationClient(String baseUrl) {
129 return new FaultNotificationClient(baseUrl);