623fa62206ba3a7451d16fe0559134d1589d4a81
[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.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         faultService.faultNotification(faultAlarm);
264         notificationService.sendNotification(notification, acessor.getNodeId().getValue(), ProblemNotification.QNAME,
265                 notification.getTimeStamp());
266     }
267
268     /*-----------------------------------------------------------------------------
269      * Reading problems for specific interface pacs
270      */
271
272     /**
273      * Read problems of specific interfaces
274      *
275      * @param uuId Universal Id String of the interface
276      * @return number of alarms
277      */
278     private FaultData readTheFaultsOfMwAirInterfacePac(UniversalId interfacePacUuid, FaultData resultList) {
279
280         final Class<MwAirInterfacePac> clazzPac = MwAirInterfacePac.class;
281
282         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
283                 mountpointId, interfacePacUuid.getValue());
284
285         // Step 2.2: construct data and the relative iid
286         InstanceIdentifier<AirInterfaceCurrentProblems> mwAirInterfaceIID =
287                 InstanceIdentifier.builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(interfacePacUuid))
288                         .child(AirInterfaceCurrentProblems.class).build();
289
290         // Step 2.3: read to the config data store
291         AirInterfaceCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
292                 LogicalDatastoreType.OPERATIONAL, mwAirInterfaceIID);
293
294         if (problems == null) {
295             LOG.debug("DBRead Id {} no AirInterfaceCurrentProblems", interfacePacUuid);
296         } else if (problems.getCurrentProblemList() == null) {
297             LOG.debug("DBRead Id {} empty CurrentProblemList", interfacePacUuid);
298         } else {
299             for (AirInterfaceCurrentProblemTypeG problem : YangHelper
300                     .getCollection(problems.nonnullCurrentProblemList())) {
301                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
302                         interfacePacUuid.getValue(), problem.getProblemName(),
303                         mapSeverity(problem.getProblemSeverity()));
304             }
305         }
306         return resultList;
307     }
308
309     /**
310      * Read problems of specific interfaces
311      *
312      * @param uuId Universal index of Interfacepac
313      * @return number of alarms
314      */
315     private FaultData readTheFaultsOfMwEthernetContainerPac(UniversalId interfacePacUuid, FaultData resultList) {
316
317         final Class<MwEthernetContainerPac> clazzPac = MwEthernetContainerPac.class;
318
319         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
320                 mountpointId, interfacePacUuid.getValue());
321
322         InstanceIdentifier<EthernetContainerCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
323                 .builder(MwEthernetContainerPac.class, new MwEthernetContainerPacKey(interfacePacUuid))
324                 .child(EthernetContainerCurrentProblems.class).build();
325
326         EthernetContainerCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
327                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
328         if (problems == null) {
329             LOG.debug("DBRead Id {} no EthernetContainerCurrentProblems", interfacePacUuid);
330         } else if (problems.getCurrentProblemList() == null) {
331             LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
332         } else {
333             for (ContainerCurrentProblemTypeG problem : YangHelper
334                     .getCollection(problems.nonnullCurrentProblemList())) {
335                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
336                         interfacePacUuid.getValue(), problem.getProblemName(),
337                         mapSeverity(problem.getProblemSeverity()));
338             }
339         }
340         return resultList;
341     }
342
343     /**
344      * Read problems of specific interfaces
345      *
346      * @param uuId Universal index of Interfacepac
347      * @return number of alarms
348      */
349     private FaultData readTheFaultsOfMwAirInterfaceDiversityPac(UniversalId interfacePacUuid, FaultData resultList) {
350
351         final Class<MwAirInterfaceDiversityPac> clazzPac = MwAirInterfaceDiversityPac.class;
352         final Class<AirInterfaceDiversityCurrentProblems> clazzProblems = AirInterfaceDiversityCurrentProblems.class;
353
354         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
355                 mountpointId, interfacePacUuid.getValue());
356
357         InstanceIdentifier<AirInterfaceDiversityCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
358                 .builder(clazzPac, new MwAirInterfaceDiversityPacKey(interfacePacUuid)).child(clazzProblems).build();
359
360         AirInterfaceDiversityCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
361                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
362         if (problems == null) {
363             LOG.debug("DBRead Id {} no AirInterfaceDiversityCurrentProblems", interfacePacUuid);
364         } else if (problems.getCurrentProblemList() == null) {
365             LOG.debug("DBRead Id {} empty CurrentProblemList", interfacePacUuid);
366         } else {
367             for (AirInterfaceDiversityCurrentProblemTypeG problem : YangHelper
368                     .getCollection(problems.nonnullCurrentProblemList())) {
369                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
370                         interfacePacUuid.getValue(), problem.getProblemName(),
371                         mapSeverity(problem.getProblemSeverity()));
372             }
373         }
374         return resultList;
375     }
376
377     /**
378      * Read problems of specific interfaces
379      *
380      * @param uuId Universal index of Interfacepac
381      * @return number of alarms
382      */
383     private FaultData readTheFaultsOfMwPureEthernetStructurePac(UniversalId interfacePacUuid, FaultData resultList) {
384
385         final Class<MwPureEthernetStructurePac> clazzPac = MwPureEthernetStructurePac.class;
386         final Class<PureEthernetStructureCurrentProblems> clazzProblems = PureEthernetStructureCurrentProblems.class;
387
388         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
389                 mountpointId, interfacePacUuid.getValue());
390
391         InstanceIdentifier<PureEthernetStructureCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
392                 .builder(clazzPac, new MwPureEthernetStructurePacKey(interfacePacUuid)).child(clazzProblems).build();
393
394         PureEthernetStructureCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
395                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
396         if (problems == null) {
397             LOG.debug("DBRead Id {} no PureEthernetStructureCurrentProblems", interfacePacUuid);
398         } else if (problems.getCurrentProblemList() == null) {
399             LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
400         } else {
401             for (StructureCurrentProblemTypeG problem : YangHelper
402                     .getCollection(problems.nonnullCurrentProblemList())) {
403                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
404                         interfacePacUuid.getValue(), problem.getProblemName(),
405                         mapSeverity(problem.getProblemSeverity()));
406             }
407         }
408         return resultList;
409     }
410
411     /**
412      * Read problems of specific interfaces
413      *
414      * @param uuId Universal index of Interfacepac
415      * @return number of alarms
416      */
417     private FaultData readTheFaultsOfMwHybridMwStructurePac(UniversalId interfacePacUuid, FaultData resultList) {
418
419         final Class<MwHybridMwStructurePac> clazzPac = MwHybridMwStructurePac.class;
420         final Class<HybridMwStructureCurrentProblems> clazzProblems = HybridMwStructureCurrentProblems.class;
421
422         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
423                 mountpointId, interfacePacUuid.getValue());
424
425         InstanceIdentifier<HybridMwStructureCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
426                 .builder(clazzPac, new MwHybridMwStructurePacKey(interfacePacUuid)).child(clazzProblems).build();
427
428         HybridMwStructureCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
429                 LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
430         if (problems == null) {
431             LOG.debug("DBRead Id {} no HybridMwStructureCurrentProblems", interfacePacUuid);
432         } else if (problems.getCurrentProblemList() == null) {
433             LOG.debug("DBRead Id {} empty CurrentProblemsList", interfacePacUuid);
434         } else {
435             for (StructureCurrentProblemTypeG problem : YangHelper
436                     .getCollection(problems.nonnullCurrentProblemList())) {
437                 resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
438                         interfacePacUuid.getValue(), problem.getProblemName(),
439                         mapSeverity(problem.getProblemSeverity()));
440             }
441         }
442         return resultList;
443     }
444
445     /**
446      * Read problems of specific interfaces. TODO Goal for future implementation without usage of explicit new. Key is
447      * generated by newInstance() function here to verify this approach.
448      *
449      * @param uuId Universal index of Interfacepac
450      * @return number of alarms
451      * @throws SecurityException
452      * @throws NoSuchMethodException
453      * @throws InvocationTargetException
454      * @throws IllegalArgumentException
455      * @throws IllegalAccessException
456      * @throws InstantiationException
457      */
458     private FaultData readTheFaultsOfMwTdmContainerPac(UniversalId interfacePacUuid, FaultData resultList) {
459
460         final Class<MwTdmContainerPac> clazzPac = MwTdmContainerPac.class;
461         final Class<MwTdmContainerPacKey> clazzPacKey = MwTdmContainerPacKey.class;
462         final Class<TdmContainerCurrentProblems> clazzProblems = TdmContainerCurrentProblems.class;
463
464         LOG.info("DBRead Get problems for class {} from mountpoint {} for uuid {}", clazzPac.getSimpleName(),
465                 mountpointId, interfacePacUuid.getValue());
466
467         try {
468             // -- Specific part 1
469             Constructor<MwTdmContainerPacKey> cons = clazzPacKey.getConstructor(UniversalId.class); // Avoid new()
470             InstanceIdentifier<TdmContainerCurrentProblems> mwEthInterfaceIID = InstanceIdentifier
471                     .builder(clazzPac, cons.newInstance(interfacePacUuid)).child(clazzProblems).build();
472
473             // -- Specific part 2
474             TdmContainerCurrentProblems problems = genericTransactionUtils.readData(acessor.getDataBroker(),
475                     LogicalDatastoreType.OPERATIONAL, mwEthInterfaceIID);
476             if (problems == null) {
477                 LOG.debug("DBRead Id {} no TdmContainerCurrentProblems", interfacePacUuid);
478             } else {
479                 // -- Specific part 3
480                 for (ContainerCurrentProblemTypeG problem : YangHelper
481                         .getCollection(problems.nonnullCurrentProblemList())) {
482                     resultList.add(acessor.getNodeId(), problem.getSequenceNumber(), problem.getTimeStamp(),
483                             interfacePacUuid.getValue(), problem.getProblemName(),
484                             mapSeverity(problem.getProblemSeverity()));
485                 }
486             }
487         } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
488                 | IllegalArgumentException | InvocationTargetException e) {
489             LOG.warn("Could not reade instance of MwTdmContainerPacKey: ", e);
490         }
491         return resultList;
492     }
493
494     /*-----------------------------------------------------------------------------
495      * Performance related data
496      */
497
498     /**
499      * Read and add performance data
500      *
501      * @param lp to read from
502      * @param result Object to be filled with data
503      * @return result
504      */
505     private @NonNull PerformanceDataLtp readAirInterfacePerformanceData(Lp lp, PerformanceDataLtp result) {
506
507         LOG.debug("DBRead Get {} MWAirInterfacePac: {}", acessor.getNodeId(), lp.getUuid());
508         // ----
509         UniversalId mwAirInterfacePacuuId = lp.getUuid();
510         // Step 2.1: construct data and the relative iid
511         InstanceIdentifier<AirInterfaceConfiguration> mwAirInterfaceConfigurationIID =
512                 InstanceIdentifier.builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(mwAirInterfacePacuuId))
513                         .child(AirInterfaceConfiguration.class).build();
514         AirInterfaceConfiguration airConfiguration = acessor.getTransactionUtils().readData(acessor.getDataBroker(),
515                 LogicalDatastoreType.OPERATIONAL, mwAirInterfaceConfigurationIID);
516
517         if (airConfiguration == null) {
518             LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceConfiguration", mwAirInterfacePacuuId);
519
520         } else {
521             // Step 2.2: construct data and the relative iid
522             InstanceIdentifier<AirInterfaceHistoricalPerformances> mwAirInterfaceHistoricalPerformanceIID =
523                     InstanceIdentifier.builder(MwAirInterfacePac.class, new MwAirInterfacePacKey(mwAirInterfacePacuuId))
524                             .child(AirInterfaceHistoricalPerformances.class).build();
525
526             // Step 2.3: read to the config data store
527             AirInterfaceHistoricalPerformances airHistoricalPerformanceData = genericTransactionUtils.readData(
528                     acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, mwAirInterfaceHistoricalPerformanceIID);
529
530             if (airHistoricalPerformanceData == null) {
531                 LOG.debug("DBRead MWAirInterfacePac Id {} no AirInterfaceHistoricalPerformances",
532                         mwAirInterfacePacuuId);
533             } else {
534                 // org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170320.air._interface.historical.performances.g.HistoricalPerformanceDataList
535                 Collection<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.air._interface.historical.performances.g.HistoricalPerformanceDataList> airHistPMList =
536                         YangHelper.getCollection(airHistoricalPerformanceData.nonnullHistoricalPerformanceDataList());
537                 LOG.debug("DBRead MWAirInterfacePac Id {} Records intermediate: {}", mwAirInterfacePacuuId,
538                         airHistPMList.size());
539                 for (AirInterfaceHistoricalPerformanceTypeG pmRecord : airHistPMList) {
540                     result.add(new PerformanceDataAirInterface181010Builder(acessor.getNodeId(), lp, pmRecord,
541                             airConfiguration));
542                 }
543             }
544         }
545         LOG.debug("DBRead MWAirInterfacePac Id {} Records result: {}", mwAirInterfacePacuuId, result.size());
546         return result;
547     }
548
549     private @NonNull PerformanceDataLtp readEthernetContainerPerformanceData(Lp lp, PerformanceDataLtp result) {
550         final String myName = "MWEthernetContainerPac";
551
552         LOG.debug("DBRead Get {} : {}", mountpointId, myName, lp.getUuid());
553         // ----
554         UniversalId ethContainerPacuuId = lp.getUuid();
555         // Step 2.2: construct data and the relative iid
556         InstanceIdentifier<EthernetContainerHistoricalPerformances> ethContainerIID = InstanceIdentifier
557                 .builder(MwEthernetContainerPac.class, new MwEthernetContainerPacKey(ethContainerPacuuId))
558                 .child(EthernetContainerHistoricalPerformances.class).build();
559
560         // Step 2.3: read to the config data store
561         EthernetContainerHistoricalPerformances ethContainerHistoricalPerformanceData = acessor.getTransactionUtils()
562                 .readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL, ethContainerIID);
563
564         if (ethContainerHistoricalPerformanceData == null) {
565             LOG.debug("DBRead {} Id {} no HistoricalPerformances", myName, ethContainerPacuuId);
566         } else {
567             Collection<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.ethernet.container.historical.performances.g.HistoricalPerformanceDataList> airHistPMList =
568                     YangHelper.getCollection(
569                             ethContainerHistoricalPerformanceData.nonnullHistoricalPerformanceDataList());
570             LOG.debug("DBRead {} Id {} Records intermediate: {}", myName, ethContainerPacuuId, airHistPMList.size());
571             for (ContainerHistoricalPerformanceTypeG pmRecord : airHistPMList) {
572                 result.add(new PerformanceDataAirInterface181010Builder(acessor.getNodeId(), lp, pmRecord));
573             }
574         }
575         LOG.debug("DBRead {} Id {} Records result: {}", myName, ethContainerPacuuId, result.size());
576         return result;
577     }
578
579     public static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType mapSeverity(
580             SeverityType severity) {
581
582         Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType> res =
583                 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType
584                         .forName(severity.name());
585         return res.orElse(
586                 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType.NonAlarmed);
587     }
588
589
590
591 }