2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl;
24 import java.util.List;
25 import org.eclipse.jdt.annotation.NonNull;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
31 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Faultlog;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * @author Shabnam Sultana
45 * Class to read the initial alarms at the time of device registration
49 public class InitialDeviceAlarmReader {
51 private Integer count = 1;
52 private static final Logger log = LoggerFactory.getLogger(OrgOpenroadmAlarmListener.class);
53 private final NetconfAccessor netConfAccesor;
54 private final @NonNull FaultService faultEventListener;
55 private final DataProvider dataProvider;
59 public InitialDeviceAlarmReader(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) {
60 this.netConfAccesor = accessor;
61 this.faultEventListener = serviceProvider.getFaultService();
62 this.dataProvider = serviceProvider.getDataProvider();
64 // end of constructors
67 // Mapping the alarm data with the fault data
68 protected FaultData writeFaultData() {
69 FaultData faultData = new FaultData();
70 if (this.getActiveAlarmList(this.netConfAccesor).getActiveAlarms() != null) {
71 List<ActiveAlarms> activeAlarms = this.getActiveAlarmList(this.netConfAccesor).getActiveAlarms();
72 if (!activeAlarms.isEmpty()) {
73 for (ActiveAlarms activeAlarm : activeAlarms) {
74 faultData.add(this.netConfAccesor.getNodeId(), this.count, activeAlarm.getRaiseTime(),
75 activeAlarm.getResource().getDevice().getNodeId().getValue(),
76 activeAlarm.getProbableCause().getCause().getName(),
77 checkSeverityValue(activeAlarm.getSeverity()));
86 // Write into the FaultLog
87 protected void writeAlarmLog(FaultData faultData) {
88 if (faultData != null) {
89 List<Faultlog> faultLog = faultData.getProblemList();
90 for (Faultlog fe : faultLog) {
91 this.dataProvider.writeFaultLog(fe);
96 // Use the FaultService for Alarm notifications
97 protected void faultService() {
98 this.faultEventListener.initCurrentProblemStatus(this.netConfAccesor.getNodeId(), writeFaultData());
99 writeAlarmLog(writeFaultData());
101 // end of protected methods
106 private ActiveAlarmList getActiveAlarmList(NetconfAccessor accessor) {
107 final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class;
108 log.info("Get Alarm data for element {}", accessor.getNodeId().getValue());
109 InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build();
111 ActiveAlarmList alarmData = accessor.getTransactionUtils().readData(accessor.getDataBroker(),
112 LogicalDatastoreType.OPERATIONAL, alarmDataIid);
114 log.info("AlarmData {}", alarmData.toString());
118 // Mapping Severity of AlarmNotification to SeverityType of FaultLog
119 private SeverityType checkSeverityValue(Severity severity) {
120 SeverityType severityType = null;
121 log.info("Device Severity: {}", severity.getName());
123 switch (severity.getName()) {
125 severityType = SeverityType.Warning;
128 severityType = SeverityType.Major;
131 severityType = SeverityType.Minor;
134 severityType = SeverityType.NonAlarmed;
137 severityType = SeverityType.Critical;
139 case ("indeterminate"):
140 severityType = SeverityType.Critical;
143 severityType = SeverityType.Critical;
150 // end of private methods