2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
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
31 * http://www.apache.org/licenses/LICENSE-2.0
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
37 * ============LICENSE_END==========================================================================
39 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
41 import java.util.Collections;
42 import java.util.List;
43 import java.util.concurrent.CopyOnWriteArrayList;
44 import org.eclipse.jdt.annotation.NonNull;
45 import org.eclipse.jdt.annotation.Nullable;
46 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
47 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
48 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider;
49 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.AaiProviderClient;
51 import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService;
52 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderImpl;
53 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient;
54 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor;
55 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorImpl;
56 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.DeviceManagerDatabaseNotificationService;
57 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.ODLEventListenerHandler;
58 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.RpcPushNotificationsHandler;
59 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ConnectionStatusHousekeepingService;
60 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementHouskeepingService;
61 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl;
62 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
63 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
64 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.DevicemanagerNature;
65 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration;
66 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
67 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory2;
68 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
69 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl;
70 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
71 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
72 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
73 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
74 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
75 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
76 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
77 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
78 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
79 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
80 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
81 import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl;
82 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
83 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
84 import org.opendaylight.mdsal.binding.api.DataBroker;
85 import org.opendaylight.mdsal.binding.api.MountPointService;
86 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
87 import org.opendaylight.mdsal.binding.api.RpcProviderService;
88 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
89 import org.slf4j.Logger;
90 import org.slf4j.LoggerFactory;
93 * Devicemanager - Handles startup and closedown of network element handlers for netconf session - Provide common
94 * services for network element specific components
96 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
98 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
99 private static final String APPLICATION_NAME = "DeviceManager";
100 private static final String MYDBKEYNAMEBASE = "SDN-Controller";
101 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
102 public static final long DATABASE_TIMEOUT_MS = 120 * 1000L;
104 @SuppressWarnings("unused")
105 private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
108 private DataBroker dataBroker;
109 private MountPointService mountPointService;
110 private RpcProviderService rpcProviderRegistry;
111 private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
112 private WebsocketManagerService websocketmanagerService;
113 private IEntityDataProvider iEntityDataProvider;
115 // Devicemanager common services for network element handler
116 private WebSocketServiceClientInternal webSocketService;
117 private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
118 private DeviceManagerApiServiceImpl rpcApiService;
119 private PerformanceManagerImpl performanceManager;
120 private DcaeProviderClient dcaeProviderClient;
121 private AaiProviderClient aaiProviderClient;
122 private DcaeForwarderImpl aotsDcaeForwarder;
123 private DeviceMonitor deviceMonitor;
124 private MaintenanceServiceImpl maintenanceService;
125 private DevicemanagerNotificationDelayService notificationDelayService;
126 private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
127 private ArchiveCleanService archiveCleanService;
128 private ConnectionStatusHousekeepingService housekeepingService;
129 private NetconfNodeStateService netconfNodeStateService;
130 private DataProvider dataProvider;
131 private VESCollectorServiceImpl vesCollectorServiceImpl;
134 private DeviceManagerNetconfConnectHandler deviceManagerNetconfConnectHandler;
137 private final List<NetworkElementFactory> factoryList;
139 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
141 ConfigurationFileRepresentation config;
142 private Boolean devicemanagerInitializationOk;
145 public DeviceManagerImpl() {
146 LOG.info("Creating provider for {}", APPLICATION_NAME);
147 this.devicemanagerInitializationOk = false;
148 this.factoryList = new CopyOnWriteArrayList<>();
150 this.dataBroker = null;
151 this.mountPointService = null;
152 this.rpcProviderRegistry = null;
153 this.clusterSingletonServiceProvider = null;
154 this.websocketmanagerService = null;
155 this.iEntityDataProvider = null;
157 this.webSocketService = null;
160 public void setDataBroker(DataBroker dataBroker) {
161 this.dataBroker = dataBroker;
164 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
165 this.rpcProviderRegistry = rpcProviderRegistry;
168 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {}
170 public void setMountPointService(MountPointService mountPointService) {
171 this.mountPointService = mountPointService;
174 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
175 this.clusterSingletonServiceProvider = clusterSingletonService;
178 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
179 this.netconfNodeStateService = netconfNodeStateService;
182 public void setWebsocketmanagerService(WebsocketManagerService websocketmanagerService) {
183 this.websocketmanagerService = websocketmanagerService;
186 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
187 this.iEntityDataProvider = iEntityDataProvider;
192 LOG.info("Session Initiated start {}", APPLICATION_NAME);
194 this.dataProvider = iEntityDataProvider.getDataProvider();
197 this.config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
199 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
201 // start service for device maintenance service
202 this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
205 this.webSocketService = new WebSocketServiceClientImpl(websocketmanagerService);
207 IEsConfig esConfig = iEntityDataProvider.getEsConfig();
209 this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
211 this.aaiProviderClient = new AaiProviderClient(config, this);
213 this.vesCollectorServiceImpl = new VESCollectorServiceImpl(config);
215 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
217 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
219 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
220 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
222 RpcPushNotificationsHandler rpcPushNotificationsHandler =
223 new RpcPushNotificationsHandler(webSocketService, dataProvider, aotsDcaeForwarder);
224 this.odlEventListenerHandler = new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService, dataProvider,
225 aotsDcaeForwarder, dataBroker);
226 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(),
227 clusterSingletonServiceProvider, dataProvider);
228 this.housekeepingService = new ConnectionStatusHousekeepingService(config, clusterSingletonServiceProvider,
229 this.dataBroker, dataProvider);
231 this.performanceManager = new PerformanceManagerImpl(60, this, dataProvider, config);
233 // DeviceMonitor has to be available before netconfSubscriptionManager is
235 LOG.debug("start DeviceMonitor Service");
236 this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
238 // ResyncNetworkElementHouskeepingService
239 this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(this,
240 mountPointService, odlEventListenerHandler, dataProvider, deviceMonitor);
242 // RPC Service for specific services
244 LOG.debug("start rpc service");
245 this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
246 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
248 // netconfSubscriptionManager should be the last one because this is a callback
251 LOG.debug("start NetconfSubscriptionManager Service");
252 this.deviceManagerNetconfConnectHandler = new DeviceManagerNetconfConnectHandler(netconfNodeStateService,
253 clusterSingletonServiceProvider, odlEventListenerHandler, deviceMonitor, this, factoryList);
255 writeToEventLog(APPLICATION_NAME, "startup", "done");
256 this.devicemanagerInitializationOk = true;
258 LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
262 public void close() {
263 LOG.info("DeviceManagerImpl closing ...");
264 close(performanceManager);
265 close(dcaeProviderClient);
266 close(aotsDcaeForwarder);
267 close(aaiProviderClient);
268 close(deviceMonitor);
269 close(maintenanceService);
270 close(rpcApiService);
271 close(notificationDelayService);
272 close(archiveCleanService);
273 close(housekeepingService);
274 close(deviceManagerNetconfConnectHandler);
275 close(vesCollectorServiceImpl);
276 LOG.info("DeviceManagerImpl closing done");
280 synchronized public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerBindingNetworkElementFactory(
281 @NonNull final L factory) {
282 LOG.debug("Factory registration {}", factory.getClass().getName());
284 factoryList.add(factory);
285 Collections.sort(factoryList, (a,b) -> DevicemanagerNature.compareTo(a, b) );
286 factory.init(getServiceProvider());
287 return new FactoryRegistration<L>() {
290 public @NonNull L getInstance() {
295 public void close() {
296 factoryList.remove(factory);
302 private DevicemanagerNature getNature(NetworkElementFactory a) {
303 return (a instanceof NetworkElementFactory2) ? ((NetworkElementFactory2)a).getDevicemanagerNature()
304 : DevicemanagerNature.NETWORKELEMENT_FACTORY_DEFAULT;
308 public @NonNull DataProvider getDataProvider() {
309 return this.dataProvider;
312 @SuppressWarnings("null")
314 public @NonNull NotificationService getNotificationService() {
315 return this.deviceManagerDatabaseAndNotificationService;
318 @SuppressWarnings("null")
320 public @NonNull FaultService getFaultService() {
321 return this.deviceManagerDatabaseAndNotificationService;
324 @SuppressWarnings("null")
326 public @NonNull EquipmentService getEquipmentService() {
327 return this.deviceManagerDatabaseAndNotificationService;
330 @SuppressWarnings("null")
332 public @NonNull AaiService getAaiService() {
333 return this.aaiProviderClient;
336 @SuppressWarnings("null")
338 public @NonNull MaintenanceService getMaintenanceService() {
339 return this.maintenanceService;
342 @SuppressWarnings("null")
344 public @NonNull PerformanceManager getPerformanceManagerService() {
345 return this.performanceManager;
348 @SuppressWarnings("null")
350 public @NonNull EventHandlingService getEventHandlingService() {
351 return this.odlEventListenerHandler;
354 @SuppressWarnings("null")
356 public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() {
360 // Deviceinitialization
363 * Used to close all Services, that should support AutoCloseable Pattern
367 private void close(AutoCloseable... toCloseList) {
368 for (AutoCloseable element : toCloseList) {
369 if (element != null) {
372 } catch (Exception e) {
373 LOG.warn("Problem during close {}", e);
379 /*-------------------------------------------------------------------------------------------
383 public ArchiveCleanService getArchiveCleanService() {
384 return this.archiveCleanService;
387 public DataProvider getDatabaseClientEvents() {
392 public DeviceManagerServiceProvider getServiceProvider() {
397 * Indication if init() of devicemanager successfully done.
399 * @return true if init() was sucessfull. False if not done or not successfull.
401 public boolean isDevicemanagerInitializationOk() {
402 return this.devicemanagerInitializationOk;
406 * Get NE object. Used by DCAE Service
408 * @param mountpoint mount point name
409 * @return null or NE specific data
411 public @Nullable NetworkElement getConnectedNeByMountpoint(String mountpoint) {
413 return this.deviceManagerNetconfConnectHandler.getConnectedNeByMountpoint(mountpoint);
418 public void writeToEventLog(String objectId, String msg, String value) {
419 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);
423 public @NonNull VESCollectorService getVESCollectorService() {
424 return this.vesCollectorServiceImpl;
428 public WebsocketManagerService getWebsocketService() {
429 return this.websocketmanagerService;