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.service.VESCollectorService;
77 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService;
78 import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl;
79 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
81 import org.opendaylight.mdsal.binding.api.DataBroker;
82 import org.opendaylight.mdsal.binding.api.MountPointService;
83 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
84 import org.opendaylight.mdsal.binding.api.RpcProviderService;
85 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
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;
128 private VESCollectorServiceImpl vesCollectorServiceImpl;
131 private DeviceManagerNetconfConnectHandler deviceManagerNetconfConnectHandler;
134 private final List<NetworkElementFactory> factoryList;
136 private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService;
138 ConfigurationFileRepresentation config;
139 private Boolean devicemanagerInitializationOk;
142 public DeviceManagerImpl() {
143 LOG.info("Creating provider for {}", APPLICATION_NAME);
144 this.devicemanagerInitializationOk = false;
145 this.factoryList = new CopyOnWriteArrayList<>();
147 this.dataBroker = null;
148 this.mountPointService = null;
149 this.rpcProviderRegistry = null;
150 this.clusterSingletonServiceProvider = null;
151 this.websocketmanagerService = null;
152 this.iEntityDataProvider = null;
154 this.webSocketService = null;
157 public void setDataBroker(DataBroker dataBroker) {
158 this.dataBroker = dataBroker;
161 public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
162 this.rpcProviderRegistry = rpcProviderRegistry;
165 public void setNotificationPublishService(NotificationPublishService notificationPublishService) {}
167 public void setMountPointService(MountPointService mountPointService) {
168 this.mountPointService = mountPointService;
171 public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) {
172 this.clusterSingletonServiceProvider = clusterSingletonService;
175 public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) {
176 this.netconfNodeStateService = netconfNodeStateService;
179 public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) {
180 this.websocketmanagerService = websocketmanagerService;
183 public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) {
184 this.iEntityDataProvider = iEntityDataProvider;
189 LOG.info("Session Initiated start {}", APPLICATION_NAME);
191 this.iEntityDataProvider.setReadyStatus(false);
193 this.dataProvider = iEntityDataProvider.getDataProvider();
196 this.config = new ConfigurationFileRepresentation(CONFIGURATIONFILE);
198 this.notificationDelayService = new DevicemanagerNotificationDelayService(config);
200 // start service for device maintenance service
201 this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance());
204 this.webSocketService = new WebSocketServiceClientImpl2(websocketmanagerService);
206 IEsConfig esConfig = iEntityDataProvider.getEsConfig();
208 this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this);
210 this.aaiProviderClient = new AaiProviderClient(config, this);
212 this.vesCollectorServiceImpl = new VESCollectorServiceImpl(config);
214 String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster();
216 this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService);
218 this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider,
219 maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder);
221 RpcPushNotificationsHandler rpcPushNotificationsHandler =
222 new RpcPushNotificationsHandler(webSocketService, dataProvider, aotsDcaeForwarder);
223 this.odlEventListenerHandler =
224 new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService, dataProvider, aotsDcaeForwarder);
225 this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(),
226 clusterSingletonServiceProvider, dataProvider);
227 this.housekeepingService = new ConnectionStatusHousekeepingService(config, clusterSingletonServiceProvider,
228 this.dataBroker, dataProvider);
230 this.performanceManager = new PerformanceManagerImpl(60, this, dataProvider, config);
232 // DeviceMonitor has to be available before netconfSubscriptionManager is
234 LOG.debug("start DeviceMonitor Service");
235 this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config);
237 // ResyncNetworkElementHouskeepingService
238 this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(this,
239 mountPointService, odlEventListenerHandler, dataProvider, deviceMonitor);
241 // RPC Service for specific services
243 LOG.debug("start rpc service");
244 this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService,
245 resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler);
247 // netconfSubscriptionManager should be the last one because this is a callback
250 LOG.debug("start NetconfSubscriptionManager Service");
251 this.deviceManagerNetconfConnectHandler = new DeviceManagerNetconfConnectHandler(netconfNodeStateService,
252 clusterSingletonServiceProvider, odlEventListenerHandler, deviceMonitor, this, factoryList);
254 writeToEventLog(APPLICATION_NAME, "startup", "done");
255 this.devicemanagerInitializationOk = true;
257 LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk);
258 this.iEntityDataProvider.setReadyStatus(true);
263 public void close() {
264 LOG.info("DeviceManagerImpl closing ...");
265 close(performanceManager);
266 close(dcaeProviderClient);
267 close(aotsDcaeForwarder);
268 close(aaiProviderClient);
269 close(deviceMonitor);
270 close(maintenanceService);
271 close(rpcApiService);
272 close(notificationDelayService);
273 close(archiveCleanService);
274 close(housekeepingService);
275 close(deviceManagerNetconfConnectHandler);
276 close(vesCollectorServiceImpl);
277 LOG.info("DeviceManagerImpl closing done");
281 public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerBindingNetworkElementFactory(
282 @NonNull final L factory) {
283 LOG.info("Factory registration {}", factory.getClass().getName());
285 factoryList.add(factory);
286 return new FactoryRegistration<L>() {
289 public @NonNull L getInstance() {
294 public void close() {
295 factoryList.remove(factory);
301 @SuppressWarnings("null")
303 public @NonNull DataProvider getDataProvider() {
304 return this.dataProvider;
307 @SuppressWarnings("null")
309 public @NonNull NotificationService getNotificationService() {
310 return this.deviceManagerDatabaseAndNotificationService;
313 @SuppressWarnings("null")
315 public @NonNull FaultService getFaultService() {
316 return this.deviceManagerDatabaseAndNotificationService;
319 @SuppressWarnings("null")
321 public @NonNull EquipmentService getEquipmentService() {
322 return this.deviceManagerDatabaseAndNotificationService;
325 @SuppressWarnings("null")
327 public @NonNull AaiService getAaiService() {
328 return this.aaiProviderClient;
331 @SuppressWarnings("null")
333 public @NonNull MaintenanceService getMaintenanceService() {
334 return this.maintenanceService;
337 @SuppressWarnings("null")
339 public @NonNull PerformanceManager getPerformanceManagerService() {
340 return this.performanceManager;
343 @SuppressWarnings("null")
345 public @NonNull EventHandlingService getEventHandlingService() {
346 return this.odlEventListenerHandler;
349 @SuppressWarnings("null")
351 public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() {
355 // Deviceinitialization
358 * Used to close all Services, that should support AutoCloseable Pattern
362 private void close(AutoCloseable... toCloseList) {
363 for (AutoCloseable element : toCloseList) {
364 if (element != null) {
367 } catch (Exception e) {
368 LOG.warn("Problem during close {}", e);
374 /*-------------------------------------------------------------------------------------------
378 public ArchiveCleanService getArchiveCleanService() {
379 return this.archiveCleanService;
382 public DataProvider getDatabaseClientEvents() {
387 public DeviceManagerServiceProvider getServiceProvider() {
392 * 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
403 * @param mountpoint mount point name
404 * @return null or NE specific data
406 public @Nullable NetworkElement getConnectedNeByMountpoint(String mountpoint) {
408 return this.deviceManagerNetconfConnectHandler.getConnectedNeByMountpoint(mountpoint);
413 public void writeToEventLog(String objectId, String msg, String value) {
414 this.odlEventListenerHandler.writeEventLog(objectId, msg, value);
418 public @NonNull VESCollectorService getVESCollectorService() {
419 return this.vesCollectorServiceImpl;