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