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