19be0281a04129c7abade7a30dbd5f3e487f47d9
[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 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         LOG.debug("NETCONF read network element and interfaces completed");
147         equipment.readNetworkElementEquipment();
148         LOG.debug("NETCONF read equipment completed");
149
150         // Step 2.3: read the existing faults and add to DB
151         FaultData resultList = readAllCurrentProblemsOfNode();
152         LOG.debug("NETCONF read current problems completed");
153         equipment.addProblemsofNode(resultList);
154
155         faultService.initCurrentProblemStatus(nodeId, resultList);
156         LOG.debug("DB write current problems completed");
157
158         equipmentService.writeEquipment(equipment.getEquipmentData());
159
160         LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
161                 resultList.size());
162     }
163
164     /**
165      * Remove all entries from list
166      */
167     @Override
168     public int removeAllCurrentProblemsOfNode() {
169         return faultService.removeAllCurrentProblemsOfNode(nodeId);
170     }
171
172     @Override
173     public void register() {
174
175         // Setup microwaveEventListener for notification service
176         doRegisterEventListener(acessor.getMountpoint());
177
178         // Register netconf stream
179         acessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
180
181         // -- Read data from NE
182         initialReadFromNetworkElement();
183
184         // create automatic empty maintenance entry into db before reading and listening
185         // for problems
186         maintenanceService.createIfNotExists(mountPointNodeName);
187
188         aaiProviderClient.onDeviceRegistered(mountPointNodeName);
189         // -- Register NE to performance manager
190         performanceManager.registration(mountPointNodeName, this);
191
192         //events will be already pushed by base devmgr (needs more clarification SDNC-1123)
193         //eventListenerHandler.registration(mountPointNodeName, acessor.getNetconfNode());
194         //LOG.debug("refresh necon entry for {} with type {} not",mountPointNodeName,this.getDeviceType());
195         //eventListenerHandler.connectIndication(mountPointNodeName, getDeviceType());
196         LOG.info("Starting Event listener finished. Added Netconf device:{} type:{}", mountPointNodeName,
197                 getDeviceType());
198
199     }
200
201
202     @Override
203     public void deregister() {
204         maintenanceService.deleteIfNotRequired(mountPointNodeName);
205         performanceManager.deRegistration(mountPointNodeName);
206         aaiProviderClient.onDeviceUnregistered(mountPointNodeName);
207     }
208
209     @Override
210     public void close() throws Exception {
211         // Close to be implemented
212     }
213
214
215     @Override
216     public NetworkElementDeviceType getDeviceType() {
217         return NetworkElementDeviceType.Optical;
218     }
219
220 }