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