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