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.devicemanager.aaiconnector.impl.AaiProviderClient;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderImpl;
51 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient;
52 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor;
53 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorImpl;
54 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.DeviceManagerDatabaseNotificationService;
55 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.ODLEventListenerHandler;
56 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.RpcPushNotificationsHandler;
57 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ConnectionStatusHousekeepingService;
58 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementHouskeepingService;
59 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl;
60 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
61 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
62 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.DevicemanagerNature;
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.factory.NetworkElementFactory2;
66 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
67 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl;
68 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
69 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
70 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
71 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
72 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
73 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
74 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
75 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
76 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
77 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
78 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
79 import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl;
80 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
81 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
82 import org.opendaylight.mdsal.binding.api.DataBroker;
83 import org.opendaylight.mdsal.binding.api.MountPointService;
84 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
85 import org.opendaylight.mdsal.binding.api.RpcProviderService;
86 import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
87 import org.slf4j.Logger;
88 import org.slf4j.LoggerFactory;
91 * Devicemanager - Handles startup and closedown of network element handlers for netconf session - Provide common
92 * services for network element specific components
94 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
96 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
97 private static final String APPLICATION_NAME = "DeviceManager";
98 private static final String MYDBKEYNAMEBASE = "SDN-Controller";
99 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
100 public static final long DATABASE_TIMEOUT_MS = 120 * 1000L;
102 @SuppressWarnings("unused")
103 private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
106 private DataBroker dataBroker;
107 private MountPointService mountPointService;
108 private RpcProviderService rpcProviderRegistry;
109 private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
110 private WebsocketManagerService websocketmanagerService;
111 private IEntityDataProvider iEntityDataProvider;
113 // Devicemanager common services for network element handler
114 private WebSocketServiceClientInternal webSocketService;
115 private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
116 private DeviceManagerApiServiceImpl rpcApiService;
117 private PerformanceManagerImpl performanceManager;
118 private DcaeProviderClient dcaeProviderClient;
119 private AaiProviderClient aaiProviderClient;
120 private DcaeForwarderImpl aotsDcaeForwarder;
121 private DeviceMonitor deviceMonitor;
122 private MaintenanceServiceImpl maintenanceService;
123 private DevicemanagerNotificationDelayService notificationDelayService;
124 private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
125 private ConnectionStatusHousekeepingService housekeepingService;
126 private NetconfNodeStateService netconfNodeStateService;
127 private DataProvider dataProvider;
128 private VESCollectorServiceImpl vesCollectorServiceImpl;
131 private DeviceManagerNetconfConnectHandler deviceManagerNetconfConnectHandler;
134 private final List<NetworkElementFactory> factoryList;
136 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
138 ConfigurationFileRepresentation config;
139 private Boolean devicemanagerInitializationOk;
142 public DeviceManagerImpl() {
143 LOG.info("Creating provider for {}", APPLICATION_NAME);
144 this.devicemanagerInitializationOk = false;
145 this.factoryList = new CopyOnWriteArrayList<>();
147 this.dataBroker = null;
148 this.mountPointService = null;
149 this.rpcProviderRegistry = null;
150 this.clusterSingletonServiceProvider = null;
151 this.websocketmanagerService = null;
152 this.iEntityDataProvider = null;
154 this.webSocketService = null;
157 public void setDataBroker(DataBroker dataBroker) {
158 this.dataBroker = dataBroker;
161 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
162 this.rpcProviderRegistry = rpcProviderRegistry;
165 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {}
167 public void setMountPointService(MountPointService mountPointService) {
168 this.mountPointService = mountPointService;
171 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
172 this.clusterSingletonServiceProvider = clusterSingletonService;
175 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
176 this.netconfNodeStateService = netconfNodeStateService;
179 public void setWebsocketmanagerService(WebsocketManagerService websocketmanagerService) {
180 this.websocketmanagerService = websocketmanagerService;
183 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
184 this.iEntityDataProvider = iEntityDataProvider;
189 LOG.info("Session Initiated start {}", APPLICATION_NAME);
191 this.dataProvider = iEntityDataProvider.getDataProvider();
194 this.config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
196 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
198 // start service for device maintenance service
199 this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
202 this.webSocketService = new WebSocketServiceClientImpl(websocketmanagerService);
205 this.dcaeProviderClient = new DcaeProviderClient(config,"", this);
207 this.aaiProviderClient = new AaiProviderClient(config, this);
209 this.vesCollectorServiceImpl = new VESCollectorServiceImpl(config);
211 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-";
213 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
215 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
216 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
218 RpcPushNotificationsHandler rpcPushNotificationsHandler =
219 new RpcPushNotificationsHandler(webSocketService, dataProvider, aotsDcaeForwarder);
220 this.odlEventListenerHandler = new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService, dataProvider,
221 aotsDcaeForwarder, dataBroker);
222 this.housekeepingService = new ConnectionStatusHousekeepingService(config, clusterSingletonServiceProvider,
223 this.dataBroker, dataProvider);
225 this.performanceManager = new PerformanceManagerImpl(60, this, dataProvider, config);
227 // DeviceMonitor has to be available before netconfSubscriptionManager is
229 LOG.debug("start DeviceMonitor Service");
230 this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
232 // ResyncNetworkElementHouskeepingService
233 this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(this,
234 mountPointService, odlEventListenerHandler, dataProvider, deviceMonitor);
236 // RPC Service for specific services
238 LOG.debug("start rpc service");
239 this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
240 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
242 // netconfSubscriptionManager should be the last one because this is a callback
245 LOG.debug("start NetconfSubscriptionManager Service");
246 this.deviceManagerNetconfConnectHandler = new DeviceManagerNetconfConnectHandler(netconfNodeStateService,
247 clusterSingletonServiceProvider, odlEventListenerHandler, deviceMonitor, this, factoryList);
249 writeToEventLog(APPLICATION_NAME, "startup", "done");
250 this.devicemanagerInitializationOk = true;
252 LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
256 public void close() {
257 LOG.info("DeviceManagerImpl closing ...");
258 close(performanceManager);
259 close(dcaeProviderClient);
260 close(aotsDcaeForwarder);
261 close(aaiProviderClient);
262 close(deviceMonitor);
263 close(maintenanceService);
264 close(rpcApiService);
265 close(notificationDelayService);
266 close(housekeepingService);
267 close(deviceManagerNetconfConnectHandler);
268 close(vesCollectorServiceImpl);
269 LOG.info("DeviceManagerImpl closing done");
273 synchronized public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerBindingNetworkElementFactory(
274 @NonNull final L factory) {
275 LOG.debug("Factory registration {}", factory.getClass().getName());
277 factoryList.add(factory);
278 Collections.sort(factoryList, (a,b) -> DevicemanagerNature.compareTo(a, b) );
279 factory.init(getServiceProvider());
280 return new FactoryRegistration<L>() {
283 public @NonNull L getInstance() {
288 public void close() {
289 factoryList.remove(factory);
295 private DevicemanagerNature getNature(NetworkElementFactory a) {
296 return (a instanceof NetworkElementFactory2) ? ((NetworkElementFactory2)a).getDevicemanagerNature()
297 : DevicemanagerNature.NETWORKELEMENT_FACTORY_DEFAULT;
301 public @NonNull DataProvider getDataProvider() {
302 return this.dataProvider;
305 @SuppressWarnings("null")
307 public @NonNull NotificationService getNotificationService() {
308 return this.deviceManagerDatabaseAndNotificationService;
311 @SuppressWarnings("null")
313 public @NonNull FaultService getFaultService() {
314 return this.deviceManagerDatabaseAndNotificationService;
317 @SuppressWarnings("null")
319 public @NonNull EquipmentService getEquipmentService() {
320 return this.deviceManagerDatabaseAndNotificationService;
323 @SuppressWarnings("null")
325 public @NonNull AaiService getAaiService() {
326 return this.aaiProviderClient;
329 @SuppressWarnings("null")
331 public @NonNull MaintenanceService getMaintenanceService() {
332 return this.maintenanceService;
335 @SuppressWarnings("null")
337 public @NonNull PerformanceManager getPerformanceManagerService() {
338 return this.performanceManager;
341 @SuppressWarnings("null")
343 public @NonNull EventHandlingService getEventHandlingService() {
344 return this.odlEventListenerHandler;
347 @SuppressWarnings("null")
349 public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() {
353 // Deviceinitialization
356 * Used to close all Services, that should support AutoCloseable Pattern
360 private void close(AutoCloseable... toCloseList) {
361 for (AutoCloseable element : toCloseList) {
362 if (element != null) {
365 } catch (Exception e) {
366 LOG.warn("Problem during close {}", e);
372 /*-------------------------------------------------------------------------------------------
375 public DataProvider getDatabaseClientEvents() {
380 public DeviceManagerServiceProvider getServiceProvider() {
385 * Indication if init() of devicemanager successfully done.
387 * @return true if init() was sucessfull. False if not done or not successfull.
389 public boolean isDevicemanagerInitializationOk() {
390 return this.devicemanagerInitializationOk;
394 * Get NE object. Used by DCAE Service
396 * @param mountpoint mount point name
397 * @return null or NE specific data
399 public @Nullable NetworkElement getConnectedNeByMountpoint(String mountpoint) {
401 return this.deviceManagerNetconfConnectHandler.getConnectedNeByMountpoint(mountpoint);
406 public void writeToEventLog(String objectId, String msg, String value) {
407 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);
411 public @NonNull VESCollectorService getVESCollectorService() {
412 return this.vesCollectorServiceImpl;
416 public WebsocketManagerService getWebsocketService() {
417 return this.websocketmanagerService;