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