70bbfa5c03949fbcbcd33dbf3960ffd4f830a77c
[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.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;
41
42 /**
43  * @author Shabnam Sultana
44  *
45  *         Class to read the initial alarms at the time of device registration
46  *
47  **/
48
49 public class InitialDeviceAlarmReader {
50     // variables
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;
56     // end of variables
57
58     // constructors
59     public InitialDeviceAlarmReader(NetconfAccessor accessor, DeviceManagerServiceProvider serviceProvider) {
60         this.netConfAccesor = accessor;
61         this.faultEventListener = serviceProvider.getFaultService();
62         this.dataProvider = serviceProvider.getDataProvider();
63     }
64     // end of constructors
65
66     // protected methods
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()));
78                     count = count + 1;
79                 }
80                 return faultData;
81             }
82         }
83         return faultData;
84     }
85
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);
92             }
93         }
94     }
95
96     // Use the FaultService for Alarm notifications
97     protected void faultService() {
98         this.faultEventListener.initCurrentProblemStatus(this.netConfAccesor.getNodeId(), writeFaultData());
99         writeAlarmLog(writeFaultData());
100     }
101     // end of protected methods
102
103     // private methods
104
105     // Read Alarm Data
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();
110
111         ActiveAlarmList alarmData = accessor.getTransactionUtils().readData(accessor.getDataBroker(),
112                 LogicalDatastoreType.OPERATIONAL, alarmDataIid);
113
114         log.info("AlarmData {}", alarmData.toString());
115         return alarmData;
116     }
117
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());
122
123         switch (severity.getName()) {
124             case ("warning"):
125                 severityType = SeverityType.Warning;
126                 break;
127             case ("major"):
128                 severityType = SeverityType.Major;
129                 break;
130             case ("minor"):
131                 severityType = SeverityType.Minor;
132                 break;
133             case ("clear"):
134                 severityType = SeverityType.NonAlarmed;
135                 break;
136             case ("critical"):
137                 severityType = SeverityType.Critical;
138                 break;
139             case ("indeterminate"):
140                 severityType = SeverityType.Critical;
141                 break;
142             default:
143                 severityType = SeverityType.Critical;
144                 break;
145
146         }
147         return severityType;
148
149     }
150     // end of private methods
151
152
153
154 }