ee9d0220afc4cd2bb1d24c1ee2922403630a861d
[ccsdk/features.git] /
1 /*
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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
16  * the License.
17  * ============LICENSE_END==========================================================================
18  */
19
20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21
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;
27 import java.util.Map;
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;
31
32 public class DMaaPFaultVESMsgConsumer extends DMaaPVESMsgConsumerImpl {
33
34     private static final Logger LOG = LoggerFactory.getLogger(DMaaPFaultVESMsgConsumer.class);
35
36     public DMaaPFaultVESMsgConsumer(GeneralConfig generalConfig) {
37         super(generalConfig);
38     }
39
40     @Override
41     public void processMsg(String msg) throws Exception {
42         String faultNodeId;
43         String faultOccurrenceTime;
44         String faultObjectId;
45         String faultReason;
46         String faultSeverity;
47         String vesDomain;
48         int faultSequence;
49         String reportingEntityName;
50         ObjectMapper oMapper = new ObjectMapper();
51         JsonNode dmaapMessageRootNode;
52
53         LOG.info("Fault VES Message is - {}", msg);
54         try {
55             dmaapMessageRootNode = oMapper.readTree(msg);
56             reportingEntityName = dmaapMessageRootNode.at("/event/commonEventHeader/reportingEntityName").textValue();
57             if (reportingEntityName.equals("ONAP SDN-R")) {
58                 LOG.info(
59                         "VES PNF Registration message generated by SDNR, hence no need to process any further; Ignoring the received message");
60                 return;
61             }
62
63             vesDomain = dmaapMessageRootNode.at("/event/commonEventHeader/domain").textValue();
64             if (!vesDomain.equalsIgnoreCase("fault")) {
65                 LOG.warn("Received {} domain VES Message in DMaaP Fault topic, ignoring it", vesDomain);
66                 return;
67             }
68             faultNodeId = dmaapMessageRootNode.at("/event/commonEventHeader/sourceName").textValue();
69             faultOccurrenceTime = Instant
70                     .ofEpochMilli(
71                             dmaapMessageRootNode.at("/event/commonEventHeader/startEpochMicrosec").longValue() / 1000)
72                     .atZone(ZoneId.of("Z")).toString();
73             faultObjectId = dmaapMessageRootNode.at("/event/faultFields/alarmInterfaceA").textValue();
74             faultReason = dmaapMessageRootNode.at("/event/faultFields/specificProblem").textValue();
75             faultSeverity = dmaapMessageRootNode.at("/event/faultFields/eventSeverity").textValue();
76             faultSequence = dmaapMessageRootNode.at("/event/commonEventHeader/sequence").intValue();
77
78             if (faultSeverity.equalsIgnoreCase("critical")) {
79                 faultSeverity = SeverityType.Critical.toString();
80             } else if (faultSeverity.equalsIgnoreCase("major")) {
81                 faultSeverity = SeverityType.Major.toString();
82             } else if (faultSeverity.equalsIgnoreCase("minor")) {
83                 faultSeverity = SeverityType.Minor.toString();
84             } else if (faultSeverity.equalsIgnoreCase("warning")) {
85                 faultSeverity = SeverityType.Warning.toString();
86             } else if (faultSeverity.equalsIgnoreCase("nonalarmed")) {
87                 faultSeverity = SeverityType.NonAlarmed.toString();
88             } else {
89                 faultSeverity = SeverityType.NonAlarmed.toString();
90             }
91
92             String baseUrl = getBaseUrl();
93             String sdnrUser = getSDNRUser();
94             String sdnrPasswd = getSDNRPasswd();
95
96             Map<String, String> payloadMapMessage = FaultNotificationClient.createFaultNotificationPayloadMap(faultNodeId,
97                     Integer.toString(faultSequence), faultOccurrenceTime, faultObjectId, faultReason, faultSeverity);
98
99             FaultNotificationClient faultClient = new FaultNotificationClient(baseUrl);
100             LOG.debug("Setting RESTConf Authorization values - {} : {}", sdnrUser, sdnrPasswd);
101             faultClient.setAuthorization(sdnrUser, sdnrPasswd);
102             String message = faultClient.prepareMessageFromPayloadMap(payloadMapMessage);
103             faultClient.sendNotification(message);
104
105         } catch (IOException e) {
106             LOG.info("Cannot parse json object ");
107             throw new Exception("Cannot parse json object", e);
108         }
109     }
110
111 }