881f6b415835cdf446cf18ad10ad62b69d128bd3
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 /*
23  * ============LICENSE_START========================================================================
24  * ONAP : ccsdk feature sdnr wt
25  * =================================================================================================
26  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
27  * =================================================================================================
28  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
29  * in compliance with the License. You may obtain a copy of the License at
30  *
31  * http://www.apache.org/licenses/LICENSE-2.0
32  *
33  * Unless required by applicable law or agreed to in writing, software distributed under the License
34  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
35  * or implied. See the License for the specific language governing permissions and limitations under
36  * the License.
37  * ============LICENSE_END==========================================================================
38  */
39 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
40
41 import java.util.List;
42 import java.util.concurrent.CopyOnWriteArrayList;
43 import org.eclipse.jdt.annotation.NonNull;
44 import org.eclipse.jdt.annotation.Nullable;
45 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
46 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
47 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider;
48 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig;
49 import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.AaiProviderClient;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService;
51 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderImpl;
52 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient;
53 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor;
54 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorImpl;
55 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.DeviceManagerDatabaseNotificationService;
56 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.ODLEventListenerHandler;
57 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.RpcPushNotificationsHandler;
58 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ConnectionStatusHousekeepingService;
59 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementHouskeepingService;
60 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl;
61 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
62 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
63 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration;
64 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
65 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
66 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl;
67 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
68 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
69 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
70 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
71 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
72 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
73 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
74 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
75 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
76 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
77 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
78 import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl;
79 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
80 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
81 import org.opendaylight.mdsal.binding.api.DataBroker;
82 import org.opendaylight.mdsal.binding.api.MountPointService;
83 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
84 import org.opendaylight.mdsal.binding.api.RpcProviderService;
85 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
86 import org.slf4j.Logger;
87 import org.slf4j.LoggerFactory;
88
89 /**
90  * Devicemanager - Handles startup and closedown of network element handlers for netconf session - Provide common
91  * services for network element specific components
92  */
93 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
94
95     private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
96     private static final String APPLICATION_NAME = "DeviceManager";
97     private static final String MYDBKEYNAMEBASE = "SDN-Controller";
98     private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
99     public static final long DATABASE_TIMEOUT_MS = 120 * 1000L;
100
101     @SuppressWarnings("unused")
102     private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
103
104     // MDSAL Services
105     private DataBroker dataBroker;
106     private MountPointService mountPointService;
107     private RpcProviderService rpcProviderRegistry;
108     private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
109     private WebsocketManagerService websocketmanagerService;
110     private IEntityDataProvider iEntityDataProvider;
111
112     // Devicemanager common services for network element handler
113     private WebSocketServiceClientInternal webSocketService;
114     private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
115     private DeviceManagerApiServiceImpl rpcApiService;
116     private PerformanceManagerImpl performanceManager;
117     private DcaeProviderClient dcaeProviderClient;
118     private AaiProviderClient aaiProviderClient;
119     private DcaeForwarderImpl aotsDcaeForwarder;
120     private DeviceMonitor deviceMonitor;
121     private MaintenanceServiceImpl maintenanceService;
122     private DevicemanagerNotificationDelayService notificationDelayService;
123     private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
124     private ArchiveCleanService archiveCleanService;
125     private ConnectionStatusHousekeepingService housekeepingService;
126     private NetconfNodeStateService netconfNodeStateService;
127     private DataProvider dataProvider;
128     private VESCollectorServiceImpl vesCollectorServiceImpl;
129
130     // Handler
131     private DeviceManagerNetconfConnectHandler deviceManagerNetconfConnectHandler;
132
133     // Attributes
134     private final List<NetworkElementFactory> factoryList;
135
136     private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
137
138     ConfigurationFileRepresentation config;
139     private Boolean devicemanagerInitializationOk;
140
141     // Blueprint 1
142     public DeviceManagerImpl() {
143         LOG.info("Creating provider for {}", APPLICATION_NAME);
144         this.devicemanagerInitializationOk = false;
145         this.factoryList = new CopyOnWriteArrayList<>();
146
147         this.dataBroker = null;
148         this.mountPointService = null;
149         this.rpcProviderRegistry = null;
150         this.clusterSingletonServiceProvider = null;
151         this.websocketmanagerService = null;
152         this.iEntityDataProvider = null;
153
154         this.webSocketService = null;
155     }
156
157     public void setDataBroker(DataBroker dataBroker) {
158         this.dataBroker = dataBroker;
159     }
160
161     public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
162         this.rpcProviderRegistry = rpcProviderRegistry;
163     }
164
165     public void setNotificationPublishService(NotificationPublishService notificationPublishService) {}
166
167     public void setMountPointService(MountPointService mountPointService) {
168         this.mountPointService = mountPointService;
169     }
170
171     public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
172         this.clusterSingletonServiceProvider = clusterSingletonService;
173     }
174
175     public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
176         this.netconfNodeStateService = netconfNodeStateService;
177     }
178
179     public void setWebsocketmanagerService(WebsocketManagerService websocketmanagerService) {
180         this.websocketmanagerService = websocketmanagerService;
181     }
182
183     public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
184         this.iEntityDataProvider = iEntityDataProvider;
185     }
186
187     public void init() {
188
189         LOG.info("Session Initiated start {}", APPLICATION_NAME);
190
191         this.dataProvider = iEntityDataProvider.getDataProvider();
192
193         // Get configuration
194         this.config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
195
196         this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
197
198         // start service for device maintenance service
199         this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
200
201         // Websockets
202         this.webSocketService = new WebSocketServiceClientImpl(websocketmanagerService);
203
204         IEsConfig esConfig = iEntityDataProvider.getEsConfig();
205         // DCAE
206         this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
207
208         this.aaiProviderClient = new AaiProviderClient(config, this);
209
210         this.vesCollectorServiceImpl = new VESCollectorServiceImpl(config);
211         // EM
212         String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
213
214         this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
215
216         this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
217                 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
218
219         RpcPushNotificationsHandler rpcPushNotificationsHandler =
220                 new RpcPushNotificationsHandler(webSocketService, dataProvider, aotsDcaeForwarder);
221         this.odlEventListenerHandler = new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService, dataProvider,
222                 aotsDcaeForwarder, dataBroker);
223         this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(),
224                 clusterSingletonServiceProvider, dataProvider);
225         this.housekeepingService = new ConnectionStatusHousekeepingService(config, clusterSingletonServiceProvider,
226                 this.dataBroker, dataProvider);
227         // PM
228         this.performanceManager = new PerformanceManagerImpl(60, this, dataProvider, config);
229         // DM
230         // DeviceMonitor has to be available before netconfSubscriptionManager is
231         // configured
232         LOG.debug("start DeviceMonitor Service");
233         this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
234
235         // ResyncNetworkElementHouskeepingService
236         this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(this,
237                 mountPointService, odlEventListenerHandler, dataProvider, deviceMonitor);
238
239         // RPC Service for specific services
240         // Start RPC Service
241         LOG.debug("start rpc service");
242         this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
243                 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
244
245         // netconfSubscriptionManager should be the last one because this is a callback
246
247         // service
248         LOG.debug("start NetconfSubscriptionManager Service");
249         this.deviceManagerNetconfConnectHandler = new DeviceManagerNetconfConnectHandler(netconfNodeStateService,
250                 clusterSingletonServiceProvider, odlEventListenerHandler, deviceMonitor, this, factoryList);
251
252         writeToEventLog(APPLICATION_NAME, "startup", "done");
253         this.devicemanagerInitializationOk = true;
254
255         LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
256     }
257
258     @Override
259     public void close() {
260         LOG.info("DeviceManagerImpl closing ...");
261         close(performanceManager);
262         close(dcaeProviderClient);
263         close(aotsDcaeForwarder);
264         close(aaiProviderClient);
265         close(deviceMonitor);
266         close(maintenanceService);
267         close(rpcApiService);
268         close(notificationDelayService);
269         close(archiveCleanService);
270         close(housekeepingService);
271         close(deviceManagerNetconfConnectHandler);
272         close(vesCollectorServiceImpl);
273         LOG.info("DeviceManagerImpl closing done");
274     }
275
276     @Override
277     public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerBindingNetworkElementFactory(
278             @NonNull final L factory) {
279         LOG.debug("Factory registration {}", factory.getClass().getName());
280
281         factoryList.add(factory);
282         factory.init(getServiceProvider());
283         return new FactoryRegistration<L>() {
284
285             @Override
286             public @NonNull L getInstance() {
287                 return factory;
288             }
289
290             @Override
291             public void close() {
292                 factoryList.remove(factory);
293             }
294
295         };
296     }
297
298     @SuppressWarnings("null")
299     @Override
300     public @NonNull DataProvider getDataProvider() {
301         return this.dataProvider;
302     }
303
304     @SuppressWarnings("null")
305     @Override
306     public @NonNull NotificationService getNotificationService() {
307         return this.deviceManagerDatabaseAndNotificationService;
308     }
309
310     @SuppressWarnings("null")
311     @Override
312     public @NonNull FaultService getFaultService() {
313         return this.deviceManagerDatabaseAndNotificationService;
314     }
315
316     @SuppressWarnings("null")
317     @Override
318     public @NonNull EquipmentService getEquipmentService() {
319         return this.deviceManagerDatabaseAndNotificationService;
320     }
321
322     @SuppressWarnings("null")
323     @Override
324     public @NonNull AaiService getAaiService() {
325         return this.aaiProviderClient;
326     }
327
328     @SuppressWarnings("null")
329     @Override
330     public @NonNull MaintenanceService getMaintenanceService() {
331         return this.maintenanceService;
332     }
333
334     @SuppressWarnings("null")
335     @Override
336     public @NonNull PerformanceManager getPerformanceManagerService() {
337         return this.performanceManager;
338     }
339
340     @SuppressWarnings("null")
341     @Override
342     public @NonNull EventHandlingService getEventHandlingService() {
343         return this.odlEventListenerHandler;
344     }
345
346     @SuppressWarnings("null")
347     @Override
348     public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() {
349         return this.config;
350     }
351
352     // Deviceinitialization
353
354     /**
355      * Used to close all Services, that should support AutoCloseable Pattern
356      *
357      * @param toClose
358      */
359     private void close(AutoCloseable... toCloseList) {
360         for (AutoCloseable element : toCloseList) {
361             if (element != null) {
362                 try {
363                     element.close();
364                 } catch (Exception e) {
365                     LOG.warn("Problem during close {}", e);
366                 }
367             }
368         }
369     }
370
371     /*-------------------------------------------------------------------------------------------
372      * Functions
373      */
374
375     public ArchiveCleanService getArchiveCleanService() {
376         return this.archiveCleanService;
377     }
378
379     public DataProvider getDatabaseClientEvents() {
380         return dataProvider;
381     }
382
383     @Override
384     public DeviceManagerServiceProvider getServiceProvider() {
385         return this;
386     }
387
388     /**
389      * Indication if init() of devicemanager successfully done.
390      *
391      * @return true if init() was sucessfull. False if not done or not successfull.
392      */
393     public boolean isDevicemanagerInitializationOk() {
394         return this.devicemanagerInitializationOk;
395     }
396
397     /**
398      * Get NE object. Used by DCAE Service
399      *
400      * @param mountpoint mount point name
401      * @return null or NE specific data
402      */
403     public @Nullable NetworkElement getConnectedNeByMountpoint(String mountpoint) {
404
405         return this.deviceManagerNetconfConnectHandler.getConnectedNeByMountpoint(mountpoint);
406
407     }
408
409     @Override
410     public void writeToEventLog(String objectId, String msg, String value) {
411         this.odlEventListenerHandler.writeEventLog(objectId, msg, value);
412     }
413
414     @Override
415     public @NonNull VESCollectorService getVESCollectorService() {
416         return this.vesCollectorServiceImpl;
417     }
418
419     @Override
420     public WebsocketManagerService getWebsocketService() {
421         return this.websocketmanagerService;
422     }
423
424
425 }