a06e4a6013e28b6bd660dc683ce6b450545cdf37
[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.List;
21
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container.Capabilities;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.util.GenericTransactionUtils;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayService;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.ProviderClient;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.NetconfEventListener12;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.MaintenanceService;
35 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
36 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
37 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
38 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.extension.g.Extension;
39 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 /**
44  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and
45  * conditional packages.
46  *
47  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP),
48  * MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client),
49  * MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
50  * MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
51  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
52  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
53  *
54  * @author herbert
55  *
56  */
57 @SuppressWarnings("deprecation")
58 public class ONFCoreNetworkElement12 extends ONFCoreNetworkElement12Base
59         implements ONFCoreNetworkElementCallback, NotificationActor<AttributeValueChangedNotificationXml> {
60
61     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12.class);
62
63     /*-----------------------------------------------------------------------------
64      * Class members
65      */
66     private final @Nonnull NetconfEventListener12 netconfEventListener;
67     private final NotificationWorker<AttributeValueChangedNotificationXml> notificationQueue;
68
69     /*-----------------------------------------------------------------------------
70      * Construction
71      */
72
73     /**
74      * Constructor
75      *
76      * @param mountPointNodeName as String
77      * @param capabilities of the specific network element
78      * @param netconfNodeDataBroker for the network element specific data
79      * @param webSocketService to forward event notifications
80      * @param databaseService to access the database
81      * @param dcaeProvider to forward problem / change notifications
82      */
83     ONFCoreNetworkElement12(String mountPointNodeName, Capabilities capabilities,
84             DataBroker netconfNodeDataBroker, WebSocketServiceClient webSocketService,
85             HtDatabaseEventsService databaseService, ProviderClient dcaeProvider, @Nullable ProviderClient aotsmClient,
86             MaintenanceService maintenanceService,
87             NotificationDelayService<ProblemNotificationXml> notificationDelayService ) {
88
89         super(mountPointNodeName, netconfNodeDataBroker, capabilities);
90
91         this.netconfEventListener = new NetconfEventListener12(mountPointNodeName, webSocketService,
92                 databaseService, dcaeProvider, aotsmClient, maintenanceService, notificationDelayService, this);
93         this.notificationQueue = new NotificationWorker<>(1, 100, this);
94
95     }
96
97
98     /*-----------------------------------------------------------------------------
99      * Functions
100      */
101
102     /**
103      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
104      */
105     @Override
106     public void prepareCheck() {
107         synchronized (dmLock) {
108             boolean change = readNetworkElementAndInterfaces();
109             if (change) {
110                 int problems = netconfEventListener.removeAllCurrentProblemsOfNode();
111                 List<ProblemNotificationXml> resultList = readAllCurrentProblemsOfNode();
112                 netconfEventListener.initCurrentProblemStatus(resultList);
113                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountPointNodeName(),
114                         getUuId(), problems, resultList.size());
115             }
116         }
117     }
118
119     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
120     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
121
122     /*-----------------------------------------------------------------------------
123      * Synchronization
124      */
125
126     // public void initSynchronizationExtension() -> Shifted to super class
127     // private InstanceList readPTPClockInstances() -> Shifted to super class
128
129     /*-----------------------------------------------------------------------------
130      * Services for NE/Device synchronization
131      */
132
133     /**
134      * Handling of specific Notifications from NE, indicating changes and need for synchronization.
135      *
136      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
137      * <attribute-name>/equipment-pac/equipment-current-problems</attribute-name>
138      * <object-id-ref>CARD-1.1.1.0</object-id-ref> <new-value></new-value>
139      * </attribute-value-changed-notification>
140      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
141      * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
142      * <object-id-ref>Hybrid-Z</object-id-ref>
143      * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
144      * </attribute-value-changed-notification>
145      */
146
147
148     @Override
149     public void notificationFromNeListener(AttributeValueChangedNotificationXml notificationXml) {
150         notificationQueue.put(notificationXml);
151     }
152
153     @Override
154     public void notificationActor(AttributeValueChangedNotificationXml notificationXml) {
155
156         LOG.debug("Enter change notification listener");
157         if (LOG.isTraceEnabled()) {
158             LOG.trace("Notification: {}", notificationXml);
159         }
160         if (notificationXml.getAttributeName().equals("/equipment-pac/equipment-current-problems")) {
161             syncEquipmentPac(notificationXml.getObjectId());
162         } else if (notificationXml.getAttributeName()
163                 .equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
164             initialReadFromNetworkElement();
165         }
166         LOG.debug("Leave change notification listener");
167     }
168
169     /**
170      * Synchronize problems for a specific equipment-pac
171      *
172      * @param uuidString of the equipment-pac
173      */
174     private synchronized void syncEquipmentPac(String uuidString) {
175
176         int problems = netconfEventListener.removeObjectsCurrentProblemsOfNode(uuidString);
177         LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
178
179         List<ProblemNotificationXml> resultList = getEquipment().addProblemsofNodeObject(uuidString);
180         netconfEventListener.initCurrentProblemStatus(resultList);
181         LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
182
183     }
184
185
186     /*-----------------------------------------------------------------------------
187      * Problem/Fault related functions
188      */
189
190     /**
191      * Read during startup all relevant structure and status parameters from device
192      */
193     @Override
194     public synchronized void initialReadFromNetworkElement() {
195         // optionalNe.getLtp().get(0).getLp();
196         LOG.debug("Get info about {}", getMountPointNodeName());
197
198         int problems = netconfEventListener.removeAllCurrentProblemsOfNode();
199         LOG.debug("Removed all {} problems from database at registration", problems);
200
201         // Step 2.1: access data broker within this mount point
202         LOG.debug("DBRead start");
203
204         // Step 2.2: read ne from data store
205         readNetworkElementAndInterfaces();
206         getEquipment().readNetworkElementEquipment();
207
208         // Step 2.3: read the existing faults and add to DB
209         List<ProblemNotificationXml> resultList = readAllCurrentProblemsOfNode();
210         getEquipment().addProblemsofNode(resultList);
211
212         netconfEventListener.initCurrentProblemStatus(resultList);
213
214         netconfEventListener.writeEquipment(getEquipment());
215
216         LOG.info("Found info at {} for device {} number of problems: {}", getMountPointNodeName(), getUuId(),
217                 resultList.size());
218     }
219
220
221
222
223     /**
224      * Read the NetworkElement part from database.
225      *
226      * @return Optional with NetworkElement or empty
227      */
228     @Nullable
229     private NetworkElement readNetworkElement() {
230         // Step 2.2: construct data and the relative iid
231         // The schema path to identify an instance is
232         // <i>CoreModel-CoreNetworkModule-ObjectClasses/NetworkElement</i>
233         // Read to the config data store
234         return GenericTransactionUtils.readData(getNetconfNodeDataBroker(), LogicalDatastoreType.OPERATIONAL,
235                 NETWORKELEMENT_IID);
236     }
237
238     /**
239      * Read element from class that could be not available
240      *
241      * @param ltp layer termination point
242      * @return List with extension parameters or empty list
243      */
244     @Nonnull
245     private static List<Extension> getExtensionList(@Nullable Lp ltp) {
246         if (ltp != null && ltp.getExtension() != null) {
247             return ltp.getExtension();
248         } else {
249             return EMPTYLTPEXTENSIONLIST;
250         }
251     }
252
253     /**
254      * Remove all entries from list
255      */
256     @Override
257     public int removeAllCurrentProblemsOfNode() {
258         return netconfEventListener.removeAllCurrentProblemsOfNode();
259     }
260
261
262         @Override
263         public void close() throws Exception {
264         }
265
266 }