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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
20 import java.util.List;
21 import java.util.concurrent.ConcurrentHashMap;
22 import java.util.concurrent.CopyOnWriteArrayList;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
27 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.AaiProviderClient;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderImpl;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorImpl;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.DeviceManagerDatabaseNotificationService;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.ODLEventListenerHandler;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.RpcPushNotificationsHandler;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ConnectionStatusHousekeepingService;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementHouskeepingService;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl2;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
45 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
46 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl;
47 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
48 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
49 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
51 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
52 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
53 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
54 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
55 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
56 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
57 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
58 import org.opendaylight.mdsal.binding.api.DataBroker;
59 import org.opendaylight.mdsal.binding.api.MountPointService;
60 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
61 import org.opendaylight.mdsal.binding.api.RpcProviderService;
62 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
63 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
70 * - Handles startup and closedown of network element handlers for netconf session
71 * - Provide common services for network element specific components
73 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
75 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
76 private static final String APPLICATION_NAME = "DeviceManager";
77 private static final String MYDBKEYNAMEBASE = "SDN-Controller";
78 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
79 public static final long DATABASE_TIMEOUT_MS = 120*1000L;
81 @SuppressWarnings("unused")
82 private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
85 private DataBroker dataBroker;
86 private MountPointService mountPointService;
87 private RpcProviderService rpcProviderRegistry;
88 private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
89 private WebsocketmanagerService websocketmanagerService;
90 private IEntityDataProvider iEntityDataProvider;
92 // Devicemanager common services for network element handler
93 private WebSocketServiceClientInternal webSocketService;
94 private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
95 private DeviceManagerApiServiceImpl rpcApiService;
96 private PerformanceManagerImpl performanceManager;
97 private DcaeProviderClient dcaeProviderClient;
98 private AaiProviderClient aaiProviderClient;
99 private DcaeForwarderImpl aotsDcaeForwarder;
100 private DeviceMonitor deviceMonitor;
101 private MaintenanceServiceImpl maintenanceService;
102 private DevicemanagerNotificationDelayService notificationDelayService;
103 private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
104 private ArchiveCleanService archiveCleanService;
105 private ConnectionStatusHousekeepingService housekeepingService;
106 private NetconfNodeStateService netconfNodeStateService;
107 private DataProvider dataProvider;
110 private DeviceManagerNetconfConnectHandler forTest;
113 private final ConcurrentHashMap<String, NetworkElement> networkElementRepresentations;
114 private final List<NetworkElementFactory> factoryList;
116 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
117 private ClusterSingletonServiceRegistration cssRegistration;
118 private ClusterSingletonServiceRegistration cssRegistration2;
121 private Boolean devicemanagerInitializationOk;
124 public DeviceManagerImpl() {
125 LOG.info("Creating provider for {}", APPLICATION_NAME);
126 this.devicemanagerInitializationOk = false;
127 this.factoryList = new CopyOnWriteArrayList<>();
128 this.networkElementRepresentations = new ConcurrentHashMap<>();
130 this.dataBroker = null;
131 this.mountPointService = null;
132 this.rpcProviderRegistry = null;
133 this.clusterSingletonServiceProvider = null;
134 this.websocketmanagerService = null;
135 this.iEntityDataProvider = null;
137 this.webSocketService = null;
140 public void setDataBroker(DataBroker dataBroker) {
141 this.dataBroker = dataBroker;
144 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
145 this.rpcProviderRegistry = rpcProviderRegistry;
148 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
151 public void setMountPointService(MountPointService mountPointService) {
152 this.mountPointService = mountPointService;
154 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
155 this.clusterSingletonServiceProvider = clusterSingletonService;
157 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
158 this.netconfNodeStateService = netconfNodeStateService;
160 public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) {
161 this.websocketmanagerService = websocketmanagerService;
163 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
164 this.iEntityDataProvider = iEntityDataProvider;
169 LOG.info("Session Initiated start {}", APPLICATION_NAME);
171 this.iEntityDataProvider.setReadyStatus(false);
173 this.dataProvider = iEntityDataProvider.getDataProvider(); // Get configuration
175 ConfigurationFileRepresentation config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
177 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
179 // start service for device maintenance service
180 this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
183 this.webSocketService = new WebSocketServiceClientImpl2(websocketmanagerService);
185 IEsConfig esConfig = iEntityDataProvider.getEsConfig();
187 this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
189 this.aaiProviderClient = new AaiProviderClient(config, this);
191 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
193 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
195 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
196 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
198 RpcPushNotificationsHandler rpcPushNotificationsHandler = new RpcPushNotificationsHandler(webSocketService,
199 dataProvider, aotsDcaeForwarder);
200 this.odlEventListenerHandler = new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService,
201 dataProvider, aotsDcaeForwarder);
202 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(), dataProvider);
203 this.housekeepingService = new ConnectionStatusHousekeepingService(this.dataBroker,
205 this.cssRegistration = this.clusterSingletonServiceProvider
206 .registerClusterSingletonService(this.archiveCleanService);
207 this.cssRegistration2 = this.clusterSingletonServiceProvider
208 .registerClusterSingletonService(this.housekeepingService);
210 this.performanceManager = new PerformanceManagerImpl(60, this, dataProvider, config);
212 // DeviceMonitor has to be available before netconfSubscriptionManager is
214 LOG.debug("start DeviceMonitor Service");
215 this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
217 // ResyncNetworkElementHouskeepingService
218 this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(
219 this, mountPointService, odlEventListenerHandler,
220 dataProvider, deviceMonitor);
222 // RPC Service for specific services
224 LOG.debug("start rpc service");
225 this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
226 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
228 // netconfSubscriptionManager should be the last one because this is a callback
231 LOG.debug("start NetconfSubscriptionManager Service");
232 this.forTest = new DeviceManagerNetconfConnectHandler(netconfNodeStateService, odlEventListenerHandler,
233 deviceMonitor, this, factoryList);
235 writeToEventLog(APPLICATION_NAME, "startup", "done");
236 this.devicemanagerInitializationOk = true;
238 LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
239 this.iEntityDataProvider.setReadyStatus(true);
244 public void close() {
245 LOG.info("DeviceManagerImpl closing ...");
246 close(performanceManager);
247 close(dcaeProviderClient);
248 close(aotsDcaeForwarder);
249 close(aaiProviderClient);
250 close(deviceMonitor);
251 close(maintenanceService);
252 close(rpcApiService);
253 close(notificationDelayService);
254 close(archiveCleanService);
255 close(housekeepingService);
257 close(cssRegistration, cssRegistration2);
258 LOG.info("DeviceManagerImpl closing done");
262 public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerNetworkElementFactory(@NonNull L factory) {
263 LOG.info("Factory registration {}", factory.getClass().getName());
265 factoryList.add(factory);
266 return new FactoryRegistration<L>() {
269 public @NonNull L getInstance() {
274 public void close() {
275 factoryList.remove(factory);
281 @SuppressWarnings("null")
283 public @NonNull DataProvider getDataProvider() {
284 return this.dataProvider;
287 @SuppressWarnings("null")
289 public @NonNull NotificationService getNotificationService() {
290 return this.deviceManagerDatabaseAndNotificationService;
293 @SuppressWarnings("null")
295 public @NonNull FaultService getFaultService() {
296 return this.deviceManagerDatabaseAndNotificationService;
299 @SuppressWarnings("null")
301 public @NonNull EquipmentService getEquipmentService() {
302 return this.deviceManagerDatabaseAndNotificationService;
305 @SuppressWarnings("null")
307 public @NonNull AaiService getAaiService() {
308 return this.aaiProviderClient;
311 @SuppressWarnings("null")
313 public @NonNull MaintenanceService getMaintenanceService() {
314 return this.maintenanceService;
317 @SuppressWarnings("null")
319 public @NonNull PerformanceManager getPerformanceManagerService() {
320 return this.performanceManager;
323 @SuppressWarnings("null")
325 public @NonNull EventHandlingService getEventHandlingService() {
326 return this.odlEventListenerHandler;
328 // Deviceinitialization
331 * Used to close all Services, that should support AutoCloseable Pattern
334 private void close(AutoCloseable... toCloseList) {
335 for (AutoCloseable element : toCloseList) {
336 if (element != null) {
339 } catch (Exception e) {
340 LOG.warn("Problem during close {}", e);
346 /*-------------------------------------------------------------------------------------------
350 public ArchiveCleanService getArchiveCleanService() {
351 return this.archiveCleanService;
354 public DataProvider getDatabaseClientEvents() {
359 public DeviceManagerServiceProvider getServiceProvider() {
364 * Indication if init() of devicemanager successfully done.
365 * @return true if init() was sucessfull. False if not done or not successfull.
367 public boolean isDevicemanagerInitializationOk() {
368 return this.devicemanagerInitializationOk;
372 * Get NE object. Used by DCAE Service
373 * @param mountpoint mount point name
374 * @return null or NE specific data
376 public @Nullable NetworkElement getNeByMountpoint(String mountpoint) {
378 return networkElementRepresentations.get(mountpoint);
383 public void writeToEventLog(String objectId, String msg, String value) {
384 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);