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.ConcurrentHashMap;
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.WebSocketServiceClientImpl2;
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.FactoryRegistration;
65 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
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.toggleAlarmFilter.DevicemanagerNotificationDelayService;
78 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
79 import org.opendaylight.mdsal.binding.api.DataBroker;
80 import org.opendaylight.mdsal.binding.api.MountPointService;
81 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
82 import org.opendaylight.mdsal.binding.api.RpcProviderService;
83 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
84 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
86 import org.slf4j.Logger;
87 import org.slf4j.LoggerFactory;
91 * - Handles startup and closedown of network element handlers for netconf session
92 * - Provide common 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 ArchiveCleanService archiveCleanService;
126 private ConnectionStatusHousekeepingService housekeepingService;
127 private NetconfNodeStateService netconfNodeStateService;
128 private DataProvider dataProvider;
131 private DeviceManagerNetconfConnectHandler forTest;
134 private final ConcurrentHashMap<String, NetworkElement> networkElementRepresentations;
135 private final List<NetworkElementFactory> factoryList;
137 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
138 private ClusterSingletonServiceRegistration cssRegistration;
139 private ClusterSingletonServiceRegistration cssRegistration2;
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<>();
149 this.networkElementRepresentations = new ConcurrentHashMap<>();
151 this.dataBroker = null;
152 this.mountPointService = null;
153 this.rpcProviderRegistry = null;
154 this.clusterSingletonServiceProvider = null;
155 this.websocketmanagerService = null;
156 this.iEntityDataProvider = null;
158 this.webSocketService = null;
161 public void setDataBroker(DataBroker dataBroker) {
162 this.dataBroker = dataBroker;
165 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
166 this.rpcProviderRegistry = rpcProviderRegistry;
169 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
172 public void setMountPointService(MountPointService mountPointService) {
173 this.mountPointService = mountPointService;
175 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
176 this.clusterSingletonServiceProvider = clusterSingletonService;
178 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
179 this.netconfNodeStateService = netconfNodeStateService;
181 public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) {
182 this.websocketmanagerService = websocketmanagerService;
184 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
185 this.iEntityDataProvider = iEntityDataProvider;
190 LOG.info("Session Initiated start {}", APPLICATION_NAME);
192 this.iEntityDataProvider.setReadyStatus(false);
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 WebSocketServiceClientImpl2(websocketmanagerService);
207 IEsConfig esConfig = iEntityDataProvider.getEsConfig();
209 this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
211 this.aaiProviderClient = new AaiProviderClient(config, this);
213 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
215 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
217 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
218 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
220 RpcPushNotificationsHandler rpcPushNotificationsHandler = new RpcPushNotificationsHandler(webSocketService,
221 dataProvider, aotsDcaeForwarder);
222 this.odlEventListenerHandler = new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService,
223 dataProvider, aotsDcaeForwarder);
224 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(), dataProvider);
225 this.housekeepingService = new ConnectionStatusHousekeepingService(this.dataBroker,
227 this.cssRegistration = this.clusterSingletonServiceProvider
228 .registerClusterSingletonService(this.archiveCleanService);
229 this.cssRegistration2 = this.clusterSingletonServiceProvider
230 .registerClusterSingletonService(this.housekeepingService);
232 this.performanceManager = new PerformanceManagerImpl(60, this, dataProvider, config);
234 // DeviceMonitor has to be available before netconfSubscriptionManager is
236 LOG.debug("start DeviceMonitor Service");
237 this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
239 // ResyncNetworkElementHouskeepingService
240 this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(
241 this, mountPointService, odlEventListenerHandler,
242 dataProvider, deviceMonitor);
244 // RPC Service for specific services
246 LOG.debug("start rpc service");
247 this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
248 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
250 // netconfSubscriptionManager should be the last one because this is a callback
253 LOG.debug("start NetconfSubscriptionManager Service");
254 this.forTest = new DeviceManagerNetconfConnectHandler(netconfNodeStateService, odlEventListenerHandler,
255 deviceMonitor, this, factoryList);
257 writeToEventLog(APPLICATION_NAME, "startup", "done");
258 this.devicemanagerInitializationOk = true;
260 LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
261 this.iEntityDataProvider.setReadyStatus(true);
266 public void close() {
267 LOG.info("DeviceManagerImpl closing ...");
268 close(performanceManager);
269 close(dcaeProviderClient);
270 close(aotsDcaeForwarder);
271 close(aaiProviderClient);
272 close(deviceMonitor);
273 close(maintenanceService);
274 close(rpcApiService);
275 close(notificationDelayService);
276 close(archiveCleanService);
277 close(housekeepingService);
279 close(cssRegistration, cssRegistration2);
280 LOG.info("DeviceManagerImpl closing done");
284 public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerNetworkElementFactory(@NonNull L factory) {
285 LOG.info("Factory registration {}", factory.getClass().getName());
287 factoryList.add(factory);
288 return new FactoryRegistration<L>() {
291 public @NonNull L getInstance() {
296 public void close() {
297 factoryList.remove(factory);
303 @SuppressWarnings("null")
305 public @NonNull DataProvider getDataProvider() {
306 return this.dataProvider;
309 @SuppressWarnings("null")
311 public @NonNull NotificationService getNotificationService() {
312 return this.deviceManagerDatabaseAndNotificationService;
315 @SuppressWarnings("null")
317 public @NonNull FaultService getFaultService() {
318 return this.deviceManagerDatabaseAndNotificationService;
321 @SuppressWarnings("null")
323 public @NonNull EquipmentService getEquipmentService() {
324 return this.deviceManagerDatabaseAndNotificationService;
327 @SuppressWarnings("null")
329 public @NonNull AaiService getAaiService() {
330 return this.aaiProviderClient;
333 @SuppressWarnings("null")
335 public @NonNull MaintenanceService getMaintenanceService() {
336 return this.maintenanceService;
339 @SuppressWarnings("null")
341 public @NonNull PerformanceManager getPerformanceManagerService() {
342 return this.performanceManager;
345 @SuppressWarnings("null")
347 public @NonNull EventHandlingService getEventHandlingService() {
348 return this.odlEventListenerHandler;
351 @SuppressWarnings("null")
353 public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() {
357 // Deviceinitialization
360 * Used to close all Services, that should support AutoCloseable Pattern
363 private void close(AutoCloseable... toCloseList) {
364 for (AutoCloseable element : toCloseList) {
365 if (element != null) {
368 } catch (Exception e) {
369 LOG.warn("Problem during close {}", e);
375 /*-------------------------------------------------------------------------------------------
379 public ArchiveCleanService getArchiveCleanService() {
380 return this.archiveCleanService;
383 public DataProvider getDatabaseClientEvents() {
388 public DeviceManagerServiceProvider getServiceProvider() {
393 * Indication if init() of devicemanager successfully done.
394 * @return true if init() was sucessfull. False if not done or not successfull.
396 public boolean isDevicemanagerInitializationOk() {
397 return this.devicemanagerInitializationOk;
401 * Get NE object. Used by DCAE Service
402 * @param mountpoint mount point name
403 * @return null or NE specific data
405 public @Nullable NetworkElement getNeByMountpoint(String mountpoint) {
407 return networkElementRepresentations.get(mountpoint);
412 public void writeToEventLog(String objectId, String msg, String value) {
413 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);