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