de6947dd4c6a7795d51e78bf073f8db435f0f663
[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
37  * conditional packages.
38  *
39  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP),
40  * MWAirInterfacePac, MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client),
41  * MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD), MWAirInterfaceDiversityPac,
42  * MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
43  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
44  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
45  *
46  * @author herbert
47  *
48  */
49 public class ONFCoreNetworkElement12Basic extends ONFCoreNetworkElement12Base {
50
51     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Basic.class);
52
53     /*-----------------------------------------------------------------------------
54      * Class members
55      */
56     private final @NonNull FaultService faultService;
57     private final @NonNull EquipmentService equipmentService;
58     private final @NonNull MaintenanceService maintenanceService;
59     private final @NonNull AaiService aaiProviderClient;
60     private final @NonNull PerformanceManager performanceManager;
61     private final @NonNull EventHandlingService eventListenerHandler;
62
63
64     private final @NonNull String mountPointNodeName;
65     private final @NonNull NetconfAccessor acessor;
66     private final @NonNull DeviceManagerOnfConfiguration pollAlarmConfig;
67
68     /*-----------------------------------------------------------------------------
69      * Construction
70      */
71
72     /**
73      * Basic element for netconf device with ONF Core model V1.2
74      * @param acessor to manage device connection
75      * @param serviceProvider to get devicemanager services
76      */
77     public ONFCoreNetworkElement12Basic(@NonNull NetconfAccessor acessor,
78             @NonNull DeviceManagerServiceProvider serviceProvider, DeviceManagerOnfConfiguration configuration) {
79
80         super(acessor);
81         this.mountPointNodeName = acessor.getNodeId().getValue();
82         this.acessor = acessor;
83         this.pollAlarmConfig = configuration;
84
85         this.faultService = serviceProvider.getFaultService();
86         this.equipmentService = serviceProvider.getEquipmentService();
87         this.maintenanceService = serviceProvider.getMaintenanceService();
88         this.aaiProviderClient = serviceProvider.getAaiService();
89         this.performanceManager = serviceProvider.getPerformanceManagerService();
90         this.eventListenerHandler = serviceProvider.getEventHandlingService();
91
92
93     }
94
95     /*-----------------------------------------------------------------------------
96      * Functions
97      */
98
99     /**
100      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
101      */
102     @Override
103     public void prepareCheck() {
104         synchronized (dmLock) {
105             boolean change = readNetworkElementAndInterfaces();
106             if (change || pollAlarmConfig.isPollAlarmsEnabled()) {
107                 int problems = faultService.removeAllCurrentProblemsOfNode(nodeId);
108                 FaultData resultList = readAllCurrentProblemsOfNode();
109                 faultService.initCurrentProblemStatus(nodeId, resultList);
110                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountpoint(),
111                         getUuId(), problems, resultList.size());
112             }
113         }
114     }
115
116     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
117     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
118
119     /*-----------------------------------------------------------------------------
120      * Synchronization
121      */
122
123     // public void initSynchronizationExtension() -> Shifted to super class
124     // private InstanceList readPTPClockInstances() -> Shifted to super class
125
126
127     /*-----------------------------------------------------------------------------
128      * Problem/Fault related functions
129      */
130
131     /**
132      * Read during startup all relevant structure and status parameters from device
133      */
134     @Override
135     public synchronized void initialReadFromNetworkElement() {
136
137         LOG.debug("Get info about {}", getMountpoint());
138
139         int problems = faultService.removeAllCurrentProblemsOfNode(nodeId);
140         LOG.debug("Removed all {} problems from database at registration", problems);
141
142         // Step 2.1: access data broker within this mount point
143         LOG.debug("DBRead start");
144
145         // Step 2.2: read ne from data store
146         readNetworkElementAndInterfaces();
147         equipment.readNetworkElementEquipment();
148
149         // Step 2.3: read the existing faults and add to DB
150         FaultData resultList = readAllCurrentProblemsOfNode();
151         equipment.addProblemsofNode(resultList);
152
153         faultService.initCurrentProblemStatus(nodeId, resultList);
154         equipmentService.writeEquipment(equipment.getEquipmentData());
155
156         LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
157                 resultList.size());
158     }
159
160     /**
161      * Remove all entries from list
162      */
163     @Override
164     public int removeAllCurrentProblemsOfNode() {
165         return faultService.removeAllCurrentProblemsOfNode(nodeId);
166     }
167
168     @Override
169     public void register() {
170
171         // Setup microwaveEventListener for notification service
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         // Close to be implemented
205     }
206
207
208     @Override
209     public NetworkElementDeviceType getDeviceType() {
210         return NetworkElementDeviceType.Optical;
211     }
212
213 }