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.datamanager.DeviceManagerDatabaseNotificationService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderImpl;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorImpl;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ConnectionStatusHousekeepingService;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementHouskeepingService;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.handler.ODLEventListenerHandler;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.handler.RpcPushNotificationsHandler;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.NetconfChangeListener;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientDummyImpl;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl2;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
45 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
46 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration;
47 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
48 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
49 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.service.MicrowaveHistoricalPerformanceWriterService;
51 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
52 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
53 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
54 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
55 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
56 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
57 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
58 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
59 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
60 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
61 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
62 import org.opendaylight.mdsal.binding.api.DataBroker;
63 import org.opendaylight.mdsal.binding.api.MountPoint;
64 import org.opendaylight.mdsal.binding.api.MountPointService;
65 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
66 import org.opendaylight.mdsal.binding.api.RpcProviderService;
67 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
68 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
75 * - Handles startup and closedown of network element handlers for netconf session
76 * - Provide common services for network element specific components
78 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
80 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
81 private static final String APPLICATION_NAME = "DeviceManager";
82 private static final String MYDBKEYNAMEBASE = "SDN-Controller";
83 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
84 public static final long DATABASE_TIMEOUT_MS = 120*1000L;
86 @SuppressWarnings("unused")
87 private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
88 // private static final String STARTUPLOG_FILENAME2 = "data/cache/devicemanager.startup.log";
91 private DataBroker dataBroker;
92 private MountPointService mountPointService;
93 private RpcProviderService rpcProviderRegistry;
94 @SuppressWarnings("unused")
95 private NotificationPublishService notificationPublishService;
96 private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
97 private WebsocketmanagerService websocketmanagerService;
98 private IEntityDataProvider iEntityDataProvider;
100 // Devicemanager common services for network element handler
101 private @Nullable WebSocketServiceClientInternal webSocketService;
102 private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
103 private NetconfChangeListener netconfChangeListener;
104 private DeviceManagerApiServiceImpl rpcApiService;
105 private PerformanceManagerImpl performanceManager;
106 private DcaeProviderClient dcaeProviderClient;
107 private AaiProviderClient aaiProviderClient;
108 private DcaeForwarderInternal aotsDcaeForwarder;
109 private DeviceMonitor deviceMonitor;
110 private MaintenanceServiceImpl maintenanceService;
111 private DevicemanagerNotificationDelayService notificationDelayService;
112 private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
113 private ArchiveCleanService archiveCleanService;
114 private ConnectionStatusHousekeepingService housekeepingService;
115 private NetconfNodeStateService netconfNodeStateService;
116 private DataProvider dataProvider;
117 //private HtDatabaseClient htDatabaseClient;
119 private RpcPushNotificationsHandler rpcPushNotificationsHandler;
120 private DeviceManagerNetconfConnectHandler forTest;
122 private final Object networkelementLock;
123 private final ConcurrentHashMap<String, NetworkElement> networkElementRepresentations;
124 private final List<MyNetworkElementFactory<? extends NetworkElementFactory>> factoryList;
126 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
127 private ClusterSingletonServiceRegistration cssRegistration;
128 private ClusterSingletonServiceRegistration cssRegistration2;
131 private Boolean devicemanagerInitializationOk;
134 public DeviceManagerImpl() {
135 LOG.info("Creating provider for {}", APPLICATION_NAME);
136 this.devicemanagerInitializationOk = false;
137 this.factoryList = new CopyOnWriteArrayList<>();
138 this.networkelementLock = new Object();
139 this.networkElementRepresentations = new ConcurrentHashMap<>();
141 this.dataBroker = null;
142 this.mountPointService = null;
143 this.rpcProviderRegistry = null;
144 this.notificationPublishService = null;
145 this.clusterSingletonServiceProvider = null;
146 this.websocketmanagerService = null;
147 this.iEntityDataProvider = null;
149 this.webSocketService = null;
152 public void setDataBroker(DataBroker dataBroker) {
153 this.dataBroker = dataBroker;
156 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
157 this.rpcProviderRegistry = rpcProviderRegistry;
160 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
161 this.notificationPublishService = notificationPublishService;
164 public void setMountPointService(MountPointService mountPointService) {
165 this.mountPointService = mountPointService;
167 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
168 this.clusterSingletonServiceProvider = clusterSingletonService;
170 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
171 this.netconfNodeStateService = netconfNodeStateService;
173 public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) {
174 this.websocketmanagerService = websocketmanagerService;
176 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
177 this.iEntityDataProvider = iEntityDataProvider;
180 @SuppressWarnings({ "deprecation", "null" })
181 public void init() throws Exception {
183 LOG.info("Session Initiated start {}", APPLICATION_NAME);
184 this.iEntityDataProvider.setReadyStatus(false);
186 this.dataProvider = iEntityDataProvider.getDataProvider(); // Get configuration
188 ConfigurationFileRepresentation config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
190 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
192 //EsConfig dbConfig = new EsConfig(config);
193 //LOG.debug("esConfig=" + dbConfig.toString());
195 // TODO Remove this database client
196 //this.htDatabaseClient = new HtDatabaseClient(dbConfig.getHosts());
197 //this.htDatabaseClient.waitForYellowStatus(DATABASE_TIMEOUT_MS);
199 // start service for device maintenance service
200 this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
204 this.webSocketService = new WebSocketServiceClientImpl2(websocketmanagerService);
205 } catch (Exception e) {
206 LOG.error("Can not start websocket service. Loading mock class.", e);
207 this.webSocketService = new WebSocketServiceClientDummyImpl();
210 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider, webSocketService);
212 IEsConfig esConfig = iEntityDataProvider.getEsConfig();
214 this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
216 this.aaiProviderClient = new AaiProviderClient(config, this);
218 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
220 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
221 this.rpcPushNotificationsHandler = new RpcPushNotificationsHandler(webSocketService,
222 dataProvider, aotsDcaeForwarder);
223 this.odlEventListenerHandler = new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService,
224 dataProvider, aotsDcaeForwarder);
225 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(), dataProvider);
226 this.housekeepingService = new ConnectionStatusHousekeepingService(this.dataBroker,
228 this.cssRegistration = this.clusterSingletonServiceProvider
229 .registerClusterSingletonService(this.archiveCleanService);
230 this.cssRegistration2 = this.clusterSingletonServiceProvider
231 .registerClusterSingletonService(this.housekeepingService);
233 this.performanceManager = new PerformanceManagerImpl(60, this, new MicrowaveHistoricalPerformanceWriterService(dataProvider), config);
235 // DeviceMonitor has to be available before netconfSubscriptionManager is
237 LOG.debug("start DeviceMonitor Service");
238 this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
240 // ResyncNetworkElementHouskeepingService
241 this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(
242 this, mountPointService, odlEventListenerHandler,
243 dataProvider, deviceMonitor);
245 // RPC Service for specific services
247 LOG.debug("start rpc service");
248 this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
249 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
251 // netconfSubscriptionManager should be the last one because this is a callback
253 LOG.debug("start NetconfSubscriptionManager Service");
254 // this.netconfSubscriptionManager = new
255 // NetconfSubscriptionManagerOfDeviceManager(this, dataBroker);
256 // this.netconfSubscriptionManager.register();
258 //---->>>>>>> OLD OLD OLD
259 //this.netconfChangeListener = new NetconfChangeListener(this, dataBroker);
260 //this.netconfChangeListener.register();
262 //---->>>>>>> NEW NEW NEW
263 this.forTest = new DeviceManagerNetconfConnectHandler(netconfNodeStateService, odlEventListenerHandler,
264 deviceMonitor, this, factoryList);
266 writeToEventLog(APPLICATION_NAME, "startup", "done");
267 this.devicemanagerInitializationOk = true;
269 LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
270 this.iEntityDataProvider.setReadyStatus(true);
275 public void close() {
276 LOG.info("DeviceManagerImpl closing ...");
277 close(performanceManager);
278 close(dcaeProviderClient);
279 close(aaiProviderClient);
280 close(deviceMonitor);
281 //close(htDatabaseClient);
282 close(netconfChangeListener);
283 close(maintenanceService);
284 close(rpcApiService);
285 close(notificationDelayService);
286 close(archiveCleanService);
287 close(housekeepingService);
289 close(cssRegistration, cssRegistration2);
290 LOG.info("DeviceManagerImpl closing done");
294 public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerNetworkElementFactory(@NonNull L factory) {
295 LOG.info("Factory registration {}", factory.getClass().getName());
296 MyNetworkElementFactory<L> myFactory = new MyNetworkElementFactory<>(factory, (a,b,c) -> initDefault(a,b,c));
297 factoryList.add(myFactory);
298 return new FactoryRegistration<L>() {
301 public @NonNull L getInstance() {
302 return myFactory.getFactory();
306 public void close() {
307 factoryList.remove(myFactory);
314 * Execute register command, for network element
315 * @param mountPointNodeName of new network element
316 * @param mountPoint of new network element
317 * @param inNe that needs to register
319 private void initDefault(String mountPointNodeName, MountPoint mountPoint, NetworkElement inNe) {
320 // sendUpdateNotification(mountPointNodeName, nNode.getConnectionStatus(), nNode);
322 NetworkElement result;
323 synchronized (networkelementLock) {
324 result = networkElementRepresentations.put(mountPointNodeName, inNe);
326 if (result != null) {
327 LOG.warn("NE list was not empty as expected, but contained {} ", result.getNodeId());
329 deviceMonitor.deviceConnectMasterIndication(mountPointNodeName, inNe);
330 inNe.register(); // Call NE specific initialization
331 odlEventListenerHandler.connectIndication(mountPointNodeName, inNe.getDeviceType());
335 @SuppressWarnings("null")
337 public @NonNull DataProvider getDataProvider() {
338 return this.dataProvider;
341 @SuppressWarnings("null")
343 public @NonNull NotificationService getNotificationService() {
344 return this.deviceManagerDatabaseAndNotificationService;
347 @SuppressWarnings("null")
349 public @NonNull FaultService getFaultService() {
350 return this.deviceManagerDatabaseAndNotificationService;
353 @SuppressWarnings("null")
355 public @NonNull EquipmentService getEquipmentService() {
356 return this.deviceManagerDatabaseAndNotificationService;
359 @SuppressWarnings("null")
361 public @NonNull AaiService getAaiService() {
362 return this.aaiProviderClient;
365 @SuppressWarnings("null")
367 public @NonNull MaintenanceService getMaintenanceService() {
368 return this.maintenanceService;
371 @SuppressWarnings("null")
373 public @NonNull PerformanceManager getPerformanceManagerService() {
374 return this.performanceManager;
377 @SuppressWarnings("null")
379 public @NonNull EventHandlingService getEventHandlingService() {
380 return this.odlEventListenerHandler;
382 // Deviceinitialization
385 * Used to close all Services, that should support AutoCloseable Pattern
388 private void close(AutoCloseable... toCloseList) {
389 for (AutoCloseable element : toCloseList) {
390 if (element != null) {
393 } catch (Exception e) {
394 LOG.warn("Problem during close {}", e);
400 /*-------------------------------------------------------------------------------------------
404 public ArchiveCleanService getArchiveCleanService() {
405 return this.archiveCleanService;
408 public DataProvider getDatabaseClientEvents() {
413 public DeviceManagerServiceProvider getServiceProvider() {
418 * Indication if init() of devicemanager successfully done.
419 * @return true if init() was sucessfull. False if not done or not successfull.
421 public boolean isDevicemanagerInitializationOk() {
422 return this.devicemanagerInitializationOk;
426 * Get NE object. Used by DCAE Service
427 * @param mountpoint mount point name
428 * @return null or NE specific data
430 public @Nullable NetworkElement getNeByMountpoint(String mountpoint) {
432 return networkElementRepresentations.get(mountpoint);
437 public void writeToEventLog(String objectId, String msg, String value) {
438 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);