fb73b823ee57e3bec692ee98a7fda0c2d24349e9
[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.onf.ne;
19
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
29 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and
36  * conditional packages.
37  *
38  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP),
39  * MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client),
40  * MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
41  * MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
42  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
43  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
44  *
45  * @author herbert
46  *
47  */
48 public class ONFCoreNetworkElement12Basic extends ONFCoreNetworkElement12Base {
49
50     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Basic.class);
51
52     /*-----------------------------------------------------------------------------
53      * Class members
54      */
55     private final @NonNull FaultService faultService;
56     private final @NonNull EquipmentService equipmentService;
57     private final @NonNull MaintenanceService maintenanceService;
58     private final @NonNull AaiService aaiProviderClient;
59     private final @NonNull PerformanceManager performanceManager;
60     private final @NonNull EventHandlingService eventListenerHandler;
61
62
63     private final @NonNull String mountPointNodeName;
64     private final @NonNull NetconfAccessor acessor;
65
66     /*-----------------------------------------------------------------------------
67      * Construction
68      */
69
70     /**
71      * Basic element for netconf device with ONF Core model V1.2
72      * @param acessor to manage device connection
73      * @param serviceProvider to get devicemanager services
74      */
75     public ONFCoreNetworkElement12Basic(@NonNull NetconfAccessor acessor,
76             @NonNull DeviceManagerServiceProvider serviceProvider) {
77
78         super(acessor);
79         this.mountPointNodeName = acessor.getNodeId().getValue();
80         this.acessor = acessor;
81
82         this.faultService = serviceProvider.getFaultService();
83         this.equipmentService = serviceProvider.getEquipmentService();
84         this.maintenanceService = serviceProvider.getMaintenanceService();
85         this.aaiProviderClient = serviceProvider.getAaiService();
86         this.performanceManager = serviceProvider.getPerformanceManagerService();
87         this.eventListenerHandler = serviceProvider.getEventHandlingService();
88
89
90     }
91
92     /*-----------------------------------------------------------------------------
93      * Functions
94      */
95
96     /**
97      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
98      */
99     @Override
100     public void prepareCheck() {
101         synchronized (dmLock) {
102             boolean change = readNetworkElementAndInterfaces();
103             if (change) {
104                 int problems = faultService.removeAllCurrentProblemsOfNode(nodeId);
105                 FaultData resultList = readAllCurrentProblemsOfNode();
106                 faultService.initCurrentProblemStatus(nodeId, resultList);
107                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountPointNodeName(),
108                         getUuId(), problems, resultList.size());
109             }
110         }
111     }
112
113     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
114     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
115
116     /*-----------------------------------------------------------------------------
117      * Synchronization
118      */
119
120     // public void initSynchronizationExtension() -> Shifted to super class
121     // private InstanceList readPTPClockInstances() -> Shifted to super class
122
123
124     /*-----------------------------------------------------------------------------
125      * Problem/Fault related functions
126      */
127
128     /**
129      * Read during startup all relevant structure and status parameters from device
130      */
131     @Override
132     public synchronized void initialReadFromNetworkElement() {
133         // optionalNe.getLtp().get(0).getLp();
134         LOG.debug("Get info about {}", getMountPointNodeName());
135
136         int problems = faultService.removeAllCurrentProblemsOfNode(nodeId);
137         LOG.debug("Removed all {} problems from database at registration", problems);
138
139         // Step 2.1: access data broker within this mount point
140         LOG.debug("DBRead start");
141
142         // Step 2.2: read ne from data store
143         readNetworkElementAndInterfaces();
144         equipment.readNetworkElementEquipment();
145
146         // Step 2.3: read the existing faults and add to DB
147         FaultData resultList = readAllCurrentProblemsOfNode();
148         equipment.addProblemsofNode(resultList);
149
150         faultService.initCurrentProblemStatus(nodeId, resultList);
151         equipmentService.writeEquipment(equipment.getEquipmentData());
152
153         LOG.info("Found info at {} for device {} number of problems: {}", getMountPointNodeName(), getUuId(),
154                 resultList.size());
155     }
156
157     /**
158      * Remove all entries from list
159      */
160     @Override
161     public int removeAllCurrentProblemsOfNode() {
162         return faultService.removeAllCurrentProblemsOfNode(nodeId);
163     }
164
165     @Override
166     public void register() {
167
168         // Setup microwaveEventListener for notification service
169         // MicrowaveEventListener microwaveEventListener = new
170         // MicrowaveEventListener(mountPointNodeName, websocketmanagerService,
171         // xmlMapper, databaseClientEvents);
172         doRegisterEventListener(acessor.getMountpoint());
173
174         // Register netconf stream
175         acessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
176
177         // -- Read data from NE
178         initialReadFromNetworkElement();
179
180         // create automatic empty maintenance entry into db before reading and listening
181         // for problems
182         maintenanceService.createIfNotExists(mountPointNodeName);
183
184         aaiProviderClient.onDeviceRegistered(mountPointNodeName);
185         // -- Register NE to performance manager
186         performanceManager.registration(mountPointNodeName, this);
187
188         eventListenerHandler.registration(mountPointNodeName, acessor.getNetconfNode());
189         eventListenerHandler.connectIndication(mountPointNodeName, getDeviceType());
190         LOG.info("Starting Event listener finished. Added Netconf device:{} type:{}", mountPointNodeName, getDeviceType());
191
192     }
193
194
195     @Override
196     public void deregister() {
197         maintenanceService.deleteIfNotRequired(mountPointNodeName);
198         performanceManager.deRegistration(mountPointNodeName);
199         aaiProviderClient.onDeviceUnregistered(mountPointNodeName);
200     }
201
202     @Override
203     public void close() throws Exception {
204     }
205
206
207     @Override
208     public NetworkElementDeviceType getDeviceType() {
209         return NetworkElementDeviceType.Optical;
210     }
211
212 }