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