6f5de9677ae24403d24808027e6c7fab9e8a51d3
[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  * =================================================================================================
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
19
20 import com.fasterxml.jackson.core.JsonProcessingException;
21 import java.time.Instant;
22 import java.time.format.DateTimeParseException;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO;
28 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
30 import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.Alarm.FaultSeverity;
31 import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.AlarmNotif;
32 import org.opendaylight.yang.gen.v1.urn.o.ran.fm._1._0.rev190204.ORanFmListener;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  * @author herbert
40  *
41  */
42 public class ORanFaultNotificationListener implements ORanFmListener {
43
44     private static final Logger log = LoggerFactory.getLogger(ORanFaultNotificationListener.class);
45     private NetconfBindingAccessor netconfAccessor;
46     private DataProvider databaseService;
47     private VESCollectorService vesCollectorService;
48     private int counter = 0;
49     private ORanFaultToVESFaultMapper mapper = null;
50
51     public ORanFaultNotificationListener(NetconfBindingAccessor netconfAccessor, DataProvider databaseService,
52             VESCollectorService vesCollectorService) {
53         this.netconfAccessor = netconfAccessor;
54         this.databaseService = databaseService;
55         this.vesCollectorService = vesCollectorService;
56     }
57
58     @Override
59     public void onAlarmNotif(AlarmNotif notification) {
60
61         log.info("onAlarmNotif {}", notification.getClass().getSimpleName());
62         @Nullable
63         DateAndTime eventTime = notification.getEventTime();
64         try {
65             Instant eventTimeInstant = Instant.parse(eventTime.getValue());
66
67             FaultcurrentBuilder faultCurrent = new FaultcurrentBuilder();
68             faultCurrent.setNodeId(netconfAccessor.getNodeId().getValue());
69             faultCurrent.setObjectId(notification.getFaultSource());
70             faultCurrent.setProblem(notification.getFaultText());
71             faultCurrent.setSeverity(getSeverityType(notification.getFaultSeverity()));
72             faultCurrent.setCounter(Integer.valueOf(counter++));
73             faultCurrent.setId(notification.getFaultId().toString());
74             faultCurrent.setTimestamp(eventTime);
75
76             databaseService.updateFaultCurrent(faultCurrent.build());
77
78             if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
79                 if (mapper == null) {
80                     this.mapper = new ORanFaultToVESFaultMapper(netconfAccessor.getNodeId(), vesCollectorService,
81                             AlarmNotif.class.getSimpleName());
82                 }
83                 VESCommonEventHeaderPOJO header =
84                         mapper.mapCommonEventHeader(notification, eventTimeInstant, counter);
85                 VESFaultFieldsPOJO body = mapper.mapFaultFields(notification);
86                 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
87             }
88         } catch (JsonProcessingException | DateTimeParseException e) {
89             log.debug("Can not convert event into VES message {}", notification, e);
90         }
91
92     }
93
94     private SeverityType getSeverityType(FaultSeverity faultSeverity) {
95         String severity = faultSeverity.getName();
96         switch (severity) {
97             case "CRITICAL":
98                 return SeverityType.Critical;
99             case "MAJOR":
100                 return SeverityType.Major;
101             case "MINOR":
102                 return SeverityType.Minor;
103             case "WARNING":
104                 return SeverityType.Warning;
105             default:
106                 return SeverityType.NonAlarmed;
107         }
108     }
109
110 }