f1b3821b826c6e9bc43dde18f209d9b16ec91485
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.openroadm.impl;
23
24 import java.util.Collection;
25 import java.util.List;
26 import org.eclipse.jdt.annotation.NonNull;
27 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
33 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.ActiveAlarmList;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.OrgOpenroadmAlarmListener;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.Severity;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev191129.active.alarm.list.ActiveAlarms;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 /**
45  * @author Shabnam Sultana
46  *
47  *         Class to read the initial alarms at the time of device registration
48  *
49  **/
50
51 public class InitialDeviceAlarmReader {
52     // variables
53     private Integer count = 1;
54     private static final Logger log = LoggerFactory.getLogger(OrgOpenroadmAlarmListener.class);
55     private final NetconfAccessor netConfAccesor;
56     private final @NonNull FaultService faultEventListener;
57     private final DataProvider dataProvider;
58     // end of variables
59
60     // constructors
61     public InitialDeviceAlarmReader(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) {
62         this.netConfAccesor = accessor;
63         this.faultEventListener = serviceProvider.getFaultService();
64         this.dataProvider = serviceProvider.getDataProvider();
65     }
66     // end of constructors
67
68     // protected methods
69     // Mapping the alarm data with the fault data
70     protected FaultData writeFaultData() {
71         FaultData faultData = new FaultData();
72         if (this.getActiveAlarmList(this.netConfAccesor).getActiveAlarms() != null) {
73             Collection<ActiveAlarms> activeAlarms = YangHelper.getCollection(this.getActiveAlarmList(this.netConfAccesor).getActiveAlarms());
74             if (!activeAlarms.isEmpty()) {
75                 for (ActiveAlarms activeAlarm : activeAlarms) {
76                     faultData.add(this.netConfAccesor.getNodeId(), this.count, activeAlarm.getRaiseTime(),
77                             activeAlarm.getResource().getDevice().getNodeId().getValue(),
78                             activeAlarm.getProbableCause().getCause().getName(),
79                             checkSeverityValue(activeAlarm.getSeverity()));
80                     count = count + 1;
81                 }
82                 return faultData;
83             }
84         }
85         return faultData;
86     }
87
88     // Write into the FaultLog
89     protected void writeAlarmLog(FaultData faultData) {
90         if (faultData != null) {
91             List<Faultlog> faultLog = faultData.getProblemList();
92             for (Faultlog fe : faultLog) {
93                 this.dataProvider.writeFaultLog(fe);
94             }
95         }
96     }
97
98     // Use the FaultService for Alarm notifications
99     protected void faultService() {
100         this.faultEventListener.initCurrentProblemStatus(this.netConfAccesor.getNodeId(), writeFaultData());
101         writeAlarmLog(writeFaultData());
102     }
103     // end of protected methods
104
105     // private methods
106
107     // Read Alarm Data
108     private ActiveAlarmList getActiveAlarmList(NetconfAccessor accessor) {
109         final Class<ActiveAlarmList> classAlarm = ActiveAlarmList.class;
110         log.info("Get Alarm data for element {}", accessor.getNodeId().getValue());
111         InstanceIdentifier<ActiveAlarmList> alarmDataIid = InstanceIdentifier.builder(classAlarm).build();
112
113         ActiveAlarmList alarmData = accessor.getTransactionUtils().readData(accessor.getDataBroker(),
114                 LogicalDatastoreType.OPERATIONAL, alarmDataIid);
115
116         log.info("AlarmData {}", alarmData.toString());
117         return alarmData;
118     }
119
120     // Mapping Severity of AlarmNotification to SeverityType of FaultLog
121     private SeverityType checkSeverityValue(Severity severity) {
122         SeverityType severityType = null;
123         log.info("Device Severity: {}", severity.getName());
124
125         switch (severity.getName()) {
126             case ("warning"):
127                 severityType = SeverityType.Warning;
128                 break;
129             case ("major"):
130                 severityType = SeverityType.Major;
131                 break;
132             case ("minor"):
133                 severityType = SeverityType.Minor;
134                 break;
135             case ("clear"):
136                 severityType = SeverityType.NonAlarmed;
137                 break;
138             case ("critical"):
139                 severityType = SeverityType.Critical;
140                 break;
141             case ("indeterminate"):
142                 severityType = SeverityType.Critical;
143                 break;
144             default:
145                 severityType = SeverityType.Critical;
146                 break;
147
148         }
149         return severityType;
150
151     }
152     // end of private methods
153
154
155
156 }