b57e8c90649ba47ae68cb4435b5b4de33f04acca
[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.base.netconf;
19
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.List;
23 import javax.annotation.Nonnull;
24 import javax.annotation.Nullable;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.AllPm;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.ONFLayerProtocolName;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.OnfMicrowaveModel;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperMicrowaveModelRev170324;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperMicrowaveModelRev180907;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperMicrowaveModelRev181010;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayService;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.ProviderClient;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.MicrowaveEventListener12;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance24Hours;
45 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
46 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
47 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
48 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
49 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
50 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId;
51 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
52 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
53 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.network.element.Ltp;
54 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.GranularityPeriodType;
55 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.OtnHistoryDataG;
56 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac;
57 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.pac.NetworkElementCurrentProblems;
58 import org.opendaylight.yangtools.concepts.ListenerRegistration;
59 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
60 import org.opendaylight.yangtools.yang.binding.NotificationListener;
61 import org.opendaylight.yangtools.yang.common.QName;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
64 import com.google.common.base.Optional;
65
66 /**
67  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and
68  * conditional packages.
69  *
70  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP),
71  * MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client),
72  * MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
73  * MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
74  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
75  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
76  *
77  * @author herbert
78  *
79  */
80 public class ONFCoreNetworkElement12 extends ONFCoreNetworkElement12Base
81         implements ONFCoreNetworkElementCallback, NotificationActor<AttributeValueChangedNotificationXml> {
82
83     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12.class);
84
85     /*-----------------------------------------------------------------------------
86      * Class members
87      */
88     private final @Nonnull MicrowaveEventListener12 microwaveEventListener;
89     private final @Nonnull OnfMicrowaveModel microwaveModel;
90     private final NotificationWorker<AttributeValueChangedNotificationXml> notificationQueue;
91
92     private ListenerRegistration<NotificationListener> listenerRegistrationresult = null;
93
94     /*-----------------------------------------------------------------------------
95      * Construction
96      */
97
98     /**
99      * Constructor
100      *
101      * @param mountPointNodeName as String
102      * @param capabilities of the specific network element
103      * @param netconfNodeDataBroker for the network element specific data
104      * @param webSocketService to forward event notifications
105      * @param databaseService to access the database
106      * @param dcaeProvider to forward problem / change notifications
107      */
108     private ONFCoreNetworkElement12(String mountPointNodeName, Capabilities capabilities,
109             DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
110             HtDatabaseEventsService databaseService, ProviderClient dcaeProvider, @Nullable ProviderClient aotsmClient,
111             MaintenanceService maintenanceService,
112             NotificationDelayService<ProblemNotificationXml> notificationDelayService,
113             OnfMicrowaveModel onfMicrowaveModel) {
114
115         super(mountPointNodeName, netconfNodeDataBroker, capabilities);
116
117         this.microwaveModel = onfMicrowaveModel;
118         this.microwaveModel.setCoreData(this);
119
120         // Create MicrowaveService here
121         this.microwaveEventListener = new MicrowaveEventListener12(mountPointNodeName, webSocketService,
122                 databaseService, dcaeProvider, aotsmClient, maintenanceService, notificationDelayService, this);
123         this.microwaveModel.setOnfMicrowaveModelListener(microwaveEventListener);
124
125         this.notificationQueue = new NotificationWorker<>(1, 100, this);
126
127         // ->Below shifted to super class
128         // this.isNetworkElementCurrentProblemsSupporting12 =
129         // capabilities.isSupportingNamespaceAndRevision(NetworkElementPac.QNAME);
130         // LOG.debug("support necurrent-problem-list=" + this.isNetworkElementCurrentProblemsSupporting12);
131         // LOG.info("Create NE instance {}", InstanceList.QNAME.getLocalName());
132
133     }
134
135     /**
136      * Check capabilities are matching the this specific implementation and create network element
137      * representation if so.
138      *
139      * @param mountPointNodeName as String
140      * @param capabilities of the specific network element
141      * @param netconfNodeDataBroker for the network element specific data
142      * @param webSocketService to forward event notifications
143      * @param databaseService to access the database
144      * @param dcaeProvider to forward problem / change notifications
145      * @return created Object if conditions are OK or null if not.
146      */
147     public static @Nullable ONFCoreNetworkElement12 build(String mountPointNodeName, Capabilities capabilities,
148             DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
149             HtDatabaseEventsService databaseService, ProviderClient dcaeProvider, @Nullable ProviderClient aotsmClient,
150             MaintenanceService maintenanceService,
151             NotificationDelayService<ProblemNotificationXml> notificationDelayService) {
152
153         if (capabilities.isSupportingNamespaceAndRevision(NetworkElement.QNAME)) {
154             OnfMicrowaveModel onfMicrowaveModel = null;
155
156             if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev170324.QNAME)) {
157                 onfMicrowaveModel = new WrapperMicrowaveModelRev170324();
158             } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev180907.QNAME)) {
159                 onfMicrowaveModel = new WrapperMicrowaveModelRev180907();
160             } else if (capabilities.isSupportingNamespaceAndRevision(WrapperMicrowaveModelRev181010.QNAME)) {
161                 onfMicrowaveModel = new WrapperMicrowaveModelRev181010();
162             }
163
164             if (onfMicrowaveModel != null) {
165                 return new ONFCoreNetworkElement12(mountPointNodeName, capabilities, netconfNodeDataBroker,
166                         webSocketService, databaseService, dcaeProvider, aotsmClient, maintenanceService,
167                         notificationDelayService, onfMicrowaveModel);
168             }
169         }
170         return null;
171
172     }
173
174     /*-----------------------------------------------------------------------------
175      * Functions
176      */
177
178     /**
179      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
180      */
181     @Override
182     public void prepareCheck() {
183         synchronized (dmLock) {
184             boolean change = readNetworkElementAndInterfaces();
185             if (change) {
186                 int problems = microwaveEventListener.removeAllCurrentProblemsOfNode();
187                 List<ProblemNotificationXml> resultList = readAllCurrentProblemsOfNode();
188                 microwaveEventListener.initCurrentProblemStatus(resultList);
189                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountPointNodeName(),
190                         getUuId(), problems, resultList.size());
191             }
192         }
193     }
194
195     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
196     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
197
198     /*-----------------------------------------------------------------------------
199      * Synchronization
200      */
201
202     // public void initSynchronizationExtension() -> Shifted to super class
203     // private InstanceList readPTPClockInstances() -> Shifted to super class
204
205     /*-----------------------------------------------------------------------------
206      * Services for NE/Device synchronization
207      */
208
209     /**
210      * Handling of specific Notifications from NE, indicating changes and need for synchronization.
211      *
212      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
213      * <attribute-name>/equipment-pac/equipment-current-problems</attribute-name>
214      * <object-id-ref>CARD-1.1.1.0</object-id-ref> <new-value></new-value>
215      * </attribute-value-changed-notification>
216      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
217      * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
218      * <object-id-ref>Hybrid-Z</object-id-ref>
219      * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
220      * </attribute-value-changed-notification>
221      */
222
223
224     @Override
225     public void notificationFromNeListener(AttributeValueChangedNotificationXml notificationXml) {
226         notificationQueue.put(notificationXml);
227     }
228
229     @Override
230     public void notificationActor(AttributeValueChangedNotificationXml notificationXml) {
231
232         LOG.debug("Enter change notification listener");
233         if (LOG.isTraceEnabled()) {
234             LOG.trace("Notification: {}", notificationXml);
235         }
236         if (notificationXml.getAttributeName().equals("/equipment-pac/equipment-current-problems")) {
237             syncEquipmentPac(notificationXml.getObjectId());
238         } else if (notificationXml.getAttributeName()
239                 .equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
240             initialReadFromNetworkElement();
241         }
242         LOG.debug("Leave change notification listener");
243     }
244
245     /**
246      * Synchronize problems for a specific equipment-pac
247      *
248      * @param uuidString of the equipment-pac
249      */
250     private synchronized void syncEquipmentPac(String uuidString) {
251
252         int problems = microwaveEventListener.removeObjectsCurrentProblemsOfNode(uuidString);
253         LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
254
255         List<ProblemNotificationXml> resultList = equipment.addProblemsofNodeObject(uuidString);
256         microwaveEventListener.initCurrentProblemStatus(resultList);
257         LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
258
259     }
260
261
262     /*-----------------------------------------------------------------------------
263      * Problem/Fault related functions
264      */
265
266     /**
267      * Read during startup all relevant structure and status parameters from device
268      */
269     @Override
270     public synchronized void initialReadFromNetworkElement() {
271         // optionalNe.getLtp().get(0).getLp();
272         LOG.debug("Get info about {}", getMountPointNodeName());
273
274         int problems = microwaveEventListener.removeAllCurrentProblemsOfNode();
275         LOG.debug("Removed all {} problems from database at registration", problems);
276
277         // Step 2.1: access data broker within this mount point
278         LOG.debug("DBRead start");
279
280         // Step 2.2: read ne from data store
281         readNetworkElementAndInterfaces();
282         equipment.readNetworkElementEquipment();
283
284         // Step 2.3: read the existing faults and add to DB
285         List<ProblemNotificationXml> resultList = readAllCurrentProblemsOfNode();
286         equipment.addProblemsofNode(resultList);
287
288         microwaveEventListener.initCurrentProblemStatus(resultList);
289
290         microwaveEventListener.writeEquipment(equipment);
291
292         LOG.info("Found info at {} for device {} number of problems: {}", getMountPointNodeName(), getUuId(),
293                 resultList.size());
294     }
295
296     /**
297      * LOG the newly added problems of the interface pac
298      *
299      * @param idxStart
300      * @param uuid
301      * @param resultList
302      */
303     private void debugResultList(String uuid, List<ProblemNotificationXml> resultList, int idxStart) {
304         if (LOG.isDebugEnabled()) {
305             StringBuffer sb = new StringBuffer();
306             int idx = 0;
307             for (int t = idxStart; t < resultList.size(); t++) {
308                 sb.append(idx++);
309                 sb.append(":{");
310                 sb.append(resultList.get(t));
311                 sb.append('}');
312             }
313             LOG.debug("Found problems {} {}", uuid, sb.toString());
314         }
315     }
316
317     /**
318      * Read from NetworkElement and verify LTPs have changed. If the NE has changed, update to the new
319      * structure. From initial state it changes also.
320      */
321     private synchronized boolean readNetworkElementAndInterfaces() {
322
323         LOG.debug("Update mountpoint if changed {}", getMountPointNodeName());
324
325         optionalNe = GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
326                 NETWORKELEMENT_IID);;
327         synchronized (pmLock) {
328             boolean change = false;
329
330             if (optionalNe == null) {
331                 LOG.debug("Unable to read NE data for mountpoint {}", getMountPointNodeName());
332                 if (!interfaceList.isEmpty()) {
333                     interfaceList.clear();
334                     interfaceListIterator = null;
335                     change = true;
336                 }
337
338             } else {
339                 LOG.debug("Mountpoint '{}' NE-Name '{}'", getMountPointNodeName(), optionalNe.getName());
340                 List<Lp> actualInterfaceList = getLtpList(optionalNe);
341                 if (!interfaceList.equals(actualInterfaceList)) {
342                     LOG.debug("Mountpoint '{}' Update LTP List. Elements {}", getMountPointNodeName(),
343                             actualInterfaceList.size());
344                     interfaceList.clear();
345                     interfaceList.addAll(actualInterfaceList);
346                     interfaceListIterator = null;
347                     change = true;
348                 }
349             }
350             return change;
351         }
352     }
353
354     /**
355      * Read current problems of AirInterfaces and EthernetContainer according to NE status into DB
356      *
357      * @return List with all problems
358      */
359     private List<ProblemNotificationXml> readAllCurrentProblemsOfNode() {
360
361         // Step 2.3: read the existing faults and add to DB
362         List<ProblemNotificationXml> resultList = new ArrayList<>();
363         int idxStart; // Start index for debug messages
364         UniversalId uuid;
365
366         synchronized (pmLock) {
367             for (Lp lp : interfaceList) {
368
369                 idxStart = resultList.size();
370                 uuid = lp.getUuid();
371                 Class<?> lpClass = getLpExtension(lp);
372
373                 ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
374
375                 microwaveModel.readTheFaultsOfMicrowaveModel(lpName, lpClass, uuid, resultList);
376
377                 debugResultList(uuid.getValue(), resultList, idxStart);
378
379             }
380         }
381
382         // Step 2.4: Read other problems from mountpoint
383         if (isNetworkElementCurrentProblemsSupporting12) {
384             idxStart = resultList.size();
385             readNetworkElementCurrentProblems12(resultList);
386             debugResultList("CurrentProblems12", resultList, idxStart);
387         }
388
389         return resultList;
390
391     }
392
393     /**
394      * Get uuid of Optional NE.
395      *
396      * @return Uuid or EMPTY String if optionNE is not available
397      */
398     private String getUuId() {
399         String uuid = EMPTY;
400
401         try {
402             uuid = optionalNe != null ? optionalNe.getUuid() != null ? optionalNe.getUuid().getValue() : EMPTY : EMPTY;
403         } catch (NullPointerException e) {
404             // Unfortunately throws null pointer if not definied
405         }
406         return uuid;
407     }
408
409     /**
410      * Read the NetworkElement part from database.
411      *
412      * @return Optional with NetworkElement or empty
413      */
414     @Nullable
415     private NetworkElement readNetworkElement() {
416         // Step 2.2: construct data and the relative iid
417         // The schema path to identify an instance is
418         // <i>CoreModel-CoreNetworkModule-ObjectClasses/NetworkElement</i>
419         // Read to the config data store
420         return GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
421                 NETWORKELEMENT_IID);
422     }
423
424     /**
425      * Get from LayerProtocolExtensions the related generated ONF Interface PAC class which represents it.
426      *
427      * @param lp logical termination point
428      * @return Class of InterfacePac
429      */
430     @Nullable
431     private Class<?> getLpExtension(@Nullable Lp lp) {
432
433         String capability = EMPTY;
434         String revision = EMPTY;
435         String conditionalPackage = EMPTY;
436         Class<?> res = null;
437
438         if (lp != null) {
439             for (Extension e : getExtensionList(lp)) {
440                 if (e.getValueName().contentEquals("capability")) {
441                     capability = e.getValue();
442                     int idx = capability.indexOf("?");
443                     if (idx != -1) {
444                         capability = capability.substring(0, idx);
445                     }
446                 }
447                 if (e.getValueName().contentEquals("revision")) {
448                     revision = e.getValue();
449                 }
450                 if (e.getValueName().contentEquals("conditional-package")) {
451                     conditionalPackage = e.getValue();
452                 }
453             }
454         }
455         // QName qName =
456         // org.opendaylight.yangtools.yang.common.QName.create("urn:onf:params:xml:ns:yang:microwave-model",
457         // "2017-03-24", "mw-air-interface-pac").intern();
458         LOG.info("LpExtension capability={} revision={} conditionalPackage={}", capability, revision,
459                 conditionalPackage);
460         if (!capability.isEmpty() && !revision.isEmpty() && !conditionalPackage.isEmpty()) {
461             try {
462                 QName qName = QName.create(capability, revision, conditionalPackage);
463                 res = this.microwaveModel.getClassForLtpExtension(qName);
464             } catch (IllegalArgumentException e) {
465                 LOG.debug("Can not create QName from ({}{}{}): {}", capability, revision, conditionalPackage,
466                         e.getMessage());
467             }
468         }
469         return res;
470     }
471
472     /**
473      * Read element from class that could be not available
474      *
475      * @param ltp layer termination point
476      * @return List with extension parameters or empty list
477      */
478     @Nonnull
479     private static List<Extension> getExtensionList(@Nullable Lp ltp) {
480         if (ltp != null && ltp.getExtension() != null) {
481             return ltp.getExtension();
482         } else {
483             return EMPTYLTPEXTENSIONLIST;
484         }
485     }
486
487     /**
488      * Get List of UUIDs for conditional packages from Networkelement<br>
489      * Possible interfaces are:<br>
490      * MWPS, LTP(MWPS-TTP), MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface<br>
491      * ETH-CTP,LTP(Client), MW_EthernetContainer_Pac<br>
492      * MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
493      * MicrowaveModel-ObjectClasses-AirInterfaceDiversity<br>
494      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-HybridMwStructure<br>
495      * MWS, LTP(MWS-TTP), ,MicrowaveModel-ObjectClasses-PureEthernetStructure<br>
496      *
497      * @param ne Networkelement
498      * @return Id List, never null.
499      */
500     private static List<Lp> getLtpList(@Nullable NetworkElement ne) {
501
502         List<Lp> res = Collections.synchronizedList(new ArrayList<Lp>());
503
504         if (ne != null) {
505             List<Ltp> ltpRefList = ne.getLtp();
506             if (ltpRefList == null) {
507                 LOG.debug("DBRead NE-Interfaces: null");
508             } else {
509                 for (Ltp ltRefListE : ltpRefList) {
510                     List<Lp> lpList = ltRefListE.getLp();
511                     if (lpList == null) {
512                         LOG.debug("DBRead NE-Interfaces Reference List: null");
513                     } else {
514                         for (Lp ltp : lpList) {
515                             //// LayerProtocolName layerProtocolName = lpListE.getLayerProtocolName();
516                             // UniversalId uuId = lpListE.getUuid();
517                             res.add(ltp);
518                         }
519                     }
520                 }
521             }
522         } else {
523             LOG.debug("DBRead NE: null");
524         }
525
526         // ---- Debug
527         if (LOG.isDebugEnabled()) {
528             StringBuffer strBuf = new StringBuffer();
529             for (Lp ltp : res) {
530                 if (strBuf.length() > 0) {
531                     strBuf.append(", ");
532                 }
533                 strBuf.append(ltp.getLayerProtocolName().getValue());
534                 strBuf.append(':');
535                 strBuf.append(ltp.getUuid().getValue());
536             }
537             LOG.debug("DBRead NE-Interfaces: {}", strBuf.toString());
538         }
539         // ---- Debug end
540
541         return res;
542     }
543
544
545     @Nonnull
546     private List<? extends OtnHistoryDataG> readTheHistoricalPerformanceData(Lp lp) {
547         ONFLayerProtocolName lpName = ONFLayerProtocolName.valueOf(lp.getLayerProtocolName());
548
549         return this.microwaveModel.readTheHistoricalPerformanceData(lpName, lp);
550         /*
551          * switch (lpName) { case MWAirInterface: return
552          * readTheHistoricalPerformanceDataOfMwAirInterfacePac(lp);
553          *
554          * case EthernetContainer12: return readTheHistoricalPerformanceDataOfEthernetContainer(lp);
555          *
556          * case EthernetContainer10: case EthernetPhysical: case Ethernet: case TDMContainer: case
557          * Structure: case Unknown: LOG.debug("Do not read HistoricalPM data for {} {}", lpName,
558          * lp.getUuid().getValue()); break; } return new ArrayList<>();
559          */
560     }
561
562     @Override
563     public AllPm getHistoricalPM() {
564
565         synchronized (pmLock) {
566             if (pmLp != null) {
567                 LOG.debug("Enter query PM");
568                 AllPm allPm = new AllPm();
569                 Lp lp = pmLp;
570
571                 List<? extends OtnHistoryDataG> resultList = readTheHistoricalPerformanceData(lp);
572                 LOG.debug("Got records: {}", resultList.size());
573                 // org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.g._874._1.model.rev170320.GranularityPeriodType
574                 GranularityPeriodType granularityPeriod;
575                 for (OtnHistoryDataG perf : resultList) {
576
577                     granularityPeriod = perf.getGranularityPeriod();
578                     if (granularityPeriod == null) {
579                         granularityPeriod = GranularityPeriodType.Unknown;
580                     }
581
582                     switch (granularityPeriod) {
583                         case Period15Min: {
584                             EsHistoricalPerformance15Minutes pm =
585                                     new EsHistoricalPerformance15Minutes(getMountPointNodeName(), lp)
586                                             .setHistoricalRecord15Minutes(perf);
587                             allPm.add(pm);
588                         }
589                             break;
590
591                         case Period24Hours: {
592                             EsHistoricalPerformance24Hours pm =
593                                     new EsHistoricalPerformance24Hours(getMountPointNodeName(), lp)
594                                             .setHistoricalRecord24Hours(perf);
595                             LOG.debug("Write 24h write to DB");
596                             allPm.add(pm);
597                         }
598                             break;
599
600                         default:
601                             LOG.warn("Unknown granularity {}", perf.getGranularityPeriod());
602                             break;
603
604                     }
605                 }
606                 LOG.debug("Deliver normalized records: {}", allPm.size());
607                 return allPm;
608             } else {
609                 LOG.debug("Deliver empty, no LTP");
610                 return AllPm.getEmpty();
611             }
612         }
613     }
614
615     @Override
616     public void resetPMIterator() {
617         synchronized (pmLock) {
618             interfaceListIterator = interfaceList.iterator();
619         }
620         LOG.debug("PM reset iterator");
621     }
622
623     @Override
624     public boolean hasNext() {
625         boolean res;
626         synchronized (pmLock) {
627             res = interfaceListIterator != null ? interfaceListIterator.hasNext() : false;
628         }
629         LOG.debug("PM hasNext LTP {}", res);
630         return res;
631     }
632
633     @Override
634     public void next() {
635         synchronized (pmLock) {
636             if (interfaceListIterator == null) {
637                 pmLp = null;
638                 LOG.debug("PM next LTP null");
639             } else {
640                 pmLp = interfaceListIterator.next();
641                 LOG.debug("PM next LTP {}", pmLp.getLayerProtocolName().getValue());
642             }
643         }
644     }
645
646     @Override
647     public String pmStatusToString() {
648         StringBuffer res = new StringBuffer();
649         synchronized (pmLock) {
650             res.append(pmLp == null ? "no interface" : pmLp.getLayerProtocolName().getValue());
651             for (Lp lp : interfaceList) {
652                 res.append("IF:");
653                 res.append(lp.getLayerProtocolName().getValue());
654                 res.append(" ");
655             }
656         }
657         return res.toString();
658     }
659
660     /**
661      * Remove all entries from list
662      */
663     @Override
664     public int removeAllCurrentProblemsOfNode() {
665         return microwaveEventListener.removeAllCurrentProblemsOfNode();
666     }
667
668     /**
669      * Register the listener
670      */
671     @Override
672     public void doRegisterMicrowaveEventListener(MountPoint mountPoint) {
673         LOG.info("End registration listener for Mountpoint {}", mountPoint.getIdentifier().toString());
674         final Optional<NotificationService> optionalNotificationService =
675                 mountPoint.getService(NotificationService.class);
676         final NotificationService notificationService = optionalNotificationService.get();
677         // notificationService.registerNotificationListener(microwaveEventListener);
678         listenerRegistrationresult =
679                 notificationService.registerNotificationListener(microwaveModel.getNotificationListener());
680         LOG.info("End registration listener for Mountpoint {} Listener: {} Result: {}",
681                 mountPoint.getIdentifier().toString(), optionalNotificationService, listenerRegistrationresult);
682     }
683
684
685     /*------------------------------------------------------------
686      * private function to access database
687      */
688
689     /*-----------------------------------------------------------------------------
690      * Reading problems for the networkElement V1.2
691      */
692
693     private List<ProblemNotificationXml> readNetworkElementCurrentProblems12(List<ProblemNotificationXml> resultList) {
694
695         LOG.info("DBRead Get {} NetworkElementCurrentProblems12", getMountPointNodeName());
696
697         InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac> networkElementCurrentProblemsIID =
698                 InstanceIdentifier.builder(
699                         org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.NetworkElementPac.class)
700                         .build();
701
702         // Step 2.3: read to the config data store
703         NetworkElementPac problemPac;
704         NetworkElementCurrentProblems problems;
705         try {
706             problemPac = GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
707                     networkElementCurrentProblemsIID);
708             problems = problemPac.getNetworkElementCurrentProblems();
709             if (problems == null) {
710                 LOG.debug("DBRead no NetworkElementCurrentProblems12");
711             } else if (problems.getCurrentProblemList() == null) {
712                 LOG.debug("DBRead empty CurrentProblemList12");
713             } else {
714                 for (org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.onf.core.model.conditional.packages.rev170402.network.element.current.problems.g.CurrentProblemList problem : problems
715                         .getCurrentProblemList()) {
716                     resultList.add(new ProblemNotificationXml(getMountPointNodeName(), problem.getObjectReference(),
717                             problem.getProblemName(), InternalSeverity.valueOf(problem.getProblemSeverity()),
718                             problem.getSequenceNumber().toString(),
719                             InternalDateAndTime.valueOf(problem.getTimeStamp())));
720                 }
721             }
722         } catch (Exception e) {
723             LOG.warn("DBRead {} NetworkElementCurrentProblems12 not supported. Message '{}' ", getMountPointNodeName(),
724                     e.getMessage());
725         }
726         return resultList;
727
728     }
729
730     @Override
731     public void close() throws Exception {
732         super.close();
733         if (listenerRegistrationresult != null) {
734             listenerRegistrationresult.close();
735         }
736     }
737
738
739
740
741 }