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;
90 * Devicemanager - Handles startup and closedown of network element handlers for netconf session - Provide common
91 * services for network element specific components
93 public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable {
95 private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
96 private static final String APPLICATION_NAME = "DeviceManager";
97 private static final String MYDBKEYNAMEBASE = "SDN-Controller";
98 private static final String CONFIGURATIONFILE = "etc/devicemanager.properties";
99 public static final long DATABASE_TIMEOUT_MS = 120 * 1000L;
101 @SuppressWarnings("unused")
102 private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log";
105 private DataBroker dataBroker;
106 private MountPointService mountPointService;
107 private RpcProviderService rpcProviderRegistry;
108 private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
109 private WebsocketmanagerService websocketmanagerService;
110 private IEntityDataProvider iEntityDataProvider;
112 // Devicemanager common services for network element handler
113 private WebSocketServiceClientInternal webSocketService;
114 private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService
115 private DeviceManagerApiServiceImpl rpcApiService;
116 private PerformanceManagerImpl performanceManager;
117 private DcaeProviderClient dcaeProviderClient;
118 private AaiProviderClient aaiProviderClient;
119 private DcaeForwarderImpl aotsDcaeForwarder;
120 private DeviceMonitor deviceMonitor;
121 private MaintenanceServiceImpl maintenanceService;
122 private DevicemanagerNotificationDelayService notificationDelayService;
123 private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService;
124 private ArchiveCleanService archiveCleanService;
125 private ConnectionStatusHousekeepingService housekeepingService;
126 private NetconfNodeStateService netconfNodeStateService;
127 private DataProvider dataProvider;
130 private DeviceManagerNetconfConnectHandler forTest;
133 private final ConcurrentHashMap<String, NetworkElement> networkElementRepresentations;
134 private final List<NetworkElementFactory> factoryList;
136 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
137 private ClusterSingletonServiceRegistration cssRegistration;
138 private ClusterSingletonServiceRegistration cssRegistration2;
140 ConfigurationFileRepresentation config;
141 private Boolean devicemanagerInitializationOk;
144 public DeviceManagerImpl() {
145 LOG.info("Creating provider for {}", APPLICATION_NAME);
146 this.devicemanagerInitializationOk = false;
147 this.factoryList = new CopyOnWriteArrayList<>();
148 this.networkElementRepresentations = new ConcurrentHashMap<>();
150 this.dataBroker = null;
151 this.mountPointService = null;
152 this.rpcProviderRegistry = null;
153 this.clusterSingletonServiceProvider = null;
154 this.websocketmanagerService = null;
155 this.iEntityDataProvider = null;
157 this.webSocketService = null;
160 public void setDataBroker(DataBroker dataBroker) {
161 this.dataBroker = dataBroker;
164 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
165 this.rpcProviderRegistry = rpcProviderRegistry;
168 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {}
170 public void setMountPointService(MountPointService mountPointService) {
171 this.mountPointService = mountPointService;
174 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
175 this.clusterSingletonServiceProvider = clusterSingletonService;
178 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
179 this.netconfNodeStateService = netconfNodeStateService;
182 public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) {
183 this.websocketmanagerService = websocketmanagerService;
186 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
187 this.iEntityDataProvider = iEntityDataProvider;
192 LOG.info("Session Initiated start {}", APPLICATION_NAME);
194 this.iEntityDataProvider.setReadyStatus(false);
196 this.dataProvider = iEntityDataProvider.getDataProvider();
199 this.config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
201 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
203 // start service for device maintenance service
204 this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
207 this.webSocketService = new WebSocketServiceClientImpl2(websocketmanagerService);
209 IEsConfig esConfig = iEntityDataProvider.getEsConfig();
211 this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
213 this.aaiProviderClient = new AaiProviderClient(config, this);
215 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
217 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
219 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
220 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
222 RpcPushNotificationsHandler rpcPushNotificationsHandler =
223 new RpcPushNotificationsHandler(webSocketService, dataProvider, aotsDcaeForwarder);
224 this.odlEventListenerHandler =
225 new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService, dataProvider, aotsDcaeForwarder);
226 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(), dataProvider);
227 this.housekeepingService = new ConnectionStatusHousekeepingService(this.dataBroker, dataProvider);
228 this.cssRegistration =
229 this.clusterSingletonServiceProvider.registerClusterSingletonService(this.archiveCleanService);
230 this.cssRegistration2 =
231 this.clusterSingletonServiceProvider.registerClusterSingletonService(this.housekeepingService);
233 this.performanceManager = new PerformanceManagerImpl(60, this, 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(this,
242 mountPointService, odlEventListenerHandler, 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(
285 @NonNull L factory) {
286 LOG.info("Factory registration {}", factory.getClass().getName());
288 factoryList.add(factory);
289 return new FactoryRegistration<L>() {
292 public @NonNull L getInstance() {
297 public void close() {
298 factoryList.remove(factory);
304 @SuppressWarnings("null")
306 public @NonNull DataProvider getDataProvider() {
307 return this.dataProvider;
310 @SuppressWarnings("null")
312 public @NonNull NotificationService getNotificationService() {
313 return this.deviceManagerDatabaseAndNotificationService;
316 @SuppressWarnings("null")
318 public @NonNull FaultService getFaultService() {
319 return this.deviceManagerDatabaseAndNotificationService;
322 @SuppressWarnings("null")
324 public @NonNull EquipmentService getEquipmentService() {
325 return this.deviceManagerDatabaseAndNotificationService;
328 @SuppressWarnings("null")
330 public @NonNull AaiService getAaiService() {
331 return this.aaiProviderClient;
334 @SuppressWarnings("null")
336 public @NonNull MaintenanceService getMaintenanceService() {
337 return this.maintenanceService;
340 @SuppressWarnings("null")
342 public @NonNull PerformanceManager getPerformanceManagerService() {
343 return this.performanceManager;
346 @SuppressWarnings("null")
348 public @NonNull EventHandlingService getEventHandlingService() {
349 return this.odlEventListenerHandler;
352 @SuppressWarnings("null")
354 public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() {
358 // Deviceinitialization
361 * Used to close all Services, that should support AutoCloseable Pattern
365 private void close(AutoCloseable... toCloseList) {
366 for (AutoCloseable element : toCloseList) {
367 if (element != null) {
370 } catch (Exception e) {
371 LOG.warn("Problem during close {}", e);
377 /*-------------------------------------------------------------------------------------------
381 public ArchiveCleanService getArchiveCleanService() {
382 return this.archiveCleanService;
385 public DataProvider getDatabaseClientEvents() {
390 public DeviceManagerServiceProvider getServiceProvider() {
395 * Indication if init() of devicemanager successfully done.
397 * @return true if init() was sucessfull. False if not done or not successfull.
399 public boolean isDevicemanagerInitializationOk() {
400 return this.devicemanagerInitializationOk;
404 * Get NE object. Used by DCAE Service
406 * @param mountpoint mount point name
407 * @return null or NE specific data
409 public @Nullable NetworkElement getNeByMountpoint(String mountpoint) {
411 return networkElementRepresentations.get(mountpoint);
416 public void writeToEventLog(String objectId, String msg, String value) {
417 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);