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.dcaeconnector.impl.DcaeForwarderImpl;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderInternal;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorImpl;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.DeviceManagerDatabaseNotificationService;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.ODLEventListenerHandler;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.RpcPushNotificationsHandler;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ConnectionStatusHousekeepingService;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementHouskeepingService;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl2;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration;
45 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
46 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
47 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl;
48 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.service.MicrowaveHistoricalPerformanceWriterService;
49 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
51 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
52 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
53 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
54 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
55 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService;
56 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
57 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
58 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
59 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
60 import org.opendaylight.mdsal.binding.api.DataBroker;
61 import org.opendaylight.mdsal.binding.api.MountPoint;
62 import org.opendaylight.mdsal.binding.api.MountPointService;
63 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
64 import org.opendaylight.mdsal.binding.api.RpcProviderService;
65 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
66 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
73 * - Handles startup and closedown of network element handlers for netconf session
74 * - Provide common services for network element specific components
76 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
78 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
79 private static final String APPLICATION_NAME = "DeviceManager";
80 private static final String MYDBKEYNAMEBASE = "SDN-Controller";
81 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
82 public static final long DATABASE_TIMEOUT_MS = 120*1000L;
84 @SuppressWarnings("unused")
85 private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
86 // private static final String STARTUPLOG_FILENAME2 = "data/cache/devicemanager.startup.log";
89 private DataBroker dataBroker;
90 private MountPointService mountPointService;
91 private RpcProviderService rpcProviderRegistry;
92 @SuppressWarnings("unused")
93 private NotificationPublishService notificationPublishService;
94 private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
95 private WebsocketmanagerService websocketmanagerService;
96 private IEntityDataProvider iEntityDataProvider;
98 // Devicemanager common services for network element handler
99 private @Nullable WebSocketServiceClientInternal webSocketService;
100 private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
101 //private NetconfChangeListener netconfChangeListener;
102 private DeviceManagerApiServiceImpl rpcApiService;
103 private PerformanceManagerImpl performanceManager;
104 private DcaeProviderClient dcaeProviderClient;
105 private AaiProviderClient aaiProviderClient;
106 private DcaeForwarderInternal aotsDcaeForwarder;
107 private DeviceMonitor deviceMonitor;
108 private MaintenanceServiceImpl maintenanceService;
109 private DevicemanagerNotificationDelayService notificationDelayService;
110 private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
111 private ArchiveCleanService archiveCleanService;
112 private ConnectionStatusHousekeepingService housekeepingService;
113 private NetconfNodeStateService netconfNodeStateService;
114 private DataProvider dataProvider;
115 //private HtDatabaseClient htDatabaseClient;
117 private RpcPushNotificationsHandler rpcPushNotificationsHandler;
118 private DeviceManagerNetconfConnectHandler forTest;
120 private final Object networkelementLock;
121 private final ConcurrentHashMap<String, NetworkElement> networkElementRepresentations;
122 private final List<MyNetworkElementFactory<? extends NetworkElementFactory>> factoryList;
124 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
125 private ClusterSingletonServiceRegistration cssRegistration;
126 private ClusterSingletonServiceRegistration cssRegistration2;
129 private Boolean devicemanagerInitializationOk;
132 public DeviceManagerImpl() {
133 LOG.info("Creating provider for {}", APPLICATION_NAME);
134 this.devicemanagerInitializationOk = false;
135 this.factoryList = new CopyOnWriteArrayList<>();
136 this.networkelementLock = new Object();
137 this.networkElementRepresentations = new ConcurrentHashMap<>();
139 this.dataBroker = null;
140 this.mountPointService = null;
141 this.rpcProviderRegistry = null;
142 this.notificationPublishService = null;
143 this.clusterSingletonServiceProvider = null;
144 this.websocketmanagerService = null;
145 this.iEntityDataProvider = null;
147 this.webSocketService = null;
150 public void setDataBroker(DataBroker dataBroker) {
151 this.dataBroker = dataBroker;
154 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
155 this.rpcProviderRegistry = rpcProviderRegistry;
158 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
159 this.notificationPublishService = notificationPublishService;
162 public void setMountPointService(MountPointService mountPointService) {
163 this.mountPointService = mountPointService;
165 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
166 this.clusterSingletonServiceProvider = clusterSingletonService;
168 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
169 this.netconfNodeStateService = netconfNodeStateService;
171 public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) {
172 this.websocketmanagerService = websocketmanagerService;
174 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
175 this.iEntityDataProvider = iEntityDataProvider;
178 @SuppressWarnings({ "deprecation", "null" })
179 public void init() throws Exception {
181 LOG.info("Session Initiated start {}", APPLICATION_NAME);
182 this.iEntityDataProvider.setReadyStatus(false);
184 this.dataProvider = iEntityDataProvider.getDataProvider(); // Get configuration
186 ConfigurationFileRepresentation config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
188 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
190 //EsConfig dbConfig = new EsConfig(config);
191 //LOG.debug("esConfig=" + dbConfig.toString());
193 // TODO Remove this database client
194 //this.htDatabaseClient = new HtDatabaseClient(dbConfig.getHosts());
195 //this.htDatabaseClient.waitForYellowStatus(DATABASE_TIMEOUT_MS);
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, maintenanceService,webSocketService, notificationDelayService, aotsDcaeForwarder);
215 this.rpcPushNotificationsHandler = new RpcPushNotificationsHandler(webSocketService,
216 dataProvider, aotsDcaeForwarder);
217 this.odlEventListenerHandler = new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService,
218 dataProvider, aotsDcaeForwarder);
219 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(), dataProvider);
220 this.housekeepingService = new ConnectionStatusHousekeepingService(this.dataBroker,
222 this.cssRegistration = this.clusterSingletonServiceProvider
223 .registerClusterSingletonService(this.archiveCleanService);
224 this.cssRegistration2 = this.clusterSingletonServiceProvider
225 .registerClusterSingletonService(this.housekeepingService);
227 this.performanceManager = new PerformanceManagerImpl(60, this, new MicrowaveHistoricalPerformanceWriterService(dataProvider), config);
229 // DeviceMonitor has to be available before netconfSubscriptionManager is
231 LOG.debug("start DeviceMonitor Service");
232 this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
234 // ResyncNetworkElementHouskeepingService
235 this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(
236 this, mountPointService, odlEventListenerHandler,
237 dataProvider, deviceMonitor);
239 // RPC Service for specific services
241 LOG.debug("start rpc service");
242 this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
243 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
245 // netconfSubscriptionManager should be the last one because this is a callback
247 LOG.debug("start NetconfSubscriptionManager Service");
248 // this.netconfSubscriptionManager = new
249 // NetconfSubscriptionManagerOfDeviceManager(this, dataBroker);
250 // this.netconfSubscriptionManager.register();
252 //---->>>>>>> OLD OLD OLD
253 //this.netconfChangeListener = new NetconfChangeListener(this, dataBroker);
254 //this.netconfChangeListener.register();
256 //---->>>>>>> NEW NEW NEW
257 this.forTest = new DeviceManagerNetconfConnectHandler(netconfNodeStateService, odlEventListenerHandler,
258 deviceMonitor, this, factoryList);
260 writeToEventLog(APPLICATION_NAME, "startup", "done");
261 this.devicemanagerInitializationOk = true;
263 LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
264 this.iEntityDataProvider.setReadyStatus(true);
269 public void close() {
270 LOG.info("DeviceManagerImpl closing ...");
271 close(performanceManager);
272 close(dcaeProviderClient);
273 close(aaiProviderClient);
274 close(deviceMonitor);
275 //close(htDatabaseClient);
276 //close(netconfChangeListener);
277 close(maintenanceService);
278 close(rpcApiService);
279 close(notificationDelayService);
280 close(archiveCleanService);
281 close(housekeepingService);
283 close(cssRegistration, cssRegistration2);
284 LOG.info("DeviceManagerImpl closing done");
288 public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerNetworkElementFactory(@NonNull L factory) {
289 LOG.info("Factory registration {}", factory.getClass().getName());
290 MyNetworkElementFactory<L> myFactory = new MyNetworkElementFactory<>(factory, (a,b,c) -> initDefault(a,b,c));
291 factoryList.add(myFactory);
292 return new FactoryRegistration<L>() {
295 public @NonNull L getInstance() {
296 return myFactory.getFactory();
300 public void close() {
301 factoryList.remove(myFactory);
308 * Execute register command, for network element
309 * @param mountPointNodeName of new network element
310 * @param mountPoint of new network element
311 * @param inNe that needs to register
313 private void initDefault(String mountPointNodeName, MountPoint mountPoint, NetworkElement inNe) {
314 // sendUpdateNotification(mountPointNodeName, nNode.getConnectionStatus(), nNode);
316 NetworkElement result;
317 synchronized (networkelementLock) {
318 result = networkElementRepresentations.put(mountPointNodeName, inNe);
320 if (result != null) {
321 LOG.warn("NE list was not empty as expected, but contained {} ", result.getNodeId());
323 deviceMonitor.deviceConnectMasterIndication(mountPointNodeName, inNe);
324 inNe.register(); // Call NE specific initialization
325 odlEventListenerHandler.connectIndication(mountPointNodeName, inNe.getDeviceType());
329 @SuppressWarnings("null")
331 public @NonNull DataProvider getDataProvider() {
332 return this.dataProvider;
335 @SuppressWarnings("null")
337 public @NonNull NotificationService getNotificationService() {
338 return this.deviceManagerDatabaseAndNotificationService;
341 @SuppressWarnings("null")
343 public @NonNull FaultService getFaultService() {
344 return this.deviceManagerDatabaseAndNotificationService;
347 @SuppressWarnings("null")
349 public @NonNull EquipmentService getEquipmentService() {
350 return this.deviceManagerDatabaseAndNotificationService;
353 @SuppressWarnings("null")
355 public @NonNull AaiService getAaiService() {
356 return this.aaiProviderClient;
359 @SuppressWarnings("null")
361 public @NonNull MaintenanceService getMaintenanceService() {
362 return this.maintenanceService;
365 @SuppressWarnings("null")
367 public @NonNull PerformanceManager getPerformanceManagerService() {
368 return this.performanceManager;
371 @SuppressWarnings("null")
373 public @NonNull EventHandlingService getEventHandlingService() {
374 return this.odlEventListenerHandler;
376 // Deviceinitialization
379 * Used to close all Services, that should support AutoCloseable Pattern
382 private void close(AutoCloseable... toCloseList) {
383 for (AutoCloseable element : toCloseList) {
384 if (element != null) {
387 } catch (Exception e) {
388 LOG.warn("Problem during close {}", e);
394 /*-------------------------------------------------------------------------------------------
398 public ArchiveCleanService getArchiveCleanService() {
399 return this.archiveCleanService;
402 public DataProvider getDatabaseClientEvents() {
407 public DeviceManagerServiceProvider getServiceProvider() {
412 * Indication if init() of devicemanager successfully done.
413 * @return true if init() was sucessfull. False if not done or not successfull.
415 public boolean isDevicemanagerInitializationOk() {
416 return this.devicemanagerInitializationOk;
420 * Get NE object. Used by DCAE Service
421 * @param mountpoint mount point name
422 * @return null or NE specific data
424 public @Nullable NetworkElement getNeByMountpoint(String mountpoint) {
426 return networkElementRepresentations.get(mountpoint);
431 public void writeToEventLog(String objectId, String msg, String value) {
432 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);