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
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==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
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;
42 public class ORanFaultNotificationListener implements ORanFmListener {
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;
51 public ORanFaultNotificationListener(NetconfBindingAccessor netconfAccessor, DataProvider databaseService,
52 VESCollectorService vesCollectorService) {
53 this.netconfAccessor = netconfAccessor;
54 this.databaseService = databaseService;
55 this.vesCollectorService = vesCollectorService;
59 public void onAlarmNotif(AlarmNotif notification) {
61 log.info("onAlarmNotif {}", notification.getClass().getSimpleName());
63 DateAndTime eventTime = notification.getEventTime();
65 Instant eventTimeInstant = Instant.parse(eventTime.getValue());
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);
76 databaseService.updateFaultCurrent(faultCurrent.build());
78 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
80 this.mapper = new ORanFaultToVESFaultMapper(netconfAccessor.getNodeId(), vesCollectorService,
81 AlarmNotif.class.getSimpleName());
83 VESCommonEventHeaderPOJO header =
84 mapper.mapCommonEventHeader(notification, eventTimeInstant, counter);
85 VESFaultFieldsPOJO body = mapper.mapFaultFields(notification);
86 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
88 } catch (JsonProcessingException | DateTimeParseException e) {
89 log.debug("Can not convert event into VES message {}", notification, e);
94 private SeverityType getSeverityType(FaultSeverity faultSeverity) {
95 String severity = faultSeverity.getName();
98 return SeverityType.Critical;
100 return SeverityType.Major;
102 return SeverityType.Minor;
104 return SeverityType.Warning;
106 return SeverityType.NonAlarmed;