Improve Websocket notification interface
[ccsdk/features.git] / sdnr / wt / devicemanager-onap / onf12 / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / onf / ifpac / microwave / WrapperMicrowaveModelRev181010.java
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.onf.ifpac.microwave;
19
20
21
22 import java.lang.reflect.Constructor;
23 import java.lang.reflect.InvocationTargetException;
24 import java.util.Collection;
25 import java.util.Optional;
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.devicemanager.onf.ifpac.microwave.pm.PerformanceDataAirInterface181010Builder;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.notifications.NotificationWorker;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.util.ONFLayerProtocolName;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.PerformanceDataLtp;
36 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
37 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils;
38 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
39 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
40 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
41 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
42 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.AirInterfaceCurrentProblemTypeG;
43 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.AirInterfaceDiversityCurrentProblemTypeG;
44 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.AirInterfaceHistoricalPerformanceTypeG;
45 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.AttributeValueChangedNotification;
46 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ContainerCurrentProblemTypeG;
47 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ContainerHistoricalPerformanceTypeG;
48 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MicrowaveModelListener;
49 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwAirInterfaceDiversityPac;
50 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwAirInterfaceDiversityPacKey;
51 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwAirInterfacePac;
52 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwAirInterfacePacKey;
53 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwEthernetContainerPac;
54 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwEthernetContainerPacKey;
55 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwHybridMwStructurePac;
56 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwHybridMwStructurePacKey;
57 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwPureEthernetStructurePac;
58 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwPureEthernetStructurePacKey;
59 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwTdmContainerPac;
60 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.MwTdmContainerPacKey;
61 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ObjectCreationNotification;
62 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ObjectDeletionNotification;
63 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ProblemNotification;
64 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.SeverityType;
65 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.StructureCurrentProblemTypeG;
66 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.air._interface.diversity.pac.AirInterfaceDiversityCurrentProblems;
67 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.air._interface.pac.AirInterfaceConfiguration;
68 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.air._interface.pac.AirInterfaceCurrentProblems;
69 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.air._interface.pac.AirInterfaceHistoricalPerformances;
70 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.ethernet.container.pac.EthernetContainerCurrentProblems;
71 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.ethernet.container.pac.EthernetContainerHistoricalPerformances;
72 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.hybrid.mw.structure.pac.HybridMwStructureCurrentProblems;
73 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.pure.ethernet.structure.pac.PureEthernetStructureCurrentProblems;
74 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.mw.tdm.container.pac.TdmContainerCurrentProblems;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType;
80 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
81 import org.opendaylight.yangtools.yang.binding.NotificationListener;
82 import org.opendaylight.yangtools.yang.common.QName;
83 import org.slf4j.Logger;
84 import org.slf4j.LoggerFactory;
85
86
87 public class WrapperMicrowaveModelRev181010 implements OnfMicrowaveModel, MicrowaveModelListener {
88
89     private static final Logger LOG = LoggerFactory.getLogger(WrapperMicrowaveModelRev181010.class);
90
91     public static final QName QNAME = MwAirInterfacePac.QNAME;
92
93
94     private final NetconfBindingAccessor acessor;
95     private final NotificationService microwaveModelListener;
96     private final TransactionUtils genericTransactionUtils;
97     private final String mountpointId;
98     private final @NonNull FaultService faultService;
99     private final WebsocketManagerService notificationService;
100
101     private Optional<NotificationWorker<EventlogEntity>> notificationQueue;
102
103     /**
104      * Handle specific version of microwave model
105      *
106      * @param acessor to access device
107      * @param serviceProvider for devicemanager services
108      */
109     public WrapperMicrowaveModelRev181010(@NonNull NetconfBindingAccessor acessor,
110             @NonNull DeviceManagerServiceProvider serviceProvider) {
111         this.acessor = acessor;
112         this.genericTransactionUtils = acessor.getTransactionUtils();
113         this.mountpointId = acessor.getNodeId().getValue();
114         this.microwaveModelListener = serviceProvider.getNotificationService();
115         this.faultService = serviceProvider.getFaultService();
116         this.notificationService = serviceProvider.getWebsocketService();
117         this.notificationQueue = Optional.empty();
118     }
119
120     /*-----------------------------------------------------------------------------
121      * Setter/Getter
122      */
123
124     @SuppressWarnings("unchecked")
125     @Override
126     public <T extends NotificationListener> T getNotificationListener() {
127         return (T) this;
128     }
129
130     @Override
131     public void setNotificationQueue(NotificationWorker<EventlogEntity> notificationQueue) {
132         this.notificationQueue = Optional.of(notificationQueue);
133     }
134
135     /*-----------------------------------------------------------------------------
136      * Interfacefunctions
137      */
138
139     @Override
140     public void readTheFaultsOfMicrowaveModel(ONFLayerProtocolName lpName, Class<?> lpClass, UniversalId uuid,
141             FaultData resultList) {
142
143         switch (lpName) {
144             case MWAIRINTERFACE:
145                 readTheFaultsOfMwAirInterfacePac(uuid, resultList);
146                 break;
147
148             case ETHERNETCONTAINER12:
149                 readTheFaultsOfMwEthernetContainerPac(uuid, resultList);
150                 break;
151
152             case TDMCONTAINER:
153                 readTheFaultsOfMwTdmContainerPac(uuid, resultList);
154                 break;
155
156             case STRUCTURE:
157                 if (lpClass == MwHybridMwStructurePac.class) {
158                     readTheFaultsOfMwHybridMwStructurePac(uuid, resultList);
159
160                 } else if (lpClass == MwAirInterfaceDiversityPac.class) {
161                     readTheFaultsOfMwAirInterfaceDiversityPac(uuid, resultList);
162
163                 } else if (lpClass == MwPureEthernetStructurePac.class) {
164                     readTheFaultsOfMwPureEthernetStructurePac(uuid, resultList);
165
166                 } else {
167                     LOG.warn("Unassigned lp model {} class {}", lpName, lpClass);
168                 }
169                 break;
170             case ETHERNET:
171                 // No alarms supported
172                 break;
173             case ETHERNETCONTAINER10:
174             default:
175                 LOG.warn("Unassigned or not expected lp in model {}", lpName);
176         }
177     }
178
179     @Override
180     public @NonNull PerformanceDataLtp getLtpHistoricalPerformanceData(@NonNull ONFLayerProtocolName lpName,
181             @NonNull Lp lp) {
182         PerformanceDataLtp res = new PerformanceDataLtp();
183         switch (lpName) {
184             case MWAIRINTERFACE:
185                 return readAirInterfacePerformanceData(lp, res);
186
187             case ETHERNETCONTAINER12:
188                 return readEthernetContainerPerformanceData(lp, res);
189
190             case ETHERNETCONTAINER10:
191             case ETHERNETPHYSICAL:
192             case ETHERNET:
193             case TDMCONTAINER:
194             case STRUCTURE:
195             case UNKNOWN:
196                 LOG.debug("Do not read HistoricalPM data for {} {}", lpName,
197                         Helper.nnGetUniversalId(lp.getUuid()).getValue());
198         }
199         return res;
200     }
201
202     @Override
203     public Class<?> getClassForLtpExtension(QName qName) {
204         Class<?> res = null;
205         if (qName.equals(MwAirInterfacePac.QNAME)) {
206             res = MwAirInterfacePac.class;
207         } else if (qName.equals(MwAirInterfaceDiversityPac.QNAME)) {
208             res = MwAirInterfaceDiversityPac.class;
209         } else if (qName.equals(MwPureEthernetStructurePac.QNAME)) {
210             res = MwPureEthernetStructurePac.class;
211         } else if (qName.equals(MwHybridMwStructurePac.QNAME)) {
212             res = MwHybridMwStructurePac.class;
213         } else if (qName.equals(MwEthernetContainerPac.QNAME)) {
214             res = MwEthernetContainerPac.class;
215         } else if (qName.equals(MwTdmContainerPac.QNAME)) {
216             res = MwTdmContainerPac.class;
217         }
218         LOG.info("Found QName {} mapped to {}", String.valueOf(qName), String.valueOf(res));
219         return res;
220     }
221
222     @Override
223     public void onObjectCreationNotification(ObjectCreationNotification notification) {
224         LOG.debug("Got event of type :: {}", ObjectCreationNotification.class.getSimpleName());
225         if (notification != null) {
226             microwaveModelListener.creationNotification(acessor.getNodeId(), notification.getCounter(),
227                     notification.getTimeStamp(), Helper.nnGetUniversalId(notification.getObjectIdRef()).getValue());
228         }
229     }
230
231     @Override
232     public void onObjectDeletionNotification(ObjectDeletionNotification notification) {
233         LOG.debug("Got event of type :: {}", ObjectDeletionNotification.class.getSimpleName());
234         if (notification != null) {
235             microwaveModelListener.deletionNotification(acessor.getNodeId(), notification.getCounter(),
236                     notification.getTimeStamp(), Helper.nnGetUniversalId(notification.getObjectIdRef()).getValue());
237         }
238     }
239
240     @Override
241     public void onAttributeValueChangedNotification(AttributeValueChangedNotification notification) {
242         LOG.debug("Got event of type :: {}", AttributeValueChangedNotification.class.getSimpleName());
243         EventlogEntity beventlogEntity = new EventlogBuilder().setNodeId(acessor.getNodeId().getValue())
244                 .setCounter(notification.getCounter()).setTimestamp(notification.getTimeStamp())
245                 .setObjectId(Helper.nnGetUniversalId(notification.getObjectIdRef()).getValue())
246                 .setAttributeName(notification.getAttributeName()).setNewValue(notification.getNewValue()).build();
247         microwaveModelListener.eventNotification(beventlogEntity);
248         if (notificationQueue.isPresent()) {
249             notificationQueue.get().put(beventlogEntity);
250         }
251     }
252
253     @Override
254     public void onProblemNotification(ProblemNotification notification) {
255
256         LOG.debug("Got event of type :: {}", ProblemNotification.class.getSimpleName());
257         FaultlogEntity faultAlarm = new FaultlogBuilder().setObjectId(notification.getObjectIdRef().getValue())
258                 .setProblem(notification.getProblem()).setSourceType(SourceType.Netconf)
259                 .setTimestamp(notification.getTimeStamp())
260                 .setNodeId(this.acessor.getNodeId().getValue())
261                 .setSeverity(mapSeverity(notification.getSeverity())).setCounter(notification.getCounter())
262                 .build();
263         // Send devicemanager specific notification for database and ODLUX
264         faultService.faultNotification(faultAlarm);
265         // Send model specific notification to WebSocketManager
266         notificationService.sendNotification(notification, acessor.getNodeId(), ProblemNotification.QNAME,
267                 notification.getTimeStamp());
268     }
269
270     /*-----------------------------------------------------------------------------
271      * Reading problems for specific interface pacs
272      */
273
274     /**
275      * Read problems of specific interfaces
276      *
277      * @param uuId Universal Id String of the interface
278      * @return number of alarms
279      */
280     private FaultData readTheFaultsOfMwAirInterfacePac(UniversalId interfacePacUuid, FaultData resultList) {
281
282         final Class<MwAirInterfacePac> clazzPac = MwAirInterfacePac.class;
283
284         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
285                 mountpointId, interfacePacUuid.getValue());
286
287         // Step 2.2: construct data and the relative iid
288         InstanceIdentifier<AirInterfaceCurrentProblems> mwAirInterfaceIID =
289                 InstanceIdentifier.builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(interfacePacUuid))
290                         .child(AirInterfaceCurrentProblems.class).build();
291
292         // Step 2.3: read to the config data store
293         AirInterfaceCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
294                 LogicalDatastoreType.OPERATIONAL, mwAirInterfaceIID);
295
296         if (problems == null) {
297             LOG.debug("DBRead Id {} no AirInterfaceCurrentProblems", interfacePacUuid);
298         } else if (problems.getCurrentProblemList() == null) {
299             LOG.debug("DBRead Id {} empty CurrentProblemList", interfacePacUuid);
300         } else {
301             for (AirInterfaceCurrentProblemTypeG problem : YangHelper
302                     .getCollection(problems.nonnullCurrentProblemList())) {
303                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
304                         interfacePacUuid.getValue(), problem.getProblemName(),
305                         mapSeverity(problem.getProblemSeverity()));
306             }
307         }
308         return resultList;
309     }
310
311     /**
312      * Read problems of specific interfaces
313      *
314      * @param uuId Universal index of Interfacepac
315      * @return number of alarms
316      */
317     private FaultData readTheFaultsOfMwEthernetContainerPac(UniversalId interfacePacUuid, FaultData resultList) {
318
319         final Class<MwEthernetContainerPac> clazzPac = MwEthernetContainerPac.class;
320
321         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
322                 mountpointId, interfacePacUuid.getValue());
323
324         InstanceIdentifier<EthernetContainerCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
325                 .builder(MwEthernetContainerPac.class, new MwEthernetContainerPacKey(interfacePacUuid))
326                 .child(EthernetContainerCurrentProblems.class).build();
327
328         EthernetContainerCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
329                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
330         if (problems == null) {
331             LOG.debug("DBRead Id {} no EthernetContainerCurrentProblems", interfacePacUuid);
332         } else if (problems.getCurrentProblemList() == null) {
333             LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
334         } else {
335             for (ContainerCurrentProblemTypeG problem : YangHelper
336                     .getCollection(problems.nonnullCurrentProblemList())) {
337                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
338                         interfacePacUuid.getValue(), problem.getProblemName(),
339                         mapSeverity(problem.getProblemSeverity()));
340             }
341         }
342         return resultList;
343     }
344
345     /**
346      * Read problems of specific interfaces
347      *
348      * @param uuId Universal index of Interfacepac
349      * @return number of alarms
350      */
351     private FaultData readTheFaultsOfMwAirInterfaceDiversityPac(UniversalId interfacePacUuid, FaultData resultList) {
352
353         final Class<MwAirInterfaceDiversityPac> clazzPac = MwAirInterfaceDiversityPac.class;
354         final Class<AirInterfaceDiversityCurrentProblems> clazzProblems = AirInterfaceDiversityCurrentProblems.class;
355
356         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
357                 mountpointId, interfacePacUuid.getValue());
358
359         InstanceIdentifier<AirInterfaceDiversityCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
360                 .builder(clazzPac, new MwAirInterfaceDiversityPacKey(interfacePacUuid)).child(clazzProblems).build();
361
362         AirInterfaceDiversityCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
363                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
364         if (problems == null) {
365             LOG.debug("DBRead Id {} no AirInterfaceDiversityCurrentProblems", interfacePacUuid);
366         } else if (problems.getCurrentProblemList() == null) {
367             LOG.debug("DBRead Id {} empty CurrentProblemList", interfacePacUuid);
368         } else {
369             for (AirInterfaceDiversityCurrentProblemTypeG problem : YangHelper
370                     .getCollection(problems.nonnullCurrentProblemList())) {
371                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
372                         interfacePacUuid.getValue(), problem.getProblemName(),
373                         mapSeverity(problem.getProblemSeverity()));
374             }
375         }
376         return resultList;
377     }
378
379     /**
380      * Read problems of specific interfaces
381      *
382      * @param uuId Universal index of Interfacepac
383      * @return number of alarms
384      */
385     private FaultData readTheFaultsOfMwPureEthernetStructurePac(UniversalId interfacePacUuid, FaultData resultList) {
386
387         final Class<MwPureEthernetStructurePac> clazzPac = MwPureEthernetStructurePac.class;
388         final Class<PureEthernetStructureCurrentProblems> clazzProblems = PureEthernetStructureCurrentProblems.class;
389
390         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
391                 mountpointId, interfacePacUuid.getValue());
392
393         InstanceIdentifier<PureEthernetStructureCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
394                 .builder(clazzPac, new MwPureEthernetStructurePacKey(interfacePacUuid)).child(clazzProblems).build();
395
396         PureEthernetStructureCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
397                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
398         if (problems == null) {
399             LOG.debug("DBRead Id {} no PureEthernetStructureCurrentProblems", interfacePacUuid);
400         } else if (problems.getCurrentProblemList() == null) {
401             LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
402         } else {
403             for (StructureCurrentProblemTypeG problem : YangHelper
404                     .getCollection(problems.nonnullCurrentProblemList())) {
405                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
406                         interfacePacUuid.getValue(), problem.getProblemName(),
407                         mapSeverity(problem.getProblemSeverity()));
408             }
409         }
410         return resultList;
411     }
412
413     /**
414      * Read problems of specific interfaces
415      *
416      * @param uuId Universal index of Interfacepac
417      * @return number of alarms
418      */
419     private FaultData readTheFaultsOfMwHybridMwStructurePac(UniversalId interfacePacUuid, FaultData resultList) {
420
421         final Class<MwHybridMwStructurePac> clazzPac = MwHybridMwStructurePac.class;
422         final Class<HybridMwStructureCurrentProblems> clazzProblems = HybridMwStructureCurrentProblems.class;
423
424         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
425                 mountpointId, interfacePacUuid.getValue());
426
427         InstanceIdentifier<HybridMwStructureCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
428                 .builder(clazzPac, new MwHybridMwStructurePacKey(interfacePacUuid)).child(clazzProblems).build();
429
430         HybridMwStructureCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
431                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
432         if (problems == null) {
433             LOG.debug("DBRead Id {} no HybridMwStructureCurrentProblems", interfacePacUuid);
434         } else if (problems.getCurrentProblemList() == null) {
435             LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
436         } else {
437             for (StructureCurrentProblemTypeG problem : YangHelper
438                     .getCollection(problems.nonnullCurrentProblemList())) {
439                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
440                         interfacePacUuid.getValue(), problem.getProblemName(),
441                         mapSeverity(problem.getProblemSeverity()));
442             }
443         }
444         return resultList;
445     }
446
447     /**
448      * Read problems of specific interfaces. TODO Goal for future implementation without usage of explicit new. Key is
449      * generated by newInstance() function here to verify this approach.
450      *
451      * @param uuId Universal index of Interfacepac
452      * @return number of alarms
453      * @throws SecurityException
454      * @throws NoSuchMethodException
455      * @throws InvocationTargetException
456      * @throws IllegalArgumentException
457      * @throws IllegalAccessException
458      * @throws InstantiationException
459      */
460     private FaultData readTheFaultsOfMwTdmContainerPac(UniversalId interfacePacUuid, FaultData resultList) {
461
462         final Class<MwTdmContainerPac> clazzPac = MwTdmContainerPac.class;
463         final Class<MwTdmContainerPacKey> clazzPacKey = MwTdmContainerPacKey.class;
464         final Class<TdmContainerCurrentProblems> clazzProblems = TdmContainerCurrentProblems.class;
465
466         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
467                 mountpointId, interfacePacUuid.getValue());
468
469         try {
470             // -- Specific part 1
471             Constructor<MwTdmContainerPacKey> cons = clazzPacKey.getConstructor(UniversalId.class); // Avoid new()
472             InstanceIdentifier<TdmContainerCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
473                     .builder(clazzPac, cons.newInstance(interfacePacUuid)).child(clazzProblems).build();
474
475             // -- Specific part 2
476             TdmContainerCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
477                     LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
478             if (problems == null) {
479                 LOG.debug("DBRead Id {} no TdmContainerCurrentProblems", interfacePacUuid);
480             } else {
481                 // -- Specific part 3
482                 for (ContainerCurrentProblemTypeG problem : YangHelper
483                         .getCollection(problems.nonnullCurrentProblemList())) {
484                     resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
485                             interfacePacUuid.getValue(), problem.getProblemName(),
486                             mapSeverity(problem.getProblemSeverity()));
487                 }
488             }
489         } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
490                 | IllegalArgumentException | InvocationTargetException e) {
491             LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
492         }
493         return resultList;
494     }
495
496     /*-----------------------------------------------------------------------------
497      * Performance related data
498      */
499
500     /**
501      * Read and add performance data
502      *
503      * @param lp to read from
504      * @param result Object to be filled with data
505      * @return result
506      */
507     private @NonNull PerformanceDataLtp readAirInterfacePerformanceData(Lp lp, PerformanceDataLtp result) {
508
509         LOG.debug("DBRead Get {} MWAirInterfacePac: {}", acessor.getNodeId(), lp.getUuid());
510         // ----
511         UniversalId mwAirInterfacePacuuId = lp.getUuid();
512         // Step 2.1: construct data and the relative iid
513         InstanceIdentifier<AirInterfaceConfiguration> mwAirInterfaceConfigurationIID =
514                 InstanceIdentifier.builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(mwAirInterfacePacuuId))
515                         .child(AirInterfaceConfiguration.class).build();
516         AirInterfaceConfiguration airConfiguration = acessor.getTransactionUtils().readData(acessor.getDataBroker(),
517                 LogicalDatastoreType.OPERATIONAL, mwAirInterfaceConfigurationIID);
518
519         if (airConfiguration == null) {
520             LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceConfiguration", mwAirInterfacePacuuId);
521
522         } else {
523             // Step 2.2: construct data and the relative iid
524             InstanceIdentifier<AirInterfaceHistoricalPerformances> mwAirInterfaceHistoricalPerformanceIID =
525                     InstanceIdentifier.builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(mwAirInterfacePacuuId))
526                             .child(AirInterfaceHistoricalPerformances.class).build();
527
528             // Step 2.3: read to the config data store
529             AirInterfaceHistoricalPerformances airHistoricalPerformanceData = genericTransactionUtils.readData(
530                     acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, mwAirInterfaceHistoricalPerformanceIID);
531
532             if (airHistoricalPerformanceData == null) {
533                 LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceHistoricalPerformances",
534                         mwAirInterfacePacuuId);
535             } else {
536                 // org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170320.air._interface.historical.performances.g.HistoricalPerformanceDataList
537                 Collection<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.air._interface.historical.performances.g.HistoricalPerformanceDataList> airHistPMList =
538                         YangHelper.getCollection(airHistoricalPerformanceData.nonnullHistoricalPerformanceDataList());
539                 LOG.debug("DBRead MWAirInterfacePac Id {} Records intermediate: {}", mwAirInterfacePacuuId,
540                         airHistPMList.size());
541                 for (AirInterfaceHistoricalPerformanceTypeG pmRecord : airHistPMList) {
542                     result.add(new PerformanceDataAirInterface181010Builder(acessor.getNodeId(), lp, pmRecord,
543                             airConfiguration));
544                 }
545             }
546         }
547         LOG.debug("DBRead MWAirInterfacePac Id {} Records result: {}", mwAirInterfacePacuuId, result.size());
548         return result;
549     }
550
551     private @NonNull PerformanceDataLtp readEthernetContainerPerformanceData(Lp lp, PerformanceDataLtp result) {
552         final String myName = "MWEthernetContainerPac";
553
554         LOG.debug("DBRead Get {} : {}", mountpointId, myName, lp.getUuid());
555         // ----
556         UniversalId ethContainerPacuuId = lp.getUuid();
557         // Step 2.2: construct data and the relative iid
558         InstanceIdentifier<EthernetContainerHistoricalPerformances> ethContainerIID = InstanceIdentifier
559                 .builder(MwEthernetContainerPac.class, new MwEthernetContainerPacKey(ethContainerPacuuId))
560                 .child(EthernetContainerHistoricalPerformances.class).build();
561
562         // Step 2.3: read to the config data store
563         EthernetContainerHistoricalPerformances ethContainerHistoricalPerformanceData = acessor.getTransactionUtils()
564                 .readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, ethContainerIID);
565
566         if (ethContainerHistoricalPerformanceData == null) {
567             LOG.debug("DBRead {} Id {} no HistoricalPerformances", myName, ethContainerPacuuId);
568         } else {
569             Collection<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ethernet.container.historical.performances.g.HistoricalPerformanceDataList> airHistPMList =
570                     YangHelper.getCollection(
571                             ethContainerHistoricalPerformanceData.nonnullHistoricalPerformanceDataList());
572             LOG.debug("DBRead {} Id {} Records intermediate: {}", myName, ethContainerPacuuId, airHistPMList.size());
573             for (ContainerHistoricalPerformanceTypeG pmRecord : airHistPMList) {
574                 result.add(new PerformanceDataAirInterface181010Builder(acessor.getNodeId(), lp, pmRecord));
575             }
576         }
577         LOG.debug("DBRead {} Id {} Records result: {}", myName, ethContainerPacuuId, result.size());
578         return result;
579     }
580
581     public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType mapSeverity(
582             SeverityType severity) {
583
584         Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType> res =
585                 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType
586                         .forName(severity.name());
587         return res.orElse(
588                 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType.NonAlarmed);
589     }
590
591
592
593 }