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.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.WebSocketServiceClientImpl2;
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.toggleAlarmFilter.DevicemanagerNotificationDelayService;
77 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
78 import org.opendaylight.mdsal.binding.api.DataBroker;
79 import org.opendaylight.mdsal.binding.api.MountPointService;
80 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
81 import org.opendaylight.mdsal.binding.api.RpcProviderService;
82 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
84 import org.slf4j.Logger;
85 import org.slf4j.LoggerFactory;
88 * Devicemanager - Handles startup and closedown of network element handlers for netconf session - Provide common
89 * services for network element specific components
91 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
93 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
94 private static final String APPLICATION_NAME = "DeviceManager";
95 private static final String MYDBKEYNAMEBASE = "SDN-Controller";
96 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
97 public static final long DATABASE_TIMEOUT_MS = 120 * 1000L;
99 @SuppressWarnings("unused")
100 private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
103 private DataBroker dataBroker;
104 private MountPointService mountPointService;
105 private RpcProviderService rpcProviderRegistry;
106 private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
107 private WebsocketmanagerService websocketmanagerService;
108 private IEntityDataProvider iEntityDataProvider;
110 // Devicemanager common services for network element handler
111 private WebSocketServiceClientInternal webSocketService;
112 private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
113 private DeviceManagerApiServiceImpl rpcApiService;
114 private PerformanceManagerImpl performanceManager;
115 private DcaeProviderClient dcaeProviderClient;
116 private AaiProviderClient aaiProviderClient;
117 private DcaeForwarderImpl aotsDcaeForwarder;
118 private DeviceMonitor deviceMonitor;
119 private MaintenanceServiceImpl maintenanceService;
120 private DevicemanagerNotificationDelayService notificationDelayService;
121 private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
122 private ArchiveCleanService archiveCleanService;
123 private ConnectionStatusHousekeepingService housekeepingService;
124 private NetconfNodeStateService netconfNodeStateService;
125 private DataProvider dataProvider;
128 private DeviceManagerNetconfConnectHandler deviceManagerNetconfConnectHandler;
131 private final List<NetworkElementFactory> factoryList;
133 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
135 ConfigurationFileRepresentation config;
136 private Boolean devicemanagerInitializationOk;
139 public DeviceManagerImpl() {
140 LOG.info("Creating provider for {}", APPLICATION_NAME);
141 this.devicemanagerInitializationOk = false;
142 this.factoryList = new CopyOnWriteArrayList<>();
144 this.dataBroker = null;
145 this.mountPointService = null;
146 this.rpcProviderRegistry = null;
147 this.clusterSingletonServiceProvider = null;
148 this.websocketmanagerService = null;
149 this.iEntityDataProvider = null;
151 this.webSocketService = null;
154 public void setDataBroker(DataBroker dataBroker) {
155 this.dataBroker = dataBroker;
158 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
159 this.rpcProviderRegistry = rpcProviderRegistry;
162 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {}
164 public void setMountPointService(MountPointService mountPointService) {
165 this.mountPointService = mountPointService;
168 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
169 this.clusterSingletonServiceProvider = clusterSingletonService;
172 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
173 this.netconfNodeStateService = netconfNodeStateService;
176 public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) {
177 this.websocketmanagerService = websocketmanagerService;
180 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
181 this.iEntityDataProvider = iEntityDataProvider;
186 LOG.info("Session Initiated start {}", APPLICATION_NAME);
188 this.iEntityDataProvider.setReadyStatus(false);
190 this.dataProvider = iEntityDataProvider.getDataProvider();
193 this.config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
195 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
197 // start service for device maintenance service
198 this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
201 this.webSocketService = new WebSocketServiceClientImpl2(websocketmanagerService);
203 IEsConfig esConfig = iEntityDataProvider.getEsConfig();
205 this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
207 this.aaiProviderClient = new AaiProviderClient(config, this);
209 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
211 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
213 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
214 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
216 RpcPushNotificationsHandler rpcPushNotificationsHandler =
217 new RpcPushNotificationsHandler(webSocketService, dataProvider, aotsDcaeForwarder);
218 this.odlEventListenerHandler =
219 new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService, dataProvider, aotsDcaeForwarder);
220 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(),
221 clusterSingletonServiceProvider, dataProvider);
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);
253 this.iEntityDataProvider.setReadyStatus(true);
258 public void close() {
259 LOG.info("DeviceManagerImpl closing ...");
260 close(performanceManager);
261 close(dcaeProviderClient);
262 close(aotsDcaeForwarder);
263 close(aaiProviderClient);
264 close(deviceMonitor);
265 close(maintenanceService);
266 close(rpcApiService);
267 close(notificationDelayService);
268 close(archiveCleanService);
269 close(housekeepingService);
270 close(deviceManagerNetconfConnectHandler);
271 LOG.info("DeviceManagerImpl closing done");
275 public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerNetworkElementFactory(
276 @NonNull L factory) {
277 LOG.info("Factory registration {}", factory.getClass().getName());
279 factoryList.add(factory);
280 return new FactoryRegistration<L>() {
283 public @NonNull L getInstance() {
288 public void close() {
289 factoryList.remove(factory);
295 @SuppressWarnings("null")
297 public @NonNull DataProvider getDataProvider() {
298 return this.dataProvider;
301 @SuppressWarnings("null")
303 public @NonNull NotificationService getNotificationService() {
304 return this.deviceManagerDatabaseAndNotificationService;
307 @SuppressWarnings("null")
309 public @NonNull FaultService getFaultService() {
310 return this.deviceManagerDatabaseAndNotificationService;
313 @SuppressWarnings("null")
315 public @NonNull EquipmentService getEquipmentService() {
316 return this.deviceManagerDatabaseAndNotificationService;
319 @SuppressWarnings("null")
321 public @NonNull AaiService getAaiService() {
322 return this.aaiProviderClient;
325 @SuppressWarnings("null")
327 public @NonNull MaintenanceService getMaintenanceService() {
328 return this.maintenanceService;
331 @SuppressWarnings("null")
333 public @NonNull PerformanceManager getPerformanceManagerService() {
334 return this.performanceManager;
337 @SuppressWarnings("null")
339 public @NonNull EventHandlingService getEventHandlingService() {
340 return this.odlEventListenerHandler;
343 @SuppressWarnings("null")
345 public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() {
349 // Deviceinitialization
352 * Used to close all Services, that should support AutoCloseable Pattern
356 private void close(AutoCloseable... toCloseList) {
357 for (AutoCloseable element : toCloseList) {
358 if (element != null) {
361 } catch (Exception e) {
362 LOG.warn("Problem during close {}", e);
368 /*-------------------------------------------------------------------------------------------
372 public ArchiveCleanService getArchiveCleanService() {
373 return this.archiveCleanService;
376 public DataProvider getDatabaseClientEvents() {
381 public DeviceManagerServiceProvider getServiceProvider() {
386 * Indication if init() of devicemanager successfully done.
388 * @return true if init() was sucessfull. False if not done or not successfull.
390 public boolean isDevicemanagerInitializationOk() {
391 return this.devicemanagerInitializationOk;
395 * Get NE object. Used by DCAE Service
397 * @param mountpoint mount point name
398 * @return null or NE specific data
400 public @Nullable NetworkElement getConnectedNeByMountpoint(String mountpoint) {
402 return this.deviceManagerNetconfConnectHandler.getConnectedNeByMountpoint(mountpoint);
407 public void writeToEventLog(String objectId, String msg, String value) {
408 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);