Removing blueprints-processor
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / base / onfcore / ONFCoreNetworkElement12Basic.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.base.onfcore;
19
20 import java.util.List;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.handler.NetconfEventListenerHandler12;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.AttributeValueChangedNotificationXml;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.NotificationDelayService;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
30 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.INetconfAcessor;
31 import org.opendaylight.mdsal.binding.api.DataBroker;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and
38  * conditional packages.
39  *
40  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP),
41  * MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client),
42  * MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
43  * MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
44  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
45  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
46  *
47  * @author herbert
48  *
49  */
50 public class ONFCoreNetworkElement12Basic extends ONFCoreNetworkElement12Base
51         implements ONFCoreNetworkElementCallback, NotificationActor<AttributeValueChangedNotificationXml> {
52
53     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Basic.class);
54
55     /*-----------------------------------------------------------------------------
56      * Class members
57      */
58     private final @NonNull NetconfEventListenerHandler12 netconfEventListener;
59     private final NotificationWorker<AttributeValueChangedNotificationXml> notificationQueue;
60
61     /*-----------------------------------------------------------------------------
62      * Construction
63      */
64
65     /**
66      * Constructor
67      *
68      * @param mountPointNodeName as String
69      * @param capabilities of the specific network element
70      * @param netconfNodeDataBroker for the network element specific data
71      * @param webSocketService to forward event notifications
72      * @param databaseService to access the database
73      * @param dcaeProvider to forward problem / change notifications
74      */
75     ONFCoreNetworkElement12Basic(INetconfAcessor acessor, String mountPointNodeName, Capabilities capabilities,
76             DataBroker netconfNodeDataBroker, WebSocketServiceClientInternal webSocketService,
77             DataProvider databaseService, DcaeForwarderInternal aotsDcaeForwarder,
78             NotificationDelayService<ProblemNotificationXml> notificationDelayService ) {
79
80         super(acessor, mountPointNodeName, netconfNodeDataBroker, capabilities);
81
82         this.netconfEventListener = new NetconfEventListenerHandler12(mountPointNodeName, webSocketService,
83                 databaseService, aotsDcaeForwarder, notificationDelayService, this);
84         this.notificationQueue = new NotificationWorker<>(1, 100, this);
85
86     }
87
88
89     /*-----------------------------------------------------------------------------
90      * Functions
91      */
92
93     /**
94      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
95      */
96     @Override
97     public void prepareCheck() {
98         synchronized (dmLock) {
99             boolean change = readNetworkElementAndInterfaces();
100             if (change) {
101                 int problems = netconfEventListener.removeAllCurrentProblemsOfNode();
102                 List<ProblemNotificationXml> resultList = readAllCurrentProblemsOfNode();
103                 netconfEventListener.initCurrentProblemStatus(resultList);
104                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountPointNodeName(),
105                         getUuId(), problems, resultList.size());
106             }
107         }
108     }
109
110     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
111     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
112
113     /*-----------------------------------------------------------------------------
114      * Synchronization
115      */
116
117     // public void initSynchronizationExtension() -> Shifted to super class
118     // private InstanceList readPTPClockInstances() -> Shifted to super class
119
120     /*-----------------------------------------------------------------------------
121      * Services for NE/Device synchronization
122      */
123
124     /**
125      * Handling of specific Notifications from NE, indicating changes and need for synchronization.
126      *
127      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
128      * <attribute-name>/equipment-pac/equipment-current-problems</attribute-name>
129      * <object-id-ref>CARD-1.1.1.0</object-id-ref> <new-value></new-value>
130      * </attribute-value-changed-notification>
131      * <attribute-value-changed-notification xmlns="urn:onf:params:xml:ns:yang:microwave-model">
132      * <attribute-name>/network-element/extension[value-name="top-level-equipment"]/value</attribute-name>
133      * <object-id-ref>Hybrid-Z</object-id-ref>
134      * <new-value>SHELF-1.1.0.0,IDU-1.55.0.0,ODU-1.56.0.0,IDU-1.65.0.0</new-value>
135      * </attribute-value-changed-notification>
136      */
137
138
139     @Override
140     public void notificationFromNeListener(AttributeValueChangedNotificationXml notificationXml) {
141         notificationQueue.put(notificationXml);
142     }
143
144     @Override
145     public void notificationActor(AttributeValueChangedNotificationXml notificationXml) {
146
147         LOG.debug("Enter change notification listener");
148         if (LOG.isTraceEnabled()) {
149             LOG.trace("Notification: {}", notificationXml);
150         }
151         if (notificationXml.getAttributeName().equals("/equipment-pac/equipment-current-problems")) {
152             syncEquipmentPac(notificationXml.getObjectId());
153         } else if (notificationXml.getAttributeName()
154                 .equals("/network-element/extension[value-name=\"top-level-equipment\"]/value")) {
155             initialReadFromNetworkElement();
156         }
157         LOG.debug("Leave change notification listener");
158     }
159
160     /**
161      * Synchronize problems for a specific equipment-pac
162      *
163      * @param uuidString of the equipment-pac
164      */
165     private synchronized void syncEquipmentPac(String uuidString) {
166
167         int problems = netconfEventListener.removeObjectsCurrentProblemsOfNode(uuidString);
168         LOG.debug("Removed {} problems for uuid {}", problems, uuidString);
169
170         List<ProblemNotificationXml> resultList = equipment.addProblemsofNodeObject(uuidString);
171         netconfEventListener.initCurrentProblemStatus(resultList);
172         LOG.debug("Added {} problems for uuid {}", resultList.size(), uuidString);
173
174     }
175
176
177     /*-----------------------------------------------------------------------------
178      * Problem/Fault related functions
179      */
180
181     /**
182      * Read during startup all relevant structure and status parameters from device
183      */
184     @Override
185     public synchronized void initialReadFromNetworkElement() {
186         // optionalNe.getLtp().get(0).getLp();
187         LOG.debug("Get info about {}", getMountPointNodeName());
188
189         int problems = netconfEventListener.removeAllCurrentProblemsOfNode();
190         LOG.debug("Removed all {} problems from database at registration", problems);
191
192         // Step 2.1: access data broker within this mount point
193         LOG.debug("DBRead start");
194
195         // Step 2.2: read ne from data store
196         readNetworkElementAndInterfaces();
197         equipment.readNetworkElementEquipment();
198
199         // Step 2.3: read the existing faults and add to DB
200         List<ProblemNotificationXml> resultList = readAllCurrentProblemsOfNode();
201         equipment.addProblemsofNode(resultList);
202
203         netconfEventListener.initCurrentProblemStatus(resultList);
204
205         netconfEventListener.writeEquipment(equipment);
206
207         LOG.info("Found info at {} for device {} number of problems: {}", getMountPointNodeName(), getUuId(),
208                 resultList.size());
209     }
210
211     /**
212      * Remove all entries from list
213      */
214     @Override
215     public int removeAllCurrentProblemsOfNode() {
216         return netconfEventListener.removeAllCurrentProblemsOfNode();
217     }
218
219
220     @Override
221     public void close() throws Exception {
222     }
223
224
225     @Override
226     public NetworkElementDeviceType getDeviceType() {
227         return NetworkElementDeviceType.Optical;
228     }
229
230 }