X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=sdnr%2Fwt%2Fdevicemanager%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fccsdk%2Ffeatures%2Fsdnr%2Fwt%2Fdevicemanager%2Fimpl%2FDeviceManagerImpl.java;h=689336f5e11f527f1aad9de9b7219885f91a17b8;hb=9fb395380431345b7da7a765651185815a9ac91d;hp=f0efe7aa4bd962e87991696a26c729ff2598618c;hpb=5219087382301e0534c4e565ca7fbad987e6d9f7;p=ccsdk%2Ffeatures.git diff --git a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java index f0efe7aa4..689336f5e 100644 --- a/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java +++ b/sdnr/wt/devicemanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java @@ -1,4 +1,25 @@ -/******************************************************************************* +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ +/* * ============LICENSE_START======================================================================== * ONAP : ccsdk feature sdnr wt * ================================================================================================= @@ -14,634 +35,388 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. * ============LICENSE_END========================================================================== - ******************************************************************************/ + */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl; -import com.google.common.base.Optional; -import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import java.util.concurrent.CopyOnWriteArrayList; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEntityDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.IEsConfig; import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.AaiProviderClient; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtDatabaseNode; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElementFactory; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.ONFCoreNetworkElementRepresentation; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.toggleAlarmFilter.NotificationDelayService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.HtDevicemanagerConfiguration; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.AkkaConfig; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.EsConfig; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.GeoConfig; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.PmConfig; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeForwarderImpl; import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitor; import org.onap.ccsdk.features.sdnr.wt.devicemanager.devicemonitor.impl.DeviceMonitorImpl; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.database.service.HtDatabaseEventsService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.NetconfChangeListener; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.listener.ODLEventListener; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClient; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientDummyImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.DeviceManagerDatabaseNotificationService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.ODLEventListenerHandler; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.eventdatahandler.RpcPushNotificationsHandler; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ConnectionStatusHousekeepingService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkElementHouskeepingService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl2; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.index.impl.IndexConfigService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.index.impl.IndexMwtnService; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.index.impl.IndexUpdateService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal; import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl; -import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.service.MicrowaveHistoricalPerformanceWriterService; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.MountPoint; -import org.opendaylight.controller.md.sal.binding.api.MountPointService; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInput; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionInputBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.NotificationsService; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NetconfNetworkElementService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.DevicemanagerNotificationDelayService; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.MountPointService; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@SuppressWarnings("deprecation") -public class DeviceManagerImpl implements DeviceManagerService, AutoCloseable, ResyncNetworkElementsListener { +/** + * Devicemanager - Handles startup and closedown of network element handlers for netconf session - Provide common + * services for network element specific components + */ +public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceManagerServiceProvider, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class); private static final String APPLICATION_NAME = "DeviceManager"; private static final String MYDBKEYNAMEBASE = "SDN-Controller"; + private static final String CONFIGURATIONFILE = "etc/devicemanager.properties"; + public static final long DATABASE_TIMEOUT_MS = 120 * 1000L; - // http://sendateodl:8181/restconf/operational/network-topology:network-topology/topology/topology-netconf - private static final InstanceIdentifier NETCONF_TOPO_IID = - InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, - new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName()))); @SuppressWarnings("unused") private static final String STARTUPLOG_FILENAME = "etc/devicemanager.startup.log"; - // private static final String STARTUPLOG_FILENAME2 = "data/cache/devicemanager.startup.log"; - - private DataBroker dataBroker = null; - private MountPointService mountPointService = null; - private RpcProviderRegistry rpcProviderRegistry = null; - @SuppressWarnings("unused") - private NotificationPublishService notificationPublishService = null; - - private final ConcurrentHashMap networkElementRepresentations = - new ConcurrentHashMap<>(); - private WebSocketServiceClient webSocketService; - private HtDatabaseEventsService databaseClientEvents; - private ODLEventListener odlEventListener; - private NetconfChangeListener netconfChangeListener; + // MDSAL Services + private DataBroker dataBroker; + private MountPointService mountPointService; + private RpcProviderService rpcProviderRegistry; + private ClusterSingletonServiceProvider clusterSingletonServiceProvider; + private WebsocketmanagerService websocketmanagerService; + private IEntityDataProvider iEntityDataProvider; + + // Devicemanager common services for network element handler + private WebSocketServiceClientInternal webSocketService; + private ODLEventListenerHandler odlEventListenerHandler; //EventHandlingService private DeviceManagerApiServiceImpl rpcApiService; - private @Nullable PerformanceManagerImpl performanceManager = null; - private ProviderClient dcaeProviderClient; - private ProviderClient aotsMProvider; - private @Nullable AaiProviderClient aaiProviderClient; - private DeviceMonitorImpl deviceMonitor; - private IndexUpdateService updateService; - private IndexConfigService configService; - private IndexMwtnService mwtnService; - private HtDatabaseNode htDatabase; - private Boolean devicemanagerInitializationOk = false; + private PerformanceManagerImpl performanceManager; + private DcaeProviderClient dcaeProviderClient; + private AaiProviderClient aaiProviderClient; + private DcaeForwarderImpl aotsDcaeForwarder; + private DeviceMonitor deviceMonitor; private MaintenanceServiceImpl maintenanceService; - private NotificationDelayService notificationDelayService; - private Thread threadDoClearCurrentFaultByNodename = null; - private int refreshCounter = 0; - private AkkaConfig akkaConfig; + private DevicemanagerNotificationDelayService notificationDelayService; + private ResyncNetworkElementHouskeepingService resyncNetworkElementHouskeepingService; + private ArchiveCleanService archiveCleanService; + private ConnectionStatusHousekeepingService housekeepingService; + private NetconfNodeStateService netconfNodeStateService; + private DataProvider dataProvider; + private VESCollectorServiceImpl vesCollectorServiceImpl; + + // Handler + private DeviceManagerNetconfConnectHandler deviceManagerNetconfConnectHandler; + + // Attributes + private final List factoryList; + + private DeviceManagerDatabaseNotificationService deviceManagerDatabaseAndNotificationService; + + ConfigurationFileRepresentation config; + private Boolean devicemanagerInitializationOk; // Blueprint 1 public DeviceManagerImpl() { LOG.info("Creating provider for {}", APPLICATION_NAME); + this.devicemanagerInitializationOk = false; + this.factoryList = new CopyOnWriteArrayList<>(); + + this.dataBroker = null; + this.mountPointService = null; + this.rpcProviderRegistry = null; + this.clusterSingletonServiceProvider = null; + this.websocketmanagerService = null; + this.iEntityDataProvider = null; + + this.webSocketService = null; } public void setDataBroker(DataBroker dataBroker) { this.dataBroker = dataBroker; } - public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) { + public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) { this.rpcProviderRegistry = rpcProviderRegistry; } - public void setNotificationPublishService(NotificationPublishService notificationPublishService) { - this.notificationPublishService = notificationPublishService; - } + public void setNotificationPublishService(NotificationPublishService notificationPublishService) {} public void setMountPointService(MountPointService mountPointService) { this.mountPointService = mountPointService; } + public void setClusterSingletonService(ClusterSingletonServiceProvider clusterSingletonService) { + this.clusterSingletonServiceProvider = clusterSingletonService; + } + + public void setNetconfNodeStateService(NetconfNodeStateService netconfNodeStateService) { + this.netconfNodeStateService = netconfNodeStateService; + } + + public void setWebsocketmanagerService(WebsocketmanagerService websocketmanagerService) { + this.websocketmanagerService = websocketmanagerService; + } + + public void setEntityDataProvider(IEntityDataProvider iEntityDataProvider) { + this.iEntityDataProvider = iEntityDataProvider; + } + public void init() { LOG.info("Session Initiated start {}", APPLICATION_NAME); - // Start RPC Service - this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry); + this.iEntityDataProvider.setReadyStatus(false); + + this.dataProvider = iEntityDataProvider.getDataProvider(); + // Get configuration - HtDevicemanagerConfiguration config = HtDevicemanagerConfiguration.getConfiguration(); - this.akkaConfig = null; - try { - this.akkaConfig = AkkaConfig.load(); - LOG.debug("akka.conf loaded: " + akkaConfig.toString()); - } catch (Exception e1) { - LOG.warn("problem loading akka.conf: " + e1.getMessage()); - } - GeoConfig geoConfig = null; - if (akkaConfig != null && akkaConfig.isCluster()) { - LOG.info("cluster mode detected"); - if (GeoConfig.fileExists()) { - try { - LOG.debug("try to load geoconfig"); - geoConfig = GeoConfig.load(); - } catch (Exception err) { - LOG.warn("problem loading geoconfig: " + err.getMessage()); - } - } else { - LOG.debug("no geoconfig file found"); - } - } else { - LOG.info("single node mode detected"); - } + this.config = new ConfigurationFileRepresentation(CONFIGURATIONFILE); - this.notificationDelayService = new NotificationDelayService<>(config); - - EsConfig dbConfig = config.getEs(); - LOG.debug("esConfig=" + dbConfig.toString()); - // Start database - htDatabase = HtDatabaseNode.start(dbConfig, akkaConfig, geoConfig); - if (htDatabase == null) { - LOG.error("Can only run with local database. Stop initialization of devicemanager."); - } else { - // init Database Values only if singleNode or clusterMember=1 - if (akkaConfig == null || akkaConfig.isSingleNode() || akkaConfig != null && akkaConfig.isCluster() - && akkaConfig.getClusterConfig().getRoleMemberIndex() == 1) { - // Create DB index if not existing and if database is running - try { - this.configService = new IndexConfigService(htDatabase); - this.mwtnService = new IndexMwtnService(htDatabase); - } catch (Exception e) { - LOG.warn("Can not start ES access clients to provide database index config, mwtn. ", e); - } - } - // start service for device maintenance service - this.maintenanceService = new MaintenanceServiceImpl(htDatabase); - // Websockets - try { - this.webSocketService = new WebSocketServiceClientImpl2(rpcProviderRegistry); - } catch (Exception e) { - LOG.error("Can not start websocket service. Loading mock class.", e); - this.webSocketService = new WebSocketServiceClientDummyImpl(); - } - // DCAE - this.dcaeProviderClient = new DcaeProviderClient(config, dbConfig.getCluster(), this); + this.notificationDelayService = new DevicemanagerNotificationDelayService(config); - this.aaiProviderClient = new AaiProviderClient(config, this); - // EM - EsConfig emConfig = dbConfig.cloneWithIndex("sdnevents"); + // start service for device maintenance service + this.maintenanceService = new MaintenanceServiceImpl(iEntityDataProvider.getHtDatabaseMaintenance()); - if (emConfig == null) { - LOG.warn("No configuration available. Don't start event manager"); - } else { - this.databaseClientEvents = new HtDatabaseEventsService(htDatabase); + // Websockets + this.webSocketService = new WebSocketServiceClientImpl2(websocketmanagerService); - String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + dbConfig.getCluster(); + IEsConfig esConfig = iEntityDataProvider.getEsConfig(); + // DCAE + this.dcaeProviderClient = new DcaeProviderClient(config, esConfig.getCluster(), this); + this.aaiProviderClient = new AaiProviderClient(config, this); - this.odlEventListener = new ODLEventListener(myDbKeyNameExtended, webSocketService, - databaseClientEvents, dcaeProviderClient, aotsMProvider, maintenanceService); - } + this.vesCollectorServiceImpl = new VESCollectorServiceImpl(config); + // EM + String myDbKeyNameExtended = MYDBKEYNAMEBASE + "-" + esConfig.getCluster(); - // PM - PmConfig configurationPM = config.getPm(); - LOG.info("Performance manager configuration: {}", configurationPM); - if (!configurationPM.isPerformanceManagerEnabled()) { - - LOG.info("No configuration available. Don't start performance manager"); - } else { - @Nullable - MicrowaveHistoricalPerformanceWriterService databaseClientHistoricalPerformance; - databaseClientHistoricalPerformance = new MicrowaveHistoricalPerformanceWriterService(htDatabase); - this.performanceManager = new PerformanceManagerImpl(60, databaseClientHistoricalPerformance); - } + this.aotsDcaeForwarder = new DcaeForwarderImpl(null, dcaeProviderClient, maintenanceService); + + this.deviceManagerDatabaseAndNotificationService = new DeviceManagerDatabaseNotificationService(dataProvider, + maintenanceService, webSocketService, notificationDelayService, aotsDcaeForwarder); + + RpcPushNotificationsHandler rpcPushNotificationsHandler = + new RpcPushNotificationsHandler(webSocketService, dataProvider, aotsDcaeForwarder); + this.odlEventListenerHandler = + new ODLEventListenerHandler(myDbKeyNameExtended, webSocketService, dataProvider, aotsDcaeForwarder); + this.archiveCleanService = new ArchiveCleanService(iEntityDataProvider.getEsConfig(), + clusterSingletonServiceProvider, dataProvider); + this.housekeepingService = new ConnectionStatusHousekeepingService(config, clusterSingletonServiceProvider, + this.dataBroker, dataProvider); + // PM + this.performanceManager = new PerformanceManagerImpl(60, this, dataProvider, config); + // DM + // DeviceMonitor has to be available before netconfSubscriptionManager is + // configured + LOG.debug("start DeviceMonitor Service"); + this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListenerHandler, config); + + // ResyncNetworkElementHouskeepingService + this.resyncNetworkElementHouskeepingService = new ResyncNetworkElementHouskeepingService(this, + mountPointService, odlEventListenerHandler, dataProvider, deviceMonitor); + + // RPC Service for specific services + // Start RPC Service + LOG.debug("start rpc service"); + this.rpcApiService = new DeviceManagerApiServiceImpl(rpcProviderRegistry, maintenanceService, + resyncNetworkElementHouskeepingService, rpcPushNotificationsHandler); + + // netconfSubscriptionManager should be the last one because this is a callback + + // service + LOG.debug("start NetconfSubscriptionManager Service"); + this.deviceManagerNetconfConnectHandler = new DeviceManagerNetconfConnectHandler(netconfNodeStateService, + clusterSingletonServiceProvider, odlEventListenerHandler, deviceMonitor, this, factoryList); + + writeToEventLog(APPLICATION_NAME, "startup", "done"); + this.devicemanagerInitializationOk = true; - // DUS (Database update service) - LOG.debug("start db update service"); - this.updateService = - new IndexUpdateService(htDatabase, dbConfig.getHost(), dbConfig.getCluster(), dbConfig.getNode()); - this.updateService.start(); - - // RPC Service for specific services - this.rpcApiService.setMaintenanceService(this.maintenanceService); - this.rpcApiService.setResyncListener(this); - // DM - // DeviceMonitor has to be available before netconfSubscriptionManager is - // configured - LOG.debug("start DeviceMonitor Service"); - this.deviceMonitor = new DeviceMonitorImpl(dataBroker, odlEventListener); - - // netconfSubscriptionManager should be the last one because this is a callback - // service - LOG.debug("start NetconfSubscriptionManager Service"); - // this.netconfSubscriptionManager = new - // NetconfSubscriptionManagerOfDeviceManager(this, dataBroker); - // this.netconfSubscriptionManager.register(); - this.netconfChangeListener = new NetconfChangeListener(this, dataBroker); - this.netconfChangeListener.register(); - - this.devicemanagerInitializationOk = true; - } LOG.info("Session Initiated end. Initialization done {}", devicemanagerInitializationOk); + this.iEntityDataProvider.setReadyStatus(true); + } @Override - public void close() throws Exception { + public void close() { LOG.info("DeviceManagerImpl closing ..."); - close(performanceManager); close(dcaeProviderClient); + close(aotsDcaeForwarder); close(aaiProviderClient); - close(aotsMProvider); close(deviceMonitor); - close(updateService, configService, mwtnService); - close(htDatabase); - close(netconfChangeListener); close(maintenanceService); close(rpcApiService); close(notificationDelayService); - + close(archiveCleanService); + close(housekeepingService); + close(deviceManagerNetconfConnectHandler); + close(vesCollectorServiceImpl); LOG.info("DeviceManagerImpl closing done"); } - - /** - * Used to close all Services, that should support AutoCloseable Pattern - * - * @param toClose - * @throws Exception - */ - private void close(AutoCloseable... toCloseList) throws Exception { - for (AutoCloseable element : toCloseList) { - if (element != null) { - element.close(); - } - } - } - - /*------------------------------------------------------------------------------------------- - * Functions for interface DeviceManagerService - */ - - /** - * For each mounted device a mountpoint is created and this listener is called. - */ @Override - public void startListenerOnNodeForConnectedState(Action action, NodeId nNodeId, NetconfNode nNode) { - - String mountPointNodeName = nNodeId.getValue(); - LOG.info("Starting Event listener on Netconf for mountpoint {} Action {}", mountPointNodeName, action); - - boolean preConditionMissing = false; - if (mountPointService == null) { - preConditionMissing = true; - LOG.warn("No mountservice available."); - } - if (!devicemanagerInitializationOk) { - preConditionMissing = true; - LOG.warn("Devicemanager initialization still pending."); - } - if (preConditionMissing) { - return; - } - - if (networkElementRepresentations.containsKey(mountPointNodeName)) { - LOG.warn("Mountpoint {} already registered. Leave startup procedure.", mountPointNodeName); - return; - } - - if (!isMaster(nNode)) { - // Change Devicemonitor-status to connected ... for non master mountpoints. - deviceMonitor.deviceConnectSlaveIndication(mountPointNodeName); - return; - } - - InstanceIdentifier instanceIdentifier = - NETCONF_TOPO_IID.child(Node.class, new NodeKey(new NodeId(mountPointNodeName))); - - Optional optionalMountPoint = null; - int timeout = 10000; - while (!(optionalMountPoint = mountPointService.getMountPoint(instanceIdentifier)).isPresent() && timeout > 0) { - LOG.info("Event listener waiting for mount point for Netconf device :: Name : {}", mountPointNodeName); - sleepMs(1000); - timeout -= 1000; - } + public @NonNull FactoryRegistration registerBindingNetworkElementFactory( + @NonNull final L factory) { + LOG.info("Factory registration {}", factory.getClass().getName()); - if (!optionalMountPoint.isPresent()) { - LOG.warn("Event listener timeout while waiting for mount point for Netconf device :: Name : {} ", - mountPointNodeName); - return; - } - // Mountpoint is present for sure - MountPoint mountPoint = optionalMountPoint.get(); - //BindingDOMDataBrokerAdapter.BUILDER_FACTORY; - LOG.info("Mountpoint with id: {} class {} toString {}", mountPoint.getIdentifier(), mountPoint.getClass().getName(), mountPoint); - Optional optionalNetconfNodeDatabroker = mountPoint.getService(DataBroker.class); - - if (! optionalNetconfNodeDatabroker.isPresent()) { - LOG.info("Slave mountpoint {} without databroker", mountPointNodeName); - return; - } + factoryList.add(factory); + return new FactoryRegistration() { - DataBroker netconfNodeDataBroker = optionalNetconfNodeDatabroker.get(); - LOG.info("Master mountpoint {}", mountPointNodeName); - // getNodeInfoTest(dataBroker); - - // create automatic empty maintenance entry into db before reading and listening for problems - this.maintenanceService.createIfNotExists(mountPointNodeName); + @Override + public @NonNull L getInstance() { + return factory; + } - // Setup microwaveEventListener for Notificationservice + @Override + public void close() { + factoryList.remove(factory); + } - // MicrowaveEventListener microwaveEventListener = new - // MicrowaveEventListener(mountPointNodeName, websocketmanagerService, - // xmlMapper, databaseClientEvents); - ONFCoreNetworkElementRepresentation ne = ONFCoreNetworkElementFactory.create(mountPointNodeName, dataBroker, - webSocketService, databaseClientEvents, instanceIdentifier, netconfNodeDataBroker, dcaeProviderClient, - aotsMProvider, maintenanceService, notificationDelayService); - networkElementRepresentations.put(mountPointNodeName, ne); - ne.doRegisterMicrowaveEventListener(mountPoint); + }; + } - // Register netconf stream - registerNotificationStream(mountPointNodeName, mountPoint, "NETCONF"); + @SuppressWarnings("null") + @Override + public @NonNull DataProvider getDataProvider() { + return this.dataProvider; + } - // -- Read data from NE - ne.initialReadFromNetworkElement(); - ne.initSynchronizationExtension(); + @SuppressWarnings("null") + @Override + public @NonNull NotificationService getNotificationService() { + return this.deviceManagerDatabaseAndNotificationService; + } - // Setup Service that monitors registration/ deregistration of session - odlEventListener.registration(mountPointNodeName); + @SuppressWarnings("null") + @Override + public @NonNull FaultService getFaultService() { + return this.deviceManagerDatabaseAndNotificationService; + } - if (aaiProviderClient != null) { - aaiProviderClient.onDeviceRegistered(mountPointNodeName); - } - // -- Register NE to performance manager - if (performanceManager != null) { - performanceManager.registration(mountPointNodeName, ne); - } + @SuppressWarnings("null") + @Override + public @NonNull EquipmentService getEquipmentService() { + return this.deviceManagerDatabaseAndNotificationService; + } - deviceMonitor.deviceConnectMasterIndication(mountPointNodeName, ne); + @SuppressWarnings("null") + @Override + public @NonNull AaiService getAaiService() { + return this.aaiProviderClient; + } - LOG.info("Starting Event listener on Netconf device :: Name : {} finished", mountPointNodeName); + @SuppressWarnings("null") + @Override + public @NonNull MaintenanceService getMaintenanceService() { + return this.maintenanceService; } + @SuppressWarnings("null") @Override - public void enterNonConnectedState(NodeId nNodeId, NetconfNode nNode) { - String mountPointNodeName = nNodeId.getValue(); - LOG.info("enter Non ConnectedState for device :: Name : {}", mountPointNodeName); - - ONFCoreNetworkElementRepresentation ne = networkElementRepresentations.remove(mountPointNodeName); - if (ne != null) { - // Handling transition mountpoint connected -> connecting - this.maintenanceService.deleteIfNotRequired(mountPointNodeName); - int problems = ne.removeAllCurrentProblemsOfNode(); - LOG.debug("Removed all {} problems from database at deregistration for {}", problems, mountPointNodeName); - if (odlEventListener != null) { - odlEventListener.deRegistration(mountPointNodeName); - } - if (performanceManager != null) { - performanceManager.deRegistration(mountPointNodeName); - } - if (aaiProviderClient != null) { - aaiProviderClient.onDeviceUnregistered(mountPointNodeName); - } - } else { - // Handling -> create not connected mountpoint, or change other beside connected. - ConnectionStatus csts = nNode.getConnectionStatus(); - if (csts != null) { - odlEventListener.updateRegistration(mountPointNodeName, csts.getClass().getSimpleName(), csts.getName()); - } else { - LOG.info("Unknown connection status"); - } - } - if (deviceMonitor != null) { - deviceMonitor.deviceDisconnectIndication(mountPointNodeName); - } + public @NonNull PerformanceManager getPerformanceManagerService() { + return this.performanceManager; + } + @SuppressWarnings("null") + @Override + public @NonNull EventHandlingService getEventHandlingService() { + return this.odlEventListenerHandler; } + @SuppressWarnings("null") @Override - public void removeMountpointState(NodeId nNodeId) { - String mountPointNodeName = nNodeId.getValue(); - LOG.info("mountpointNodeRemoved {}", nNodeId.getValue()); - deviceMonitor.removeMountpointIndication(mountPointNodeName); + public @NonNull ConfigurationFileRepresentation getConfigurationFileRepresentation() { + return this.config; } - /*------------------------------------------------------------------------------------------- - * Functions - */ + // Deviceinitialization /** - * Async RPC Interface implementation + * Used to close all Services, that should support AutoCloseable Pattern + * + * @param toClose */ - @Override - public @Nonnull List doClearCurrentFaultByNodename(@Nullable List nodeNamesInput) - throws IllegalStateException { - - if (this.databaseClientEvents == null) { - throw new IllegalStateException("dbEvents service not instantiated"); - } - - if (threadDoClearCurrentFaultByNodename != null && threadDoClearCurrentFaultByNodename.isAlive()) { - throw new IllegalStateException("A clear task is already active"); - } else { - - // Create list of mountpoints if input is empty, using the content in ES - if (nodeNamesInput == null || nodeNamesInput.size() <= 0) { - nodeNamesInput = this.databaseClientEvents.getAllNodesWithCurrentAlarms(); - } - - // Filter all mountpoints from input that were found and are known to this Cluster-node instance of - // DeviceManager - final List nodeNamesHandled = new ArrayList<>(); - for (String mountpointName : nodeNamesInput) { - LOG.info("Work with mountpoint {}", mountpointName); - - if (odlEventListener != null && mountpointName.equals(odlEventListener.getOwnKeyName())) { - - // SDN Controller related alarms - // -- can not be recreated on all nodes in connected state - // -- would result in a DCAE/AAI Notification - // Conclusion for 1810 Delivery ... not covered by RPC function (See issue #43) - LOG.info("Ignore SDN Controller related alarms for {}", mountpointName); - // this.databaseClientEvents.clearFaultsCurrentOfNode(mountpointName); - // nodeNamesHandled.add(mountpointName); - - } else { - - if (mountPointService != null) { - InstanceIdentifier instanceIdentifier = - NETCONF_TOPO_IID.child(Node.class, new NodeKey(new NodeId(mountpointName))); - Optional optionalMountPoint = mountPointService.getMountPoint(instanceIdentifier); - - if (!optionalMountPoint.isPresent()) { - LOG.info("Remove Alarms for unknown mountpoint {}", mountpointName); - this.databaseClientEvents.clearFaultsCurrentOfNode(mountpointName); - nodeNamesHandled.add(mountpointName); - } else { - if (networkElementRepresentations.containsKey(mountpointName)) { - LOG.info("At node known mountpoint {}", mountpointName); - nodeNamesHandled.add(mountpointName); - } else { - LOG.info("At node unknown mountpoint {}", mountpointName); - } - } - } + private void close(AutoCloseable... toCloseList) { + for (AutoCloseable element : toCloseList) { + if (element != null) { + try { + element.close(); + } catch (Exception e) { + LOG.warn("Problem during close {}", e); } } - - // Force a sync - if (this.deviceMonitor != null) { - this.deviceMonitor.refreshAlarmsInDb(); - } - - threadDoClearCurrentFaultByNodename = new Thread(() -> { - refreshCounter++; - LOG.info("Start refresh mountpoint task {}", refreshCounter); - // for(String nodeName:nodeNamesOutput) { - for (String nodeName : nodeNamesHandled) { - ONFCoreNetworkElementRepresentation ne = networkElementRepresentations.get(nodeName); - if (ne != null) { - LOG.info("Refresh mountpoint {}", nodeName); - ne.initialReadFromNetworkElement(); - } else { - LOG.info("Unhandled mountpoint {}", nodeName); - } - } - LOG.info("End refresh mountpoint task {}", refreshCounter); - }); - threadDoClearCurrentFaultByNodename.start(); - return nodeNamesHandled; } - }; + } - /** - * Indication if init() of devicemanager successfully done. - * - * @return true if init() was sucessfull. False if not done or not successfull. + /*------------------------------------------------------------------------------------------- + * Functions */ - public boolean isDevicemanagerInitializationOk() { - return this.devicemanagerInitializationOk; + + public ArchiveCleanService getArchiveCleanService() { + return this.archiveCleanService; } - /** - * Get initialization status of database. - * - * @return true if fully initialized false if not - */ - public boolean isDatabaseInitializationFinished() { - return htDatabase == null ? false : htDatabase.getInitialized(); + public DataProvider getDatabaseClientEvents() { + return dataProvider; } - /*--------------------------------------------------------------------- - * Private funtions - */ + @Override + public DeviceManagerServiceProvider getServiceProvider() { + return this; + } /** - * Do the stream creation for the device. + * Indication if init() of devicemanager successfully done. * - * @param mountPointNodeName - * @param mountPoint + * @return true if init() was sucessfull. False if not done or not successfull. */ - private void registerNotificationStream(String mountPointNodeName, MountPoint mountPoint, String streamName) { - - final Optional optionalRpcConsumerService = - mountPoint.getService(RpcConsumerRegistry.class); - if (optionalRpcConsumerService.isPresent()) { - final RpcConsumerRegistry rpcConsumerRegitry = optionalRpcConsumerService.get(); - final NotificationsService rpcService = rpcConsumerRegitry.getRpcService(NotificationsService.class); - if (rpcService == null) { - LOG.warn("rpcService is null for mountpoint {}", mountPointNodeName); - } else { - final CreateSubscriptionInputBuilder createSubscriptionInputBuilder = - new CreateSubscriptionInputBuilder(); - createSubscriptionInputBuilder.setStream(new StreamNameType(streamName)); - LOG.info("Event listener triggering notification stream {} for node {}", streamName, - mountPointNodeName); - try { - CreateSubscriptionInput createSubscriptionInput = createSubscriptionInputBuilder.build(); - if (createSubscriptionInput == null) { - LOG.warn("createSubscriptionInput is null for mountpoint {}", mountPointNodeName); - } else { - rpcService.createSubscription(createSubscriptionInput); - } - } catch (NullPointerException e) { - LOG.warn("createSubscription failed"); - } - } - } else { - LOG.warn("No RpcConsumerRegistry avaialble."); - } - + public boolean isDevicemanagerInitializationOk() { + return this.devicemanagerInitializationOk; } /** - * Get NE object + * Get NE object. Used by DCAE Service * * @param mountpoint mount point name * @return null or NE specific data */ - public @Nullable ONFCoreNetworkElementRepresentation getNeByMountpoint(String mountpoint) { - - return networkElementRepresentations.get(mountpoint); - - } - - /* -- LOG related functions -- */ + public @Nullable NetworkElement getConnectedNeByMountpoint(String mountpoint) { + return this.deviceManagerNetconfConnectHandler.getConnectedNeByMountpoint(mountpoint); - private boolean isInClusterMode() { - return this.akkaConfig == null ? false : this.akkaConfig.isCluster(); } - private String getClusterNetconfNodeName() { - return this.akkaConfig == null ? "" : this.akkaConfig.getClusterConfig().getClusterSeedNodeName("abc"); - } - - private boolean isMaster(NetconfNode nnode) { - if (isInClusterMode()) { - LOG.debug("check if me is responsible for node"); - String masterNodeName = nnode.getClusteredConnectionStatus() == null ? "null" - : nnode.getClusteredConnectionStatus().getNetconfMasterNode(); - /* - * List clusterNodeStatusList=nnode.getClusteredConnectionStatus()==null?null:nnode. - * getClusteredConnectionStatus().getNodeStatus(); if(clusterNodeStatusList!=null) { for(NodeStatus - * s: clusterNodeStatusList) LOG.debug("node "+s.getNode()+ - * " with status "+(s.getStatus()==null?"null":s.getStatus().getName())); } - */ - String myNodeName = getClusterNetconfNodeName(); - LOG.debug("sdnMasterNode=" + masterNodeName + " and sdnMyNode=" + myNodeName); - if (!masterNodeName.equals(myNodeName)) { - LOG.debug("netconf change but me is not master for this node"); - return false; - } - } - return true; + @Override + public void writeToEventLog(String objectId, String msg, String value) { + this.odlEventListenerHandler.writeEventLog(objectId, msg, value); } - - private void sleepMs(int milliseconds) { - try { - Thread.sleep(milliseconds); - } catch (InterruptedException e) { - LOG.debug("Interrupted sleep"); - // Restore interrupted state... - Thread.currentThread().interrupt(); - } + @Override + public @NonNull VESCollectorService getVESCollectorService() { + return this.vesCollectorServiceImpl; } }